Pārlūkot izejas kodu

Prevents back compat issue with renderPriority and stable sort

sevan 8 gadi atpakaļ
vecāks
revīzija
8779bf7499
2 mainītis faili ar 14 papildinājumiem un 5 dzēšanām
  1. 6 1
      src/Lights/babylon.light.ts
  2. 8 4
      src/babylon.scene.ts

+ 6 - 1
src/Lights/babylon.light.ts

@@ -169,6 +169,7 @@
          * exceeding the number allowed of the materials.
          */
         @serialize()
+        private _renderPriority: number;
         @expandToProperty("_reorderLightsInScene")
         public renderPriority: number = 0;
 
@@ -651,7 +652,11 @@
         }
 
         private _reorderLightsInScene(): void {
-            this.getScene().orderLightsByPriority();
+            var scene = this.getScene();
+            if (this.renderPriority != 0) {
+                scene.requireLightSorting = true;
+            }
+            this.getScene().sortLightsByPriority();
         }
     }
 }

+ 8 - 4
src/babylon.scene.ts

@@ -737,6 +737,8 @@
             return this._frustumPlanes;
         }
 
+        public requireLightSorting = false;
+
         private _selectionOctree: Octree<AbstractMesh>;
 
         private _pointerOverMesh: AbstractMesh;
@@ -1826,7 +1828,7 @@
             if (index !== -1) {
                 // Remove from the scene if mesh found 
                 this.lights.splice(index, 1);
-                this.orderLightsByPriority();
+                this.sortLightsByPriority();
             }
             this.onLightRemovedObservable.notifyObservers(toRemove);
             return index;
@@ -1859,13 +1861,15 @@
         public addLight(newLight: Light) {
             newLight.uniqueId = this.getUniqueId();
             this.lights.push(newLight);
-            this.orderLightsByPriority();
+            this.sortLightsByPriority();
 
             this.onNewLightAddedObservable.notifyObservers(newLight);
         }
 
-        public orderLightsByPriority(): void {
-            this.lights = this.lights.sort(Light.compareLightsPriority);
+        public sortLightsByPriority(): void {
+            if(this.requireLightSorting) {
+                this.lights.sort(Light.compareLightsPriority);
+            }
         }
 
         public addCamera(newCamera: Camera) {