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.
 
 
 

84 lines
2.3 KiB

import BaseEntity from '@/core/base/BaseItemEntity.ts'
import type Viewport from '@/core/engine/Viewport.ts'
import * as THREE from 'three'
import gsap from 'gsap'
import Clx3dObject from './Clx3dObject.ts'
export default class ClxEntity extends BaseEntity {
constructor(viewport: Viewport, id: string) {
super(viewport, id)
}
// 抬
addArmRaise(height: number) {
// super.addArmRaise(height)
this.taskQueue.add(this.createTask('ARM_RAISE',
() => this.clxObject.animationUpFork(height)
))
}
// 降
addArmLower() {
// super.addArmLower()
this.taskQueue.add(this.createTask('ARM_LOWER',
() => this.clxObject.animationDownFork()
))
}
// 伸
addArmExtender(z: number = 1.3) {
// super.addArmExtender()
this.taskQueue.add(this.createTask('ARM_EXTEND',
() => this.clxObject.animationShowFork(z)
))
}
// 缩
addArmRetractor() {
// super.addArmRetractor()
this.taskQueue.add(this.createTask('ARM_RETRACT',
() => this.clxObject.animationHideFork()
))
}
// 装
addLoad(item: string): void {
const ptrForkMesh = this.getArmObject()
this.taskQueue.add(this.createTask('LOAD', async () => {
// 实际业务中应包含装载逻辑
this.isCarrying = true
this.isLoading = true
// 将物品拾取到机械臂上
const mesh = this.pickupItem(item)
mesh.position.set(0, 0, -0.2)
mesh.rotation.set(0, THREE.MathUtils.degToRad(90), 0)
ptrForkMesh.add(mesh)
}))
this.taskQueue.add(this.createTask('ARM_RAISE',
()=>this.clxObject.animationUpFork(ptrForkMesh.position.y + 0.2, 1).then(()=>{
this.isCarrying = true
this.isLoading = false
})))
}
// 卸
addUnload(itemId: string, rackId: string, bay?: number, level?: number, cell?: number): void {
this.taskQueue.add(this.createTask('UNLOAD', async () => {
const item = this.viewport.entityManager.findItemById(itemId)
this.isCarrying = false
this.isUnloading = false
// 将物品从机械臂上卸下
this.dropItem(item, rackId, bay, level)
}))
}
get clxObject(): Clx3dObject {
return this.object as Clx3dObject
}
// 帮助方法:获取机械臂对象
getArmObject(): THREE.Object3D {
return this.clxObject.getObjectByName('clxFork')
}
}