Bläddra i källkod

Merge pull request #7040 from Popov72/ShaderMaterial-cloning

Cloning of ShaderMaterial should also clone _shaderPath and _options properties
David Catuhe 5 år sedan
förälder
incheckning
7c15a64737
2 ändrade filer med 16 tillägg och 0 borttagningar
  1. 1 0
      dist/preview release/what's new.md
  2. 15 0
      src/Materials/shaderMaterial.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -202,6 +202,7 @@
 - Fixed a single frame drop after leaving webxr on some devices ([RaananW](https://github.com/RaananW/))
 - Fixed bug where vignette aspect ratio would be wrong when rendering direct to canvas
 - Fixed Path2 length computation ([Poolminer](https://github.com/Poolminer/))
+- Cloning of `ShaderMaterial` also clone `shaderPath` and `options` properties ([Popov72](https://github.com/Popov72))
 
 ## Breaking changes
 

+ 15 - 0
src/Materials/shaderMaterial.ts

@@ -791,6 +791,21 @@ export class ShaderMaterial extends Material {
         result.name = name;
         result.id = name;
 
+        // Shader code path
+        if (typeof result._shaderPath === 'object') {
+            result._shaderPath = { ...result._shaderPath };
+        }
+
+        // Options
+        this._options = { ...this._options };
+
+        (Object.keys(this._options) as Array<keyof IShaderMaterialOptions>).forEach((propName) => {
+            const propValue = this._options[propName];
+            if (Array.isArray(propValue)) {
+                (<string[]>this._options[propName]) = propValue.slice(0);
+            }
+        });
+
         // Texture
         for (var key in this._textures) {
             result.setTexture(key, this._textures[key]);