소스 검색

Merge pull request #198 from nicolas-obre/ScreenshotActiveCameraFix

Fixing camera using on CreateScreenshot.
deltakosh 11 년 전
부모
커밋
0f0e9c3c6b
3개의 변경된 파일26개의 추가작업 그리고 6개의 파일을 삭제
  1. 15 2
      Babylon/Tools/babylon.tools.js
  2. 10 3
      Babylon/Tools/babylon.tools.ts
  3. 1 1
      Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/ourOwnBabylon.js

+ 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

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 1 - 1
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/ourOwnBabylon.js