浏览代码

Fixing cannon.js driver
Fixing postProcess for RenderTargetTexture

David Catuhe 11 年之前
父节点
当前提交
1c4410d6a1

+ 4 - 0
Babylon/Cameras/babylon.camera.js

@@ -270,6 +270,10 @@ var BABYLON;
 
 
             var engine = this.getEngine();
             var engine = this.getEngine();
             if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
             if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
+                if (this.minZ <= 0) {
+                    this.minZ = BABYLON.Engine.Epsilon;
+                }
+
                 BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix);
                 BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix);
                 return this._projectionMatrix;
                 return this._projectionMatrix;
             }
             }

+ 4 - 0
Babylon/Cameras/babylon.camera.ts

@@ -286,6 +286,10 @@
 
 
             var engine = this.getEngine();
             var engine = this.getEngine();
             if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
             if (this.mode === BABYLON.Camera.PERSPECTIVE_CAMERA) {
+                if (this.minZ <= 0) {
+                    this.minZ = Engine.Epsilon;
+                }
+
                 BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix);
                 BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix);
                 return this._projectionMatrix;
                 return this._projectionMatrix;
             }
             }

+ 5 - 1
Babylon/Materials/textures/babylon.renderTargetTexture.js

@@ -54,7 +54,9 @@ var BABYLON;
             }
             }
 
 
             // Bind
             // Bind
-            engine.bindFramebuffer(this._texture);
+            if (!scene.postProcessManager._prepareFrame()) {
+                engine.bindFramebuffer(this._texture);
+            }
 
 
             // Clear
             // Clear
             engine.clear(scene.clearColor, true, true);
             engine.clear(scene.clearColor, true, true);
@@ -84,6 +86,8 @@ var BABYLON;
             // Render
             // Render
             this._renderingManager.render(this.customRenderFunction, this.renderList, this.renderParticles, this.renderSprites);
             this._renderingManager.render(this.customRenderFunction, this.renderList, this.renderParticles, this.renderSprites);
 
 
+            scene.postProcessManager._finalizeFrame(false, this._texture);
+
             if (this.onAfterRender) {
             if (this.onAfterRender) {
                 this.onAfterRender();
                 this.onAfterRender();
             }
             }

+ 6 - 1
Babylon/Materials/textures/babylon.renderTargetTexture.ts

@@ -57,7 +57,9 @@
             }
             }
 
 
             // Bind
             // Bind
-            engine.bindFramebuffer(this._texture);
+            if (!scene.postProcessManager._prepareFrame()) {
+                engine.bindFramebuffer(this._texture);
+            }
 
 
             // Clear
             // Clear
             engine.clear(scene.clearColor, true, true);
             engine.clear(scene.clearColor, true, true);
@@ -85,8 +87,11 @@
             }
             }
 
 
             // Render
             // Render
+
             this._renderingManager.render(this.customRenderFunction, this.renderList, this.renderParticles, this.renderSprites);
             this._renderingManager.render(this.customRenderFunction, this.renderList, this.renderParticles, this.renderSprites);
 
 
+            scene.postProcessManager._finalizeFrame(false, this._texture);
+
             if (this.onAfterRender) {
             if (this.onAfterRender) {
                 this.onAfterRender();
                 this.onAfterRender();
             }
             }

+ 1 - 1
Babylon/Physics/Plugins/babylon.cannonJSPlugin.js

@@ -63,7 +63,7 @@
                     var min = bbox.minimumWorld;
                     var min = bbox.minimumWorld;
                     var max = bbox.maximumWorld;
                     var max = bbox.maximumWorld;
                     var box = max.subtract(min).scale(0.5);
                     var box = max.subtract(min).scale(0.5);
-                    return this._createBox(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.z), this._checkWithEpsilon(box.y), mesh, options);
+                    return this._createBox(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.y), this._checkWithEpsilon(box.z), mesh, options);
                 case BABYLON.PhysicsEngine.PlaneImpostor:
                 case BABYLON.PhysicsEngine.PlaneImpostor:
                     return this._createPlane(mesh, options);
                     return this._createPlane(mesh, options);
                 case BABYLON.PhysicsEngine.MeshImpostor:
                 case BABYLON.PhysicsEngine.MeshImpostor:

