|
@@ -7,15 +7,32 @@ var BABYLON;
|
|
|
/**
|
|
|
* Creates a SPS (Solid Particle System) object.
|
|
|
* @param name the SPS name, this will be the underlying mesh name
|
|
|
- * @param updatable (default true) if the SPS must be updatable or immutable
|
|
|
- * @param isPickable (default false) if the solid particles must be pickable
|
|
|
+ * @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
|
|
|
*/
|
|
|
function SolidParticleSystem(name, scene, options) {
|
|
|
// public members
|
|
|
+ /**
|
|
|
+ * The SPS array of Solid Particle objects. Just access each particle as with any classic array.
|
|
|
+ * Example : var p = SPS.particles[i];
|
|
|
+ */
|
|
|
this.particles = new Array();
|
|
|
+ /**
|
|
|
+ * The SPS total number of particles. Read only. Use SPS.counter instead if you need to set your own value.
|
|
|
+ */
|
|
|
this.nbParticles = 0;
|
|
|
+ /**
|
|
|
+ * If the particles must ever face the camera (default false). Useful for planar particles.
|
|
|
+ */
|
|
|
this.billboard = false;
|
|
|
+ /**
|
|
|
+ * This a counter ofr your own usage. It's not set by any SPS functions.
|
|
|
+ */
|
|
|
this.counter = 0;
|
|
|
+ /**
|
|
|
+ * This empty object is intended to store some SPS specific or temporary values in order to lower the Garbage Collector activity.
|
|
|
+ * Please read : http://doc.babylonjs.com/tutorials/Solid_Particle_System#garbage-collector-concerns
|
|
|
+ */
|
|
|
this.vars = {};
|
|
|
this._positions = new Array();
|
|
|
this._indices = new Array();
|
|
@@ -34,6 +51,7 @@ var BABYLON;
|
|
|
this._computeParticleTexture = true;
|
|
|
this._computeParticleRotation = true;
|
|
|
this._computeParticleVertex = false;
|
|
|
+ this._computeBoundingBox = false;
|
|
|
this._cam_axisZ = BABYLON.Vector3.Zero();
|
|
|
this._cam_axisY = BABYLON.Vector3.Zero();
|
|
|
this._cam_axisX = BABYLON.Vector3.Zero();
|
|
@@ -60,6 +78,9 @@ var BABYLON;
|
|
|
this._sinYaw = 0.0;
|
|
|
this._cosYaw = 0.0;
|
|
|
this._w = 0.0;
|
|
|
+ this._minimum = BABYLON.Tmp.Vector3[0];
|
|
|
+ this._maximum = BABYLON.Tmp.Vector3[1];
|
|
|
+ this._vertexWorld = BABYLON.Tmp.Vector3[2];
|
|
|
this.name = name;
|
|
|
this._scene = scene;
|
|
|
this._camera = scene.activeCamera;
|
|
@@ -305,8 +326,7 @@ var BABYLON;
|
|
|
* 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 positionFunction an optional javascript function to called for each particle on SPS creation
|
|
|
- * @param vertexFunction an optional javascript function to called for each vertex of each particle on SPS creation
|
|
|
+ * @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
|
|
|
*/
|
|
|
SolidParticleSystem.prototype.addShape = function (mesh, nb, options) {
|
|
|
var meshPos = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
|
|
@@ -438,6 +458,10 @@ var BABYLON;
|
|
|
var colorIndex = 0;
|
|
|
var uvidx = 0;
|
|
|
var uvIndex = 0;
|
|
|
+ if (this._computeBoundingBox) {
|
|
|
+ BABYLON.Vector3.FromFloatsToRef(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, this._minimum);
|
|
|
+ BABYLON.Vector3.FromFloatsToRef(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE, this._maximum);
|
|
|
+ }
|
|
|
// particle loop
|
|
|
end = (end > this.nbParticles - 1) ? this.nbParticles - 1 : end;
|
|
|
for (var p = start; p <= end; p++) {
|
|
@@ -487,6 +511,26 @@ var BABYLON;
|
|
|
this._positions32[idx] = this._particle.position.x + this._cam_axisX.x * this._rotated.x + this._cam_axisY.x * this._rotated.y + this._cam_axisZ.x * this._rotated.z;
|
|
|
this._positions32[idx + 1] = this._particle.position.y + this._cam_axisX.y * this._rotated.x + this._cam_axisY.y * this._rotated.y + this._cam_axisZ.y * this._rotated.z;
|
|
|
this._positions32[idx + 2] = this._particle.position.z + this._cam_axisX.z * this._rotated.x + this._cam_axisY.z * this._rotated.y + this._cam_axisZ.z * this._rotated.z;
|
|
|
+ if (this._computeBoundingBox) {
|
|
|
+ if (this._positions32[idx] < this._minimum.x) {
|
|
|
+ this._minimum.x = this._positions32[idx];
|
|
|
+ }
|
|
|
+ if (this._positions32[idx] > this._maximum.x) {
|
|
|
+ this._maximum.x = this._positions32[idx];
|
|
|
+ }
|
|
|
+ if (this._positions32[idx + 1] < this._minimum.y) {
|
|
|
+ this._minimum.y = this._positions32[idx + 1];
|
|
|
+ }
|
|
|
+ if (this._positions32[idx + 1] > this._maximum.y) {
|
|
|
+ this._maximum.y = this._positions32[idx + 1];
|
|
|
+ }
|
|
|
+ if (this._positions32[idx + 2] < this._minimum.z) {
|
|
|
+ this._minimum.z = this._positions32[idx + 2];
|
|
|
+ }
|
|
|
+ if (this._positions32[idx + 2] > this._maximum.z) {
|
|
|
+ this._maximum.z = this._positions32[idx + 2];
|
|
|
+ }
|
|
|
+ }
|
|
|
// normals : if the particles can't be morphed then just rotate the normals
|
|
|
if (!this._computeParticleVertex && !this.billboard) {
|
|
|
this._normal.x = this._fixedNormal32[idx];
|
|
@@ -534,6 +578,10 @@ var BABYLON;
|
|
|
this.mesh.updateVerticesData(BABYLON.VertexBuffer.NormalKind, this._normals32, false, false);
|
|
|
}
|
|
|
}
|
|
|
+ if (this._computeBoundingBox) {
|
|
|
+ this.mesh._boundingInfo = new BABYLON.BoundingInfo(this._minimum, this._maximum);
|
|
|
+ this.mesh._boundingInfo.boundingBox.setWorldMatrix(this.mesh._worldMatrix);
|
|
|
+ }
|
|
|
this.afterUpdateParticles(start, end, update);
|
|
|
};
|
|
|
SolidParticleSystem.prototype._quaternionRotationYPR = function () {
|
|
@@ -650,7 +698,7 @@ var BABYLON;
|
|
|
},
|
|
|
// Optimizer setters
|
|
|
/**
|
|
|
- * Tells to setParticle() 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.
|
|
|
* Note : the particle rotations aren't stored values, so setting computeParticleRotation to false will prevents the particle to rotate.
|
|
|
*/
|
|
@@ -665,7 +713,7 @@ var BABYLON;
|
|
|
return this._computeParticleColor;
|
|
|
},
|
|
|
/**
|
|
|
- * Tells to setParticle() 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.
|
|
|
* Note : the particle colors are stored values, so setting computeParticleColor to false will keep yet the last colors set.
|
|
|
*/
|
|
@@ -680,7 +728,7 @@ var BABYLON;
|
|
|
return this._computeParticleTexture;
|
|
|
},
|
|
|
/**
|
|
|
- * Tells to setParticle() 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.
|
|
|
* Note : the particle textures are stored values, so setting computeParticleTexture to false will keep yet the last colors set.
|
|
|
*/
|
|
@@ -695,7 +743,7 @@ var BABYLON;
|
|
|
return this._computeParticleVertex;
|
|
|
},
|
|
|
/**
|
|
|
- * Tells to setParticle() 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.
|
|
|
* Note : the particle custom vertex positions aren't stored values.
|
|
|
*/
|
|
@@ -705,6 +753,19 @@ var BABYLON;
|
|
|
enumerable: true,
|
|
|
configurable: true
|
|
|
});
|
|
|
+ Object.defineProperty(SolidParticleSystem.prototype, "computeBoundingBox", {
|
|
|
+ get: function () {
|
|
|
+ return this._computeBoundingBox;
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * Tells to setParticles() to compute or not the mesh bounding box when computing the particle positions.
|
|
|
+ */
|
|
|
+ set: function (val) {
|
|
|
+ this._computeBoundingBox = val;
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
// =======================================================================
|
|
|
// Particle behavior logic
|
|
|
// these following methods may be overwritten by the user to fit his needs
|