diff --git a/src/components/InteractiveObjects/InteractiveObject.js b/src/components/InteractiveObjects/InteractiveObject.js index 09f7f3e..452bd4d 100644 --- a/src/components/InteractiveObjects/InteractiveObject.js +++ b/src/components/InteractiveObjects/InteractiveObject.js @@ -81,6 +81,8 @@ class InteractiveObject extends EventManager{ this.object = engine.meshUtils.wrapInGroup(this.object) this.activator = new (obj.activationType == 'unlock' ? LockActivator : VisibilityActivator)(engine, this.object); this.activator.deactivate(); + }else{ + this.object.dispatchEvent({type: 'io-activate'}) } engine.meshUtils.assignParams(this.object, obj); if (obj.motion){ @@ -107,10 +109,12 @@ class VisibilityActivator{ this.deactivate = function(){ group.visible = false; group.__active = false; + group.dispatchEvent({type: 'io-deactivate'}) } this.activate = function(){ group.visible = true; group.__active = true; + group.dispatchEvent({type: 'io-activate'}) } this.isActive = function(){ return group.__active; @@ -143,11 +147,13 @@ class LockActivator{ engine.motionQueue.clear(bckMesh); group.__active = false; animate(); + group.dispatchEvent({type: 'io-deactivate'}) } this.activate = function(){ bckMesh.visible = false; engine.motionQueue.clear(bckMesh); group.__active = true; + group.dispatchEvent({type: 'io-activate'}) } this.isActive = function(){ return group.__active; diff --git a/src/components/InteractiveObjects/SceneSwitcher.js b/src/components/InteractiveObjects/SceneSwitcher.js index e7b27ae..e662a03 100644 --- a/src/components/InteractiveObjects/SceneSwitcher.js +++ b/src/components/InteractiveObjects/SceneSwitcher.js @@ -7,7 +7,6 @@ class SceneSwitcher extends EventManager{ super(); return new Promise(async(resolve, reject)=>{ this.source = this; - this.object = new Group() if (data.switchType == 'award'){ let gltf = await engine.load('trophy.glb', '/static/meshes/scene-switcher/'); let awards = {}; @@ -15,10 +14,15 @@ class SceneSwitcher extends EventManager{ awards[o.name] = o; o.position.multiplyScalar(0); }) - this.object.add(awards.silver); - engine.motionQueue.add({ - o: awards.silver, - a:{rotation: { y: k=>k*Math.PI*2 }}, r: true, t: 4 + this.object = engine.meshUtils.wrapInGroup(awards.silver); + this.object.addEventListener('io-activate', ()=>{ + engine.motionQueue.add({ + o: this.object, + a:{rotation: { y: k=>k*Math.PI*2 }}, r: true, t: 4 + }) + }) + this.object.addEventListener('io-deactivate', ()=>{ + engine.motionQueue.clear(this.object, true) }) }else if(data.switchType == 'sphere'){ let geo = new SphereGeometry(1); @@ -27,7 +31,16 @@ class SceneSwitcher extends EventManager{ }) let sphere = new Mesh(geo, material); sphere.position.y = 0.5; - this.object.add(sphere); + this.object = engine.meshUtils.wrapInGroup(sphere); + this.object.addEventListener('io-activate', ()=>{ + engine.motionQueue.add({ + o: this.object, + a:{ scale: (k,s)=>s.setScalar(1+0.05*Math.sin(4*k*Math.PI)) }, r: true, t: 4 + }) + }) + this.object.addEventListener('io-deactivate', ()=>{ + engine.motionQueue.clear(this.object, true) + }) }else{ //sensor, TODO!!!, to be implemented }