babylon.IParticleSystem.ts 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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. * Defines the delay in milliseconds before starting the system (0 by default)
  135. */
  136. startDelay: number;
  137. /**
  138. * 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
  139. */
  140. preWarmCycles: number;
  141. /**
  142. * Gets or sets a value indicating the time step multiplier to use in pre-warm mode (default is 1)
  143. */
  144. preWarmStepOffset: number;
  145. /**
  146. * 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)
  147. */
  148. spriteCellChangeSpeed: number;
  149. /**
  150. * If using a spritesheet (isAnimationSheetEnabled) defines the first sprite cell to display
  151. */
  152. startSpriteCellID: number;
  153. /**
  154. * If using a spritesheet (isAnimationSheetEnabled) defines the last sprite cell to display
  155. */
  156. endSpriteCellID: number;
  157. /**
  158. * If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell width to use
  159. */
  160. spriteCellWidth: number;
  161. /**
  162. * If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell height to use
  163. */
  164. spriteCellHeight: number;
  165. /**
  166. * This allows the system to random pick the start cell ID between startSpriteCellID and endSpriteCellID
  167. */
  168. spriteRandomStartCell: boolean;
  169. /**
  170. * Gets or sets a boolean indicating if a spritesheet is used to animate the particles texture
  171. */
  172. isAnimationSheetEnabled: boolean;
  173. /** Gets or sets a Vector2 used to move the pivot (by default (0,0)) */
  174. translationPivot: Vector2;
  175. /**
  176. * Gets or sets a texture used to add random noise to particle positions
  177. */
  178. noiseTexture: Nullable<BaseTexture>;
  179. /** Gets or sets the strength to apply to the noise value (default is (10, 10, 10)) */
  180. noiseStrength: Vector3;
  181. /**
  182. * Gets or sets the billboard mode to use when isBillboardBased = true.
  183. * Value can be: ParticleSystem.BILLBOARDMODE_ALL, ParticleSystem.BILLBOARDMODE_Y, ParticleSystem.BILLBOARDMODE_STRETCHED
  184. */
  185. billboardMode: number;
  186. /** Gets or sets a value indicating the damping to apply if the limit velocity factor is reached */
  187. limitVelocityDamping: number;
  188. /**
  189. * Gets the maximum number of particles active at the same time.
  190. * @returns The max number of active particles.
  191. */
  192. getCapacity(): number;
  193. /**
  194. * Gets if the system has been started. (Note: this will still be true after stop is called)
  195. * @returns True if it has been started, otherwise false.
  196. */
  197. isStarted(): boolean;
  198. /**
  199. * Animates the particle system for this frame.
  200. */
  201. animate(): void;
  202. /**
  203. * Renders the particle system in its current state.
  204. * @returns the current number of particles
  205. */
  206. render(): number;
  207. /**
  208. * Dispose the particle system and frees its associated resources.
  209. * @param disposeTexture defines if the particule texture must be disposed as well (true by default)
  210. */
  211. dispose(disposeTexture?: boolean): void;
  212. /**
  213. * Clones the particle system.
  214. * @param name The name of the cloned object
  215. * @param newEmitter The new emitter to use
  216. * @returns the cloned particle system
  217. */
  218. clone(name: string, newEmitter: any): Nullable<IParticleSystem>;
  219. /**
  220. * Serializes the particle system to a JSON object.
  221. * @returns the JSON object
  222. */
  223. serialize(): any;
  224. /**
  225. * Rebuild the particle system
  226. */
  227. rebuild(): void;
  228. /**
  229. * Starts the particle system and begins to emit
  230. * @param delay defines the delay in milliseconds before starting the system (0 by default)
  231. */
  232. start(delay?: number): void;
  233. /**
  234. * Stops the particle system.
  235. */
  236. stop(): void;
  237. /**
  238. * Remove all active particles
  239. */
  240. reset(): void;
  241. /**
  242. * Is this system ready to be used/rendered
  243. * @return true if the system is ready
  244. */
  245. isReady(): boolean;
  246. /**
  247. * Adds a new color gradient
  248. * @param gradient defines the gradient to use (between 0 and 1)
  249. * @param color1 defines the color to affect to the specified gradient
  250. * @param color2 defines an additional color used to define a range ([color, color2]) with main color to pick the final color from
  251. * @returns the current particle system
  252. */
  253. addColorGradient(gradient: number, color1: Color4, color2?: Color4): IParticleSystem;
  254. /**
  255. * Remove a specific color gradient
  256. * @param gradient defines the gradient to remove
  257. * @returns the current particle system
  258. */
  259. removeColorGradient(gradient: number): IParticleSystem;
  260. /**
  261. * Adds a new size gradient
  262. * @param gradient defines the gradient to use (between 0 and 1)
  263. * @param factor defines the size factor to affect to the specified gradient
  264. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  265. * @returns the current particle system
  266. */
  267. addSizeGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  268. /**
  269. * Remove a specific size gradient
  270. * @param gradient defines the gradient to remove
  271. * @returns the current particle system
  272. */
  273. removeSizeGradient(gradient: number): IParticleSystem;
  274. /**
  275. * Gets the current list of color gradients.
  276. * You must use addColorGradient and removeColorGradient to udpate this list
  277. * @returns the list of color gradients
  278. */
  279. getColorGradients(): Nullable<Array<ColorGradient>>;
  280. /**
  281. * Gets the current list of size gradients.
  282. * You must use addSizeGradient and removeSizeGradient to udpate this list
  283. * @returns the list of size gradients
  284. */
  285. getSizeGradients(): Nullable<Array<FactorGradient>>;
  286. /**
  287. * Gets the current list of angular speed gradients.
  288. * You must use addAngularSpeedGradient and removeAngularSpeedGradient to udpate this list
  289. * @returns the list of angular speed gradients
  290. */
  291. getAngularSpeedGradients(): Nullable<Array<FactorGradient>>;
  292. /**
  293. * Adds a new angular speed gradient
  294. * @param gradient defines the gradient to use (between 0 and 1)
  295. * @param factor defines the angular speed to affect to the specified gradient
  296. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  297. * @returns the current particle system
  298. */
  299. addAngularSpeedGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  300. /**
  301. * Remove a specific angular speed gradient
  302. * @param gradient defines the gradient to remove
  303. * @returns the current particle system
  304. */
  305. removeAngularSpeedGradient(gradient: number): IParticleSystem;
  306. /**
  307. * Gets the current list of velocity gradients.
  308. * You must use addVelocityGradient and removeVelocityGradient to udpate this list
  309. * @returns the list of velocity gradients
  310. */
  311. getVelocityGradients(): Nullable<Array<FactorGradient>>;
  312. /**
  313. * Adds a new velocity gradient
  314. * @param gradient defines the gradient to use (between 0 and 1)
  315. * @param factor defines the velocity to affect to the specified gradient
  316. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  317. * @returns the current particle system
  318. */
  319. addVelocityGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  320. /**
  321. * Remove a specific velocity gradient
  322. * @param gradient defines the gradient to remove
  323. * @returns the current particle system
  324. */
  325. removeVelocityGradient(gradient: number): IParticleSystem;
  326. /**
  327. * Gets the current list of limit velocity gradients.
  328. * You must use addLimitVelocityGradient and removeLimitVelocityGradient to udpate this list
  329. * @returns the list of limit velocity gradients
  330. */
  331. getLimitVelocityGradients(): Nullable<Array<FactorGradient>>;
  332. /**
  333. * Adds a new limit velocity gradient
  334. * @param gradient defines the gradient to use (between 0 and 1)
  335. * @param factor defines the limit velocity to affect to the specified gradient
  336. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  337. * @returns the current particle system
  338. */
  339. addLimitVelocityGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  340. /**
  341. * Remove a specific limit velocity gradient
  342. * @param gradient defines the gradient to remove
  343. * @returns the current particle system
  344. */
  345. removeLimitVelocityGradient(gradient: number): IParticleSystem;
  346. /**
  347. * Adds a new drag gradient
  348. * @param gradient defines the gradient to use (between 0 and 1)
  349. * @param factor defines the drag to affect to the specified gradient
  350. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  351. * @returns the current particle system
  352. */
  353. addDragGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  354. /**
  355. * Remove a specific drag gradient
  356. * @param gradient defines the gradient to remove
  357. * @returns the current particle system
  358. */
  359. removeDragGradient(gradient: number): IParticleSystem;
  360. /**
  361. * Gets the current list of drag gradients.
  362. * You must use addDragGradient and removeDragGradient to udpate this list
  363. * @returns the list of drag gradients
  364. */
  365. getDragGradients(): Nullable<Array<FactorGradient>>;
  366. /**
  367. * Adds a new emit rate gradient (please note that this will only work if you set the targetStopDuration property)
  368. * @param gradient defines the gradient to use (between 0 and 1)
  369. * @param factor defines the emit rate to affect to the specified gradient
  370. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  371. * @returns the current particle system
  372. */
  373. addEmitRateGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  374. /**
  375. * Remove a specific emit rate gradient
  376. * @param gradient defines the gradient to remove
  377. * @returns the current particle system
  378. */
  379. removeEmitRateGradient(gradient: number): IParticleSystem;
  380. /**
  381. * Gets the current list of emit rate gradients.
  382. * You must use addEmitRateGradient and removeEmitRateGradient to udpate this list
  383. * @returns the list of emit rate gradients
  384. */
  385. getEmitRateGradients(): Nullable<Array<FactorGradient>>;
  386. /**
  387. * Adds a new start size gradient (please note that this will only work if you set the targetStopDuration property)
  388. * @param gradient defines the gradient to use (between 0 and 1)
  389. * @param factor defines the start size to affect to the specified gradient
  390. * @param factor2 defines an additional factor used to define a range ([factor, factor2]) with main value to pick the final value from
  391. * @returns the current particle system
  392. */
  393. addStartSizeGradient(gradient: number, factor: number, factor2?: number): IParticleSystem;
  394. /**
  395. * Remove a specific start size gradient
  396. * @param gradient defines the gradient to remove
  397. * @returns the current particle system
  398. */
  399. removeStartSizeGradient(gradient: number): IParticleSystem;
  400. /**
  401. * Gets the current list of start size gradients.
  402. * You must use addStartSizeGradient and removeStartSizeGradient to udpate this list
  403. * @returns the list of start size gradients
  404. */
  405. getStartSizeGradients(): Nullable<Array<FactorGradient>>;
  406. /**
  407. * Gets the current list of color gradients.
  408. * You must use addColorGradient and removeColorGradient to udpate this list
  409. * @returns the list of color gradients
  410. */
  411. getColorGradients(): Nullable<Array<ColorGradient>>;
  412. /**
  413. * Adds a new ramp gradient used to remap particle colors
  414. * @param gradient defines the gradient to use (between 0 and 1)
  415. * @param color defines the color to affect to the specified gradient
  416. * @returns the current particle system
  417. */
  418. addRampGradient(gradient: number, color: Color3): IParticleSystem;
  419. /**
  420. * Gets the current list of ramp gradients.
  421. * You must use addRampGradient and removeRampGradient to udpate this list
  422. * @returns the list of ramp gradients
  423. */
  424. getRampGradients(): Nullable<Array<Color3Gradient>>;
  425. /** Gets or sets a boolean indicating that ramp gradients must be used
  426. * @see http://doc.babylonjs.com/babylon101/particles#ramp-gradients
  427. */
  428. useRampGradients: boolean;
  429. /**
  430. * Adds a new color remap gradient
  431. * @param gradient defines the gradient to use (between 0 and 1)
  432. * @param min defines the color remap minimal range
  433. * @param max defines the color remap maximal range
  434. * @returns the current particle system
  435. */
  436. addColorRemapGradient(gradient: number, min: number, max: number): IParticleSystem;
  437. /**
  438. * Gets the current list of color remap gradients.
  439. * You must use addColorRemapGradient and removeColorRemapGradient to udpate this list
  440. * @returns the list of color remap gradients
  441. */
  442. getColorRemapGradients(): Nullable<Array<FactorGradient>>;
  443. /**
  444. * Adds a new alpha remap gradient
  445. * @param gradient defines the gradient to use (between 0 and 1)
  446. * @param min defines the alpha remap minimal range
  447. * @param max defines the alpha remap maximal range
  448. * @returns the current particle system
  449. */
  450. addAlphaRemapGradient(gradient: number, min: number, max: number): IParticleSystem;
  451. /**
  452. * Gets the current list of alpha remap gradients.
  453. * You must use addAlphaRemapGradient and removeAlphaRemapGradient to udpate this list
  454. * @returns the list of alpha remap gradients
  455. */
  456. getAlphaRemapGradients(): Nullable<Array<FactorGradient>>;
  457. /**
  458. * Creates a Point Emitter for the particle system (emits directly from the emitter position)
  459. * @param direction1 Particles are emitted between the direction1 and direction2 from within the box
  460. * @param direction2 Particles are emitted between the direction1 and direction2 from within the box
  461. * @returns the emitter
  462. */
  463. createPointEmitter(direction1: Vector3, direction2: Vector3): PointParticleEmitter;
  464. /**
  465. * Creates a Hemisphere Emitter for the particle system (emits along the hemisphere radius)
  466. * @param radius The radius of the hemisphere to emit from
  467. * @param radiusRange The range of the hemisphere to emit from [0-1] 0 Surface Only, 1 Entire Radius
  468. * @returns the emitter
  469. */
  470. createHemisphericEmitter(radius: number, radiusRange: number): HemisphericParticleEmitter;
  471. /**
  472. * Creates a Sphere Emitter for the particle system (emits along the sphere radius)
  473. * @param radius The radius of the sphere to emit from
  474. * @param radiusRange The range of the sphere to emit from [0-1] 0 Surface Only, 1 Entire Radius
  475. * @returns the emitter
  476. */
  477. createSphereEmitter(radius: number, radiusRange: number): SphereParticleEmitter;
  478. /**
  479. * Creates a Directed Sphere Emitter for the particle system (emits between direction1 and direction2)
  480. * @param radius The radius of the sphere to emit from
  481. * @param direction1 Particles are emitted between the direction1 and direction2 from within the sphere
  482. * @param direction2 Particles are emitted between the direction1 and direction2 from within the sphere
  483. * @returns the emitter
  484. */
  485. createDirectedSphereEmitter(radius: number, direction1:Vector3, direction2: Vector3): SphereDirectedParticleEmitter;
  486. /**
  487. * Creates a Cylinder Emitter for the particle system (emits from the cylinder to the particle position)
  488. * @param radius The radius of the emission cylinder
  489. * @param height The height of the emission cylinder
  490. * @param radiusRange The range of emission [0-1] 0 Surface only, 1 Entire Radius
  491. * @param directionRandomizer How much to randomize the particle direction [0-1]
  492. * @returns the emitter
  493. */
  494. createCylinderEmitter(radius: number, height: number, radiusRange: number, directionRandomizer: number): CylinderParticleEmitter;
  495. /**
  496. * Creates a Directed Cylinder Emitter for the particle system (emits between direction1 and direction2)
  497. * @param radius The radius of the cylinder to emit from
  498. * @param height The height of the emission cylinder
  499. * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)
  500. * @param direction1 Particles are emitted between the direction1 and direction2 from within the cylinder
  501. * @param direction2 Particles are emitted between the direction1 and direction2 from within the cylinder
  502. * @returns the emitter
  503. */
  504. createDirectedCylinderEmitter(radius: number, height: number, radiusRange:number , direction1:Vector3, direction2: Vector3): SphereDirectedParticleEmitter;
  505. /**
  506. * Creates a Cone Emitter for the particle system (emits from the cone to the particle position)
  507. * @param radius The radius of the cone to emit from
  508. * @param angle The base angle of the cone
  509. * @returns the emitter
  510. */
  511. createConeEmitter(radius: number, angle: number): ConeParticleEmitter;
  512. /**
  513. * Creates a Box Emitter for the particle system. (emits between direction1 and direction2 from withing the box defined by minEmitBox and maxEmitBox)
  514. * @param direction1 Particles are emitted between the direction1 and direction2 from within the box
  515. * @param direction2 Particles are emitted between the direction1 and direction2 from within the box
  516. * @param minEmitBox Particles are emitted from the box between minEmitBox and maxEmitBox
  517. * @param maxEmitBox Particles are emitted from the box between minEmitBox and maxEmitBox
  518. * @returns the emitter
  519. */
  520. createBoxEmitter(direction1: Vector3, direction2: Vector3, minEmitBox: Vector3, maxEmitBox: Vector3): BoxParticleEmitter;
  521. /**
  522. * Get hosting scene
  523. * @returns the scene
  524. */
  525. getScene(): Scene;
  526. }
  527. }