Преглед на файлове

remove light from mesh when it is removed from the scene

Trevor Baron преди 7 години
родител
ревизия
38eb5f61fc
променени са 2 файла, в които са добавени 13 реда и са изтрити 5 реда
  1. 0 5
      src/Lights/babylon.light.ts
  2. 13 0
      src/babylon.scene.ts

+ 0 - 5
src/Lights/babylon.light.ts

@@ -397,11 +397,6 @@
             // Animations
             this.getScene().stopAnimation(this);
 
-            // Remove from meshes
-            for (var mesh of this.getScene().meshes) {
-                mesh._removeLightSource(this);
-            }
-
             this._uniformBuffer.dispose();
 
             // Remove from scene

+ 13 - 0
src/babylon.scene.ts

@@ -2278,6 +2278,11 @@
         public removeLight(toRemove: Light): number {
             var index = this.lights.indexOf(toRemove);
             if (index !== -1) {
+                // Remove from meshes
+                for (var mesh of this.meshes) {
+                    mesh._removeLightSource(toRemove);
+                }
+
                 // Remove from the scene if mesh found
                 this.lights.splice(index, 1);
                 this.sortLightsByPriority();
@@ -2314,6 +2319,14 @@
             this.lights.push(newLight);
             this.sortLightsByPriority();
 
+            // Add light to all meshes (To support if the light is removed and then readded)
+            for (var mesh of this.meshes) {
+                if(mesh._lightSources.indexOf(newLight) === -1){
+                    mesh._lightSources.push(newLight);
+                    mesh._resyncLightSources();
+                }
+            }
+
             this.onNewLightAddedObservable.notifyObservers(newLight);
         }