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.
77 lines
2.3 KiB
77 lines
2.3 KiB
import * as THREE from 'three'
|
|
import BaseRenderer from '@/core/base/BaseRenderer.ts'
|
|
import Constract from '@/core/Constract.ts'
|
|
import InstancePointManager from '@/core/manager/InstancePointManager.ts'
|
|
import type { Object3DLike } from '@/types/ModelTypes.ts'
|
|
import MODULE_3DS_File from '@/assets/Models/Tote.3ds?url'
|
|
import MODULE_3DS_TEX from '@/assets/Models/ToteTex.png?url'
|
|
import { load3DModule, loadByUrl, loadTexture } from '@/core/ModelUtils.ts'
|
|
|
|
/**
|
|
* 货架货位渲染器
|
|
*/
|
|
export default class PalletRenderer extends BaseRenderer {
|
|
static POINT_NAME = 'pallet_point'
|
|
|
|
/**
|
|
* 默认点的高度, 防止和地面重合
|
|
*/
|
|
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 defaultUserData = {
|
|
color: 0x4559A0
|
|
}
|
|
|
|
toteGeometry: THREE.BufferGeometry
|
|
toteMaterial: THREE.Material
|
|
|
|
init() {
|
|
return Promise.all([
|
|
super.init(),
|
|
loadByUrl(MODULE_3DS_File),
|
|
loadTexture(MODULE_3DS_TEX)
|
|
|
|
]).then(([_, { data: queue3dsFile }, queueTexture]) => {
|
|
const mesh = load3DModule(queue3dsFile, '.3ds').children[0] as THREE.Mesh
|
|
this.toteGeometry = mesh.geometry.rotateX(-Math.PI / 2)
|
|
this.toteGeometry.scale(1, 1, 1)
|
|
this.toteGeometry.center()
|
|
this.toteMaterial = mesh.material as THREE.Material
|
|
//@ts-ignore
|
|
this.toteMaterial.map = queueTexture
|
|
//@ts-ignore
|
|
this.toteMaterial.color.set(this.defaultUserData.color)
|
|
})
|
|
}
|
|
|
|
createPointBasic(item: ItemJson, option?: RendererCudOption): Object3DLike {
|
|
return this.pointManager.createPoint(item)
|
|
}
|
|
|
|
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.toteGeometry,
|
|
this.toteMaterial,
|
|
true, true)
|
|
)
|
|
}
|
|
|
|
dispose() {
|
|
super.dispose()
|
|
if (this.toteGeometry) {
|
|
this.toteGeometry.dispose()
|
|
this.toteGeometry = undefined
|
|
}
|
|
if (this.toteMaterial) {
|
|
this.toteMaterial.dispose()
|
|
this.toteMaterial = undefined
|
|
}
|
|
}
|
|
}
|
|
|