|
|
|
@ -3,9 +3,10 @@ import BaseRenderer from '@/core/base/BaseRenderer.ts' |
|
|
|
import Constract from '@/core/Constract.ts' |
|
|
|
import { type Object3DLike } from '@/types/ModelTypes.ts' |
|
|
|
import InstancePointManager from '@/core/manager/InstancePointManager.ts' |
|
|
|
import LineSegmentManager from '@/core/manager/LineSegmentManager.ts' |
|
|
|
import { LineMaterial } from 'three/examples/jsm/lines/LineMaterial' |
|
|
|
import { getOBBox } from '@/core/ModelUtils.ts' |
|
|
|
import { getMatrixFromTf } from '@/core/ModelUtils.ts' |
|
|
|
import InstanceMeshManager from '@/core/manager/InstanceMeshManager.ts' |
|
|
|
import { translate } from 'element-plus' |
|
|
|
|
|
|
|
/** |
|
|
|
* 地堆货位渲染器 |
|
|
|
@ -29,76 +30,28 @@ export default class GstoreRenderer extends BaseRenderer { |
|
|
|
strokeWidth: 0.08 |
|
|
|
} |
|
|
|
|
|
|
|
pointGeometry = new THREE.PlaneGeometry( |
|
|
|
1, 1 |
|
|
|
).rotateX(-Math.PI / 2) |
|
|
|
pointGeometry = new THREE.BoxGeometry( |
|
|
|
1, 1, 1 |
|
|
|
).translate(0, 0.5, 0) |
|
|
|
pointMaterial: THREE.Material = new THREE.MeshBasicMaterial({ |
|
|
|
color: 0xffffff, |
|
|
|
transparent: true, |
|
|
|
opacity: 0.5 |
|
|
|
}) |
|
|
|
|
|
|
|
strokeMaterial = new LineMaterial({ |
|
|
|
color: this.defaultPointOption.strokeColor, |
|
|
|
transparent: false, |
|
|
|
linewidth: this.defaultPointOption.strokeWidth, |
|
|
|
gapSize: 0, |
|
|
|
worldUnits: true |
|
|
|
strokeMaterial = new THREE.MeshBasicMaterial({ |
|
|
|
color: 0x038217, |
|
|
|
// transparent: true,
|
|
|
|
// opacity: 0.2,
|
|
|
|
side: THREE.DoubleSide |
|
|
|
}) |
|
|
|
|
|
|
|
get pointManager(): InstancePointManager { |
|
|
|
if (!this.tempViewport) { |
|
|
|
throw new Error('tempViewport is not set.') |
|
|
|
} |
|
|
|
return this.tempViewport.getOrCreatePointManager(this.itemTypeName, () => |
|
|
|
// 构建 InstanceMesh 代理对象
|
|
|
|
InstancePointManager.create(this.itemTypeName, |
|
|
|
this.tempViewport, |
|
|
|
this.pointGeometry, |
|
|
|
this.pointMaterial, |
|
|
|
true, true) |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
strokeGeometry = new THREE.BoxGeometry(1, 1, 1) |
|
|
|
|
|
|
|
createPointBasic(item: ItemJson, option?: RendererCudOption): Object3DLike { |
|
|
|
return this.pointManager.createPoint(item) |
|
|
|
} |
|
|
|
|
|
|
|
afterCreateOrUpdatePoint(item: ItemJson, option: RendererCudOption, object: Object3DLike) { |
|
|
|
super.afterCreateOrUpdatePoint(item, option, object) |
|
|
|
|
|
|
|
const edgePositions = getOBBox(item) |
|
|
|
// const positions = []
|
|
|
|
for (let i = 0; i < edgePositions.length; i += 2) { |
|
|
|
const p1 = edgePositions[i] |
|
|
|
const p2 = edgePositions[i + 1] |
|
|
|
// positions.push(p1.x, p1.y, p1.z)
|
|
|
|
// positions.push(p2.x, p2.y, p2.z)
|
|
|
|
this.lineSegmentManager.createLine(item.id + '_l' + i, p1, p2, this.strokeMaterial.color) |
|
|
|
} |
|
|
|
|
|
|
|
// // 画边线
|
|
|
|
// const center = [item.tf[0][0], item.tf[0][2]]
|
|
|
|
// const h = (item.tf[0][1] || this.defulePositionY) + 0.01
|
|
|
|
// const widthHalf = item.tf[2][0] / 2
|
|
|
|
// const depthHalf = item.tf[2][2] / 2
|
|
|
|
// const lwHalf = (item.dt.strokeWidth || this.defaultPointOption.strokeWidth) / 2
|
|
|
|
// // 左上角
|
|
|
|
// const p1 = [center[0] - widthHalf + lwHalf, h, center[1] - depthHalf + lwHalf]
|
|
|
|
// // 右上角
|
|
|
|
// const p2 = [center[0] + widthHalf - lwHalf, h, center[1] - depthHalf + lwHalf]
|
|
|
|
// // 右下角
|
|
|
|
// const p3 = [center[0] + widthHalf - lwHalf, h, center[1] + depthHalf - lwHalf]
|
|
|
|
// // 左下角
|
|
|
|
// const p4 = [center[0] - widthHalf + lwHalf, h, center[1] + depthHalf - lwHalf]
|
|
|
|
//
|
|
|
|
// this.lineSegmentManager.createLine(item.id + '_l1', p1, p2, this.strokeMaterial.color)
|
|
|
|
// this.lineSegmentManager.createLine(item.id + '_l2', p2, p3, this.strokeMaterial.color)
|
|
|
|
// this.lineSegmentManager.createLine(item.id + '_l3', p3, p4, this.strokeMaterial.color)
|
|
|
|
// this.lineSegmentManager.createLine(item.id + '_l4', p4, p1, this.strokeMaterial.color)
|
|
|
|
} |
|
|
|
|
|
|
|
createLineBasic(start: ItemJson, end: ItemJson, type: LinkType): THREE.Object3D { |
|
|
|
throw new Error('not allow store line.') |
|
|
|
} |
|
|
|
@ -107,26 +60,109 @@ export default class GstoreRenderer extends BaseRenderer { |
|
|
|
throw new Error('not allow store line.') |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 地堆位置发生变化后, 创建地堆货位标记 |
|
|
|
* @param item |
|
|
|
* @param option |
|
|
|
* @param object |
|
|
|
*/ |
|
|
|
afterCreateOrUpdatePoint(item: ItemJson, option: RendererCudOption, object: Object3DLike) { |
|
|
|
super.afterCreateOrUpdatePoint(item, option, object) |
|
|
|
// 目标物体 matrix
|
|
|
|
const matrix = getMatrixFromTf(item.tf) |
|
|
|
|
|
|
|
const depth = item.dt.strokeWidth || 0.2 |
|
|
|
|
|
|
|
// 从矩阵分解位置、旋转和缩放
|
|
|
|
const position = new THREE.Vector3() |
|
|
|
const rotation = new THREE.Quaternion() |
|
|
|
const scale = new THREE.Vector3() |
|
|
|
matrix.decompose(position, rotation, scale) |
|
|
|
|
|
|
|
// 计算半尺寸(考虑建筑物缩放)
|
|
|
|
const halfWidth = scale.x / 2 |
|
|
|
const halfHeight = scale.y / 2 |
|
|
|
const halfLength = scale.z / 2 |
|
|
|
const halfDepth = depth / 2 |
|
|
|
|
|
|
|
position.y = position.y + halfHeight |
|
|
|
|
|
|
|
// 计算向内偏移量(确保墙完全包含在内部)
|
|
|
|
const insetX = halfWidth - halfDepth |
|
|
|
const insetZ = halfLength - halfDepth |
|
|
|
|
|
|
|
// 定义四面墙的参数:位置偏移和缩放(全部向内偏移)
|
|
|
|
const walls = [ |
|
|
|
// 前墙 (Z+方向)
|
|
|
|
{ |
|
|
|
offset: new THREE.Vector3(0, 0, insetZ), |
|
|
|
scale: new THREE.Vector3(scale.x, scale.y, depth) |
|
|
|
}, |
|
|
|
// 后墙 (Z-方向)
|
|
|
|
{ |
|
|
|
offset: new THREE.Vector3(0, 0, -insetZ), |
|
|
|
scale: new THREE.Vector3(scale.x, scale.y, depth) |
|
|
|
}, |
|
|
|
// 左墙 (X-方向)
|
|
|
|
{ |
|
|
|
offset: new THREE.Vector3(-insetX, 0, 0), |
|
|
|
scale: new THREE.Vector3(depth, scale.y, scale.z - depth * 2) |
|
|
|
}, |
|
|
|
// 右墙 (X+方向)
|
|
|
|
{ |
|
|
|
offset: new THREE.Vector3(insetX, 0, 0), |
|
|
|
scale: new THREE.Vector3(depth, scale.y, scale.z - depth * 2) |
|
|
|
} |
|
|
|
] |
|
|
|
|
|
|
|
// 为每面墙创建变换矩阵
|
|
|
|
const tempMatrix = new THREE.Matrix4() |
|
|
|
const tempPosition = new THREE.Vector3() |
|
|
|
const tempScale = new THREE.Vector3() |
|
|
|
|
|
|
|
walls.forEach((wall, i) => { |
|
|
|
tempPosition.copy(wall.offset).applyQuaternion(rotation).add(position) |
|
|
|
tempScale.copy(wall.scale) |
|
|
|
tempMatrix.compose(tempPosition, rotation, tempScale) |
|
|
|
|
|
|
|
const wrap1 = this.wallManager.create(item.id + '_' + i, {}) |
|
|
|
wrap1.setMatrix4(tempMatrix) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
dispose() { |
|
|
|
super.dispose() |
|
|
|
this.pointGeometry.dispose() |
|
|
|
this.pointMaterial.dispose() |
|
|
|
this.strokeMaterial.dispose() |
|
|
|
// this.strokeMaterial.dispose()
|
|
|
|
} |
|
|
|
|
|
|
|
get pointManager(): InstancePointManager { |
|
|
|
if (!this.tempViewport) { |
|
|
|
throw new Error('tempViewport is not set.') |
|
|
|
} |
|
|
|
return this.tempViewport.getOrCreatePointManager(this.itemTypeName, () => |
|
|
|
// 构建 InstanceMesh 代理对象
|
|
|
|
InstancePointManager.create(this.itemTypeName, |
|
|
|
this.tempViewport, |
|
|
|
this.pointGeometry, |
|
|
|
this.pointMaterial, |
|
|
|
true, true) |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
get lineSegmentManager(): LineSegmentManager { |
|
|
|
get wallManager(): InstanceMeshManager { |
|
|
|
if (!this.tempViewport) { |
|
|
|
throw new Error('tempViewport is not set.') |
|
|
|
} |
|
|
|
|
|
|
|
const name = this.itemTypeName + '_bj' |
|
|
|
const name = 'GS_WALL' |
|
|
|
|
|
|
|
return this.tempViewport.getOrCreateLineManager(name, () => |
|
|
|
return this.tempViewport.getOrCreateMeshManager(name, () => { |
|
|
|
// 构建 LineSegment.points 代理对象
|
|
|
|
LineSegmentManager.create(name, |
|
|
|
this.tempViewport, |
|
|
|
this.strokeMaterial) |
|
|
|
) |
|
|
|
return new InstanceMeshManager(name, this.tempViewport, this.strokeGeometry, this.strokeMaterial, |
|
|
|
false, false) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|