You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
4.6 KiB
146 lines
4.6 KiB
import * as THREE from 'three'
|
|
import BaseRenderer from '@/core/base/BaseRenderer.ts'
|
|
import { Line2 } from 'three/examples/jsm/lines/Line2.js'
|
|
import { LineGeometry } from 'three/examples/jsm/lines/LineGeometry.js'
|
|
import { LineMaterial } from 'three/examples/jsm/lines/LineMaterial.js'
|
|
import {decimalSumBy} from "@/core/ModelUtils";
|
|
import Constract from '@/core/Constract.ts'
|
|
|
|
/**
|
|
* 货架货位渲染器
|
|
*/
|
|
export default class RackRenderer extends BaseRenderer {
|
|
static POINT_NAME = 'rack'
|
|
|
|
pointMaterial: THREE.Material
|
|
|
|
/**
|
|
* 默认点的高度, 防止和地面重合
|
|
*/
|
|
readonly defulePositionY: number = Constract.HEIGHT_WAY
|
|
readonly defaultScale: THREE.Vector3 = new THREE.Vector3(1, 1, 1)
|
|
readonly defaultRotation: THREE.Vector3 = new THREE.Vector3(0, 0, 0)
|
|
readonly defaultLineWidth: number = 0.05
|
|
|
|
constructor(itemTypeName: string) {
|
|
super(itemTypeName)
|
|
}
|
|
|
|
/**
|
|
* 所有的点,必须使用 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(_.sumBy(item.dt.bays, b=>b.bayWidth), this.defaultScale.y, item.dt.rackDepth)
|
|
point.rotation.set(
|
|
THREE.MathUtils.degToRad(item.tf[1][0]),
|
|
THREE.MathUtils.degToRad(item.tf[1][1]),
|
|
THREE.MathUtils.degToRad(item.tf[1][2])
|
|
)
|
|
}
|
|
|
|
|
|
createLineBasic(start: ItemJson, end: ItemJson, type: LinkType): THREE.Object3D[] {
|
|
throw new Error('not allow store line.')
|
|
}
|
|
|
|
updateLine(start: ItemJson, end: ItemJson, type: LinkType, option?: RendererCudOption) {
|
|
throw new Error('not allow store line.')
|
|
}
|
|
|
|
|
|
createPoint(item: ItemJson, option?: RendererCudOption): THREE.Object3D[] {
|
|
// 创建平面几何体
|
|
if (!item.dt.bays || !item.dt.rackDepth) {
|
|
return []
|
|
}
|
|
|
|
const group = new THREE.Group()
|
|
group.name = RackRenderer.POINT_NAME
|
|
|
|
const rackWidth = decimalSumBy(item.dt.bays, b=>b.bayWidth)
|
|
const heights = []
|
|
for (let i = 0; i < item.dt.bays.length; i++) {
|
|
const bay = item.dt.bays[i]
|
|
const bayHeight = decimalSumBy(bay.levelHeight)
|
|
heights.push(bayHeight)
|
|
}
|
|
const rackHeight = _.max(heights)
|
|
// 绘制背景矩形框
|
|
const planeGeometry = new THREE.PlaneGeometry(rackWidth, item.dt.rackDepth);
|
|
|
|
planeGeometry.rotateX(Math.PI / 2)
|
|
|
|
const planeMaterial = new THREE.MeshBasicMaterial({
|
|
color: '#9a9090',
|
|
transparent: true, // 启用透明
|
|
opacity: 0.5, // 50%透明度
|
|
depthWrite: false, // 防止深度冲突
|
|
side: THREE.DoubleSide // 双面渲染:ml-citation{ref="5,8" data="citationList"}
|
|
})
|
|
const planeMesh = new THREE.Mesh(planeGeometry, planeMaterial)
|
|
group.add(planeMesh)
|
|
|
|
|
|
// 绘制边框
|
|
const lineXLen = rackWidth - this.defaultLineWidth
|
|
const lineYLen = item.dt.rackDepth - this.defaultLineWidth
|
|
|
|
const lineGeometry = new LineGeometry().setPositions([
|
|
-(lineXLen/2),0,-(lineYLen/2),
|
|
lineXLen/2,0,-(lineYLen/2),
|
|
lineXLen/2,0,lineYLen/2,
|
|
-(lineXLen/2),0,lineYLen/2,
|
|
-(lineXLen/2),0,-(lineYLen/2)
|
|
])
|
|
const lineMaterial = new LineMaterial({
|
|
color: '#0d89a5',
|
|
linewidth: this.defaultLineWidth,
|
|
worldUnits: true,
|
|
resolution: new THREE.Vector2(window.innerWidth, window.innerHeight),
|
|
side: THREE.DoubleSide
|
|
});
|
|
const line = new Line2(lineGeometry, lineMaterial);
|
|
group.add(line as THREE.Object3D)
|
|
|
|
let lineDistanceX = 0
|
|
|
|
for (let i = 0; item.dt.bays.length > 1 && i < item.dt.bays.length - 1; i++) {
|
|
const bay = item.dt.bays[i]
|
|
lineDistanceX += bay.bayWidth
|
|
const lineGeometryT = new LineGeometry().setPositions([
|
|
-(lineDistanceX) +(lineXLen/2),0,lineYLen/2,
|
|
-(lineDistanceX)+(lineXLen/2),0,-(lineYLen/2)
|
|
])
|
|
const lineT = new Line2(lineGeometryT, lineMaterial);
|
|
group.add(lineT as THREE.Object3D)
|
|
}
|
|
|
|
// 设置位置
|
|
group.position.set(item.tf[0][0], item.tf[0][1], item.tf[0][2])
|
|
|
|
|
|
item.dt.rackWidth = rackWidth
|
|
item.dt.rackHeight = rackHeight
|
|
|
|
const points = [group]
|
|
this.fillObjectUserDataFromItem(item, ...points)
|
|
this.afterCreateOrUpdatePoint(item, option, points)
|
|
this.tempViewport.entityManager.appendObject(item.id, points)
|
|
this.appendToScene(...points)
|
|
return points
|
|
}
|
|
|
|
dispose() {
|
|
super.dispose()
|
|
this.pointMaterial?.dispose()
|
|
}
|
|
|
|
createPointBasic(item: ItemJson, option?: RendererCudOption): Object3D[] {
|
|
return [];
|
|
}
|
|
}
|
|
|