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

Adding ID to lens flare systems

Including the function to search by ID.
id defaults to the name provided (like in the node), but can be changed.
Raanan Weber преди 9 години
родител
ревизия
4ac831e618
променени са 2 файла, в които са добавени 17 реда и са изтрити 1 реда
  1. 7 1
      src/LensFlare/babylon.lensFlareSystem.ts
  2. 10 0
      src/babylon.scene.ts

+ 7 - 1
src/LensFlare/babylon.lensFlareSystem.ts

@@ -4,6 +4,7 @@
         public borderLimit = 300;
         public meshesSelectionPredicate: (mesh: Mesh) => boolean;
         public layerMask: number = 0x0FFFFFFF;
+        public id: string;
 
         private _scene: Scene;
         private _emitter: any;
@@ -20,6 +21,7 @@
 
             this._scene = scene;
             this._emitter = emitter;
+            this.id = name;
             scene.lensFlareSystems.push(this);
 
             this.meshesSelectionPredicate = m => m.material && m.isVisible && m.isEnabled() && m.isBlocker && ((m.layerMask & scene.activeCamera.layerMask) != 0);
@@ -240,6 +242,9 @@
             var name = parsedLensFlareSystem.name || "lensFlareSystem#" + parsedLensFlareSystem.emitterId;
 
             var lensFlareSystem = new LensFlareSystem(name, emitter, scene);
+            if (parsedLensFlareSystem.id) {
+                lensFlareSystem.id = parsedLensFlareSystem.id;
+            }
             lensFlareSystem.borderLimit = parsedLensFlareSystem.borderLimit;
 
             for (var index = 0; index < parsedLensFlareSystem.flares.length; index++) {
@@ -252,7 +257,8 @@
 
         public serialize(): any {
             var serializationObject: any = {};
-
+            
+            serializationObject.id = this.id;
             serializationObject.name = this.name;
 
             serializationObject.emitterId = this.getEmitter().id;

+ 10 - 0
src/babylon.scene.ts

@@ -1288,6 +1288,16 @@
 
             return null;
         }
+        
+        public getLensFlareSystemByID(id: string): LensFlareSystem {
+            for (var index = 0; index < this.lensFlareSystems.length; index++) {
+                if (this.lensFlareSystems[index].id === id) {
+                    return this.lensFlareSystems[index];
+                }
+            }
+
+            return null;
+        }
 
         public getCameraByID(id: string): Camera {
             for (var index = 0; index < this.cameras.length; index++) {