diff --git a/app/controllers/dashboard/DashboardsController.js b/app/controllers/dashboard/DashboardsController.js index 65042af..d2608e7 100644 --- a/app/controllers/dashboard/DashboardsController.js +++ b/app/controllers/dashboard/DashboardsController.js @@ -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({ diff --git a/app/thirdparty/Threetobus/threetobus.module.js b/app/thirdparty/Threetobus/threetobus.module.js index 2f18f3e..60d539d 100644 --- a/app/thirdparty/Threetobus/threetobus.module.js +++ b/app/thirdparty/Threetobus/threetobus.module.js @@ -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() } }