baseParticleSystem.ts 28 KB

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