diff --git a/src/modules/cl2/Cl23dObject.ts b/src/modules/cl2/Cl23dObject.ts index 37cae18..6a19419 100644 --- a/src/modules/cl2/Cl23dObject.ts +++ b/src/modules/cl2/Cl23dObject.ts @@ -2,6 +2,7 @@ import * as THREE from "three"; import {CSG} from "three-csg-ts"; //@ts-ignore import {mergeGeometries} from 'three/addons/utils/BufferGeometryUtils.js' +import gsap from "gsap"; export default class Cl23dObject extends THREE.Object3D { @@ -301,7 +302,7 @@ export default class Cl23dObject extends THREE.Object3D { const ptrPedestalGeometry = Cl23dObject.ptrPedestalGeometry const ptrPedestalMaterial = new THREE.MeshPhongMaterial({color: 0xffdddbca}); const ptrPedestalMesh = new THREE.Mesh(ptrPedestalGeometry, ptrPedestalMaterial); - ptrPedestalMesh.name = 'ptrPedestalMesh' + ptrPedestalMesh.name = 'ptrPedestal' if (!Cl23dObject.ptrPillarGeometry) { Cl23dObject.ptrPillarGeometry = Cl23dObject.createPtrPillar() @@ -309,7 +310,7 @@ export default class Cl23dObject extends THREE.Object3D { const ptrPillarGeometry = Cl23dObject.ptrPillarGeometry; const ptrPillarMaterial = new THREE.MeshPhongMaterial({color: 0xff6c6956}); const ptrPillarMesh = new THREE.Mesh(ptrPillarGeometry, ptrPillarMaterial); - ptrPillarMesh.name = 'ptrPillarMesh' + if (!Cl23dObject.ptrForkGeometry) { Cl23dObject.ptrForkGeometry = Cl23dObject.createPtrFork() @@ -317,13 +318,73 @@ export default class Cl23dObject extends THREE.Object3D { const ptrForkGeometry = Cl23dObject.ptrForkGeometry; const ptrForkMaterial = new THREE.MeshPhongMaterial({color: 0xff444444}); const ptrForkMesh = new THREE.Mesh(ptrForkGeometry, ptrForkMaterial); - ptrForkMesh.name = 'ptrForkMesh' + ptrForkMesh.name = 'ptrFork' this.add(ptrPedestalMesh) const groupPillar = new THREE.Group() + groupPillar.name = 'ptrPillar' groupPillar.add(ptrPillarMesh) groupPillar.add(ptrForkMesh) this.add(groupPillar) } + animationShowFork(z: number): Promise { + + const ptrPillar = this.getObjectByName('ptrPillar') + const time = 3 + return new Promise(resolve => { + gsap.to(ptrPillar.position, { + z: -z, + duration: time, + repeat: 0, + ease: 'sine.inOut', + onComplete: resolve + }) + }) + + } + + animationHideFork(): Promise { + return this.animationShowFork(0) + } + + animationUpFork(y: number, time?: number = 3): Promise { + const ptrFork = this.getObjectByName('ptrFork') + const ptrPillar = this.getObjectByName('ptrPillar') + const pz = ptrPillar.position.z + return new Promise(resolve => { + const bh = 0.22 + 0.075 + const children = ptrFork.children + + gsap.to(ptrFork.position, { + y: y, + duration: time, + repeat: 0, + ease: 'sine.inOut', + onComplete: resolve, + onUpdate: function() { + const a = this.targets()[0] + if (a.y < bh) { + if (pz > -1) { + for (let i = 0; i < children.length; i++) { + const child = children[i] + child.position.y = -0.05 + bh - a.y + } + } else if (a.y < 0.1 ) { + for (let i = 0; i < children.length; i++) { + const child = children[i] + child.position.y = -0.05 + 0.15 - a.y + } + } + } + } + }) + }) + } + + animationDownFork(): Promise { + return this.animationUpFork(0) + } + + } diff --git a/src/modules/cl2/Cl2Entity.ts b/src/modules/cl2/Cl2Entity.ts index 9799313..a41f331 100644 --- a/src/modules/cl2/Cl2Entity.ts +++ b/src/modules/cl2/Cl2Entity.ts @@ -3,6 +3,7 @@ import BaseEntity from '@/core/base/BaseItemEntity.ts' import type Viewport from '@/core/engine/Viewport.ts' import gsap from 'gsap' import { nextTick } from 'vue' +import Cl23dObject from "@/modules/cl2/Cl23dObject"; /** * CL2 机械臂实体类 @@ -12,33 +13,67 @@ export default class Cl2Entity extends BaseEntity { super(viewport, id) } + // 抬 + addArmRaise(height: number) { + // super.addArmRaise(height) + this.taskQueue.add(this.createTask('ARM_RAISE', + () => this.cl2Object.animationUpFork(height) + )) + } + + // 降 + addArmLower() { + // super.addArmLower() + this.taskQueue.add(this.createTask('ARM_LOWER', + () => this.cl2Object.animationDownFork() + )) + } + + // 伸 + addArmExtender(z: number = 1.2) { + // super.addArmExtender() + this.taskQueue.add(this.createTask('ARM_EXTEND', + () => this.cl2Object.animationShowFork(z) + )) + } + + // 缩 + addArmRetractor() { + // super.addArmRetractor() + this.taskQueue.add(this.createTask('ARM_RETRACT', + () => this.cl2Object.animationHideFork() + )) + } // 装 addLoad(item: string): void { + + const ptrForkMesh = this.getArmObject() this.taskQueue.add(this.createTask('LOAD', async () => { // 实际业务中应包含装载逻辑 this.isCarrying = true - - const arm = this.getArmObject() - this.isLoading = true // 将物品拾取到机械臂上 const mesh = this.pickupItem(item) - const ptrForkMesh = this.getArmObject() - mesh.position.set(0, 0.1, 0) + mesh.position.set(0, -0.05, -0.15) mesh.rotation.set(0, THREE.MathUtils.degToRad(90), 0) ptrForkMesh.add(mesh) + })) - // 抬高20cm - gsap.to(arm.position, { - y: arm.position.y + 0.2, - duration: 0.5, - ease: 'sine.inOut', - onComplete: () => { - this.isCarrying = true - this.isLoading = false - } + this.taskQueue.add(this.createTask('ARM_RAISE', + ()=>{ + return new Promise(resolve => { + gsap.to(ptrForkMesh.position, { + y: ptrForkMesh.position.y + 0.2, + duration: 1, + ease: 'sine.inOut', + onComplete: () => { + this.isCarrying = true + this.isLoading = false + resolve() + } + }) }) - })) + })) } // 卸 @@ -73,4 +108,8 @@ export default class Cl2Entity extends BaseEntity { } return undefined } + + get cl2Object(): Cl23dObject { + return this.object as Cl23dObject + } } diff --git a/src/modules/clx/Clx3dObject.ts b/src/modules/clx/Clx3dObject.ts index 9594606..7294a33 100644 --- a/src/modules/clx/Clx3dObject.ts +++ b/src/modules/clx/Clx3dObject.ts @@ -641,17 +641,18 @@ export default class Clx3dObject extends THREE.Object3D { onComplete: resolve, onUpdate: function() { const a = this.targets()[0] - if (a.y < 0.1 ) { - for (let i = 0; i < children.length; i++) { - const child = children[i] - child.position.y = -0.05 + 0.15 - a.y - } - } - if (a.y < bh && a.z > -1) { + if (a.y < bh) { console.log(a.z) - for (let i = 0; i < children.length; i++) { - const child = children[i] - child.position.y = -0.05 + bh - a.y + if (a.z > -1) { + for (let i = 0; i < children.length; i++) { + const child = children[i] + child.position.y = -0.05 + bh - a.y + } + } else if (a.y < 0.1 ) { + for (let i = 0; i < children.length; i++) { + const child = children[i] + child.position.y = -0.05 + 0.15 - a.y + } } } }