pointsCloudSystem.d.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. import { Color4 } from "../Maths/math";
  2. import { Mesh } from "../Meshes/mesh";
  3. import type { Scene, IDisposable } from "../scene";
  4. import { CloudPoint } from "./cloudPoint";
  5. import type { Material } from "../Materials/material";
  6. /** Defines the 4 color options */
  7. export declare enum PointColor {
  8. /** color value */
  9. Color = 2,
  10. /** uv value */
  11. UV = 1,
  12. /** random value */
  13. Random = 0,
  14. /** stated value */
  15. Stated = 3
  16. }
  17. /**
  18. * The PointCloudSystem (PCS) is a single updatable mesh. The points corresponding to the vertices of this big mesh.
  19. * As it is just a mesh, the PointCloudSystem has all the same properties as any other BJS mesh : not more, not less. It can be scaled, rotated, translated, enlighted, textured, moved, etc.
  20. * The PointCloudSystem is also a particle system, with each point being a particle. It provides some methods to manage the particles.
  21. * However it is behavior agnostic. This means it has no emitter, no particle physics, no particle recycler. You have to implement your own behavior.
  22. *
  23. * Full documentation here : TO BE ENTERED
  24. */
  25. export declare class PointsCloudSystem implements IDisposable {
  26. /**
  27. * The PCS array of cloud point objects. Just access each particle as with any classic array.
  28. * Example : var p = SPS.particles[i];
  29. */
  30. particles: CloudPoint[];
  31. /**
  32. * The PCS total number of particles. Read only. Use PCS.counter instead if you need to set your own value.
  33. */
  34. nbParticles: number;
  35. /**
  36. * This a counter for your own usage. It's not set by any SPS functions.
  37. */
  38. counter: number;
  39. /**
  40. * The PCS name. This name is also given to the underlying mesh.
  41. */
  42. name: string;
  43. /**
  44. * The PCS mesh. It's a standard BJS Mesh, so all the methods from the Mesh class are available.
  45. */
  46. mesh?: Mesh;
  47. /**
  48. * This empty object is intended to store some PCS specific or temporary values in order to lower the Garbage Collector activity.
  49. * Please read :
  50. */
  51. vars: any;
  52. /**
  53. * @internal
  54. */
  55. _size: number;
  56. private _scene;
  57. private _promises;
  58. private _positions;
  59. private _indices;
  60. private _normals;
  61. private _colors;
  62. private _uvs;
  63. private _indices32;
  64. private _positions32;
  65. private _colors32;
  66. private _uvs32;
  67. private _updatable;
  68. private _isVisibilityBoxLocked;
  69. private _alwaysVisible;
  70. private _groups;
  71. private _groupCounter;
  72. private _computeParticleColor;
  73. private _computeParticleTexture;
  74. private _computeParticleRotation;
  75. private _computeBoundingBox;
  76. private _isReady;
  77. /**
  78. * Gets the particle positions computed by the Point Cloud System
  79. */
  80. get positions(): Float32Array;
  81. /**
  82. * Gets the particle colors computed by the Point Cloud System
  83. */
  84. get colors(): Float32Array;
  85. /**
  86. * Gets the particle uvs computed by the Point Cloud System
  87. */
  88. get uvs(): Float32Array;
  89. /**
  90. * Creates a PCS (Points Cloud System) object
  91. * @param name (String) is the PCS name, this will be the underlying mesh name
  92. * @param pointSize (number) is the size for each point. Has no effect on a WebGPU engine.
  93. * @param scene (Scene) is the scene in which the PCS is added
  94. * @param options defines the options of the PCS e.g.
  95. * * updatable (optional boolean, default true) : if the PCS must be updatable or immutable
  96. * @param options.updatable
  97. */
  98. constructor(name: string, pointSize: number, scene: Scene, options?: {
  99. updatable?: boolean;
  100. });
  101. /**
  102. * Builds the PCS underlying mesh. Returns a standard Mesh.
  103. * If no points were added to the PCS, the returned mesh is just a single point.
  104. * @param material The material to use to render the mesh. If not provided, will create a default one
  105. * @returns a promise for the created mesh
  106. */
  107. buildMeshAsync(material?: Material): Promise<Mesh>;
  108. /**
  109. * @internal
  110. */
  111. private _buildMesh;
  112. private _addParticle;
  113. private _randomUnitVector;
  114. private _getColorIndicesForCoord;
  115. private _setPointsColorOrUV;
  116. private _colorFromTexture;
  117. private _calculateDensity;
  118. /**
  119. * Adds points to the PCS in random positions within a unit sphere
  120. * @param nb (positive integer) the number of particles to be created from this model
  121. * @param pointFunction is an optional javascript function to be called for each particle on PCS creation
  122. * @returns the number of groups in the system
  123. */
  124. addPoints(nb: number, pointFunction?: any): number;
  125. /**
  126. * Adds points to the PCS from the surface of the model shape
  127. * @param mesh is any Mesh object that will be used as a surface model for the points
  128. * @param nb (positive integer) the number of particles to be created from this model
  129. * @param colorWith determines whether a point is colored using color (default), uv, random, stated or none (invisible)
  130. * @param color (color4) to be used when colorWith is stated or color (number) when used to specify texture position
  131. * @param range (number from 0 to 1) to determine the variation in shape and tone for a stated color
  132. * @returns the number of groups in the system
  133. */
  134. addSurfacePoints(mesh: Mesh, nb: number, colorWith?: number, color?: Color4 | number, range?: number): number;
  135. /**
  136. * Adds points to the PCS inside the model shape
  137. * @param mesh is any Mesh object that will be used as a surface model for the points
  138. * @param nb (positive integer) the number of particles to be created from this model
  139. * @param colorWith determines whether a point is colored using color (default), uv, random, stated or none (invisible)
  140. * @param color (color4) to be used when colorWith is stated or color (number) when used to specify texture position
  141. * @param range (number from 0 to 1) to determine the variation in shape and tone for a stated color
  142. * @returns the number of groups in the system
  143. */
  144. addVolumePoints(mesh: Mesh, nb: number, colorWith?: number, color?: Color4 | number, range?: number): number;
  145. /**
  146. * Sets all the particles : this method actually really updates the mesh according to the particle positions, rotations, colors, textures, etc.
  147. * This method calls `updateParticle()` for each particle of the SPS.
  148. * For an animated SPS, it is usually called within the render loop.
  149. * @param start The particle index in the particle array where to start to compute the particle property values _(default 0)_
  150. * @param end The particle index in the particle array where to stop to compute the particle property values _(default nbParticle - 1)_
  151. * @param update If the mesh must be finally updated on this call after all the particle computations _(default true)_
  152. * @returns the PCS.
  153. */
  154. setParticles(start?: number, end?: number, update?: boolean): PointsCloudSystem;
  155. /**
  156. * Disposes the PCS.
  157. */
  158. dispose(): void;
  159. /**
  160. * Visibility helper : Recomputes the visible size according to the mesh bounding box
  161. * doc :
  162. * @returns the PCS.
  163. */
  164. refreshVisibleSize(): PointsCloudSystem;
  165. /**
  166. * Visibility helper : Sets the size of a visibility box, this sets the underlying mesh bounding box.
  167. * @param size the size (float) of the visibility box
  168. * note : this doesn't lock the PCS mesh bounding box.
  169. * doc :
  170. */
  171. setVisibilityBox(size: number): void;
  172. /**
  173. * Gets whether the PCS is always visible or not
  174. * doc :
  175. */
  176. get isAlwaysVisible(): boolean;
  177. /**
  178. * Sets the PCS as always visible or not
  179. * doc :
  180. */
  181. set isAlwaysVisible(val: boolean);
  182. /**
  183. * Tells to `setParticles()` to compute the particle rotations or not
  184. * Default value : false. The PCS is faster when it's set to false
  185. * Note : particle rotations are only applied to parent particles
  186. * Note : the particle rotations aren't stored values, so setting `computeParticleRotation` to false will prevents the particle to rotate
  187. */
  188. set computeParticleRotation(val: boolean);
  189. /**
  190. * Tells to `setParticles()` to compute the particle colors or not.
  191. * Default value : true. The PCS is faster when it's set to false.
  192. * Note : the particle colors are stored values, so setting `computeParticleColor` to false will keep yet the last colors set.
  193. */
  194. set computeParticleColor(val: boolean);
  195. set computeParticleTexture(val: boolean);
  196. /**
  197. * Gets if `setParticles()` computes the particle colors or not.
  198. * Default value : false. The PCS is faster when it's set to false.
  199. * Note : the particle colors are stored values, so setting `computeParticleColor` to false will keep yet the last colors set.
  200. */
  201. get computeParticleColor(): boolean;
  202. /**
  203. * Gets if `setParticles()` computes the particle textures or not.
  204. * Default value : false. The PCS is faster when it's set to false.
  205. * Note : the particle textures are stored values, so setting `computeParticleTexture` to false will keep yet the last colors set.
  206. */
  207. get computeParticleTexture(): boolean;
  208. /**
  209. * Tells to `setParticles()` to compute or not the mesh bounding box when computing the particle positions.
  210. */
  211. set computeBoundingBox(val: boolean);
  212. /**
  213. * Gets if `setParticles()` computes or not the mesh bounding box when computing the particle positions.
  214. */
  215. get computeBoundingBox(): boolean;
  216. /**
  217. * This function does nothing. It may be overwritten to set all the particle first values.
  218. * The PCS doesn't call this function, you may have to call it by your own.
  219. * doc :
  220. */
  221. initParticles(): void;
  222. /**
  223. * This function does nothing. It may be overwritten to recycle a particle
  224. * The PCS doesn't call this function, you can to call it
  225. * doc :
  226. * @param particle The particle to recycle
  227. * @returns the recycled particle
  228. */
  229. recycleParticle(particle: CloudPoint): CloudPoint;
  230. /**
  231. * Updates a particle : this function should be overwritten by the user.
  232. * It is called on each particle by `setParticles()`. This is the place to code each particle behavior.
  233. * doc :
  234. * @example : just set a particle position or velocity and recycle conditions
  235. * @param particle The particle to update
  236. * @returns the updated particle
  237. */
  238. updateParticle(particle: CloudPoint): CloudPoint;
  239. /**
  240. * This will be called before any other treatment by `setParticles()` and will be passed three parameters.
  241. * This does nothing and may be overwritten by the user.
  242. * @param start the particle index in the particle array where to start to iterate, same than the value passed to setParticle()
  243. * @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
  244. * @param update the boolean update value actually passed to setParticles()
  245. */
  246. beforeUpdateParticles(start?: number, stop?: number, update?: boolean): void;
  247. /**
  248. * This will be called by `setParticles()` after all the other treatments and just before the actual mesh update.
  249. * This will be passed three parameters.
  250. * This does nothing and may be overwritten by the user.
  251. * @param start the particle index in the particle array where to start to iterate, same than the value passed to setParticle()
  252. * @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
  253. * @param update the boolean update value actually passed to setParticles()
  254. */
  255. afterUpdateParticles(start?: number, stop?: number, update?: boolean): void;
  256. }