Browse Source

Adding BABYLON.MergeMeshesOptimization.UpdateSelectionTree
Fixes #650

David catuhe 10 years ago
parent
commit
8e4d83b219

File diff suppressed because it is too large
+ 638 - 635
dist/preview release - alpha/babylon.2.2.d.ts


File diff suppressed because it is too large
+ 30 - 26
dist/preview release - alpha/babylon.2.2.js


+ 24 - 4
dist/preview release - alpha/babylon.2.2.max.js

@@ -5810,13 +5810,15 @@ var BABYLON;
         };
         Engine.prototype.unBindFramebuffer = function (texture) {
             this._currentRenderTarget = null;
+            this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
             if (texture.generateMipMaps) {
                 var gl = this._gl;
                 gl.bindTexture(gl.TEXTURE_2D, texture);
                 gl.generateMipmap(gl.TEXTURE_2D);
                 gl.bindTexture(gl.TEXTURE_2D, null);
             }
-            this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
+            this.setViewport(this._cachedViewport);
+            this.wipeCaches();
         };
         Engine.prototype.flushFramebuffer = function () {
             this._gl.flush();
@@ -12501,6 +12503,13 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(Scene.prototype, "SelectionOctree", {
+            get: function () {
+                return this._selectionOctree;
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(Scene.prototype, "meshUnderPointer", {
             /**
              * The mesh that is currently under the pointer.
@@ -13406,9 +13415,6 @@ var BABYLON;
                 BABYLON.Tools.EndPerformanceCounter("Render targets", this._renderTargets.length > 0);
                 this._renderId++;
             }
-            if (this._renderTargets.length > 0) {
-                engine.restoreDefaultFramebuffer();
-            }
             this._renderTargetsDuration += BABYLON.Tools.Now - beforeRenderTargetDate;
             // Prepare Frame
             this.postProcessManager._prepareFrame();
@@ -29671,9 +29677,23 @@ var BABYLON;
                     // Merge meshes
                     BABYLON.Mesh.MergeMeshes(currentPool);
                 }
+                if (MergeMeshesOptimization.UpdateSelectionTree) {
+                    scene.createOrUpdateSelectionOctree();
+                }
                 return true;
             };
         }
+        Object.defineProperty(MergeMeshesOptimization, "UpdateSelectionTree", {
+            get: function () {
+                return MergeMeshesOptimization._UpdateSelectionTree;
+            },
+            set: function (value) {
+                MergeMeshesOptimization._UpdateSelectionTree = value;
+            },
+            enumerable: true,
+            configurable: true
+        });
+        MergeMeshesOptimization._UpdateSelectionTree = false;
         return MergeMeshesOptimization;
     })(SceneOptimization);
     BABYLON.MergeMeshesOptimization = MergeMeshesOptimization;

File diff suppressed because it is too large
+ 27 - 23
dist/preview release - alpha/babylon.2.2.noworker.js


+ 1 - 1
src/PostProcess/babylon.volumetricLightScatteringPostProcess.ts

@@ -301,7 +301,7 @@
             this._volumetricLightScatteringRTT.onAfterRender = (): void => {
                 scene.clearColor = savedSceneClearColor;
             };
-
+            
             this._volumetricLightScatteringRTT.customRenderFunction = (opaqueSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>): void => {
                 var engine = scene.getEngine();
                 var index: number;

+ 14 - 0
src/Tools/babylon.sceneOptimizer.js

@@ -181,9 +181,23 @@ var BABYLON;
                     // Merge meshes
                     BABYLON.Mesh.MergeMeshes(currentPool);
                 }
+                if (MergeMeshesOptimization.UpdateSelectionTree) {
+                    scene.createOrUpdateSelectionOctree();
+                }
                 return true;
             };
         }
+        Object.defineProperty(MergeMeshesOptimization, "UpdateSelectionTree", {
+            get: function () {
+                return MergeMeshesOptimization._UpdateSelectionTree;
+            },
+            set: function (value) {
+                MergeMeshesOptimization._UpdateSelectionTree = value;
+            },
+            enumerable: true,
+            configurable: true
+        });
+        MergeMeshesOptimization._UpdateSelectionTree = false;
         return MergeMeshesOptimization;
     })(SceneOptimization);
     BABYLON.MergeMeshesOptimization = MergeMeshesOptimization;

+ 13 - 0
src/Tools/babylon.sceneOptimizer.ts

@@ -89,6 +89,15 @@
     }
 
     export class MergeMeshesOptimization extends SceneOptimization {
+        static _UpdateSelectionTree = false;
+
+        public static get UpdateSelectionTree(): boolean {
+            return MergeMeshesOptimization._UpdateSelectionTree;
+        }
+
+        public static set UpdateSelectionTree(value: boolean) {
+            MergeMeshesOptimization._UpdateSelectionTree = value;
+        }
 
         private _canBeMerged = (abstractMesh: AbstractMesh): boolean => {
             if (!(abstractMesh instanceof Mesh)) {
@@ -160,6 +169,10 @@
                 Mesh.MergeMeshes(currentPool);
             }
 
+            if (MergeMeshesOptimization.UpdateSelectionTree) {
+                scene.createOrUpdateSelectionOctree();
+            }
+
             return true;
         };
     }

+ 3 - 1
src/babylon.engine.js

@@ -842,13 +842,15 @@ var BABYLON;
         };
         Engine.prototype.unBindFramebuffer = function (texture) {
             this._currentRenderTarget = null;
+            this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
             if (texture.generateMipMaps) {
                 var gl = this._gl;
                 gl.bindTexture(gl.TEXTURE_2D, texture);
                 gl.generateMipmap(gl.TEXTURE_2D);
                 gl.bindTexture(gl.TEXTURE_2D, null);
             }
-            this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
+            this.setViewport(this._cachedViewport);
+            this.wipeCaches();
         };
         Engine.prototype.flushFramebuffer = function () {
             this._gl.flush();

+ 6 - 1
src/babylon.engine.ts

@@ -963,14 +963,19 @@
 
         public unBindFramebuffer(texture: WebGLTexture): void {
             this._currentRenderTarget = null;
+
+            this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
+
             if (texture.generateMipMaps) {
                 var gl = this._gl;
                 gl.bindTexture(gl.TEXTURE_2D, texture);
                 gl.generateMipmap(gl.TEXTURE_2D);
                 gl.bindTexture(gl.TEXTURE_2D, null);
             }
+            
+            this.setViewport(this._cachedViewport);
 
-            this._gl.bindFramebuffer(this._gl.FRAMEBUFFER, null);
+            this.wipeCaches();
         }
 
         public flushFramebuffer(): void {

+ 7 - 3
src/babylon.scene.js

@@ -196,6 +196,13 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(Scene.prototype, "SelectionOctree", {
+            get: function () {
+                return this._selectionOctree;
+            },
+            enumerable: true,
+            configurable: true
+        });
         Object.defineProperty(Scene.prototype, "meshUnderPointer", {
             /**
              * The mesh that is currently under the pointer.
@@ -1101,9 +1108,6 @@ var BABYLON;
                 BABYLON.Tools.EndPerformanceCounter("Render targets", this._renderTargets.length > 0);
                 this._renderId++;
             }
-            if (this._renderTargets.length > 0) {
-                engine.restoreDefaultFramebuffer();
-            }
             this._renderTargetsDuration += BABYLON.Tools.Now - beforeRenderTargetDate;
             // Prepare Frame
             this.postProcessManager._prepareFrame();

+ 4 - 4
src/babylon.scene.ts

@@ -319,6 +319,10 @@
             return this._workerCollisions;
         }
 
+        public get SelectionOctree(): Octree<AbstractMesh> {
+            return this._selectionOctree;
+        }
+
         /**
          * The mesh that is currently under the pointer.
          * @return {BABYLON.AbstractMesh} mesh under the pointer/mouse cursor or null if none.
@@ -1415,13 +1419,9 @@
                 }
                 Tools.EndPerformanceCounter("Render targets", this._renderTargets.length > 0);
 
-
                 this._renderId++;
             }
 
-            if (this._renderTargets.length > 0) { // Restore back buffer
-                engine.restoreDefaultFramebuffer();
-            }
             this._renderTargetsDuration += Tools.Now - beforeRenderTargetDate;
 
             // Prepare Frame