Skip to content
Browse files

new rebuild for sshachtleben

  • Loading branch information...
1 parent 14796c6 commit eae2c2ae0515ab5c56fb59fcee89a652e04b88e3 @jeromeetienne committed Jul 6, 2012
Showing with 734 additions and 74 deletions.
  1. +659 −52 build/fireworks-bundle.js
  2. +24 −8 build/fireworks-bundle.min.js
  3. +44 −8 build/fireworks.js
  4. +7 −6 build/fireworks.min.js
View
711 build/fireworks-bundle.js
@@ -8,6 +8,7 @@ Fireworks.Emitter = function(opts){
this._particles = [];
this._spawner = null;
this._effects = [];
+ this._started = false;
this._onUpdated = null;
}
@@ -39,29 +40,23 @@ Fireworks.Emitter.prototype.liveParticles = function(){
Fireworks.Emitter.prototype.deadParticles = function(){
return this._deadParticles;
}
+Fireworks.Emitter.prototype.nParticles = function(){
+ return this._nParticles;
+}
-//////////////////////////////////////////////////////////////////////////////////
-// configuration helper //
-// TODO put that elsewhere.. in each plugins ?? //
-//////////////////////////////////////////////////////////////////////////////////
-
-Fireworks.Emitter.prototype.addEffectBase = function(){
- var emitter = this;
- var effect = new Fireworks.EffectBase(emitter);
- this._effects.push( effect );
+Fireworks.Emitter.prototype.setSpawner = function(spawner){
+ this._spawner = spawner;
return this; // for chained API
}
-Fireworks.Emitter.prototype.addEffectAge = function(){
- var emitter = this;
- var effect = new Fireworks.EffectAge(emitter);
- this._effects.push( effect );
- return this; // for chained API
+
+Fireworks.Emitter.prototype.setParticleData = function(particle, namespace, value){
+ particle[namespace] = value;
}
-Fireworks.Emitter.prototype.setSpawnerRate = function(){
- this._spawner = new Fireworks.SpawnerRate();
- return this; // for chained API
+Fireworks.Emitter.prototype.getParticleData = function(particle, namespace){
+ console.assert( particle[namespace] !== undefined, "namespace undefined: "+namespace );
+ return particle[namespace];
}
//////////////////////////////////////////////////////////////////////////////////
@@ -72,6 +67,7 @@ Fireworks.Emitter.prototype.start = function()
{
console.assert( this._spawner, "a spawner MUST be set" );
console.assert( this._effects.length > 0, "Some effects MUST be set")
+ console.assert( this._started === false );
this._particles = new Array(this._nParticles);
for(var i = 0; i < this._nParticles; i++){
@@ -85,8 +81,8 @@ Fireworks.Emitter.prototype.start = function()
// onCreate on all particles
this._effects.forEach(function(effect){
if( !effect.onCreate ) return;
- this._particles.forEach(function(particle){
- effect.onCreate(particle);
+ this._particles.forEach(function(particle, particleIdx){
+ effect.onCreate(particle, particleIdx);
})
}.bind(this));
@@ -103,6 +99,21 @@ Fireworks.Emitter.prototype.update = function(deltaTime){
effect.onUpdate(particle, deltaTime);
})
}.bind(this));
+ return this; // for chained API
+}
+
+Fireworks.Emitter.prototype.render = function(){
+ this._effects.forEach(function(effect){
+ if( !effect.onPreRender ) return;
+ effect.onPreRender();
+ }.bind(this));
+ this._effects.forEach(function(effect){
+ if( !effect.onRender ) return;
+ this._liveParticles.forEach(function(particle){
+ effect.onRender(particle);
+ })
+ }.bind(this));
+ return this; // for chained API
}
//////////////////////////////////////////////////////////////////////////////////
@@ -119,7 +130,7 @@ Fireworks.Emitter.prototype.killParticle = function(particle)
this._liveParticles.splice(idx, 1)
this._deadParticles.push(particle);
// do the death on all effects
- emitter.effects().forEach(function(effect){
+ this.effects().forEach(function(effect){
effect.onDeath && effect.onDeath(particle);
}.bind(this));
}
@@ -129,10 +140,10 @@ Fireworks.Emitter.prototype.killParticle = function(particle)
*/
Fireworks.Emitter.prototype.spawnParticle = function(){
// change the particles
- var particle = emitter.deadParticles().pop();
- emitter.liveParticles().push(particle);
+ var particle = this.deadParticles().pop();
+ this.liveParticles().push(particle);
// do the birth on all effects
- emitter.effects().forEach(function(effect){
+ this.effects().forEach(function(effect){
effect.onBirth && effect.onBirth(particle);
}.bind(this));
}
@@ -144,35 +155,405 @@ Fireworks.Spawner = function(){
Fireworks.Particle = function(){
}
/**
+ * Basic Fireworks.Effect builder
+*/
+Fireworks.createEffect = function(name, opts){
+ // handle polymophism
+ if( typeof(name) === 'object' ){
+ opts = name;
+ name = undefined;
+ }
+ console.log("createEffect", name, opts)
+
+ var effect = new Fireworks.Effect();
+ effect.opts = opts;
+ effect.name = name;
+ var methods = {
+ onCreate: function(val){
+ effect.onCreate = val;
+ return methods;
+ },
+ onBirth: function(val){
+ effect.onBirth = val;
+ return methods;
+ },
+ onUpdate: function(val){
+ effect.onUpdate = val;
+ return methods;
+ },
+ onDeath: function(val){
+ effect.onDeath = val;
+ return methods;
+ },
+ onPreRender: function(val){
+ effect.onPreRender = val;
+ return methods;
+ },
+ onRender: function(val){
+ effect.onRender = val;
+ return methods;
+ },
+ pushTo : function(emitter){
+ emitter.effects().push(effect);
+ return methods;
+ },
+ effect : function(){
+ return effect;
+ }
+ }
+ return methods;
+}
+
+/**
* An effect to apply on particles
*/
Fireworks.Effect = function(){
}
-//Firefly.Effect.prototype.onCreate = function(){
+/**
+ * Callback called on particle creation
+*/
+//Fireworks.Effect.prototype.onCreate = function(){
+//}
+//
+/**
+ * Callback called when a particle is spawning
+ *
+ * TODO to rename onSpawn
+*/
+//Fireworks.Effect.prototype.onBirth = function(){
//}
//
-//Firefly.Effect.prototype.onBirth = function(){
+//Fireworks.Effect.prototype.onDeath = function(){
//}
//
-//Firefly.Effect.prototype.onDeath = function(){
+//Fireworks.Effect.prototype.onUpdate = function(){
+//}
+
+Fireworks.Shape = function(){
+}
+
+///**
+// * @param {Fireworks.Vector} point the point coordinate to test
+// * @returns {Boolean} true if point is inside the shape, false otherwise
+//*/
+//Fireworks.Shape.prototype.contains = function(point){
//}
//
-//Firefly.Effect.prototype.onUpdate = function(){
+///**
+// * generate a random point contained in this shape
+// * @returns {Fireworks.Vector} the just generated random point
+//*/
+//Firefly.Shape.prototype.randomPoint = function(){
//}
-Fireworks.EffectAge = function(emitter)
+/**
+ * jme- copy of THREE.Vector3 https://github.com/mrdoob/three.js/blob/master/src/core/Vector3.js
+ *
+ * @author mr.doob / http://mrdoob.com/
+ * @author kile / http://kile.stravaganza.org/
+ * @author philogb / http://blog.thejit.org/
+ * @author mikael emtinger / http://gomo.se/
+ * @author egraether / http://egraether.com/
+ */
+
+Fireworks.Vector = function ( x, y, z ) {
+
+ this.x = x || 0;
+ this.y = y || 0;
+ this.z = z || 0;
+
+};
+
+
+Fireworks.Vector.prototype = {
+
+ constructor: Fireworks.Vector,
+
+ set: function ( x, y, z ) {
+
+ this.x = x;
+ this.y = y;
+ this.z = z;
+
+ return this;
+
+ },
+
+ setX: function ( x ) {
+
+ this.x = x;
+
+ return this;
+
+ },
+
+ setY: function ( y ) {
+
+ this.y = y;
+
+ return this;
+
+ },
+
+ setZ: function ( z ) {
+
+ this.z = z;
+
+ return this;
+
+ },
+
+ random : function( ) {
+ this.x = Math.random() - 0.5;
+ this.y = Math.random() - 0.5;
+ this.z = Math.random() - 0.5;
+ return this;
+ }, // jme - added
+
+ toString : function(){
+ return JSON.stringify(this);
+ }, // jme - added
+
+ copy: function ( v ) {
+
+ this.x = v.x;
+ this.y = v.y;
+ this.z = v.z;
+
+ return this;
+
+ },
+
+ add: function ( a, b ) {
+
+ this.x = a.x + b.x;
+ this.y = a.y + b.y;
+ this.z = a.z + b.z;
+
+ return this;
+
+ },
+
+ addSelf: function ( v ) {
+
+ this.x += v.x;
+ this.y += v.y;
+ this.z += v.z;
+
+ return this;
+
+ },
+
+ addScalar: function ( s ) {
+
+ this.x += s;
+ this.y += s;
+ this.z += s;
+
+ return this;
+
+ },
+
+ sub: function ( a, b ) {
+
+ this.x = a.x - b.x;
+ this.y = a.y - b.y;
+ this.z = a.z - b.z;
+
+ return this;
+
+ },
+
+ subSelf: function ( v ) {
+
+ this.x -= v.x;
+ this.y -= v.y;
+ this.z -= v.z;
+
+ return this;
+
+ },
+
+ multiply: function ( a, b ) {
+
+ this.x = a.x * b.x;
+ this.y = a.y * b.y;
+ this.z = a.z * b.z;
+
+ return this;
+
+ },
+
+ multiplySelf: function ( v ) {
+
+ this.x *= v.x;
+ this.y *= v.y;
+ this.z *= v.z;
+
+ return this;
+
+ },
+
+ multiplyScalar: function ( s ) {
+
+ this.x *= s;
+ this.y *= s;
+ this.z *= s;
+
+ return this;
+
+ },
+
+ divideSelf: function ( v ) {
+
+ this.x /= v.x;
+ this.y /= v.y;
+ this.z /= v.z;
+
+ return this;
+
+ },
+
+ divideScalar: function ( s ) {
+
+ if ( s ) {
+
+ this.x /= s;
+ this.y /= s;
+ this.z /= s;
+
+ } else {
+
+ this.x = 0;
+ this.y = 0;
+ this.z = 0;
+
+ }
+
+ return this;
+
+ },
+
+
+ negate: function() {
+
+ return this.multiplyScalar( - 1 );
+
+ },
+
+ dot: function ( v ) {
+
+ return this.x * v.x + this.y * v.y + this.z * v.z;
+
+ },
+
+ lengthSq: function () {
+
+ return this.x * this.x + this.y * this.y + this.z * this.z;
+
+ },
+
+ length: function () {
+
+ return Math.sqrt( this.lengthSq() );
+
+ },
+
+ normalize: function () {
+
+ return this.divideScalar( this.length() );
+
+ },
+
+ setLength: function ( l ) {
+
+ return this.normalize().multiplyScalar( l );
+
+ },
+
+ cross: function ( a, b ) {
+
+ this.x = a.y * b.z - a.z * b.y;
+ this.y = a.z * b.x - a.x * b.z;
+ this.z = a.x * b.y - a.y * b.x;
+
+ return this;
+
+ },
+
+ crossSelf: function ( v ) {
+
+ var x = this.x, y = this.y, z = this.z;
+
+ this.x = y * v.z - z * v.y;
+ this.y = z * v.x - x * v.z;
+ this.z = x * v.y - y * v.x;
+
+ return this;
+
+ },
+
+ distanceTo: function ( v ) {
+
+ return Math.sqrt( this.distanceToSquared( v ) );
+
+ },
+
+ distanceToSquared: function ( v ) {
+
+ return new Fireworks.Vector().sub( this, v ).lengthSq();
+
+ },
+
+ equals: function ( v ) {
+
+ return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
+
+ },
+
+ isZero: function () {
+
+ return ( this.lengthSq() < 0.0001 /* almostZero */ );
+
+ },
+
+ clone: function () {
+
+ return new Fireworks.Vector( this.x, this.y, this.z );
+
+ }
+
+};
+/**
+ * Shortcut to create Fireworks.EffectAge
+*/
+Fireworks.Emitter.prototype.pushAge = function(minAge, maxAge){
+ var emitter = this;
+ if( arguments.length === 1 ){
+ minAge = minAge;
+ maxAge = minAge;
+ }
+ emitter.effects().push(new Fireworks.EffectAge(emitter, minAge, maxAge));
+ return this; // for chained API
+};
+
+
+Fireworks.EffectAge = function(emitter, minAge, maxAge)
{
+ console.assert( minAge !== undefined )
+ console.assert( maxAge !== undefined )
this.onCreate = function(particle){
particle.xAge = {
curAge : 0,
+ minAge : 0,
maxAge : 0
};
}.bind(this);
this.onBirth = function(particle){
var ctx = particle.xAge;
ctx.curAge = 0;
- ctx.maxAge = 1;
+ ctx.maxAge = minAge + Math.random()*(maxAge-minAge);
}.bind(this);
this.onUpdate = function(particle, deltaTime){
@@ -185,37 +566,60 @@ Fireworks.EffectAge = function(emitter)
// inherit from Fireworks.Effect
Fireworks.EffectAge.prototype = new Fireworks.Effect();
Fireworks.EffectAge.prototype.constructor = Fireworks.EffectAge;
+Fireworks.Effect.ApplyForce = function(emitter, opts)
+{
+ this.onUpdate = function(particle){
+ var xBase = emitter.getParticleData(particle, 'xBase')
+ xBase.position.addSelf(opts.vector);
+ }.bind(this);
+}
+
+// inherit from Fireworks.Effect
+Fireworks.Effect.ApplyForce.prototype = new Fireworks.Effect();
+Fireworks.Effect.ApplyForce.prototype.constructor = Fireworks.Effect.ApplyForce;
+
+
+/**
+ * Shortcut to create Fireworks.EffectBase
+*/
+Fireworks.Emitter.prototype.pushBase = function(maxAge){
+ var emitter = this;
+ emitter.effects().push(new Fireworks.EffectBase(emitter, maxAge));
+ return this; // for chained API
+};
+
+
Fireworks.EffectBase = function(emitter, opts)
{
+ this.name = "Base";
+ this.opts = {
+ friction : 0.99,
+ birthPosition : new Fireworks.Vector(0,0,0),
+ birthVelocity : new Fireworks.Vector(1,0,0),
+ birthAcceleration:new Fireworks.Vector(0,0,0)
+ };
this.onCreate = function(particle){
- particle.xBase = {
- x : 0,
- y : 0,
- z : 0,
- velocityX : 0,
- velocityY : 0,
- velocityZ : 0
- };
+ emitter.setParticleData(particle, 'xBase', {
+ position : new Fireworks.Vector(),
+ velocity : new Fireworks.Vector(),
+ acceleration : new Fireworks.Vector(),
+ friction : this.opts.friction
+ });
}.bind(this);
this.onBirth = function(particle){
- var ctx = particle.xBase;
- ctx.x = 0;
- ctx.y = 0;
- ctx.z = 0;
- //ctx.x = window.innerWidth/2;
- //ctx.y = window.innerHeight/2;
- var mult = 0.01;
- ctx.velocityX = 2*(Math.random()-0.5) * mult;
- ctx.velocityY = 2*(Math.random()-0.5) * mult;
- ctx.velocityZ = 2*(Math.random()-0.5) * mult;
+ var ctx = emitter.getParticleData(particle, 'xBase')
+ ctx.position.copy( this.opts.birthPosition );
+ ctx.velocity.copy( this.opts.birthVelocity );
+ ctx.acceleration.copy( this.opts.birthAcceleration );
+ ctx.friction = this.opts.friction;
}.bind(this);
this.onUpdate = function(particle){
var ctx = particle.xBase;
- ctx.x += ctx.velocityX;
- ctx.y += ctx.velocityY;
- ctx.z += ctx.velocityZ;
+ ctx.velocity.addSelf(ctx.acceleration);
+ ctx.velocity.multiplyScalar(ctx.friction);
+ ctx.position.addSelf(ctx.velocity);
}.bind(this);
}
@@ -224,18 +628,221 @@ Fireworks.EffectBase.prototype = new Fireworks.Effect();
Fireworks.EffectBase.prototype.constructor = Fireworks.EffectBase;
-Fireworks.SpawnerRate = function(){
+/**
+ * Shortcut to create Fireworks.Effect.Init2Shapes
+*/
+Fireworks.Emitter.prototype.pushDieIfContained = function(shape){
+ var emitter = this;
+ emitter.effects().push(new Fireworks.Effect.DieIfContained(emitter, shape));
+};
+
+
+Fireworks.Effect.DieIfContained = function(emitter, shape)
+{
+ this.onUpdate = function(particle){
+ var xBase = emitter.getParticleData(particle, 'xBase');
+ var position = xBase.position;
+ if( shape.contains(position) ) emitter.killParticle(particle);
+ }.bind(this);
+}
+
+// inherit from Fireworks.Effect
+Fireworks.Effect.DieIfContained.prototype = new Fireworks.Effect();
+Fireworks.Effect.DieIfContained.prototype.constructor = Fireworks.Effect.DieIfContained;
+
+/**
+ * Shortcut to create Fireworks.Effect.Init2Shapes
+*/
+Fireworks.Emitter.prototype.pushInit2Shapes = function(opts){
+ var emitter = this;
+ emitter.effects().push(new Fireworks.Effect.Init2Shapes(emitter, opts));
+ return this; // for chained API
+};
+
+Fireworks.Effect.Init2Shapes = function(emitter, opts)
+{
+ console.assert( opts.origin instanceof Fireworks.Shape );
+ console.assert( opts.target instanceof Fireworks.Shape );
+ opts.speed = opts.speed !== undefined ? opts.speed : 1;
+ this.opts = opts;
+ this.name = "Init2Shapes"
+ this.onBirth = function(particle){
+ var ctx = emitter.getParticleData(particle, 'xBase')
+
+ ctx.position.copy( opts.origin.randomPoint() );
+
+ var delta = opts.target.randomPoint().subSelf(ctx.position);
+ delta.setLength(opts.speed);
+
+ ctx.velocity.copy( delta );
+ }.bind(this);
+}
+
+// inherit from Fireworks.Effect
+Fireworks.Effect.Init2Shapes.prototype = new Fireworks.Effect();
+Fireworks.Effect.Init2Shapes.prototype.constructor = Fireworks.Effect.Init2Shapes;
+
+
+/**
+ * Shortcut to create Fireworks.Shape.Box
+*/
+Fireworks.createBox = function(centerX, centerY, centerZ, sizeX, sizeY, sizeZ){
+ var center = new Fireworks.Vector(centerX, centerY, centerZ);
+ var size = new Fireworks.Vector(sizeX, sizeY, sizeZ);
+ return new Fireworks.Shape.Box(center, size);
+};
+
+/**
+ * Handle a Firework.Shape forming a sphere
+ *
+ * @param {Fireworks.Vector} center the center of the sphape
+ * @param {Fireworks.Vector} shape the size of the shape
+*/
+Fireworks.Shape.Box = function(center, size)
+{
+ this.center = center;
+ this.size = size;
+ this._vector = new Fireworks.Vector();
+}
+
+// inherit from Fireworks.Effect
+Fireworks.Shape.Box.prototype = new Fireworks.Shape();
+Fireworks.Shape.Box.prototype.constructor = Fireworks.Shape.Box;
+
+Fireworks.Shape.Box.prototype.contains = function(point){
+ // compute delta between the point and the center
+ var delta = this._vector.sub(point, this.center);
+ // test the delta is too far
+ if( Math.abs(delta.x) > this.size.x/2 ) return false;
+ if( Math.abs(delta.y) > this.size.y/2 ) return false;
+ if( Math.abs(delta.z) > this.size.z/2 ) return false;
+ // if all tests, passed true
+ return true;
+}
+
+Fireworks.Shape.Box.prototype.randomPoint = function(){
+ var point = this._vector;
+ // get a random point
+ point.x = Math.random() * this.size.x - this.size.x/2;
+ point.y = Math.random() * this.size.y - this.size.y/2;
+ point.z = Math.random() * this.size.z - this.size.z/2;
+ // add this.center
+ point.addSelf(this.center);
+ // return the point
+ return point;
+}
+Fireworks.DatGui4Emitter = function(emitter){
+ var gui = new dat.GUI();
+ var effects = emitter.effects();
+ effects.forEach(function(effect, idx){
+ var effectName = effect.name || "effect-"+idx;
+ var opts = effect.opts || {};
+ var keys = Object.keys(opts).filter(function(key){
+ if( opts[key] instanceof Fireworks.Vector ) return true;
+ if( typeof(opts[key]) === 'object' ) return false;
+ return true;
+ });
+ if( keys.length ){
+ var folder = gui.addFolder('Effect: '+effectName);
+ keys.forEach(function(key){
+ if( opts[key] instanceof Fireworks.Vector ){
+ folder.add(opts[key], 'x').name(key+"X");
+ folder.add(opts[key], 'y').name(key+"Y");
+ folder.add(opts[key], 'z').name(key+"Z");
+ }else{
+ folder.add(opts, key);
+ }
+ });
+ }
+ });
+ // return the built gui
+ return gui;
+};/**
+ * Shortcut to create Fireworks.Shape.Box
+*/
+Fireworks.createSphere = function(centerX, centerY, centerZ, radius){
+ var center = new Fireworks.Vector(centerX, centerY, centerZ);
+ return new Fireworks.ShapeSphere(center, radius);
+};
+
+
+/**
+ * Handle a Firework.Shape forming a sphere
+ *
+ * @param {Fireworks.Vector} center the center of the sphere
+ * @param {Number} radius the radius of the sphere
+*/
+Fireworks.ShapeSphere = function(center, radius)
+{
+ this.center = center;
+ this.radius = radius;
+ this._vector = new Fireworks.Vector();
+}
+
+// inherit from Fireworks.Effect
+Fireworks.ShapeSphere.prototype = new Fireworks.Shape();
+Fireworks.ShapeSphere.prototype.constructor = Fireworks.ShapeSphere;
+
+Fireworks.ShapeSphere.prototype.contains = function(point){
+ // compute distance between the point and the center
+ var distance = this._vector.sub(point, this.center).length();
+ // return true if this distance is <= than sphere radius
+ return distance <= this.radius;
+}
+
+Fireworks.ShapeSphere.prototype.randomPoint = function(){
+ var point = this._vector;
+ // get a random point
+ point.x = Math.random()-0.5;
+ point.y = Math.random()-0.5;
+ point.z = Math.random()-0.5;
+ // compute the length between the point
+ var length = Math.random()*this.radius;
+ // set the point at the proper distance;
+ point.setLength( length );
+ // add the center
+ point.addSelf(this.center);
+ // return the point
+ return point;
+}
+Fireworks.SpawnerOneShot = function(nParticles){
+ this._nParticles = nParticles || 1;
+ this._completed = false;
+}
+
+// inherit from Fireworks.Spawner
+Fireworks.SpawnerOneShot.prototype = new Fireworks.Spawner();
+Fireworks.SpawnerOneShot.prototype.constructor = Fireworks.SpawnerOneShot;
+
+Fireworks.SpawnerOneShot.prototype.update = function(emitter, deltaTime){
+ // if already completed, do nothing
+ if( this._completed ) return;
+ // spawn each particle
+ for(var i = 0; i < this._nParticles; i++){
+ emitter.spawnParticle();
+ }
+ // mark it as completed
+ this._completed = true;
+}
+Fireworks.SpawnerRate = function(rate){
+ this._rate = rate || 10;
+ this._nToCreate = 1;
}
// inherit from Fireworks.Spawner
Fireworks.SpawnerRate.prototype = new Fireworks.Spawner();
Fireworks.SpawnerRate.prototype.constructor = Fireworks.SpawnerRate;
Fireworks.SpawnerRate.prototype.update = function(emitter, deltaTime){
- var nParticles = 1;
+ this._nToCreate += this._rate * deltaTime;
+ // nParticles is the interger part of this._nToCreate as you spawn them one by one
+ var nParticles = Math.floor(this._nToCreate);
// dont spawn more particles than available
+ // TODO here estimate how much more is needed to never lack of it
nParticles = Math.min(nParticles, emitter.deadParticles().length);
+ // update this._nToCreate
+ this._nToCreate -= nParticles;
// spawn each particle
for(var i = 0; i < nParticles; i++){
emitter.spawnParticle();
View
32 build/fireworks-bundle.min.js
@@ -1,8 +1,24 @@
-var Fireworks={Emitter:function(a){this._nParticles=void 0!==a.nParticles?a.nParticles:100;this._particles=[];this._spawner=null;this._effects=[];this._onUpdated=null}};Fireworks.Emitter.prototype.destroy=function(){this._effects.forEach(function(a){a.destroy()});this._spawner&&this._spawner.destroy();this._particles.forEach(function(a){a.destroy()})};Fireworks.Emitter.prototype.effects=function(){return this._effects};Fireworks.Emitter.prototype.particles=function(){return this._particles};
-Fireworks.Emitter.prototype.liveParticles=function(){return this._liveParticles};Fireworks.Emitter.prototype.deadParticles=function(){return this._deadParticles};Fireworks.Emitter.prototype.addEffectBase=function(){this._effects.push(new Fireworks.EffectBase(this));return this};Fireworks.Emitter.prototype.addEffectAge=function(){this._effects.push(new Fireworks.EffectAge(this));return this};Fireworks.Emitter.prototype.setSpawnerRate=function(){this._spawner=new Fireworks.SpawnerRate;return this};
-Fireworks.Emitter.prototype.start=function(){console.assert(this._spawner,"a spawner MUST be set");console.assert(0<this._effects.length,"Some effects MUST be set");this._particles=Array(this._nParticles);for(var a=0;a<this._nParticles;a++)this._particles[a]=new Fireworks.Particle;this._liveParticles=[];this._deadParticles=this._particles.slice(0);this._started=!0;this._effects.forEach(function(a){a.onCreate&&this._particles.forEach(function(c){a.onCreate(c)})}.bind(this));return this};
-Fireworks.Emitter.prototype.update=function(a){this._spawner.update(this,a);this._effects.forEach(function(b){b.onUpdate&&this._liveParticles.forEach(function(c){b.onUpdate(c,a)})}.bind(this))};Fireworks.Emitter.prototype.killParticle=function(a){var b=this._liveParticles.indexOf(a);console.assert(-1!==b);this._liveParticles.splice(b,1);this._deadParticles.push(a);emitter.effects().forEach(function(b){b.onDeath&&b.onDeath(a)}.bind(this))};
-Fireworks.Emitter.prototype.spawnParticle=function(){var a=emitter.deadParticles().pop();emitter.liveParticles().push(a);emitter.effects().forEach(function(b){b.onBirth&&b.onBirth(a)}.bind(this))};Fireworks.Spawner=function(){};Fireworks.Particle=function(){};Fireworks.Effect=function(){};
-Fireworks.EffectAge=function(a){this.onCreate=function(a){a.xAge={curAge:0,maxAge:0}}.bind(this);this.onBirth=function(a){a=a.xAge;a.curAge=0;a.maxAge=1}.bind(this);this.onUpdate=function(b,c){var d=b.xAge;d.curAge+=c;d.curAge>d.maxAge&&a.killParticle(b)}.bind(this)};Fireworks.EffectAge.prototype=new Fireworks.Effect;Fireworks.EffectAge.prototype.constructor=Fireworks.EffectAge;
-Fireworks.EffectBase=function(){this.onCreate=function(a){a.xBase={x:0,y:0,z:0,velocityX:0,velocityY:0,velocityZ:0}}.bind(this);this.onBirth=function(a){a=a.xBase;a.x=0;a.y=0;a.z=0;a.velocityX=0.02*(Math.random()-0.5);a.velocityY=0.02*(Math.random()-0.5);a.velocityZ=0.02*(Math.random()-0.5)}.bind(this);this.onUpdate=function(a){a=a.xBase;a.x+=a.velocityX;a.y+=a.velocityY;a.z+=a.velocityZ}.bind(this)};Fireworks.EffectBase.prototype=new Fireworks.Effect;Fireworks.EffectBase.prototype.constructor=Fireworks.EffectBase;
-Fireworks.SpawnerRate=function(){};Fireworks.SpawnerRate.prototype=new Fireworks.Spawner;Fireworks.SpawnerRate.prototype.constructor=Fireworks.SpawnerRate;Fireworks.SpawnerRate.prototype.update=function(a){var b;b=Math.min(1,a.deadParticles().length);for(var c=0;c<b;c++)a.spawnParticle()};
+var Fireworks={Emitter:function(a){this._nParticles=void 0!==a.nParticles?a.nParticles:100;this._particles=[];this._spawner=null;this._effects=[];this._started=!1;this._onUpdated=null}};Fireworks.Emitter.prototype.destroy=function(){this._effects.forEach(function(a){a.destroy()});this._spawner&&this._spawner.destroy();this._particles.forEach(function(a){a.destroy()})};Fireworks.Emitter.prototype.effects=function(){return this._effects};Fireworks.Emitter.prototype.particles=function(){return this._particles};
+Fireworks.Emitter.prototype.liveParticles=function(){return this._liveParticles};Fireworks.Emitter.prototype.deadParticles=function(){return this._deadParticles};Fireworks.Emitter.prototype.nParticles=function(){return this._nParticles};Fireworks.Emitter.prototype.setSpawner=function(a){this._spawner=a;return this};Fireworks.Emitter.prototype.setParticleData=function(a,b,c){a[b]=c};Fireworks.Emitter.prototype.getParticleData=function(a,b){console.assert(void 0!==a[b],"namespace undefined: "+b);return a[b]};
+Fireworks.Emitter.prototype.start=function(){console.assert(this._spawner,"a spawner MUST be set");console.assert(0<this._effects.length,"Some effects MUST be set");console.assert(!1===this._started);this._particles=Array(this._nParticles);for(var a=0;a<this._nParticles;a++)this._particles[a]=new Fireworks.Particle;this._liveParticles=[];this._deadParticles=this._particles.slice(0);this._started=!0;this._effects.forEach(function(a){a.onCreate&&this._particles.forEach(function(c,d){a.onCreate(c,d)})}.bind(this));
+return this};Fireworks.Emitter.prototype.update=function(a){this._spawner.update(this,a);this._effects.forEach(function(b){b.onUpdate&&this._liveParticles.forEach(function(c){b.onUpdate(c,a)})}.bind(this));return this};Fireworks.Emitter.prototype.render=function(){this._effects.forEach(function(a){if(a.onPreRender)a.onPreRender()}.bind(this));this._effects.forEach(function(a){a.onRender&&this._liveParticles.forEach(function(b){a.onRender(b)})}.bind(this));return this};
+Fireworks.Emitter.prototype.killParticle=function(a){var b=this._liveParticles.indexOf(a);console.assert(-1!==b);this._liveParticles.splice(b,1);this._deadParticles.push(a);this.effects().forEach(function(b){b.onDeath&&b.onDeath(a)}.bind(this))};Fireworks.Emitter.prototype.spawnParticle=function(){var a=this.deadParticles().pop();this.liveParticles().push(a);this.effects().forEach(function(b){b.onBirth&&b.onBirth(a)}.bind(this))};Fireworks.Spawner=function(){};Fireworks.Particle=function(){};
+Fireworks.createEffect=function(a,b){"object"===typeof a&&(b=a,a=void 0);console.log("createEffect",a,b);var c=new Fireworks.Effect;c.opts=b;c.name=a;var d={onCreate:function(a){c.onCreate=a;return d},onBirth:function(a){c.onBirth=a;return d},onUpdate:function(a){c.onUpdate=a;return d},onDeath:function(a){c.onDeath=a;return d},onPreRender:function(a){c.onPreRender=a;return d},onRender:function(a){c.onRender=a;return d},pushTo:function(a){a.effects().push(c);return d},effect:function(){return c}};
+return d};Fireworks.Effect=function(){};Fireworks.Shape=function(){};Fireworks.Vector=function(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0};
+Fireworks.Vector.prototype={constructor:Fireworks.Vector,set:function(a,b,c){this.x=a;this.y=b;this.z=c;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setZ:function(a){this.z=a;return this},random:function(){this.x=Math.random()-0.5;this.y=Math.random()-0.5;this.z=Math.random()-0.5;return this},toString:function(){return JSON.stringify(this)},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=
+a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;
+this.z*=a;return this},divideSelf:function(a){this.x/=a.x;this.y/=a.y;this.z/=a.z;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a):this.z=this.y=this.x=0;return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},
+cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,c=this.y,d=this.z;this.x=c*a.z-d*a.y;this.y=d*a.x-b*a.z;this.z=b*a.y-c*a.x;return this},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){return(new Fireworks.Vector).sub(this,a).lengthSq()},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z},isZero:function(){return 1.0E-4>this.lengthSq()},clone:function(){return new Fireworks.Vector(this.x,
+this.y,this.z)}};Fireworks.Emitter.prototype.pushAge=function(a,b){1===arguments.length&&(b=a);this.effects().push(new Fireworks.EffectAge(this,a,b));return this};Fireworks.EffectAge=function(a,b,c){console.assert(void 0!==b);console.assert(void 0!==c);this.onCreate=function(a){a.xAge={curAge:0,minAge:0,maxAge:0}}.bind(this);this.onBirth=function(a){a=a.xAge;a.curAge=0;a.maxAge=b+Math.random()*(c-b)}.bind(this);this.onUpdate=function(b,c){var e=b.xAge;e.curAge+=c;e.curAge>e.maxAge&&a.killParticle(b)}.bind(this)};
+Fireworks.EffectAge.prototype=new Fireworks.Effect;Fireworks.EffectAge.prototype.constructor=Fireworks.EffectAge;Fireworks.Effect.ApplyForce=function(a,b){this.onUpdate=function(c){a.getParticleData(c,"xBase").position.addSelf(b.vector)}.bind(this)};Fireworks.Effect.ApplyForce.prototype=new Fireworks.Effect;Fireworks.Effect.ApplyForce.prototype.constructor=Fireworks.Effect.ApplyForce;Fireworks.Emitter.prototype.pushBase=function(a){this.effects().push(new Fireworks.EffectBase(this,a));return this};
+Fireworks.EffectBase=function(a){this.name="Base";this.opts={friction:0.99,birthPosition:new Fireworks.Vector(0,0,0),birthVelocity:new Fireworks.Vector(1,0,0),birthAcceleration:new Fireworks.Vector(0,0,0)};this.onCreate=function(b){a.setParticleData(b,"xBase",{position:new Fireworks.Vector,velocity:new Fireworks.Vector,acceleration:new Fireworks.Vector,friction:this.opts.friction})}.bind(this);this.onBirth=function(b){b=a.getParticleData(b,"xBase");b.position.copy(this.opts.birthPosition);b.velocity.copy(this.opts.birthVelocity);
+b.acceleration.copy(this.opts.birthAcceleration);b.friction=this.opts.friction}.bind(this);this.onUpdate=function(a){a=a.xBase;a.velocity.addSelf(a.acceleration);a.velocity.multiplyScalar(a.friction);a.position.addSelf(a.velocity)}.bind(this)};Fireworks.EffectBase.prototype=new Fireworks.Effect;Fireworks.EffectBase.prototype.constructor=Fireworks.EffectBase;Fireworks.Emitter.prototype.pushDieIfContained=function(a){this.effects().push(new Fireworks.Effect.DieIfContained(this,a))};
+Fireworks.Effect.DieIfContained=function(a,b){this.onUpdate=function(c){var d=a.getParticleData(c,"xBase").position;b.contains(d)&&a.killParticle(c)}.bind(this)};Fireworks.Effect.DieIfContained.prototype=new Fireworks.Effect;Fireworks.Effect.DieIfContained.prototype.constructor=Fireworks.Effect.DieIfContained;Fireworks.Emitter.prototype.pushInit2Shapes=function(a){this.effects().push(new Fireworks.Effect.Init2Shapes(this,a));return this};
+Fireworks.Effect.Init2Shapes=function(a,b){console.assert(b.origin instanceof Fireworks.Shape);console.assert(b.target instanceof Fireworks.Shape);b.speed=void 0!==b.speed?b.speed:1;this.opts=b;this.name="Init2Shapes";this.onBirth=function(c){c=a.getParticleData(c,"xBase");c.position.copy(b.origin.randomPoint());var d=b.target.randomPoint().subSelf(c.position);d.setLength(b.speed);c.velocity.copy(d)}.bind(this)};Fireworks.Effect.Init2Shapes.prototype=new Fireworks.Effect;
+Fireworks.Effect.Init2Shapes.prototype.constructor=Fireworks.Effect.Init2Shapes;Fireworks.createBox=function(a,b,c,d,g,e){a=new Fireworks.Vector(a,b,c);d=new Fireworks.Vector(d,g,e);return new Fireworks.Shape.Box(a,d)};Fireworks.Shape.Box=function(a,b){this.center=a;this.size=b;this._vector=new Fireworks.Vector};Fireworks.Shape.Box.prototype=new Fireworks.Shape;Fireworks.Shape.Box.prototype.constructor=Fireworks.Shape.Box;
+Fireworks.Shape.Box.prototype.contains=function(a){a=this._vector.sub(a,this.center);return Math.abs(a.x)>this.size.x/2||Math.abs(a.y)>this.size.y/2||Math.abs(a.z)>this.size.z/2?!1:!0};Fireworks.Shape.Box.prototype.randomPoint=function(){var a=this._vector;a.x=Math.random()*this.size.x-this.size.x/2;a.y=Math.random()*this.size.y-this.size.y/2;a.z=Math.random()*this.size.z-this.size.z/2;a.addSelf(this.center);return a};
+Fireworks.DatGui4Emitter=function(a){var b=new dat.GUI;a.effects().forEach(function(a,d){var g=a.name||"effect-"+d,e=a.opts||{},h=Object.keys(e).filter(function(a){return e[a]instanceof Fireworks.Vector?!0:"object"===typeof e[a]?!1:!0});if(h.length){var f=b.addFolder("Effect: "+g);h.forEach(function(a){e[a]instanceof Fireworks.Vector?(f.add(e[a],"x").name(a+"X"),f.add(e[a],"y").name(a+"Y"),f.add(e[a],"z").name(a+"Z")):f.add(e,a)})}});return b};
+Fireworks.createSphere=function(a,b,c,d){a=new Fireworks.Vector(a,b,c);return new Fireworks.ShapeSphere(a,d)};Fireworks.ShapeSphere=function(a,b){this.center=a;this.radius=b;this._vector=new Fireworks.Vector};Fireworks.ShapeSphere.prototype=new Fireworks.Shape;Fireworks.ShapeSphere.prototype.constructor=Fireworks.ShapeSphere;Fireworks.ShapeSphere.prototype.contains=function(a){return this._vector.sub(a,this.center).length()<=this.radius};
+Fireworks.ShapeSphere.prototype.randomPoint=function(){var a=this._vector;a.x=Math.random()-0.5;a.y=Math.random()-0.5;a.z=Math.random()-0.5;var b=Math.random()*this.radius;a.setLength(b);a.addSelf(this.center);return a};Fireworks.SpawnerOneShot=function(a){this._nParticles=a||1;this._completed=!1};Fireworks.SpawnerOneShot.prototype=new Fireworks.Spawner;Fireworks.SpawnerOneShot.prototype.constructor=Fireworks.SpawnerOneShot;
+Fireworks.SpawnerOneShot.prototype.update=function(a){if(!this._completed){for(var b=0;b<this._nParticles;b++)a.spawnParticle();this._completed=!0}};Fireworks.SpawnerRate=function(a){this._rate=a||10;this._nToCreate=1};Fireworks.SpawnerRate.prototype=new Fireworks.Spawner;Fireworks.SpawnerRate.prototype.constructor=Fireworks.SpawnerRate;
+Fireworks.SpawnerRate.prototype.update=function(a,b){this._nToCreate+=this._rate*b;var c=Math.floor(this._nToCreate),c=Math.min(c,a.deadParticles().length);this._nToCreate-=c;for(var d=0;d<c;d++)a.spawnParticle()};
View
52 build/fireworks.js
@@ -7,6 +7,7 @@ Fireworks.Emitter = function(opts){
this._particles = [];
this._spawner = null;
this._effects = [];
+ this._started = false;
this._onUpdated = null;
}
@@ -38,6 +39,9 @@ Fireworks.Emitter.prototype.liveParticles = function(){
Fireworks.Emitter.prototype.deadParticles = function(){
return this._deadParticles;
}
+Fireworks.Emitter.prototype.nParticles = function(){
+ return this._nParticles;
+}
Fireworks.Emitter.prototype.setSpawner = function(spawner){
this._spawner = spawner;
@@ -50,7 +54,7 @@ Fireworks.Emitter.prototype.setParticleData = function(particle, namespace, valu
}
Fireworks.Emitter.prototype.getParticleData = function(particle, namespace){
- console.assert( particle[namespace] !== undefined );
+ console.assert( particle[namespace] !== undefined, "namespace undefined: "+namespace );
return particle[namespace];
}
@@ -62,6 +66,7 @@ Fireworks.Emitter.prototype.start = function()
{
console.assert( this._spawner, "a spawner MUST be set" );
console.assert( this._effects.length > 0, "Some effects MUST be set")
+ console.assert( this._started === false );
this._particles = new Array(this._nParticles);
for(var i = 0; i < this._nParticles; i++){
@@ -75,8 +80,8 @@ Fireworks.Emitter.prototype.start = function()
// onCreate on all particles
this._effects.forEach(function(effect){
if( !effect.onCreate ) return;
- this._particles.forEach(function(particle){
- effect.onCreate(particle);
+ this._particles.forEach(function(particle, particleIdx){
+ effect.onCreate(particle, particleIdx);
})
}.bind(this));
@@ -93,6 +98,21 @@ Fireworks.Emitter.prototype.update = function(deltaTime){
effect.onUpdate(particle, deltaTime);
})
}.bind(this));
+ return this; // for chained API
+}
+
+Fireworks.Emitter.prototype.render = function(){
+ this._effects.forEach(function(effect){
+ if( !effect.onPreRender ) return;
+ effect.onPreRender();
+ }.bind(this));
+ this._effects.forEach(function(effect){
+ if( !effect.onRender ) return;
+ this._liveParticles.forEach(function(particle){
+ effect.onRender(particle);
+ })
+ }.bind(this));
+ return this; // for chained API
}
//////////////////////////////////////////////////////////////////////////////////
@@ -109,7 +129,7 @@ Fireworks.Emitter.prototype.killParticle = function(particle)
this._liveParticles.splice(idx, 1)
this._deadParticles.push(particle);
// do the death on all effects
- emitter.effects().forEach(function(effect){
+ this.effects().forEach(function(effect){
effect.onDeath && effect.onDeath(particle);
}.bind(this));
}
@@ -119,10 +139,10 @@ Fireworks.Emitter.prototype.killParticle = function(particle)
*/
Fireworks.Emitter.prototype.spawnParticle = function(){
// change the particles
- var particle = emitter.deadParticles().pop();
- emitter.liveParticles().push(particle);
+ var particle = this.deadParticles().pop();
+ this.liveParticles().push(particle);
// do the birth on all effects
- emitter.effects().forEach(function(effect){
+ this.effects().forEach(function(effect){
effect.onBirth && effect.onBirth(particle);
}.bind(this));
}
@@ -136,9 +156,17 @@ Fireworks.Particle = function(){
/**
* Basic Fireworks.Effect builder
*/
-Fireworks.createEffect = function(opts){
+Fireworks.createEffect = function(name, opts){
+ // handle polymophism
+ if( typeof(name) === 'object' ){
+ opts = name;
+ name = undefined;
+ }
+ console.log("createEffect", name, opts)
+
var effect = new Fireworks.Effect();
effect.opts = opts;
+ effect.name = name;
var methods = {
onCreate: function(val){
effect.onCreate = val;
@@ -156,6 +184,14 @@ Fireworks.createEffect = function(opts){
effect.onDeath = val;
return methods;
},
+ onPreRender: function(val){
+ effect.onPreRender = val;
+ return methods;
+ },
+ onRender: function(val){
+ effect.onRender = val;
+ return methods;
+ },
pushTo : function(emitter){
emitter.effects().push(effect);
return methods;
View
13 build/fireworks.min.js
@@ -1,9 +1,10 @@
-var Fireworks={Emitter:function(a){this._nParticles=void 0!==a.nParticles?a.nParticles:100;this._particles=[];this._spawner=null;this._effects=[];this._onUpdated=null}};Fireworks.Emitter.prototype.destroy=function(){this._effects.forEach(function(a){a.destroy()});this._spawner&&this._spawner.destroy();this._particles.forEach(function(a){a.destroy()})};Fireworks.Emitter.prototype.effects=function(){return this._effects};Fireworks.Emitter.prototype.particles=function(){return this._particles};
-Fireworks.Emitter.prototype.liveParticles=function(){return this._liveParticles};Fireworks.Emitter.prototype.deadParticles=function(){return this._deadParticles};Fireworks.Emitter.prototype.setSpawner=function(a){this._spawner=a;return this};Fireworks.Emitter.prototype.setParticleData=function(a,b,c){a[b]=c};Fireworks.Emitter.prototype.getParticleData=function(a,b){console.assert(void 0!==a[b]);return a[b]};
-Fireworks.Emitter.prototype.start=function(){console.assert(this._spawner,"a spawner MUST be set");console.assert(0<this._effects.length,"Some effects MUST be set");this._particles=Array(this._nParticles);for(var a=0;a<this._nParticles;a++)this._particles[a]=new Fireworks.Particle;this._liveParticles=[];this._deadParticles=this._particles.slice(0);this._started=!0;this._effects.forEach(function(a){a.onCreate&&this._particles.forEach(function(c){a.onCreate(c)})}.bind(this));return this};
-Fireworks.Emitter.prototype.update=function(a){this._spawner.update(this,a);this._effects.forEach(function(b){b.onUpdate&&this._liveParticles.forEach(function(c){b.onUpdate(c,a)})}.bind(this))};Fireworks.Emitter.prototype.killParticle=function(a){var b=this._liveParticles.indexOf(a);console.assert(-1!==b);this._liveParticles.splice(b,1);this._deadParticles.push(a);emitter.effects().forEach(function(b){b.onDeath&&b.onDeath(a)}.bind(this))};
-Fireworks.Emitter.prototype.spawnParticle=function(){var a=emitter.deadParticles().pop();emitter.liveParticles().push(a);emitter.effects().forEach(function(b){b.onBirth&&b.onBirth(a)}.bind(this))};Fireworks.Spawner=function(){};Fireworks.Particle=function(){};
-Fireworks.createEffect=function(a){var b=new Fireworks.Effect;b.opts=a;var c={onCreate:function(a){b.onCreate=a;return c},onBirth:function(a){b.onBirth=a;return c},onUpdate:function(a){b.onUpdate=a;return c},onDeath:function(a){b.onDeath=a;return c},pushTo:function(a){a.effects().push(b);return c},effect:function(){return b}};return c};Fireworks.Effect=function(){};Fireworks.Shape=function(){};Fireworks.Vector=function(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0};
+var Fireworks={Emitter:function(a){this._nParticles=void 0!==a.nParticles?a.nParticles:100;this._particles=[];this._spawner=null;this._effects=[];this._started=!1;this._onUpdated=null}};Fireworks.Emitter.prototype.destroy=function(){this._effects.forEach(function(a){a.destroy()});this._spawner&&this._spawner.destroy();this._particles.forEach(function(a){a.destroy()})};Fireworks.Emitter.prototype.effects=function(){return this._effects};Fireworks.Emitter.prototype.particles=function(){return this._particles};
+Fireworks.Emitter.prototype.liveParticles=function(){return this._liveParticles};Fireworks.Emitter.prototype.deadParticles=function(){return this._deadParticles};Fireworks.Emitter.prototype.nParticles=function(){return this._nParticles};Fireworks.Emitter.prototype.setSpawner=function(a){this._spawner=a;return this};Fireworks.Emitter.prototype.setParticleData=function(a,b,c){a[b]=c};Fireworks.Emitter.prototype.getParticleData=function(a,b){console.assert(void 0!==a[b],"namespace undefined: "+b);return a[b]};
+Fireworks.Emitter.prototype.start=function(){console.assert(this._spawner,"a spawner MUST be set");console.assert(0<this._effects.length,"Some effects MUST be set");console.assert(!1===this._started);this._particles=Array(this._nParticles);for(var a=0;a<this._nParticles;a++)this._particles[a]=new Fireworks.Particle;this._liveParticles=[];this._deadParticles=this._particles.slice(0);this._started=!0;this._effects.forEach(function(a){a.onCreate&&this._particles.forEach(function(c,d){a.onCreate(c,d)})}.bind(this));
+return this};Fireworks.Emitter.prototype.update=function(a){this._spawner.update(this,a);this._effects.forEach(function(b){b.onUpdate&&this._liveParticles.forEach(function(c){b.onUpdate(c,a)})}.bind(this));return this};Fireworks.Emitter.prototype.render=function(){this._effects.forEach(function(a){if(a.onPreRender)a.onPreRender()}.bind(this));this._effects.forEach(function(a){a.onRender&&this._liveParticles.forEach(function(b){a.onRender(b)})}.bind(this));return this};
+Fireworks.Emitter.prototype.killParticle=function(a){var b=this._liveParticles.indexOf(a);console.assert(-1!==b);this._liveParticles.splice(b,1);this._deadParticles.push(a);this.effects().forEach(function(b){b.onDeath&&b.onDeath(a)}.bind(this))};Fireworks.Emitter.prototype.spawnParticle=function(){var a=this.deadParticles().pop();this.liveParticles().push(a);this.effects().forEach(function(b){b.onBirth&&b.onBirth(a)}.bind(this))};Fireworks.Spawner=function(){};Fireworks.Particle=function(){};
+Fireworks.createEffect=function(a,b){"object"===typeof a&&(b=a,a=void 0);console.log("createEffect",a,b);var c=new Fireworks.Effect;c.opts=b;c.name=a;var d={onCreate:function(a){c.onCreate=a;return d},onBirth:function(a){c.onBirth=a;return d},onUpdate:function(a){c.onUpdate=a;return d},onDeath:function(a){c.onDeath=a;return d},onPreRender:function(a){c.onPreRender=a;return d},onRender:function(a){c.onRender=a;return d},pushTo:function(a){a.effects().push(c);return d},effect:function(){return c}};
+return d};Fireworks.Effect=function(){};Fireworks.Shape=function(){};Fireworks.Vector=function(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0};
Fireworks.Vector.prototype={constructor:Fireworks.Vector,set:function(a,b,c){this.x=a;this.y=b;this.z=c;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setZ:function(a){this.z=a;return this},random:function(){this.x=Math.random()-0.5;this.y=Math.random()-0.5;this.z=Math.random()-0.5;return this},toString:function(){return JSON.stringify(this)},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=
a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;
this.z*=a;return this},divideSelf:function(a){this.x/=a.x;this.y/=a.y;this.z/=a.z;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a):this.z=this.y=this.x=0;return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},

0 comments on commit eae2c2a

Please sign in to comment.
Something went wrong with that request. Please try again.