Procházet zdrojové kódy

now search for reflection probes + reflection probe as scene component

Julien MOREAU-MATHIS před 6 roky
rodič
revize
b48ac86679

+ 8 - 4
src/Materials/Textures/babylon.texture.ts

@@ -621,10 +621,14 @@ module BABYLON {
                 } else if (parsedTexture.isRenderTarget) {
                     let renderTargetTexture: Nullable<RenderTargetTexture> = null;
                     if (parsedTexture.isCube) {
-                        const probe = ReflectionProbe.Parse(parsedTexture, scene, rootUrl);
-
-                        if (probe) {
-                            renderTargetTexture = probe.cubeTexture;
+                        // Search for an existing reflection probe (which contains a cube render target texture)
+                        if (scene.reflectionProbes) {
+                            for (var index = 0; index < scene.reflectionProbes.length; index++) {
+                                const probe = scene.reflectionProbes[index];
+                                if (probe.name === parsedTexture.name) {
+                                    return probe.cubeTexture;
+                                }
+                            }
                         }
                     } else {
                         renderTargetTexture = new RenderTargetTexture(parsedTexture.name, parsedTexture.renderTargetSize, scene, generateMipMaps);

+ 34 - 0
src/Probes/babylon.reflectionProbe.ts

@@ -5,8 +5,42 @@ module BABYLON {
          * @see http://doc.babylonjs.com/how_to/how_to_use_reflection_probes
          */
         reflectionProbes: Array<ReflectionProbe>;
+
+        /**
+         * Removes the given reflection probe from this scene.
+         * @param toRemove The reflection probe to remove
+         * @returns The index of the removed reflection probe
+         */
+        removeReflectionProbe(toRemove: ReflectionProbe): number;
+
+        /**
+         * Adds the given reflection probe to this scene.
+         * @param newReflectionProbe The reflection probe to add
+         */
+        addReflectionProbe(newReflectionProbe: ReflectionProbe): void;
     }
 
+    AbstractScene.prototype.removeReflectionProbe = function(toRemove: ReflectionProbe): number {
+        if (!this.reflectionProbes) {
+            return -1;
+        }
+
+        var index = this.reflectionProbes.indexOf(toRemove);
+        if (index !== -1) {
+            this.reflectionProbes.splice(index, 1);
+        }
+
+        return index;
+    };
+
+    AbstractScene.prototype.addReflectionProbe = function(newReflectionProbe: ReflectionProbe): void {
+        if (!this.reflectionProbes) {
+            this.reflectionProbes = [];
+        }
+
+        this.reflectionProbes.push(newReflectionProbe);
+    };
+
     /**
      * Class used to generate realtime reflection / refraction cube textures
      * @see http://doc.babylonjs.com/how_to/how_to_use_reflection_probes

+ 0 - 30
src/babylon.scene.ts

@@ -3237,24 +3237,6 @@ module BABYLON {
         }
 
         /**
-         * Removes the given reflection probe from this scene.
-         * @param toRemove The reflection probe to remove
-         * @returns The index of the removed reflection probe
-         */
-        public removeReflectionProbe(toRemove: ReflectionProbe): number {
-            if (!this.reflectionProbes) {
-                return -1;
-            }
-
-            var index = this.reflectionProbes.indexOf(toRemove);
-            if (index !== -1) {
-                this.reflectionProbes.splice(index, 1);
-            }
-
-            return index;
-        }
-
-        /**
          * Adds the given light to this scene
          * @param newLight The light to add
          */
@@ -3379,18 +3361,6 @@ module BABYLON {
         }
 
         /**
-         * Adds the given reflection probe to this scene.
-         * @param newReflectionProbe The reflection probe to add
-         */
-        public addReflectionProbe(newReflectionProbe: ReflectionProbe): void {
-            if (!this.reflectionProbes) {
-                this.reflectionProbes = [];
-            }
-
-            this.reflectionProbes.push(newReflectionProbe);
-        }
-
-        /**
          * Switch active camera
          * @param newCamera defines the new active camera
          * @param attachControl defines if attachControl must be called for the new active camera (default: true)