cancelling tweens

This commit is contained in:
STEINNI
2025-09-29 19:28:18 +00:00
parent e4ac2a8dc0
commit 7a50311fcd
2 changed files with 8 additions and 4 deletions
@@ -22,7 +22,7 @@ class DashboardsController extends EICController {
grid: true,
})
const m1 = ttb.buildFromJSON('agent42', this.agentDefs.molecule1)
const m1 = ttb.agentFromJSON('agent42', this.agentDefs.molecule1)
ttb.scene.add(m1)
// setTimeout(() => {
// ttb.smoothMove({
+7 -3
View File
@@ -11,6 +11,7 @@ export class Threetobus{
this.cameras = {}
this.renderers = []
this.tweensRegistry = {}
}
get EventsMapping() { return this._stagedEventsMapping }
@@ -185,7 +186,7 @@ export class Threetobus{
}
buildFromJSON(id, desc){
agentFromJSON(id, desc){
let obj
if(desc.type === 'Mesh') {
const geom = new THREE[desc.geometry.type](...(desc.geometry.args || []))
@@ -206,10 +207,11 @@ export class Threetobus{
if(desc.children) {
desc.children.forEach(childDesc => {
const childId = (childDesc.idSuffix) ? `${id}_${childDesc.idSuffix}` : ''
obj.add(this.buildFromJSON(childId, childDesc))
obj.add(this.agentFromJSON(childId, childDesc))
})
}
obj.name = id
this.tweensRegistry[id] = { 'move': null }
return obj
}
@@ -237,12 +239,14 @@ export class Threetobus{
newZ = isNaN(newZ) ? options.object.position.z : newZ
newZ += (parseFloat(options.dz) || 0)
new TWEEN.Tween(options.object.position)
if(this.tweensRegistry[options.object.name]['move']) this.tweensRegistry[options.object.name]['move'].end()
this.tweensRegistry[options.object.name]['move'] = new TWEEN.Tween(options.object.position)
.to({ x: newX,
y: newY,
z: newZ,
}, options.delay)
.easing(TWEEN.Easing[options.easing][options.easingMode])
.onComplete(() => this.tweensRegistry[options.object.name]['move']=null)
.start()
}
}