baseParticleSystem.ts 30 KB

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