Browse Source

Cloning of ShaderMaterial also clone _shaderPath and _options properties

Popov72 5 years ago
parent
commit
64d277779d
2 changed files with 16 additions and 0 deletions
  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

@@ -201,6 +201,7 @@
 - Fixed a single frame drop after leaving webxr on some devices ([RaananW](https://github.com/RaananW/))
 - 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 bug where vignette aspect ratio would be wrong when rendering direct to canvas
 - Fixed Path2 length computation ([Poolminer](https://github.com/Poolminer/))
 - 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
 ## Breaking changes
 
 

+ 15 - 0
src/Materials/shaderMaterial.ts

@@ -775,6 +775,21 @@ export class ShaderMaterial extends Material {
         result.name = name;
         result.name = name;
         result.id = 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
         // Texture
         for (var key in this._textures) {
         for (var key in this._textures) {
             result.setTexture(key, this._textures[key]);
             result.setTexture(key, this._textures[key]);