浏览代码

Merge pull request #9488 from Popov72/material-bypass-unique-name

Add enforceUniqueId parameter to material constructor
sebavan 4 年之前
父节点
当前提交
24151410af
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      src/Materials/material.ts

+ 6 - 3
src/Materials/material.ts

@@ -659,15 +659,18 @@ export class Material implements IAnimatable {
      * @param name defines the name of the material
      * @param scene defines the scene to reference
      * @param doNotAdd specifies if the material should be added to the scene
+     * @param enforceUniqueId true (default) to enforce unique ids for materials in the scene
      */
-    constructor(name: string, scene: Scene, doNotAdd?: boolean) {
+    constructor(name: string, scene: Scene, doNotAdd?: boolean, enforceUniqueId = true) {
         this.name = name;
         let idSubscript = 1;
         this._scene = scene || EngineStore.LastCreatedScene;
 
         this.id = name || Tools.RandomId();
-        while (this._scene.getMaterialByID(this.id)) {
-            this.id = name + " " + idSubscript++;
+        if (enforceUniqueId) {
+            while (this._scene.getMaterialByID(this.id)) {
+                this.id = name + " " + idSubscript++;
+            }
         }
 
         this.uniqueId = this._scene.getUniqueId();