|
@@ -6,9 +6,10 @@ var BABYLON;
|
|
var SolidParticleSystem = (function () {
|
|
var SolidParticleSystem = (function () {
|
|
/**
|
|
/**
|
|
* Creates a SPS (Solid Particle System) object.
|
|
* Creates a SPS (Solid Particle System) object.
|
|
- * @param name the SPS name, this will be the underlying mesh name
|
|
|
|
- * @param scene the scene in which the SPS is added
|
|
|
|
- * @param options "updatable" (default true) : if the SPS must be updatable or immutable, "isPickable" (default false) : if the solid particles must be pickable
|
|
|
|
|
|
+ * `name` (String) is the SPS name, this will be the underlying mesh name.
|
|
|
|
+ * `scene` (Scene) is the scene in which the SPS is added.
|
|
|
|
+ * `updatableè (default true) : if the SPS must be updatable or immutable.
|
|
|
|
+ * `isPickable` (default false) : if the solid particles must be pickable.
|
|
*/
|
|
*/
|
|
function SolidParticleSystem(name, scene, options) {
|
|
function SolidParticleSystem(name, scene, options) {
|
|
// public members
|
|
// public members
|
|
@@ -96,7 +97,7 @@ var BABYLON;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* Builds the SPS underlying mesh. Returns a standard Mesh.
|
|
* Builds the SPS underlying mesh. Returns a standard Mesh.
|
|
- * If no model shape was added to the SPS, the return mesh is only a single triangular plane.
|
|
|
|
|
|
+ * If no model shape was added to the SPS, the returned mesh is just a single triangular plane.
|
|
*/
|
|
*/
|
|
SolidParticleSystem.prototype.buildMesh = function () {
|
|
SolidParticleSystem.prototype.buildMesh = function () {
|
|
if (this.nbParticles === 0) {
|
|
if (this.nbParticles === 0) {
|
|
@@ -136,13 +137,13 @@ var BABYLON;
|
|
return mesh;
|
|
return mesh;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
- * Digests the mesh and generates as many solid particles in the system as wanted.
|
|
|
|
|
|
+ * Digests the mesh and generates as many solid particles in the system as wanted. Returns the SPS.
|
|
* These particles will have the same geometry than the mesh parts and will be positioned at the same localisation than the mesh original places.
|
|
* These particles will have the same geometry than the mesh parts and will be positioned at the same localisation than the mesh original places.
|
|
- * Thus the particles generated from digest() have their property "positiion" yet set.
|
|
|
|
- * @param mesh the mesh to be digested
|
|
|
|
- * @param facetNb the number of mesh facets per particle (optional, default 1), this parameter is overriden by the parameter "number" if any
|
|
|
|
- * @param delta the random extra number of facets per partical (optional, default 0), each particle will have between facetNb and facetNb + delta facets
|
|
|
|
- * @param number the wanted number of particles : each particle is built with mesh_total_facets / number facets (optional)
|
|
|
|
|
|
+ * Thus the particles generated from `digest()` have their property `position` set yet.
|
|
|
|
+ * `mesh` (`Mesh`) is the mesh to be digested
|
|
|
|
+ * `facetNb` (optional integer, default 1) is the number of mesh facets per particle, this parameter is overriden by the parameter `number` if any
|
|
|
|
+ * `delta` (optional integer, default 0) is the random extra number of facets per particle , each particle will have between `facetNb` and `facetNb + delta` facets
|
|
|
|
+ * `number` (optional positive integer) is the wanted number of particles : each particle is built with `mesh_total_facets / number` facets
|
|
*/
|
|
*/
|
|
SolidParticleSystem.prototype.digest = function (mesh, options) {
|
|
SolidParticleSystem.prototype.digest = function (mesh, options) {
|
|
var size = (options && options.facetNb) || 1;
|
|
var size = (options && options.facetNb) || 1;
|
|
@@ -220,6 +221,7 @@ var BABYLON;
|
|
this._shapeCounter++;
|
|
this._shapeCounter++;
|
|
f += size;
|
|
f += size;
|
|
}
|
|
}
|
|
|
|
+ return this;
|
|
};
|
|
};
|
|
//reset copy
|
|
//reset copy
|
|
SolidParticleSystem.prototype._resetCopy = function () {
|
|
SolidParticleSystem.prototype._resetCopy = function () {
|
|
@@ -327,11 +329,12 @@ var BABYLON;
|
|
this.particles.push(new BABYLON.SolidParticle(idx, idxpos, model, shapeId, idxInShape));
|
|
this.particles.push(new BABYLON.SolidParticle(idx, idxpos, model, shapeId, idxInShape));
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
- * Adds some particles to the SPS from the model shape.
|
|
|
|
|
|
+ * Adds some particles to the SPS from the model shape. Returns the shape id.
|
|
* Please read the doc : http://doc.babylonjs.com/tutorials/Solid_Particle_System#create-an-immutable-sps
|
|
* Please read the doc : http://doc.babylonjs.com/tutorials/Solid_Particle_System#create-an-immutable-sps
|
|
- * @param mesh any Mesh object that will be used as a model for the solid particles.
|
|
|
|
- * @param nb the number of particles to be created from this model
|
|
|
|
- * @param options positionFunction is an optional javascript function to called for each particle on SPS creation. vertexFunction an optional javascript function to called for each vertex of each particle on SPS creation
|
|
|
|
|
|
+ * `mesh` is any `Mesh` object that will be used as a model for the solid particles.
|
|
|
|
+ * `nb` (positive integer) the number of particles to be created from this model
|
|
|
|
+ * `positionFunction` is an optional javascript function to called for each particle on SPS creation.
|
|
|
|
+ * `vertexFunction` is an optional javascript function to called for each vertex of each particle on SPS creation
|
|
*/
|
|
*/
|
|
SolidParticleSystem.prototype.addShape = function (mesh, nb, options) {
|
|
SolidParticleSystem.prototype.addShape = function (mesh, nb, options) {
|
|
var meshPos = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
|
|
var meshPos = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
|
|
@@ -414,7 +417,7 @@ var BABYLON;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* Sets all the particles : this method actually really updates the mesh according to the particle positions, rotations, colors, textures, etc.
|
|
* Sets all the particles : this method actually really updates the mesh according to the particle positions, rotations, colors, textures, etc.
|
|
- * This method calls updateParticle() for each particles of the SPS.
|
|
|
|
|
|
+ * This method calls `updateParticle()` for each particle of the SPS.
|
|
* For an animated SPS, it is usually called within the render loop.
|
|
* For an animated SPS, it is usually called within the render loop.
|
|
* @param start (default 0) the particle index in the particle array where to start to compute the particle property values
|
|
* @param start (default 0) the particle index in the particle array where to start to compute the particle property values
|
|
* @param end (default nbParticle - 1) the particle index in the particle array where to stop to compute the particle property values
|
|
* @param end (default nbParticle - 1) the particle index in the particle array where to stop to compute the particle property values
|
|
@@ -642,7 +645,7 @@ var BABYLON;
|
|
this.pickedParticles = null;
|
|
this.pickedParticles = null;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
- * Visibilty helper : Recomputes the visible size according to the mesh bounding box
|
|
|
|
|
|
+ * Visibilty helper : Recomputes the visible size according to the mesh bounding box
|
|
* doc : http://doc.babylonjs.com/tutorials/Solid_Particle_System#sps-visibility
|
|
* doc : http://doc.babylonjs.com/tutorials/Solid_Particle_System#sps-visibility
|
|
*/
|
|
*/
|
|
SolidParticleSystem.prototype.refreshVisibleSize = function () {
|
|
SolidParticleSystem.prototype.refreshVisibleSize = function () {
|
|
@@ -650,7 +653,8 @@ var BABYLON;
|
|
this.mesh.refreshBoundingInfo();
|
|
this.mesh.refreshBoundingInfo();
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- /** Visibility helper : Sets the size of a visibility box, this sets the underlying mesh bounding box.
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Visibility helper : Sets the size of a visibility box, this sets the underlying mesh bounding box.
|
|
* @param size the size (float) of the visibility box
|
|
* @param size the size (float) of the visibility box
|
|
* note : this doesn't lock the SPS mesh bounding box.
|
|
* note : this doesn't lock the SPS mesh bounding box.
|
|
* doc : http://doc.babylonjs.com/tutorials/Solid_Particle_System#sps-visibility
|
|
* doc : http://doc.babylonjs.com/tutorials/Solid_Particle_System#sps-visibility
|
|
@@ -661,9 +665,6 @@ var BABYLON;
|
|
};
|
|
};
|
|
Object.defineProperty(SolidParticleSystem.prototype, "isAlwaysVisible", {
|
|
Object.defineProperty(SolidParticleSystem.prototype, "isAlwaysVisible", {
|
|
// getter and setter
|
|
// getter and setter
|
|
- /**
|
|
|
|
- * True if the SPS is set as always visible
|
|
|
|
- */
|
|
|
|
get: function () {
|
|
get: function () {
|
|
return this._alwaysVisible;
|
|
return this._alwaysVisible;
|
|
},
|
|
},
|
|
@@ -679,9 +680,6 @@ var BABYLON;
|
|
configurable: true
|
|
configurable: true
|
|
});
|
|
});
|
|
Object.defineProperty(SolidParticleSystem.prototype, "isVisibilityBoxLocked", {
|
|
Object.defineProperty(SolidParticleSystem.prototype, "isVisibilityBoxLocked", {
|
|
- /**
|
|
|
|
- * True if the SPS visibility box is locked. The underlying mesh bounding box is then not updatable any more.
|
|
|
|
- */
|
|
|
|
get: function () {
|
|
get: function () {
|
|
return this._isVisibilityBoxLocked;
|
|
return this._isVisibilityBoxLocked;
|
|
},
|
|
},
|
|
@@ -703,9 +701,9 @@ var BABYLON;
|
|
},
|
|
},
|
|
// Optimizer setters
|
|
// Optimizer setters
|
|
/**
|
|
/**
|
|
- * Tells to setParticles() to compute the particle rotations or not.
|
|
|
|
|
|
+ * Tells to `setParticles()` to compute the particle rotations or not.
|
|
* Default value : true. The SPS is faster when it's set to false.
|
|
* Default value : true. The SPS is faster when it's set to false.
|
|
- * Note : the particle rotations aren't stored values, so setting computeParticleRotation to false will prevents the particle to rotate.
|
|
|
|
|
|
+ * Note : the particle rotations aren't stored values, so setting `computeParticleRotation` to false will prevents the particle to rotate.
|
|
*/
|
|
*/
|
|
set: function (val) {
|
|
set: function (val) {
|
|
this._computeParticleRotation = val;
|
|
this._computeParticleRotation = val;
|
|
@@ -718,9 +716,9 @@ var BABYLON;
|
|
return this._computeParticleColor;
|
|
return this._computeParticleColor;
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
- * Tells to setParticles() to compute the particle colors or not.
|
|
|
|
|
|
+ * Tells to `setParticles()` to compute the particle colors or not.
|
|
* Default value : true. The SPS is faster when it's set to false.
|
|
* Default value : true. The SPS is faster when it's set to false.
|
|
- * Note : the particle colors are stored values, so setting computeParticleColor to false will keep yet the last colors set.
|
|
|
|
|
|
+ * Note : the particle colors are stored values, so setting `computeParticleColor` to false will keep yet the last colors set.
|
|
*/
|
|
*/
|
|
set: function (val) {
|
|
set: function (val) {
|
|
this._computeParticleColor = val;
|
|
this._computeParticleColor = val;
|
|
@@ -733,9 +731,9 @@ var BABYLON;
|
|
return this._computeParticleTexture;
|
|
return this._computeParticleTexture;
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
- * Tells to setParticles() to compute the particle textures or not.
|
|
|
|
|
|
+ * Tells to `setParticles()` to compute the particle textures or not.
|
|
* Default value : true. The SPS is faster when it's set to false.
|
|
* Default value : true. The SPS is faster when it's set to false.
|
|
- * Note : the particle textures are stored values, so setting computeParticleTexture to false will keep yet the last colors set.
|
|
|
|
|
|
+ * Note : the particle textures are stored values, so setting `computeParticleTexture` to false will keep yet the last colors set.
|
|
*/
|
|
*/
|
|
set: function (val) {
|
|
set: function (val) {
|
|
this._computeParticleTexture = val;
|
|
this._computeParticleTexture = val;
|
|
@@ -748,7 +746,7 @@ var BABYLON;
|
|
return this._computeParticleVertex;
|
|
return this._computeParticleVertex;
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
- * Tells to setParticles() to call the vertex function for each vertex of each particle, or not.
|
|
|
|
|
|
+ * Tells to `setParticles()` to call the vertex function for each vertex of each particle, or not.
|
|
* Default value : false. The SPS is faster when it's set to false.
|
|
* Default value : false. The SPS is faster when it's set to false.
|
|
* Note : the particle custom vertex positions aren't stored values.
|
|
* Note : the particle custom vertex positions aren't stored values.
|
|
*/
|
|
*/
|
|
@@ -763,7 +761,7 @@ var BABYLON;
|
|
return this._computeBoundingBox;
|
|
return this._computeBoundingBox;
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
- * Tells to setParticles() to compute or not the mesh bounding box when computing the particle positions.
|
|
|
|
|
|
+ * Tells to `setParticles()` to compute or not the mesh bounding box when computing the particle positions.
|
|
*/
|
|
*/
|
|
set: function (val) {
|
|
set: function (val) {
|
|
this._computeBoundingBox = val;
|
|
this._computeBoundingBox = val;
|
|
@@ -775,7 +773,7 @@ var BABYLON;
|
|
// Particle behavior logic
|
|
// Particle behavior logic
|
|
// these following methods may be overwritten by the user to fit his needs
|
|
// these following methods may be overwritten by the user to fit his needs
|
|
/**
|
|
/**
|
|
- * This function does nothing. It may be overwritten to set all the particles first values.
|
|
|
|
|
|
+ * This function does nothing. It may be overwritten to set all the particle first values.
|
|
* The SPS doesn't call this function, you may have to call it by your own.
|
|
* The SPS doesn't call this function, you may have to call it by your own.
|
|
* doc : http://doc.babylonjs.com/tutorials/Solid_Particle_System#particle-management
|
|
* doc : http://doc.babylonjs.com/tutorials/Solid_Particle_System#particle-management
|
|
*/
|
|
*/
|
|
@@ -791,7 +789,7 @@ var BABYLON;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* Updates a particle : this function should be overwritten by the user.
|
|
* Updates a particle : this function should be overwritten by the user.
|
|
- * It is called on each particle by setParticles(). This is the place to code each particle behavior.
|
|
|
|
|
|
+ * It is called on each particle by `setParticles()`. This is the place to code each particle behavior.
|
|
* doc : http://doc.babylonjs.com/tutorials/Solid_Particle_System#particle-management
|
|
* doc : http://doc.babylonjs.com/tutorials/Solid_Particle_System#particle-management
|
|
* ex : just set a particle position or velocity and recycle conditions
|
|
* ex : just set a particle position or velocity and recycle conditions
|
|
*/
|
|
*/
|
|
@@ -800,7 +798,7 @@ var BABYLON;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* Updates a vertex of a particle : it can be overwritten by the user.
|
|
* Updates a vertex of a particle : it can be overwritten by the user.
|
|
- * This will be called on each vertex particle by setParticles() if computeParticleVertex is set to true only.
|
|
|
|
|
|
+ * This will be called on each vertex particle by `setParticles()` if `computeParticleVertex` is set to true only.
|
|
* @param particle the current particle
|
|
* @param particle the current particle
|
|
* @param vertex the current index of the current particle
|
|
* @param vertex the current index of the current particle
|
|
* @param pt the index of the current vertex in the particle shape
|
|
* @param pt the index of the current vertex in the particle shape
|
|
@@ -811,7 +809,7 @@ var BABYLON;
|
|
return vertex;
|
|
return vertex;
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
- * This will be called before any other treatment by setParticles() and will be passed three parameters.
|
|
|
|
|
|
+ * This will be called before any other treatment by `setParticles()` and will be passed three parameters.
|
|
* This does nothing and may be overwritten by the user.
|
|
* This does nothing and may be overwritten by the user.
|
|
* @param start the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
|
|
* @param start the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
|
|
* @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
|
|
* @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
|
|
@@ -820,7 +818,7 @@ var BABYLON;
|
|
SolidParticleSystem.prototype.beforeUpdateParticles = function (start, stop, update) {
|
|
SolidParticleSystem.prototype.beforeUpdateParticles = function (start, stop, update) {
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
- * This will be called by setParticles() after all the other treatments and just before the actual mesh update.
|
|
|
|
|
|
+ * This will be called by `setParticles()` after all the other treatments and just before the actual mesh update.
|
|
* This will be passed three parameters.
|
|
* This will be passed three parameters.
|
|
* This does nothing and may be overwritten by the user.
|
|
* This does nothing and may be overwritten by the user.
|
|
* @param start the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
|
|
* @param start the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
|