solidParticleSystem.d.ts 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. import type { Nullable, IndicesArray } from "../types";
  2. import { Vector3 } from "../Maths/math.vector";
  3. import { Color4 } from "../Maths/math.color";
  4. import { Mesh } from "../Meshes/mesh";
  5. import type { Scene, IDisposable } from "../scene";
  6. import { DepthSortedParticle, SolidParticle, ModelShape, SolidParticleVertex } from "./solidParticle";
  7. import type { TargetCamera } from "../Cameras/targetCamera";
  8. import { BoundingInfo } from "../Culling/boundingInfo";
  9. import type { Material } from "../Materials/material";
  10. import { MultiMaterial } from "../Materials/multiMaterial";
  11. import type { PickingInfo } from "../Collisions/pickingInfo";
  12. /**
  13. * The SPS is a single updatable mesh. The solid particles are simply separate parts or faces of this big mesh.
  14. *As it is just a mesh, the SPS has all the same properties than any other BJS mesh : not more, not less. It can be scaled, rotated, translated, enlighted, textured, moved, etc.
  15. * The SPS is also a particle system. It provides some methods to manage the particles.
  16. * However it is behavior agnostic. This means it has no emitter, no particle physics, no particle recycler. You have to implement your own behavior.
  17. *
  18. * Full documentation here : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_intro
  19. */
  20. export declare class SolidParticleSystem implements IDisposable {
  21. /**
  22. * The SPS array of Solid Particle objects. Just access each particle as with any classic array.
  23. * Example : var p = SPS.particles[i];
  24. */
  25. particles: SolidParticle[];
  26. /**
  27. * The SPS total number of particles. Read only. Use SPS.counter instead if you need to set your own value.
  28. */
  29. nbParticles: number;
  30. /**
  31. * If the particles must ever face the camera (default false). Useful for planar particles.
  32. */
  33. billboard: boolean;
  34. /**
  35. * Recompute normals when adding a shape
  36. */
  37. recomputeNormals: boolean;
  38. /**
  39. * This a counter ofr your own usage. It's not set by any SPS functions.
  40. */
  41. counter: number;
  42. /**
  43. * The SPS name. This name is also given to the underlying mesh.
  44. */
  45. name: string;
  46. /**
  47. * The SPS mesh. It's a standard BJS Mesh, so all the methods from the Mesh class are available.
  48. */
  49. mesh: Mesh;
  50. /**
  51. * This empty object is intended to store some SPS specific or temporary values in order to lower the Garbage Collector activity.
  52. * Please read : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/optimize_sps#limit-garbage-collection
  53. */
  54. vars: any;
  55. /**
  56. * This array is populated when the SPS is set as 'pickable'.
  57. * Each key of this array is a `faceId` value that you can get from a pickResult object.
  58. * Each element of this array is an object `{idx: int, faceId: int}`.
  59. * `idx` is the picked particle index in the `SPS.particles` array
  60. * `faceId` is the picked face index counted within this particle.
  61. * This array is the first element of the pickedBySubMesh array : sps.pickBySubMesh[0].
  62. * It's not pertinent to use it when using a SPS with the support for MultiMaterial enabled.
  63. * Use the method SPS.pickedParticle(pickingInfo) instead.
  64. * Please read : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/picking_sps
  65. */
  66. pickedParticles: {
  67. idx: number;
  68. faceId: number;
  69. }[];
  70. /**
  71. * This array is populated when the SPS is set as 'pickable'
  72. * Each key of this array is a submesh index.
  73. * Each element of this array is a second array defined like this :
  74. * Each key of this second array is a `faceId` value that you can get from a pickResult object.
  75. * Each element of this second array is an object `{idx: int, faceId: int}`.
  76. * `idx` is the picked particle index in the `SPS.particles` array
  77. * `faceId` is the picked face index counted within this particle.
  78. * It's better to use the method SPS.pickedParticle(pickingInfo) rather than using directly this array.
  79. * Please read : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/picking_sps
  80. */
  81. pickedBySubMesh: {
  82. idx: number;
  83. faceId: number;
  84. }[][];
  85. /**
  86. * This array is populated when `enableDepthSort` is set to true.
  87. * Each element of this array is an instance of the class DepthSortedParticle.
  88. */
  89. depthSortedParticles: DepthSortedParticle[];
  90. /**
  91. * If the particle intersection must be computed only with the bounding sphere (no bounding box computation, so faster). (Internal use only)
  92. * @internal
  93. */
  94. _bSphereOnly: boolean;
  95. /**
  96. * A number to multiply the bounding sphere radius by in order to reduce it for instance. (Internal use only)
  97. * @internal
  98. */
  99. _bSphereRadiusFactor: number;
  100. protected _scene: Scene;
  101. protected _positions: number[];
  102. protected _indices: number[];
  103. protected _normals: number[];
  104. protected _colors: number[];
  105. protected _uvs: number[];
  106. protected _indices32: IndicesArray;
  107. protected _positions32: Float32Array;
  108. protected _normals32: Float32Array;
  109. protected _fixedNormal32: Float32Array;
  110. protected _colors32: Float32Array;
  111. protected _uvs32: Float32Array;
  112. protected _index: number;
  113. protected _updatable: boolean;
  114. protected _pickable: boolean;
  115. protected _isVisibilityBoxLocked: boolean;
  116. protected _alwaysVisible: boolean;
  117. protected _depthSort: boolean;
  118. protected _expandable: boolean;
  119. protected _shapeCounter: number;
  120. protected _copy: SolidParticle;
  121. protected _color: Color4;
  122. protected _computeParticleColor: boolean;
  123. protected _computeParticleTexture: boolean;
  124. protected _computeParticleRotation: boolean;
  125. protected _computeParticleVertex: boolean;
  126. protected _computeBoundingBox: boolean;
  127. protected _autoFixFaceOrientation: boolean;
  128. protected _depthSortParticles: boolean;
  129. protected _camera: TargetCamera;
  130. protected _mustUnrotateFixedNormals: boolean;
  131. protected _particlesIntersect: boolean;
  132. protected _needs32Bits: boolean;
  133. protected _isNotBuilt: boolean;
  134. protected _lastParticleId: number;
  135. protected _idxOfId: number[];
  136. protected _multimaterialEnabled: boolean;
  137. protected _useModelMaterial: boolean;
  138. protected _indicesByMaterial: number[];
  139. protected _materialIndexes: number[];
  140. protected _depthSortFunction: (p1: DepthSortedParticle, p2: DepthSortedParticle) => number;
  141. protected _materialSortFunction: (p1: DepthSortedParticle, p2: DepthSortedParticle) => number;
  142. protected _materials: Material[];
  143. protected _multimaterial: MultiMaterial;
  144. protected _materialIndexesById: any;
  145. protected _defaultMaterial: Material;
  146. protected _autoUpdateSubMeshes: boolean;
  147. protected _tmpVertex: SolidParticleVertex;
  148. protected _recomputeInvisibles: boolean;
  149. /**
  150. * Creates a SPS (Solid Particle System) object.
  151. * @param name (String) is the SPS name, this will be the underlying mesh name.
  152. * @param scene (Scene) is the scene in which the SPS is added.
  153. * @param options defines the options of the sps e.g.
  154. * * updatable (optional boolean, default true) : if the SPS must be updatable or immutable.
  155. * * isPickable (optional boolean, default false) : if the solid particles must be pickable.
  156. * * enableDepthSort (optional boolean, default false) : if the solid particles must be sorted in the geometry according to their distance to the camera.
  157. * * useModelMaterial (optional boolean, default false) : if the model materials must be used to create the SPS multimaterial. This enables the multimaterial supports of the SPS.
  158. * * enableMultiMaterial (optional boolean, default false) : if the solid particles can be given different materials.
  159. * * expandable (optional boolean, default false) : if particles can still be added after the initial SPS mesh creation.
  160. * * particleIntersection (optional boolean, default false) : if the solid particle intersections must be computed.
  161. * * boundingSphereOnly (optional boolean, default false) : if the particle intersection must be computed only with the bounding sphere (no bounding box computation, so faster).
  162. * * bSphereRadiusFactor (optional float, default 1.0) : a number to multiply the bounding sphere radius by in order to reduce it for instance.
  163. * * computeBoundingBox (optional boolean, default false): if the bounding box of the entire SPS will be computed (for occlusion detection, for example). If it is false, the bounding box will be the bounding box of the first particle.
  164. * * autoFixFaceOrientation (optional boolean, default false): if the particle face orientations will be flipped for transformations that change orientation (scale (-1, 1, 1), for example)
  165. * @param options.updatable
  166. * @param options.isPickable
  167. * @param options.enableDepthSort
  168. * @param options.particleIntersection
  169. * @param options.boundingSphereOnly
  170. * @param options.bSphereRadiusFactor
  171. * @param options.expandable
  172. * @param options.useModelMaterial
  173. * @param options.enableMultiMaterial
  174. * @param options.computeBoundingBox
  175. * @param options.autoFixFaceOrientation
  176. * @example bSphereRadiusFactor = 1.0 / Math.sqrt(3.0) => the bounding sphere exactly matches a spherical mesh.
  177. */
  178. constructor(name: string, scene: Scene, options?: {
  179. updatable?: boolean;
  180. isPickable?: boolean;
  181. enableDepthSort?: boolean;
  182. particleIntersection?: boolean;
  183. boundingSphereOnly?: boolean;
  184. bSphereRadiusFactor?: number;
  185. expandable?: boolean;
  186. useModelMaterial?: boolean;
  187. enableMultiMaterial?: boolean;
  188. computeBoundingBox?: boolean;
  189. autoFixFaceOrientation?: boolean;
  190. });
  191. /**
  192. * Builds the SPS underlying mesh. Returns a standard Mesh.
  193. * If no model shape was added to the SPS, the returned mesh is just a single triangular plane.
  194. * @returns the created mesh
  195. */
  196. buildMesh(): Mesh;
  197. private _getUVKind;
  198. /**
  199. * Digests the mesh and generates as many solid particles in the system as wanted. Returns the SPS.
  200. * These particles will have the same geometry than the mesh parts and will be positioned at the same localisation than the mesh original places.
  201. * Thus the particles generated from `digest()` have their property `position` set yet.
  202. * @param mesh ( Mesh ) is the mesh to be digested
  203. * @param options {facetNb} (optional integer, default 1) is the number of mesh facets per particle, this parameter is overridden by the parameter `number` if any
  204. * {delta} (optional integer, default 0) is the random extra number of facets per particle , each particle will have between `facetNb` and `facetNb + delta` facets
  205. * {number} (optional positive integer) is the wanted number of particles : each particle is built with `mesh_total_facets / number` facets
  206. * {storage} (optional existing array) is an array where the particles will be stored for a further use instead of being inserted in the SPS.
  207. * {uvKind} (optional positive integer, default 0) is the kind of UV to read from. Use -1 to deduce it from the diffuse/albedo texture (if any) of the mesh material
  208. * @param options.facetNb
  209. * @param options.number
  210. * @param options.delta
  211. * @param options.storage
  212. * @param options.uvKind
  213. * @returns the current SPS
  214. */
  215. digest(mesh: Mesh, options?: {
  216. facetNb?: number;
  217. number?: number;
  218. delta?: number;
  219. storage?: [];
  220. uvKind?: number;
  221. }): SolidParticleSystem;
  222. /**
  223. * Unrotate the fixed normals in case the mesh was built with pre-rotated particles, ex : use of positionFunction in addShape()
  224. * @internal
  225. */
  226. protected _unrotateFixedNormals(): void;
  227. /**
  228. * Resets the temporary working copy particle
  229. * @internal
  230. */
  231. protected _resetCopy(): void;
  232. /**
  233. * Inserts the shape model geometry in the global SPS mesh by updating the positions, indices, normals, colors, uvs arrays
  234. * @param p the current index in the positions array to be updated
  235. * @param ind the current index in the indices array
  236. * @param shape a Vector3 array, the shape geometry
  237. * @param positions the positions array to be updated
  238. * @param meshInd the shape indices array
  239. * @param indices the indices array to be updated
  240. * @param meshUV the shape uv array
  241. * @param uvs the uv array to be updated
  242. * @param meshCol the shape color array
  243. * @param colors the color array to be updated
  244. * @param meshNor the shape normals array
  245. * @param normals the normals array to be updated
  246. * @param idx the particle index
  247. * @param idxInShape the particle index in its shape
  248. * @param options the addShape() method passed options
  249. * @param model
  250. * @model the particle model
  251. * @internal
  252. */
  253. protected _meshBuilder(p: number, ind: number, shape: Vector3[], positions: number[], meshInd: IndicesArray, indices: number[], meshUV: number[] | Float32Array, uvs: number[], meshCol: number[] | Float32Array, colors: number[], meshNor: number[] | Float32Array, normals: number[], idx: number, idxInShape: number, options: any, model: ModelShape): SolidParticle;
  254. /**
  255. * Returns a shape Vector3 array from positions float array
  256. * @param positions float array
  257. * @returns a vector3 array
  258. * @internal
  259. */
  260. protected _posToShape(positions: number[] | Float32Array): Vector3[];
  261. /**
  262. * Returns a shapeUV array from a float uvs (array deep copy)
  263. * @param uvs as a float array
  264. * @returns a shapeUV array
  265. * @internal
  266. */
  267. protected _uvsToShapeUV(uvs: number[] | Float32Array): number[];
  268. /**
  269. * Adds a new particle object in the particles array
  270. * @param idx particle index in particles array
  271. * @param id particle id
  272. * @param idxpos positionIndex : the starting index of the particle vertices in the SPS "positions" array
  273. * @param idxind indiceIndex : he starting index of the particle indices in the SPS "indices" array
  274. * @param model particle ModelShape object
  275. * @param shapeId model shape identifier
  276. * @param idxInShape index of the particle in the current model
  277. * @param bInfo model bounding info object
  278. * @param storage target storage array, if any
  279. * @internal
  280. */
  281. protected _addParticle(idx: number, id: number, idxpos: number, idxind: number, model: ModelShape, shapeId: number, idxInShape: number, bInfo?: Nullable<BoundingInfo>, storage?: Nullable<[]>): SolidParticle;
  282. /**
  283. * Adds some particles to the SPS from the model shape. Returns the shape id.
  284. * Please read the doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/immutable_sps
  285. * @param mesh is any Mesh object that will be used as a model for the solid particles. If the mesh does not have vertex normals, it will turn on the recomputeNormals attribute.
  286. * @param nb (positive integer) the number of particles to be created from this model
  287. * @param options {positionFunction} is an optional javascript function to called for each particle on SPS creation.
  288. * {vertexFunction} is an optional javascript function to called for each vertex of each particle on SPS creation
  289. * {storage} (optional existing array) is an array where the particles will be stored for a further use instead of being inserted in the SPS.
  290. * @param options.positionFunction
  291. * @param options.vertexFunction
  292. * @param options.storage
  293. * @returns the number of shapes in the system
  294. */
  295. addShape(mesh: Mesh, nb: number, options?: {
  296. positionFunction?: any;
  297. vertexFunction?: any;
  298. storage?: [];
  299. }): number;
  300. /**
  301. * Rebuilds a particle back to its just built status : if needed, recomputes the custom positions and vertices
  302. * @internal
  303. */
  304. protected _rebuildParticle(particle: SolidParticle, reset?: boolean): void;
  305. /**
  306. * Rebuilds the whole mesh and updates the VBO : custom positions and vertices are recomputed if needed.
  307. * @param reset boolean, default false : if the particles must be reset at position and rotation zero, scaling 1, color white, initial UVs and not parented.
  308. * @returns the SPS.
  309. */
  310. rebuildMesh(reset?: boolean): SolidParticleSystem;
  311. /** Removes the particles from the start-th to the end-th included from an expandable SPS (required).
  312. * Returns an array with the removed particles.
  313. * If the number of particles to remove is lower than zero or greater than the global remaining particle number, then an empty array is returned.
  314. * The SPS can't be empty so at least one particle needs to remain in place.
  315. * Under the hood, the VertexData array, so the VBO buffer, is recreated each call.
  316. * @param start index of the first particle to remove
  317. * @param end index of the last particle to remove (included)
  318. * @returns an array populated with the removed particles
  319. */
  320. removeParticles(start: number, end: number): SolidParticle[];
  321. /**
  322. * Inserts some pre-created particles in the solid particle system so that they can be managed by setParticles().
  323. * @param solidParticleArray an array populated with Solid Particles objects
  324. * @returns the SPS
  325. */
  326. insertParticlesFromArray(solidParticleArray: SolidParticle[]): SolidParticleSystem;
  327. /**
  328. * Creates a new particle and modifies the SPS mesh geometry :
  329. * - calls _meshBuilder() to increase the SPS mesh geometry step by step
  330. * - calls _addParticle() to populate the particle array
  331. * factorized code from addShape() and insertParticlesFromArray()
  332. * @param idx particle index in the particles array
  333. * @param i particle index in its shape
  334. * @param modelShape particle ModelShape object
  335. * @param shape shape vertex array
  336. * @param meshInd shape indices array
  337. * @param meshUV shape uv array
  338. * @param meshCol shape color array
  339. * @param meshNor shape normals array
  340. * @param bbInfo shape bounding info
  341. * @param storage target particle storage
  342. * @param options
  343. * @options addShape() passed options
  344. * @internal
  345. */
  346. protected _insertNewParticle(idx: number, i: number, modelShape: ModelShape, shape: Vector3[], meshInd: IndicesArray, meshUV: number[] | Float32Array, meshCol: number[] | Float32Array, meshNor: number[] | Float32Array, bbInfo: Nullable<BoundingInfo>, storage: Nullable<[]>, options: any): Nullable<SolidParticle>;
  347. /**
  348. * Sets all the particles : this method actually really updates the mesh according to the particle positions, rotations, colors, textures, etc.
  349. * This method calls `updateParticle()` for each particle of the SPS.
  350. * For an animated SPS, it is usually called within the render loop.
  351. * This methods does nothing if called on a non updatable or not yet built SPS. Example : buildMesh() not called after having added or removed particles from an expandable SPS.
  352. * @param start The particle index in the particle array where to start to compute the particle property values _(default 0)_
  353. * @param end The particle index in the particle array where to stop to compute the particle property values _(default nbParticle - 1)_
  354. * @param update If the mesh must be finally updated on this call after all the particle computations _(default true)_
  355. * @returns the SPS.
  356. */
  357. setParticles(start?: number, end?: number, update?: boolean): SolidParticleSystem;
  358. /**
  359. * Disposes the SPS.
  360. */
  361. dispose(): void;
  362. /** Returns an object {idx: number faceId: number} for the picked particle from the passed pickingInfo object.
  363. * idx is the particle index in the SPS
  364. * faceId is the picked face index counted within this particle.
  365. * Returns null if the pickInfo can't identify a picked particle.
  366. * @param pickingInfo (PickingInfo object)
  367. * @returns {idx: number, faceId: number} or null
  368. */
  369. pickedParticle(pickingInfo: PickingInfo): Nullable<{
  370. idx: number;
  371. faceId: number;
  372. }>;
  373. /**
  374. * Returns a SolidParticle object from its identifier : particle.id
  375. * @param id (integer) the particle Id
  376. * @returns the searched particle or null if not found in the SPS.
  377. */
  378. getParticleById(id: number): Nullable<SolidParticle>;
  379. /**
  380. * Returns a new array populated with the particles having the passed shapeId.
  381. * @param shapeId (integer) the shape identifier
  382. * @returns a new solid particle array
  383. */
  384. getParticlesByShapeId(shapeId: number): SolidParticle[];
  385. /**
  386. * Populates the passed array "ref" with the particles having the passed shapeId.
  387. * @param shapeId the shape identifier
  388. * @param ref array to populate
  389. * @returns the SPS
  390. */
  391. getParticlesByShapeIdToRef(shapeId: number, ref: SolidParticle[]): SolidParticleSystem;
  392. /**
  393. * Computes the required SubMeshes according the materials assigned to the particles.
  394. * @returns the solid particle system.
  395. * Does nothing if called before the SPS mesh is built.
  396. */
  397. computeSubMeshes(): SolidParticleSystem;
  398. /**
  399. * Sorts the solid particles by material when MultiMaterial is enabled.
  400. * Updates the indices32 array.
  401. * Updates the indicesByMaterial array.
  402. * Updates the mesh indices array.
  403. * @returns the SPS
  404. * @internal
  405. */
  406. protected _sortParticlesByMaterial(): SolidParticleSystem;
  407. /**
  408. * Sets the material indexes by id materialIndexesById[id] = materialIndex
  409. * @internal
  410. */
  411. protected _setMaterialIndexesById(): void;
  412. /**
  413. * Returns an array with unique values of Materials from the passed array
  414. * @param array the material array to be checked and filtered
  415. * @internal
  416. */
  417. protected _filterUniqueMaterialId(array: Material[]): Material[];
  418. /**
  419. * Sets a new Standard Material as _defaultMaterial if not already set.
  420. * @internal
  421. */
  422. protected _setDefaultMaterial(): Material;
  423. /**
  424. * Visibility helper : Recomputes the visible size according to the mesh bounding box
  425. * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility
  426. * @returns the SPS.
  427. */
  428. refreshVisibleSize(): SolidParticleSystem;
  429. /**
  430. * Visibility helper : Sets the size of a visibility box, this sets the underlying mesh bounding box.
  431. * @param size the size (float) of the visibility box
  432. * note : this doesn't lock the SPS mesh bounding box.
  433. * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility
  434. */
  435. setVisibilityBox(size: number): void;
  436. /**
  437. * Gets whether the SPS as always visible or not
  438. * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility
  439. */
  440. get isAlwaysVisible(): boolean;
  441. /**
  442. * Sets the SPS as always visible or not
  443. * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility
  444. */
  445. set isAlwaysVisible(val: boolean);
  446. /**
  447. * Sets the SPS visibility box as locked or not. This enables/disables the underlying mesh bounding box updates.
  448. * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility
  449. */
  450. set isVisibilityBoxLocked(val: boolean);
  451. /**
  452. * Gets if the SPS visibility box as locked or not. This enables/disables the underlying mesh bounding box updates.
  453. * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_visibility
  454. */
  455. get isVisibilityBoxLocked(): boolean;
  456. /**
  457. * Tells to `setParticles()` to compute the particle rotations or not.
  458. * Default value : true. The SPS is faster when it's set to false.
  459. * Note : the particle rotations aren't stored values, so setting `computeParticleRotation` to false will prevents the particle to rotate.
  460. */
  461. set computeParticleRotation(val: boolean);
  462. /**
  463. * Tells to `setParticles()` to compute the particle colors or not.
  464. * Default value : true. The SPS is faster when it's set to false.
  465. * Note : the particle colors are stored values, so setting `computeParticleColor` to false will keep yet the last colors set.
  466. */
  467. set computeParticleColor(val: boolean);
  468. set computeParticleTexture(val: boolean);
  469. /**
  470. * Tells to `setParticles()` to call the vertex function for each vertex of each particle, or not.
  471. * Default value : false. The SPS is faster when it's set to false.
  472. * Note : the particle custom vertex positions aren't stored values.
  473. */
  474. set computeParticleVertex(val: boolean);
  475. /**
  476. * Tells to `setParticles()` to compute or not the mesh bounding box when computing the particle positions.
  477. */
  478. set computeBoundingBox(val: boolean);
  479. /**
  480. * Tells to `setParticles()` to sort or not the distance between each particle and the camera.
  481. * Skipped when `enableDepthSort` is set to `false` (default) at construction time.
  482. * Default : `true`
  483. */
  484. set depthSortParticles(val: boolean);
  485. /**
  486. * Gets if `setParticles()` computes the particle rotations or not.
  487. * Default value : true. The SPS is faster when it's set to false.
  488. * Note : the particle rotations aren't stored values, so setting `computeParticleRotation` to false will prevents the particle to rotate.
  489. */
  490. get computeParticleRotation(): boolean;
  491. /**
  492. * Gets if `setParticles()` computes the particle colors or not.
  493. * Default value : true. The SPS is faster when it's set to false.
  494. * Note : the particle colors are stored values, so setting `computeParticleColor` to false will keep yet the last colors set.
  495. */
  496. get computeParticleColor(): boolean;
  497. /**
  498. * Gets if `setParticles()` computes the particle textures or not.
  499. * Default value : true. The SPS is faster when it's set to false.
  500. * Note : the particle textures are stored values, so setting `computeParticleTexture` to false will keep yet the last colors set.
  501. */
  502. get computeParticleTexture(): boolean;
  503. /**
  504. * Gets if `setParticles()` calls the vertex function for each vertex of each particle, or not.
  505. * Default value : false. The SPS is faster when it's set to false.
  506. * Note : the particle custom vertex positions aren't stored values.
  507. */
  508. get computeParticleVertex(): boolean;
  509. /**
  510. * Gets if `setParticles()` computes or not the mesh bounding box when computing the particle positions.
  511. */
  512. get computeBoundingBox(): boolean;
  513. /**
  514. * Gets if `setParticles()` sorts or not the distance between each particle and the camera.
  515. * Skipped when `enableDepthSort` is set to `false` (default) at construction time.
  516. * Default : `true`
  517. */
  518. get depthSortParticles(): boolean;
  519. /**
  520. * Gets if the SPS is created as expandable at construction time.
  521. * Default : `false`
  522. */
  523. get expandable(): boolean;
  524. /**
  525. * Gets if the SPS supports the Multi Materials
  526. */
  527. get multimaterialEnabled(): boolean;
  528. /**
  529. * Gets if the SPS uses the model materials for its own multimaterial.
  530. */
  531. get useModelMaterial(): boolean;
  532. /**
  533. * The SPS used material array.
  534. */
  535. get materials(): Material[];
  536. /**
  537. * Sets the SPS MultiMaterial from the passed materials.
  538. * Note : the passed array is internally copied and not used then by reference.
  539. * @param materials an array of material objects. This array indexes are the materialIndex values of the particles.
  540. */
  541. setMultiMaterial(materials: Material[]): void;
  542. /**
  543. * The SPS computed multimaterial object
  544. */
  545. get multimaterial(): MultiMaterial;
  546. set multimaterial(mm: MultiMaterial);
  547. /**
  548. * If the subMeshes must be updated on the next call to setParticles()
  549. */
  550. get autoUpdateSubMeshes(): boolean;
  551. set autoUpdateSubMeshes(val: boolean);
  552. /**
  553. * This function does nothing. It may be overwritten to set all the particle first values.
  554. * The SPS doesn't call this function, you may have to call it by your own.
  555. * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/manage_sps_particles
  556. */
  557. initParticles(): void;
  558. /**
  559. * This function does nothing. It may be overwritten to recycle a particle.
  560. * The SPS doesn't call this function, you may have to call it by your own.
  561. * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/manage_sps_particles
  562. * @param particle The particle to recycle
  563. * @returns the recycled particle
  564. */
  565. recycleParticle(particle: SolidParticle): SolidParticle;
  566. /**
  567. * Updates a particle : this function should be overwritten by the user.
  568. * It is called on each particle by `setParticles()`. This is the place to code each particle behavior.
  569. * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/manage_sps_particles
  570. * @example : just set a particle position or velocity and recycle conditions
  571. * @param particle The particle to update
  572. * @returns the updated particle
  573. */
  574. updateParticle(particle: SolidParticle): SolidParticle;
  575. /**
  576. * Updates a vertex of a particle : it can be overwritten by the user.
  577. * This will be called on each vertex particle by `setParticles()` if `computeParticleVertex` is set to true only.
  578. * @param particle the current particle
  579. * @param vertex the current vertex of the current particle : a SolidParticleVertex object
  580. * @param pt the index of the current vertex in the particle shape
  581. * doc : https://doc.babylonjs.com/features/featuresDeepDive/particles/solid_particle_system/sps_vertices
  582. * @example : just set a vertex particle position or color
  583. * @returns the sps
  584. */
  585. updateParticleVertex(particle: SolidParticle, vertex: SolidParticleVertex, pt: number): SolidParticleSystem;
  586. /**
  587. * This will be called before any other treatment by `setParticles()` and will be passed three parameters.
  588. * This does nothing and may be overwritten by the user.
  589. * @param start the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
  590. * @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
  591. * @param update the boolean update value actually passed to setParticles()
  592. */
  593. beforeUpdateParticles(start?: number, stop?: number, update?: boolean): void;
  594. /**
  595. * This will be called by `setParticles()` after all the other treatments and just before the actual mesh update.
  596. * This will be passed three parameters.
  597. * This does nothing and may be overwritten by the user.
  598. * @param start the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
  599. * @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
  600. * @param update the boolean update value actually passed to setParticles()
  601. */
  602. afterUpdateParticles(start?: number, stop?: number, update?: boolean): void;
  603. }