Browse Source

Add Clone function to NME

sebavan 5 years ago
parent
commit
93433a5ceb
1 changed files with 17 additions and 0 deletions
  1. 17 0
      src/Materials/Node/nodeMaterial.ts

+ 17 - 0
src/Materials/Node/nodeMaterial.ts

@@ -1285,6 +1285,23 @@ export class NodeMaterial extends PushMaterial {
     }
     }
 
 
     /**
     /**
+     * Makes a duplicate of the current material.
+     * @param name - name to use for the new material.
+     */
+    public clone(name: string): NodeMaterial {
+        const serializationObject = this.serialize();
+
+        const clone = SerializationHelper.Clone(() => new NodeMaterial(name, this.getScene(), this.options), this);
+        clone.id = name;
+        clone.name = name;
+
+        clone.loadFromSerialization(serializationObject);
+        clone.build();
+
+        return clone;
+    }
+
+    /**
      * Creates a node material from parsed material data
      * Creates a node material from parsed material data
      * @param source defines the JSON representation of the material
      * @param source defines the JSON representation of the material
      * @param scene defines the hosting scene
      * @param scene defines the hosting scene