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.
98 lines
3.1 KiB
98 lines
3.1 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'
|
|
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, 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(this.defaultRotation.x),
|
|
THREE.MathUtils.degToRad(this.defaultRotation.y),
|
|
THREE.MathUtils.degToRad(this.defaultRotation.z)
|
|
)
|
|
}
|
|
|
|
|
|
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) {
|
|
return []
|
|
}
|
|
|
|
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)
|
|
planeGeometry.rotateY(-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])
|
|
|
|
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 [];
|
|
}
|
|
}
|
|
|