Przeglądaj źródła

fix particle serialization and clone for custom effect

David Catuhe 7 lat temu
rodzic
commit
2c629bc414

+ 8 - 2
src/Engine/babylon.engine.ts

@@ -3450,7 +3450,13 @@
             var attributesNamesOrOptions = ParticleSystem._GetAttributeNamesOrOptions();
             var effectCreationOption = ParticleSystem._GetEffectCreationOptions();
 
-            defines += "\n#define BILLBOARD\n";
+            if (defines.indexOf(" BILLBOARD") === -1) {
+                defines += "\n#define BILLBOARD\n";
+            }
+
+            if (samplers.indexOf("diffuseSampler") === -1) {
+                samplers.push("diffuseSampler");
+            }
 
             return this.createEffect(
                 {
@@ -3459,7 +3465,7 @@
                 },
                 attributesNamesOrOptions,
                 effectCreationOption.concat(uniformsNames),
-                ["diffuseSampler"].concat(samplers), defines, fallbacks, onCompiled, onError);
+                samplers, defines, fallbacks, onCompiled, onError);
         }
 
         /**

+ 7 - 2
src/Particles/babylon.particleSystem.ts

@@ -1329,6 +1329,8 @@
                 program = this.customShader;
                 var defines: string = (program.shaderOptions.defines.length > 0) ? program.shaderOptions.defines.join("\n") : "";
                 custom = this._scene.getEngine().createEffectForParticles(program.shaderPath.fragmentElement, program.shaderOptions.uniforms, program.shaderOptions.samplers, defines);
+            } else if (this._customEffect) {
+                custom = this._customEffect;
             }
             var result = new ParticleSystem(name, this._capacity, this._scene, custom);
             result.customShader = program;
@@ -1537,8 +1539,8 @@
             }       
             
             // Emitter
+            let emitterType: IParticleEmitterType;
             if (parsedParticleSystem.particleEmitterType) {
-                let emitterType: IParticleEmitterType;
                 switch (parsedParticleSystem.particleEmitterType.type) {
                     case "SphereEmitter":
                         emitterType = new SphereParticleEmitter();
@@ -1556,8 +1558,11 @@
                 }
 
                 emitterType.parse(parsedParticleSystem.particleEmitterType);
-                particleSystem.particleEmitterType = emitterType;
+            } else {
+                emitterType = new BoxParticleEmitter();
+                emitterType.parse(parsedParticleSystem);
             }
+            particleSystem.particleEmitterType = emitterType;
         }
 
         /**