Browse Source

fix screenshot

Trevor Baron 6 years ago
parent
commit
9c9989d48c
3 changed files with 15 additions and 18 deletions
  1. 1 0
      dist/preview release/what's new.md
  2. 5 8
      src/Misc/screenshotTools.ts
  3. 9 10
      src/Misc/tools.ts

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

@@ -175,6 +175,7 @@
 - Utility layer should render on last active camera ([TrevorDev](https://github.com/TrevorDev))
 - PointerDragBehavior should not let the drag plane get out of sync when rotating the object during dragging ([TrevorDev](https://github.com/TrevorDev))
 - Do not crash the application if webVR submitFrame fails ([TrevorDev](https://github.com/TrevorDev))
+- Tools.CreateScreenshot stopped working ([TrevorDev](https://github.com/TrevorDev))
 
 ### Core Engine
 - Fixed a bug with `mesh.alwaysSelectAsActiveMesh` preventing layerMask to be taken in account ([Deltakosh](https://github.com/deltakosh))

+ 5 - 8
src/Misc/screenshotTools.ts

@@ -10,9 +10,6 @@ import { Tools } from './tools';
 
 declare type Engine = import("../Engines/engine").Engine;
 
-// Screenshots
-var screenshotCanvas: HTMLCanvasElement;
-
 /**
  * Class containing a set of static utilities functions for screenshots
  */
@@ -66,14 +63,14 @@ export class ScreenshotTools {
             return;
         }
 
-        if (!screenshotCanvas) {
-            screenshotCanvas = document.createElement('canvas');
+        if (!Tools._ScreenshotCanvas) {
+            Tools._ScreenshotCanvas = document.createElement('canvas');
         }
 
-        screenshotCanvas.width = width;
-        screenshotCanvas.height = height;
+        Tools._ScreenshotCanvas.width = width;
+        Tools._ScreenshotCanvas.height = height;
 
-        var renderContext = screenshotCanvas.getContext("2d");
+        var renderContext = Tools._ScreenshotCanvas.getContext("2d");
 
         var ratio = engine.getRenderWidth() / engine.getRenderHeight();
         var newWidth = width;

+ 9 - 10
src/Misc/tools.ts

@@ -190,9 +190,6 @@ export interface IFileRequest {
     abort: () => void;
 }
 
-// Screenshots
-var screenshotCanvas: HTMLCanvasElement;
-
 /**
  * Class containing a set of static utilities functions
  */
@@ -1187,6 +1184,8 @@ export class Tools {
         }
     }
 
+    public static _ScreenshotCanvas: HTMLCanvasElement;
+
     /**
      * Dumps the current bound framebuffer
      * @param width defines the rendering width
@@ -1218,12 +1217,12 @@ export class Tools {
         }
 
         // Create a 2D canvas to store the result
-        if (!screenshotCanvas) {
-            screenshotCanvas = document.createElement('canvas');
+        if (!Tools._ScreenshotCanvas) {
+            Tools._ScreenshotCanvas = document.createElement('canvas');
         }
-        screenshotCanvas.width = width;
-        screenshotCanvas.height = height;
-        var context = screenshotCanvas.getContext('2d');
+        Tools._ScreenshotCanvas.width = width;
+        Tools._ScreenshotCanvas.height = height;
+        var context = Tools._ScreenshotCanvas.getContext('2d');
 
         if (context) {
             // Copy the pixels to a 2D canvas
@@ -1273,11 +1272,11 @@ export class Tools {
      */
     static EncodeScreenshotCanvasData(successCallback?: (data: string) => void, mimeType: string = "image/png", fileName?: string): void {
         if (successCallback) {
-            var base64Image = screenshotCanvas.toDataURL(mimeType);
+            var base64Image = Tools._ScreenshotCanvas.toDataURL(mimeType);
             successCallback(base64Image);
         }
         else {
-            this.ToBlob(screenshotCanvas, function(blob) {
+            this.ToBlob(Tools._ScreenshotCanvas, function(blob) {
                 //Creating a link if the browser have the download attribute on the a tag, to automatically start download generated image.
                 if (("download" in document.createElement("a"))) {
                     if (!fileName) {