particles become only instances
parent
abc78b2993
commit
60491aa240
|
@ -128,28 +128,31 @@ GameLib.D3.ParticleEngine.prototype.updateInstance = function(property) {
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.ParticleEngine.prototype.processParticles = function(delta) {
|
GameLib.D3.ParticleEngine.prototype.processParticles = function(delta) {
|
||||||
this.particles.map(
|
this.particles = this.particles.reduce(
|
||||||
function(particle){
|
function(result, particle){
|
||||||
|
|
||||||
particle.mesh.position.x += particle.direction.x * delta;
|
particle.position.x += particle.userData.direction.x * delta;
|
||||||
particle.mesh.position.y += particle.direction.y * delta;
|
particle.position.y += particle.userData.direction.y * delta;
|
||||||
particle.mesh.position.z += particle.direction.z * delta;
|
particle.position.z += particle.userData.direction.z * delta;
|
||||||
particle.mesh.updateInstancePosition();
|
|
||||||
|
|
||||||
particle.elapsed += delta;
|
particle.userData.elapsed += delta;
|
||||||
if (particle.elapsed > particle.lifeTime) {
|
if (particle.userData.elapsed > particle.userData.lifeTime) {
|
||||||
GameLib.Event.Emit(
|
particle.parent.remove(particle);
|
||||||
GameLib.Event.REMOVE_COMPONENT,
|
} else {
|
||||||
{
|
result.push(particle);
|
||||||
component: particle
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.ParticleEngine.prototype.createNewParticle = function(delta) {
|
GameLib.D3.ParticleEngine.prototype.createNewParticle = function(camera) {
|
||||||
|
|
||||||
|
var particle = this.templateParticle.clone(camera);
|
||||||
|
|
||||||
|
this.particles.push(particle);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ GameLib.D3.Particle.prototype.createInstance = function() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.instance = true;
|
this.instance = this.mesh.instance;
|
||||||
|
|
||||||
GameLib.Component.prototype.createInstance.call(this);
|
GameLib.Component.prototype.createInstance.call(this);
|
||||||
};
|
};
|
||||||
|
@ -148,6 +148,27 @@ GameLib.D3.Particle.prototype.updateInstance = function(property) {
|
||||||
console.log('Update Particle Property : ' + property);
|
console.log('Update Particle Property : ' + property);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clones a particle - this only clones 3rd party instances, so we have less overhead of creating these types of objects
|
||||||
|
*/
|
||||||
|
GameLib.D3.Particle.prototype.clone = function(camera) {
|
||||||
|
|
||||||
|
var position = camera.instance.position.clone();
|
||||||
|
var lookAt = camera.lookAt.instance.clone();
|
||||||
|
|
||||||
|
var direction = lookAt.sub(position).negate();
|
||||||
|
|
||||||
|
var instance = this.instance.clone();
|
||||||
|
instance.lookAt(direction);
|
||||||
|
|
||||||
|
instance.userData.direction = this.direction.instance;
|
||||||
|
instance.userData.elapsed = 0;
|
||||||
|
instance.userData.lifeTime = this.lifeTime;
|
||||||
|
this.mesh.parentScene.instance.add(instance);
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a GameLib.D3.Particle to a new GameLib.D3.API.Particle
|
* Converts a GameLib.D3.Particle to a new GameLib.D3.API.Particle
|
||||||
* @returns {GameLib.D3.API.Particle}
|
* @returns {GameLib.D3.API.Particle}
|
||||||
|
|
|
@ -44,18 +44,11 @@ GameLib.System.Particle.prototype.start = function() {
|
||||||
|
|
||||||
this.particleEngines = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.ParticleEngine);
|
this.particleEngines = GameLib.EntityManager.Instance.queryComponents(GameLib.D3.ParticleEngine);
|
||||||
|
|
||||||
//this.camera = GameLib.EntityManager.Instance.defaultRenderer.camera;
|
|
||||||
|
|
||||||
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
|
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
|
||||||
GameLib.Event.INSTANCE_CREATED,
|
GameLib.Event.INSTANCE_CREATED,
|
||||||
this.instanceCreated.bind(this)
|
this.instanceCreated.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
// this.instanceUpdatedSubscription = GameLib.Event.Subscribe(
|
|
||||||
// GameLib.Event.PARTICLE_INSTANCE_UPDATED,
|
|
||||||
// this.instanceUpdated.bind(this)
|
|
||||||
// );
|
|
||||||
|
|
||||||
this.removeComponentSubscription = GameLib.Event.Subscribe(
|
this.removeComponentSubscription = GameLib.Event.Subscribe(
|
||||||
GameLib.Event.REMOVE_COMPONENT,
|
GameLib.Event.REMOVE_COMPONENT,
|
||||||
this.removeComponent.bind(this)
|
this.removeComponent.bind(this)
|
||||||
|
@ -81,10 +74,6 @@ GameLib.System.Particle.prototype.instanceCreated = function(data) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.System.Particle.prototype.instanceUpdated = function(data) {
|
|
||||||
// console.log('particle engine updated : ' + data.component.name);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a particle engine from this system
|
* Removes a particle engine from this system
|
||||||
* @param data
|
* @param data
|
||||||
|
@ -125,24 +114,10 @@ GameLib.System.Particle.prototype.beforeRender = function(data) {
|
||||||
|
|
||||||
if (particleEngine.elapsed > particleEngine.frequency) {
|
if (particleEngine.elapsed > particleEngine.frequency) {
|
||||||
particleEngine.elapsed = 0;
|
particleEngine.elapsed = 0;
|
||||||
particleEngine.createNewParticle();
|
particleEngine.createNewParticle(this.camera);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// var position = this.camera.position.instance.clone();
|
|
||||||
// var lookAt = this.camera.lookAt.instance.clone();
|
|
||||||
//
|
|
||||||
// var direction = lookAt.sub(position).negate();
|
|
||||||
//
|
|
||||||
// particleEngine.lookAt.setFrom(direction);
|
|
||||||
// particleEngine.updateInstance('lookAt');
|
|
||||||
|
|
||||||
|
|
||||||
// if (particleEngine.elapsed > particleEngine.frequency) {
|
|
||||||
// particleEngine.elapsed = 0;
|
|
||||||
// console.log('change time');
|
|
||||||
// }
|
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -157,7 +132,6 @@ GameLib.System.Particle.prototype.stop = function() {
|
||||||
GameLib.System.prototype.stop.call(this);
|
GameLib.System.prototype.stop.call(this);
|
||||||
|
|
||||||
this.instanceCreatedSubscription.remove();
|
this.instanceCreatedSubscription.remove();
|
||||||
// this.instanceUpdatedSubscription.remove();
|
|
||||||
this.removeComponentSubscription.remove();
|
this.removeComponentSubscription.remove();
|
||||||
this.beforeRenderSubscription.remove();
|
this.beforeRenderSubscription.remove();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue