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.
 
 
 

136 lines
3.9 KiB

import * as THREE from 'three'
import {CSG} from 'three-csg-ts'
import gsap from 'gsap'
import mqtt from 'mqtt'
import {Euler} from 'three/src/math/Euler'
import Cl2Entity from '@/modules/amr/ptr/cl2/Cl2Entity'
import Cl23DGraphics from "@/modules/amr/ptr/cl2/Cl23DGraphics"
import PtrObject from "../PtrObject";
import Viewport from "@/core/engine/Viewport";
export default class Cl23dObject extends PtrObject {
private _cl2Entity: Cl2Entity = null
override rotationSpeed = (Math.PI / 7)
override showForkSpeed: number = 0.15
override upForkSpeed: number = 0.15
public get cl2Entity(): Cl2Entity {
if (!this._cl2Entity) {
const cl2: Cl2Entity = Model.getCl2(this.item.id) as Cl2Entity
this._cl2Entity = cl2
}
return this._cl2Entity
}
constructor(item: ItemJson, viewport: Viewport, option?: RendererCudOption) {
super(item, viewport)
if (!Cl23DGraphics.ptrPedestalGeometry) {
Cl23DGraphics.ptrPedestalGeometry = Cl23DGraphics.createPtrPedestal()
}
const ptrPedestalGeometry = Cl23DGraphics.ptrPedestalGeometry
const ptrPedestalMaterial = new THREE.MeshPhongMaterial({color: 0xffdddbca})
const ptrPedestalMesh = new THREE.Mesh(ptrPedestalGeometry, ptrPedestalMaterial)
ptrPedestalMesh.name = 'ptrPedestal'
if (!Cl23DGraphics.ptrPillarGeometry) {
Cl23DGraphics.ptrPillarGeometry = Cl23DGraphics.createPtrPillar()
}
const ptrPillarGeometry = Cl23DGraphics.ptrPillarGeometry
const ptrPillarMaterial = new THREE.MeshPhongMaterial({color: 0xff6c6956})
const ptrPillarMesh = new THREE.Mesh(ptrPillarGeometry, ptrPillarMaterial)
if (!Cl23DGraphics.ptrForkGeometry) {
Cl23DGraphics.ptrForkGeometry = Cl23DGraphics.createPtrFork()
}
const ptrForkGeometry = Cl23DGraphics.ptrForkGeometry
const ptrForkMaterial = new THREE.MeshPhongMaterial({color: 0xff444444})
const ptrForkMesh = new THREE.Mesh(ptrForkGeometry, ptrForkMaterial)
ptrForkMesh.name = 'ptrFork'
this.add(ptrPedestalMesh)
const groupPillar = new THREE.Group()
groupPillar.name = 'ptrPillar'
groupPillar.add(ptrPillarMesh)
groupPillar.add(ptrForkMesh)
this.add(groupPillar)
}
/*==========动画处理============*/
override animationShowFork(z: number): Promise<void> {
const ptrPillar = this.getObjectByName('ptrPillar')
const time = Math.abs(z/ this.showForkSpeed)
return new Promise(resolve => {
this.actionAnimation = gsap.to(ptrPillar.position, {
z: -z,
duration: time,
repeat: 0,
ease: 'sine.inOut',
onComplete: ()=>{
setTimeout(() => {
resolve()
}, 1000)
},
})
})
}
override animationHideFork(): Promise<void> {
return this.animationShowFork(0)
}
override animationUpFork(y: number): Promise<void> {
const ptrFork = this.getObjectByName('ptrFork')
const ptrPillar = this.getObjectByName('ptrPillar')
const pz = ptrPillar.position.z
const time = Math.abs((ptrFork.position.y - y) / this.upForkSpeed)
return new Promise(resolve => {
const bh = 0.22
const children = ptrFork.children
this.actionAnimation = gsap.to(ptrFork.position, {
y: y,
duration: time,
repeat: 0,
ease: 'sine.inOut',
onComplete: ()=>{
setTimeout(() => {
resolve()
}, 1000)
},
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 = bh - a.y
}
} else if (a.y < 0) {
for (let i = 0; i < children.length; i++) {
const child = children[i]
child.position.y = 0 - a.y
}
}
}
}
})
})
}
override animationDownFork(): Promise<void> {
return this.animationUpFork(0)
}
}