baseParticleSystem.ts 28 KB

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