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.
119 lines
3.6 KiB
119 lines
3.6 KiB
import * as THREE from 'three'
|
|
import BaseRenderer from '@/core/base/BaseRenderer.ts'
|
|
import Constract from '@/core/Constract.ts'
|
|
import Clx3dObject from './Clx3dObject'
|
|
import type { Object3DLike } from '@/types/ModelTypes.ts'
|
|
import Viewport from "@/core/engine/Viewport";
|
|
|
|
/**
|
|
* clx渲染器
|
|
*/
|
|
export default class ClxRenderer extends BaseRenderer {
|
|
static POINT_NAME = 'clx'
|
|
|
|
pointMaterial: THREE.Material
|
|
|
|
/**
|
|
* 默认点的高度, 防止和地面重合
|
|
*/
|
|
readonly defulePositionY: number = Constract.HEIGHT_WAY
|
|
readonly defaultScale: THREE.Vector3 = new THREE.Vector3(1.65, 3.393, 1.65)
|
|
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 {
|
|
// 创建平面几何体
|
|
const group = new Clx3dObject(item, this.tempViewport, option)
|
|
group.name = ClxRenderer.POINT_NAME
|
|
|
|
// 设置位置
|
|
group.position.set(item.tf[0][0], item.tf[0][1], item.tf[0][2])
|
|
return group
|
|
}
|
|
|
|
/**
|
|
* 如果某物品要放到 Cl2 上 返回可存放的位置和角度一个 Position 和 Rotation
|
|
*/
|
|
getStorePlacement(storeItem: ItemJson, bay = 0, level = 0, cell = 0)
|
|
: {
|
|
position: [number, number, number], rotation: [number, number, number],
|
|
getParentObject3D?: (viewport: Viewport, parent: THREE.Object3D) => THREE.Object3D
|
|
} {
|
|
|
|
return {
|
|
position: [0, 0.2, 0],
|
|
rotation: [0, 90, 0],
|
|
getParentObject3D: this.getArmObject.bind(this)
|
|
}
|
|
}
|
|
getArmObject(viewport: Viewport, item: ItemJson): THREE.Object3D {
|
|
// 获取机械臂对象
|
|
const object = viewport.entityManager.findObjectById(item.dt.storeAt?.item)
|
|
if (!object) {
|
|
console.warn('PtrRenderer: getArmObject failed, not found Cl2:', item.dt.storeAt?.item)
|
|
return
|
|
}
|
|
|
|
const agv = object as THREE.Group
|
|
const clxFork = agv.getObjectByName('clxFork')
|
|
return clxFork
|
|
}
|
|
|
|
updatePoint(item: ItemJson, object: Object3DLike, option?: RendererCudOption): Object3DLike {
|
|
const group: THREE.Group = object as THREE.Group
|
|
|
|
group.position.set(item.tf[0][0], item.tf[0][1], item.tf[0][2])
|
|
group.rotation.set(
|
|
THREE.MathUtils.degToRad(item.tf[1][0]),
|
|
THREE.MathUtils.degToRad(item.tf[1][1]),
|
|
THREE.MathUtils.degToRad(item.tf[1][2])
|
|
)
|
|
|
|
// 禁止缩放,
|
|
item.tf[2][0] = this.defaultScale.x
|
|
item.tf[2][1] = this.defaultScale.y
|
|
item.tf[2][2] = this.defaultScale.z
|
|
|
|
return group
|
|
}
|
|
|
|
dispose() {
|
|
super.dispose()
|
|
this.pointMaterial?.dispose()
|
|
}
|
|
|
|
createPointBasic(item: ItemJson, option?: RendererCudOption): THREE.Object3D {
|
|
throw new Error('Clx createPointBasic not allow!')
|
|
}
|
|
|
|
}
|
|
|