ソースを参照

HD CreateScreenshotWithRenderTexture

Support Axeon 7 年 前
コミット
84faf45e5a
1 ファイル変更14 行追加18 行削除
  1. 14 18
      src/Tools/babylon.tools.ts

+ 14 - 18
src/Tools/babylon.tools.ts

@@ -781,25 +781,21 @@
             }
             else {
                 // We need HTMLCanvasElement.toBlob for HD screenshots
-                if (!HTMLCanvasElement.prototype.toBlob) {
+                if (!screenshotCanvas.toBlob) {
                     //  low performance polyfill based on toDataURL (https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob)
-                    Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
-                        value: function (callback : any, type : any, quality : any) {
-                            var canvas = this;
-                            setTimeout(function() {
-                                var binStr = atob( canvas.toDataURL(type, quality).split(',')[1] ),
-                                    len = binStr.length,
-                                    arr = new Uint8Array(len);
-
-                                for (var i = 0; i < len; i++ ) {
-                                    arr[i] = binStr.charCodeAt(i);
-                                }
-
-                                callback( new Blob( [arr], {type: type || 'image/png'} ) );
-
-                            });
-                        }
-                    });
+                    screenshotCanvas.toBlob = function (callback, type, quality) {
+                        var canvas = this;
+                        setTimeout(function() {
+                            var binStr = atob( canvas.toDataURL(type, quality).split(',')[1] ),
+                                len = binStr.length,
+                                arr = new Uint8Array(len);
+
+                            for (var i = 0; i < len; i++ ) {
+                                arr[i] = binStr.charCodeAt(i);
+                            }
+                            callback( new Blob( [arr], {type: type || 'image/png'} ) );
+                        });
+                    }
                 }
                 screenshotCanvas.toBlob(function(blob) {
                     var url = URL.createObjectURL(blob);