+ 1 - 1
Babylon/Physics/Plugins/babylon.cannonJSPlugin.ts

@@ -66,7 +66,7 @@
                     var min = bbox.minimumWorld;
                     var min = bbox.minimumWorld;
                     var max = bbox.maximumWorld;
                     var max = bbox.maximumWorld;
                     var box = max.subtract(min).scale(0.5);
                     var box = max.subtract(min).scale(0.5);
-                    return this._createBox(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.z), this._checkWithEpsilon(box.y), mesh, options);
+                    return this._createBox(this._checkWithEpsilon(box.x), this._checkWithEpsilon(box.y), this._checkWithEpsilon(box.z), mesh, options);
                 case BABYLON.PhysicsEngine.PlaneImpostor:
                 case BABYLON.PhysicsEngine.PlaneImpostor:
                     return this._createPlane(mesh, options);
                     return this._createPlane(mesh, options);
                 case BABYLON.PhysicsEngine.MeshImpostor:
                 case BABYLON.PhysicsEngine.MeshImpostor:

+ 2 - 2
Babylon/PostProcess/babylon.postProcess.js

@@ -34,8 +34,8 @@
             camera = camera || this._camera;
             camera = camera || this._camera;
 
 
             var scene = camera.getScene();
             var scene = camera.getScene();
