fluidRenderingObjectParticleSystem.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { FluidRenderingObject } from "./fluidRenderingObject.js";
  2. /**
  3. * Defines a rendering object based on a particle system
  4. */
  5. export class FluidRenderingObjectParticleSystem extends FluidRenderingObject {
  6. /** Gets the particle system */
  7. get particleSystem() {
  8. return this._particleSystem;
  9. }
  10. /**
  11. * @returns the name of the class
  12. */
  13. getClassName() {
  14. return "FluidRenderingObjectParticleSystem";
  15. }
  16. /**
  17. * Gets or sets a boolean indicating that the diffuse texture should be generated based on the regular rendering of the particle system (default: true).
  18. * Sometimes, generating the diffuse texture this way may be sub-optimal. In that case, you can disable this property, in which case the particle system will be
  19. * rendered using a ALPHA_COMBINE mode instead of the one used by the particle system.
  20. */
  21. get useTrueRenderingForDiffuseTexture() {
  22. return this._useTrueRenderingForDiffuseTexture;
  23. }
  24. set useTrueRenderingForDiffuseTexture(use) {
  25. if (this._useTrueRenderingForDiffuseTexture === use) {
  26. return;
  27. }
  28. this._useTrueRenderingForDiffuseTexture = use;
  29. if (use) {
  30. this._particleSystem.blendMode = this._blendMode;
  31. this._particleSystem.onBeforeDrawParticlesObservable.remove(this._onBeforeDrawParticleObserver);
  32. this._onBeforeDrawParticleObserver = null;
  33. }
  34. else {
  35. this._particleSystem.blendMode = -1;
  36. this._onBeforeDrawParticleObserver = this._particleSystem.onBeforeDrawParticlesObservable.add(() => {
  37. this._engine.setAlphaMode(2);
  38. });
  39. }
  40. }
  41. /**
  42. * Gets the vertex buffers
  43. */
  44. get vertexBuffers() {
  45. return this._particleSystem.vertexBuffers;
  46. }
  47. /**
  48. * Gets the index buffer (or null if the object is using instancing)
  49. */
  50. get indexBuffer() {
  51. return this._particleSystem.indexBuffer;
  52. }
  53. /**
  54. * Creates a new instance of the class
  55. * @param scene The scene the particle system is part of
  56. * @param ps The particle system
  57. */
  58. constructor(scene, ps) {
  59. super(scene);
  60. this._useTrueRenderingForDiffuseTexture = true;
  61. this._particleSystem = ps;
  62. this._originalRender = ps.render.bind(ps);
  63. this._blendMode = ps.blendMode;
  64. this._onBeforeDrawParticleObserver = null;
  65. this._updateInAnimate = this._particleSystem.updateInAnimate;
  66. this._particleSystem.updateInAnimate = true;
  67. this._particleSystem.render = () => 0;
  68. this.particleSize = (ps.minSize + ps.maxSize) / 2;
  69. this.useTrueRenderingForDiffuseTexture = false;
  70. }
  71. /**
  72. * Indicates if the object is ready to be rendered
  73. * @returns True if everything is ready for the object to be rendered, otherwise false
  74. */
  75. isReady() {
  76. return super.isReady() && this._particleSystem.isReady();
  77. }
  78. /**
  79. * Gets the number of particles in this particle system
  80. * @returns The number of particles
  81. */
  82. get numParticles() {
  83. return this._particleSystem.getActiveCount();
  84. }
  85. /**
  86. * Render the diffuse texture for this object
  87. */
  88. renderDiffuseTexture() {
  89. this._originalRender();
  90. }
  91. /**
  92. * Releases the ressources used by the class
  93. */
  94. dispose() {
  95. super.dispose();
  96. this._particleSystem.onBeforeDrawParticlesObservable.remove(this._onBeforeDrawParticleObserver);
  97. this._onBeforeDrawParticleObserver = null;
  98. this._particleSystem.render = this._originalRender;
  99. this._particleSystem.blendMode = this._blendMode;
  100. this._particleSystem.updateInAnimate = this._updateInAnimate;
  101. }
  102. }
  103. //# sourceMappingURL=fluidRenderingObjectParticleSystem.js.map