babylon.solidParticleSystem.js 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. var BABYLON;
  2. (function (BABYLON) {
  3. /**
  4. * Full documentation here : http://doc.babylonjs.com/overviews/Solid_Particle_System
  5. */
  6. var SolidParticleSystem = (function () {
  7. /**
  8. * Creates a SPS (Solid Particle System) object.
  9. * `name` (String) is the SPS name, this will be the underlying mesh name.
  10. * `scene` (Scene) is the scene in which the SPS is added.
  11. * `updatable` (default true) : if the SPS must be updatable or immutable.
  12. * `isPickable` (default false) : if the solid particles must be pickable.
  13. * `particleIntersection` (default false) : if the solid particle intersections must be computed
  14. */
  15. function SolidParticleSystem(name, scene, options) {
  16. // public members
  17. /**
  18. * The SPS array of Solid Particle objects. Just access each particle as with any classic array.
  19. * Example : var p = SPS.particles[i];
  20. */
  21. this.particles = new Array();
  22. /**
  23. * The SPS total number of particles. Read only. Use SPS.counter instead if you need to set your own value.
  24. */
  25. this.nbParticles = 0;
  26. /**
  27. * If the particles must ever face the camera (default false). Useful for planar particles.
  28. */
  29. this.billboard = false;
  30. /**
  31. * Recompute normals when adding a shape
  32. */
  33. this.recomputeNormals = true;
  34. /**
  35. * This a counter ofr your own usage. It's not set by any SPS functions.
  36. */
  37. this.counter = 0;
  38. /**
  39. * This empty object is intended to store some SPS specific or temporary values in order to lower the Garbage Collector activity.
  40. * Please read : http://doc.babylonjs.com/overviews/Solid_Particle_System#garbage-collector-concerns
  41. */
  42. this.vars = {};
  43. this._positions = new Array();
  44. this._indices = new Array();
  45. this._normals = new Array();
  46. this._colors = new Array();
  47. this._uvs = new Array();
  48. this._index = 0; // indices index
  49. this._updatable = true;
  50. this._pickable = false;
  51. this._isVisibilityBoxLocked = false;
  52. this._alwaysVisible = false;
  53. this._shapeCounter = 0;
  54. this._copy = new BABYLON.SolidParticle(null, null, null, null, null);
  55. this._color = new BABYLON.Color4(0, 0, 0, 0);
  56. this._computeParticleColor = true;
  57. this._computeParticleTexture = true;
  58. this._computeParticleRotation = true;
  59. this._computeParticleVertex = false;
  60. this._computeBoundingBox = false;
  61. this._cam_axisZ = BABYLON.Vector3.Zero();
  62. this._cam_axisY = BABYLON.Vector3.Zero();
  63. this._cam_axisX = BABYLON.Vector3.Zero();
  64. this._axisX = BABYLON.Axis.X;
  65. this._axisY = BABYLON.Axis.Y;
  66. this._axisZ = BABYLON.Axis.Z;
  67. this._camDir = BABYLON.Vector3.Zero();
  68. this._rotMatrix = new BABYLON.Matrix();
  69. this._invertMatrix = new BABYLON.Matrix();
  70. this._rotated = BABYLON.Vector3.Zero();
  71. this._quaternion = new BABYLON.Quaternion();
  72. this._vertex = BABYLON.Vector3.Zero();
  73. this._normal = BABYLON.Vector3.Zero();
  74. this._yaw = 0.0;
  75. this._pitch = 0.0;
  76. this._roll = 0.0;
  77. this._halfroll = 0.0;
  78. this._halfpitch = 0.0;
  79. this._halfyaw = 0.0;
  80. this._sinRoll = 0.0;
  81. this._cosRoll = 0.0;
  82. this._sinPitch = 0.0;
  83. this._cosPitch = 0.0;
  84. this._sinYaw = 0.0;
  85. this._cosYaw = 0.0;
  86. this._w = 0.0;
  87. this._minimum = BABYLON.Tmp.Vector3[0];
  88. this._maximum = BABYLON.Tmp.Vector3[1];
  89. this._scale = BABYLON.Tmp.Vector3[2];
  90. this._translation = BABYLON.Tmp.Vector3[3];
  91. this._particlesIntersect = false;
  92. this.name = name;
  93. this._scene = scene;
  94. this._camera = scene.activeCamera;
  95. this._pickable = options ? options.isPickable : false;
  96. this._particlesIntersect = options ? options.particleIntersection : false;
  97. if (options && options.updatable) {
  98. this._updatable = options.updatable;
  99. }
  100. else {
  101. this._updatable = true;
  102. }
  103. if (this._pickable) {
  104. this.pickedParticles = [];
  105. }
  106. }
  107. /**
  108. * Builds the SPS underlying mesh. Returns a standard Mesh.
  109. * If no model shape was added to the SPS, the returned mesh is just a single triangular plane.
  110. */
  111. SolidParticleSystem.prototype.buildMesh = function () {
  112. if (this.nbParticles === 0) {
  113. var triangle = BABYLON.MeshBuilder.CreateDisc("", { radius: 1, tessellation: 3 }, this._scene);
  114. this.addShape(triangle, 1);
  115. triangle.dispose();
  116. }
  117. this._positions32 = new Float32Array(this._positions);
  118. this._uvs32 = new Float32Array(this._uvs);
  119. this._colors32 = new Float32Array(this._colors);
  120. if (this.recomputeNormals) {
  121. BABYLON.VertexData.ComputeNormals(this._positions32, this._indices, this._normals);
  122. }
  123. this._normals32 = new Float32Array(this._normals);
  124. this._fixedNormal32 = new Float32Array(this._normals);
  125. var vertexData = new BABYLON.VertexData();
  126. vertexData.set(this._positions32, BABYLON.VertexBuffer.PositionKind);
  127. vertexData.indices = this._indices;
  128. vertexData.set(this._normals32, BABYLON.VertexBuffer.NormalKind);
  129. if (this._uvs32) {
  130. vertexData.set(this._uvs32, BABYLON.VertexBuffer.UVKind);
  131. ;
  132. }
  133. if (this._colors32) {
  134. vertexData.set(this._colors32, BABYLON.VertexBuffer.ColorKind);
  135. }
  136. var mesh = new BABYLON.Mesh(this.name, this._scene);
  137. vertexData.applyToMesh(mesh, this._updatable);
  138. this.mesh = mesh;
  139. this.mesh.isPickable = this._pickable;
  140. // free memory
  141. this._positions = null;
  142. this._normals = null;
  143. this._uvs = null;
  144. this._colors = null;
  145. if (!this._updatable) {
  146. this.particles.length = 0;
  147. }
  148. return mesh;
  149. };
  150. /**
  151. * Digests the mesh and generates as many solid particles in the system as wanted. Returns the SPS.
  152. * These particles will have the same geometry than the mesh parts and will be positioned at the same localisation than the mesh original places.
  153. * Thus the particles generated from `digest()` have their property `position` set yet.
  154. * `mesh` ( Mesh ) is the mesh to be digested
  155. * `facetNb` (optional integer, default 1) is the number of mesh facets per particle, this parameter is overriden by the parameter `number` if any
  156. * `delta` (optional integer, default 0) is the random extra number of facets per particle , each particle will have between `facetNb` and `facetNb + delta` facets
  157. * `number` (optional positive integer) is the wanted number of particles : each particle is built with `mesh_total_facets / number` facets
  158. */
  159. SolidParticleSystem.prototype.digest = function (mesh, options) {
  160. var size = (options && options.facetNb) || 1;
  161. var number = (options && options.number);
  162. var delta = (options && options.delta) || 0;
  163. var meshPos = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  164. var meshInd = mesh.getIndices();
  165. var meshUV = mesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
  166. var meshCol = mesh.getVerticesData(BABYLON.VertexBuffer.ColorKind);
  167. var meshNor = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  168. var f = 0; // facet counter
  169. var totalFacets = meshInd.length / 3; // a facet is a triangle, so 3 indices
  170. // compute size from number
  171. if (number) {
  172. number = (number > totalFacets) ? totalFacets : number;
  173. size = Math.round(totalFacets / number);
  174. delta = 0;
  175. }
  176. else {
  177. size = (size > totalFacets) ? totalFacets : size;
  178. }
  179. var facetPos = []; // submesh positions
  180. var facetInd = []; // submesh indices
  181. var facetUV = []; // submesh UV
  182. var facetCol = []; // submesh colors
  183. var barycenter = BABYLON.Tmp.Vector3[0];
  184. var rand;
  185. var sizeO = size;
  186. while (f < totalFacets) {
  187. size = sizeO + Math.floor((1 + delta) * Math.random());
  188. if (f > totalFacets - size) {
  189. size = totalFacets - f;
  190. }
  191. // reset temp arrays
  192. facetPos.length = 0;
  193. facetInd.length = 0;
  194. facetUV.length = 0;
  195. facetCol.length = 0;
  196. // iterate over "size" facets
  197. var fi = 0;
  198. for (var j = f * 3; j < (f + size) * 3; j++) {
  199. facetInd.push(fi);
  200. var i = meshInd[j];
  201. facetPos.push(meshPos[i * 3], meshPos[i * 3 + 1], meshPos[i * 3 + 2]);
  202. if (meshUV) {
  203. facetUV.push(meshUV[i * 2], meshUV[i * 2 + 1]);
  204. }
  205. if (meshCol) {
  206. facetCol.push(meshCol[i * 4], meshCol[i * 4 + 1], meshCol[i * 4 + 2], meshCol[i * 4 + 3]);
  207. }
  208. fi++;
  209. }
  210. // create a model shape for each single particle
  211. var idx = this.nbParticles;
  212. var shape = this._posToShape(facetPos);
  213. var shapeUV = this._uvsToShapeUV(facetUV);
  214. // compute the barycenter of the shape
  215. var v;
  216. for (v = 0; v < shape.length; v++) {
  217. barycenter.addInPlace(shape[v]);
  218. }
  219. barycenter.scaleInPlace(1 / shape.length);
  220. // shift the shape from its barycenter to the origin
  221. for (v = 0; v < shape.length; v++) {
  222. shape[v].subtractInPlace(barycenter);
  223. }
  224. var modelShape = new BABYLON.ModelShape(this._shapeCounter, shape, shapeUV, null, null);
  225. // add the particle in the SPS
  226. this._meshBuilder(this._index, shape, this._positions, facetInd, this._indices, facetUV, this._uvs, facetCol, this._colors, meshNor, this._normals, idx, 0, null);
  227. this._addParticle(idx, this._positions.length, modelShape, this._shapeCounter, 0);
  228. // initialize the particle position
  229. this.particles[this.nbParticles].position.addInPlace(barycenter);
  230. this._index += shape.length;
  231. idx++;
  232. this.nbParticles++;
  233. this._shapeCounter++;
  234. f += size;
  235. }
  236. return this;
  237. };
  238. //reset copy
  239. SolidParticleSystem.prototype._resetCopy = function () {
  240. this._copy.position.x = 0;
  241. this._copy.position.y = 0;
  242. this._copy.position.z = 0;
  243. this._copy.rotation.x = 0;
  244. this._copy.rotation.y = 0;
  245. this._copy.rotation.z = 0;
  246. this._copy.rotationQuaternion = null;
  247. this._copy.scaling.x = 1;
  248. this._copy.scaling.y = 1;
  249. this._copy.scaling.z = 1;
  250. this._copy.uvs.x = 0;
  251. this._copy.uvs.y = 0;
  252. this._copy.uvs.z = 1;
  253. this._copy.uvs.w = 1;
  254. this._copy.color = null;
  255. };
  256. // _meshBuilder : inserts the shape model in the global SPS mesh
  257. SolidParticleSystem.prototype._meshBuilder = function (p, shape, positions, meshInd, indices, meshUV, uvs, meshCol, colors, meshNor, normals, idx, idxInShape, options) {
  258. var i;
  259. var u = 0;
  260. var c = 0;
  261. var n = 0;
  262. this._resetCopy();
  263. if (options && options.positionFunction) {
  264. options.positionFunction(this._copy, idx, idxInShape);
  265. }
  266. if (this._copy.rotationQuaternion) {
  267. this._quaternion.copyFrom(this._copy.rotationQuaternion);
  268. }
  269. else {
  270. this._yaw = this._copy.rotation.y;
  271. this._pitch = this._copy.rotation.x;
  272. this._roll = this._copy.rotation.z;
  273. this._quaternionRotationYPR();
  274. }
  275. this._quaternionToRotationMatrix();
  276. for (i = 0; i < shape.length; i++) {
  277. this._vertex.x = shape[i].x;
  278. this._vertex.y = shape[i].y;
  279. this._vertex.z = shape[i].z;
  280. if (options && options.vertexFunction) {
  281. options.vertexFunction(this._copy, this._vertex, i);
  282. }
  283. this._vertex.x *= this._copy.scaling.x;
  284. this._vertex.y *= this._copy.scaling.y;
  285. this._vertex.z *= this._copy.scaling.z;
  286. BABYLON.Vector3.TransformCoordinatesToRef(this._vertex, this._rotMatrix, this._rotated);
  287. positions.push(this._copy.position.x + this._rotated.x, this._copy.position.y + this._rotated.y, this._copy.position.z + this._rotated.z);
  288. if (meshUV) {
  289. uvs.push((this._copy.uvs.z - this._copy.uvs.x) * meshUV[u] + this._copy.uvs.x, (this._copy.uvs.w - this._copy.uvs.y) * meshUV[u + 1] + this._copy.uvs.y);
  290. u += 2;
  291. }
  292. if (this._copy.color) {
  293. this._color = this._copy.color;
  294. }
  295. else if (meshCol && meshCol[c] !== undefined) {
  296. this._color.r = meshCol[c];
  297. this._color.g = meshCol[c + 1];
  298. this._color.b = meshCol[c + 2];
  299. this._color.a = meshCol[c + 3];
  300. }
  301. else {
  302. this._color.r = 1;
  303. this._color.g = 1;
  304. this._color.b = 1;
  305. this._color.a = 1;
  306. }
  307. colors.push(this._color.r, this._color.g, this._color.b, this._color.a);
  308. c += 4;
  309. if (!this.recomputeNormals && meshNor) {
  310. this._normal.x = meshNor[n];
  311. this._normal.y = meshNor[n + 1];
  312. this._normal.z = meshNor[n + 2];
  313. BABYLON.Vector3.TransformCoordinatesToRef(this._normal, this._rotMatrix, this._normal);
  314. normals.push(this._normal.x, this._normal.y, this._normal.z);
  315. n += 3;
  316. }
  317. }
  318. for (i = 0; i < meshInd.length; i++) {
  319. indices.push(p + meshInd[i]);
  320. }
  321. if (this._pickable) {
  322. var nbfaces = meshInd.length / 3;
  323. for (i = 0; i < nbfaces; i++) {
  324. this.pickedParticles.push({ idx: idx, faceId: i });
  325. }
  326. }
  327. };
  328. // returns a shape array from positions array
  329. SolidParticleSystem.prototype._posToShape = function (positions) {
  330. var shape = [];
  331. for (var i = 0; i < positions.length; i += 3) {
  332. shape.push(new BABYLON.Vector3(positions[i], positions[i + 1], positions[i + 2]));
  333. }
  334. return shape;
  335. };
  336. // returns a shapeUV array from a Vector4 uvs
  337. SolidParticleSystem.prototype._uvsToShapeUV = function (uvs) {
  338. var shapeUV = [];
  339. if (uvs) {
  340. for (var i = 0; i < uvs.length; i++)
  341. shapeUV.push(uvs[i]);
  342. }
  343. return shapeUV;
  344. };
  345. // adds a new particle object in the particles array
  346. SolidParticleSystem.prototype._addParticle = function (idx, idxpos, model, shapeId, idxInShape, bbInfo) {
  347. this.particles.push(new BABYLON.SolidParticle(idx, idxpos, model, shapeId, idxInShape, bbInfo));
  348. };
  349. /**
  350. * Adds some particles to the SPS from the model shape. Returns the shape id.
  351. * Please read the doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#create-an-immutable-sps
  352. * `mesh` is any Mesh object that will be used as a model for the solid particles.
  353. * `nb` (positive integer) the number of particles to be created from this model
  354. * `positionFunction` is an optional javascript function to called for each particle on SPS creation.
  355. * `vertexFunction` is an optional javascript function to called for each vertex of each particle on SPS creation
  356. */
  357. SolidParticleSystem.prototype.addShape = function (mesh, nb, options) {
  358. var meshPos = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  359. var meshInd = mesh.getIndices();
  360. var meshUV = mesh.getVerticesData(BABYLON.VertexBuffer.UVKind);
  361. var meshCol = mesh.getVerticesData(BABYLON.VertexBuffer.ColorKind);
  362. var meshNor = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind);
  363. var bbInfo;
  364. if (this._particlesIntersect) {
  365. bbInfo = mesh.getBoundingInfo();
  366. }
  367. var shape = this._posToShape(meshPos);
  368. var shapeUV = this._uvsToShapeUV(meshUV);
  369. var posfunc = options ? options.positionFunction : null;
  370. var vtxfunc = options ? options.vertexFunction : null;
  371. var modelShape = new BABYLON.ModelShape(this._shapeCounter, shape, shapeUV, posfunc, vtxfunc);
  372. // particles
  373. var idx = this.nbParticles;
  374. for (var i = 0; i < nb; i++) {
  375. this._meshBuilder(this._index, shape, this._positions, meshInd, this._indices, meshUV, this._uvs, meshCol, this._colors, meshNor, this._normals, idx, i, options);
  376. if (this._updatable) {
  377. this._addParticle(idx, this._positions.length, modelShape, this._shapeCounter, i, bbInfo);
  378. }
  379. this._index += shape.length;
  380. idx++;
  381. }
  382. this.nbParticles += nb;
  383. this._shapeCounter++;
  384. return this._shapeCounter - 1;
  385. };
  386. // rebuilds a particle back to its just built status : if needed, recomputes the custom positions and vertices
  387. SolidParticleSystem.prototype._rebuildParticle = function (particle) {
  388. this._resetCopy();
  389. if (particle._model._positionFunction) {
  390. particle._model._positionFunction(this._copy, particle.idx, particle.idxInShape);
  391. }
  392. if (this._copy.rotationQuaternion) {
  393. this._quaternion.copyFrom(this._copy.rotationQuaternion);
  394. }
  395. else {
  396. this._yaw = this._copy.rotation.y;
  397. this._pitch = this._copy.rotation.x;
  398. this._roll = this._copy.rotation.z;
  399. this._quaternionRotationYPR();
  400. }
  401. this._quaternionToRotationMatrix();
  402. this._shape = particle._model._shape;
  403. for (var pt = 0; pt < this._shape.length; pt++) {
  404. this._vertex.x = this._shape[pt].x;
  405. this._vertex.y = this._shape[pt].y;
  406. this._vertex.z = this._shape[pt].z;
  407. if (particle._model._vertexFunction) {
  408. particle._model._vertexFunction(this._copy, this._vertex, pt); // recall to stored vertexFunction
  409. }
  410. this._vertex.x *= this._copy.scaling.x;
  411. this._vertex.y *= this._copy.scaling.y;
  412. this._vertex.z *= this._copy.scaling.z;
  413. BABYLON.Vector3.TransformCoordinatesToRef(this._vertex, this._rotMatrix, this._rotated);
  414. this._positions32[particle._pos + pt * 3] = this._copy.position.x + this._rotated.x;
  415. this._positions32[particle._pos + pt * 3 + 1] = this._copy.position.y + this._rotated.y;
  416. this._positions32[particle._pos + pt * 3 + 2] = this._copy.position.z + this._rotated.z;
  417. }
  418. particle.position.x = 0.0;
  419. particle.position.y = 0.0;
  420. particle.position.z = 0.0;
  421. particle.rotation.x = 0.0;
  422. particle.rotation.y = 0.0;
  423. particle.rotation.z = 0.0;
  424. particle.rotationQuaternion = null;
  425. particle.scaling.x = 1.0;
  426. particle.scaling.y = 1.0;
  427. particle.scaling.z = 1.0;
  428. };
  429. /**
  430. * Rebuilds the whole mesh and updates the VBO : custom positions and vertices are recomputed if needed.
  431. */
  432. SolidParticleSystem.prototype.rebuildMesh = function () {
  433. for (var p = 0; p < this.particles.length; p++) {
  434. this._rebuildParticle(this.particles[p]);
  435. }
  436. this.mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, this._positions32, false, false);
  437. };
  438. /**
  439. * Sets all the particles : this method actually really updates the mesh according to the particle positions, rotations, colors, textures, etc.
  440. * This method calls `updateParticle()` for each particle of the SPS.
  441. * For an animated SPS, it is usually called within the render loop.
  442. * @param start The particle index in the particle array where to start to compute the particle property values _(default 0)_
  443. * @param end The particle index in the particle array where to stop to compute the particle property values _(default nbParticle - 1)_
  444. * @param update If the mesh must be finally updated on this call after all the particle computations _(default true)_
  445. */
  446. SolidParticleSystem.prototype.setParticles = function (start, end, update) {
  447. if (start === void 0) { start = 0; }
  448. if (end === void 0) { end = this.nbParticles - 1; }
  449. if (update === void 0) { update = true; }
  450. if (!this._updatable) {
  451. return;
  452. }
  453. // custom beforeUpdate
  454. this.beforeUpdateParticles(start, end, update);
  455. this._cam_axisX.x = 1.0;
  456. this._cam_axisX.y = 0.0;
  457. this._cam_axisX.z = 0.0;
  458. this._cam_axisY.x = 0.0;
  459. this._cam_axisY.y = 1.0;
  460. this._cam_axisY.z = 0.0;
  461. this._cam_axisZ.x = 0.0;
  462. this._cam_axisZ.y = 0.0;
  463. this._cam_axisZ.z = 1.0;
  464. // if the particles will always face the camera
  465. if (this.billboard) {
  466. // compute the camera position and un-rotate it by the current mesh rotation
  467. if (this.mesh._worldMatrix.decompose(this._scale, this._quaternion, this._translation)) {
  468. this._quaternionToRotationMatrix();
  469. this._rotMatrix.invertToRef(this._invertMatrix);
  470. this._camera._currentTarget.subtractToRef(this._camera.globalPosition, this._camDir);
  471. BABYLON.Vector3.TransformCoordinatesToRef(this._camDir, this._invertMatrix, this._cam_axisZ);
  472. this._cam_axisZ.normalize();
  473. // set two orthogonal vectors (_cam_axisX and and _cam_axisY) to the rotated camDir axis (_cam_axisZ)
  474. BABYLON.Vector3.CrossToRef(this._cam_axisZ, this._axisX, this._cam_axisY);
  475. BABYLON.Vector3.CrossToRef(this._cam_axisY, this._cam_axisZ, this._cam_axisX);
  476. this._cam_axisY.normalize();
  477. this._cam_axisX.normalize();
  478. }
  479. }
  480. BABYLON.Matrix.IdentityToRef(this._rotMatrix);
  481. var idx = 0;
  482. var index = 0;
  483. var colidx = 0;
  484. var colorIndex = 0;
  485. var uvidx = 0;
  486. var uvIndex = 0;
  487. var pt = 0;
  488. if (this._computeBoundingBox) {
  489. BABYLON.Vector3.FromFloatsToRef(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, this._minimum);
  490. BABYLON.Vector3.FromFloatsToRef(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE, this._maximum);
  491. }
  492. // particle loop
  493. end = (end > this.nbParticles - 1) ? this.nbParticles - 1 : end;
  494. for (var p = start; p <= end; p++) {
  495. this._particle = this.particles[p];
  496. this._shape = this._particle._model._shape;
  497. this._shapeUV = this._particle._model._shapeUV;
  498. // call to custom user function to update the particle properties
  499. this.updateParticle(this._particle);
  500. if (this._particle.isVisible) {
  501. // particle rotation matrix
  502. if (this.billboard) {
  503. this._particle.rotation.x = 0.0;
  504. this._particle.rotation.y = 0.0;
  505. }
  506. if (this._computeParticleRotation || this.billboard) {
  507. if (this._particle.rotationQuaternion) {
  508. this._quaternion.copyFrom(this._particle.rotationQuaternion);
  509. }
  510. else {
  511. this._yaw = this._particle.rotation.y;
  512. this._pitch = this._particle.rotation.x;
  513. this._roll = this._particle.rotation.z;
  514. this._quaternionRotationYPR();
  515. }
  516. this._quaternionToRotationMatrix();
  517. }
  518. // particle vertex loop
  519. for (pt = 0; pt < this._shape.length; pt++) {
  520. idx = index + pt * 3;
  521. colidx = colorIndex + pt * 4;
  522. uvidx = uvIndex + pt * 2;
  523. this._vertex.x = this._shape[pt].x;
  524. this._vertex.y = this._shape[pt].y;
  525. this._vertex.z = this._shape[pt].z;
  526. if (this._computeParticleVertex) {
  527. this.updateParticleVertex(this._particle, this._vertex, pt);
  528. }
  529. // positions
  530. this._vertex.x *= this._particle.scaling.x;
  531. this._vertex.y *= this._particle.scaling.y;
  532. this._vertex.z *= this._particle.scaling.z;
  533. this._w = (this._vertex.x * this._rotMatrix.m[3]) + (this._vertex.y * this._rotMatrix.m[7]) + (this._vertex.z * this._rotMatrix.m[11]) + this._rotMatrix.m[15];
  534. this._rotated.x = ((this._vertex.x * this._rotMatrix.m[0]) + (this._vertex.y * this._rotMatrix.m[4]) + (this._vertex.z * this._rotMatrix.m[8]) + this._rotMatrix.m[12]) / this._w;
  535. this._rotated.y = ((this._vertex.x * this._rotMatrix.m[1]) + (this._vertex.y * this._rotMatrix.m[5]) + (this._vertex.z * this._rotMatrix.m[9]) + this._rotMatrix.m[13]) / this._w;
  536. this._rotated.z = ((this._vertex.x * this._rotMatrix.m[2]) + (this._vertex.y * this._rotMatrix.m[6]) + (this._vertex.z * this._rotMatrix.m[10]) + this._rotMatrix.m[14]) / this._w;
  537. 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;
  538. 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;
  539. 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;
  540. if (this._computeBoundingBox) {
  541. if (this._positions32[idx] < this._minimum.x) {
  542. this._minimum.x = this._positions32[idx];
  543. }
  544. if (this._positions32[idx] > this._maximum.x) {
  545. this._maximum.x = this._positions32[idx];
  546. }
  547. if (this._positions32[idx + 1] < this._minimum.y) {
  548. this._minimum.y = this._positions32[idx + 1];
  549. }
  550. if (this._positions32[idx + 1] > this._maximum.y) {
  551. this._maximum.y = this._positions32[idx + 1];
  552. }
  553. if (this._positions32[idx + 2] < this._minimum.z) {
  554. this._minimum.z = this._positions32[idx + 2];
  555. }
  556. if (this._positions32[idx + 2] > this._maximum.z) {
  557. this._maximum.z = this._positions32[idx + 2];
  558. }
  559. }
  560. // normals : if the particles can't be morphed then just rotate the normals, what if much more faster than ComputeNormals()
  561. if (!this._computeParticleVertex) {
  562. this._normal.x = this._fixedNormal32[idx];
  563. this._normal.y = this._fixedNormal32[idx + 1];
  564. this._normal.z = this._fixedNormal32[idx + 2];
  565. this._w = (this._normal.x * this._rotMatrix.m[3]) + (this._normal.y * this._rotMatrix.m[7]) + (this._normal.z * this._rotMatrix.m[11]) + this._rotMatrix.m[15];
  566. this._rotated.x = ((this._normal.x * this._rotMatrix.m[0]) + (this._normal.y * this._rotMatrix.m[4]) + (this._normal.z * this._rotMatrix.m[8]) + this._rotMatrix.m[12]) / this._w;
  567. this._rotated.y = ((this._normal.x * this._rotMatrix.m[1]) + (this._normal.y * this._rotMatrix.m[5]) + (this._normal.z * this._rotMatrix.m[9]) + this._rotMatrix.m[13]) / this._w;
  568. this._rotated.z = ((this._normal.x * this._rotMatrix.m[2]) + (this._normal.y * this._rotMatrix.m[6]) + (this._normal.z * this._rotMatrix.m[10]) + this._rotMatrix.m[14]) / this._w;
  569. this._normals32[idx] = this._cam_axisX.x * this._rotated.x + this._cam_axisY.x * this._rotated.y + this._cam_axisZ.x * this._rotated.z;
  570. this._normals32[idx + 1] = this._cam_axisX.y * this._rotated.x + this._cam_axisY.y * this._rotated.y + this._cam_axisZ.y * this._rotated.z;
  571. this._normals32[idx + 2] = this._cam_axisX.z * this._rotated.x + this._cam_axisY.z * this._rotated.y + this._cam_axisZ.z * this._rotated.z;
  572. }
  573. if (this._computeParticleColor) {
  574. this._colors32[colidx] = this._particle.color.r;
  575. this._colors32[colidx + 1] = this._particle.color.g;
  576. this._colors32[colidx + 2] = this._particle.color.b;
  577. this._colors32[colidx + 3] = this._particle.color.a;
  578. }
  579. if (this._computeParticleTexture) {
  580. this._uvs32[uvidx] = this._shapeUV[pt * 2] * (this._particle.uvs.z - this._particle.uvs.x) + this._particle.uvs.x;
  581. this._uvs32[uvidx + 1] = this._shapeUV[pt * 2 + 1] * (this._particle.uvs.w - this._particle.uvs.y) + this._particle.uvs.y;
  582. }
  583. }
  584. }
  585. else {
  586. for (pt = 0; pt < this._shape.length; pt++) {
  587. idx = index + pt * 3;
  588. colidx = colorIndex + pt * 4;
  589. uvidx = uvIndex + pt * 2;
  590. this._positions32[idx] = this._camera.position.x;
  591. this._positions32[idx + 1] = this._camera.position.y;
  592. this._positions32[idx + 2] = this._camera.position.z;
  593. this._normals32[idx] = 0.0;
  594. this._normals32[idx + 1] = 0.0;
  595. this._normals32[idx + 2] = 0.0;
  596. if (this._computeParticleColor) {
  597. this._colors32[colidx] = this._particle.color.r;
  598. this._colors32[colidx + 1] = this._particle.color.g;
  599. this._colors32[colidx + 2] = this._particle.color.b;
  600. this._colors32[colidx + 3] = this._particle.color.a;
  601. }
  602. if (this._computeParticleTexture) {
  603. this._uvs32[uvidx] = this._shapeUV[pt * 2] * (this._particle.uvs.z - this._particle.uvs.x) + this._particle.uvs.x;
  604. this._uvs32[uvidx + 1] = this._shapeUV[pt * 2 + 1] * (this._particle.uvs.w - this._particle.uvs.y) + this._particle.uvs.y;
  605. }
  606. }
  607. }
  608. // if the particle intersections must be computed : update the bbInfo
  609. if (this._particlesIntersect) {
  610. var bInfo = this._particle._boundingInfo;
  611. var bBox = bInfo.boundingBox;
  612. var bSphere = bInfo.boundingSphere;
  613. // place, scale and rotate the particle bbox within the SPS local system
  614. for (var b = 0; b < bBox.vectors.length; b++) {
  615. if (this._particle.isVisible) {
  616. this._vertex.x = this._particle._modelBoundingInfo.boundingBox.vectors[b].x * this._particle.scaling.x;
  617. this._vertex.y = this._particle._modelBoundingInfo.boundingBox.vectors[b].y * this._particle.scaling.y;
  618. this._vertex.z = this._particle._modelBoundingInfo.boundingBox.vectors[b].z * this._particle.scaling.z;
  619. this._w = (this._vertex.x * this._rotMatrix.m[3]) + (this._vertex.y * this._rotMatrix.m[7]) + (this._vertex.z * this._rotMatrix.m[11]) + this._rotMatrix.m[15];
  620. this._rotated.x = ((this._vertex.x * this._rotMatrix.m[0]) + (this._vertex.y * this._rotMatrix.m[4]) + (this._vertex.z * this._rotMatrix.m[8]) + this._rotMatrix.m[12]) / this._w;
  621. this._rotated.y = ((this._vertex.x * this._rotMatrix.m[1]) + (this._vertex.y * this._rotMatrix.m[5]) + (this._vertex.z * this._rotMatrix.m[9]) + this._rotMatrix.m[13]) / this._w;
  622. this._rotated.z = ((this._vertex.x * this._rotMatrix.m[2]) + (this._vertex.y * this._rotMatrix.m[6]) + (this._vertex.z * this._rotMatrix.m[10]) + this._rotMatrix.m[14]) / this._w;
  623. bBox.vectors[b].x = 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;
  624. bBox.vectors[b].y = 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;
  625. bBox.vectors[b].z = 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;
  626. }
  627. else {
  628. bBox.vectors[b].x = this._camera.position.x;
  629. bBox.vectors[b].y = this._camera.position.y;
  630. bBox.vectors[b].z = this._camera.position.z;
  631. }
  632. }
  633. // place and scale the particle bouding sphere in the SPS local system
  634. if (this._particle.isVisible) {
  635. this._minimum.x = this._particle._modelBoundingInfo.minimum.x * this._particle.scaling.x;
  636. this._minimum.y = this._particle._modelBoundingInfo.minimum.y * this._particle.scaling.y;
  637. this._minimum.z = this._particle._modelBoundingInfo.minimum.z * this._particle.scaling.z;
  638. this._maximum.x = this._particle._modelBoundingInfo.maximum.x * this._particle.scaling.x;
  639. this._maximum.y = this._particle._modelBoundingInfo.maximum.y * this._particle.scaling.y;
  640. this._maximum.z = this._particle._modelBoundingInfo.maximum.z * this._particle.scaling.z;
  641. bSphere.center.x = this._particle.position.x + (this._minimum.x + this._maximum.x) * 0.5;
  642. bSphere.center.y = this._particle.position.y + (this._minimum.y + this._maximum.y) * 0.5;
  643. bSphere.center.z = this._particle.position.z + (this._minimum.z + this._maximum.z) * 0.5;
  644. bSphere.radius = BABYLON.Vector3.Distance(this._minimum, this._maximum) * 0.5;
  645. }
  646. else {
  647. bSphere.center.x = this._camera.position.x;
  648. bSphere.center.y = this._camera.position.x;
  649. bSphere.center.z = this._camera.position.x;
  650. bSphere.radius = 0.0;
  651. }
  652. // then update the bbox and the bsphere into the world system
  653. bBox._update(this.mesh.getWorldMatrix());
  654. bSphere._update(this.mesh.getWorldMatrix());
  655. }
  656. // increment indexes for the next particle
  657. index = idx + 3;
  658. colorIndex = colidx + 4;
  659. uvIndex = uvidx + 2;
  660. }
  661. // if the VBO must be updated
  662. if (update) {
  663. if (this._computeParticleColor) {
  664. this.mesh.updateVerticesData(BABYLON.VertexBuffer.ColorKind, this._colors32, false, false);
  665. }
  666. if (this._computeParticleTexture) {
  667. this.mesh.updateVerticesData(BABYLON.VertexBuffer.UVKind, this._uvs32, false, false);
  668. }
  669. this.mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, this._positions32, false, false);
  670. if (!this.mesh.areNormalsFrozen) {
  671. if (this._computeParticleVertex) {
  672. // recompute the normals only if the particles can be morphed, update then also the normal reference array _fixedNormal32[]
  673. BABYLON.VertexData.ComputeNormals(this._positions32, this._indices, this._normals32);
  674. for (var i = 0; i < this._normals32.length; i++) {
  675. this._fixedNormal32[i] = this._normals32[i];
  676. }
  677. }
  678. this.mesh.updateVerticesData(BABYLON.VertexBuffer.NormalKind, this._normals32, false, false);
  679. }
  680. }
  681. if (this._computeBoundingBox) {
  682. this.mesh._boundingInfo = new BABYLON.BoundingInfo(this._minimum, this._maximum);
  683. this.mesh._boundingInfo.update(this.mesh._worldMatrix);
  684. }
  685. this.afterUpdateParticles(start, end, update);
  686. };
  687. SolidParticleSystem.prototype._quaternionRotationYPR = function () {
  688. this._halfroll = this._roll * 0.5;
  689. this._halfpitch = this._pitch * 0.5;
  690. this._halfyaw = this._yaw * 0.5;
  691. this._sinRoll = Math.sin(this._halfroll);
  692. this._cosRoll = Math.cos(this._halfroll);
  693. this._sinPitch = Math.sin(this._halfpitch);
  694. this._cosPitch = Math.cos(this._halfpitch);
  695. this._sinYaw = Math.sin(this._halfyaw);
  696. this._cosYaw = Math.cos(this._halfyaw);
  697. this._quaternion.x = (this._cosYaw * this._sinPitch * this._cosRoll) + (this._sinYaw * this._cosPitch * this._sinRoll);
  698. this._quaternion.y = (this._sinYaw * this._cosPitch * this._cosRoll) - (this._cosYaw * this._sinPitch * this._sinRoll);
  699. this._quaternion.z = (this._cosYaw * this._cosPitch * this._sinRoll) - (this._sinYaw * this._sinPitch * this._cosRoll);
  700. this._quaternion.w = (this._cosYaw * this._cosPitch * this._cosRoll) + (this._sinYaw * this._sinPitch * this._sinRoll);
  701. };
  702. SolidParticleSystem.prototype._quaternionToRotationMatrix = function () {
  703. this._rotMatrix.m[0] = 1.0 - (2.0 * (this._quaternion.y * this._quaternion.y + this._quaternion.z * this._quaternion.z));
  704. this._rotMatrix.m[1] = 2.0 * (this._quaternion.x * this._quaternion.y + this._quaternion.z * this._quaternion.w);
  705. this._rotMatrix.m[2] = 2.0 * (this._quaternion.z * this._quaternion.x - this._quaternion.y * this._quaternion.w);
  706. this._rotMatrix.m[3] = 0;
  707. this._rotMatrix.m[4] = 2.0 * (this._quaternion.x * this._quaternion.y - this._quaternion.z * this._quaternion.w);
  708. this._rotMatrix.m[5] = 1.0 - (2.0 * (this._quaternion.z * this._quaternion.z + this._quaternion.x * this._quaternion.x));
  709. this._rotMatrix.m[6] = 2.0 * (this._quaternion.y * this._quaternion.z + this._quaternion.x * this._quaternion.w);
  710. this._rotMatrix.m[7] = 0;
  711. this._rotMatrix.m[8] = 2.0 * (this._quaternion.z * this._quaternion.x + this._quaternion.y * this._quaternion.w);
  712. this._rotMatrix.m[9] = 2.0 * (this._quaternion.y * this._quaternion.z - this._quaternion.x * this._quaternion.w);
  713. this._rotMatrix.m[10] = 1.0 - (2.0 * (this._quaternion.y * this._quaternion.y + this._quaternion.x * this._quaternion.x));
  714. this._rotMatrix.m[11] = 0;
  715. this._rotMatrix.m[12] = 0;
  716. this._rotMatrix.m[13] = 0;
  717. this._rotMatrix.m[14] = 0;
  718. this._rotMatrix.m[15] = 1.0;
  719. };
  720. /**
  721. * Disposes the SPS
  722. */
  723. SolidParticleSystem.prototype.dispose = function () {
  724. this.mesh.dispose();
  725. this.vars = null;
  726. // drop references to internal big arrays for the GC
  727. this._positions = null;
  728. this._indices = null;
  729. this._normals = null;
  730. this._uvs = null;
  731. this._colors = null;
  732. this._positions32 = null;
  733. this._normals32 = null;
  734. this._fixedNormal32 = null;
  735. this._uvs32 = null;
  736. this._colors32 = null;
  737. this.pickedParticles = null;
  738. };
  739. /**
  740. * Visibilty helper : Recomputes the visible size according to the mesh bounding box
  741. * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#sps-visibility
  742. */
  743. SolidParticleSystem.prototype.refreshVisibleSize = function () {
  744. if (!this._isVisibilityBoxLocked) {
  745. this.mesh.refreshBoundingInfo();
  746. }
  747. };
  748. /**
  749. * Visibility helper : Sets the size of a visibility box, this sets the underlying mesh bounding box.
  750. * @param size the size (float) of the visibility box
  751. * note : this doesn't lock the SPS mesh bounding box.
  752. * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#sps-visibility
  753. */
  754. SolidParticleSystem.prototype.setVisibilityBox = function (size) {
  755. var vis = size / 2;
  756. this.mesh._boundingInfo = new BABYLON.BoundingInfo(new BABYLON.Vector3(-vis, -vis, -vis), new BABYLON.Vector3(vis, vis, vis));
  757. };
  758. Object.defineProperty(SolidParticleSystem.prototype, "isAlwaysVisible", {
  759. // getter and setter
  760. get: function () {
  761. return this._alwaysVisible;
  762. },
  763. /**
  764. * Sets the SPS as always visible or not
  765. * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#sps-visibility
  766. */
  767. set: function (val) {
  768. this._alwaysVisible = val;
  769. this.mesh.alwaysSelectAsActiveMesh = val;
  770. },
  771. enumerable: true,
  772. configurable: true
  773. });
  774. Object.defineProperty(SolidParticleSystem.prototype, "isVisibilityBoxLocked", {
  775. get: function () {
  776. return this._isVisibilityBoxLocked;
  777. },
  778. /**
  779. * Sets the SPS visibility box as locked or not. This enables/disables the underlying mesh bounding box updates.
  780. * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#sps-visibility
  781. */
  782. set: function (val) {
  783. this._isVisibilityBoxLocked = val;
  784. this.mesh.getBoundingInfo().isLocked = val;
  785. },
  786. enumerable: true,
  787. configurable: true
  788. });
  789. Object.defineProperty(SolidParticleSystem.prototype, "computeParticleRotation", {
  790. // getters
  791. get: function () {
  792. return this._computeParticleRotation;
  793. },
  794. // Optimizer setters
  795. /**
  796. * Tells to `setParticles()` to compute the particle rotations or not.
  797. * Default value : true. The SPS is faster when it's set to false.
  798. * Note : the particle rotations aren't stored values, so setting `computeParticleRotation` to false will prevents the particle to rotate.
  799. */
  800. set: function (val) {
  801. this._computeParticleRotation = val;
  802. },
  803. enumerable: true,
  804. configurable: true
  805. });
  806. Object.defineProperty(SolidParticleSystem.prototype, "computeParticleColor", {
  807. get: function () {
  808. return this._computeParticleColor;
  809. },
  810. /**
  811. * Tells to `setParticles()` to compute the particle colors or not.
  812. * Default value : true. The SPS is faster when it's set to false.
  813. * Note : the particle colors are stored values, so setting `computeParticleColor` to false will keep yet the last colors set.
  814. */
  815. set: function (val) {
  816. this._computeParticleColor = val;
  817. },
  818. enumerable: true,
  819. configurable: true
  820. });
  821. Object.defineProperty(SolidParticleSystem.prototype, "computeParticleTexture", {
  822. get: function () {
  823. return this._computeParticleTexture;
  824. },
  825. /**
  826. * Tells to `setParticles()` to compute the particle textures or not.
  827. * Default value : true. The SPS is faster when it's set to false.
  828. * Note : the particle textures are stored values, so setting `computeParticleTexture` to false will keep yet the last colors set.
  829. */
  830. set: function (val) {
  831. this._computeParticleTexture = val;
  832. },
  833. enumerable: true,
  834. configurable: true
  835. });
  836. Object.defineProperty(SolidParticleSystem.prototype, "computeParticleVertex", {
  837. get: function () {
  838. return this._computeParticleVertex;
  839. },
  840. /**
  841. * Tells to `setParticles()` to call the vertex function for each vertex of each particle, or not.
  842. * Default value : false. The SPS is faster when it's set to false.
  843. * Note : the particle custom vertex positions aren't stored values.
  844. */
  845. set: function (val) {
  846. this._computeParticleVertex = val;
  847. },
  848. enumerable: true,
  849. configurable: true
  850. });
  851. Object.defineProperty(SolidParticleSystem.prototype, "computeBoundingBox", {
  852. get: function () {
  853. return this._computeBoundingBox;
  854. },
  855. /**
  856. * Tells to `setParticles()` to compute or not the mesh bounding box when computing the particle positions.
  857. */
  858. set: function (val) {
  859. this._computeBoundingBox = val;
  860. },
  861. enumerable: true,
  862. configurable: true
  863. });
  864. // =======================================================================
  865. // Particle behavior logic
  866. // these following methods may be overwritten by the user to fit his needs
  867. /**
  868. * This function does nothing. It may be overwritten to set all the particle first values.
  869. * The SPS doesn't call this function, you may have to call it by your own.
  870. * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#particle-management
  871. */
  872. SolidParticleSystem.prototype.initParticles = function () {
  873. };
  874. /**
  875. * This function does nothing. It may be overwritten to recycle a particle.
  876. * The SPS doesn't call this function, you may have to call it by your own.
  877. * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#particle-management
  878. */
  879. SolidParticleSystem.prototype.recycleParticle = function (particle) {
  880. return particle;
  881. };
  882. /**
  883. * Updates a particle : this function should be overwritten by the user.
  884. * It is called on each particle by `setParticles()`. This is the place to code each particle behavior.
  885. * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#particle-management
  886. * ex : just set a particle position or velocity and recycle conditions
  887. */
  888. SolidParticleSystem.prototype.updateParticle = function (particle) {
  889. return particle;
  890. };
  891. /**
  892. * Updates a vertex of a particle : it can be overwritten by the user.
  893. * This will be called on each vertex particle by `setParticles()` if `computeParticleVertex` is set to true only.
  894. * @param particle the current particle
  895. * @param vertex the current index of the current particle
  896. * @param pt the index of the current vertex in the particle shape
  897. * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#update-each-particle-shape
  898. * ex : just set a vertex particle position
  899. */
  900. SolidParticleSystem.prototype.updateParticleVertex = function (particle, vertex, pt) {
  901. return vertex;
  902. };
  903. /**
  904. * This will be called before any other treatment by `setParticles()` and will be passed three parameters.
  905. * This does nothing and may be overwritten by the user.
  906. * @param start the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
  907. * @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
  908. * @param update the boolean update value actually passed to setParticles()
  909. */
  910. SolidParticleSystem.prototype.beforeUpdateParticles = function (start, stop, update) {
  911. };
  912. /**
  913. * This will be called by `setParticles()` after all the other treatments and just before the actual mesh update.
  914. * This will be passed three parameters.
  915. * This does nothing and may be overwritten by the user.
  916. * @param start the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
  917. * @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
  918. * @param update the boolean update value actually passed to setParticles()
  919. */
  920. SolidParticleSystem.prototype.afterUpdateParticles = function (start, stop, update) {
  921. };
  922. return SolidParticleSystem;
  923. }());
  924. BABYLON.SolidParticleSystem = SolidParticleSystem;
  925. })(BABYLON || (BABYLON = {}));