From a4668a619cb00adb4739490f6cf6b9da4262f37c Mon Sep 17 00:00:00 2001 From: luoyifan Date: Wed, 4 Jun 2025 15:32:33 +0800 Subject: [PATCH] gstore --- src/modules/gstore/GstoreInteraction.ts | 4 +- src/modules/gstore/GstoreRenderer.ts | 113 ++------------------------------ 2 files changed, 6 insertions(+), 111 deletions(-) diff --git a/src/modules/gstore/GstoreInteraction.ts b/src/modules/gstore/GstoreInteraction.ts index 56efc2c..2979e4a 100644 --- a/src/modules/gstore/GstoreInteraction.ts +++ b/src/modules/gstore/GstoreInteraction.ts @@ -15,8 +15,8 @@ export default class GstoreInteraction extends BaseInteraction { item = super.createPointOfItem(item, point) // 创建一个地堆货架 - item.dt.rackWidth = 1.2 // 宽度 - item.dt.rackDepth = 1.2 // 深度 + item.dt.storeWidth = 1.2 // 宽度 + item.dt.storeDepth = 1.2 // 深度 return item } } \ No newline at end of file diff --git a/src/modules/gstore/GstoreRenderer.ts b/src/modules/gstore/GstoreRenderer.ts index 3f50912..789b311 100644 --- a/src/modules/gstore/GstoreRenderer.ts +++ b/src/modules/gstore/GstoreRenderer.ts @@ -9,16 +9,9 @@ import { getLineId } from '@/core/ModelUtils.ts' * 辅助测量工具渲染器 */ export default class GstoreRenderer extends BaseRenderer { - static LABEL_NAME = 'way_label' static POINT_NAME = 'way_point' pointMaterial: THREE.Material - lineMaterial = new THREE.MeshBasicMaterial({ - color: 0xa0cfff, - transparent: true, - opacity: 0.2, - side: THREE.DoubleSide - }) /** * 默认点的高度, 防止和地面重合 @@ -31,42 +24,15 @@ export default class GstoreRenderer extends BaseRenderer { super(itemTypeName) } - async init() { - return Promise.all([ - super.init(), - this.loadFont() - ]) - } - - async loadFont() { - return new Promise((resolve, reject) => { - new THREE.TextureLoader().load( - MoveLinePointPng, - (texture) => { - this.pointMaterial = new THREE.SpriteMaterial({ - map: texture, - transparent: true, - side: THREE.DoubleSide - }) - resolve() - }, - undefined, - function(err) { - reject(err) - } - ) - }) - } - /** - * 所有的点,必须使用同一个尺寸, 改属性也无效 + * 所有的点,必须使用 storeWidth/storeDepth, 改TF无效 */ override afterCreateOrUpdatePoint(item: ItemJson, option: RendererCudOption, objects: THREE.Object3D[]) { super.afterCreateOrUpdatePoint(item, option, objects) const point = objects[0] point.position.y = this.defulePositionY - point.scale.set(this.defaultScale.x, this.defaultScale.y, this.defaultScale.z) + point.scale.set(item.dt.storeWidth, this.defaultScale.y, item.dt.storeDepth) point.rotation.set( THREE.MathUtils.degToRad(this.defaultRotation.x), THREE.MathUtils.degToRad(this.defaultRotation.y), @@ -76,73 +42,11 @@ export default class GstoreRenderer extends BaseRenderer { createLineBasic(start: ItemJson, end: ItemJson, type: LinkType): THREE.Object3D[] { - const group = new THREE.Group() - const startPosition = new THREE.Vector3(start.tf[0][0], 0.01, start.tf[0][2]) - const endPosition = new THREE.Vector3(end.tf[0][0], 0.01, end.tf[0][2]) - const width = 1 - - const curve = new THREE.LineCurve3(startPosition, endPosition) - const tubeGeometry = new THREE.TubeGeometry(curve, 1, width / 2, 8, false) - const lineMesh = new THREE.Mesh(tubeGeometry, this.lineMaterial) - group.add(lineMesh) - - - const midPoint = new THREE.Vector3() - .addVectors(startPosition, endPosition) - .multiplyScalar(0.5) - - const distance = (startPosition.distanceTo(endPosition) * 1000).toFixed(0) - - const label = new Text() - label.text = distance - label.font = SimSunTTF - label.fontSize = 0.2 - label.color = '#5f5f5f' - label.opacity = 0.8 - label.anchorX = 'center' - label.anchorY = 'middle' - label.depthOffset = 1 - label.material.depthTest = false - label.name = GstoreRenderer.LABEL_NAME - label.quaternion.copy(this.tempViewport.camera.quaternion) - label.sync() - label.position.set(midPoint.x, midPoint.y, midPoint.z) - - group.add(label) - - return [group] + throw new Error('not allow store line.') } updateLine(start: ItemJson, end: ItemJson, type: LinkType, option?: RendererCudOption) { - super.updateLine(start, end, type, option) - - const startPosition = new THREE.Vector3(start.tf[0][0], 0.01, start.tf[0][2]) - const endPosition = new THREE.Vector3(end.tf[0][0], 0.01, end.tf[0][2]) - const width = 1 - - const lineId = getLineId(start.id, end.id, type) - const lines = this.tempViewport.entityManager.findLineObjectsById(lineId) - const group: THREE.Group = lines[0] as THREE.Group - - // 清空group里的元素 - const label: Text = group.children[1] - group.clear() - - const curve = new THREE.LineCurve3(startPosition, endPosition) - const tubeGeometry = new THREE.TubeGeometry(curve, 1, width / 2, 8, false) - const lineMesh = new THREE.Mesh(tubeGeometry, this.lineMaterial) - group.add(lineMesh) - - const midPoint = new THREE.Vector3() - .addVectors(startPosition, endPosition) - .multiplyScalar(0.5) - - const distance = (startPosition.distanceTo(endPosition) * 1000).toFixed(0) - label.text = distance - label.quaternion.copy(this.tempViewport.camera.quaternion) - label.sync() - label.position.set(midPoint.x, midPoint.y, midPoint.z) - group.add(label) + throw new Error('not allow store line.') } createPointBasic(item: ItemJson, option?: RendererCudOption): THREE.Object3D[] { @@ -151,17 +55,8 @@ export default class GstoreRenderer extends BaseRenderer { return [obj] } - appendToScene(...objects: THREE.Object3D[]) { - const dragObjects = objects.filter(obj => !!obj.userData.draggable) - this.tempViewport.dragControl.setDragObjects(dragObjects, 'push') - // this.tempViewport.dragControl.setDragObjects(objects, 'remove') - - this.tempViewport?.scene.add(...objects) - } - dispose() { super.dispose() this.pointMaterial.dispose() - this.lineMaterial.dispose() } } \ No newline at end of file