Explorar o código

Merge pull request #9492 from sebavan/master

Rework #9290 due to perf hit
sebavan %!s(int64=4) %!d(string=hai) anos
pai
achega
bd34bef5e8

+ 11 - 3
inspector/src/components/sceneExplorer/sceneExplorerComponent.tsx

@@ -333,26 +333,34 @@ export class SceneExplorerComponent extends React.Component<ISceneExplorerCompon
             }
         });
 
+        const getUniqueName = (name: string) : string => {
+            let idSubscript = 1;
+            while (scene.getMaterialByID(name)) {
+                name = name + " " + idSubscript++;
+            }
+            return name;
+        };
+
         // Materials
         let materialsContextMenus: { label: string, action: () => void }[] = [];
         materialsContextMenus.push({
             label: "Add new standard material",
             action: () => {
-                let newStdMaterial = new StandardMaterial("Standard material", scene);
+                let newStdMaterial = new StandardMaterial(getUniqueName("Standard material"), scene);
                 this.props.globalState.onSelectionChangedObservable.notifyObservers(newStdMaterial);
             }
         });
         materialsContextMenus.push({
             label: "Add new PBR material",
             action: () => {
-                let newPBRMaterial = new PBRMaterial("PBR material", scene);
+                let newPBRMaterial = new PBRMaterial(getUniqueName("PBR material"), scene);
                 this.props.globalState.onSelectionChangedObservable.notifyObservers(newPBRMaterial);
             }
         });
         materialsContextMenus.push({
             label: "Add new node material",
             action: () => {
-                let newNodeMaterial = new NodeMaterial("node material", scene);
+                let newNodeMaterial = new NodeMaterial(getUniqueName("node material"), scene);
                 newNodeMaterial.setToDefault();
                 newNodeMaterial.build();
                 this.props.globalState.onSelectionChangedObservable.notifyObservers(newNodeMaterial);

+ 1 - 9
src/Materials/material.ts

@@ -659,20 +659,12 @@ 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, enforceUniqueId = true) {
+    constructor(name: string, scene: Scene, doNotAdd?: boolean) {
         this.name = name;
-        let idSubscript = 1;
         this._scene = scene || EngineStore.LastCreatedScene;
 
         this.id = name || Tools.RandomId();
-        if (enforceUniqueId) {
-            while (this._scene.getMaterialByID(this.id)) {
-                this.id = name + " " + idSubscript++;
-            }
-        }
-
         this.uniqueId = this._scene.getUniqueId();
 
         if (this._scene.useRightHandedSystem) {