Преглед на файлове

Merge pull request #9202 from gabrielheming/master

Fixed screenshot when scene has multi-cameras. Issue #9201
David Catuhe преди 4 години
родител
ревизия
38bda5f733
променени са 2 файла, в които са добавени 10 реда и са изтрити 9 реда
  1. 1 0
      dist/preview release/what's new.md
  2. 9 9
      src/Misc/screenshotTools.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -356,6 +356,7 @@
 - Fix incorrect shadows on the master mesh when using a lod mesh ([Popov72](https://github.com/Popov72))
 - Take first gamepad connected when attaching camera (and not only XBOX gamepads) ([#9136](https://github.com/BabylonJS/Babylon.js/issues/9136)) ([RaananW](https://github.com/RaananW))
 - Fixed bug in `Mesh.IncreaseVertices` assuming null value if a property didn't exist. ([aWeirdo](https://github.com/aWeirdo))
+- Fix issue when taking a screenshot with multi-cameras using method `CreateScreenshotUsingRenderTarget` ([#9201](https://github.com/BabylonJS/Babylon.js/issues/9201)) ([gabrielheming](https://github.com/gabrielheming))
 
 ## Breaking changes
 

+ 9 - 9
src/Misc/screenshotTools.ts

@@ -123,15 +123,6 @@ export class ScreenshotTools {
             Logger.Error("Invalid 'size' parameter !");
             return;
         }
-
-        var scene = camera.getScene();
-        var previousCamera: Nullable<Camera> = null;
-
-        if (scene.activeCamera !== camera) {
-            previousCamera = scene.activeCamera;
-            scene.activeCamera = camera;
-        }
-
         var renderCanvas = engine.getRenderingCanvas();
         if (!renderCanvas) {
             Logger.Error("No rendering canvas found !");
@@ -140,8 +131,16 @@ export class ScreenshotTools {
 
         var originalSize = { width: renderCanvas.width, height: renderCanvas.height };
         engine.setSize(width, height);
+
+        var scene = camera.getScene();
         scene.render();
 
+        var previousCamera: Nullable<Camera> = null;
+        if (scene.activeCamera !== camera) {
+            previousCamera = scene.activeCamera;
+            scene.activeCamera = camera;
+        }
+
         // At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)
         var texture = new RenderTargetTexture("screenShot", targetTextureSize, scene, false, false, Constants.TEXTURETYPE_UNSIGNED_INT, false, Texture.NEAREST_SAMPLINGMODE, undefined, enableStencilBuffer);
         texture.renderList = null;
@@ -160,6 +159,7 @@ export class ScreenshotTools {
             if (previousCamera) {
                 scene.activeCamera = previousCamera;
             }
+
             engine.setSize(originalSize.width, originalSize.height);
             camera.getProjectionMatrix(true); // Force cache refresh;
         };