babylon.IParticleSystem.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. module BABYLON {
  2. /**
  3. * Interface representing a particle system in Babylon.js.
  4. * This groups the common functionalities that needs to be implemented in order to create a particle system.
  5. * A particle system represents a way to manage particles from their emission to their animation and rendering.
  6. */
  7. export interface IParticleSystem {
  8. /**
  9. * List of animations used by the particle system.
  10. */
  11. animations: Animation[];
  12. /**
  13. * The id of the Particle system.
  14. */
  15. id: string;
  16. /**
  17. * The name of the Particle system.
  18. */
  19. name: string;
  20. /**
  21. * The emitter represents the Mesh or position we are attaching the particle system to.
  22. */
  23. emitter: Nullable<AbstractMesh | Vector3>;
  24. /**
  25. * Gets or sets a boolean indicating if the particles must be rendered as billboard or aligned with the direction
  26. */
  27. isBillboardBased: boolean;
  28. /**
  29. * The rendering group used by the Particle system to chose when to render.
  30. */
  31. renderingGroupId: number;
  32. /**
  33. * The layer mask we are rendering the particles through.
  34. */
  35. layerMask: number;
  36. /**
  37. * The overall motion speed (0.01 is default update speed, faster updates = faster animation)
  38. */
  39. updateSpeed: number;
  40. /**
  41. * The amount of time the particle system is running (depends of the overall update speed).
  42. */
  43. targetStopDuration: number;
  44. /**
  45. * The texture used to render each particle. (this can be a spritesheet)
  46. */
  47. particleTexture: Nullable<Texture>;
  48. /**
  49. * Blend mode use to render the particle, it can be either ParticleSystem.BLENDMODE_ONEONE, ParticleSystem.BLENDMODE_STANDARD or ParticleSystem.BLENDMODE_ADD.
  50. */
  51. blendMode: number;
  52. /**
  53. * Minimum life time of emitting particles.
  54. */
  55. minLifeTime: number;
  56. /**
  57. * Maximum life time of emitting particles.
  58. */
  59. maxLifeTime: number;
  60. /**
  61. * Minimum Size of emitting particles.
  62. */
  63. minSize: number;
  64. /**
  65. * Maximum Size of emitting particles.
  66. */
  67. maxSize: number;
  68. /**
  69. * Minimum scale of emitting particles on X axis.
  70. */
  71. minScaleX: number;
  72. /**
  73. * Maximum scale of emitting particles on X axis.
  74. */
  75. maxScaleX: number;
  76. /**
  77. * Minimum scale of emitting particles on Y axis.
  78. */
  79. minScaleY: number;
  80. /**
  81. * Maximum scale of emitting particles on Y axis.
  82. */
  83. maxScaleY: number;
  84. /**
  85. * Random color of each particle after it has been emitted, between color1 and color2 vectors.
  86. */
  87. color1: Color4;
  88. /**
  89. * Random color of each particle after it has been emitted, between color1 and color2 vectors.
  90. */
  91. color2: Color4;
  92. /**
  93. * Color the particle will have at the end of its lifetime.
  94. */
  95. colorDead: Color4;
  96. /**
  97. * The maximum number of particles to emit per frame until we reach the activeParticleCount value
  98. */
  99. emitRate: number;
  100. /**
  101. * You can use gravity if you want to give an orientation to your particles.
  102. */
  103. gravity: Vector3;
  104. /**
  105. * Minimum power of emitting particles.
  106. */
  107. minEmitPower: number;
  108. /**
  109. * Maximum power of emitting particles.
  110. */
  111. maxEmitPower: number;
  112. /**
  113. * Minimum angular speed of emitting particles (Z-axis rotation for each particle).
  114. */
  115. minAngularSpeed: number;
  116. /**
  117. * Maximum angular speed of emitting particles (Z-axis rotation for each particle).
  118. */
  119. maxAngularSpeed: number;
  120. /**
  121. * Gets or sets the minimal initial rotation in radians.
  122. */
  123. minInitialRotation: number;
  124. /**
  125. * Gets or sets the maximal initial rotation in radians.
  126. */
  127. maxInitialRotation: number;
  128. /**
  129. * The particle emitter type defines the emitter used by the particle system.
  130. * It can be for example box, sphere, or cone...
  131. */
  132. particleEmitterType: Nullable<IParticleEmitterType>;
  133. /**
  134. * Gets or sets a value indicating how many cycles (or frames) must be executed before first rendering (this value has to be set before starting the system). Default is 0
  135. */
  136. preWarmCycles: number;
  137. /**
  138. * Gets or sets a value indicating the time step multiplier to use in pre-warm mode (default is 1)
  139. */
  140. preWarmStepOffset: number;
  141. /**
  142. * If using a spritesheet (isAnimationSheetEnabled) defines the speed of the sprite loop (default is 1 meaning the animation will play once during the entire particle lifetime)
  143. */
  144. spriteCellChangeSpeed: number;
  145. /**
  146. * If using a spritesheet (isAnimationSheetEnabled) defines the first sprite cell to display
  147. */
  148. startSpriteCellID: number;
  149. /**
  150. * If using a spritesheet (isAnimationSheetEnabled) defines the last sprite cell to display
  151. */
  152. endSpriteCellID: number;
  153. /**
  154. * If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell width to use
  155. */
  156. spriteCellWidth: number;
  157. /**
  158. * If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell height to use
  159. */
  160. spriteCellHeight: number;
  161. /**
  162. * This allows the system to random pick the start cell ID between startSpriteCellID and endSpriteCellID
  163. */
  164. spriteRandomStartCell: boolean;
  165. /** Gets or sets a Vector2 used to move the pivot (by default (0,0)) */
  166. translationPivot: Vector2;
  167. /**
  168. * Gets or sets a texture used to add random noise to particle positions
  169. */
  170. noiseTexture: Nullable<BaseTexture>;
  171. /** Gets or sets the strength to apply to the noise value (default is (10, 10, 10)) */
  172. noiseStrength: Vector3;
  173. /**
  174. * Gets or sets the billboard mode to use when isBillboardBased = true.
  175. * Only BABYLON.AbstractMesh.BILLBOARDMODE_ALL and AbstractMesh.BILLBOARDMODE_Y are supported so far
  176. */
  177. billboardMode: number;
  178. /** Gets or sets a value indicating the damping to apply if the limit velocity factor is reached */
  179. limitVelocityDamping: number;
  180. /**
  181. * Gets the maximum number of particles active at the same time.
  182. * @returns The max number of active particles.
  183. */
  184. getCapacity(): number;
  185. /**
  186. * Gets if the system has been started. (Note: this will still be true after stop is called)
  187. * @returns True if it has been started, otherwise false.
  188. */
  189. isStarted(): boolean;
  190. /**
  191. * Animates the particle system for this frame.
  192. */
  193. animate(): void;
  194. /**
  195. * Renders the particle system in its current state.
  196. * @returns the current number of particles
  197. */
  198. render(): number;
  199. /**
  200. * Dispose the particle system and frees its associated resources.
  201. * @param disposeTexture defines if the particule texture must be disposed as well (true by default)
  202. */
  203. dispose(disposeTexture?: boolean): void;
  204. /**
  205. * Clones the particle system.
  206. * @param name The name of the cloned object
  207. * @param newEmitter The new emitter to use
  208. * @returns the cloned particle system
  209. */
  210. clone(name: string, newEmitter: any): Nullable<IParticleSystem>;
  211. /**
  212. * Serializes the particle system to a JSON object.
  213. * @returns the JSON object
  214. */
  215. serialize(): any;
  216. /**
  217. * Rebuild the particle system
  218. */
  219. rebuild(): void;
  220. /**
  221. * Starts the particle system and begins to emit
  222. * @param delay defines the delay in milliseconds before starting the system (0 by default)
  223. */
  224. start(delay?: number): void;
  225. /**
  226. * Stops the particle system.
  227. */
  228. stop(): void;
  229. /**
  230. * Remove all active particles
  231. */
  232. reset(): void;
  233. /**
  234. * Is this system ready to be used/rendered
  235. * @return true if the system is ready
  236. */
  237. isReady(): boolean;
  238. /**
  239. * Adds a new color gradient
  240. * @param gradient defines the gradient to use (between 0 and 1)
  241. * @param color defines the color to affect to the specified gradient
  242. * @param color2 defines an additional color used to define a range ([color, color2]) with main color to pick the final color from
  243. * @returns the current particle system
  244. */
  245. addColorGradient(gradient: number, color1: Color4, color2?: Color4): IParticleSystem;
  246. /**
  247. * Remove a specific color gradient
  248. * @param gradient defines the gradient to remove
  249. * @returns the current particle system
  250. */
  251. removeColorGradient(gradient: number): IParticleSystem;
  252. /**
  253. * Adds a new size gradient
  254. * @param gradient defines the gradient to use (between 0 and 1)
  255. * @param factor defines the size factor to affect to the specified gradient
  256. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  257. * @returns the current particle system
  258. */
  259. addSizeGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  260. /**
  261. * Remove a specific size gradient
  262. * @param gradient defines the gradient to remove
  263. * @returns the current particle system
  264. */
  265. removeSizeGradient(gradient: number): IParticleSystem;
  266. /**
  267. * Gets the current list of color gradients.
  268. * You must use addColorGradient and removeColorGradient to udpate this list
  269. * @returns the list of color gradients
  270. */
  271. getColorGradients(): Nullable<Array<ColorGradient>>;
  272. /**
  273. * Gets the current list of size gradients.
  274. * You must use addSizeGradient and removeSizeGradient to udpate this list
  275. * @returns the list of size gradients
  276. */
  277. getSizeGradients(): Nullable<Array<FactorGradient>>;
  278. /**
  279. * Gets the current list of angular speed gradients.
  280. * You must use addAngularSpeedGradient and removeAngularSpeedGradient to udpate this list
  281. * @returns the list of angular speed gradients
  282. */
  283. getAngularSpeedGradients(): Nullable<Array<FactorGradient>>;
  284. /**
  285. * Adds a new angular speed gradient
  286. * @param gradient defines the gradient to use (between 0 and 1)
  287. * @param factor defines the angular speed to affect to the specified gradient
  288. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  289. * @returns the current particle system
  290. */
  291. addAngularSpeedGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  292. /**
  293. * Remove a specific angular speed gradient
  294. * @param gradient defines the gradient to remove
  295. * @returns the current particle system
  296. */
  297. removeAngularSpeedGradient(gradient: number): IParticleSystem;
  298. /**
  299. * Gets the current list of velocity gradients.
  300. * You must use addVelocityGradient and removeVelocityGradient to udpate this list
  301. * @returns the list of velocity gradients
  302. */
  303. getVelocityGradients(): Nullable<Array<FactorGradient>>;
  304. /**
  305. * Adds a new velocity gradient
  306. * @param gradient defines the gradient to use (between 0 and 1)
  307. * @param factor defines the velocity to affect to the specified gradient
  308. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  309. * @returns the current particle system
  310. */
  311. addVelocityGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  312. /**
  313. * Remove a specific velocity gradient
  314. * @param gradient defines the gradient to remove
  315. * @returns the current particle system
  316. */
  317. removeVelocityGradient(gradient: number): IParticleSystem;
  318. /**
  319. * Gets the current list of limit velocity gradients.
  320. * You must use addLimitVelocityGradient and removeLimitVelocityGradient to udpate this list
  321. * @returns the list of limit velocity gradients
  322. */
  323. getLimitVelocityGradients(): Nullable<Array<FactorGradient>>;
  324. /**
  325. * Adds a new limit velocity gradient
  326. * @param gradient defines the gradient to use (between 0 and 1)
  327. * @param factor defines the limit velocity to affect to the specified gradient
  328. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  329. * @returns the current particle system
  330. */
  331. addLimitVelocityGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  332. /**
  333. * Remove a specific limit velocity gradient
  334. * @param gradient defines the gradient to remove
  335. * @returns the current particle system
  336. */
  337. removeLimitVelocityGradient(gradient: number): IParticleSystem;
  338. /**
  339. * Adds a new drag gradient
  340. * @param gradient defines the gradient to use (between 0 and 1)
  341. * @param factor defines the drag to affect to the specified gradient
  342. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  343. * @returns the current particle system
  344. */
  345. addDragGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  346. /**
  347. * Remove a specific drag gradient
  348. * @param gradient defines the gradient to remove
  349. * @returns the current particle system
  350. */
  351. removeDragGradient(gradient: number): IParticleSystem;
  352. /**
  353. * Gets the current list of drag gradients.
  354. * You must use addDragGradient and removeDragGradient to udpate this list
  355. * @returns the list of drag gradients
  356. */
  357. getDragGradients(): Nullable<Array<FactorGradient>>;
  358. /**
  359. * Adds a new emit rate gradient (please note that this will only work if you set the targetStopDuration property)
  360. * @param gradient defines the gradient to use (between 0 and 1)
  361. * @param factor defines the emit rate to affect to the specified gradient
  362. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  363. * @returns the current particle system
  364. */
  365. addEmitRateGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  366. /**
  367. * Remove a specific emit rate gradient
  368. * @param gradient defines the gradient to remove
  369. * @returns the current particle system
  370. */
  371. removeEmitRateGradient(gradient: number): IParticleSystem;
  372. /**
  373. * Gets the current list of emit rate gradients.
  374. * You must use addEmitRateGradient and removeEmitRateGradient to udpate this list
  375. * @returns the list of emit rate gradients
  376. */
  377. getEmitRateGradients(): Nullable<Array<FactorGradient>>;
  378. /**
  379. * Adds a new start size gradient (please note that this will only work if you set the targetStopDuration property)
  380. * @param gradient defines the gradient to use (between 0 and 1)
  381. * @param factor defines the start size to affect to the specified gradient
  382. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  383. * @returns the current particle system
  384. */
  385. addStartSizeGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  386. /**
  387. * Remove a specific start size gradient
  388. * @param gradient defines the gradient to remove
  389. * @returns the current particle system
  390. */
  391. removeStartSizeGradient(gradient: number): IParticleSystem;
  392. /**
  393. * Gets the current list of start size gradients.
  394. * You must use addStartSizeGradient and removeStartSizeGradient to udpate this list
  395. * @returns the list of start size gradients
  396. */
  397. getStartSizeGradients(): Nullable<Array<FactorGradient>>;
  398. /**
  399. * Creates a Point Emitter for the particle system (emits directly from the emitter position)
  400. * @param direction1 Particles are emitted between the direction1 and direction2 from within the box
  401. * @param direction2 Particles are emitted between the direction1 and direction2 from within the box
  402. * @returns the emitter
  403. */
  404. createPointEmitter(direction1: Vector3, direction2: Vector3): PointParticleEmitter;
  405. /**
  406. * Creates a Hemisphere Emitter for the particle system (emits along the hemisphere radius)
  407. * @param radius The radius of the hemisphere to emit from
  408. * @param radiusRange The range of the hemisphere to emit from [0-1] 0 Surface Only, 1 Entire Radius
  409. * @returns the emitter
  410. */
  411. createHemisphericEmitter(radius: number, radiusRange: number): HemisphericParticleEmitter;
  412. /**
  413. * Creates a Sphere Emitter for the particle system (emits along the sphere radius)
  414. * @param radius The radius of the sphere to emit from
  415. * @param radiusRange The range of the sphere to emit from [0-1] 0 Surface Only, 1 Entire Radius
  416. * @returns the emitter
  417. */
  418. createSphereEmitter(radius: number, radiusRange: number): SphereParticleEmitter;
  419. /**
  420. * Creates a Directed Sphere Emitter for the particle system (emits between direction1 and direction2)
  421. * @param radius The radius of the sphere to emit from
  422. * @param direction1 Particles are emitted between the direction1 and direction2 from within the sphere
  423. * @param direction2 Particles are emitted between the direction1 and direction2 from within the sphere
  424. * @returns the emitter
  425. */
  426. createDirectedSphereEmitter(radius: number, direction1:Vector3, direction2: Vector3): SphereDirectedParticleEmitter;
  427. /**
  428. * Creates a Cylinder Emitter for the particle system (emits from the cylinder to the particle position)
  429. * @param radius The radius of the emission cylinder
  430. * @param height The height of the emission cylinder
  431. * @param radiusRange The range of emission [0-1] 0 Surface only, 1 Entire Radius
  432. * @param directionRandomizer How much to randomize the particle direction [0-1]
  433. * @returns the emitter
  434. */
  435. createCylinderEmitter(radius: number, height: number, radiusRange: number, directionRandomizer: number): CylinderParticleEmitter;
  436. /**
  437. * Creates a Directed Cylinder Emitter for the particle system (emits between direction1 and direction2)
  438. * @param radius The radius of the cylinder to emit from
  439. * @param height The height of the emission cylinder
  440. * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)
  441. * @param direction1 Particles are emitted between the direction1 and direction2 from within the cylinder
  442. * @param direction2 Particles are emitted between the direction1 and direction2 from within the cylinder
  443. * @returns the emitter
  444. */
  445. createDirectedCylinderEmitter(radius: number, height: number, radiusRange:number , direction1:Vector3, direction2: Vector3): SphereDirectedParticleEmitter;
  446. /**
  447. * Creates a Cone Emitter for the particle system (emits from the cone to the particle position)
  448. * @param radius The radius of the cone to emit from
  449. * @param angle The base angle of the cone
  450. * @returns the emitter
  451. */
  452. createConeEmitter(radius: number, angle: number): ConeParticleEmitter;
  453. /**
  454. * Creates a Box Emitter for the particle system. (emits between direction1 and direction2 from withing the box defined by minEmitBox and maxEmitBox)
  455. * @param direction1 Particles are emitted between the direction1 and direction2 from within the box
  456. * @param direction2 Particles are emitted between the direction1 and direction2 from within the box
  457. * @param minEmitBox Particles are emitted from the box between minEmitBox and maxEmitBox
  458. * @param maxEmitBox Particles are emitted from the box between minEmitBox and maxEmitBox
  459. * @returns the emitter
  460. */
  461. createBoxEmitter(direction1: Vector3, direction2: Vector3, minEmitBox: Vector3, maxEmitBox: Vector3): BoxParticleEmitter;
  462. /**
  463. * Get hosting scene
  464. * @returns the scene
  465. */
  466. getScene(): Scene;
  467. }
  468. }