babylon.solidParticleSystem.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. module BABYLON {
  2. export class SolidParticleSystem implements IDisposable {
  3. // public members
  4. public particles: SolidParticle[] = new Array<SolidParticle>();
  5. public nbParticles: number = 0;
  6. public billboard: boolean = false;
  7. public counter: number = 0;
  8. public name: string;
  9. public mesh: Mesh;
  10. // private members
  11. private _scene: Scene;
  12. private _positions: number[] = new Array<number>();
  13. private _indices: number[] = new Array<number>();
  14. private _normals: number[] = new Array<number>();
  15. private _colors: number[] = new Array<number>();
  16. private _uvs: number[] = new Array<number>();
  17. private _positions32: Float32Array;
  18. private _normals32: Float32Array;
  19. private _colors32: Float32Array;
  20. private _uvs32: Float32Array;
  21. private _index: number = 0; // indices index
  22. private _updatable: boolean = true;
  23. private _shapeCounter: number = 0;
  24. private _copy: SolidParticle = new SolidParticle(null, null, null, null, null);
  25. private _shape: Vector3[];
  26. private _shapeUV: number[];
  27. private _color: Color4 = new Color4(0, 0, 0, 0);
  28. private _computeParticleColor: boolean = true;
  29. private _computeParticleTexture: boolean = true;
  30. private _computeParticleRotation: boolean = true;
  31. private _computeParticleVertex: boolean = false;
  32. private _cam_axisZ: Vector3 = Vector3.Zero();
  33. private _cam_axisY: Vector3 = Vector3.Zero();
  34. private _cam_axisX: Vector3 = Vector3.Zero();
  35. private _axisX: Vector3 = Axis.X;
  36. private _axisY: Vector3 = Axis.Y;
  37. private _axisZ: Vector3 = Axis.Z;
  38. private _camera: Camera;
  39. private _particle: SolidParticle;
  40. private _fakeCamPos: Vector3 = Vector3.Zero();
  41. private _rotMatrix: Matrix = new Matrix();
  42. private _invertedMatrix: Matrix = new Matrix();
  43. private _rotated: Vector3 = Vector3.Zero();
  44. private _quaternion: Quaternion = new Quaternion();
  45. private _vertex: Vector3 = Vector3.Zero();
  46. private _yaw: number = 0.0;
  47. private _pitch: number = 0.0;
  48. private _roll: number = 0.0;
  49. private _halfroll: number = 0.0;
  50. private _halfpitch: number = 0.0;
  51. private _halfyaw: number = 0.0;
  52. private _sinRoll: number = 0.0;
  53. private _cosRoll: number = 0.0;
  54. private _sinPitch: number = 0.0;
  55. private _cosPitch: number = 0.0;
  56. private _sinYaw: number = 0.0;
  57. private _cosYaw: number = 0.0;
  58. constructor(name: string, scene: Scene, options?: {updatable?: boolean}) {
  59. this.name = name;
  60. this._scene = scene;
  61. this._camera = scene.activeCamera;
  62. if (options && options.updatable) {
  63. this._updatable = options.updatable;
  64. } else {
  65. this._updatable = true;
  66. }
  67. }
  68. // build the SPS mesh : returns the mesh
  69. public buildMesh(): Mesh {
  70. if (this.nbParticles === 0) {
  71. var triangle = MeshBuilder.CreateDisc("", { radius: 1, tessellation: 3 }, this._scene);
  72. this.addShape(triangle, 1);
  73. triangle.dispose();
  74. }
  75. this._positions32 = new Float32Array(this._positions);
  76. this._uvs32 = new Float32Array(this._uvs);
  77. this._colors32 = new Float32Array(this._colors);
  78. VertexData.ComputeNormals(this._positions32, this._indices, this._normals);
  79. this._normals32 = new Float32Array(this._normals);
  80. var vertexData = new VertexData();
  81. vertexData.set(this._positions32, VertexBuffer.PositionKind);
  82. vertexData.indices = this._indices;
  83. vertexData.set(this._normals32, VertexBuffer.NormalKind);
  84. if (this._uvs32) {
  85. vertexData.set(this._uvs32, VertexBuffer.UVKind);;
  86. }
  87. if (this._colors32) {
  88. vertexData.set(this._colors32, VertexBuffer.ColorKind);
  89. }
  90. var mesh = new Mesh(name, this._scene);
  91. vertexData.applyToMesh(mesh, this._updatable);
  92. this.mesh = mesh;
  93. // free memory
  94. this._positions = null;
  95. this._normals = null;
  96. this._uvs = null;
  97. this._colors = null;
  98. if (!this._updatable) {
  99. this.particles.length = 0;
  100. }
  101. return mesh;
  102. }
  103. //reset copy
  104. private _resetCopy() {
  105. this._copy.position.x = 0;
  106. this._copy.position.y = 0;
  107. this._copy.position.z = 0;
  108. this._copy.rotation.x = 0;
  109. this._copy.rotation.y = 0;
  110. this._copy.rotation.z = 0;
  111. this._copy.quaternion = null;
  112. this._copy.scale.x = 1;
  113. this._copy.scale.y = 1;
  114. this._copy.scale.z = 1;
  115. this._copy.uvs.x = 0;
  116. this._copy.uvs.y = 0;
  117. this._copy.uvs.z = 1;
  118. this._copy.uvs.w = 1;
  119. this._copy.color = null;
  120. }
  121. // _meshBuilder : inserts the shape model in the global SPS mesh
  122. private _meshBuilder(p, shape, positions, meshInd, indices, meshUV, uvs, meshCol, colors, idx, idxInShape, options): void {
  123. var i;
  124. var u = 0;
  125. var c = 0;
  126. this._resetCopy();
  127. if (options && options.positionFunction) { // call to custom positionFunction
  128. options.positionFunction(this._copy, idx, idxInShape);
  129. }
  130. if (this._copy.quaternion) {
  131. this._quaternion.x = this._copy.quaternion.x;
  132. this._quaternion.y = this._copy.quaternion.y;
  133. this._quaternion.z = this._copy.quaternion.z;
  134. this._quaternion.w = this._copy.quaternion.w;
  135. } else {
  136. this._yaw = this._copy.rotation.y;
  137. this._pitch = this._copy.rotation.x;
  138. this._roll = this._copy.rotation.z;
  139. this._quaternionRotationYPR();
  140. }
  141. this._quaternionToRotationMatrix();
  142. for (i = 0; i < shape.length; i++) {
  143. this._vertex.x = shape[i].x;
  144. this._vertex.y = shape[i].y;
  145. this._vertex.z = shape[i].z;
  146. if (options && options.vertexFunction) {
  147. options.vertexFunction(this._copy, this._vertex, i);
  148. }
  149. this._vertex.x *= this._copy.scale.x;
  150. this._vertex.y *= this._copy.scale.y;
  151. this._vertex.z *= this._copy.scale.z;
  152. Vector3.TransformCoordinatesToRef(this._vertex, this._rotMatrix, this._rotated);
  153. positions.push(this._copy.position.x + this._rotated.x, this._copy.position.y + this._rotated.y, this._copy.position.z + this._rotated.z);
  154. if (meshUV) {
  155. 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);
  156. u += 2;
  157. }
  158. if (this._copy.color) {
  159. this._color = this._copy.color;
  160. } else if (meshCol && meshCol[c]) {
  161. this._color.r = meshCol[c];
  162. this._color.g = meshCol[c + 1];
  163. this._color.b = meshCol[c + 2];
  164. this._color.a = meshCol[c + 3];
  165. } else {
  166. this._color.r = 1;
  167. this._color.g = 1;
  168. this._color.b = 1;
  169. this._color.a = 1;
  170. }
  171. colors.push(this._color.r, this._color.g, this._color.b, this._color.a);
  172. c += 4;
  173. }
  174. for (i = 0; i < meshInd.length; i++) {
  175. indices.push(p + meshInd[i]);
  176. }
  177. }
  178. // returns a shape array from positions array
  179. private _posToShape(positions): Vector3[] {
  180. var shape = [];
  181. for (var i = 0; i < positions.length; i += 3) {
  182. shape.push(new Vector3(positions[i], positions[i + 1], positions[i + 2]));
  183. }
  184. return shape;
  185. }
  186. // returns a shapeUV array from a Vector4 uvs
  187. private _uvsToShapeUV(uvs): number[] {
  188. var shapeUV = [];
  189. if (uvs) {
  190. for (var i = 0; i < uvs.length; i++)
  191. shapeUV.push(uvs[i]);
  192. }
  193. return shapeUV;
  194. }
  195. // adds a new particle object in the particles array
  196. private _addParticle(p: number, idxpos: number, model: ModelShape, shapeId: number, idxInShape: number): void {
  197. this.particles.push(new SolidParticle(p, idxpos, model, shapeId, idxInShape));
  198. }
  199. // add solid particles from a shape model in the particles array
  200. public addShape(mesh: Mesh, nb: number, options?: { positionFunction?: any, vertexFunction?: any }): number {
  201. var meshPos = mesh.getVerticesData(VertexBuffer.PositionKind);
  202. var meshInd = mesh.getIndices();
  203. var meshUV = mesh.getVerticesData(VertexBuffer.UVKind);
  204. var meshCol = mesh.getVerticesData(VertexBuffer.ColorKind);
  205. var shape = this._posToShape(meshPos);
  206. var shapeUV = this._uvsToShapeUV(meshUV);
  207. var posfunc = options ? options.positionFunction : null;
  208. var vtxfunc = options ? options.vertexFunction : null;
  209. var modelShape = new ModelShape(this._shapeCounter, shape, shapeUV, posfunc, vtxfunc);
  210. // particles
  211. for (var i = 0; i < nb; i++) {
  212. this._meshBuilder(this._index, shape, this._positions, meshInd, this._indices, meshUV, this._uvs, meshCol, this._colors, this.nbParticles + i, i, options);
  213. if (this._updatable) {
  214. this._addParticle(this.nbParticles + i, this._positions.length, modelShape, this._shapeCounter, i);
  215. }
  216. this._index += shape.length;
  217. }
  218. this.nbParticles += nb;
  219. this._shapeCounter++;
  220. return this._shapeCounter;
  221. }
  222. // rebuilds a particle back to its just built status : if needed, recomputes the custom positions and vertices
  223. private _rebuildParticle(particle: SolidParticle): void {
  224. this._resetCopy();
  225. if (particle._model._positionFunction) { // recall to stored custom positionFunction
  226. particle._model._positionFunction(this._copy, particle.idx, particle.idxInShape);
  227. }
  228. if (this._copy.quaternion) {
  229. this._quaternion.x = this._copy.quaternion.x;
  230. this._quaternion.y = this._copy.quaternion.y;
  231. this._quaternion.z = this._copy.quaternion.z;
  232. this._quaternion.w = this._copy.quaternion.w;
  233. } else {
  234. this._yaw = this._copy.rotation.y;
  235. this._pitch = this._copy.rotation.x;
  236. this._roll = this._copy.rotation.z;
  237. this._quaternionRotationYPR();
  238. }
  239. this._quaternionToRotationMatrix();
  240. this._shape = particle._model._shape;
  241. for (var pt = 0; pt < this._shape.length; pt++) {
  242. this._vertex.x = this._shape[pt].x;
  243. this._vertex.y = this._shape[pt].y;
  244. this._vertex.z = this._shape[pt].z;
  245. if (particle._model._vertexFunction) {
  246. particle._model._vertexFunction(this._copy, this._vertex, pt); // recall to stored vertexFunction
  247. }
  248. this._vertex.x *= this._copy.scale.x;
  249. this._vertex.y *= this._copy.scale.y;
  250. this._vertex.z *= this._copy.scale.z;
  251. Vector3.TransformCoordinatesToRef(this._vertex, this._rotMatrix, this._rotated);
  252. this._positions32[particle._pos + pt * 3] = this._copy.position.x + this._rotated.x;
  253. this._positions32[particle._pos + pt * 3 + 1] = this._copy.position.y + this._rotated.y;
  254. this._positions32[particle._pos + pt * 3 + 2] = this._copy.position.z + this._rotated.z;
  255. }
  256. particle.position.x = 0;
  257. particle.position.y = 0;
  258. particle.position.z = 0;
  259. particle.rotation.x = 0;
  260. particle.rotation.y = 0;
  261. particle.rotation.z = 0;
  262. particle.quaternion = null;
  263. particle.scale.x = 1;
  264. particle.scale.y = 1;
  265. particle.scale.z = 1;
  266. }
  267. // rebuilds the whole mesh and updates the VBO : custom positions and vertices are recomputed if needed
  268. public rebuildMesh(): void {
  269. for (var p = 0; p < this.particles.length; p++) {
  270. this._rebuildParticle(this.particles[p]);
  271. }
  272. this.mesh.updateVerticesData(VertexBuffer.PositionKind, this._positions32, false, false);
  273. }
  274. // sets all the particles : updates the VBO
  275. public setParticles(start: number = 0, end: number = this.nbParticles - 1, update: boolean = true): void {
  276. // custom beforeUpdate
  277. this.beforeUpdateParticles(start, end, update);
  278. this._cam_axisX.x = 1;
  279. this._cam_axisX.y = 0;
  280. this._cam_axisX.z = 0;
  281. this._cam_axisY.x = 0;
  282. this._cam_axisY.y = 1;
  283. this._cam_axisY.z = 0;
  284. this._cam_axisZ.x = 0;
  285. this._cam_axisZ.y = 0;
  286. this._cam_axisZ.z = 1;
  287. // if the particles will always face the camera
  288. if (this.billboard) {
  289. // compute a fake camera position : un-rotate the camera position by the current mesh rotation
  290. this._yaw = this.mesh.rotation.y;
  291. this._pitch = this.mesh.rotation.x;
  292. this._roll = this.mesh.rotation.z;
  293. this._quaternionRotationYPR();
  294. this._quaternionToRotationMatrix();
  295. this._rotMatrix.invertToRef(this._invertedMatrix);
  296. Vector3.TransformCoordinatesToRef(this._camera.globalPosition, this._invertedMatrix, this._fakeCamPos);
  297. // set two orthogonal vectors (_cam_axisX and and _cam_axisY) to the cam-mesh axis (_cam_axisZ)
  298. (this._fakeCamPos).subtractToRef(this.mesh.position, this._cam_axisZ);
  299. Vector3.CrossToRef(this._cam_axisZ, this._axisX, this._cam_axisY);
  300. Vector3.CrossToRef(this._cam_axisZ, this._cam_axisY, this._cam_axisX);
  301. this._cam_axisY.normalize();
  302. this._cam_axisX.normalize();
  303. this._cam_axisZ.normalize();
  304. }
  305. Matrix.IdentityToRef(this._rotMatrix);
  306. var idx = 0;
  307. var index = 0;
  308. var colidx = 0;
  309. var colorIndex = 0;
  310. var uvidx = 0;
  311. var uvIndex = 0;
  312. // particle loop
  313. end = (end > this.nbParticles - 1) ? this.nbParticles - 1 : end;
  314. for (var p = start; p <= end; p++) {
  315. this._particle = this.particles[p];
  316. this._shape = this._particle._model._shape;
  317. this._shapeUV = this._particle._model._shapeUV;
  318. // call to custom user function to update the particle properties
  319. this.updateParticle(this._particle);
  320. // particle rotation matrix
  321. if (this.billboard) {
  322. this._particle.rotation.x = 0.0;
  323. this._particle.rotation.y = 0.0;
  324. }
  325. if (this._computeParticleRotation) {
  326. if (this._particle.quaternion) {
  327. this._quaternion.x = this._particle.quaternion.x;
  328. this._quaternion.y = this._particle.quaternion.y;
  329. this._quaternion.z = this._particle.quaternion.z;
  330. this._quaternion.w = this._particle.quaternion.w;
  331. } else {
  332. this._yaw = this._particle.rotation.y;
  333. this._pitch = this._particle.rotation.x;
  334. this._roll = this._particle.rotation.z;
  335. this._quaternionRotationYPR();
  336. }
  337. this._quaternionToRotationMatrix();
  338. }
  339. for (var pt = 0; pt < this._shape.length; pt++) {
  340. idx = index + pt * 3;
  341. colidx = colorIndex + pt * 4;
  342. uvidx = uvIndex + pt * 2;
  343. this._vertex.x = this._shape[pt].x;
  344. this._vertex.y = this._shape[pt].y;
  345. this._vertex.z = this._shape[pt].z;
  346. if (this._computeParticleVertex) {
  347. this.updateParticleVertex(this._particle, this._vertex, pt);
  348. }
  349. this._vertex.x *= this._particle.scale.x;
  350. this._vertex.y *= this._particle.scale.y;
  351. this._vertex.z *= this._particle.scale.z;
  352. Vector3.TransformCoordinatesToRef(this._vertex, this._rotMatrix, this._rotated);
  353. 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;
  354. 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;
  355. 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;
  356. if (this._computeParticleColor) {
  357. this._colors32[colidx] = this._particle.color.r;
  358. this._colors32[colidx + 1] = this._particle.color.g;
  359. this._colors32[colidx + 2] = this._particle.color.b;
  360. this._colors32[colidx + 3] = this._particle.color.a;
  361. }
  362. if (this._computeParticleTexture) {
  363. this._uvs32[uvidx] = this._shapeUV[pt * 2] * (this._particle.uvs.z - this._particle.uvs.x) + this._particle.uvs.x;
  364. this._uvs32[uvidx + 1] = this._shapeUV[pt * 2 + 1] * (this._particle.uvs.w - this._particle.uvs.y) + this._particle.uvs.y;
  365. }
  366. }
  367. index = idx + 3;
  368. colorIndex = colidx + 4;
  369. uvIndex = uvidx + 2;
  370. }
  371. if (update) {
  372. if (this._computeParticleColor) {
  373. this.mesh.updateVerticesData(VertexBuffer.ColorKind, this._colors32, false, false);
  374. }
  375. if (this._computeParticleTexture) {
  376. this.mesh.updateVerticesData(VertexBuffer.UVKind, this._uvs32, false, false);
  377. }
  378. this.mesh.updateVerticesData(VertexBuffer.PositionKind, this._positions32, false, false);
  379. if (!this.mesh.areNormalsFrozen) {
  380. VertexData.ComputeNormals(this._positions32, this._indices, this._normals32);
  381. this.mesh.updateVerticesData(VertexBuffer.NormalKind, this._normals32, false, false);
  382. }
  383. }
  384. this.afterUpdateParticles(start, end, update);
  385. }
  386. private _quaternionRotationYPR(): void {
  387. this._halfroll = this._roll * 0.5;
  388. this._halfpitch = this._pitch * 0.5;
  389. this._halfyaw = this._yaw * 0.5;
  390. this._sinRoll = Math.sin(this._halfroll);
  391. this._cosRoll = Math.cos(this._halfroll);
  392. this._sinPitch = Math.sin(this._halfpitch);
  393. this._cosPitch = Math.cos(this._halfpitch);
  394. this._sinYaw = Math.sin(this._halfyaw);
  395. this._cosYaw = Math.cos(this._halfyaw);
  396. this._quaternion.x = (this._cosYaw * this._sinPitch * this._cosRoll) + (this._sinYaw * this._cosPitch * this._sinRoll);
  397. this._quaternion.y = (this._sinYaw * this._cosPitch * this._cosRoll) - (this._cosYaw * this._sinPitch * this._sinRoll);
  398. this._quaternion.z = (this._cosYaw * this._cosPitch * this._sinRoll) - (this._sinYaw * this._sinPitch * this._cosRoll);
  399. this._quaternion.w = (this._cosYaw * this._cosPitch * this._cosRoll) + (this._sinYaw * this._sinPitch * this._sinRoll);
  400. }
  401. private _quaternionToRotationMatrix(): void {
  402. this._rotMatrix.m[0] = 1.0 - (2.0 * (this._quaternion.y * this._quaternion.y + this._quaternion.z * this._quaternion.z));
  403. this._rotMatrix.m[1] = 2.0 * (this._quaternion.x * this._quaternion.y + this._quaternion.z * this._quaternion.w);
  404. this._rotMatrix.m[2] = 2.0 * (this._quaternion.z * this._quaternion.x - this._quaternion.y * this._quaternion.w);
  405. this._rotMatrix.m[3] = 0;
  406. this._rotMatrix.m[4] = 2.0 * (this._quaternion.x * this._quaternion.y - this._quaternion.z * this._quaternion.w);
  407. this._rotMatrix.m[5] = 1.0 - (2.0 * (this._quaternion.z * this._quaternion.z + this._quaternion.x * this._quaternion.x));
  408. this._rotMatrix.m[6] = 2.0 * (this._quaternion.y * this._quaternion.z + this._quaternion.x * this._quaternion.w);
  409. this._rotMatrix.m[7] = 0;
  410. this._rotMatrix.m[8] = 2.0 * (this._quaternion.z * this._quaternion.x + this._quaternion.y * this._quaternion.w);
  411. this._rotMatrix.m[9] = 2.0 * (this._quaternion.y * this._quaternion.z - this._quaternion.x * this._quaternion.w);
  412. this._rotMatrix.m[10] = 1.0 - (2.0 * (this._quaternion.y * this._quaternion.y + this._quaternion.x * this._quaternion.x));
  413. this._rotMatrix.m[11] = 0;
  414. this._rotMatrix.m[12] = 0;
  415. this._rotMatrix.m[13] = 0;
  416. this._rotMatrix.m[14] = 0;
  417. this._rotMatrix.m[15] = 1.0;
  418. }
  419. // dispose the SPS
  420. public dispose(): void {
  421. this.mesh.dispose();
  422. // drop references to internal big arrays for the GC
  423. this._positions = null;
  424. this._indices = null;
  425. this._normals = null;
  426. this._uvs = null;
  427. this._colors = null;
  428. this._positions32 = null;
  429. this._normals32 = null;
  430. this._uvs32 = null;
  431. this._colors32 = null;
  432. }
  433. // Optimizer setters
  434. public set computeParticleRotation(val: boolean) {
  435. this._computeParticleRotation = val;
  436. }
  437. public set computeParticleColor(val: boolean) {
  438. this._computeParticleColor = val;
  439. }
  440. public set computeParticleTexture(val: boolean) {
  441. this._computeParticleTexture = val;
  442. }
  443. public set computeParticleVertex(val: boolean) {
  444. this._computeParticleVertex = val;
  445. }
  446. // getters
  447. public get computeParticleRotation(): boolean {
  448. return this._computeParticleRotation;
  449. }
  450. public get computeParticleColor(): boolean {
  451. return this._computeParticleColor;
  452. }
  453. public get computeParticleTexture(): boolean {
  454. return this._computeParticleTexture;
  455. }
  456. public get computeParticleVertex(): boolean {
  457. return this._computeParticleVertex;
  458. }
  459. // =======================================================================
  460. // Particle behavior logic
  461. // these following methods may be overwritten by the user to fit his needs
  462. // init : sets all particles first values and calls updateParticle to set them in space
  463. // can be overwritten by the user
  464. public initParticles(): void {
  465. }
  466. // recycles a particle : can by overwritten by the user
  467. public recycleParticle(particle: SolidParticle): SolidParticle {
  468. return particle;
  469. }
  470. // updates a particle : can be overwritten by the user
  471. // will be called on each particle by setParticles() :
  472. // ex : just set a particle position or velocity and recycle conditions
  473. public updateParticle(particle: SolidParticle): SolidParticle {
  474. return particle;
  475. }
  476. // updates a vertex of a particle : can be overwritten by the user
  477. // will be called on each vertex particle by setParticles() :
  478. // particle : the current particle
  479. // vertex : the current index of the current particle
  480. // pt : the index of the current vertex in the particle shape
  481. // ex : just set a vertex particle position
  482. public updateParticleVertex(particle: SolidParticle, vertex: Vector3, pt: number): Vector3 {
  483. return vertex;
  484. }
  485. // will be called before any other treatment by setParticles()
  486. public beforeUpdateParticles(start?: number, stop?: number, update?: boolean): void {
  487. }
  488. // will be called after all setParticles() treatments
  489. public afterUpdateParticles(start?: number, stop?: number, update?: boolean): void {
  490. }
  491. }
  492. }