浏览代码

add id incrementing when duplicate material ids are found in scene

Nicholas Barlow 4 年之前
父节点
当前提交
aab07e013a
共有 1 个文件被更改,包括 4 次插入0 次删除
  1. 4 0
      src/Materials/material.ts

+ 4 - 0
src/Materials/material.ts

@@ -661,6 +661,10 @@ export class Material implements IAnimatable {
     constructor(name: string, scene: Scene, doNotAdd?: boolean) {
         this.name = name;
         this.id = name || Tools.RandomId();
+        let idSubscript = 0;
+        while (scene.getMaterialByID(this.id) != null) {
+            this.id = name + "_" + idSubscript;
+        }
 
         this._scene = scene || EngineStore.LastCreatedScene;
         this.uniqueId = this._scene.getUniqueId();