Przeglądaj źródła

Merge pull request #198 from nicolas-obre/ScreenshotActiveCameraFix

Fixing camera using on CreateScreenshot.
deltakosh 11 lat temu
rodzic
commit
0f0e9c3c6b

+ 15 - 2
Babylon/Tools/babylon.tools.js

@@ -349,6 +349,12 @@
         Tools.CreateScreenshot = function (engine, camera, size) {
             var width;
             var height;
+            var scene = engine.scenes[0];
+            var previousCamera = null;
+            if (scene.activeCamera !== camera) {
+                previousCamera = scene.activeCamera;
+                scene.activeCamera = camera;
+            }
 
             //If a precision value is specified
             if (size.precision) {
@@ -436,8 +442,15 @@
                 }
             };
 
-            texture.render();
-            texture.dispose();
+            scene.afterRender = function () {
+                texture.render();
+                texture.dispose();
+                if (previousCamera) {
+                    scene.activeCamera = previousCamera;
+                }
+                scene.afterRender = function () {
+                };
+            };
         };
 
         Object.defineProperty(Tools, "NoneLogLevel", {

+ 10 - 3
Babylon/Tools/babylon.tools.ts

@@ -370,7 +370,12 @@
         public static CreateScreenshot(engine: Engine, camera: Camera, size: any): void {
             var width: number;
             var height: number;
-
+            var scene = engine.scenes[0];
+            var previousCamera: BABYLON.Camera = null;
+            if (scene.activeCamera !== camera) {
+                previousCamera = scene.activeCamera;
+                scene.activeCamera = camera;
+            }
             //If a precision value is specified
             if (size.precision) {
                 width = Math.round(engine.getRenderWidth() * size.precision);
@@ -402,7 +407,6 @@
                 Tools.Error("Invalid 'size' parameter !");
                 return;
             }
-
             //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]);
             texture.renderList = engine.scenes[0].meshes;
@@ -468,9 +472,12 @@
                 }
 
             };
-
+            
             texture.render();
             texture.dispose();
+            if (previousCamera) {
+                scene.activeCamera = previousCamera;
+            }
         }
 
         // Logs

Plik diff jest za duży
+ 1 - 1
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/ourOwnBabylon.js