baseParticleSystem.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  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. protected _rootUrl = "";
  166. private _noiseTexture: Nullable<ProceduralTexture>;
  167. /**
  168. * Gets or sets a texture used to add random noise to particle positions
  169. */
  170. public get noiseTexture(): Nullable<ProceduralTexture> {
  171. return this._noiseTexture;
  172. }
  173. public set noiseTexture(value: Nullable<ProceduralTexture>) {
  174. if (this._noiseTexture === value) {
  175. return;
  176. }
  177. this._noiseTexture = value;
  178. this._reset();
  179. }
  180. /** Gets or sets the strength to apply to the noise value (default is (10, 10, 10)) */
  181. public noiseStrength = new Vector3(10, 10, 10);
  182. /**
  183. * Callback triggered when the particle animation is ending.
  184. */
  185. public onAnimationEnd: Nullable<() => void> = null;
  186. /**
  187. * Blend mode use to render the particle, it can be either ParticleSystem.BLENDMODE_ONEONE or ParticleSystem.BLENDMODE_STANDARD.
  188. */
  189. public blendMode = BaseParticleSystem.BLENDMODE_ONEONE;
  190. /**
  191. * Forces the particle to write their depth information to the depth buffer. This can help preventing other draw calls
  192. * to override the particles.
  193. */
  194. public forceDepthWrite = false;
  195. /** 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 */
  196. public preWarmCycles = 0;
  197. /** Gets or sets a value indicating the time step multiplier to use in pre-warm mode (default is 1) */
  198. public preWarmStepOffset = 1;
  199. /**
  200. * 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)
  201. */
  202. public spriteCellChangeSpeed = 1;
  203. /**
  204. * If using a spritesheet (isAnimationSheetEnabled) defines the first sprite cell to display
  205. */
  206. public startSpriteCellID = 0;
  207. /**
  208. * If using a spritesheet (isAnimationSheetEnabled) defines the last sprite cell to display
  209. */
  210. public endSpriteCellID = 0;
  211. /**
  212. * If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell width to use
  213. */
  214. public spriteCellWidth = 0;
  215. /**
  216. * If using a spritesheet (isAnimationSheetEnabled), defines the sprite cell height to use
  217. */
  218. public spriteCellHeight = 0;
  219. /**
  220. * This allows the system to random pick the start cell ID between startSpriteCellID and endSpriteCellID
  221. */
  222. public spriteRandomStartCell = false;
  223. /** Gets or sets a Vector2 used to move the pivot (by default (0,0)) */
  224. public translationPivot = new Vector2(0, 0);
  225. /** @hidden */
  226. protected _isAnimationSheetEnabled: boolean;
  227. /**
  228. * Gets or sets a boolean indicating that hosted animations (in the system.animations array) must be started when system.start() is called
  229. */
  230. public beginAnimationOnStart = false;
  231. /**
  232. * Gets or sets the frame to start the animation from when beginAnimationOnStart is true
  233. */
  234. public beginAnimationFrom = 0;
  235. /**
  236. * Gets or sets the frame to end the animation on when beginAnimationOnStart is true
  237. */
  238. public beginAnimationTo = 60;
  239. /**
  240. * Gets or sets a boolean indicating if animations must loop when beginAnimationOnStart is true
  241. */
  242. public beginAnimationLoop = false;
  243. /**
  244. * Gets or sets a world offset applied to all particles
  245. */
  246. public worldOffset = new Vector3(0, 0, 0);
  247. /**
  248. * Gets or sets whether an animation sprite sheet is enabled or not on the particle system
  249. */
  250. public get isAnimationSheetEnabled(): boolean {
  251. return this._isAnimationSheetEnabled;
  252. }
  253. public set isAnimationSheetEnabled(value: boolean) {
  254. if (this._isAnimationSheetEnabled == value) {
  255. return;
  256. }
  257. this._isAnimationSheetEnabled = value;
  258. this._reset();
  259. }
  260. /**
  261. * Get hosting scene
  262. * @returns the scene
  263. */
  264. public getScene(): Nullable<Scene> {
  265. return this._scene;
  266. }
  267. /**
  268. * You can use gravity if you want to give an orientation to your particles.
  269. */
  270. public gravity = Vector3.Zero();
  271. protected _colorGradients: Nullable<Array<ColorGradient>> = null;
  272. protected _sizeGradients: Nullable<Array<FactorGradient>> = null;
  273. protected _lifeTimeGradients: Nullable<Array<FactorGradient>> = null;
  274. protected _angularSpeedGradients: Nullable<Array<FactorGradient>> = null;
  275. protected _velocityGradients: Nullable<Array<FactorGradient>> = null;
  276. protected _limitVelocityGradients: Nullable<Array<FactorGradient>> = null;
  277. protected _dragGradients: Nullable<Array<FactorGradient>> = null;
  278. protected _emitRateGradients: Nullable<Array<FactorGradient>> = null;
  279. protected _startSizeGradients: Nullable<Array<FactorGradient>> = null;
  280. protected _rampGradients: Nullable<Array<Color3Gradient>> = null;
  281. protected _colorRemapGradients: Nullable<Array<FactorGradient>> = null;
  282. protected _alphaRemapGradients: Nullable<Array<FactorGradient>> = null;
  283. protected _hasTargetStopDurationDependantGradient() {
  284. return (this._startSizeGradients && this._startSizeGradients.length > 0)
  285. || (this._emitRateGradients && this._emitRateGradients.length > 0)
  286. || (this._lifeTimeGradients && this._lifeTimeGradients.length > 0);
  287. }
  288. /**
  289. * Defines the delay in milliseconds before starting the system (0 by default)
  290. */
  291. public startDelay = 0;
  292. /**
  293. * Gets the current list of drag gradients.
  294. * You must use addDragGradient and removeDragGradient to udpate this list
  295. * @returns the list of drag gradients
  296. */
  297. public getDragGradients(): Nullable<Array<FactorGradient>> {
  298. return this._dragGradients;
  299. }
  300. /** Gets or sets a value indicating the damping to apply if the limit velocity factor is reached */
  301. public limitVelocityDamping = 0.4;
  302. /**
  303. * Gets the current list of limit velocity gradients.
  304. * You must use addLimitVelocityGradient and removeLimitVelocityGradient to udpate this list
  305. * @returns the list of limit velocity gradients
  306. */
  307. public getLimitVelocityGradients(): Nullable<Array<FactorGradient>> {
  308. return this._limitVelocityGradients;
  309. }
  310. /**
  311. * Gets the current list of color gradients.
  312. * You must use addColorGradient and removeColorGradient to udpate this list
  313. * @returns the list of color gradients
  314. */
  315. public getColorGradients(): Nullable<Array<ColorGradient>> {
  316. return this._colorGradients;
  317. }
  318. /**
  319. * Gets the current list of size gradients.
  320. * You must use addSizeGradient and removeSizeGradient to udpate this list
  321. * @returns the list of size gradients
  322. */
  323. public getSizeGradients(): Nullable<Array<FactorGradient>> {
  324. return this._sizeGradients;
  325. }
  326. /**
  327. * Gets the current list of color remap gradients.
  328. * You must use addColorRemapGradient and removeColorRemapGradient to udpate this list
  329. * @returns the list of color remap gradients
  330. */
  331. public getColorRemapGradients(): Nullable<Array<FactorGradient>> {
  332. return this._colorRemapGradients;
  333. }
  334. /**
  335. * Gets the current list of alpha remap gradients.
  336. * You must use addAlphaRemapGradient and removeAlphaRemapGradient to udpate this list
  337. * @returns the list of alpha remap gradients
  338. */
  339. public getAlphaRemapGradients(): Nullable<Array<FactorGradient>> {
  340. return this._alphaRemapGradients;
  341. }
  342. /**
  343. * Gets the current list of life time gradients.
  344. * You must use addLifeTimeGradient and removeLifeTimeGradient to udpate this list
  345. * @returns the list of life time gradients
  346. */
  347. public getLifeTimeGradients(): Nullable<Array<FactorGradient>> {
  348. return this._lifeTimeGradients;
  349. }
  350. /**
  351. * Gets the current list of angular speed gradients.
  352. * You must use addAngularSpeedGradient and removeAngularSpeedGradient to udpate this list
  353. * @returns the list of angular speed gradients
  354. */
  355. public getAngularSpeedGradients(): Nullable<Array<FactorGradient>> {
  356. return this._angularSpeedGradients;
  357. }
  358. /**
  359. * Gets the current list of velocity gradients.
  360. * You must use addVelocityGradient and removeVelocityGradient to udpate this list
  361. * @returns the list of velocity gradients
  362. */
  363. public getVelocityGradients(): Nullable<Array<FactorGradient>> {
  364. return this._velocityGradients;
  365. }
  366. /**
  367. * Gets the current list of start size gradients.
  368. * You must use addStartSizeGradient and removeStartSizeGradient to udpate this list
  369. * @returns the list of start size gradients
  370. */
  371. public getStartSizeGradients(): Nullable<Array<FactorGradient>> {
  372. return this._startSizeGradients;
  373. }
  374. /**
  375. * Gets the current list of emit rate gradients.
  376. * You must use addEmitRateGradient and removeEmitRateGradient to udpate this list
  377. * @returns the list of emit rate gradients
  378. */
  379. public getEmitRateGradients(): Nullable<Array<FactorGradient>> {
  380. return this._emitRateGradients;
  381. }
  382. /**
  383. * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.
  384. * This only works when particleEmitterTyps is a BoxParticleEmitter
  385. */
  386. public get direction1(): Vector3 {
  387. if ((<BoxParticleEmitter>this.particleEmitterType).direction1) {
  388. return (<BoxParticleEmitter>this.particleEmitterType).direction1;
  389. }
  390. return Vector3.Zero();
  391. }
  392. public set direction1(value: Vector3) {
  393. if ((<BoxParticleEmitter>this.particleEmitterType).direction1) {
  394. (<BoxParticleEmitter>this.particleEmitterType).direction1 = value;
  395. }
  396. }
  397. /**
  398. * Random direction of each particle after it has been emitted, between direction1 and direction2 vectors.
  399. * This only works when particleEmitterTyps is a BoxParticleEmitter
  400. */
  401. public get direction2(): Vector3 {
  402. if ((<BoxParticleEmitter>this.particleEmitterType).direction2) {
  403. return (<BoxParticleEmitter>this.particleEmitterType).direction2;
  404. }
  405. return Vector3.Zero();
  406. }
  407. public set direction2(value: Vector3) {
  408. if ((<BoxParticleEmitter>this.particleEmitterType).direction2) {
  409. (<BoxParticleEmitter>this.particleEmitterType).direction2 = value;
  410. }
  411. }
  412. /**
  413. * 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.
  414. * This only works when particleEmitterTyps is a BoxParticleEmitter
  415. */
  416. public get minEmitBox(): Vector3 {
  417. if ((<BoxParticleEmitter>this.particleEmitterType).minEmitBox) {
  418. return (<BoxParticleEmitter>this.particleEmitterType).minEmitBox;
  419. }
  420. return Vector3.Zero();
  421. }
  422. public set minEmitBox(value: Vector3) {
  423. if ((<BoxParticleEmitter>this.particleEmitterType).minEmitBox) {
  424. (<BoxParticleEmitter>this.particleEmitterType).minEmitBox = value;
  425. }
  426. }
  427. /**
  428. * 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.
  429. * This only works when particleEmitterTyps is a BoxParticleEmitter
  430. */
  431. public get maxEmitBox(): Vector3 {
  432. if ((<BoxParticleEmitter>this.particleEmitterType).maxEmitBox) {
  433. return (<BoxParticleEmitter>this.particleEmitterType).maxEmitBox;
  434. }
  435. return Vector3.Zero();
  436. }
  437. public set maxEmitBox(value: Vector3) {
  438. if ((<BoxParticleEmitter>this.particleEmitterType).maxEmitBox) {
  439. (<BoxParticleEmitter>this.particleEmitterType).maxEmitBox = value;
  440. }
  441. }
  442. /**
  443. * Random color of each particle after it has been emitted, between color1 and color2 vectors
  444. */
  445. public color1 = new Color4(1.0, 1.0, 1.0, 1.0);
  446. /**
  447. * Random color of each particle after it has been emitted, between color1 and color2 vectors
  448. */
  449. public color2 = new Color4(1.0, 1.0, 1.0, 1.0);
  450. /**
  451. * Color the particle will have at the end of its lifetime
  452. */
  453. public colorDead = new Color4(0, 0, 0, 1.0);
  454. /**
  455. * An optional mask to filter some colors out of the texture, or filter a part of the alpha channel
  456. */
  457. public textureMask = new Color4(1.0, 1.0, 1.0, 1.0);
  458. /**
  459. * The particle emitter type defines the emitter used by the particle system.
  460. * It can be for example box, sphere, or cone...
  461. */
  462. public particleEmitterType: IParticleEmitterType;
  463. /** @hidden */
  464. public _isSubEmitter = false;
  465. /**
  466. * Gets or sets the billboard mode to use when isBillboardBased = true.
  467. * Value can be: ParticleSystem.BILLBOARDMODE_ALL, ParticleSystem.BILLBOARDMODE_Y, ParticleSystem.BILLBOARDMODE_STRETCHED
  468. */
  469. public billboardMode = Constants.PARTICLES_BILLBOARDMODE_ALL;
  470. protected _isBillboardBased = true;
  471. /**
  472. * Gets or sets a boolean indicating if the particles must be rendered as billboard or aligned with the direction
  473. */
  474. public get isBillboardBased(): boolean {
  475. return this._isBillboardBased;
  476. }
  477. public set isBillboardBased(value: boolean) {
  478. if (this._isBillboardBased === value) {
  479. return;
  480. }
  481. this._isBillboardBased = value;
  482. this._reset();
  483. }
  484. /**
  485. * The scene the particle system belongs to.
  486. */
  487. protected _scene: Nullable<Scene>;
  488. /**
  489. * The engine the particle system belongs to.
  490. */
  491. protected _engine: ThinEngine;
  492. /**
  493. * Local cache of defines for image processing.
  494. */
  495. protected _imageProcessingConfigurationDefines = new ImageProcessingConfigurationDefines();
  496. /**
  497. * Default configuration related to image processing available in the standard Material.
  498. */
  499. protected _imageProcessingConfiguration: Nullable<ImageProcessingConfiguration>;
  500. /**
  501. * Gets the image processing configuration used either in this material.
  502. */
  503. public get imageProcessingConfiguration(): Nullable<ImageProcessingConfiguration> {
  504. return this._imageProcessingConfiguration;
  505. }
  506. /**
  507. * Sets the Default image processing configuration used either in the this material.
  508. *
  509. * If sets to null, the scene one is in use.
  510. */
  511. public set imageProcessingConfiguration(value: Nullable<ImageProcessingConfiguration>) {
  512. this._attachImageProcessingConfiguration(value);
  513. }
  514. /**
  515. * Attaches a new image processing configuration to the Standard Material.
  516. * @param configuration
  517. */
  518. protected _attachImageProcessingConfiguration(configuration: Nullable<ImageProcessingConfiguration>): void {
  519. if (configuration === this._imageProcessingConfiguration) {
  520. return;
  521. }
  522. // Pick the scene configuration if needed.
  523. if (!configuration && this._scene) {
  524. this._imageProcessingConfiguration = this._scene.imageProcessingConfiguration;
  525. }
  526. else {
  527. this._imageProcessingConfiguration = configuration;
  528. }
  529. }
  530. /** @hidden */
  531. protected _reset() {
  532. }
  533. /** @hidden */
  534. protected _removeGradientAndTexture(gradient: number, gradients: Nullable<IValueGradient[]>, texture: Nullable<RawTexture>): BaseParticleSystem {
  535. if (!gradients) {
  536. return this;
  537. }
  538. let index = 0;
  539. for (var valueGradient of gradients) {
  540. if (valueGradient.gradient === gradient) {
  541. gradients.splice(index, 1);
  542. break;
  543. }
  544. index++;
  545. }
  546. if (texture) {
  547. texture.dispose();
  548. }
  549. return this;
  550. }
  551. /**
  552. * Instantiates a particle system.
  553. * 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.
  554. * @param name The name of the particle system
  555. */
  556. public constructor(name: string) {
  557. this.id = name;
  558. this.name = name;
  559. }
  560. /**
  561. * Creates a Point Emitter for the particle system (emits directly from the emitter position)
  562. * @param direction1 Particles are emitted between the direction1 and direction2 from within the box
  563. * @param direction2 Particles are emitted between the direction1 and direction2 from within the box
  564. * @returns the emitter
  565. */
  566. public createPointEmitter(direction1: Vector3, direction2: Vector3): PointParticleEmitter {
  567. var particleEmitter = new PointParticleEmitter();
  568. particleEmitter.direction1 = direction1;
  569. particleEmitter.direction2 = direction2;
  570. this.particleEmitterType = particleEmitter;
  571. return particleEmitter;
  572. }
  573. /**
  574. * Creates a Hemisphere Emitter for the particle system (emits along the hemisphere radius)
  575. * @param radius The radius of the hemisphere to emit from
  576. * @param radiusRange The range of the hemisphere to emit from [0-1] 0 Surface Only, 1 Entire Radius
  577. * @returns the emitter
  578. */
  579. public createHemisphericEmitter(radius = 1, radiusRange = 1): HemisphericParticleEmitter {
  580. var particleEmitter = new HemisphericParticleEmitter(radius, radiusRange);
  581. this.particleEmitterType = particleEmitter;
  582. return particleEmitter;
  583. }
  584. /**
  585. * Creates a Sphere Emitter for the particle system (emits along the sphere radius)
  586. * @param radius The radius of the sphere to emit from
  587. * @param radiusRange The range of the sphere to emit from [0-1] 0 Surface Only, 1 Entire Radius
  588. * @returns the emitter
  589. */
  590. public createSphereEmitter(radius = 1, radiusRange = 1): SphereParticleEmitter {
  591. var particleEmitter = new SphereParticleEmitter(radius, radiusRange);
  592. this.particleEmitterType = particleEmitter;
  593. return particleEmitter;
  594. }
  595. /**
  596. * Creates a Directed Sphere Emitter for the particle system (emits between direction1 and direction2)
  597. * @param radius The radius of the sphere to emit from
  598. * @param direction1 Particles are emitted between the direction1 and direction2 from within the sphere
  599. * @param direction2 Particles are emitted between the direction1 and direction2 from within the sphere
  600. * @returns the emitter
  601. */
  602. public createDirectedSphereEmitter(radius = 1, direction1 = new Vector3(0, 1.0, 0), direction2 = new Vector3(0, 1.0, 0)): SphereDirectedParticleEmitter {
  603. var particleEmitter = new SphereDirectedParticleEmitter(radius, direction1, direction2);
  604. this.particleEmitterType = particleEmitter;
  605. return particleEmitter;
  606. }
  607. /**
  608. * Creates a Cylinder Emitter for the particle system (emits from the cylinder to the particle position)
  609. * @param radius The radius of the emission cylinder
  610. * @param height The height of the emission cylinder
  611. * @param radiusRange The range of emission [0-1] 0 Surface only, 1 Entire Radius
  612. * @param directionRandomizer How much to randomize the particle direction [0-1]
  613. * @returns the emitter
  614. */
  615. public createCylinderEmitter(radius = 1, height = 1, radiusRange = 1, directionRandomizer = 0): CylinderParticleEmitter {
  616. var particleEmitter = new CylinderParticleEmitter(radius, height, radiusRange, directionRandomizer);
  617. this.particleEmitterType = particleEmitter;
  618. return particleEmitter;
  619. }
  620. /**
  621. * Creates a Directed Cylinder Emitter for the particle system (emits between direction1 and direction2)
  622. * @param radius The radius of the cylinder to emit from
  623. * @param height The height of the emission cylinder
  624. * @param radiusRange the range of the emission cylinder [0-1] 0 Surface only, 1 Entire Radius (1 by default)
  625. * @param direction1 Particles are emitted between the direction1 and direction2 from within the cylinder
  626. * @param direction2 Particles are emitted between the direction1 and direction2 from within the cylinder
  627. * @returns the emitter
  628. */
  629. public createDirectedCylinderEmitter(radius = 1, height = 1, radiusRange = 1, direction1 = new Vector3(0, 1.0, 0), direction2 = new Vector3(0, 1.0, 0)): CylinderDirectedParticleEmitter {
  630. var particleEmitter = new CylinderDirectedParticleEmitter(radius, height, radiusRange, direction1, direction2);
  631. this.particleEmitterType = particleEmitter;
  632. return particleEmitter;
  633. }
  634. /**
  635. * Creates a Cone Emitter for the particle system (emits from the cone to the particle position)
  636. * @param radius The radius of the cone to emit from
  637. * @param angle The base angle of the cone
  638. * @returns the emitter
  639. */
  640. public createConeEmitter(radius = 1, angle = Math.PI / 4): ConeParticleEmitter {
  641. var particleEmitter = new ConeParticleEmitter(radius, angle);
  642. this.particleEmitterType = particleEmitter;
  643. return particleEmitter;
  644. }
  645. /**
  646. * Creates a Box Emitter for the particle system. (emits between direction1 and direction2 from withing the box defined by minEmitBox and maxEmitBox)
  647. * @param direction1 Particles are emitted between the direction1 and direction2 from within the box
  648. * @param direction2 Particles are emitted between the direction1 and direction2 from within the box
  649. * @param minEmitBox Particles are emitted from the box between minEmitBox and maxEmitBox
  650. * @param maxEmitBox Particles are emitted from the box between minEmitBox and maxEmitBox
  651. * @returns the emitter
  652. */
  653. public createBoxEmitter(direction1: Vector3, direction2: Vector3, minEmitBox: Vector3, maxEmitBox: Vector3): BoxParticleEmitter {
  654. var particleEmitter = new BoxParticleEmitter();
  655. this.particleEmitterType = particleEmitter;
  656. this.direction1 = direction1;
  657. this.direction2 = direction2;
  658. this.minEmitBox = minEmitBox;
  659. this.maxEmitBox = maxEmitBox;
  660. return particleEmitter;
  661. }
  662. }