diff --git a/src/core/base/BaseItemEntity.ts b/src/core/base/BaseItemEntity.ts index 68689c6..19d772c 100644 --- a/src/core/base/BaseItemEntity.ts +++ b/src/core/base/BaseItemEntity.ts @@ -34,10 +34,16 @@ export default abstract class BaseEntity implements EntityIf, Loadable, Carry, W } // 帮助方法:获取机械臂对象 - abstract getArmObject(): THREE.Object3D | undefined + getArmObject(): THREE.Object3D | undefined { + console.error('getArmObject 方法未实现') + return undefined + } // 帮助方法:获取机械臂立柱 - abstract getArmPillar(): THREE.Object3D | undefined + getArmPillar(): THREE.Object3D | undefined { + console.error('getArmPillar 方法未实现') + return undefined + } // 待执行任务总数 get taskCount(): number { @@ -116,7 +122,7 @@ export default abstract class BaseEntity implements EntityIf, Loadable, Carry, W } // 伸 - addArmExtender(): void { + addArmExtender(z: number = 1.3): void { this.taskQueue.add(this.createTask('ARM_EXTEND', async () => { return new Promise(resolve => { const pillar = this.getArmPillar() diff --git a/src/core/script/ModelManager.ts b/src/core/script/ModelManager.ts index 4be9969..7581562 100644 --- a/src/core/script/ModelManager.ts +++ b/src/core/script/ModelManager.ts @@ -5,6 +5,7 @@ import { getMatrixFromTf } from '@/core/ModelUtils.ts' import type { Object3DLike } from '@/types/ModelTypes.ts' import TaskManager from '../manager/TaskManager.ts' import Cl2Entity from '@/modules/cl2/Cl2Entity.ts' +import ClxEntity from '@/modules/clx/ClxEntity.ts' export default class ModelManager implements IControls, Model { private viewport: Viewport @@ -14,7 +15,7 @@ export default class ModelManager implements IControls, Model { } getClx(id: string): ClxIf { - throw new Error('Method not implemented.') + return new ClxEntity(this.viewport, id) } createTask(agv: object): TaskManager { diff --git a/src/modules/carton/CartonRenderer.ts b/src/modules/carton/CartonRenderer.ts index 3e66a83..c6ad676 100644 --- a/src/modules/carton/CartonRenderer.ts +++ b/src/modules/carton/CartonRenderer.ts @@ -3,7 +3,7 @@ import BaseRenderer from '@/core/base/BaseRenderer.ts' import Constract from '@/core/Constract.ts' import type { Object3DLike } from '@/types/ModelTypes.ts' import MODULE_GLB_File from '@/assets/Models/carton.glb?url' -import MODULE_3DS_TEX from '@/assets/Models/carton.jpg?url' +import MODULE_3DS_TEX from '@/assets/Models/carton.jpg?inline' import { loadGlbModule, loadTexture, processModel } from '@/core/ModelUtils.ts' import InstanceMeshManager from '@/core/manager/InstanceMeshManager.ts' diff --git a/src/modules/clx/Clx3dObject.ts b/src/modules/clx/Clx3dObject.ts index c1edcf4..9851c83 100644 --- a/src/modules/clx/Clx3dObject.ts +++ b/src/modules/clx/Clx3dObject.ts @@ -1,8 +1,8 @@ -import * as THREE from "three"; -import {CSG} from "three-csg-ts"; +import * as THREE from 'three' +import { CSG } from 'three-csg-ts' import gsap from 'gsap' //@ts-ignore -import {mergeGeometries} from 'three/addons/utils/BufferGeometryUtils.js' +import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js' export default class Clx3dObject extends THREE.Object3D { @@ -15,26 +15,26 @@ export default class Clx3dObject extends THREE.Object3D { const dd = 0.05 const bd = 0.175 - const shape = new THREE.Shape(); - shape.moveTo(-width/2, -depth/2 + bd); - shape.lineTo(-width/2 + bd, -depth/2); - shape.lineTo(width/2 - bd, -depth/2); - shape.lineTo(width/2, -depth/2 + bd); - - shape.lineTo(width/2, -0.285); - shape.lineTo(-0.475, -0.285); - shape.lineTo(-0.475, -0.125); - shape.lineTo(width/2, -0.125); - shape.lineTo(width/2, 0.125); - shape.lineTo(-0.475, 0.125); - shape.lineTo(-0.475, 0.285); - shape.lineTo(width/2, 0.285); - - shape.lineTo(width/2, depth/2 - bd); - shape.lineTo(width/2 - bd, depth/2); - shape.lineTo(-width/2 + bd, depth/2); - shape.lineTo(-width/2, depth/2 - bd); - shape.closePath(); // 闭合路径 + const shape = new THREE.Shape() + shape.moveTo(-width / 2, -depth / 2 + bd) + shape.lineTo(-width / 2 + bd, -depth / 2) + shape.lineTo(width / 2 - bd, -depth / 2) + shape.lineTo(width / 2, -depth / 2 + bd) + + shape.lineTo(width / 2, -0.285) + shape.lineTo(-0.475, -0.285) + shape.lineTo(-0.475, -0.125) + shape.lineTo(width / 2, -0.125) + shape.lineTo(width / 2, 0.125) + shape.lineTo(-0.475, 0.125) + shape.lineTo(-0.475, 0.285) + shape.lineTo(width / 2, 0.285) + + shape.lineTo(width / 2, depth / 2 - bd) + shape.lineTo(width / 2 - bd, depth / 2) + shape.lineTo(-width / 2 + bd, depth / 2) + shape.lineTo(-width / 2, depth / 2 - bd) + shape.closePath() // 闭合路径 // 拉伸轨迹线 const curve = new THREE.CatmullRomCurve3( @@ -52,32 +52,32 @@ export default class Clx3dObject extends THREE.Object3D { } // 创建挤出几何体 const geometry = new THREE.ExtrudeGeometry(shape, options) - const material = new THREE.MeshBasicMaterial({color: 0xffdddbca}); - const mesh = new THREE.Mesh(geometry, material); + const material = new THREE.MeshBasicMaterial({ color: 0xffdddbca }) + const mesh = new THREE.Mesh(geometry, material) mesh.updateMatrix() // 倒角 - const shapeD = new THREE.Shape(); - shapeD.moveTo(-0.02, -0.02); + const shapeD = new THREE.Shape() + shapeD.moveTo(-0.02, -0.02) shapeD.lineTo(0.02, 0.02) shapeD.lineTo(-0.02, 0.02) shapeD.closePath() - const shapeDW = new THREE.Shape(); - shapeDW.moveTo(0.02, -0.02); + const shapeDW = new THREE.Shape() + shapeDW.moveTo(0.02, -0.02) shapeDW.lineTo(0.02, 0.02) shapeDW.lineTo(-0.02, 0.02) shapeDW.closePath() - const shapeDW1 = new THREE.Shape(); - shapeDW1.moveTo(-0.02, -0.02); + const shapeDW1 = new THREE.Shape() + shapeDW1.moveTo(-0.02, -0.02) shapeDW1.lineTo(0.02, -0.02) shapeDW1.lineTo(-0.02, 0.02) shapeDW1.closePath() - const positionDs:THREE.Vector3[] = [ + const positionDs: THREE.Vector3[] = [ new THREE.Vector3(-width / 2, 0.20, -depth / 2 + bd), new THREE.Vector3(-width / 2 + bd, 0.20, -depth / 2), new THREE.Vector3(width / 2 - bd, 0.20, -depth / 2), @@ -93,7 +93,7 @@ export default class Clx3dObject extends THREE.Object3D { for (let i = 0; i < positionDs.length - 1; i++) { - const curveD = new THREE.CatmullRomCurve3([positionDs[i], positionDs[i+1]], + const curveD = new THREE.CatmullRomCurve3([positionDs[i], positionDs[i + 1]], false, 'catmullrom', 0) @@ -101,7 +101,7 @@ export default class Clx3dObject extends THREE.Object3D { steps: 1, bevelEnabled: false, extrudePath: curveD - }; + } let geometryD: THREE.BufferGeometry = null if (i == 1) { geometryD = new THREE.ExtrudeGeometry(shapeDW, optionsD) @@ -110,7 +110,7 @@ export default class Clx3dObject extends THREE.Object3D { } else { geometryD = new THREE.ExtrudeGeometry(shapeD, optionsD) } - const meshD = new THREE.Mesh(geometryD, material); + const meshD = new THREE.Mesh(geometryD, material) meshD.updateMatrix() result = CSG.subtract(result, meshD) } @@ -123,21 +123,21 @@ export default class Clx3dObject extends THREE.Object3D { const width = 0.3 const depth = 1.188 const dd = 0.05 - const shape = new THREE.Shape(); - shape.moveTo(-0.744, -0.594 + dd); - shape.lineTo(-0.744 + dd, -0.594); - shape.lineTo(-0.744 + width - dd, -0.594); - shape.lineTo(-0.744 + width, -0.594 + dd); - - shape.lineTo(-0.744 + width, -0.4); - shape.lineTo(-0.744 + width - 0.08, -0.4); - shape.lineTo(-0.744 + width - 0.08, 0.4); - shape.lineTo(-0.744 + width, 0.4); - - shape.lineTo(-0.744 + width, -0.594 + depth - dd); - shape.lineTo(-0.744 + width - dd, -0.594 + depth); - shape.lineTo(-0.744 + dd, -0.594 + depth); - shape.lineTo(-0.744, -0.594 + depth - dd); + const shape = new THREE.Shape() + shape.moveTo(-0.744, -0.594 + dd) + shape.lineTo(-0.744 + dd, -0.594) + shape.lineTo(-0.744 + width - dd, -0.594) + shape.lineTo(-0.744 + width, -0.594 + dd) + + shape.lineTo(-0.744 + width, -0.4) + shape.lineTo(-0.744 + width - 0.08, -0.4) + shape.lineTo(-0.744 + width - 0.08, 0.4) + shape.lineTo(-0.744 + width, 0.4) + + shape.lineTo(-0.744 + width, -0.594 + depth - dd) + shape.lineTo(-0.744 + width - dd, -0.594 + depth) + shape.lineTo(-0.744 + dd, -0.594 + depth) + shape.lineTo(-0.744, -0.594 + depth - dd) // shape.lineTo(-0.728, -0.594 + dd); // shape.closePath() @@ -171,24 +171,24 @@ export default class Clx3dObject extends THREE.Object3D { const dd = 0.05 const fdx = 0.06 const fdy = 0.03 - const shape = new THREE.Shape(); - - shape.moveTo(-0.744 + width - 0.08, -0.4); - shape.lineTo(-0.744 + width + 0.02, -0.4); - shape.lineTo(-0.744 + width + 0.02, -0.275); - shape.lineTo(-0.744 + width + 0.02 + 1.24 - fdx, -0.275); - shape.lineTo(-0.744 + width + 0.02 + 1.24, -0.275 + fdy); - shape.lineTo(-0.744 + width + 0.02 + 1.24, -0.135 - fdy); - shape.lineTo(-0.744 + width + 0.02 + 1.24 - fdx, -0.135); - shape.lineTo(-0.744 + width + 0.02, -0.135); - shape.lineTo(-0.744 + width + 0.02, 0.135); - shape.lineTo(-0.744 + width + 0.02 + 1.24 - fdx, 0.135); - shape.lineTo(-0.744 + width + 0.02 + 1.24, 0.135 + fdy); - shape.lineTo(-0.744 + width + 0.02 + 1.24, 0.275 - fdy); - shape.lineTo(-0.744 + width + 0.02 + 1.24 - fdx, 0.275); - shape.lineTo(-0.744 + width + 0.02, 0.275); - shape.lineTo(-0.744 + width + 0.02, 0.4); - shape.lineTo(-0.744 + width - 0.08, 0.4); + const shape = new THREE.Shape() + + shape.moveTo(-0.744 + width - 0.08, -0.4) + shape.lineTo(-0.744 + width + 0.02, -0.4) + shape.lineTo(-0.744 + width + 0.02, -0.275) + shape.lineTo(-0.744 + width + 0.02 + 1.24 - fdx, -0.275) + shape.lineTo(-0.744 + width + 0.02 + 1.24, -0.275 + fdy) + shape.lineTo(-0.744 + width + 0.02 + 1.24, -0.135 - fdy) + shape.lineTo(-0.744 + width + 0.02 + 1.24 - fdx, -0.135) + shape.lineTo(-0.744 + width + 0.02, -0.135) + shape.lineTo(-0.744 + width + 0.02, 0.135) + shape.lineTo(-0.744 + width + 0.02 + 1.24 - fdx, 0.135) + shape.lineTo(-0.744 + width + 0.02 + 1.24, 0.135 + fdy) + shape.lineTo(-0.744 + width + 0.02 + 1.24, 0.275 - fdy) + shape.lineTo(-0.744 + width + 0.02 + 1.24 - fdx, 0.275) + shape.lineTo(-0.744 + width + 0.02, 0.275) + shape.lineTo(-0.744 + width + 0.02, 0.4) + shape.lineTo(-0.744 + width - 0.08, 0.4) shape.closePath() @@ -209,17 +209,17 @@ export default class Clx3dObject extends THREE.Object3D { } // 创建挤出几何体 const geometry = new THREE.ExtrudeGeometry(shape, options) - const material = new THREE.MeshBasicMaterial({color: 0xffdddbca}); - const mesh = new THREE.Mesh(geometry, material); + const material = new THREE.MeshBasicMaterial({ color: 0xffdddbca }) + const mesh = new THREE.Mesh(geometry, material) mesh.updateMatrix() - const shapeD = new THREE.Shape(); + const shapeD = new THREE.Shape() - shapeD.moveTo(-0.744 + width + 0.02, -0.3); - shapeD.lineTo(-0.744 + width + 0.02 + 1.3, -0.3); - shapeD.lineTo(-0.744 + width + 0.02 + 1.3, 0.3); - shapeD.lineTo(-0.744 + width + 0.02, 0.3); + shapeD.moveTo(-0.744 + width + 0.02, -0.3) + shapeD.lineTo(-0.744 + width + 0.02 + 1.3, -0.3) + shapeD.lineTo(-0.744 + width + 0.02 + 1.3, 0.3) + shapeD.lineTo(-0.744 + width + 0.02, 0.3) shape.closePath() // 拉伸轨迹线 @@ -239,7 +239,7 @@ export default class Clx3dObject extends THREE.Object3D { } // 创建挤出几何体 const geometryD = new THREE.ExtrudeGeometry(shapeD, optionsD) - const meshD = new THREE.Mesh(geometryD, material); + const meshD = new THREE.Mesh(geometryD, material) meshD.updateMatrix() @@ -254,20 +254,20 @@ export default class Clx3dObject extends THREE.Object3D { const width = 0.08 const depth = 0.9 const dd = 0.02 - const shape = new THREE.Shape(); - shape.moveTo(-width/2, -depth/2 + dd); - shape.lineTo(-width/2 + dd, -depth/2); - shape.lineTo(width/2 - dd, -depth/2); - shape.lineTo(width/2, -depth/2 + dd); - shape.lineTo(width/2, depth/2 - dd); - shape.lineTo(width/2 - dd, depth/2); - shape.lineTo(-width/2 + dd, depth/2); - shape.lineTo(-width/2, depth/2 - dd); + const shape = new THREE.Shape() + shape.moveTo(-width / 2, -depth / 2 + dd) + shape.lineTo(-width / 2 + dd, -depth / 2) + shape.lineTo(width / 2 - dd, -depth / 2) + shape.lineTo(width / 2, -depth / 2 + dd) + shape.lineTo(width / 2, depth / 2 - dd) + shape.lineTo(width / 2 - dd, depth / 2) + shape.lineTo(-width / 2 + dd, depth / 2) + shape.lineTo(-width / 2, depth / 2 - dd) shape.closePath() - const shapeBar = new THREE.Shape(); - shapeBar.moveTo(0, 0); // 起点在圆心 - shapeBar.absarc(0, 0, 0.02, 0, Math.PI * 2, false); // 从0到π绘制半圆 + const shapeBar = new THREE.Shape() + shapeBar.moveTo(0, 0) // 起点在圆心 + shapeBar.absarc(0, 0, 0.02, 0, Math.PI * 2, false) // 从0到π绘制半圆 shapeBar.closePath() const geometries: THREE.BufferGeometry[] = [] @@ -337,25 +337,25 @@ export default class Clx3dObject extends THREE.Object3D { steps: 1, bevelEnabled: false, extrudePath: curveL1 - }); + }) const geometryL2 = new THREE.ExtrudeGeometry(shape, { steps: 1, bevelEnabled: false, extrudePath: curveL2 - }); + }) const geometryL3 = new THREE.ExtrudeGeometry(shape, { steps: 1, bevelEnabled: false, extrudePath: curveL3 - }); + }) const geometryL4 = new THREE.ExtrudeGeometry(shape, { steps: 1, bevelEnabled: false, extrudePath: curveL4 - }); + }) geometries.push(geometryL1, geometryL2, geometryL3, geometryL4) @@ -365,8 +365,8 @@ export default class Clx3dObject extends THREE.Object3D { private static clxPedestalGeometry: THREE.BufferGeometry = null private static clxPillarGeometry: THREE.BufferGeometry = null private static clxForkGeometry: THREE.BufferGeometry = null - private static clxGemelGeometryL: THREE.BufferGeometry = null; - private static clxGemelGeometryR: THREE.BufferGeometry = null; + private static clxGemelGeometryL: THREE.BufferGeometry = null + private static clxGemelGeometryR: THREE.BufferGeometry = null constructor(item: ItemJson, option?: RendererCudOption) { super() @@ -375,22 +375,22 @@ export default class Clx3dObject extends THREE.Object3D { Clx3dObject.clxPedestalGeometry = Clx3dObject.createClxPedestal() } const clxPedestalGeometry = Clx3dObject.clxPedestalGeometry - const clxPedestalMaterial = new THREE.MeshPhongMaterial({color: 0xffdddbca}); - const clxPedestalMesh = new THREE.Mesh(clxPedestalGeometry, clxPedestalMaterial); + const clxPedestalMaterial = new THREE.MeshPhongMaterial({ color: 0xffdddbca }) + const clxPedestalMesh = new THREE.Mesh(clxPedestalGeometry, clxPedestalMaterial) if (!Clx3dObject.clxPillarGeometry) { Clx3dObject.clxPillarGeometry = Clx3dObject.createClxPillar() } const clxPillarGeometry = Clx3dObject.clxPillarGeometry - const clxPillarMaterial = new THREE.MeshPhongMaterial({color: 0xff6c6956}); - const clxPillarMesh = new THREE.Mesh(clxPillarGeometry, clxPillarMaterial); + const clxPillarMaterial = new THREE.MeshPhongMaterial({ color: 0xff6c6956 }) + const clxPillarMesh = new THREE.Mesh(clxPillarGeometry, clxPillarMaterial) if (!Clx3dObject.clxForkGeometry) { Clx3dObject.clxForkGeometry = Clx3dObject.createClxFork() } - const clxForkGeometry = Clx3dObject.clxForkGeometry; - const clxForkMaterial = new THREE.MeshPhongMaterial({color: 0xff444444}); - const clxForkMesh = new THREE.Mesh(clxForkGeometry, clxForkMaterial); + const clxForkGeometry = Clx3dObject.clxForkGeometry + const clxForkMaterial = new THREE.MeshPhongMaterial({ color: 0xff444444 }) + const clxForkMesh = new THREE.Mesh(clxForkGeometry, clxForkMaterial) clxForkMesh.name = 'clxFork' if (!Clx3dObject.clxGemelGeometryL) { @@ -403,14 +403,14 @@ export default class Clx3dObject extends THREE.Object3D { } const clxGemelGeometryR = Clx3dObject.clxGemelGeometryR - const clxGemelMaterial = new THREE.MeshPhongMaterial({color: 0xff555555}); - const clxGemelMeshL1 = new THREE.Mesh(clxGemelGeometryL, clxGemelMaterial); + const clxGemelMaterial = new THREE.MeshPhongMaterial({ color: 0xff555555 }) + const clxGemelMeshL1 = new THREE.Mesh(clxGemelGeometryL, clxGemelMaterial) clxGemelMeshL1.name = 'clxGemelMeshL1' - const clxGemelMeshL2 = new THREE.Mesh(clxGemelGeometryL, clxGemelMaterial); + const clxGemelMeshL2 = new THREE.Mesh(clxGemelGeometryL, clxGemelMaterial) clxGemelMeshL2.name = 'clxGemelMeshL2' - const clxGemelMeshR1 = new THREE.Mesh(clxGemelGeometryR, clxGemelMaterial); + const clxGemelMeshR1 = new THREE.Mesh(clxGemelGeometryR, clxGemelMaterial) clxGemelMeshR1.name = 'clxGemelMeshR1' - const clxGemelMeshR2 = new THREE.Mesh(clxGemelGeometryR, clxGemelMaterial); + const clxGemelMeshR2 = new THREE.Mesh(clxGemelGeometryR, clxGemelMaterial) clxGemelMeshR2.name = 'clxGemelMeshR2' const d = 0 @@ -420,22 +420,22 @@ export default class Clx3dObject extends THREE.Object3D { this.add(clxForkMesh) - const ac = Math.asin(d/(2 * 0.8)) + const ac = Math.asin(d / (2 * 0.8)) - clxGemelMeshL1.position.z = 0.5 - d/4 + clxGemelMeshL1.position.z = 0.5 - d / 4 clxGemelMeshL1.position.y = 0.72 clxGemelMeshL1.rotation.x = -ac - clxGemelMeshL2.position.z = 0.5 - d/4 * 3 + clxGemelMeshL2.position.z = 0.5 - d / 4 * 3 clxGemelMeshL2.position.y = 0.72 clxGemelMeshL2.rotation.x = -ac - clxGemelMeshR1.position.z = 0.5 - d/4 + clxGemelMeshR1.position.z = 0.5 - d / 4 clxGemelMeshR1.position.y = 0.72 clxGemelMeshR1.rotation.x = ac - clxGemelMeshR2.position.z = 0.5 - d/4 * 3 + clxGemelMeshR2.position.z = 0.5 - d / 4 * 3 clxGemelMeshR2.position.y = 0.72 clxGemelMeshR2.rotation.x = ac @@ -445,7 +445,7 @@ export default class Clx3dObject extends THREE.Object3D { this.add(clxGemelMeshR2) } - animationShowFork(z: number): gsap.core.Tween { + animationShowFork(z: number): Promise { const clxFork = this.getObjectByName('clxFork') const clxGemelMeshL1 = this.getObjectByName('clxGemelMeshL1') const clxGemelMeshL2 = this.getObjectByName('clxGemelMeshL2') @@ -454,13 +454,13 @@ export default class Clx3dObject extends THREE.Object3D { const fy = clxFork.position.y - const ac = Math.asin(z/(2 * 0.8)) + const ac = Math.asin(z / (2 * 0.8)) // clxGemelMeshL1.position.z = 0.5 - z/4 // clxGemelMeshL1.position.y = fy + 0.72 // clxGemelMeshL1.rotation.x = -ac gsap.to(clxGemelMeshL1.position, { - z: 0.5 - z/4, + z: 0.5 - z / 4, y: fy + 0.72, duration: 3, repeat: 0, @@ -476,7 +476,7 @@ export default class Clx3dObject extends THREE.Object3D { // clxGemelMeshL2.position.y = fy + 0.72 // clxGemelMeshL2.rotation.x = -ac gsap.to(clxGemelMeshL2.position, { - z: 0.5 - z/4 * 3, + z: 0.5 - z / 4 * 3, y: fy + 0.72, duration: 3, repeat: 0, @@ -493,7 +493,7 @@ export default class Clx3dObject extends THREE.Object3D { // clxGemelMeshR1.position.y = fy + 0.72 // clxGemelMeshR1.rotation.x = ac gsap.to(clxGemelMeshR1.position, { - z: 0.5 - z/4, + z: 0.5 - z / 4, y: fy + 0.72, duration: 3, repeat: 0, @@ -510,7 +510,7 @@ export default class Clx3dObject extends THREE.Object3D { // clxGemelMeshR2.position.y = fy + 0.72 // clxGemelMeshR2.rotation.x = ac gsap.to(clxGemelMeshR2.position, { - z: 0.5 - z/4 * 3, + z: 0.5 - z / 4 * 3, y: fy + 0.72, duration: 3, repeat: 0, @@ -523,18 +523,23 @@ export default class Clx3dObject extends THREE.Object3D { ease: 'sine.inOut' }) - return gsap.to(clxFork.position, { - z: -z, - duration: 3, - repeat: 0, - ease: 'sine.inOut' + return new Promise(resolve => { + gsap.to(clxFork.position, { + z: -z, + duration: 3, + repeat: 0, + ease: 'sine.inOut', + onComplete: resolve + }) }) + } - animationHideFork(): gsap.core.Tween { + + animationHideFork(): Promise { return this.animationShowFork(0) } - animationUpFork(y: number): gsap.core.Tween { + animationUpFork(y: number): Promise { const clxFork = this.getObjectByName('clxFork') const clxGemelMeshL1 = this.getObjectByName('clxGemelMeshL1') const clxGemelMeshL2 = this.getObjectByName('clxGemelMeshL2') @@ -566,15 +571,18 @@ export default class Clx3dObject extends THREE.Object3D { ease: 'sine.inOut' }) - return gsap.to(clxFork.position, { - y: y, - duration: 3, - repeat: 0, - ease: 'sine.inOut' + return new Promise(resolve => { + gsap.to(clxFork.position, { + y: y, + duration: 3, + repeat: 0, + ease: 'sine.inOut', + onComplete: resolve + }) }) } - animationDownFork(): gsap.core.Tween { + animationDownFork(): Promise { return this.animationUpFork(0) } diff --git a/src/modules/clx/ClxEntity.ts b/src/modules/clx/ClxEntity.ts index c81c09a..6df043a 100644 --- a/src/modules/clx/ClxEntity.ts +++ b/src/modules/clx/ClxEntity.ts @@ -1,5 +1,93 @@ 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 '@/modules/clx/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 { + 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.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 + } + }) + })) + } + + // 卸 + 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') + } } diff --git a/src/modules/pallet/PalletRenderer.ts b/src/modules/pallet/PalletRenderer.ts index 2ae118f..0da7bb5 100644 --- a/src/modules/pallet/PalletRenderer.ts +++ b/src/modules/pallet/PalletRenderer.ts @@ -2,8 +2,8 @@ import * as THREE from 'three' import BaseRenderer from '@/core/base/BaseRenderer.ts' import Constract from '@/core/Constract.ts' import type { Object3DLike } from '@/types/ModelTypes.ts' -import MODULE_GLB_File from '@/assets/Models/Pallet.glb?url' -import MODULE_3DS_TEX from '@/assets/Models/Pallet.jpg?url' +import MODULE_PALLET_GLB from '@/assets/Models/Pallet.glb?url' +import MODULE_PALLET_TEX from '@/assets/Models/Pallet.jpg?inline' import { loadGlbModule, loadTexture, processModel } from '@/core/ModelUtils.ts' import InstanceMeshManager from '@/core/manager/InstanceMeshManager.ts' @@ -30,24 +30,24 @@ export default class PalletRenderer extends BaseRenderer { init() { return Promise.all([ super.init(), - loadGlbModule(MODULE_GLB_File), - loadTexture(MODULE_3DS_TEX) + loadGlbModule(MODULE_PALLET_GLB), + loadTexture(MODULE_PALLET_TEX) - ]).then(([_, glbGroup, cartonTexture]) => { + ]).then(([_, glbGroup, palletTexture]) => { const mesh = glbGroup.children[0] as THREE.Mesh this.palletGeometry = processModel(mesh) this.palletMaterial = new THREE.MeshPhongMaterial({ color: 0x2b5d94 }) - cartonTexture.flipY = true - cartonTexture.wrapS = THREE.RepeatWrapping - cartonTexture.wrapT = THREE.RepeatWrapping - cartonTexture.repeat.set(0.5, 0.5) + palletTexture.flipY = true + palletTexture.wrapS = THREE.RepeatWrapping + palletTexture.wrapT = THREE.RepeatWrapping + palletTexture.repeat.set(0.5, 0.5) //@ts-ignore this.palletMaterial.color.set(this.defaultUserData.color) //@ts-ignore - this.palletMaterial.normalMap = cartonTexture + this.palletMaterial.normalMap = palletTexture }) } diff --git a/src/modules/rack/RackRenderer.ts b/src/modules/rack/RackRenderer.ts index e89eb01..37c8455 100644 --- a/src/modules/rack/RackRenderer.ts +++ b/src/modules/rack/RackRenderer.ts @@ -3,8 +3,8 @@ import { BufferGeometry } from 'three' import BaseRenderer from '@/core/base/BaseRenderer.ts' import { decimalSumBy } from '@/core/ModelUtils' import Constract from '@/core/Constract.ts' -import Plastic_Rough_JPG from '@/assets/Models/Plastic_Rough.jpg' -import storageBar_PNG from '@/assets/Models/storageBar.png' +import Plastic_Rough_JPG from '@/assets/Models/Plastic_Rough.jpg?inline' +import storageBar_PNG from '@/assets/Models/storageBar.png?inline' import { Material } from 'three/src/materials/Material' import { InstancedMesh } from 'three/src/objects/InstancedMesh' //@ts-ignore diff --git a/src/modules/shuttle_rack/ShuttleRackRenderer.ts b/src/modules/shuttle_rack/ShuttleRackRenderer.ts index 7d46380..c37af08 100644 --- a/src/modules/shuttle_rack/ShuttleRackRenderer.ts +++ b/src/modules/shuttle_rack/ShuttleRackRenderer.ts @@ -3,8 +3,8 @@ import { BufferGeometry } from 'three' import BaseRenderer from '@/core/base/BaseRenderer.ts' import { decimalSumBy } from '@/core/ModelUtils' import Constract from '@/core/Constract.ts' -import Plastic_Rough_JPG from '@/assets/Models/Plastic_Rough.jpg' -import storageBar_PNG from '@/assets/Models/storageBar.png' +import Plastic_Rough_JPG from '@/assets/Models/Plastic_Rough.jpg?inline' +import storageBar_PNG from '@/assets/Models/storageBar.png?inline' import { Material } from 'three/src/materials/Material' import { InstancedMesh } from 'three/src/objects/InstancedMesh' //@ts-ignore diff --git a/src/modules/tote/ToteRenderer.ts b/src/modules/tote/ToteRenderer.ts index 4ed8e25..66b1609 100644 --- a/src/modules/tote/ToteRenderer.ts +++ b/src/modules/tote/ToteRenderer.ts @@ -3,7 +3,7 @@ import BaseRenderer from '@/core/base/BaseRenderer.ts' import Constract from '@/core/Constract.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 MODULE_3DS_TEX from '@/assets/Models/ToteTex.png?inline' import { load3DModule, loadByUrl, loadTexture, processModel } from '@/core/ModelUtils.ts' import InstanceMeshManager from '@/core/manager/InstanceMeshManager.ts' diff --git a/src/modules/way/WayRenderer.ts b/src/modules/way/WayRenderer.ts index cf1e3c9..e538f94 100644 --- a/src/modules/way/WayRenderer.ts +++ b/src/modules/way/WayRenderer.ts @@ -4,8 +4,8 @@ import MoveLinePointPng from '@/assets/images/moveline_point.png' import { createLinkPlaneMatrix4, getCargoLineId, getLinkDirection, getMatrixFromTf } from '@/core/ModelUtils.ts' import Constract from '@/core/Constract.ts' import type { Object3DLike } from '@/types/ModelTypes.ts' -import TriangleUrl from '@/assets/images/conveyor/shapes/triangle.png' -import Triangle2Url from '@/assets/images/conveyor/shapes/triangle-double.png' +import TriangleUrl from '@/assets/images/conveyor/shapes/triangle.png?inline' +import Triangle2Url from '@/assets/images/conveyor/shapes/triangle-double.png?inline' import InstanceMeshManager from '@/core/manager/InstanceMeshManager.ts' /**