-            var desiredWidth = this._engine.getRenderingCanvas().width * this._renderRatio;
-            var desiredHeight = this._engine.getRenderingCanvas().height * this._renderRatio;
+            var desiredWidth = this._engine.getRenderWidth() * this._renderRatio;
+            var desiredHeight = this._engine.getRenderHeight() * this._renderRatio;
             if (this.width !== desiredWidth || this.height !== desiredHeight) {
             if (this.width !== desiredWidth || this.height !== desiredHeight) {
                 if (this._textures.length > 0) {
                 if (this._textures.length > 0) {
                     for (var i = 0; i < this._textures.length; i++) {
                     for (var i = 0; i < this._textures.length; i++) {

+ 2 - 2
Babylon/PostProcess/babylon.postProcess.ts

@@ -48,8 +48,8 @@
             camera = camera || this._camera;
             camera = camera || this._camera;
 
 
             var scene = camera.getScene();
             var scene = camera.getScene();
-            var desiredWidth = this._engine.getRenderingCanvas().width * this._renderRatio;
-            var desiredHeight = this._engine.getRenderingCanvas().height * this._renderRatio;
+            var desiredWidth = this._engine.getRenderWidth() * this._renderRatio;
+            var desiredHeight = this._engine.getRenderHeight() * this._renderRatio;
             if (this.width !== desiredWidth || this.height !== desiredHeight) {
             if (this.width !== desiredWidth || this.height !== desiredHeight) {
                 if (this._textures.length > 0) {
                 if (this._textures.length > 0) {
                     for (var i = 0; i < this._textures.length; i++) {
                     for (var i = 0; i < this._textures.length; i++) {

+ 9 - 3
Babylon/PostProcess/babylon.postProcessManager.js

@@ -32,13 +32,15 @@
             var postProcessesTakenIndices = this._scene.activeCamera._postProcessesTakenIndices;
             var postProcessesTakenIndices = this._scene.activeCamera._postProcessesTakenIndices;
 
 
             if (postProcessesTakenIndices.length === 0 || !this._scene.postProcessesEnabled) {
             if (postProcessesTakenIndices.length === 0 || !this._scene.postProcessesEnabled) {
-                return;
+                return false;
             }
             }
 
 
             postProcesses[this._scene.activeCamera._postProcessesTakenIndices[0]].activate(this._scene.activeCamera);
             postProcesses[this._scene.activeCamera._postProcessesTakenIndices[0]].activate(this._scene.activeCamera);
+
+            return true;
         };
         };
 
 
-        PostProcessManager.prototype._finalizeFrame = function (doNotPresent) {
+        PostProcessManager.prototype._finalizeFrame = function (doNotPresent, targetTexture) {
             var postProcesses = this._scene.activeCamera._postProcesses;
             var postProcesses = this._scene.activeCamera._postProcesses;
             var postProcessesTakenIndices = this._scene.activeCamera._postProcessesTakenIndices;
             var postProcessesTakenIndices = this._scene.activeCamera._postProcessesTakenIndices;
             if (postProcessesTakenIndices.length === 0 || !this._scene.postProcessesEnabled) {
             if (postProcessesTakenIndices.length === 0 || !this._scene.postProcessesEnabled) {
@@ -51,7 +53,11 @@
                 if (index < postProcessesTakenIndices.length - 1) {
                 if (index < postProcessesTakenIndices.length - 1) {
                     postProcesses[postProcessesTakenIndices[index + 1]].activate(this._scene.activeCamera);
                     postProcesses[postProcessesTakenIndices[index + 1]].activate(this._scene.activeCamera);
                 } else {
                 } else {
-                    engine.restoreDefaultFramebuffer();
+                    if (targetTexture) {
+                        engine.bindFramebuffer(targetTexture);
+                    } else {
+                        engine.restoreDefaultFramebuffer();
+                    }
                 }
                 }
 
 
                 if (doNotPresent) {
                 if (doNotPresent) {

+ 10 - 4
Babylon/PostProcess/babylon.postProcessManager.ts

@@ -31,18 +31,20 @@
         }
         }
 
 
         // Methods
         // Methods
-        public _prepareFrame(): void {
+        public _prepareFrame(): boolean {
             var postProcesses = this._scene.activeCamera._postProcesses;
             var postProcesses = this._scene.activeCamera._postProcesses;
             var postProcessesTakenIndices = this._scene.activeCamera._postProcessesTakenIndices;
             var postProcessesTakenIndices = this._scene.activeCamera._postProcessesTakenIndices;
 
 
             if (postProcessesTakenIndices.length === 0 || !this._scene.postProcessesEnabled) {
             if (postProcessesTakenIndices.length === 0 || !this._scene.postProcessesEnabled) {
-                return;
+                return false;
             }
             }
 
 
             postProcesses[this._scene.activeCamera._postProcessesTakenIndices[0]].activate(this._scene.activeCamera);
             postProcesses[this._scene.activeCamera._postProcessesTakenIndices[0]].activate(this._scene.activeCamera);
+
+            return true;
         }
         }
 
 
-        public _finalizeFrame(doNotPresent?: boolean): void {
+        public _finalizeFrame(doNotPresent?: boolean, targetTexture?: WebGLTexture): void {
             var postProcesses = this._scene.activeCamera._postProcesses;
             var postProcesses = this._scene.activeCamera._postProcesses;
             var postProcessesTakenIndices = this._scene.activeCamera._postProcessesTakenIndices;
             var postProcessesTakenIndices = this._scene.activeCamera._postProcessesTakenIndices;
             if (postProcessesTakenIndices.length === 0 || !this._scene.postProcessesEnabled) {
             if (postProcessesTakenIndices.length === 0 || !this._scene.postProcessesEnabled) {
@@ -55,7 +57,11 @@
                 if (index < postProcessesTakenIndices.length - 1) {
                 if (index < postProcessesTakenIndices.length - 1) {
                     postProcesses[postProcessesTakenIndices[index + 1]].activate(this._scene.activeCamera);
                     postProcesses[postProcessesTakenIndices[index + 1]].activate(this._scene.activeCamera);
                 } else {
                 } else {
-                    engine.restoreDefaultFramebuffer();
+                    if (targetTexture) {
+                        engine.bindFramebuffer(targetTexture);
+                    } else {
+                        engine.restoreDefaultFramebuffer();
+                    }
                 }
                 }
 
 
                 if (doNotPresent) {
                 if (doNotPresent) {

+ 9 - 10
Babylon/Tools/babylon.tools.js

@@ -349,8 +349,10 @@
         Tools.CreateScreenshot = function (engine, camera, size) {
         Tools.CreateScreenshot = function (engine, camera, size) {
             var width;
             var width;
             var height;
             var height;
-            var scene = engine.scenes[0];
+
+            var scene = camera.getScene();
             var previousCamera = null;
             var previousCamera = null;
+
             if (scene.activeCamera !== camera) {
             if (scene.activeCamera !== camera) {
                 previousCamera = scene.activeCamera;
                 previousCamera = scene.activeCamera;
                 scene.activeCamera = camera;
                 scene.activeCamera = camera;
@@ -442,15 +444,12 @@
                 }
                 }
             };
             };
 
 
-            scene.afterRender = function () {
-                texture.render();
-                texture.dispose();
-                if (previousCamera) {
-                    scene.activeCamera = previousCamera;
-                }
-                scene.afterRender = function () {
-                };
-            };
+            texture.render();
+            texture.dispose();
+
+            if (previousCamera) {
+                scene.activeCamera = previousCamera;
+            }
         };
         };
 
 
         Object.defineProperty(Tools, "NoneLogLevel", {
         Object.defineProperty(Tools, "NoneLogLevel", {

+ 9 - 4
Babylon/Tools/babylon.tools.ts

@@ -370,12 +370,15 @@
         public static CreateScreenshot(engine: Engine, camera: Camera, size: any): void {
         public static CreateScreenshot(engine: Engine, camera: Camera, size: any): void {
             var width: number;
             var width: number;
             var height: number;
             var height: number;
-            var scene = engine.scenes[0];
+
+            var scene = camera.getScene();
             var previousCamera: BABYLON.Camera = null;
             var previousCamera: BABYLON.Camera = null;
+
             if (scene.activeCamera !== camera) {
             if (scene.activeCamera !== camera) {
                 previousCamera = scene.activeCamera;
                 previousCamera = scene.activeCamera;
                 scene.activeCamera = camera;
                 scene.activeCamera = camera;
             }
             }
+
             //If a precision value is specified
             //If a precision value is specified
             if (size.precision) {
             if (size.precision) {
                 width = Math.round(engine.getRenderWidth() * size.precision);
                 width = Math.round(engine.getRenderWidth() * size.precision);
@@ -407,6 +410,7 @@
                 Tools.Error("Invalid 'size' parameter !");
                 Tools.Error("Invalid 'size' parameter !");
                 return;
                 return;
             }
             }
+
             //At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)
             //At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)
             var texture = new RenderTargetTexture("screenShot", size, engine.scenes[0]);
             var texture = new RenderTargetTexture("screenShot", size, engine.scenes[0]);
             texture.renderList = engine.scenes[0].meshes;
             texture.renderList = engine.scenes[0].meshes;
@@ -472,9 +476,10 @@
                 }
                 }
 
 
             };
             };
-            
+
             texture.render();
             texture.render();
             texture.dispose();
             texture.dispose();
+
             if (previousCamera) {
             if (previousCamera) {
                 scene.activeCamera = previousCamera;
                 scene.activeCamera = previousCamera;
             }
             }
@@ -510,7 +515,7 @@
             var padStr = i => (i < 10) ? "0" + i : "" + i;
             var padStr = i => (i < 10) ? "0" + i : "" + i;
 
 
             var date = new Date();
             var date = new Date();
-            return "BJS - [" + padStr(date.getHours()) + ":" + padStr(date.getMinutes()) +  ":" + padStr(date.getSeconds()) + "]: " + message;
+            return "BJS - [" + padStr(date.getHours()) + ":" + padStr(date.getMinutes()) + ":" + padStr(date.getSeconds()) + "]: " + message;
         }
         }
 
 
         public static Log: (message: string) => void = Tools._LogEnabled;
         public static Log: (message: string) => void = Tools._LogEnabled;
@@ -539,7 +544,7 @@
         private static _ErrorEnabled(message: string): void {
         private static _ErrorEnabled(message: string): void {
             console.error(Tools._FormatMessage(message));
             console.error(Tools._FormatMessage(message));
         }
         }
-        
+
         public static set LogLevels(level: number) {
         public static set LogLevels(level: number) {
             if ((level & Tools.MessageLogLevel) === Tools.MessageLogLevel) {
             if ((level & Tools.MessageLogLevel) === Tools.MessageLogLevel) {
                 Tools.Log = Tools._LogEnabled;
                 Tools.Log = Tools._LogEnabled;

文件差异内容过多而无法显示
+ 8 - 8
babylon.1.12-beta.js