particleSystemComponent.js 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { Mesh } from "../Meshes/mesh.js";
  2. import { GPUParticleSystem } from "./gpuParticleSystem.js";
  3. import { AbstractScene } from "../abstractScene.js";
  4. import { ParticleSystem } from "./particleSystem.js";
  5. import { SceneComponentConstants } from "../sceneComponent.js";
  6. import "../Shaders/particles.vertex.js";
  7. import { AbstractEngine } from "../Engines/abstractEngine.js";
  8. // Adds the parsers to the scene parsers.
  9. AbstractScene.AddParser(SceneComponentConstants.NAME_PARTICLESYSTEM, (parsedData, scene, container, rootUrl) => {
  10. const individualParser = AbstractScene.GetIndividualParser(SceneComponentConstants.NAME_PARTICLESYSTEM);
  11. if (!individualParser) {
  12. return;
  13. }
  14. // Particles Systems
  15. if (parsedData.particleSystems !== undefined && parsedData.particleSystems !== null) {
  16. for (let index = 0, cache = parsedData.particleSystems.length; index < cache; index++) {
  17. const parsedParticleSystem = parsedData.particleSystems[index];
  18. container.particleSystems.push(individualParser(parsedParticleSystem, scene, rootUrl));
  19. }
  20. }
  21. });
  22. AbstractScene.AddIndividualParser(SceneComponentConstants.NAME_PARTICLESYSTEM, (parsedParticleSystem, scene, rootUrl) => {
  23. if (parsedParticleSystem.activeParticleCount) {
  24. const ps = GPUParticleSystem.Parse(parsedParticleSystem, scene, rootUrl);
  25. return ps;
  26. }
  27. else {
  28. const ps = ParticleSystem.Parse(parsedParticleSystem, scene, rootUrl);
  29. return ps;
  30. }
  31. });
  32. AbstractEngine.prototype.createEffectForParticles = function (fragmentName, uniformsNames = [], samplers = [], defines = "", fallbacks, onCompiled, onError, particleSystem) {
  33. let attributesNamesOrOptions = [];
  34. let effectCreationOption = [];
  35. const allSamplers = [];
  36. if (particleSystem) {
  37. particleSystem.fillUniformsAttributesAndSamplerNames(effectCreationOption, attributesNamesOrOptions, allSamplers);
  38. }
  39. else {
  40. attributesNamesOrOptions = ParticleSystem._GetAttributeNamesOrOptions();
  41. effectCreationOption = ParticleSystem._GetEffectCreationOptions();
  42. }
  43. if (defines.indexOf(" BILLBOARD") === -1) {
  44. defines += "\n#define BILLBOARD\n";
  45. }
  46. if (particleSystem?.isAnimationSheetEnabled) {
  47. if (defines.indexOf(" ANIMATESHEET") === -1) {
  48. defines += "\n#define ANIMATESHEET\n";
  49. }
  50. }
  51. if (samplers.indexOf("diffuseSampler") === -1) {
  52. samplers.push("diffuseSampler");
  53. }
  54. return this.createEffect({
  55. vertex: particleSystem?.vertexShaderName ?? "particles",
  56. fragmentElement: fragmentName,
  57. }, attributesNamesOrOptions, effectCreationOption.concat(uniformsNames), allSamplers.concat(samplers), defines, fallbacks, onCompiled, onError);
  58. };
  59. Mesh.prototype.getEmittedParticleSystems = function () {
  60. const results = [];
  61. for (let index = 0; index < this.getScene().particleSystems.length; index++) {
  62. const particleSystem = this.getScene().particleSystems[index];
  63. if (particleSystem.emitter === this) {
  64. results.push(particleSystem);
  65. }
  66. }
  67. return results;
  68. };
  69. Mesh.prototype.getHierarchyEmittedParticleSystems = function () {
  70. const results = [];
  71. const descendants = this.getDescendants();
  72. descendants.push(this);
  73. for (let index = 0; index < this.getScene().particleSystems.length; index++) {
  74. const particleSystem = this.getScene().particleSystems[index];
  75. const emitter = particleSystem.emitter;
  76. if (emitter.position && descendants.indexOf(emitter) !== -1) {
  77. results.push(particleSystem);
  78. }
  79. }
  80. return results;
  81. };
  82. //# sourceMappingURL=particleSystemComponent.js.map