#72 dispatch activation events in order to save redundant animations
This commit is contained in:
@@ -81,6 +81,8 @@ class InteractiveObject extends EventManager{
|
|||||||
this.object = engine.meshUtils.wrapInGroup(this.object)
|
this.object = engine.meshUtils.wrapInGroup(this.object)
|
||||||
this.activator = new (obj.activationType == 'unlock' ? LockActivator : VisibilityActivator)(engine, this.object);
|
this.activator = new (obj.activationType == 'unlock' ? LockActivator : VisibilityActivator)(engine, this.object);
|
||||||
this.activator.deactivate();
|
this.activator.deactivate();
|
||||||
|
}else{
|
||||||
|
this.object.dispatchEvent({type: 'io-activate'})
|
||||||
}
|
}
|
||||||
engine.meshUtils.assignParams(this.object, obj);
|
engine.meshUtils.assignParams(this.object, obj);
|
||||||
if (obj.motion){
|
if (obj.motion){
|
||||||
@@ -107,10 +109,12 @@ class VisibilityActivator{
|
|||||||
this.deactivate = function(){
|
this.deactivate = function(){
|
||||||
group.visible = false;
|
group.visible = false;
|
||||||
group.__active = false;
|
group.__active = false;
|
||||||
|
group.dispatchEvent({type: 'io-deactivate'})
|
||||||
}
|
}
|
||||||
this.activate = function(){
|
this.activate = function(){
|
||||||
group.visible = true;
|
group.visible = true;
|
||||||
group.__active = true;
|
group.__active = true;
|
||||||
|
group.dispatchEvent({type: 'io-activate'})
|
||||||
}
|
}
|
||||||
this.isActive = function(){
|
this.isActive = function(){
|
||||||
return group.__active;
|
return group.__active;
|
||||||
@@ -143,11 +147,13 @@ class LockActivator{
|
|||||||
engine.motionQueue.clear(bckMesh);
|
engine.motionQueue.clear(bckMesh);
|
||||||
group.__active = false;
|
group.__active = false;
|
||||||
animate();
|
animate();
|
||||||
|
group.dispatchEvent({type: 'io-deactivate'})
|
||||||
}
|
}
|
||||||
this.activate = function(){
|
this.activate = function(){
|
||||||
bckMesh.visible = false;
|
bckMesh.visible = false;
|
||||||
engine.motionQueue.clear(bckMesh);
|
engine.motionQueue.clear(bckMesh);
|
||||||
group.__active = true;
|
group.__active = true;
|
||||||
|
group.dispatchEvent({type: 'io-activate'})
|
||||||
}
|
}
|
||||||
this.isActive = function(){
|
this.isActive = function(){
|
||||||
return group.__active;
|
return group.__active;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ class SceneSwitcher extends EventManager{
|
|||||||
super();
|
super();
|
||||||
return new Promise(async(resolve, reject)=>{
|
return new Promise(async(resolve, reject)=>{
|
||||||
this.source = this;
|
this.source = this;
|
||||||
this.object = new Group()
|
|
||||||
if (data.switchType == 'award'){
|
if (data.switchType == 'award'){
|
||||||
let gltf = await engine.load('trophy.glb', '/static/meshes/scene-switcher/');
|
let gltf = await engine.load('trophy.glb', '/static/meshes/scene-switcher/');
|
||||||
let awards = {};
|
let awards = {};
|
||||||
@@ -15,11 +14,16 @@ class SceneSwitcher extends EventManager{
|
|||||||
awards[o.name] = o;
|
awards[o.name] = o;
|
||||||
o.position.multiplyScalar(0);
|
o.position.multiplyScalar(0);
|
||||||
})
|
})
|
||||||
this.object.add(awards.silver);
|
this.object = engine.meshUtils.wrapInGroup(awards.silver);
|
||||||
|
this.object.addEventListener('io-activate', ()=>{
|
||||||
engine.motionQueue.add({
|
engine.motionQueue.add({
|
||||||
o: awards.silver,
|
o: this.object,
|
||||||
a:{rotation: { y: k=>k*Math.PI*2 }}, r: true, t: 4
|
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'){
|
}else if(data.switchType == 'sphere'){
|
||||||
let geo = new SphereGeometry(1);
|
let geo = new SphereGeometry(1);
|
||||||
let material = new MeshStandardMaterial({
|
let material = new MeshStandardMaterial({
|
||||||
@@ -27,7 +31,16 @@ class SceneSwitcher extends EventManager{
|
|||||||
})
|
})
|
||||||
let sphere = new Mesh(geo, material);
|
let sphere = new Mesh(geo, material);
|
||||||
sphere.position.y = 0.5;
|
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{
|
}else{
|
||||||
//sensor, TODO!!!, to be implemented
|
//sensor, TODO!!!, to be implemented
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user