babylon.subEmitter.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. module BABYLON {
  2. /**
  3. * Type of sub emitter
  4. */
  5. export enum SubEmitterType {
  6. /**
  7. * Attached to the particle over it's lifetime
  8. */
  9. ATTACHED,
  10. /**
  11. * Created when the particle dies
  12. */
  13. END
  14. }
  15. /**
  16. * Sub emitter class used to emit particles from an existing particle
  17. */
  18. export class SubEmitter {
  19. /**
  20. * Type of the submitter (Default: END)
  21. */
  22. public type = SubEmitterType.END;
  23. /**
  24. * If the particle should inherit the direction from the particle it's attached to. (+Y will face the direction the particle is moving) (Default: false)
  25. * Note: This only is supported when using an emitter of type Mesh
  26. */
  27. public inheritDirection = false;
  28. /**
  29. * How much of the attached particles speed should be added to the sub emitted particle (default: 0)
  30. */
  31. public inheritedVelocityAmount = 0;
  32. /**
  33. * Creates a sub emitter
  34. * @param particleSystem the particle system to be used by the sub emitter
  35. */
  36. constructor(
  37. /**
  38. * the particle system to be used by the sub emitter
  39. */
  40. public particleSystem: ParticleSystem) {
  41. }
  42. /**
  43. * Clones the sub emitter
  44. * @returns the cloned sub emitter
  45. */
  46. clone(): SubEmitter {
  47. // Clone particle system
  48. var emitter = this.particleSystem.emitter;
  49. if (!emitter) {
  50. emitter = new Vector3();
  51. } else if (emitter instanceof Vector3) {
  52. emitter = emitter.clone();
  53. } else if (emitter instanceof AbstractMesh) {
  54. emitter = new Mesh("", emitter.getScene());
  55. emitter.isVisible = false;
  56. }
  57. var clone = new SubEmitter(this.particleSystem.clone("", emitter));
  58. // Clone properties
  59. clone.type = this.type;
  60. clone.inheritDirection = this.inheritDirection;
  61. clone.inheritedVelocityAmount = this.inheritedVelocityAmount;
  62. clone.particleSystem._disposeEmitterOnDispose = true;
  63. clone.particleSystem.disposeOnStop = true;
  64. return clone;
  65. }
  66. }
  67. }