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' import ptrUrl from '@/assets/images/ptr/ptr.png' /** * ptr侧叉渲染器 */ export default class PtrRenderer extends BaseRenderer { static POINT_NAME = 'ptr' 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.15 constructor(itemTypeName: string) { super(itemTypeName) } /** * 所有的点,必须使用 storeWidth/storeDepth, 改TF无效 */ override afterCreateOrUpdatePoint(item: ItemJson, option: RendererCudOption, object: THREE.Object3D) { super.afterCreateOrUpdatePoint(item, option, object) const point = object // 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.ptrWidth || !item.dt.ptrDepth) { system.showErrorDialog('field ptrWidth / ptrDepth is null!') return null } const textureLoader = new THREE.TextureLoader() const texture = textureLoader.load(ptrUrl) const group = new THREE.Group() group.name = PtrRenderer.POINT_NAME // 绘制背景矩形框 const planeGeometry = new THREE.PlaneGeometry(item.dt.ptrWidth, item.dt.ptrDepth) planeGeometry.rotateX(-Math.PI / 2) const planeMaterial = new THREE.MeshLambertMaterial({ map: texture, // 颜色贴图 transparent: true // 允许透明纹理 }) const planeMesh = new THREE.Mesh(planeGeometry, planeMaterial) group.add(planeMesh) // 设置位置 group.position.set(item.tf[0][0], item.tf[0][1], item.tf[0][2]) return group } dispose() { super.dispose() this.pointMaterial?.dispose() } createPointBasic(item: ItemJson, option?: RendererCudOption): THREE.Object3D { throw new Error('Ptr createPointBasic not allow!') } }