@babylonjs/core 7.40.3 → 7.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Audio/sound.js +5 -10
- package/Audio/sound.js.map +1 -1
- package/Compute/computeEffect.js +6 -14
- package/Compute/computeEffect.js.map +1 -1
- package/Compute/computeShader.js +2 -9
- package/Compute/computeShader.js.map +1 -1
- package/Culling/Helper/computeShaderBoundingHelper.js +5 -6
- package/Culling/Helper/computeShaderBoundingHelper.js.map +1 -1
- package/Engines/abstractEngine.d.ts +7 -0
- package/Engines/abstractEngine.js +7 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/engine.js +6 -8
- package/Engines/engine.js.map +1 -1
- package/Engines/thinEngine.js +6 -1
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +6 -1
- package/Engines/webgpuEngine.js.map +1 -1
- package/FrameGraph/frameGraph.js +4 -9
- package/FrameGraph/frameGraph.js.map +1 -1
- package/Layers/effectLayer.js +2 -0
- package/Layers/effectLayer.js.map +1 -1
- package/Layers/glowLayer.js +4 -0
- package/Layers/glowLayer.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.d.ts +5 -0
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js +33 -0
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/reflectionBlock.js +2 -4
- package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +4 -0
- package/Materials/Node/nodeMaterial.js +15 -1
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.js +2 -4
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.d.ts +3 -2
- package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
- package/Materials/Textures/colorGradingTexture.js +5 -2
- package/Materials/Textures/colorGradingTexture.js.map +1 -1
- package/Materials/effect.functions.d.ts +0 -1
- package/Materials/effect.functions.js +0 -19
- package/Materials/effect.functions.js.map +1 -1
- package/Materials/effect.js +3 -2
- package/Materials/effect.js.map +1 -1
- package/Materials/effect.webgl.functions.js +2 -1
- package/Materials/effect.webgl.functions.js.map +1 -1
- package/Materials/material.d.ts +4 -0
- package/Materials/material.js +8 -0
- package/Materials/material.js.map +1 -1
- package/Meshes/abstractMesh.d.ts +5 -0
- package/Meshes/abstractMesh.js +15 -0
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/index.d.ts +1 -0
- package/Meshes/index.js +1 -0
- package/Meshes/index.js.map +1 -1
- package/Meshes/mesh.vertexData.functions.d.ts +6 -0
- package/Meshes/mesh.vertexData.functions.js +65 -0
- package/Meshes/mesh.vertexData.functions.js.map +1 -0
- package/Misc/bitArray.d.ts +26 -0
- package/Misc/bitArray.js +53 -0
- package/Misc/bitArray.js.map +1 -0
- package/Misc/index.d.ts +1 -0
- package/Misc/index.js +1 -0
- package/Misc/index.js.map +1 -1
- package/Misc/screenshotTools.d.ts +18 -12
- package/Misc/screenshotTools.js +64 -56
- package/Misc/screenshotTools.js.map +1 -1
- package/Misc/timingTools.d.ts +4 -0
- package/Misc/timingTools.js +38 -0
- package/Misc/timingTools.js.map +1 -1
- package/Misc/webRequest.d.ts +1 -1
- package/Misc/webRequest.js +1 -1
- package/Misc/webRequest.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +7 -5
- package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -1
- package/Rendering/iblCdfGenerator.d.ts +14 -19
- package/Rendering/iblCdfGenerator.js +64 -57
- package/Rendering/iblCdfGenerator.js.map +1 -1
- package/Rendering/index.d.ts +6 -6
- package/Rendering/index.js +6 -6
- package/Rendering/index.js.map +1 -1
- package/Shaders/ShadersInclude/hdrFilteringFunctions.js +6 -6
- package/Shaders/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/helperFunctions.js +7 -5
- package/Shaders/ShadersInclude/helperFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockReflection.js +2 -3
- package/Shaders/ShadersInclude/pbrBlockReflection.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockSubSurface.js +2 -3
- package/Shaders/ShadersInclude/pbrBlockSubSurface.js.map +1 -1
- package/Shaders/ShadersInclude/pbrFragmentSamplersDeclaration.js +1 -1
- package/Shaders/ShadersInclude/pbrFragmentSamplersDeclaration.js.map +1 -1
- package/Shaders/{iblIcdfx.fragment.d.ts → iblCdfDebug.fragment.d.ts} +1 -1
- package/Shaders/{importanceSamplingDebug.fragment.js → iblCdfDebug.fragment.js} +12 -11
- package/Shaders/iblCdfDebug.fragment.js.map +1 -0
- package/Shaders/iblCdfy.fragment.d.ts +1 -0
- package/Shaders/iblCdfy.fragment.js +4 -4
- package/Shaders/iblCdfy.fragment.js.map +1 -1
- package/Shaders/iblIcdf.fragment.d.ts +6 -0
- package/Shaders/iblIcdf.fragment.js +43 -0
- package/Shaders/iblIcdf.fragment.js.map +1 -0
- package/Shaders/iblScaledLuminance.fragment.d.ts +6 -0
- package/Shaders/iblScaledLuminance.fragment.js +25 -0
- package/Shaders/iblScaledLuminance.fragment.js.map +1 -0
- package/Shaders/iblShadowVoxelTracing.fragment.js +2 -2
- package/Shaders/iblShadowVoxelTracing.fragment.js.map +1 -1
- package/Shaders/pbr.fragment.js +2 -4
- package/Shaders/pbr.fragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/hdrFilteringFunctions.js +8 -6
- package/ShadersWGSL/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/helperFunctions.js +23 -20
- package/ShadersWGSL/ShadersInclude/helperFunctions.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockReflection.js +4 -8
- package/ShadersWGSL/ShadersInclude/pbrBlockReflection.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrBlockSubSurface.js +4 -8
- package/ShadersWGSL/ShadersInclude/pbrBlockSubSurface.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrFragmentSamplersDeclaration.js +1 -1
- package/ShadersWGSL/ShadersInclude/pbrFragmentSamplersDeclaration.js.map +1 -1
- package/ShadersWGSL/{iblIcdfy.fragment.d.ts → iblCdfDebug.fragment.d.ts} +1 -1
- package/ShadersWGSL/{importanceSamplingDebug.fragment.js → iblCdfDebug.fragment.js} +11 -10
- package/ShadersWGSL/iblCdfDebug.fragment.js.map +1 -0
- package/ShadersWGSL/iblCdfy.fragment.js +8 -7
- package/ShadersWGSL/iblCdfy.fragment.js.map +1 -1
- package/ShadersWGSL/iblIcdf.fragment.d.ts +6 -0
- package/ShadersWGSL/iblIcdf.fragment.js +43 -0
- package/ShadersWGSL/iblIcdf.fragment.js.map +1 -0
- package/ShadersWGSL/iblScaledLuminance.fragment.d.ts +6 -0
- package/ShadersWGSL/iblScaledLuminance.fragment.js +24 -0
- package/ShadersWGSL/iblScaledLuminance.fragment.js.map +1 -0
- package/ShadersWGSL/iblShadowVoxelTracing.fragment.js +3 -3
- package/ShadersWGSL/iblShadowVoxelTracing.fragment.js.map +1 -1
- package/ShadersWGSL/pbr.fragment.js +4 -8
- package/ShadersWGSL/pbr.fragment.js.map +1 -1
- package/package.json +1 -1
- package/Shaders/iblIcdfx.fragment.js +0 -19
- package/Shaders/iblIcdfx.fragment.js.map +0 -1
- package/Shaders/iblIcdfy.fragment.d.ts +0 -5
- package/Shaders/iblIcdfy.fragment.js +0 -19
- package/Shaders/iblIcdfy.fragment.js.map +0 -1
- package/Shaders/importanceSamplingDebug.fragment.d.ts +0 -5
- package/Shaders/importanceSamplingDebug.fragment.js.map +0 -1
- package/ShadersWGSL/iblIcdfx.fragment.d.ts +0 -5
- package/ShadersWGSL/iblIcdfx.fragment.js +0 -18
- package/ShadersWGSL/iblIcdfx.fragment.js.map +0 -1
- package/ShadersWGSL/iblIcdfy.fragment.js +0 -17
- package/ShadersWGSL/iblIcdfy.fragment.js.map +0 -1
- package/ShadersWGSL/importanceSamplingDebug.fragment.d.ts +0 -5
- package/ShadersWGSL/importanceSamplingDebug.fragment.js.map +0 -1
package/Misc/screenshotTools.js
CHANGED
|
@@ -6,12 +6,13 @@ import { Logger } from "./logger.js";
|
|
|
6
6
|
import { Tools } from "./tools.js";
|
|
7
7
|
import { DumpData } from "./dumpTools.js";
|
|
8
8
|
import { ApplyPostProcess } from "./textureTools.js";
|
|
9
|
+
import { _retryWithInterval } from "./timingTools.js";
|
|
9
10
|
let screenshotCanvas = null;
|
|
10
11
|
/**
|
|
11
12
|
* Captures a screenshot of the current rendering
|
|
12
13
|
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
|
|
13
14
|
* @param engine defines the rendering engine
|
|
14
|
-
* @param camera defines the source camera
|
|
15
|
+
* @param camera defines the source camera. If the camera is not the scene's active camera, {@link CreateScreenshotUsingRenderTarget} will be used instead, and `useFill` will be ignored
|
|
15
16
|
* @param size This parameter can be set to a single number or to an object with the
|
|
16
17
|
* following (optional) properties: precision, width, height. If a single number is passed,
|
|
17
18
|
* it will be used for both width and height. If an object is passed, the screenshot size
|
|
@@ -24,28 +25,14 @@ let screenshotCanvas = null;
|
|
|
24
25
|
* Check your browser for supported MIME types
|
|
25
26
|
* @param forceDownload force the system to download the image even if a successCallback is provided
|
|
26
27
|
* @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
|
|
28
|
+
* @param useFill fill the screenshot dimensions with the render canvas and clip any overflow. If false, fit the canvas within the screenshot, as in letterboxing.
|
|
27
29
|
*/
|
|
28
|
-
export function CreateScreenshot(engine, camera, size, successCallback, mimeType = "image/png", forceDownload = false, quality) {
|
|
30
|
+
export function CreateScreenshot(engine, camera, size, successCallback, mimeType = "image/png", forceDownload = false, quality, useFill = false) {
|
|
29
31
|
const { height, width } = _GetScreenshotSize(engine, camera, size);
|
|
30
32
|
if (!(height && width)) {
|
|
31
33
|
Logger.Error("Invalid 'size' parameter !");
|
|
32
34
|
return;
|
|
33
35
|
}
|
|
34
|
-
if (!screenshotCanvas) {
|
|
35
|
-
screenshotCanvas = document.createElement("canvas");
|
|
36
|
-
}
|
|
37
|
-
screenshotCanvas.width = width;
|
|
38
|
-
screenshotCanvas.height = height;
|
|
39
|
-
const renderContext = screenshotCanvas.getContext("2d");
|
|
40
|
-
const ratio = engine.getRenderWidth() / engine.getRenderHeight();
|
|
41
|
-
let newWidth = width;
|
|
42
|
-
let newHeight = newWidth / ratio;
|
|
43
|
-
if (newHeight > height) {
|
|
44
|
-
newHeight = height;
|
|
45
|
-
newWidth = newHeight * ratio;
|
|
46
|
-
}
|
|
47
|
-
const offsetX = Math.max(0, width - newWidth) / 2;
|
|
48
|
-
const offsetY = Math.max(0, height - newHeight) / 2;
|
|
49
36
|
const scene = camera.getScene();
|
|
50
37
|
if (scene.activeCamera !== camera) {
|
|
51
38
|
CreateScreenshotUsingRenderTarget(engine, camera, size, (data) => {
|
|
@@ -60,32 +47,51 @@ export function CreateScreenshot(engine, camera, size, successCallback, mimeType
|
|
|
60
47
|
successCallback(data);
|
|
61
48
|
}
|
|
62
49
|
}, mimeType, 1.0, engine.getCreationOptions().antialias, undefined, undefined, undefined, undefined, quality);
|
|
50
|
+
return;
|
|
63
51
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
52
|
+
engine.onEndFrameObservable.addOnce(() => {
|
|
53
|
+
if (!screenshotCanvas) {
|
|
54
|
+
screenshotCanvas = document.createElement("canvas");
|
|
55
|
+
}
|
|
56
|
+
screenshotCanvas.width = width;
|
|
57
|
+
screenshotCanvas.height = height;
|
|
58
|
+
const renderContext = screenshotCanvas.getContext("2d");
|
|
59
|
+
const renderingCanvas = engine.getRenderingCanvas();
|
|
60
|
+
if (!renderContext || !renderingCanvas) {
|
|
61
|
+
Logger.Error("Failed to create screenshot. Rendering context or rendering canvas is not available.");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const srcWidth = renderingCanvas.width;
|
|
65
|
+
const srcHeight = renderingCanvas.height;
|
|
66
|
+
const destWidth = screenshotCanvas.width;
|
|
67
|
+
const destHeight = screenshotCanvas.height;
|
|
68
|
+
// Calculate scale factors for width and height.
|
|
69
|
+
const scaleX = destWidth / srcWidth;
|
|
70
|
+
const scaleY = destHeight / srcHeight;
|
|
71
|
+
// Use the larger of the two scales to fill the screenshot dimensions, else use the smaller to fit.
|
|
72
|
+
const scale = useFill ? Math.max(scaleX, scaleY) : Math.min(scaleX, scaleY);
|
|
73
|
+
const newWidth = srcWidth * scale;
|
|
74
|
+
const newHeight = srcHeight * scale;
|
|
75
|
+
// Center the image in the screenshot canvas
|
|
76
|
+
const offsetX = (destWidth - newWidth) / 2;
|
|
77
|
+
const offsetY = (destHeight - newHeight) / 2;
|
|
78
|
+
renderContext.drawImage(renderingCanvas, 0, 0, srcWidth, srcHeight, offsetX, offsetY, newWidth, newHeight);
|
|
79
|
+
if (forceDownload) {
|
|
80
|
+
Tools.EncodeScreenshotCanvasData(screenshotCanvas, undefined, mimeType, undefined, quality);
|
|
81
|
+
if (successCallback) {
|
|
82
|
+
successCallback("");
|
|
80
83
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
Tools.EncodeScreenshotCanvasData(screenshotCanvas, successCallback, mimeType, undefined, quality);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
83
89
|
}
|
|
84
90
|
/**
|
|
85
91
|
* Captures a screenshot of the current rendering
|
|
86
92
|
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
|
|
87
93
|
* @param engine defines the rendering engine
|
|
88
|
-
* @param camera defines the source camera
|
|
94
|
+
* @param camera defines the source camera. If the camera is not the scene's active camera, {@link CreateScreenshotUsingRenderTarget} will be used instead, and `useFill` will be ignored
|
|
89
95
|
* @param size This parameter can be set to a single number or to an object with the
|
|
90
96
|
* following (optional) properties: precision, width, height. If a single number is passed,
|
|
91
97
|
* it will be used for both width and height. If an object is passed, the screenshot size
|
|
@@ -94,10 +100,11 @@ export function CreateScreenshot(engine, camera, size, successCallback, mimeType
|
|
|
94
100
|
* @param mimeType defines the MIME type of the screenshot image (default: image/png).
|
|
95
101
|
* Check your browser for supported MIME types
|
|
96
102
|
* @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
|
|
103
|
+
* @param useFill fill the screenshot dimensions with the render canvas and clip any overflow. If false, fit the canvas within the screenshot, as in letterboxing.
|
|
97
104
|
* @returns screenshot as a string of base64-encoded characters. This string can be assigned
|
|
98
105
|
* to the src parameter of an <img> to display it
|
|
99
106
|
*/
|
|
100
|
-
export function CreateScreenshotAsync(engine, camera, size, mimeType = "image/png", quality) {
|
|
107
|
+
export function CreateScreenshotAsync(engine, camera, size, mimeType = "image/png", quality, useFill = false) {
|
|
101
108
|
return new Promise((resolve, reject) => {
|
|
102
109
|
CreateScreenshot(engine, camera, size, (data) => {
|
|
103
110
|
if (typeof data !== "undefined") {
|
|
@@ -106,7 +113,7 @@ export function CreateScreenshotAsync(engine, camera, size, mimeType = "image/pn
|
|
|
106
113
|
else {
|
|
107
114
|
reject(new Error("Data is undefined"));
|
|
108
115
|
}
|
|
109
|
-
}, mimeType, undefined, quality);
|
|
116
|
+
}, mimeType, undefined, quality, useFill);
|
|
110
117
|
});
|
|
111
118
|
}
|
|
112
119
|
/**
|
|
@@ -114,19 +121,20 @@ export function CreateScreenshotAsync(engine, camera, size, mimeType = "image/pn
|
|
|
114
121
|
* If screenshot image data is needed, use {@link CreateScreenshotAsync} instead.
|
|
115
122
|
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
|
|
116
123
|
* @param engine defines the rendering engine
|
|
117
|
-
* @param camera defines the source camera
|
|
124
|
+
* @param camera defines the source camera. If the camera is not the scene's active camera, {@link CreateScreenshotUsingRenderTarget} will be used instead, and `useFill` will be ignored
|
|
118
125
|
* @param width defines the expected width
|
|
119
126
|
* @param height defines the expected height
|
|
120
127
|
* @param mimeType defines the MIME type of the screenshot image (default: image/png).
|
|
121
128
|
* Check your browser for supported MIME types
|
|
122
129
|
* @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
|
|
130
|
+
* @param useFill fill the screenshot dimensions with the render canvas and clip any overflow. If false, fit the canvas within the screenshot, as in letterboxing.
|
|
123
131
|
* @returns promise that resolves once the screenshot is taken
|
|
124
132
|
*/
|
|
125
|
-
export function CreateScreenshotWithResizeAsync(engine, camera, width, height, mimeType = "image/png", quality) {
|
|
133
|
+
export function CreateScreenshotWithResizeAsync(engine, camera, width, height, mimeType = "image/png", quality, useFill = false) {
|
|
126
134
|
return new Promise((resolve) => {
|
|
127
135
|
CreateScreenshot(engine, camera, { width: width, height: height }, () => {
|
|
128
136
|
resolve();
|
|
129
|
-
}, mimeType, true, quality);
|
|
137
|
+
}, mimeType, true, quality, useFill);
|
|
130
138
|
});
|
|
131
139
|
}
|
|
132
140
|
/**
|
|
@@ -172,7 +180,7 @@ export function CreateScreenshotUsingRenderTarget(engine, camera, size, successC
|
|
|
172
180
|
texture.forceLayerMaskCheck = useLayerMask;
|
|
173
181
|
customizeTexture?.(texture);
|
|
174
182
|
const renderWhenReady = () => {
|
|
175
|
-
|
|
183
|
+
_retryWithInterval(() => texture.isReadyForRendering() && camera.isReady(true), () => {
|
|
176
184
|
engine.onEndFrameObservable.addOnce(() => {
|
|
177
185
|
if (finalWidth === width && finalHeight === height) {
|
|
178
186
|
texture.readPixels(undefined, undefined, undefined, false).then((data) => {
|
|
@@ -195,10 +203,7 @@ export function CreateScreenshotUsingRenderTarget(engine, camera, size, successC
|
|
|
195
203
|
texture.render(true);
|
|
196
204
|
engine.setSize(originalSize.width, originalSize.height);
|
|
197
205
|
camera.getProjectionMatrix(true); // Force cache refresh;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
setTimeout(renderWhenReady, 16);
|
|
201
|
-
}
|
|
206
|
+
});
|
|
202
207
|
};
|
|
203
208
|
const renderToTexture = () => {
|
|
204
209
|
// render the RTT
|
|
@@ -264,10 +269,10 @@ export function CreateScreenshotUsingRenderTargetAsync(engine, camera, size, mim
|
|
|
264
269
|
}
|
|
265
270
|
/**
|
|
266
271
|
* Gets height and width for screenshot size
|
|
267
|
-
* @param engine
|
|
268
|
-
* @param camera
|
|
269
|
-
* @param size
|
|
270
|
-
* @
|
|
272
|
+
* @param engine The engine to use for rendering
|
|
273
|
+
* @param camera The camera to use for rendering
|
|
274
|
+
* @param size This size of the screenshot. can be a number or an object implementing IScreenshotSize
|
|
275
|
+
* @returns height and width for screenshot size
|
|
271
276
|
*/
|
|
272
277
|
function _GetScreenshotSize(engine, camera, size) {
|
|
273
278
|
let height = 0;
|
|
@@ -351,7 +356,7 @@ export const ScreenshotTools = {
|
|
|
351
356
|
* Captures a screenshot of the current rendering
|
|
352
357
|
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
|
|
353
358
|
* @param engine defines the rendering engine
|
|
354
|
-
* @param camera defines the source camera
|
|
359
|
+
* @param camera defines the source camera. If the camera is not the scene's active camera, {@link CreateScreenshotUsingRenderTarget} will be used instead, and `useFill` will be ignored
|
|
355
360
|
* @param size This parameter can be set to a single number or to an object with the
|
|
356
361
|
* following (optional) properties: precision, width, height. If a single number is passed,
|
|
357
362
|
* it will be used for both width and height. If an object is passed, the screenshot size
|
|
@@ -364,13 +369,14 @@ export const ScreenshotTools = {
|
|
|
364
369
|
* Check your browser for supported MIME types
|
|
365
370
|
* @param forceDownload force the system to download the image even if a successCallback is provided
|
|
366
371
|
* @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
|
|
372
|
+
* @param useFill fill the screenshot dimensions with the render canvas and clip any overflow. If false, fit the canvas within the screenshot, as in letterboxing.
|
|
367
373
|
*/
|
|
368
374
|
CreateScreenshot,
|
|
369
375
|
/**
|
|
370
376
|
* Captures a screenshot of the current rendering
|
|
371
377
|
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
|
|
372
378
|
* @param engine defines the rendering engine
|
|
373
|
-
* @param camera defines the source camera
|
|
379
|
+
* @param camera defines the source camera. If the camera is not the scene's active camera, {@link CreateScreenshotUsingRenderTarget} will be used instead, and `useFill` will be ignored
|
|
374
380
|
* @param size This parameter can be set to a single number or to an object with the
|
|
375
381
|
* following (optional) properties: precision, width, height. If a single number is passed,
|
|
376
382
|
* it will be used for both width and height. If an object is passed, the screenshot size
|
|
@@ -379,22 +385,24 @@ export const ScreenshotTools = {
|
|
|
379
385
|
* @param mimeType defines the MIME type of the screenshot image (default: image/png).
|
|
380
386
|
* Check your browser for supported MIME types
|
|
381
387
|
* @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
|
|
388
|
+
* @param useFill fill the screenshot dimensions with the render canvas and clip any overflow. If false, fit the canvas within the screenshot, as in letterboxing.
|
|
382
389
|
* @returns screenshot as a string of base64-encoded characters. This string can be assigned
|
|
383
390
|
* to the src parameter of an <img> to display it
|
|
384
391
|
*/
|
|
385
392
|
CreateScreenshotAsync,
|
|
386
393
|
/**
|
|
387
|
-
* Captures a screenshot of the current rendering for a specific size. This will render the entire canvas but will generate a blink (due to canvas resize)
|
|
394
|
+
* Captures and automatically downloads a screenshot of the current rendering for a specific size. This will render the entire canvas but will generate a blink (due to canvas resize)
|
|
395
|
+
* If screenshot image data is needed, use {@link CreateScreenshotAsync} instead.
|
|
388
396
|
* @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG
|
|
389
397
|
* @param engine defines the rendering engine
|
|
390
|
-
* @param camera defines the source camera
|
|
398
|
+
* @param camera defines the source camera. If the camera is not the scene's active camera, {@link CreateScreenshotUsingRenderTarget} will be used instead, and `useFill` will be ignored
|
|
391
399
|
* @param width defines the expected width
|
|
392
400
|
* @param height defines the expected height
|
|
393
401
|
* @param mimeType defines the MIME type of the screenshot image (default: image/png).
|
|
394
402
|
* Check your browser for supported MIME types
|
|
395
403
|
* @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.
|
|
396
|
-
* @
|
|
397
|
-
*
|
|
404
|
+
* @param useFill fill the screenshot dimensions with the render canvas and clip any overflow. If false, fit the canvas within the screenshot, as in letterboxing.
|
|
405
|
+
* @returns promise that resolves once the screenshot is taken
|
|
398
406
|
*/
|
|
399
407
|
CreateScreenshotWithResizeAsync,
|
|
400
408
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshotTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/screenshotTools.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,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K,CAAC,CAAC;IAC9B,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACT,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IACD,IAAI,UAAU,EAAE,CAAC;QACb,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IACD,IAAI,WAAW,EAAE,CAAC;QACd,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,UAAU,EAAE,UAAU,GAAG,CAAC,EAAE,WAAW,EAAE,WAAW,GAAG,CAAC,EAAE,CAAC;AAC9G,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC3B;;;;;;;;;;;;;;;;;OAiBG;IACH,gBAAgB;IAEhB;;;;;;;;;;;;;;;OAeG;IACH,qBAAqB;IAErB;;;;;;;;;;;;OAYG;IACH,+BAA+B;IAE/B;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,iCAAiC;IAEjC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,sCAAsC;CACzC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,eAAe,GAAG,GAAG,EAAE;IACzB,+BAA+B;IAC/B,KAAK,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC1C,KAAK,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IACpD,KAAK,CAAC,iCAAiC,GAAG,iCAAiC,CAAC;IAC5E,KAAK,CAAC,sCAAsC,GAAG,sCAAsC,CAAC;AAC1F,CAAC,CAAC;AAEF,eAAe,EAAE,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { FxaaPostProcess } from \"../PostProcesses/fxaaPostProcess\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { Logger } from \"./logger\";\r\nimport { Tools } from \"./tools\";\r\nimport type { IScreenshotSize } from \"./interfaces/screenshotSize\";\r\nimport { DumpData } from \"./dumpTools\";\r\nimport type { Nullable } from \"../types\";\r\nimport { ApplyPostProcess } from \"./textureTools\";\r\n\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\n\r\nlet screenshotCanvas: Nullable<HTMLCanvasElement> = null;\r\n\r\n/**\r\n * Captures a screenshot of the current rendering\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param successCallback defines the callback receives a single parameter which contains the\r\n * screenshot as a string of base64-encoded characters. This string can be assigned to the\r\n * src parameter of an <img> to display it\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param forceDownload force the system to download the image even if a successCallback is provided\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\nexport function CreateScreenshot(\r\n engine: AbstractEngine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n forceDownload = false,\r\n quality?: number\r\n): void {\r\n const { height, width } = _GetScreenshotSize(engine, camera, size);\r\n\r\n if (!(height && width)) {\r\n Logger.Error(\"Invalid 'size' parameter !\");\r\n return;\r\n }\r\n\r\n if (!screenshotCanvas) {\r\n screenshotCanvas = document.createElement(\"canvas\");\r\n }\r\n\r\n screenshotCanvas.width = width;\r\n screenshotCanvas.height = height;\r\n\r\n const renderContext = screenshotCanvas.getContext(\"2d\");\r\n\r\n const ratio = engine.getRenderWidth() / engine.getRenderHeight();\r\n let newWidth = width;\r\n let newHeight = newWidth / ratio;\r\n if (newHeight > height) {\r\n newHeight = height;\r\n newWidth = newHeight * ratio;\r\n }\r\n\r\n const offsetX = Math.max(0, width - newWidth) / 2;\r\n const offsetY = Math.max(0, height - newHeight) / 2;\r\n\r\n const scene = camera.getScene();\r\n if (scene.activeCamera !== camera) {\r\n CreateScreenshotUsingRenderTarget(\r\n engine,\r\n camera,\r\n size,\r\n (data) => {\r\n if (forceDownload) {\r\n const blob = new Blob([data]);\r\n Tools.DownloadBlob(blob);\r\n if (successCallback) {\r\n successCallback(\"\");\r\n }\r\n } else if (successCallback) {\r\n successCallback(data);\r\n }\r\n },\r\n mimeType,\r\n 1.0,\r\n engine.getCreationOptions().antialias,\r\n undefined,\r\n undefined,\r\n undefined,\r\n undefined,\r\n quality\r\n );\r\n } else {\r\n engine.onEndFrameObservable.addOnce(() => {\r\n const renderingCanvas = engine.getRenderingCanvas();\r\n if (renderContext && renderingCanvas) {\r\n renderContext.drawImage(renderingCanvas, offsetX, offsetY, newWidth, newHeight);\r\n }\r\n\r\n if (screenshotCanvas) {\r\n if (forceDownload) {\r\n Tools.EncodeScreenshotCanvasData(screenshotCanvas, undefined, mimeType, undefined, quality);\r\n if (successCallback) {\r\n successCallback(\"\");\r\n }\r\n } else {\r\n Tools.EncodeScreenshotCanvasData(screenshotCanvas, successCallback, mimeType, undefined, quality);\r\n }\r\n }\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Captures a screenshot of the current rendering\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\r\n * to the src parameter of an <img> to display it\r\n */\r\nexport function CreateScreenshotAsync(engine: AbstractEngine, camera: Camera, size: IScreenshotSize | number, mimeType = \"image/png\", quality?: number): Promise<string> {\r\n return new Promise((resolve, reject) => {\r\n CreateScreenshot(\r\n engine,\r\n camera,\r\n size,\r\n (data) => {\r\n if (typeof data !== \"undefined\") {\r\n resolve(data);\r\n } else {\r\n reject(new Error(\"Data is undefined\"));\r\n }\r\n },\r\n mimeType,\r\n undefined,\r\n quality\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Captures and automatically downloads a screenshot of the current rendering for a specific size. This will render the entire canvas but will generate a blink (due to canvas resize)\r\n * If screenshot image data is needed, use {@link CreateScreenshotAsync} instead.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera\r\n * @param width defines the expected width\r\n * @param height defines the expected height\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns promise that resolves once the screenshot is taken\r\n */\r\nexport function CreateScreenshotWithResizeAsync(engine: AbstractEngine, camera: Camera, width: number, height: number, mimeType = \"image/png\", quality?: number): Promise<void> {\r\n return new Promise((resolve) => {\r\n CreateScreenshot(\r\n engine,\r\n camera,\r\n { width: width, height: height },\r\n () => {\r\n resolve();\r\n },\r\n mimeType,\r\n true,\r\n quality\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Generates an image screenshot from the specified camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine The engine to use for rendering\r\n * @param camera The camera to use for rendering\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height, finalWidth, finalHeight. If a single number is passed,\r\n * it will be used for both width and height, as well as finalWidth, finalHeight. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param successCallback The callback receives a single parameter which contains the\r\n * screenshot as a string of base64-encoded characters. This string can be assigned to the\r\n * src parameter of an <img> to display it\r\n * @param mimeType The MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param samples Texture samples (default: 1)\r\n * @param antialiasing Whether antialiasing should be turned on or not (default: false)\r\n * @param fileName A name for for the downloaded file.\r\n * @param renderSprites Whether the sprites should be rendered or not (default: false)\r\n * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)\r\n * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @param customizeTexture An optional callback that can be used to modify the render target texture before taking the screenshot. This can be used, for instance, to enable camera post-processes before taking the screenshot.\r\n */\r\nexport function CreateScreenshotUsingRenderTarget(\r\n engine: AbstractEngine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n samples = 1,\r\n antialiasing = false,\r\n fileName?: string,\r\n renderSprites = false,\r\n enableStencilBuffer = false,\r\n useLayerMask = true,\r\n quality?: number,\r\n customizeTexture?: (texture: RenderTargetTexture) => void\r\n): void {\r\n const { height, width, finalWidth, finalHeight } = _GetScreenshotSize(engine, camera, size);\r\n const targetTextureSize = { width, height };\r\n\r\n if (!(height && width)) {\r\n Logger.Error(\"Invalid 'size' parameter !\");\r\n return;\r\n }\r\n\r\n const originalSize = { width: engine.getRenderWidth(), height: engine.getRenderHeight() };\r\n engine.setSize(width, height); // we need this call to trigger onResizeObservable with the screenshot width/height on all the subsystems that are observing this event and that needs to (re)create some resources with the right dimensions\r\n\r\n const scene = camera.getScene();\r\n\r\n // At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)\r\n const texture = new RenderTargetTexture(\r\n \"screenShot\",\r\n targetTextureSize,\r\n scene,\r\n false,\r\n false,\r\n Constants.TEXTURETYPE_UNSIGNED_BYTE,\r\n false,\r\n Texture.BILINEAR_SAMPLINGMODE,\r\n undefined,\r\n enableStencilBuffer,\r\n undefined,\r\n undefined,\r\n undefined,\r\n samples\r\n );\r\n texture.renderList = scene.meshes.slice();\r\n texture.samples = samples;\r\n texture.renderSprites = renderSprites;\r\n texture.activeCamera = camera;\r\n texture.forceLayerMaskCheck = useLayerMask;\r\n customizeTexture?.(texture);\r\n\r\n const renderWhenReady = () => {\r\n if (texture.isReadyForRendering() && camera.isReady(true)) {\r\n engine.onEndFrameObservable.addOnce(() => {\r\n if (finalWidth === width && finalHeight === height) {\r\n texture.readPixels(undefined, undefined, undefined, false)!.then((data) => {\r\n DumpData(width, height, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true, undefined, quality);\r\n texture.dispose();\r\n });\r\n } else {\r\n const importPromise = engine.isWebGPU ? import(\"../ShadersWGSL/pass.fragment\") : import(\"../Shaders/pass.fragment\");\r\n importPromise.then(() =>\r\n ApplyPostProcess(\"pass\", texture.getInternalTexture()!, scene, undefined, undefined, undefined, finalWidth, finalHeight).then((texture) => {\r\n engine._readTexturePixels(texture, finalWidth, finalHeight, -1, 0, null, true, false, 0, 0).then((data) => {\r\n DumpData(finalWidth, finalHeight, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true, undefined, quality);\r\n texture.dispose();\r\n });\r\n })\r\n );\r\n }\r\n });\r\n scene.incrementRenderId();\r\n scene.resetCachedMaterial();\r\n texture.render(true);\r\n engine.setSize(originalSize.width, originalSize.height);\r\n camera.getProjectionMatrix(true); // Force cache refresh;\r\n } else {\r\n setTimeout(renderWhenReady, 16);\r\n }\r\n };\r\n\r\n const renderToTexture = () => {\r\n // render the RTT\r\n scene.incrementRenderId();\r\n scene.resetCachedMaterial();\r\n\r\n renderWhenReady();\r\n };\r\n\r\n if (antialiasing) {\r\n const fxaaPostProcess = new FxaaPostProcess(\"antialiasing\", 1.0, scene.activeCamera);\r\n texture.addPostProcess(fxaaPostProcess);\r\n // Async Shader Compilation can lead to none ready effects in synchronous code\r\n fxaaPostProcess.onEffectCreatedObservable.addOnce((e) => {\r\n if (!e.isReady()) {\r\n e.onCompiled = () => {\r\n renderToTexture();\r\n };\r\n }\r\n // The effect is ready we can render\r\n else {\r\n renderToTexture();\r\n }\r\n });\r\n } else {\r\n // No need to wait for extra resources to be ready\r\n renderToTexture();\r\n }\r\n}\r\n\r\n/**\r\n * Generates an image screenshot from the specified camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine The engine to use for rendering\r\n * @param camera The camera to use for rendering\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param mimeType The MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param samples Texture samples (default: 1)\r\n * @param antialiasing Whether antialiasing should be turned on or not (default: false)\r\n * @param fileName A name for for the downloaded file.\r\n * @param renderSprites Whether the sprites should be rendered or not (default: false)\r\n * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)\r\n * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @param customizeTexture An optional callback that can be used to modify the render target texture before taking the screenshot. This can be used, for instance, to enable camera post-processes before taking the screenshot.\r\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\r\n * to the src parameter of an <img> to display it\r\n */\r\nexport function CreateScreenshotUsingRenderTargetAsync(\r\n engine: AbstractEngine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n mimeType = \"image/png\",\r\n samples = 1,\r\n antialiasing = false,\r\n fileName?: string,\r\n renderSprites = false,\r\n enableStencilBuffer = false,\r\n useLayerMask = true,\r\n quality?: number,\r\n customizeTexture?: (texture: RenderTargetTexture) => void\r\n): Promise<string> {\r\n return new Promise((resolve, reject) => {\r\n CreateScreenshotUsingRenderTarget(\r\n engine,\r\n camera,\r\n size,\r\n (data) => {\r\n if (typeof data !== \"undefined\") {\r\n resolve(data);\r\n } else {\r\n reject(new Error(\"Data is undefined\"));\r\n }\r\n },\r\n mimeType,\r\n samples,\r\n antialiasing,\r\n fileName,\r\n renderSprites,\r\n enableStencilBuffer,\r\n useLayerMask,\r\n quality,\r\n customizeTexture\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Gets height and width for screenshot size\r\n * @param engine\r\n * @param camera\r\n * @param size\r\n * @private\r\n */\r\nfunction _GetScreenshotSize(engine: AbstractEngine, camera: Camera, size: IScreenshotSize | number): { height: number; width: number; finalWidth: number; finalHeight: number } {\r\n let height = 0;\r\n let width = 0;\r\n let finalWidth = 0;\r\n let finalHeight = 0;\r\n\r\n //If a size value defined as object\r\n if (typeof size === \"object\") {\r\n const precision = size.precision\r\n ? Math.abs(size.precision) // prevent GL_INVALID_VALUE : glViewport: negative width/height\r\n : 1;\r\n\r\n //If a width and height values is specified\r\n if (size.width && size.height) {\r\n height = size.height * precision;\r\n width = size.width * precision;\r\n }\r\n //If passing only width, computing height to keep display canvas ratio.\r\n else if (size.width && !size.height) {\r\n width = size.width * precision;\r\n height = Math.round(width / engine.getAspectRatio(camera));\r\n }\r\n //If passing only height, computing width to keep display canvas ratio.\r\n else if (size.height && !size.width) {\r\n height = size.height * precision;\r\n width = Math.round(height * engine.getAspectRatio(camera));\r\n } else {\r\n width = Math.round(engine.getRenderWidth() * precision);\r\n height = Math.round(width / engine.getAspectRatio(camera));\r\n }\r\n\r\n //If a finalWidth and finalHeight values is specified\r\n if (size.finalWidth && size.finalHeight) {\r\n finalHeight = size.finalHeight;\r\n finalWidth = size.finalWidth;\r\n }\r\n //If passing only finalWidth, computing finalHeight to keep display canvas ratio.\r\n else if (size.finalWidth && !size.finalHeight) {\r\n finalWidth = size.finalWidth;\r\n finalHeight = Math.round(finalWidth / engine.getAspectRatio(camera));\r\n }\r\n //If passing only finalHeight, computing finalWidth to keep display canvas ratio.\r\n else if (size.finalHeight && !size.finalWidth) {\r\n finalHeight = size.finalHeight;\r\n finalWidth = Math.round(finalHeight * engine.getAspectRatio(camera));\r\n } else {\r\n finalWidth = width;\r\n finalHeight = height;\r\n }\r\n }\r\n //Assuming here that \"size\" parameter is a number\r\n else if (!isNaN(size)) {\r\n height = size;\r\n width = size;\r\n finalWidth = size;\r\n finalHeight = size;\r\n }\r\n\r\n // When creating the image data from the CanvasRenderingContext2D, the width and height is clamped to the size of the _gl context\r\n // On certain GPUs, it seems as if the _gl context truncates to an integer automatically. Therefore, if a user tries to pass the width of their canvas element\r\n // and it happens to be a float (1000.5 x 600.5 px), the engine.readPixels will return a different size array than context.createImageData\r\n // to resolve this, we truncate the floats here to ensure the same size\r\n if (width) {\r\n width = Math.floor(width);\r\n }\r\n if (height) {\r\n height = Math.floor(height);\r\n }\r\n if (finalWidth) {\r\n finalWidth = Math.floor(finalWidth);\r\n }\r\n if (finalHeight) {\r\n finalHeight = Math.floor(finalHeight);\r\n }\r\n\r\n return { height: height | 0, width: width | 0, finalWidth: finalWidth | 0, finalHeight: finalHeight | 0 };\r\n}\r\n\r\n/**\r\n * Class containing a set of static utilities functions for screenshots\r\n */\r\nexport const ScreenshotTools = {\r\n /**\r\n * Captures a screenshot of the current rendering\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param successCallback defines the callback receives a single parameter which contains the\r\n * screenshot as a string of base64-encoded characters. This string can be assigned to the\r\n * src parameter of an <img> to display it\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param forceDownload force the system to download the image even if a successCallback is provided\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\n CreateScreenshot,\r\n\r\n /**\r\n * Captures a screenshot of the current rendering\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\r\n * to the src parameter of an <img> to display it\r\n */\r\n CreateScreenshotAsync,\r\n\r\n /**\r\n * Captures a screenshot of the current rendering for a specific size. This will render the entire canvas but will generate a blink (due to canvas resize)\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera\r\n * @param width defines the expected width\r\n * @param height defines the expected height\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\r\n * to the src parameter of an <img> to display it\r\n */\r\n CreateScreenshotWithResizeAsync,\r\n\r\n /**\r\n * Generates an image screenshot from the specified camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine The engine to use for rendering\r\n * @param camera The camera to use for rendering\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param successCallback The callback receives a single parameter which contains the\r\n * screenshot as a string of base64-encoded characters. This string can be assigned to the\r\n * src parameter of an <img> to display it\r\n * @param mimeType The MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param samples Texture samples (default: 1)\r\n * @param antialiasing Whether antialiasing should be turned on or not (default: false)\r\n * @param fileName A name for for the downloaded file.\r\n * @param renderSprites Whether the sprites should be rendered or not (default: false)\r\n * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\n CreateScreenshotUsingRenderTarget,\r\n\r\n /**\r\n * Generates an image screenshot from the specified camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine The engine to use for rendering\r\n * @param camera The camera to use for rendering\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param mimeType The MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param samples Texture samples (default: 1)\r\n * @param antialiasing Whether antialiasing should be turned on or not (default: false)\r\n * @param fileName A name for for the downloaded file.\r\n * @param renderSprites Whether the sprites should be rendered or not (default: false)\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\r\n * to the src parameter of an <img> to display it\r\n */\r\n CreateScreenshotUsingRenderTargetAsync,\r\n};\r\n\r\n/**\r\n * This will be executed automatically for UMD and es5.\r\n * If esm dev wants the side effects to execute they will have to run it manually\r\n * Once we build native modules those need to be exported.\r\n * @internal\r\n */\r\nconst initSideEffects = () => {\r\n // References the dependencies.\r\n Tools.CreateScreenshot = CreateScreenshot;\r\n Tools.CreateScreenshotAsync = CreateScreenshotAsync;\r\n Tools.CreateScreenshotUsingRenderTarget = CreateScreenshotUsingRenderTarget;\r\n Tools.CreateScreenshotUsingRenderTargetAsync = CreateScreenshotUsingRenderTargetAsync;\r\n};\r\n\r\ninitSideEffects();\r\n"]}
|
|
1
|
+
{"version":3,"file":"screenshotTools.js","sourceRoot":"","sources":["../../../../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H,gBAAgB;IAEhB;;;;;;;;;;;;;;;;OAgBG;IACH,qBAAqB;IAErB;;;;;;;;;;;;;OAaG;IACH,+BAA+B;IAE/B;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,iCAAiC;IAEjC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,sCAAsC;CACzC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,eAAe,GAAG,GAAG,EAAE;IACzB,+BAA+B;IAC/B,KAAK,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC1C,KAAK,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IACpD,KAAK,CAAC,iCAAiC,GAAG,iCAAiC,CAAC;IAC5E,KAAK,CAAC,sCAAsC,GAAG,sCAAsC,CAAC;AAC1F,CAAC,CAAC;AAEF,eAAe,EAAE,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { FxaaPostProcess } from \"../PostProcesses/fxaaPostProcess\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { Logger } from \"./logger\";\r\nimport { Tools } from \"./tools\";\r\nimport type { IScreenshotSize } from \"./interfaces/screenshotSize\";\r\nimport { DumpData } from \"./dumpTools\";\r\nimport type { Nullable } from \"../types\";\r\nimport { ApplyPostProcess } from \"./textureTools\";\r\n\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport { _retryWithInterval } from \"./timingTools\";\r\n\r\nlet screenshotCanvas: Nullable<HTMLCanvasElement> = null;\r\n\r\n/**\r\n * Captures a screenshot of the current rendering\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera. If the camera is not the scene's active camera, {@link CreateScreenshotUsingRenderTarget} will be used instead, and `useFill` will be ignored\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param successCallback defines the callback receives a single parameter which contains the\r\n * screenshot as a string of base64-encoded characters. This string can be assigned to the\r\n * src parameter of an <img> to display it\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param forceDownload force the system to download the image even if a successCallback is provided\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @param useFill fill the screenshot dimensions with the render canvas and clip any overflow. If false, fit the canvas within the screenshot, as in letterboxing.\r\n */\r\nexport function CreateScreenshot(\r\n engine: AbstractEngine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n forceDownload = false,\r\n quality?: number,\r\n useFill = false\r\n): void {\r\n const { height, width } = _GetScreenshotSize(engine, camera, size);\r\n\r\n if (!(height && width)) {\r\n Logger.Error(\"Invalid 'size' parameter !\");\r\n return;\r\n }\r\n\r\n const scene = camera.getScene();\r\n if (scene.activeCamera !== camera) {\r\n CreateScreenshotUsingRenderTarget(\r\n engine,\r\n camera,\r\n size,\r\n (data) => {\r\n if (forceDownload) {\r\n const blob = new Blob([data]);\r\n Tools.DownloadBlob(blob);\r\n if (successCallback) {\r\n successCallback(\"\");\r\n }\r\n } else if (successCallback) {\r\n successCallback(data);\r\n }\r\n },\r\n mimeType,\r\n 1.0,\r\n engine.getCreationOptions().antialias,\r\n undefined,\r\n undefined,\r\n undefined,\r\n undefined,\r\n quality\r\n );\r\n return;\r\n }\r\n\r\n engine.onEndFrameObservable.addOnce(() => {\r\n if (!screenshotCanvas) {\r\n screenshotCanvas = document.createElement(\"canvas\");\r\n }\r\n screenshotCanvas.width = width;\r\n screenshotCanvas.height = height;\r\n\r\n const renderContext = screenshotCanvas.getContext(\"2d\");\r\n const renderingCanvas = engine.getRenderingCanvas();\r\n if (!renderContext || !renderingCanvas) {\r\n Logger.Error(\"Failed to create screenshot. Rendering context or rendering canvas is not available.\");\r\n return;\r\n }\r\n\r\n const srcWidth = renderingCanvas.width;\r\n const srcHeight = renderingCanvas.height;\r\n const destWidth = screenshotCanvas.width;\r\n const destHeight = screenshotCanvas.height;\r\n\r\n // Calculate scale factors for width and height.\r\n const scaleX = destWidth / srcWidth;\r\n const scaleY = destHeight / srcHeight;\r\n // Use the larger of the two scales to fill the screenshot dimensions, else use the smaller to fit.\r\n const scale = useFill ? Math.max(scaleX, scaleY) : Math.min(scaleX, scaleY);\r\n const newWidth = srcWidth * scale;\r\n const newHeight = srcHeight * scale;\r\n\r\n // Center the image in the screenshot canvas\r\n const offsetX = (destWidth - newWidth) / 2;\r\n const offsetY = (destHeight - newHeight) / 2;\r\n\r\n renderContext.drawImage(renderingCanvas, 0, 0, srcWidth, srcHeight, offsetX, offsetY, newWidth, newHeight);\r\n\r\n if (forceDownload) {\r\n Tools.EncodeScreenshotCanvasData(screenshotCanvas, undefined, mimeType, undefined, quality);\r\n if (successCallback) {\r\n successCallback(\"\");\r\n }\r\n } else {\r\n Tools.EncodeScreenshotCanvasData(screenshotCanvas, successCallback, mimeType, undefined, quality);\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Captures a screenshot of the current rendering\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera. If the camera is not the scene's active camera, {@link CreateScreenshotUsingRenderTarget} will be used instead, and `useFill` will be ignored\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @param useFill fill the screenshot dimensions with the render canvas and clip any overflow. If false, fit the canvas within the screenshot, as in letterboxing.\r\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\r\n * to the src parameter of an <img> to display it\r\n */\r\nexport function CreateScreenshotAsync(\r\n engine: AbstractEngine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n mimeType = \"image/png\",\r\n quality?: number,\r\n useFill = false\r\n): Promise<string> {\r\n return new Promise((resolve, reject) => {\r\n CreateScreenshot(\r\n engine,\r\n camera,\r\n size,\r\n (data) => {\r\n if (typeof data !== \"undefined\") {\r\n resolve(data);\r\n } else {\r\n reject(new Error(\"Data is undefined\"));\r\n }\r\n },\r\n mimeType,\r\n undefined,\r\n quality,\r\n useFill\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Captures and automatically downloads a screenshot of the current rendering for a specific size. This will render the entire canvas but will generate a blink (due to canvas resize)\r\n * If screenshot image data is needed, use {@link CreateScreenshotAsync} instead.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera. If the camera is not the scene's active camera, {@link CreateScreenshotUsingRenderTarget} will be used instead, and `useFill` will be ignored\r\n * @param width defines the expected width\r\n * @param height defines the expected height\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @param useFill fill the screenshot dimensions with the render canvas and clip any overflow. If false, fit the canvas within the screenshot, as in letterboxing.\r\n * @returns promise that resolves once the screenshot is taken\r\n */\r\nexport function CreateScreenshotWithResizeAsync(\r\n engine: AbstractEngine,\r\n camera: Camera,\r\n width: number,\r\n height: number,\r\n mimeType = \"image/png\",\r\n quality?: number,\r\n useFill = false\r\n): Promise<void> {\r\n return new Promise((resolve) => {\r\n CreateScreenshot(\r\n engine,\r\n camera,\r\n { width: width, height: height },\r\n () => {\r\n resolve();\r\n },\r\n mimeType,\r\n true,\r\n quality,\r\n useFill\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Generates an image screenshot from the specified camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine The engine to use for rendering\r\n * @param camera The camera to use for rendering\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height, finalWidth, finalHeight. If a single number is passed,\r\n * it will be used for both width and height, as well as finalWidth, finalHeight. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param successCallback The callback receives a single parameter which contains the\r\n * screenshot as a string of base64-encoded characters. This string can be assigned to the\r\n * src parameter of an <img> to display it\r\n * @param mimeType The MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param samples Texture samples (default: 1)\r\n * @param antialiasing Whether antialiasing should be turned on or not (default: false)\r\n * @param fileName A name for for the downloaded file.\r\n * @param renderSprites Whether the sprites should be rendered or not (default: false)\r\n * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)\r\n * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @param customizeTexture An optional callback that can be used to modify the render target texture before taking the screenshot. This can be used, for instance, to enable camera post-processes before taking the screenshot.\r\n */\r\nexport function CreateScreenshotUsingRenderTarget(\r\n engine: AbstractEngine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n successCallback?: (data: string) => void,\r\n mimeType = \"image/png\",\r\n samples = 1,\r\n antialiasing = false,\r\n fileName?: string,\r\n renderSprites = false,\r\n enableStencilBuffer = false,\r\n useLayerMask = true,\r\n quality?: number,\r\n customizeTexture?: (texture: RenderTargetTexture) => void\r\n): void {\r\n const { height, width, finalWidth, finalHeight } = _GetScreenshotSize(engine, camera, size);\r\n const targetTextureSize = { width, height };\r\n\r\n if (!(height && width)) {\r\n Logger.Error(\"Invalid 'size' parameter !\");\r\n return;\r\n }\r\n\r\n const originalSize = { width: engine.getRenderWidth(), height: engine.getRenderHeight() };\r\n engine.setSize(width, height); // we need this call to trigger onResizeObservable with the screenshot width/height on all the subsystems that are observing this event and that needs to (re)create some resources with the right dimensions\r\n\r\n const scene = camera.getScene();\r\n\r\n // At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)\r\n const texture = new RenderTargetTexture(\r\n \"screenShot\",\r\n targetTextureSize,\r\n scene,\r\n false,\r\n false,\r\n Constants.TEXTURETYPE_UNSIGNED_BYTE,\r\n false,\r\n Texture.BILINEAR_SAMPLINGMODE,\r\n undefined,\r\n enableStencilBuffer,\r\n undefined,\r\n undefined,\r\n undefined,\r\n samples\r\n );\r\n texture.renderList = scene.meshes.slice();\r\n texture.samples = samples;\r\n texture.renderSprites = renderSprites;\r\n texture.activeCamera = camera;\r\n texture.forceLayerMaskCheck = useLayerMask;\r\n customizeTexture?.(texture);\r\n\r\n const renderWhenReady = () => {\r\n _retryWithInterval(\r\n () => texture.isReadyForRendering() && camera.isReady(true),\r\n () => {\r\n engine.onEndFrameObservable.addOnce(() => {\r\n if (finalWidth === width && finalHeight === height) {\r\n texture.readPixels(undefined, undefined, undefined, false)!.then((data) => {\r\n DumpData(width, height, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true, undefined, quality);\r\n texture.dispose();\r\n });\r\n } else {\r\n const importPromise = engine.isWebGPU ? import(\"../ShadersWGSL/pass.fragment\") : import(\"../Shaders/pass.fragment\");\r\n importPromise.then(() =>\r\n ApplyPostProcess(\"pass\", texture.getInternalTexture()!, scene, undefined, undefined, undefined, finalWidth, finalHeight).then((texture) => {\r\n engine._readTexturePixels(texture, finalWidth, finalHeight, -1, 0, null, true, false, 0, 0).then((data) => {\r\n DumpData(finalWidth, finalHeight, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true, undefined, quality);\r\n texture.dispose();\r\n });\r\n })\r\n );\r\n }\r\n });\r\n scene.incrementRenderId();\r\n scene.resetCachedMaterial();\r\n texture.render(true);\r\n engine.setSize(originalSize.width, originalSize.height);\r\n camera.getProjectionMatrix(true); // Force cache refresh;\r\n }\r\n );\r\n };\r\n\r\n const renderToTexture = () => {\r\n // render the RTT\r\n scene.incrementRenderId();\r\n scene.resetCachedMaterial();\r\n\r\n renderWhenReady();\r\n };\r\n\r\n if (antialiasing) {\r\n const fxaaPostProcess = new FxaaPostProcess(\"antialiasing\", 1.0, scene.activeCamera);\r\n texture.addPostProcess(fxaaPostProcess);\r\n // Async Shader Compilation can lead to none ready effects in synchronous code\r\n fxaaPostProcess.onEffectCreatedObservable.addOnce((e) => {\r\n if (!e.isReady()) {\r\n e.onCompiled = () => {\r\n renderToTexture();\r\n };\r\n }\r\n // The effect is ready we can render\r\n else {\r\n renderToTexture();\r\n }\r\n });\r\n } else {\r\n // No need to wait for extra resources to be ready\r\n renderToTexture();\r\n }\r\n}\r\n\r\n/**\r\n * Generates an image screenshot from the specified camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine The engine to use for rendering\r\n * @param camera The camera to use for rendering\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param mimeType The MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param samples Texture samples (default: 1)\r\n * @param antialiasing Whether antialiasing should be turned on or not (default: false)\r\n * @param fileName A name for for the downloaded file.\r\n * @param renderSprites Whether the sprites should be rendered or not (default: false)\r\n * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)\r\n * @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @param customizeTexture An optional callback that can be used to modify the render target texture before taking the screenshot. This can be used, for instance, to enable camera post-processes before taking the screenshot.\r\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\r\n * to the src parameter of an <img> to display it\r\n */\r\nexport function CreateScreenshotUsingRenderTargetAsync(\r\n engine: AbstractEngine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n mimeType = \"image/png\",\r\n samples = 1,\r\n antialiasing = false,\r\n fileName?: string,\r\n renderSprites = false,\r\n enableStencilBuffer = false,\r\n useLayerMask = true,\r\n quality?: number,\r\n customizeTexture?: (texture: RenderTargetTexture) => void\r\n): Promise<string> {\r\n return new Promise((resolve, reject) => {\r\n CreateScreenshotUsingRenderTarget(\r\n engine,\r\n camera,\r\n size,\r\n (data) => {\r\n if (typeof data !== \"undefined\") {\r\n resolve(data);\r\n } else {\r\n reject(new Error(\"Data is undefined\"));\r\n }\r\n },\r\n mimeType,\r\n samples,\r\n antialiasing,\r\n fileName,\r\n renderSprites,\r\n enableStencilBuffer,\r\n useLayerMask,\r\n quality,\r\n customizeTexture\r\n );\r\n });\r\n}\r\n\r\n/**\r\n * Gets height and width for screenshot size\r\n * @param engine The engine to use for rendering\r\n * @param camera The camera to use for rendering\r\n * @param size This size of the screenshot. can be a number or an object implementing IScreenshotSize\r\n * @returns height and width for screenshot size\r\n */\r\nfunction _GetScreenshotSize(engine: AbstractEngine, camera: Camera, size: IScreenshotSize | number): { height: number; width: number; finalWidth: number; finalHeight: number } {\r\n let height = 0;\r\n let width = 0;\r\n let finalWidth = 0;\r\n let finalHeight = 0;\r\n\r\n //If a size value defined as object\r\n if (typeof size === \"object\") {\r\n const precision = size.precision\r\n ? Math.abs(size.precision) // prevent GL_INVALID_VALUE : glViewport: negative width/height\r\n : 1;\r\n\r\n //If a width and height values is specified\r\n if (size.width && size.height) {\r\n height = size.height * precision;\r\n width = size.width * precision;\r\n }\r\n //If passing only width, computing height to keep display canvas ratio.\r\n else if (size.width && !size.height) {\r\n width = size.width * precision;\r\n height = Math.round(width / engine.getAspectRatio(camera));\r\n }\r\n //If passing only height, computing width to keep display canvas ratio.\r\n else if (size.height && !size.width) {\r\n height = size.height * precision;\r\n width = Math.round(height * engine.getAspectRatio(camera));\r\n } else {\r\n width = Math.round(engine.getRenderWidth() * precision);\r\n height = Math.round(width / engine.getAspectRatio(camera));\r\n }\r\n\r\n //If a finalWidth and finalHeight values is specified\r\n if (size.finalWidth && size.finalHeight) {\r\n finalHeight = size.finalHeight;\r\n finalWidth = size.finalWidth;\r\n }\r\n //If passing only finalWidth, computing finalHeight to keep display canvas ratio.\r\n else if (size.finalWidth && !size.finalHeight) {\r\n finalWidth = size.finalWidth;\r\n finalHeight = Math.round(finalWidth / engine.getAspectRatio(camera));\r\n }\r\n //If passing only finalHeight, computing finalWidth to keep display canvas ratio.\r\n else if (size.finalHeight && !size.finalWidth) {\r\n finalHeight = size.finalHeight;\r\n finalWidth = Math.round(finalHeight * engine.getAspectRatio(camera));\r\n } else {\r\n finalWidth = width;\r\n finalHeight = height;\r\n }\r\n }\r\n //Assuming here that \"size\" parameter is a number\r\n else if (!isNaN(size)) {\r\n height = size;\r\n width = size;\r\n finalWidth = size;\r\n finalHeight = size;\r\n }\r\n\r\n // When creating the image data from the CanvasRenderingContext2D, the width and height is clamped to the size of the _gl context\r\n // On certain GPUs, it seems as if the _gl context truncates to an integer automatically. Therefore, if a user tries to pass the width of their canvas element\r\n // and it happens to be a float (1000.5 x 600.5 px), the engine.readPixels will return a different size array than context.createImageData\r\n // to resolve this, we truncate the floats here to ensure the same size\r\n if (width) {\r\n width = Math.floor(width);\r\n }\r\n if (height) {\r\n height = Math.floor(height);\r\n }\r\n if (finalWidth) {\r\n finalWidth = Math.floor(finalWidth);\r\n }\r\n if (finalHeight) {\r\n finalHeight = Math.floor(finalHeight);\r\n }\r\n\r\n return { height: height | 0, width: width | 0, finalWidth: finalWidth | 0, finalHeight: finalHeight | 0 };\r\n}\r\n\r\n/**\r\n * Class containing a set of static utilities functions for screenshots\r\n */\r\nexport const ScreenshotTools = {\r\n /**\r\n * Captures a screenshot of the current rendering\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera. If the camera is not the scene's active camera, {@link CreateScreenshotUsingRenderTarget} will be used instead, and `useFill` will be ignored\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param successCallback defines the callback receives a single parameter which contains the\r\n * screenshot as a string of base64-encoded characters. This string can be assigned to the\r\n * src parameter of an <img> to display it\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param forceDownload force the system to download the image even if a successCallback is provided\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @param useFill fill the screenshot dimensions with the render canvas and clip any overflow. If false, fit the canvas within the screenshot, as in letterboxing.\r\n */\r\n CreateScreenshot,\r\n\r\n /**\r\n * Captures a screenshot of the current rendering\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera. If the camera is not the scene's active camera, {@link CreateScreenshotUsingRenderTarget} will be used instead, and `useFill` will be ignored\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @param useFill fill the screenshot dimensions with the render canvas and clip any overflow. If false, fit the canvas within the screenshot, as in letterboxing.\r\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\r\n * to the src parameter of an <img> to display it\r\n */\r\n CreateScreenshotAsync,\r\n\r\n /**\r\n * Captures and automatically downloads a screenshot of the current rendering for a specific size. This will render the entire canvas but will generate a blink (due to canvas resize)\r\n * If screenshot image data is needed, use {@link CreateScreenshotAsync} instead.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine defines the rendering engine\r\n * @param camera defines the source camera. If the camera is not the scene's active camera, {@link CreateScreenshotUsingRenderTarget} will be used instead, and `useFill` will be ignored\r\n * @param width defines the expected width\r\n * @param height defines the expected height\r\n * @param mimeType defines the MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @param useFill fill the screenshot dimensions with the render canvas and clip any overflow. If false, fit the canvas within the screenshot, as in letterboxing.\r\n * @returns promise that resolves once the screenshot is taken\r\n */\r\n CreateScreenshotWithResizeAsync,\r\n\r\n /**\r\n * Generates an image screenshot from the specified camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine The engine to use for rendering\r\n * @param camera The camera to use for rendering\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param successCallback The callback receives a single parameter which contains the\r\n * screenshot as a string of base64-encoded characters. This string can be assigned to the\r\n * src parameter of an <img> to display it\r\n * @param mimeType The MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param samples Texture samples (default: 1)\r\n * @param antialiasing Whether antialiasing should be turned on or not (default: false)\r\n * @param fileName A name for for the downloaded file.\r\n * @param renderSprites Whether the sprites should be rendered or not (default: false)\r\n * @param enableStencilBuffer Whether the stencil buffer should be enabled or not (default: false)\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n */\r\n CreateScreenshotUsingRenderTarget,\r\n\r\n /**\r\n * Generates an image screenshot from the specified camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/renderToPNG\r\n * @param engine The engine to use for rendering\r\n * @param camera The camera to use for rendering\r\n * @param size This parameter can be set to a single number or to an object with the\r\n * following (optional) properties: precision, width, height. If a single number is passed,\r\n * it will be used for both width and height. If an object is passed, the screenshot size\r\n * will be derived from the parameters. The precision property is a multiplier allowing\r\n * rendering at a higher or lower resolution\r\n * @param mimeType The MIME type of the screenshot image (default: image/png).\r\n * Check your browser for supported MIME types\r\n * @param samples Texture samples (default: 1)\r\n * @param antialiasing Whether antialiasing should be turned on or not (default: false)\r\n * @param fileName A name for for the downloaded file.\r\n * @param renderSprites Whether the sprites should be rendered or not (default: false)\r\n * @param quality The quality of the image if lossy mimeType is used (e.g. image/jpeg, image/webp). See {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob | HTMLCanvasElement.toBlob()}'s `quality` parameter.\r\n * @returns screenshot as a string of base64-encoded characters. This string can be assigned\r\n * to the src parameter of an <img> to display it\r\n */\r\n CreateScreenshotUsingRenderTargetAsync,\r\n};\r\n\r\n/**\r\n * This will be executed automatically for UMD and es5.\r\n * If esm dev wants the side effects to execute they will have to run it manually\r\n * Once we build native modules those need to be exported.\r\n * @internal\r\n */\r\nconst initSideEffects = () => {\r\n // References the dependencies.\r\n Tools.CreateScreenshot = CreateScreenshot;\r\n Tools.CreateScreenshotAsync = CreateScreenshotAsync;\r\n Tools.CreateScreenshotUsingRenderTarget = CreateScreenshotUsingRenderTarget;\r\n Tools.CreateScreenshotUsingRenderTargetAsync = CreateScreenshotUsingRenderTargetAsync;\r\n};\r\n\r\ninitSideEffects();\r\n"]}
|
package/Misc/timingTools.d.ts
CHANGED
|
@@ -8,3 +8,7 @@ export declare class TimingTools {
|
|
|
8
8
|
*/
|
|
9
9
|
static SetImmediate(action: () => void): void;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare const _retryWithInterval: (condition: () => boolean, onSuccess: () => void, onError?: (e?: any) => void, step?: number, maxTimeout?: number, checkConditionOnCall?: boolean, additionalStringOnTimeout?: string) => void;
|
package/Misc/timingTools.js
CHANGED
|
@@ -17,4 +17,42 @@ export class TimingTools {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
function _runWithCondition(condition, onSuccess, onError) {
|
|
21
|
+
try {
|
|
22
|
+
if (condition()) {
|
|
23
|
+
onSuccess();
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
onError?.(e);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export const _retryWithInterval = (condition, onSuccess, onError, step = 16, maxTimeout = 30000, checkConditionOnCall = true, additionalStringOnTimeout) => {
|
|
37
|
+
// if checkConditionOnCall is true, we check the condition immediately. If it is true, run everything synchronously
|
|
38
|
+
if (checkConditionOnCall) {
|
|
39
|
+
// that means that one of the two happened - either the condition is true or an exception was thrown when checking the condition
|
|
40
|
+
if (_runWithCondition(condition, onSuccess, onError)) {
|
|
41
|
+
// don't schedule the interval, no reason to check it again.
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const int = setInterval(() => {
|
|
46
|
+
if (_runWithCondition(condition, onSuccess, onError)) {
|
|
47
|
+
clearInterval(int);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
maxTimeout -= step;
|
|
51
|
+
if (maxTimeout < 0) {
|
|
52
|
+
clearInterval(int);
|
|
53
|
+
onError?.(new Error("Operation timed out after maximum retries. " + (additionalStringOnTimeout || "")));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, step);
|
|
57
|
+
};
|
|
20
58
|
//# sourceMappingURL=timingTools.js.map
|
package/Misc/timingTools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timingTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/timingTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;GAEG;AACH,MAAM,OAAO,WAAW;IACpB;;;OAGG;IACI,MAAM,CAAC,YAAY,CAAC,MAAkB;QACzC,IAAI,mBAAmB,EAAE,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;YAC/C,mFAAmF;YACnF,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACJ,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC1B,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { IsWindowObjectExist } from \"./domManagement\";\r\n\r\n/**\r\n * Class used to provide helper for timing\r\n */\r\nexport class TimingTools {\r\n /**\r\n * Polyfill for setImmediate\r\n * @param action defines the action to execute after the current execution block\r\n */\r\n public static SetImmediate(action: () => void) {\r\n if (IsWindowObjectExist() && window.setImmediate) {\r\n // Note - deprecated and should not be used directly. Not supported in any browser.\r\n window.setImmediate(action);\r\n } else {\r\n setTimeout(action, 1);\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"timingTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/timingTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;GAEG;AACH,MAAM,OAAO,WAAW;IACpB;;;OAGG;IACI,MAAM,CAAC,YAAY,CAAC,MAAkB;QACzC,IAAI,mBAAmB,EAAE,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;YAC/C,mFAAmF;YACnF,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACJ,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC1B,CAAC;IACL,CAAC;CACJ;AAED,SAAS,iBAAiB,CAAC,SAAwB,EAAE,SAAqB,EAAE,OAA2B;IACnG,IAAI,CAAC;QACD,IAAI,SAAS,EAAE,EAAE,CAAC;YACd,SAAS,EAAE,CAAC;YACZ,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;QACb,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAC9B,SAAwB,EACxB,SAAqB,EACrB,OAA2B,EAC3B,IAAI,GAAG,EAAE,EACT,UAAU,GAAG,KAAK,EAClB,uBAAgC,IAAI,EACpC,yBAAkC,EACpC,EAAE;IACA,mHAAmH;IACnH,IAAI,oBAAoB,EAAE,CAAC;QACvB,gIAAgI;QAChI,IAAI,iBAAiB,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC;YACnD,4DAA4D;YAC5D,OAAO;QACX,CAAC;IACL,CAAC;IACD,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,EAAE;QACzB,IAAI,iBAAiB,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC;YACnD,aAAa,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACJ,UAAU,IAAI,IAAI,CAAC;YACnB,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;gBACjB,aAAa,CAAC,GAAG,CAAC,CAAC;gBACnB,OAAO,EAAE,CAAC,IAAI,KAAK,CAAC,6CAA6C,GAAG,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC5G,CAAC;QACL,CAAC;IACL,CAAC,EAAE,IAAI,CAAC,CAAC;AACb,CAAC,CAAC","sourcesContent":["import { IsWindowObjectExist } from \"./domManagement\";\r\n\r\n/**\r\n * Class used to provide helper for timing\r\n */\r\nexport class TimingTools {\r\n /**\r\n * Polyfill for setImmediate\r\n * @param action defines the action to execute after the current execution block\r\n */\r\n public static SetImmediate(action: () => void) {\r\n if (IsWindowObjectExist() && window.setImmediate) {\r\n // Note - deprecated and should not be used directly. Not supported in any browser.\r\n window.setImmediate(action);\r\n } else {\r\n setTimeout(action, 1);\r\n }\r\n }\r\n}\r\n\r\nfunction _runWithCondition(condition: () => boolean, onSuccess: () => void, onError?: (e?: any) => void) {\r\n try {\r\n if (condition()) {\r\n onSuccess();\r\n return true;\r\n }\r\n } catch (e) {\r\n onError?.(e);\r\n return true;\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport const _retryWithInterval = (\r\n condition: () => boolean,\r\n onSuccess: () => void,\r\n onError?: (e?: any) => void,\r\n step = 16,\r\n maxTimeout = 30000,\r\n checkConditionOnCall: boolean = true,\r\n additionalStringOnTimeout?: string\r\n) => {\r\n // if checkConditionOnCall is true, we check the condition immediately. If it is true, run everything synchronously\r\n if (checkConditionOnCall) {\r\n // that means that one of the two happened - either the condition is true or an exception was thrown when checking the condition\r\n if (_runWithCondition(condition, onSuccess, onError)) {\r\n // don't schedule the interval, no reason to check it again.\r\n return;\r\n }\r\n }\r\n const int = setInterval(() => {\r\n if (_runWithCondition(condition, onSuccess, onError)) {\r\n clearInterval(int);\r\n } else {\r\n maxTimeout -= step;\r\n if (maxTimeout < 0) {\r\n clearInterval(int);\r\n onError?.(new Error(\"Operation timed out after maximum retries. \" + (additionalStringOnTimeout || \"\")));\r\n }\r\n }\r\n }, step);\r\n};\r\n"]}
|
package/Misc/webRequest.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare class WebRequest implements IWebRequest {
|
|
|
15
15
|
/**
|
|
16
16
|
* Add callback functions in this array to update all the requests before they get sent to the network
|
|
17
17
|
*/
|
|
18
|
-
static CustomRequestModifiers: ((request: XMLHttpRequest, url: string) => void)[];
|
|
18
|
+
static CustomRequestModifiers: ((request: XMLHttpRequest, url: string) => string | void)[];
|
|
19
19
|
/**
|
|
20
20
|
* If set to true, requests to Babylon.js CDN requests will not be modified
|
|
21
21
|
*/
|
package/Misc/webRequest.js
CHANGED
package/Misc/webRequest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webRequest.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/webRequest.ts"],"names":[],"mappings":"AAOA,gBAAgB;AAChB,gEAAgE;AAChE,SAAS,oBAAoB;IACzB,4GAA4G;IAC5G,IAAI,OAAO,OAAO,KAAK,WAA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AAE,AAAhC,CAAiC;AAEnE;;GAEG;AACW,iCAAsB,GAAG,IAAI,KAAK,EAAkD,AAA9D,CAA+D;AAEnG;;GAEG;AACW,+CAAoC,GAAG,IAAI,AAAP,CAAQ","sourcesContent":["import type { IWebRequest } from \"./interfaces/iWebRequest\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { INative } from \"../Engines/Native/nativeInterfaces\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare const _native: INative;\r\n\r\n/** @internal */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nfunction createXMLHttpRequest(): XMLHttpRequest {\r\n // If running in Babylon Native, then defer to the native XMLHttpRequest, which has the same public contract\r\n if (typeof _native !== \"undefined\" && _native.XMLHttpRequest) {\r\n return new _native.XMLHttpRequest();\r\n } else {\r\n return new XMLHttpRequest();\r\n }\r\n}\r\n\r\n/**\r\n * Extended version of XMLHttpRequest with support for customizations (headers, ...)\r\n */\r\nexport class WebRequest implements IWebRequest {\r\n private readonly _xhr = createXMLHttpRequest();\r\n\r\n /**\r\n * Custom HTTP Request Headers to be sent with XMLHttpRequests\r\n * i.e. when loading files, where the server/service expects an Authorization header\r\n */\r\n public static CustomRequestHeaders: { [key: string]: string } = {};\r\n\r\n /**\r\n * Add callback functions in this array to update all the requests before they get sent to the network\r\n */\r\n public static CustomRequestModifiers = new Array<(request: XMLHttpRequest, url: string) => void>();\r\n\r\n /**\r\n * If set to true, requests to Babylon.js CDN requests will not be modified\r\n */\r\n public static SkipRequestModificationForBabylonCDN = true;\r\n\r\n /**\r\n * This function can be called to check if there are request modifiers for network requests\r\n * @returns true if there are any custom requests available\r\n */\r\n public static get IsCustomRequestAvailable(): boolean {\r\n return Object.keys(WebRequest.CustomRequestHeaders).length > 0 || WebRequest.CustomRequestModifiers.length > 0;\r\n }\r\n\r\n private _requestURL: string = \"\";\r\n\r\n /**\r\n * Returns the requested URL once open has been called\r\n */\r\n public get requestURL(): string {\r\n return this._requestURL;\r\n }\r\n\r\n private _injectCustomRequestHeaders(): void {\r\n if (this._shouldSkipRequestModifications(this._requestURL)) {\r\n return;\r\n }\r\n for (const key in WebRequest.CustomRequestHeaders) {\r\n const val = WebRequest.CustomRequestHeaders[key];\r\n if (val) {\r\n this._xhr.setRequestHeader(key, val);\r\n }\r\n }\r\n }\r\n\r\n private _shouldSkipRequestModifications(url: string): boolean {\r\n return WebRequest.SkipRequestModificationForBabylonCDN && (url.includes(\"preview.babylonjs.com\") || url.includes(\"cdn.babylonjs.com\"));\r\n }\r\n\r\n /**\r\n * Gets or sets a function to be called when loading progress changes\r\n */\r\n public get onprogress(): ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null {\r\n return this._xhr.onprogress;\r\n }\r\n\r\n public set onprogress(value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null) {\r\n this._xhr.onprogress = value;\r\n }\r\n\r\n /**\r\n * Returns client's state\r\n */\r\n public get readyState(): number {\r\n return this._xhr.readyState;\r\n }\r\n\r\n /**\r\n * Returns client's status\r\n */\r\n public get status(): number {\r\n return this._xhr.status;\r\n }\r\n\r\n /**\r\n * Returns client's status as a text\r\n */\r\n public get statusText(): string {\r\n return this._xhr.statusText;\r\n }\r\n\r\n /**\r\n * Returns client's response\r\n */\r\n public get response(): any {\r\n return this._xhr.response;\r\n }\r\n\r\n /**\r\n * Returns client's response url\r\n */\r\n public get responseURL(): string {\r\n return this._xhr.responseURL;\r\n }\r\n\r\n /**\r\n * Returns client's response as text\r\n */\r\n public get responseText(): string {\r\n return this._xhr.responseText;\r\n }\r\n\r\n /**\r\n * Gets or sets the expected response type\r\n */\r\n public get responseType(): XMLHttpRequestResponseType {\r\n return this._xhr.responseType;\r\n }\r\n\r\n public set responseType(value: XMLHttpRequestResponseType) {\r\n this._xhr.responseType = value;\r\n }\r\n\r\n /**\r\n * Gets or sets the timeout value in milliseconds\r\n */\r\n public get timeout(): number {\r\n return this._xhr.timeout;\r\n }\r\n\r\n public set timeout(value: number) {\r\n this._xhr.timeout = value;\r\n }\r\n\r\n /** @internal */\r\n public addEventListener<K extends keyof XMLHttpRequestEventMap>(\r\n type: K,\r\n listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,\r\n options?: boolean | AddEventListenerOptions\r\n ): void;\r\n public addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void {\r\n this._xhr.addEventListener(type, listener, options);\r\n }\r\n\r\n /** @internal */\r\n public removeEventListener<K extends keyof XMLHttpRequestEventMap>(\r\n type: K,\r\n listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,\r\n options?: boolean | EventListenerOptions\r\n ): void;\r\n public removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void {\r\n this._xhr.removeEventListener(type, listener, options);\r\n }\r\n\r\n /**\r\n * Cancels any network activity\r\n */\r\n public abort() {\r\n this._xhr.abort();\r\n }\r\n\r\n /**\r\n * Initiates the request. The optional argument provides the request body. The argument is ignored if request method is GET or HEAD\r\n * @param body defines an optional request body\r\n */\r\n public send(body?: Document | XMLHttpRequestBodyInit | null): void {\r\n if (WebRequest.CustomRequestHeaders) {\r\n this._injectCustomRequestHeaders();\r\n }\r\n\r\n this._xhr.send(body);\r\n }\r\n\r\n /**\r\n * Sets the request method, request URL\r\n * @param method defines the method to use (GET, POST, etc..)\r\n * @param url defines the url to connect with\r\n */\r\n public open(method: string, url: string): void {\r\n for (const update of WebRequest.CustomRequestModifiers) {\r\n if (this._shouldSkipRequestModifications(url)) {\r\n return;\r\n }\r\n update(this._xhr, url);\r\n }\r\n\r\n // Clean url\r\n url = url.replace(\"file:http:\", \"http:\");\r\n url = url.replace(\"file:https:\", \"https:\");\r\n\r\n this._requestURL = url;\r\n\r\n this._xhr.open(method, url, true);\r\n }\r\n\r\n /**\r\n * Sets the value of a request header.\r\n * @param name The name of the header whose value is to be set\r\n * @param value The value to set as the body of the header\r\n */\r\n setRequestHeader(name: string, value: string): void {\r\n this._xhr.setRequestHeader(name, value);\r\n }\r\n\r\n /**\r\n * Get the string containing the text of a particular header's value.\r\n * @param name The name of the header\r\n * @returns The string containing the text of the given header name\r\n */\r\n getResponseHeader(name: string): Nullable<string> {\r\n return this._xhr.getResponseHeader(name);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"webRequest.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/webRequest.ts"],"names":[],"mappings":"AAOA,gBAAgB;AAChB,gEAAgE;AAChE,SAAS,oBAAoB;IACzB,4GAA4G;IAC5G,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QAC3D,OAAO,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IACxC,CAAC;SAAM,CAAC;QACJ,OAAO,IAAI,cAAc,EAAE,CAAC;IAChC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,UAAU;IAAvB;QACqB,SAAI,GAAG,oBAAoB,EAAE,CAAC;QA0BvC,gBAAW,GAAW,EAAE,CAAC;IAkLrC,CAAC;IA1LG;;;OAGG;IACI,MAAM,KAAK,wBAAwB;QACtC,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,CAAC,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;IACnH,CAAC;IAID;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAEO,2BAA2B;QAC/B,IAAI,IAAI,CAAC,+BAA+B,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YACzD,OAAO;QACX,CAAC;QACD,KAAK,MAAM,GAAG,IAAI,UAAU,CAAC,oBAAoB,EAAE,CAAC;YAChD,MAAM,GAAG,GAAG,UAAU,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;YACjD,IAAI,GAAG,EAAE,CAAC;gBACN,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AC;QAEvB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,IAAY,EAAE,KAAa;QACxC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,IAAY;QAC1B,OAAO,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;;AAzMD;;;GAGG;AACW,+BAAoB,GAA8B,EAAE,AAAhC,CAAiC;AAEnE;;GAEG;AACW,iCAAsB,GAAG,IAAI,KAAK,EAA2D,AAAvE,CAAwE;AAE5G;;GAEG;AACW,+CAAoC,GAAG,IAAI,AAAP,CAAQ","sourcesContent":["import type { IWebRequest } from \"./interfaces/iWebRequest\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { INative } from \"../Engines/Native/nativeInterfaces\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare const _native: INative;\r\n\r\n/** @internal */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nfunction createXMLHttpRequest(): XMLHttpRequest {\r\n // If running in Babylon Native, then defer to the native XMLHttpRequest, which has the same public contract\r\n if (typeof _native !== \"undefined\" && _native.XMLHttpRequest) {\r\n return new _native.XMLHttpRequest();\r\n } else {\r\n return new XMLHttpRequest();\r\n }\r\n}\r\n\r\n/**\r\n * Extended version of XMLHttpRequest with support for customizations (headers, ...)\r\n */\r\nexport class WebRequest implements IWebRequest {\r\n private readonly _xhr = createXMLHttpRequest();\r\n\r\n /**\r\n * Custom HTTP Request Headers to be sent with XMLHttpRequests\r\n * i.e. when loading files, where the server/service expects an Authorization header\r\n */\r\n public static CustomRequestHeaders: { [key: string]: string } = {};\r\n\r\n /**\r\n * Add callback functions in this array to update all the requests before they get sent to the network\r\n */\r\n public static CustomRequestModifiers = new Array<(request: XMLHttpRequest, url: string) => string | void>();\r\n\r\n /**\r\n * If set to true, requests to Babylon.js CDN requests will not be modified\r\n */\r\n public static SkipRequestModificationForBabylonCDN = true;\r\n\r\n /**\r\n * This function can be called to check if there are request modifiers for network requests\r\n * @returns true if there are any custom requests available\r\n */\r\n public static get IsCustomRequestAvailable(): boolean {\r\n return Object.keys(WebRequest.CustomRequestHeaders).length > 0 || WebRequest.CustomRequestModifiers.length > 0;\r\n }\r\n\r\n private _requestURL: string = \"\";\r\n\r\n /**\r\n * Returns the requested URL once open has been called\r\n */\r\n public get requestURL(): string {\r\n return this._requestURL;\r\n }\r\n\r\n private _injectCustomRequestHeaders(): void {\r\n if (this._shouldSkipRequestModifications(this._requestURL)) {\r\n return;\r\n }\r\n for (const key in WebRequest.CustomRequestHeaders) {\r\n const val = WebRequest.CustomRequestHeaders[key];\r\n if (val) {\r\n this._xhr.setRequestHeader(key, val);\r\n }\r\n }\r\n }\r\n\r\n private _shouldSkipRequestModifications(url: string): boolean {\r\n return WebRequest.SkipRequestModificationForBabylonCDN && (url.includes(\"preview.babylonjs.com\") || url.includes(\"cdn.babylonjs.com\"));\r\n }\r\n\r\n /**\r\n * Gets or sets a function to be called when loading progress changes\r\n */\r\n public get onprogress(): ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null {\r\n return this._xhr.onprogress;\r\n }\r\n\r\n public set onprogress(value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null) {\r\n this._xhr.onprogress = value;\r\n }\r\n\r\n /**\r\n * Returns client's state\r\n */\r\n public get readyState(): number {\r\n return this._xhr.readyState;\r\n }\r\n\r\n /**\r\n * Returns client's status\r\n */\r\n public get status(): number {\r\n return this._xhr.status;\r\n }\r\n\r\n /**\r\n * Returns client's status as a text\r\n */\r\n public get statusText(): string {\r\n return this._xhr.statusText;\r\n }\r\n\r\n /**\r\n * Returns client's response\r\n */\r\n public get response(): any {\r\n return this._xhr.response;\r\n }\r\n\r\n /**\r\n * Returns client's response url\r\n */\r\n public get responseURL(): string {\r\n return this._xhr.responseURL;\r\n }\r\n\r\n /**\r\n * Returns client's response as text\r\n */\r\n public get responseText(): string {\r\n return this._xhr.responseText;\r\n }\r\n\r\n /**\r\n * Gets or sets the expected response type\r\n */\r\n public get responseType(): XMLHttpRequestResponseType {\r\n return this._xhr.responseType;\r\n }\r\n\r\n public set responseType(value: XMLHttpRequestResponseType) {\r\n this._xhr.responseType = value;\r\n }\r\n\r\n /**\r\n * Gets or sets the timeout value in milliseconds\r\n */\r\n public get timeout(): number {\r\n return this._xhr.timeout;\r\n }\r\n\r\n public set timeout(value: number) {\r\n this._xhr.timeout = value;\r\n }\r\n\r\n /** @internal */\r\n public addEventListener<K extends keyof XMLHttpRequestEventMap>(\r\n type: K,\r\n listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,\r\n options?: boolean | AddEventListenerOptions\r\n ): void;\r\n public addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void {\r\n this._xhr.addEventListener(type, listener, options);\r\n }\r\n\r\n /** @internal */\r\n public removeEventListener<K extends keyof XMLHttpRequestEventMap>(\r\n type: K,\r\n listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any,\r\n options?: boolean | EventListenerOptions\r\n ): void;\r\n public removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void {\r\n this._xhr.removeEventListener(type, listener, options);\r\n }\r\n\r\n /**\r\n * Cancels any network activity\r\n */\r\n public abort() {\r\n this._xhr.abort();\r\n }\r\n\r\n /**\r\n * Initiates the request. The optional argument provides the request body. The argument is ignored if request method is GET or HEAD\r\n * @param body defines an optional request body\r\n */\r\n public send(body?: Document | XMLHttpRequestBodyInit | null): void {\r\n if (WebRequest.CustomRequestHeaders) {\r\n this._injectCustomRequestHeaders();\r\n }\r\n\r\n this._xhr.send(body);\r\n }\r\n\r\n /**\r\n * Sets the request method, request URL\r\n * @param method defines the method to use (GET, POST, etc..)\r\n * @param url defines the url to connect with\r\n */\r\n public open(method: string, url: string): void {\r\n for (const update of WebRequest.CustomRequestModifiers) {\r\n if (this._shouldSkipRequestModifications(url)) {\r\n return;\r\n }\r\n url = update(this._xhr, url) || url;\r\n }\r\n\r\n // Clean url\r\n url = url.replace(\"file:http:\", \"http:\");\r\n url = url.replace(\"file:https:\", \"https:\");\r\n\r\n this._requestURL = url;\r\n\r\n this._xhr.open(method, url, true);\r\n }\r\n\r\n /**\r\n * Sets the value of a request header.\r\n * @param name The name of the header whose value is to be set\r\n * @param value The value to set as the body of the header\r\n */\r\n setRequestHeader(name: string, value: string): void {\r\n this._xhr.setRequestHeader(name, value);\r\n }\r\n\r\n /**\r\n * Get the string containing the text of a particular header's value.\r\n * @param name The name of the header\r\n * @returns The string containing the text of the given header name\r\n */\r\n getResponseHeader(name: string): Nullable<string> {\r\n return this._xhr.getResponseHeader(name);\r\n }\r\n}\r\n"]}
|