소스 검색

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 name defines the name of the material
      * @param scene defines the scene to reference
      * @param scene defines the scene to reference
      * @param doNotAdd specifies if the material should be added to the scene
      * @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;
         this.name = name;
         let idSubscript = 1;
         let idSubscript = 1;
         this._scene = scene || EngineStore.LastCreatedScene;
         this._scene = scene || EngineStore.LastCreatedScene;
 
 
         this.id = name || Tools.RandomId();
         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();
         this.uniqueId = this._scene.getUniqueId();