Explorar el Código

Merge pull request #7860 from sebavan/master

Fix ParticleSystem and NoiseTexture Clone
David Catuhe hace 5 años
padre
commit
ec3dc9df9c

+ 24 - 0
src/Materials/Textures/Procedurals/noiseProceduralTexture.ts

@@ -82,6 +82,30 @@ export class NoiseProceduralTexture extends ProceduralTexture {
     }
 
     /**
+     * Clone the texture.
+     * @returns the cloned texture
+     */
+    public clone(): NoiseProceduralTexture {
+        var textureSize = this.getSize();
+        var newTexture = new NoiseProceduralTexture(this.name, textureSize.width, this.getScene(), this._fallbackTexture ? this._fallbackTexture : undefined, this._generateMipMaps);
+
+        // Base texture
+        newTexture.hasAlpha = this.hasAlpha;
+        newTexture.level = this.level;
+
+        // RenderTarget Texture
+        newTexture.coordinatesMode = this.coordinatesMode;
+
+        // Noise Specifics
+        newTexture.brightness = this.brightness;
+        newTexture.octaves = this.octaves;
+        newTexture.persistence = this.persistence;
+        newTexture.animationSpeedFactor = this.animationSpeedFactor;
+
+        return newTexture;
+    }
+
+    /**
      * Creates a NoiseProceduralTexture from parsed noise procedural texture data
      * @param parsedTexture defines parsed texture data
      * @param scene defines the current scene

+ 3 - 2
src/Materials/Textures/Procedurals/proceduralTexture.ts

@@ -57,6 +57,9 @@ export class ProceduralTexture extends Texture {
     /** @hidden */
     public _textures: { [key: string]: Texture } = {};
 
+    /** @hidden */
+    protected _fallbackTexture: Nullable<Texture>;
+
     @serialize()
     private _size: number;
     private _currentRefreshId = -1;
@@ -77,8 +80,6 @@ export class ProceduralTexture extends Texture {
     private _vectors3: { [key: string]: Vector3 } = {};
     private _matrices: { [key: string]: Matrix } = {};
 
-    private _fallbackTexture: Nullable<Texture>;
-
     private _fallbackTextureUsed = false;
     private _engine: Engine;
 

+ 4 - 1
src/Particles/particleSystem.ts

@@ -1982,7 +1982,10 @@ export class ParticleSystem extends BaseParticleSystem implements IDisposable, I
             newEmitter = this.emitter;
         }
 
-        result.noiseTexture = this.noiseTexture;
+        if (this.noiseTexture) {
+            result.noiseTexture = this.noiseTexture.clone();
+        }
+
         result.emitter = newEmitter;
         if (this.particleTexture) {
             if (this.particleTexture instanceof DynamicTexture) {