Explorar o código

Merge pull request #9294 from Drigax/fix-material-duplicate-id

Add increment to materials with duplicate id
Raanan Weber %!s(int64=4) %!d(string=hai) anos
pai
achega
6f9971c756
Modificáronse 2 ficheiros con 8 adicións e 2 borrados
  1. 2 1
      dist/preview release/what's new.md
  2. 6 1
      src/Materials/material.ts

+ 2 - 1
dist/preview release/what's new.md

@@ -377,4 +377,5 @@
 - Fix width/height GUI container computation to take into account paddings when `adaptWithToChildren = true` ([Popov72](https://github.com/Popov72))
 - `smoothstep` in NME is now taking any type of parameters for its `value` input. If you use generated code from the NME ("Generate code" button), you may have to move the smoothstep output connection AFTER the input connections ([Popov72](https://github.com/Popov72))
 - `SoundTrack.RemoveSound` and `SoundTrack.AddSound` were renamed to `SoundTrack.removeSound` and `SoundTrack.addSound` ([Deltakosh](https://github.com/deltakosh))
-- `PolygonPoints.add` no longer filters out points that are close to the first point ([bghgary](https://github.com/bghgary))
+- `PolygonPoints.add` no longer filters out points that are close to the first point ([bghgary](https://github.com/bghgary))
+- `Material` created with matching names now have auto-incrementing IDs.

+ 6 - 1
src/Materials/material.ts

@@ -660,9 +660,14 @@ export class Material implements IAnimatable {
      */
     constructor(name: string, scene: Scene, doNotAdd?: boolean) {
         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++;
+        }
 
-        this._scene = scene || EngineStore.LastCreatedScene;
         this.uniqueId = this._scene.getUniqueId();
 
         if (this._scene.useRightHandedSystem) {