baseParticleSystem.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. import { Nullable } from "../types";
  2. import { Vector2, Vector3 } from "../Maths/math.vector";
  3. import { AbstractMesh } from "../Meshes/abstractMesh";
  4. import { ImageProcessingConfiguration, ImageProcessingConfigurationDefines } from "../Materials/imageProcessingConfiguration";
  5. import { ProceduralTexture } from "../Materials/Textures/Procedurals/proceduralTexture";
  6. import { RawTexture } from "../Materials/Textures/rawTexture";
  7. import { ColorGradient, FactorGradient, Color3Gradient, IValueGradient } from "../Misc/gradients";
  8. import { BoxParticleEmitter, IParticleEmitterType, PointParticleEmitter, HemisphericParticleEmitter, SphereParticleEmitter, SphereDirectedParticleEmitter, CylinderParticleEmitter, CylinderDirectedParticleEmitter, ConeParticleEmitter } from "../Particles/EmitterTypes/index";
  9. import { Constants } from "../Engines/constants";
  10. import { Texture } from '../Materials/Textures/texture';
  11. import { Color4 } from '../Maths/math.color';
  12. import { ThinEngine } from '../Engines/thinEngine';
  13. declare type Animation = import("../Animations/animation").Animation;
  14. declare type Scene = import("../scene").Scene;
  15. /**
  16. * This represents the base class for particle system in Babylon.
  17. * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.
  18. * Particles can take different shapes while emitted like box, sphere, cone or you can write your custom function.
  19. * @example https://doc.babylonjs.com/babylon101/particles
  20. */
  21. export class BaseParticleSystem {
  22. /**
  23. * Source color is added to the destination color without alpha affecting the result
  24. */
  25. public static BLENDMODE_ONEONE = 0;
  26. /**
  27. * Blend current color and particle color using particle’s alpha
  28. */
  29. public static BLENDMODE_STANDARD = 1;
  30. /**
  31. * Add current color and particle color multiplied by particle’s alpha
  32. */
  33. public static BLENDMODE_ADD = 2;
  34. /**
  35. * Multiply current color with particle color
  36. */
  37. public static BLENDMODE_MULTIPLY = 3;
  38. /**
  39. * Multiply current color with particle color then add current color and particle color multiplied by particle’s alpha
  40. */
  41. public static BLENDMODE_MULTIPLYADD = 4;
  42. /**
  43. * List of animations used by the particle system.
  44. */
  45. public animations: Animation[] = [];
  46. /**
  47. * Gets or sets the unique id of the particle system
  48. */
  49. public uniqueId: number;
  50. /**
  51. * The id of the Particle system.
  52. */
  53. public id: string;
  54. /**
  55. * The friendly name of the Particle system.
  56. */
  57. public name: string;
  58. /**
  59. * Snippet ID if the particle system was created from the snippet server
  60. */
  61. public snippetId: string;
  62. /**
  63. * The rendering group used by the Particle system to chose when to render.
  64. */
  65. public renderingGroupId = 0;
  66. /**
  67. * The emitter represents the Mesh or position we are attaching the particle system to.
  68. */
  69. public emitter: Nullable<AbstractMesh | Vector3> = Vector3.Zero();
  70. /**
  71. * The maximum number of particles to emit per frame
  72. */
  73. public emitRate = 10;
  74. /**
  75. * If you want to launch only a few particles at once, that can be done, as well.
  76. */
  77. public manualEmitCount = -1;
  78. /**
  79. * The overall motion speed (0.01 is default update speed, faster updates = faster animation)
  80. */
  81. public updateSpeed = 0.01;
  82. /**
  83. * The amount of time the particle system is running (depends of the overall update speed).
  84. */
  85. public targetStopDuration = 0;
  86. /**
  87. * Specifies whether the particle system will be disposed once it reaches the end of the animation.
  88. */
  89. public disposeOnStop = false;
  90. /**
  91. * Minimum power of emitting particles.
  92. */
  93. public minEmitPower = 1;
  94. /**
  95. * Maximum power of emitting particles.
  96. */
  97. public maxEmitPower = 1;
  98. /**
  99. * Minimum life time of emitting particles.
  100. */
  101. public minLifeTime = 1;
  102. /**
  103. * Maximum life time of emitting particles.
  104. */
  105. public maxLifeTime = 1;
  106. /**
  107. * Minimum Size of emitting particles.
  108. */
  109. public minSize = 1;
  110. /**
  111. * Maximum Size of emitting particles.
  112. */
  113. public maxSize = 1;
  114. /**
  115. * Minimum scale of emitting particles on X axis.
  116. */
  117. public minScaleX = 1;
  118. /**
  119. * Maximum scale of emitting particles on X axis.
  120. */
  121. public maxScaleX = 1;
  122. /**
  123. * Minimum scale of emitting particles on Y axis.
  124. */
  125. public minScaleY = 1;
  126. /**
  127. * Maximum scale of emitting particles on Y axis.
  128. */
  129. public maxScaleY = 1;
  130. /**
  131. * Gets or sets the minimal initial rotation in radians.
  132. */
  133. public minInitialRotation = 0;
  134. /**
  135. * Gets or sets the maximal initial rotation in radians.
  136. */
  137. public maxInitialRotation = 0;
  138. /**
  139. * Minimum angular speed of emitting particles (Z-axis rotation for each particle).
  140. */
  141. public minAngularSpeed = 0;
  142. /**
  143. * Maximum angular speed of emitting particles (Z-axis rotation for each particle).
  144. */
  145. public maxAngularSpeed = 0;
  146. /**
  147. * The texture used to render each particle. (this can be a spritesheet)
  148. */
  149. public particleTexture: Nullable<Texture>;
  150. /**
  151. * The layer mask we are rendering the particles through.
  152. */
  153. public layerMask: number = 0x0FFFFFFF;
  154. /**
  155. * This can help using your own shader to render the particle system.
  156. * The according effect will be created
  157. */
  158. public customShader: any = null;
  159. /**
  160. * By default particle system starts as soon as they are created. This prevents the
  161. * automatic start to happen and let you decide when to start emitting particles.
  162. */
  163. public preventAutoStart: boolean = false;
  164. private _noiseTexture: Nullable<ProceduralTexture>;
  165. /**
  166. * Gets or sets a texture used to add random noise to particle positions
  167. */
  168. public get noiseTexture(): Nullable<ProceduralTexture> {
  169. return this._noiseTexture;
  170. }
  171. public set noiseTexture(value: Nullable<ProceduralTexture>) {
  172. if (this._noiseTexture === value) {
  173. return;
  174. }
  175. this._noiseTexture = value;
  176. this._reset();
  177. }
  178. /** Gets or sets the strength to apply to the noise value (default is (10, 10, 10)) */
  179. public noiseStrength = new Vector3(10, 10, 10);
  180. /**
  181. * Callback triggered when the particle animation is ending.
  182. */
  183. public onAnimationEnd: Nullable<() => void> = null;
  184. /**
  185. * Blend mode use to render the particle, it can be either ParticleSystem.BLENDMODE_ONEONE or ParticleSystem.BLENDMODE_STANDARD.
  186. */
  187. public blendMode = BaseParticleSystem.BLENDMODE_ONEONE;
  188. /**
  189. * Forces the particle to write their depth information to the depth buffer. This can help preventing other draw calls
  190. * to override the particles.
  191. */
  192. public forceDepthWrite = false;
  193. /** 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 */
  194. public preWarmCycles = 0;
  195. /** Gets or sets a value indicating the time step multiplier to use in pre-warm mode (default is 1) */
  196. public preWarmStepOffset = 1;
  197. /**
  198. * 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)
  199. */
  200. public spriteCellChangeSpeed = 1;
  201. /**
  202. * If using a spritesheet (isAnimationSheetEnabled) defines the first sprite cell to display
  203. */
  204. public startSpriteCellID = 0;
  205. /**
  206. * If using a spritesheet (isAnimationSheetEnabled) defines the last sprite cell to display
  207. */
  208. public endSpriteCellID = 0;
  209. /**
  210. * If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell width to use
  211. */
  212. public spriteCellWidth = 0;
  213. /**
  214. * If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell height to use
  215. */
  216. public spriteCellHeight = 0;
  217. /**
  218. * This allows the system to random pick the start cell ID between startSpriteCellID and endSpriteCellID
  219. */
  220. public spriteRandomStartCell = false;
  221. /** Gets or sets a Vector2 used to move the pivot (by default (0,0)) */
  222. public translationPivot = new Vector2(0, 0);
  223. /** @hidden */
  224. protected _isAnimationSheetEnabled: boolean;
  225. /**
  226. * Gets or sets a boolean indicating that hosted animations (in the system.animations array) must be started when system.start() is called
  227. */
  228. public beginAnimationOnStart = false;
  229. /**
  230. * Gets or sets the frame to start the animation from when beginAnimationOnStart is true
  231. */
  232. public beginAnimationFrom = 0;
  233. /**
  234. * Gets or sets the frame to end the animation on when beginAnimationOnStart is true
  235. */
  236. public beginAnimationTo = 60;
  237. /**
  238. * Gets or sets a boolean indicating if animations must loop when beginAnimationOnStart is true
  239. */
  240. public beginAnimationLoop = false;
  241. /**
  242. * Gets or sets a world offset applied to all particles
  243. */
  244. public worldOffset = new Vector3(0, 0, 0);
  245. /**
  246. * Gets or sets whether an animation sprite sheet is enabled or not on the particle system
  247. */
  248. public get isAnimationSheetEnabled(): boolean {
  249. return this._isAnimationSheetEnabled;
  250. }
  251. public set isAnimationSheetEnabled(value: boolean) {
  252. if (this._isAnimationSheetEnabled == value) {
  253. return;
  254. }
  255. this._isAnimationSheetEnabled = value;
  256. this._reset();
  257. }
  258. /**
  259. * Get hosting scene
  260. * @returns the scene
  261. */
  262. public getScene(): Nullable<Scene> {
  263. return this._scene;
  264. }
  265. /**
  266. * You can use gravity if you want to give an orientation to your particles.
  267. */
  268. public gravity = Vector3.Zero();
  269. protected _colorGradients: Nullable<Array<ColorGradient>> = null;
  270. protected _sizeGradients: Nullable<Array<FactorGradient>> = null;
  271. protected _lifeTimeGradients: Nullable<Array<FactorGradient>> = null;
  272. protected _angularSpeedGradients: Nullable<Array<FactorGradient>> = null;
  273. protected _velocityGradients: Nullable<Array<FactorGradient>> = null;
  274. protected _limitVelocityGradients: Nullable<Array<FactorGradient>> = null;
  275. protected _dragGradients: Nullable<Array<FactorGradient>> = null;
  276. protected _emitRateGradients: Nullable<Array<FactorGradient>> = null;
  277. protected _startSizeGradients: Nullable<Array<FactorGradient>> = null;
  278. protected _rampGradients: Nullable<Array<Color3Gradient>> = null;
  279. protected _colorRemapGradients: Nullable<Array<FactorGradient>> = null;
  280. protected _alphaRemapGradients: Nullable<Array<FactorGradient>> = null;
  281. protected _hasTargetStopDurationDependantGradient() {
  282. return (this._startSizeGradients && this._startSizeGradients.length > 0)
  283. || (this._emitRateGradients && this._emitRateGradients.length > 0)
  284. || (this._lifeTimeGradients && this._lifeTimeGradients.length > 0);
  285. }
  286. /**
  287. * Defines the delay in milliseconds before starting the system (0 by default)
  288. */
  289. public startDelay = 0;
  290. /**
  291. * Gets the current list of drag gradients.
  292. * You must use addDragGradient and removeDragGradient to udpate this list
  293. * @returns the list of drag gradients
  294. */
  295. public getDragGradients(): Nullable<Array<FactorGradient>> {
  296. return this._dragGradients;
  297. }
  298. /** Gets or sets a value indicating the damping to apply if the limit velocity factor is reached */
  299. public limitVelocityDamping = 0.4;
  300. /**
  301. * Gets the current list of limit velocity gradients.
  302. * You must use addLimitVelocityGradient and removeLimitVelocityGradient to udpate this list
  303. * @returns the list of limit velocity gradients
  304. */
  305. public getLimitVelocityGradients(): Nullable<Array<FactorGradient>> {
  306. return this._limitVelocityGradients;
  307. }
  308. /**
  309. * Gets the current list of color gradients.
  310. * You must use addColorGradient and removeColorGradient to udpate this list
  311. * @returns the list of color gradients
  312. */
  313. public getColorGradients(): Nullable<Array<ColorGradient>> {
  314. return this._colorGradients;
  315. }
  316. /**
  317. * Gets the current list of size gradients.
  318. * You must use addSizeGradient and removeSizeGradient to udpate this list
  319. * @returns the list of size gradients
  320. */
  321. public getSizeGradients(): Nullable<Array<FactorGradient>> {
  322. return this._sizeGradients;
  323. }
  324. /**
  325. * Gets the current list of color remap gradients.
  326. * You must use addColorRemapGradient and removeColorRemapGradient to udpate this list
  327. * @returns the list of color remap gradients
  328. */
  329. public getColorRemapGradients(): Nullable<Array<FactorGradient>> {
  330. return this._colorRemapGradients;
  331. }
  332. /**
  333. * Gets the current list of alpha remap gradients.
  334. * You must use addAlphaRemapGradient and removeAlphaRemapGradient to udpate this list
  335. * @returns the list of alpha remap gradients
  336. */
  337. public getAlphaRemapGradients(): Nullable<Array<FactorGradient>> {
  338. return this._alphaRemapGradients;
  339. }
  340. /**
  341. * Gets the current list of life time gradients.
  342. * You must use addLifeTimeGradient and removeLifeTimeGradient to udpate this list
  343. * @returns the list of life time gradients
  344. */
  345. public getLifeTimeGradients(): Nullable<Array<FactorGradient>> {
  346. return this._lifeTimeGradients;
  347. }
  348. /**
  349. * Gets the current list of angular speed gradients.
  350. * You must use addAngularSpeedGradient and removeAngularSpeedGradient to udpate this list
  351. * @returns the list of angular speed gradients
  352. */
  353. public getAngularSpeedGradients(): Nullable<Array<FactorGradient>> {
  354. return this._angularSpeedGradients;
  355. }
  356. /**
  357. * Gets the current list of velocity gradients.
  358. * You must use addVelocityGradient and removeVelocityGradient to udpate this list
  359. * @returns the list of velocity gradients
  360. */
  361. public getVelocityGradients(): Nullable<Array<FactorGradient>> {
  362. return this._velocityGradients;
  363. }
  364. /**
  365. * Gets the current list of start size gradients.
  366. * You must use addStartSizeGradient and removeStartSizeGradient to udpate this list
  367. * @returns the list of start size gradients
  368. */
  369. public getStartSizeGradients(): Nullable<Array<FactorGradient>> {
  370. return this._startSizeGradients;
  371. }
  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. public getEmitRateGradients(): Nullable<Array<FactorGradient>> {
  378. return this._emitRateGradients;
  379. }
  380. /**
  381. * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.
  382. * This only works when particleEmitterTyps is a BoxParticleEmitter
  383. */
  384. public get direction1(): Vector3 {
  385. if ((<BoxParticleEmitter>this.particleEmitterType).direction1) {
  386. return (<BoxParticleEmitter>this.particleEmitterType).direction1;
  387. }
  388. return Vector3.Zero();
  389. }
  390. public set direction1(value: Vector3) {
  391. if ((<BoxParticleEmitter>this.particleEmitterType).direction1) {
  392. (<BoxParticleEmitter>this.particleEmitterType).direction1 = value;
  393. }
  394. }
  395. /**
  396. * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.
  397. * This only works when particleEmitterTyps is a BoxParticleEmitter
  398. */
  399. public get direction2(): Vector3 {
  400. if ((<BoxParticleEmitter>this.particleEmitterType).direction2) {
  401. return (<BoxParticleEmitter>this.particleEmitterType).direction2;
  402. }
  403. return Vector3.Zero();
  404. }
  405. public set direction2(value: Vector3) {
  406. if ((<BoxParticleEmitter>this.particleEmitterType).direction2) {
  407. (<BoxParticleEmitter>this.particleEmitterType).direction2 = value;
  408. }
  409. }
  410. /**
  411. * Minimum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.
  412. * This only works when particleEmitterTyps is a BoxParticleEmitter
  413. */
  414. public get minEmitBox(): Vector3 {
  415. if ((<BoxParticleEmitter>this.particleEmitterType).minEmitBox) {
  416. return (<BoxParticleEmitter>this.particleEmitterType).minEmitBox;
  417. }
  418. return Vector3.Zero();
  419. }
  420. public set minEmitBox(value: Vector3) {
  421. if ((<BoxParticleEmitter>this.particleEmitterType).minEmitBox) {
  422. (<BoxParticleEmitter>this.particleEmitterType).minEmitBox = value;
  423. }
  424. }
  425. /**
  426. * Maximum box point around our emitter. Our emitter is the center of particles source, but if you want your particles to emit from more than one point, then you can tell it to do so.
  427. * This only works when particleEmitterTyps is a BoxParticleEmitter
  428. */
  429. public get maxEmitBox(): Vector3 {
  430. if ((<BoxParticleEmitter>this.particleEmitterType).maxEmitBox) {
  431. return (<BoxParticleEmitter>this.particleEmitterType).maxEmitBox;
  432. }
  433. return Vector3.Zero();
  434. }
  435. public set maxEmitBox(value: Vector3) {
  436. if ((<BoxParticleEmitter>this.particleEmitterType).maxEmitBox) {
  437. (<BoxParticleEmitter>this.particleEmitterType).maxEmitBox = value;
  438. }
  439. }
  440. /**
  441. * Random color of each particle after it has been emitted, between color1 and color2 vectors
  442. */
  443. public color1 = new Color4(1.0, 1.0, 1.0, 1.0);
  444. /**
  445. * Random color of each particle after it has been emitted, between color1 and color2 vectors
  446. */
  447. public color2 = new Color4(1.0, 1.0, 1.0, 1.0);
  448. /**
  449. * Color the particle will have at the end of its lifetime
  450. */
  451. public colorDead = new Color4(0, 0, 0, 1.0);
  452. /**
  453. * An optional mask to filter some colors out of the texture, or filter a part of the alpha channel
  454. */
  455. public textureMask = new Color4(1.0, 1.0, 1.0, 1.0);
  456. /**
  457. * The particle emitter type defines the emitter used by the particle system.
  458. * It can be for example box, sphere, or cone...
  459. */
  460. public particleEmitterType: IParticleEmitterType;
  461. /** @hidden */
  462. public _isSubEmitter = false;
  463. /**
  464. * Gets or sets the billboard mode to use when isBillboardBased = true.
  465. * Value can be: ParticleSystem.BILLBOARDMODE_ALL, ParticleSystem.BILLBOARDMODE_Y, ParticleSystem.BILLBOARDMODE_STRETCHED
  466. */
  467. public billboardMode = Constants.PARTICLES_BILLBOARDMODE_ALL;
  468. protected _isBillboardBased = true;
  469. /**
  470. * Gets or sets a boolean indicating if the particles must be rendered as billboard or aligned with the direction
  471. */
  472. public get isBillboardBased(): boolean {
  473. return this._isBillboardBased;
  474. }
  475. public set isBillboardBased(value: boolean) {
  476. if (this._isBillboardBased === value) {
  477. return;
  478. }
  479. this._isBillboardBased = value;
  480. this._reset();
  481. }
  482. /**
  483. * The scene the particle system belongs to.
  484. */
  485. protected _scene: Nullable<Scene>;
  486. /**
  487. * The engine the particle system belongs to.
  488. */
  489. protected _engine: ThinEngine;
  490. /**
  491. * Local cache of defines for image processing.
  492. */
  493. protected _imageProcessingConfigurationDefines = new ImageProcessingConfigurationDefines();
  494. /**
  495. * Default configuration related to image processing available in the standard Material.
  496. */
  497. protected _imageProcessingConfiguration: Nullable<ImageProcessingConfiguration>;
  498. /**
  499. * Gets the image processing configuration used either in this material.
  500. */
  501. public get imageProcessingConfiguration(): Nullable<ImageProcessingConfiguration> {
  502. return this._imageProcessingConfiguration;
  503. }
  504. /**
  505. * Sets the Default image processing configuration used either in the this material.
  506. *
  507. * If sets to null, the scene one is in use.
  508. */
  509. public set imageProcessingConfiguration(value: Nullable<ImageProcessingConfiguration>) {
  510. this._attachImageProcessingConfiguration(value);
  511. }
  512. /**
  513. * Attaches a new image processing configuration to the Standard Material.
  514. * @param configuration
  515. */
  516. protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>): void {
  517. if (configuration === this._imageProcessingConfiguration) {
  518. return;
  519. }
  520. // Pick the scene configuration if needed.
  521. if (!configuration && this._scene) {
  522. this._imageProcessingConfiguration = this._scene.imageProcessingConfiguration;
  523. }
  524. else {
  525. this._imageProcessingConfiguration = configuration;
  526. }
  527. }
  528. /** @hidden */
  529. protected _reset() {
  530. }
  531. /** @hidden */
  532. protected _removeGradientAndTexture(gradient: number, gradients: Nullable<IValueGradient[]>, texture: Nullable<RawTexture>): BaseParticleSystem {
  533. if (!gradients) {
  534. return this;
  535. }
  536. let index = 0;
  537. for (var valueGradient of gradients) {
  538. if (valueGradient.gradient === gradient) {
  539. gradients.splice(index, 1);
  540. break;
  541. }
  542. index++;
  543. }
  544. if (texture) {
  545. texture.dispose();
  546. }
  547. return this;
  548. }
  549. /**
  550. * Instantiates a particle system.
  551. * Particles are often small sprites used to simulate hard-to-reproduce phenomena like fire, smoke, water, or abstract visual effects like magic glitter and faery dust.
  552. * @param name The name of the particle system
  553. */
  554. public constructor(name: string) {
  555. this.id = name;
  556. this.name = name;
  557. }
  558. /**
  559. * Creates a Point Emitter for the particle system (emits directly from the emitter position)
  560. * @param direction1 Particles are emitted between the direction1 and direction2 from within the box
  561. * @param direction2 Particles are emitted between the direction1 and direction2 from within the box
  562. * @returns the emitter
  563. */
  564. public createPointEmitter(direction1: Vector3, direction2: Vector3): PointParticleEmitter {
  565. var particleEmitter = new PointParticleEmitter();
  566. particleEmitter.direction1 = direction1;
  567. particleEmitter.direction2 = direction2;
  568. this.particleEmitterType = particleEmitter;
  569. return particleEmitter;
  570. }
  571. /**
  572. * Creates a Hemisphere Emitter for the particle system (emits along the hemisphere radius)
  573. * @param radius The radius of the hemisphere to emit from
  574. * @param radiusRange The range of the hemisphere to emit from [0-1] 0 Surface Only, 1 Entire Radius
  575. * @returns the emitter
  576. */
  577. public createHemisphericEmitter(radius = 1, radiusRange = 1): HemisphericParticleEmitter {
  578. var particleEmitter = new HemisphericParticleEmitter(radius, radiusRange);
  579. this.particleEmitterType = particleEmitter;
  580. return particleEmitter;
  581. }
  582. /**
  583. * Creates a Sphere Emitter for the particle system (emits along the sphere radius)
  584. * @param radius The radius of the sphere to emit from
  585. * @param radiusRange The range of the sphere to emit from [0-1] 0 Surface Only, 1 Entire Radius
  586. * @returns the emitter
  587. */
  588. public createSphereEmitter(radius = 1, radiusRange = 1): SphereParticleEmitter {
  589. var particleEmitter = new SphereParticleEmitter(radius, radiusRange);
  590. this.particleEmitterType = particleEmitter;
  591. return particleEmitter;
  592. }
  593. /**
  594. * Creates a Directed Sphere Emitter for the particle system (emits between direction1 and direction2)
  595. * @param radius The radius of the sphere to emit from
  596. * @param direction1 Particles are emitted between the direction1 and direction2 from within the sphere
  597. * @param direction2 Particles are emitted between the direction1 and direction2 from within the sphere
  598. * @returns the emitter
  599. */
  600. public createDirectedSphereEmitter(radius = 1, direction1 = new Vector3(0, 1.0, 0), direction2 = new Vector3(0, 1.0, 0)): SphereDirectedParticleEmitter {
  601. var particleEmitter = new SphereDirectedParticleEmitter(radius, direction1, direction2);
  602. this.particleEmitterType = particleEmitter;
  603. return particleEmitter;
  604. }
  605. /**
  606. * Creates a Cylinder Emitter for the particle system (emits from the cylinder to the particle position)
  607. * @param radius The radius of the emission cylinder
  608. * @param height The height of the emission cylinder
  609. * @param radiusRange The range of emission [0-1] 0 Surface only, 1 Entire Radius
  610. * @param directionRandomizer How much to randomize the particle direction [0-1]
  611. * @returns the emitter
  612. */
  613. public createCylinderEmitter(radius = 1, height = 1, radiusRange = 1, directionRandomizer = 0): CylinderParticleEmitter {
  614. var particleEmitter = new CylinderParticleEmitter(radius, height, radiusRange, directionRandomizer);
  615. this.particleEmitterType = particleEmitter;
  616. return particleEmitter;
  617. }
  618. /**
  619. * Creates a Directed Cylinder Emitter for the particle system (emits between direction1 and direction2)
  620. * @param radius The radius of the cylinder to emit from
  621. * @param height The height of the emission cylinder
  622. * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)
  623. * @param direction1 Particles are emitted between the direction1 and direction2 from within the cylinder
  624. * @param direction2 Particles are emitted between the direction1 and direction2 from within the cylinder
  625. * @returns the emitter
  626. */
  627. public createDirectedCylinderEmitter(radius = 1, height = 1, radiusRange = 1, direction1 = new Vector3(0, 1.0, 0), direction2 = new Vector3(0, 1.0, 0)): CylinderDirectedParticleEmitter {
  628. var particleEmitter = new CylinderDirectedParticleEmitter(radius, height, radiusRange, direction1, direction2);
  629. this.particleEmitterType = particleEmitter;
  630. return particleEmitter;
  631. }
  632. /**
  633. * Creates a Cone Emitter for the particle system (emits from the cone to the particle position)
  634. * @param radius The radius of the cone to emit from
  635. * @param angle The base angle of the cone
  636. * @returns the emitter
  637. */
  638. public createConeEmitter(radius = 1, angle = Math.PI / 4): ConeParticleEmitter {
  639. var particleEmitter = new ConeParticleEmitter(radius, angle);
  640. this.particleEmitterType = particleEmitter;
  641. return particleEmitter;
  642. }
  643. /**
  644. * Creates a Box Emitter for the particle system. (emits between direction1 and direction2 from withing the box defined by minEmitBox and maxEmitBox)
  645. * @param direction1 Particles are emitted between the direction1 and direction2 from within the box
  646. * @param direction2 Particles are emitted between the direction1 and direction2 from within the box
  647. * @param minEmitBox Particles are emitted from the box between minEmitBox and maxEmitBox
  648. * @param maxEmitBox Particles are emitted from the box between minEmitBox and maxEmitBox
  649. * @returns the emitter
  650. */
  651. public createBoxEmitter(direction1: Vector3, direction2: Vector3, minEmitBox: Vector3, maxEmitBox: Vector3): BoxParticleEmitter {
  652. var particleEmitter = new BoxParticleEmitter();
  653. this.particleEmitterType = particleEmitter;
  654. this.direction1 = direction1;
  655. this.direction2 = direction2;
  656. this.minEmitBox = minEmitBox;
  657. this.maxEmitBox = maxEmitBox;
  658. return particleEmitter;
  659. }
  660. }