@babylonjs/core 5.53.0 → 5.54.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/Animations/animationGroup.js +8 -1
- package/Animations/animationGroup.js.map +1 -1
- package/Engines/Extensions/engine.cubeTexture.js +3 -0
- package/Engines/Extensions/engine.cubeTexture.js.map +1 -1
- package/Engines/Extensions/engine.multiRender.js +74 -19
- package/Engines/Extensions/engine.multiRender.js.map +1 -1
- package/Engines/Extensions/engine.renderTarget.js +2 -5
- package/Engines/Extensions/engine.renderTarget.js.map +1 -1
- package/Engines/WebGL/webGLHardwareTexture.d.ts +3 -1
- package/Engines/WebGL/webGLHardwareTexture.js +19 -7
- package/Engines/WebGL/webGLHardwareTexture.js.map +1 -1
- package/Engines/WebGL/webGLRenderTargetWrapper.d.ts +14 -1
- package/Engines/WebGL/webGLRenderTargetWrapper.js +76 -6
- package/Engines/WebGL/webGLRenderTargetWrapper.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.multiRender.js +20 -0
- package/Engines/WebGPU/Extensions/engine.multiRender.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.renderTarget.js +3 -1
- package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
- package/Engines/WebGPU/webgpuConstants.d.ts +22 -7
- package/Engines/WebGPU/webgpuConstants.js +24 -8
- package/Engines/WebGPU/webgpuConstants.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessorsWGSL.d.ts +0 -3
- package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js +20 -53
- package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js.map +1 -1
- package/Engines/WebGPU/webgpuTextureHelper.d.ts +3 -2
- package/Engines/WebGPU/webgpuTextureHelper.js +33 -14
- package/Engines/WebGPU/webgpuTextureHelper.js.map +1 -1
- package/Engines/WebGPU/webgpuTintWASM.d.ts +3 -2
- package/Engines/WebGPU/webgpuTintWASM.js +10 -8
- package/Engines/WebGPU/webgpuTintWASM.js.map +1 -1
- package/Engines/constants.d.ts +12 -0
- package/Engines/constants.js +12 -0
- package/Engines/constants.js.map +1 -1
- package/Engines/engine.d.ts +128 -72
- package/Engines/nativeEngine.d.ts +1 -0
- package/Engines/nativeEngine.js +16 -5
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/renderTargetWrapper.d.ts +28 -4
- package/Engines/renderTargetWrapper.js +107 -10
- package/Engines/renderTargetWrapper.js.map +1 -1
- package/Engines/thinEngine.d.ts +6 -6
- package/Engines/thinEngine.js +28 -20
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.d.ts +25 -8
- package/Engines/webgpuEngine.js +112 -48
- package/Engines/webgpuEngine.js.map +1 -1
- package/Materials/PBR/pbrAnisotropicConfiguration.js +0 -1
- package/Materials/PBR/pbrAnisotropicConfiguration.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.js +3 -0
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/Textures/internalTexture.d.ts +4 -0
- package/Materials/Textures/internalTexture.js.map +1 -1
- package/Materials/Textures/multiRenderTarget.d.ts +40 -0
- package/Materials/Textures/multiRenderTarget.js +143 -4
- package/Materials/Textures/multiRenderTarget.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.d.ts +4 -0
- package/Materials/Textures/renderTargetTexture.js +10 -2
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Materials/Textures/texture.d.ts +4 -2
- package/Materials/Textures/texture.js +1 -0
- package/Materials/Textures/texture.js.map +1 -1
- package/Materials/Textures/textureCreationOptions.d.ts +4 -0
- package/Materials/Textures/textureCreationOptions.js.map +1 -1
- package/Meshes/trailMesh.d.ts +5 -2
- package/Meshes/trailMesh.js +9 -8
- package/Meshes/trailMesh.js.map +1 -1
- package/Misc/interfaces/screenshotSize.d.ts +17 -3
- package/Misc/interfaces/screenshotSize.js.map +1 -1
- package/Misc/sceneRecorder.js +3 -0
- package/Misc/sceneRecorder.js.map +1 -1
- package/Misc/screenshotTools.d.ts +2 -2
- package/Misc/screenshotTools.js +49 -9
- package/Misc/screenshotTools.js.map +1 -1
- package/Misc/textureTools.d.ts +1 -1
- package/Misc/textureTools.js +4 -2
- package/Misc/textureTools.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js +1 -0
- package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/postProcessRenderPipelineManager.d.ts +5 -0
- package/PostProcesses/RenderPipeline/postProcessRenderPipelineManager.js +7 -0
- package/PostProcesses/RenderPipeline/postProcessRenderPipelineManager.js.map +1 -1
- package/PostProcesses/depthOfFieldMergePostProcess.d.ts +0 -23
- package/PostProcesses/depthOfFieldMergePostProcess.js +0 -5
- package/PostProcesses/depthOfFieldMergePostProcess.js.map +1 -1
- package/PostProcesses/postProcess.js +1 -0
- package/PostProcesses/postProcess.js.map +1 -1
- package/Probes/reflectionProbe.js +1 -0
- package/Probes/reflectionProbe.js.map +1 -1
- package/Rendering/depthPeelingRenderer.js +3 -1
- package/Rendering/depthPeelingRenderer.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderer.js +1 -1
- package/Rendering/fluidRenderer/fluidRenderer.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.js +2 -1
- package/Rendering/fluidRenderer/fluidRenderingDepthTextureCopy.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderingTextures.js +2 -0
- package/Rendering/fluidRenderer/fluidRenderingTextures.js.map +1 -1
- package/Shaders/default.fragment.js +1 -1
- package/Shaders/default.fragment.js.map +1 -1
- package/Shaders/depthOfFieldMerge.fragment.js +10 -5
- package/Shaders/depthOfFieldMerge.fragment.js.map +1 -1
- package/Shaders/fluidRenderingRender.fragment.js +3 -3
- package/Shaders/fluidRenderingRender.fragment.js.map +1 -1
- package/Shaders/motionBlur.fragment.js +8 -2
- package/Shaders/motionBlur.fragment.js.map +1 -1
- package/Shaders/screenSpaceReflection2.fragment.js +11 -4
- package/Shaders/screenSpaceReflection2.fragment.js.map +1 -1
- package/Shaders/screenSpaceReflection2Blur.fragment.js +6 -1
- package/Shaders/screenSpaceReflection2Blur.fragment.js.map +1 -1
- package/Shaders/ssao2.fragment.js +1 -0
- package/Shaders/ssao2.fragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/bakedVertexAnimation.js +9 -9
- package/ShadersWGSL/ShadersInclude/bakedVertexAnimation.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/bonesVertex.js +16 -16
- package/ShadersWGSL/ShadersInclude/bonesVertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/clipPlaneFragment.js +6 -6
- package/ShadersWGSL/ShadersInclude/clipPlaneFragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/clipPlaneVertex.js +6 -6
- package/ShadersWGSL/ShadersInclude/clipPlaneVertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/instancesVertex.js +1 -1
- package/ShadersWGSL/ShadersInclude/instancesVertex.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/morphTargetsVertex.js +8 -8
- package/ShadersWGSL/ShadersInclude/morphTargetsVertex.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,16 +4,30 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export interface IScreenshotSize {
|
|
6
6
|
/**
|
|
7
|
-
* number in pixels for canvas height
|
|
7
|
+
* number in pixels for canvas height. It is the height of the texture used to render the scene
|
|
8
8
|
*/
|
|
9
9
|
height?: number;
|
|
10
10
|
/**
|
|
11
11
|
* multiplier allowing render at a higher or lower resolution
|
|
12
|
-
* If value is defined then
|
|
12
|
+
* If value is defined then width and height will be multiplied by this value
|
|
13
13
|
*/
|
|
14
14
|
precision?: number;
|
|
15
15
|
/**
|
|
16
|
-
* number in pixels for canvas width
|
|
16
|
+
* number in pixels for canvas width. It is the width of the texture used to render the scene
|
|
17
17
|
*/
|
|
18
18
|
width?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Width of the final screenshot image.
|
|
21
|
+
* If only one of the two values is provided, the other will be calculated based on the camera's aspect ratio.
|
|
22
|
+
* If both finalWidth and finalHeight are not provided, width and height will be used instead.
|
|
23
|
+
* finalWidth and finalHeight are used only by CreateScreenshotUsingRenderTarget, not by CreateScreenshot!
|
|
24
|
+
*/
|
|
25
|
+
finalWidth?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Height of the final screenshot image.
|
|
28
|
+
* If only one of the two values is provided, the other will be calculated based on the camera's aspect ratio.
|
|
29
|
+
* If both finalWidth and finalHeight are not provided, width and height will be used instead
|
|
30
|
+
* finalWidth and finalHeight are used only by CreateScreenshotUsingRenderTarget, not by CreateScreenshot!
|
|
31
|
+
*/
|
|
32
|
+
finalHeight?: number;
|
|
19
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshotSize.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Misc/interfaces/screenshotSize.ts"],"names":[],"mappings":"","sourcesContent":["/**\r\n * Interface for screenshot methods with describe argument called `size` as object with options\r\n * @link https://doc.babylonjs.com/api/classes/babylon.screenshottools\r\n */\r\nexport interface IScreenshotSize {\r\n /**\r\n * number in pixels for canvas height\r\n */\r\n height?: number;\r\n\r\n /**\r\n * multiplier allowing render at a higher or lower resolution\r\n * If value is defined then
|
|
1
|
+
{"version":3,"file":"screenshotSize.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Misc/interfaces/screenshotSize.ts"],"names":[],"mappings":"","sourcesContent":["/**\r\n * Interface for screenshot methods with describe argument called `size` as object with options\r\n * @link https://doc.babylonjs.com/api/classes/babylon.screenshottools\r\n */\r\nexport interface IScreenshotSize {\r\n /**\r\n * number in pixels for canvas height. It is the height of the texture used to render the scene\r\n */\r\n height?: number;\r\n\r\n /**\r\n * multiplier allowing render at a higher or lower resolution\r\n * If value is defined then width and height will be multiplied by this value\r\n */\r\n precision?: number;\r\n\r\n /**\r\n * number in pixels for canvas width. It is the width of the texture used to render the scene\r\n */\r\n width?: number;\r\n\r\n /**\r\n * Width of the final screenshot image.\r\n * If only one of the two values is provided, the other will be calculated based on the camera's aspect ratio.\r\n * If both finalWidth and finalHeight are not provided, width and height will be used instead.\r\n * finalWidth and finalHeight are used only by CreateScreenshotUsingRenderTarget, not by CreateScreenshot!\r\n */\r\n finalWidth?: number;\r\n\r\n /**\r\n * Height of the final screenshot image.\r\n * If only one of the two values is provided, the other will be calculated based on the camera's aspect ratio.\r\n * If both finalWidth and finalHeight are not provided, width and height will be used instead\r\n * finalWidth and finalHeight are used only by CreateScreenshotUsingRenderTarget, not by CreateScreenshot!\r\n */\r\n finalHeight?: number;\r\n}\r\n"]}
|
package/Misc/sceneRecorder.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sceneRecorder.js","sourceRoot":"","sources":["../../../../lts/core/generated/Misc/sceneRecorder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,M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MAAM,CAAC,MAAM,CAAC,CAAC;aAClB;SACJ;IACL,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { SceneSerializer } from \"./sceneSerializer\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { Light } from \"../Lights/light\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport { Skeleton } from \"../Bones/skeleton\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { MultiMaterial } from \"../Materials/multiMaterial\";\r\nimport { TransformNode } from \"../Meshes/transformNode\";\r\nimport { ParticleSystem } from \"../Particles/particleSystem\";\r\nimport { MorphTargetManager } from \"../Morph/morphTargetManager\";\r\nimport { ShadowGenerator } from \"../Lights/Shadows/shadowGenerator\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { SerializationHelper } from \"./decorators\";\r\n\r\n/**\r\n * Class used to record delta files between 2 scene states\r\n */\r\nexport class SceneRecorder {\r\n private _trackedScene: Nullable<Scene> = null;\r\n private _savedJSON: any;\r\n\r\n /**\r\n * Track a given scene. This means the current scene state will be considered the original state\r\n * @param scene defines the scene to track\r\n */\r\n public track(scene: Scene) {\r\n this._trackedScene = scene;\r\n\r\n SerializationHelper.AllowLoadingUniqueId = true;\r\n this._savedJSON = SceneSerializer.Serialize(scene);\r\n SerializationHelper.AllowLoadingUniqueId = false;\r\n }\r\n\r\n /**\r\n * Get the delta between current state and original state\r\n * @returns a any containing the delta\r\n */\r\n public getDelta(): any {\r\n if (!this._trackedScene) {\r\n return null;\r\n }\r\n\r\n const currentForceSerializeBuffers = Texture.ForceSerializeBuffers;\r\n Texture.ForceSerializeBuffers = false;\r\n\r\n SerializationHelper.AllowLoadingUniqueId = true;\r\n const newJSON = SceneSerializer.Serialize(this._trackedScene);\r\n SerializationHelper.AllowLoadingUniqueId = false;\r\n const deltaJSON: any = {};\r\n\r\n for (const node in newJSON) {\r\n this._compareCollections(node, this._savedJSON[node], newJSON[node], deltaJSON);\r\n }\r\n\r\n Texture.ForceSerializeBuffers = currentForceSerializeBuffers;\r\n\r\n return deltaJSON;\r\n }\r\n\r\n private _compareArray(key: string, original: any[], current: any[], deltaJSON: any) {\r\n if (original.length === 0 && current.length === 0) {\r\n return true;\r\n }\r\n\r\n // Numbers?\r\n if ((original.length && !isNaN(original[0])) || (current.length && !isNaN(current[0]))) {\r\n if (original.length !== current.length) {\r\n return false;\r\n }\r\n\r\n if (original.length === 0) {\r\n return true;\r\n }\r\n for (let index = 0; index < original.length; index++) {\r\n if (original[index] !== current[index]) {\r\n deltaJSON[key] = current;\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n // let's use uniqueId to find similar objects\r\n const originalUniqueIds: number[] = [];\r\n for (let index = 0; index < original.length; index++) {\r\n const originalObject = original[index];\r\n const originalUniqueId = originalObject.uniqueId;\r\n\r\n originalUniqueIds.push(originalUniqueId);\r\n // Look for that object in current state\r\n const currentObjects = current.filter((c) => c.uniqueId === originalUniqueId);\r\n if (currentObjects.length) {\r\n // We have a candidate\r\n const currentObject = currentObjects[0];\r\n\r\n const newObject: any = {};\r\n if (!this._compareObjects(originalObject, currentObject, newObject)) {\r\n if (!deltaJSON[key]) {\r\n deltaJSON[key] = [];\r\n }\r\n newObject.__state = {\r\n id: currentObject.id || currentObject.name,\r\n };\r\n deltaJSON[key].push(newObject);\r\n }\r\n } else {\r\n // We need to delete\r\n const newObject: any = {\r\n __state: {\r\n deleteId: originalObject.id || originalObject.name,\r\n },\r\n };\r\n deltaJSON[key].push(newObject);\r\n }\r\n }\r\n\r\n // Checking for new objects\r\n for (let index = 0; index < current.length; index++) {\r\n const currentObject = current[index];\r\n const currentUniqueId = currentObject.uniqueId;\r\n\r\n // Object was added\r\n if (originalUniqueIds.indexOf(currentUniqueId) === -1) {\r\n if (!deltaJSON[key]) {\r\n deltaJSON[key] = [];\r\n }\r\n\r\n deltaJSON[key].push(currentObject);\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n private _compareObjects(originalObjet: any, currentObject: any, deltaJSON: any) {\r\n let aDifferenceWasFound = false;\r\n\r\n for (const prop in originalObjet) {\r\n if (!Object.prototype.hasOwnProperty.call(originalObjet, prop)) {\r\n continue;\r\n }\r\n const originalValue = originalObjet[prop];\r\n const currentValue = currentObject[prop];\r\n let diffFound = false;\r\n\r\n if (Array.isArray(originalValue)) {\r\n diffFound = JSON.stringify(originalValue) !== JSON.stringify(currentValue);\r\n } else if (!isNaN(originalValue) || Object.prototype.toString.call(originalValue) == \"[object String]\") {\r\n diffFound = originalValue !== currentValue;\r\n } else if (typeof originalValue === \"object\" && typeof currentValue === \"object\") {\r\n const newObject = {};\r\n if (!this._compareObjects(originalValue, currentValue, newObject)) {\r\n deltaJSON[prop] = newObject;\r\n aDifferenceWasFound = true;\r\n }\r\n }\r\n\r\n if (diffFound) {\r\n aDifferenceWasFound = true;\r\n deltaJSON[prop] = currentValue;\r\n }\r\n }\r\n\r\n return !aDifferenceWasFound;\r\n }\r\n\r\n private _compareCollections(key: string, original: any[], current: any[], deltaJSON: any) {\r\n // Same ?\r\n if (original === current) {\r\n return;\r\n }\r\n\r\n if (original && current) {\r\n // Array?\r\n if (Array.isArray(original) && Array.isArray(current)) {\r\n if (this._compareArray(key, original, current, deltaJSON)) {\r\n return;\r\n }\r\n } else if (typeof original === \"object\" && typeof current === \"object\") {\r\n // Object\r\n const newObject = {};\r\n if (!this._compareObjects(original, current, newObject)) {\r\n deltaJSON[key] = newObject;\r\n }\r\n return;\r\n }\r\n }\r\n }\r\n\r\n private static GetShadowGeneratorById(scene: Scene, id: string) {\r\n const allGenerators = scene.lights.map((l) => l.getShadowGenerators());\r\n\r\n for (const generators of allGenerators) {\r\n if (generators) {\r\n const iterator = generators.values();\r\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\r\n const generator = key.value;\r\n if (generator && generator.id === id) {\r\n return generator;\r\n }\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Apply a given delta to a given scene\r\n * @param deltaJSON defines the JSON containing the delta\r\n * @param scene defines the scene to apply the delta to\r\n */\r\n public static ApplyDelta(deltaJSON: any | string, scene: Scene) {\r\n if (typeof deltaJSON === \"string\") {\r\n deltaJSON = JSON.parse(deltaJSON);\r\n }\r\n\r\n // Scene\r\n const anyScene = scene as any;\r\n for (const prop in deltaJSON) {\r\n const source = deltaJSON[prop];\r\n const property = anyScene[prop];\r\n\r\n if (Array.isArray(property) || prop === \"shadowGenerators\") {\r\n // Restore array\r\n switch (prop) {\r\n case \"cameras\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getCameraById.bind(scene), (data) => Camera.Parse(data, scene));\r\n break;\r\n case \"lights\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getLightById.bind(scene), (data) => Light.Parse(data, scene));\r\n break;\r\n case \"shadowGenerators\":\r\n this._ApplyDeltaForEntity(\r\n source,\r\n scene,\r\n (id) => this.GetShadowGeneratorById(scene, id),\r\n (data) => ShadowGenerator.Parse(data, scene)\r\n );\r\n break;\r\n case \"meshes\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMeshById.bind(scene), (data) => Mesh.Parse(data, scene, \"\"));\r\n break;\r\n case \"skeletons\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getSkeletonById.bind(scene), (data) => Skeleton.Parse(data, scene));\r\n break;\r\n case \"materials\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMaterialById.bind(scene), (data) => Material.Parse(data, scene, \"\"));\r\n break;\r\n case \"multiMaterials\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMaterialById.bind(scene), (data) => MultiMaterial.Parse(data, scene, \"\"));\r\n break;\r\n case \"transformNodes\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getTransformNodeById.bind(scene), (data) => TransformNode.Parse(data, scene, \"\"));\r\n break;\r\n case \"particleSystems\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getParticleSystemById.bind(scene), (data) => ParticleSystem.Parse(data, scene, \"\"));\r\n break;\r\n case \"morphTargetManagers\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMorphTargetById.bind(scene), (data) => MorphTargetManager.Parse(data, scene));\r\n break;\r\n case \"postProcesses\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getPostProcessByName.bind(scene), (data) => PostProcess.Parse(data, scene, \"\"));\r\n break;\r\n }\r\n } else if (!isNaN(property)) {\r\n anyScene[prop] = source;\r\n } else if (property.fromArray) {\r\n property.fromArray(source);\r\n }\r\n }\r\n }\r\n\r\n private static _ApplyPropertiesToEntity(deltaJSON: any, entity: any) {\r\n for (const prop in deltaJSON) {\r\n const source = deltaJSON[prop];\r\n const property = entity[prop];\r\n\r\n if (property === undefined) {\r\n continue;\r\n }\r\n\r\n if (!isNaN(property) || Array.isArray(property)) {\r\n entity[prop] = source;\r\n } else if (property.fromArray) {\r\n property.fromArray(source);\r\n } else if (typeof property === \"object\" && property !== null) {\r\n this._ApplyPropertiesToEntity(source, property);\r\n }\r\n }\r\n }\r\n\r\n private static _ApplyDeltaForEntity(sources: any[], scene: Scene, finder: (id: string) => any, addNew: (data: any) => void) {\r\n for (const source of sources) {\r\n // Update\r\n if (source.__state && source.__state.id !== undefined) {\r\n const targetEntity = finder(source.__state.id);\r\n\r\n if (targetEntity) {\r\n // This first pass applies properties that aren't on the serialization list\r\n this._ApplyPropertiesToEntity(source, targetEntity);\r\n // The second pass applies the serializable properties\r\n SerializationHelper.ParseProperties(source, targetEntity, scene, null);\r\n }\r\n } else if (source.__state && source.__state.deleteId !== undefined) {\r\n const target = finder(source.__state.deleteId);\r\n target?.dispose();\r\n } else {\r\n // New\r\n addNew(source);\r\n }\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"sceneRecorder.js","sourceRoot":"","sources":["../../../../lts/core/generated/Misc/sceneRecorder.ts"],"names":[],"mappings":"AAGA,OAAO,EA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AE,KAAY,EAAE,MAA2B,EAAE,MAA2B;QACtH,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;YAC1B,SAAS;YACT,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,SAAS,EAAE;gBACnD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBAE/C,IAAI,YAAY,EAAE;oBACd,2EAA2E;oBAC3E,IAAI,CAAC,wBAAwB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;oBACpD,sDAAsD;oBACtD,mBAAmB,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;iBAC1E;aACJ;iBAAM,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE;gBAChE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAC/C,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EAAE,CAAC;aACrB;iBAAM;gBACH,MAAM;gBACN,MAAM,CAAC,MAAM,CAAC,CAAC;aAClB;SACJ;IACL,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { SceneSerializer } from \"./sceneSerializer\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { Light } from \"../Lights/light\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport { Skeleton } from \"../Bones/skeleton\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { MultiMaterial } from \"../Materials/multiMaterial\";\r\nimport { TransformNode } from \"../Meshes/transformNode\";\r\nimport { ParticleSystem } from \"../Particles/particleSystem\";\r\nimport { MorphTargetManager } from \"../Morph/morphTargetManager\";\r\nimport { ShadowGenerator } from \"../Lights/Shadows/shadowGenerator\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { SerializationHelper } from \"./decorators\";\r\n\r\n/**\r\n * Class used to record delta files between 2 scene states\r\n */\r\nexport class SceneRecorder {\r\n private _trackedScene: Nullable<Scene> = null;\r\n private _savedJSON: any;\r\n\r\n /**\r\n * Track a given scene. This means the current scene state will be considered the original state\r\n * @param scene defines the scene to track\r\n */\r\n public track(scene: Scene) {\r\n this._trackedScene = scene;\r\n\r\n SerializationHelper.AllowLoadingUniqueId = true;\r\n this._savedJSON = SceneSerializer.Serialize(scene);\r\n SerializationHelper.AllowLoadingUniqueId = false;\r\n }\r\n\r\n /**\r\n * Get the delta between current state and original state\r\n * @returns a any containing the delta\r\n */\r\n public getDelta(): any {\r\n if (!this._trackedScene) {\r\n return null;\r\n }\r\n\r\n const currentForceSerializeBuffers = Texture.ForceSerializeBuffers;\r\n Texture.ForceSerializeBuffers = false;\r\n\r\n SerializationHelper.AllowLoadingUniqueId = true;\r\n const newJSON = SceneSerializer.Serialize(this._trackedScene);\r\n SerializationHelper.AllowLoadingUniqueId = false;\r\n const deltaJSON: any = {};\r\n\r\n for (const node in newJSON) {\r\n this._compareCollections(node, this._savedJSON[node], newJSON[node], deltaJSON);\r\n }\r\n\r\n Texture.ForceSerializeBuffers = currentForceSerializeBuffers;\r\n\r\n return deltaJSON;\r\n }\r\n\r\n private _compareArray(key: string, original: any[], current: any[], deltaJSON: any) {\r\n if (original.length === 0 && current.length === 0) {\r\n return true;\r\n }\r\n\r\n // Numbers?\r\n if ((original.length && !isNaN(original[0])) || (current.length && !isNaN(current[0]))) {\r\n if (original.length !== current.length) {\r\n return false;\r\n }\r\n\r\n if (original.length === 0) {\r\n return true;\r\n }\r\n for (let index = 0; index < original.length; index++) {\r\n if (original[index] !== current[index]) {\r\n deltaJSON[key] = current;\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n // let's use uniqueId to find similar objects\r\n const originalUniqueIds: number[] = [];\r\n for (let index = 0; index < original.length; index++) {\r\n const originalObject = original[index];\r\n const originalUniqueId = originalObject.uniqueId;\r\n\r\n originalUniqueIds.push(originalUniqueId);\r\n // Look for that object in current state\r\n const currentObjects = current.filter((c) => c.uniqueId === originalUniqueId);\r\n if (currentObjects.length) {\r\n // We have a candidate\r\n const currentObject = currentObjects[0];\r\n\r\n const newObject: any = {};\r\n if (!this._compareObjects(originalObject, currentObject, newObject)) {\r\n if (!deltaJSON[key]) {\r\n deltaJSON[key] = [];\r\n }\r\n newObject.__state = {\r\n id: currentObject.id || currentObject.name,\r\n };\r\n deltaJSON[key].push(newObject);\r\n }\r\n } else {\r\n // We need to delete\r\n const newObject: any = {\r\n __state: {\r\n deleteId: originalObject.id || originalObject.name,\r\n },\r\n };\r\n if (!deltaJSON[key]) {\r\n deltaJSON[key] = [];\r\n }\r\n deltaJSON[key].push(newObject);\r\n }\r\n }\r\n\r\n // Checking for new objects\r\n for (let index = 0; index < current.length; index++) {\r\n const currentObject = current[index];\r\n const currentUniqueId = currentObject.uniqueId;\r\n\r\n // Object was added\r\n if (originalUniqueIds.indexOf(currentUniqueId) === -1) {\r\n if (!deltaJSON[key]) {\r\n deltaJSON[key] = [];\r\n }\r\n\r\n deltaJSON[key].push(currentObject);\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n private _compareObjects(originalObjet: any, currentObject: any, deltaJSON: any) {\r\n let aDifferenceWasFound = false;\r\n\r\n for (const prop in originalObjet) {\r\n if (!Object.prototype.hasOwnProperty.call(originalObjet, prop)) {\r\n continue;\r\n }\r\n const originalValue = originalObjet[prop];\r\n const currentValue = currentObject[prop];\r\n let diffFound = false;\r\n\r\n if (Array.isArray(originalValue)) {\r\n diffFound = JSON.stringify(originalValue) !== JSON.stringify(currentValue);\r\n } else if (!isNaN(originalValue) || Object.prototype.toString.call(originalValue) == \"[object String]\") {\r\n diffFound = originalValue !== currentValue;\r\n } else if (typeof originalValue === \"object\" && typeof currentValue === \"object\") {\r\n const newObject = {};\r\n if (!this._compareObjects(originalValue, currentValue, newObject)) {\r\n deltaJSON[prop] = newObject;\r\n aDifferenceWasFound = true;\r\n }\r\n }\r\n\r\n if (diffFound) {\r\n aDifferenceWasFound = true;\r\n deltaJSON[prop] = currentValue;\r\n }\r\n }\r\n\r\n return !aDifferenceWasFound;\r\n }\r\n\r\n private _compareCollections(key: string, original: any[], current: any[], deltaJSON: any) {\r\n // Same ?\r\n if (original === current) {\r\n return;\r\n }\r\n\r\n if (original && current) {\r\n // Array?\r\n if (Array.isArray(original) && Array.isArray(current)) {\r\n if (this._compareArray(key, original, current, deltaJSON)) {\r\n return;\r\n }\r\n } else if (typeof original === \"object\" && typeof current === \"object\") {\r\n // Object\r\n const newObject = {};\r\n if (!this._compareObjects(original, current, newObject)) {\r\n deltaJSON[key] = newObject;\r\n }\r\n return;\r\n }\r\n }\r\n }\r\n\r\n private static GetShadowGeneratorById(scene: Scene, id: string) {\r\n const allGenerators = scene.lights.map((l) => l.getShadowGenerators());\r\n\r\n for (const generators of allGenerators) {\r\n if (generators) {\r\n const iterator = generators.values();\r\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\r\n const generator = key.value;\r\n if (generator && generator.id === id) {\r\n return generator;\r\n }\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Apply a given delta to a given scene\r\n * @param deltaJSON defines the JSON containing the delta\r\n * @param scene defines the scene to apply the delta to\r\n */\r\n public static ApplyDelta(deltaJSON: any | string, scene: Scene) {\r\n if (typeof deltaJSON === \"string\") {\r\n deltaJSON = JSON.parse(deltaJSON);\r\n }\r\n\r\n // Scene\r\n const anyScene = scene as any;\r\n for (const prop in deltaJSON) {\r\n const source = deltaJSON[prop];\r\n const property = anyScene[prop];\r\n\r\n if (Array.isArray(property) || prop === \"shadowGenerators\") {\r\n // Restore array\r\n switch (prop) {\r\n case \"cameras\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getCameraById.bind(scene), (data) => Camera.Parse(data, scene));\r\n break;\r\n case \"lights\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getLightById.bind(scene), (data) => Light.Parse(data, scene));\r\n break;\r\n case \"shadowGenerators\":\r\n this._ApplyDeltaForEntity(\r\n source,\r\n scene,\r\n (id) => this.GetShadowGeneratorById(scene, id),\r\n (data) => ShadowGenerator.Parse(data, scene)\r\n );\r\n break;\r\n case \"meshes\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMeshById.bind(scene), (data) => Mesh.Parse(data, scene, \"\"));\r\n break;\r\n case \"skeletons\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getSkeletonById.bind(scene), (data) => Skeleton.Parse(data, scene));\r\n break;\r\n case \"materials\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMaterialById.bind(scene), (data) => Material.Parse(data, scene, \"\"));\r\n break;\r\n case \"multiMaterials\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMaterialById.bind(scene), (data) => MultiMaterial.Parse(data, scene, \"\"));\r\n break;\r\n case \"transformNodes\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getTransformNodeById.bind(scene), (data) => TransformNode.Parse(data, scene, \"\"));\r\n break;\r\n case \"particleSystems\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getParticleSystemById.bind(scene), (data) => ParticleSystem.Parse(data, scene, \"\"));\r\n break;\r\n case \"morphTargetManagers\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMorphTargetById.bind(scene), (data) => MorphTargetManager.Parse(data, scene));\r\n break;\r\n case \"postProcesses\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getPostProcessByName.bind(scene), (data) => PostProcess.Parse(data, scene, \"\"));\r\n break;\r\n }\r\n } else if (!isNaN(property)) {\r\n anyScene[prop] = source;\r\n } else if (property.fromArray) {\r\n property.fromArray(source);\r\n }\r\n }\r\n }\r\n\r\n private static _ApplyPropertiesToEntity(deltaJSON: any, entity: any) {\r\n for (const prop in deltaJSON) {\r\n const source = deltaJSON[prop];\r\n const property = entity[prop];\r\n\r\n if (property === undefined) {\r\n continue;\r\n }\r\n\r\n if (!isNaN(property) || Array.isArray(property)) {\r\n entity[prop] = source;\r\n } else if (property.fromArray) {\r\n property.fromArray(source);\r\n } else if (typeof property === \"object\" && property !== null) {\r\n this._ApplyPropertiesToEntity(source, property);\r\n }\r\n }\r\n }\r\n\r\n private static _ApplyDeltaForEntity(sources: any[], scene: Scene, finder: (id: string) => any, addNew: (data: any) => void) {\r\n for (const source of sources) {\r\n // Update\r\n if (source.__state && source.__state.id !== undefined) {\r\n const targetEntity = finder(source.__state.id);\r\n\r\n if (targetEntity) {\r\n // This first pass applies properties that aren't on the serialization list\r\n this._ApplyPropertiesToEntity(source, targetEntity);\r\n // The second pass applies the serializable properties\r\n SerializationHelper.ParseProperties(source, targetEntity, scene, null);\r\n }\r\n } else if (source.__state && source.__state.deleteId !== undefined) {\r\n const target = finder(source.__state.deleteId);\r\n target?.dispose();\r\n } else {\r\n // New\r\n addNew(source);\r\n }\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -54,8 +54,8 @@ export declare function CreateScreenshotWithResizeAsync(engine: Engine, camera:
|
|
|
54
54
|
* @param engine The engine to use for rendering
|
|
55
55
|
* @param camera The camera to use for rendering
|
|
56
56
|
* @param size This parameter can be set to a single number or to an object with the
|
|
57
|
-
* following (optional) properties: precision, width, height. If a single number is passed,
|
|
58
|
-
* it will be used for both width and height. If an object is passed, the screenshot size
|
|
57
|
+
* following (optional) properties: precision, width, height, finalWidth, finalHeight. If a single number is passed,
|
|
58
|
+
* it will be used for both width and height, as well as finalWidth, finalHeight. If an object is passed, the screenshot size
|
|
59
59
|
* will be derived from the parameters. The precision property is a multiplier allowing
|
|
60
60
|
* rendering at a higher or lower resolution
|
|
61
61
|
* @param successCallback The callback receives a single parameter which contains the
|
package/Misc/screenshotTools.js
CHANGED
|
@@ -5,6 +5,7 @@ import { FxaaPostProcess } from "../PostProcesses/fxaaPostProcess.js";
|
|
|
5
5
|
import { Logger } from "./logger.js";
|
|
6
6
|
import { Tools } from "./tools.js";
|
|
7
7
|
import { DumpTools } from "./dumpTools.js";
|
|
8
|
+
import { ApplyPostProcess } from "./textureTools.js";
|
|
8
9
|
let screenshotCanvas = null;
|
|
9
10
|
/**
|
|
10
11
|
* Captures a screenshot of the current rendering
|
|
@@ -131,8 +132,8 @@ export function CreateScreenshotWithResizeAsync(engine, camera, width, height, m
|
|
|
131
132
|
* @param engine The engine to use for rendering
|
|
132
133
|
* @param camera The camera to use for rendering
|
|
133
134
|
* @param size This parameter can be set to a single number or to an object with the
|
|
134
|
-
* following (optional) properties: precision, width, height. If a single number is passed,
|
|
135
|
-
* it will be used for both width and height. If an object is passed, the screenshot size
|
|
135
|
+
* following (optional) properties: precision, width, height, finalWidth, finalHeight. If a single number is passed,
|
|
136
|
+
* it will be used for both width and height, as well as finalWidth, finalHeight. If an object is passed, the screenshot size
|
|
136
137
|
* will be derived from the parameters. The precision property is a multiplier allowing
|
|
137
138
|
* rendering at a higher or lower resolution
|
|
138
139
|
* @param successCallback The callback receives a single parameter which contains the
|
|
@@ -148,7 +149,7 @@ export function CreateScreenshotWithResizeAsync(engine, camera, width, height, m
|
|
|
148
149
|
* @param useLayerMask if the camera's layer mask should be used to filter what should be rendered (default: true)
|
|
149
150
|
*/
|
|
150
151
|
export function CreateScreenshotUsingRenderTarget(engine, camera, size, successCallback, mimeType = "image/png", samples = 1, antialiasing = false, fileName, renderSprites = false, enableStencilBuffer = false, useLayerMask = true) {
|
|
151
|
-
const { height, width } = _GetScreenshotSize(engine, camera, size);
|
|
152
|
+
const { height, width, finalWidth, finalHeight } = _GetScreenshotSize(engine, camera, size);
|
|
152
153
|
const targetTextureSize = { width, height };
|
|
153
154
|
if (!(height && width)) {
|
|
154
155
|
Logger.Error("Invalid 'size' parameter !");
|
|
@@ -158,7 +159,7 @@ export function CreateScreenshotUsingRenderTarget(engine, camera, size, successC
|
|
|
158
159
|
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
|
|
159
160
|
const scene = camera.getScene();
|
|
160
161
|
// At this point size can be a number, or an object (according to engine.prototype.createRenderTargetTexture method)
|
|
161
|
-
const texture = new RenderTargetTexture("screenShot", targetTextureSize, scene, false, false, 0, false, Texture.
|
|
162
|
+
const texture = new RenderTargetTexture("screenShot", targetTextureSize, scene, false, false, 0, false, Texture.BILINEAR_SAMPLINGMODE, undefined, enableStencilBuffer, undefined, undefined, undefined, samples);
|
|
162
163
|
texture.renderList = scene.meshes.slice();
|
|
163
164
|
texture.samples = samples;
|
|
164
165
|
texture.renderSprites = renderSprites;
|
|
@@ -166,10 +167,20 @@ export function CreateScreenshotUsingRenderTarget(engine, camera, size, successC
|
|
|
166
167
|
texture.forceLayerMaskCheck = useLayerMask;
|
|
167
168
|
const renderToTexture = () => {
|
|
168
169
|
engine.onEndFrameObservable.addOnce(() => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
if (finalWidth === width && finalHeight === height) {
|
|
171
|
+
texture.readPixels(undefined, undefined, undefined, false).then((data) => {
|
|
172
|
+
DumpTools.DumpData(width, height, data, successCallback, mimeType, fileName, true);
|
|
173
|
+
texture.dispose();
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
ApplyPostProcess("pass", texture.getInternalTexture(), scene, undefined, undefined, undefined, finalWidth, finalHeight).then((texture) => {
|
|
178
|
+
engine._readTexturePixels(texture, finalWidth, finalHeight, -1, 0, null, true, false, 0, 0).then((data) => {
|
|
179
|
+
DumpTools.DumpData(finalWidth, finalHeight, data, successCallback, mimeType, fileName, true);
|
|
180
|
+
texture.dispose();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
173
184
|
});
|
|
174
185
|
// render the RTT
|
|
175
186
|
scene.incrementRenderId();
|
|
@@ -245,6 +256,8 @@ export function CreateScreenshotUsingRenderTargetAsync(engine, camera, size, mim
|
|
|
245
256
|
function _GetScreenshotSize(engine, camera, size) {
|
|
246
257
|
let height = 0;
|
|
247
258
|
let width = 0;
|
|
259
|
+
let finalWidth = 0;
|
|
260
|
+
let finalHeight = 0;
|
|
248
261
|
//If a size value defined as object
|
|
249
262
|
if (typeof size === "object") {
|
|
250
263
|
const precision = size.precision
|
|
@@ -269,11 +282,32 @@ function _GetScreenshotSize(engine, camera, size) {
|
|
|
269
282
|
width = Math.round(engine.getRenderWidth() * precision);
|
|
270
283
|
height = Math.round(width / engine.getAspectRatio(camera));
|
|
271
284
|
}
|
|
285
|
+
//If a finalWidth and finalHeight values is specified
|
|
286
|
+
if (size.finalWidth && size.finalHeight) {
|
|
287
|
+
finalHeight = size.finalHeight;
|
|
288
|
+
finalWidth = size.finalWidth;
|
|
289
|
+
}
|
|
290
|
+
//If passing only finalWidth, computing finalHeight to keep display canvas ratio.
|
|
291
|
+
else if (size.finalWidth && !size.finalHeight) {
|
|
292
|
+
finalWidth = size.finalWidth;
|
|
293
|
+
finalHeight = Math.round(finalWidth / engine.getAspectRatio(camera));
|
|
294
|
+
}
|
|
295
|
+
//If passing only finalHeight, computing finalWidth to keep display canvas ratio.
|
|
296
|
+
else if (size.finalHeight && !size.finalWidth) {
|
|
297
|
+
finalHeight = size.finalHeight;
|
|
298
|
+
finalWidth = Math.round(finalHeight * engine.getAspectRatio(camera));
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
finalWidth = width;
|
|
302
|
+
finalHeight = height;
|
|
303
|
+
}
|
|
272
304
|
}
|
|
273
305
|
//Assuming here that "size" parameter is a number
|
|
274
306
|
else if (!isNaN(size)) {
|
|
275
307
|
height = size;
|
|
276
308
|
width = size;
|
|
309
|
+
finalWidth = size;
|
|
310
|
+
finalHeight = size;
|
|
277
311
|
}
|
|
278
312
|
// When creating the image data from the CanvasRenderingContext2D, the width and height is clamped to the size of the _gl context
|
|
279
313
|
// 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
|
|
@@ -285,7 +319,13 @@ function _GetScreenshotSize(engine, camera, size) {
|
|
|
285
319
|
if (height) {
|
|
286
320
|
height = Math.floor(height);
|
|
287
321
|
}
|
|
288
|
-
|
|
322
|
+
if (finalWidth) {
|
|
323
|
+
finalWidth = Math.floor(finalWidth);
|
|
324
|
+
}
|
|
325
|
+
if (finalHeight) {
|
|
326
|
+
finalHeight = Math.floor(finalHeight);
|
|
327
|
+
}
|
|
328
|
+
return { height: height | 0, width: width | 0, finalWidth: finalWidth | 0, finalHeight: finalHeight | 0 };
|
|
289
329
|
}
|
|
290
330
|
/**
|
|
291
331
|
* Class containing a set of static utilities functions for screenshots
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshotTools.js","sourceRoot":"","sources":["../../../../lts/core/generated/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,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAKxC,IAAI,gBAAgB,GAAgC,IAAI,CAAC;AAEzD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAC5B,MAAc,EACd,MAAc,EACd,IAA8B,EAC9B,eAAwC,EACxC,WAAmB,WAAW,EAC9B,aAAa,GAAG,KAAK;IAErB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAEnE,IAAI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KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;SAC9D;KACJ;IACD,iDAAiD;SAC5C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;QACnB,MAAM,GAAG,IAAI,CAAC;QACd,KAAK,GAAG,IAAI,CAAC;KAChB;IAED,iIAAiI;IACjI,8JAA8J;IAC9J,0IAA0I;IAC1I,uEAAuE;IACvE,IAAI,KAAK,EAAE;QACP,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;KAC7B;IACD,IAAI,MAAM,EAAE;QACR,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;KAC/B;IAED,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC3B;;;;;;;;;;;;;;;;OAgBG;IACH,gBAAgB;IAEhB;;;;;;;;;;;;;;OAcG;IACH,qBAAqB;IAErB;;;;;;;;;;;OAWG;IACH,+BAA+B;IAE/B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,iCAAiC;IAEjC;;;;;;;;;;;;;;;;;;OAkBG;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 { DumpTools } from \"./dumpTools\";\r\nimport type { Nullable } from \"../types\";\r\n\r\ndeclare type Engine = import(\"../Engines/engine\").Engine;\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 */\r\nexport function CreateScreenshot(\r\n engine: Engine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n successCallback?: (data: string) => void,\r\n mimeType: string = \"image/png\",\r\n forceDownload = 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 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,\r\n engine.getCreationOptions().antialias\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);\r\n if (successCallback) {\r\n successCallback(\"\");\r\n }\r\n } else {\r\n Tools.EncodeScreenshotCanvasData(screenshotCanvas, successCallback, mimeType);\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 * @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: Engine, camera: Camera, size: IScreenshotSize | number, mimeType: string = \"image/png\"): 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 );\r\n });\r\n}\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 * @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 CreateScreenshotWithResizeAsync(engine: Engine, camera: Camera, width: number, height: number, mimeType: string = \"image/png\"): 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 );\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 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 */\r\nexport function CreateScreenshotUsingRenderTarget(\r\n engine: Engine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n successCallback?: (data: string) => void,\r\n mimeType: string = \"image/png\",\r\n samples: number = 1,\r\n antialiasing: boolean = false,\r\n fileName?: string,\r\n renderSprites: boolean = false,\r\n enableStencilBuffer: boolean = false,\r\n useLayerMask: boolean = true\r\n): void {\r\n const { height, width } = _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_INT,\r\n false,\r\n Texture.NEAREST_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\r\n const renderToTexture = () => {\r\n engine.onEndFrameObservable.addOnce(() => {\r\n texture.readPixels(undefined, undefined, undefined, false)!.then((data) => {\r\n DumpTools.DumpData(width, height, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true);\r\n texture.dispose();\r\n });\r\n });\r\n\r\n // render the RTT\r\n scene.incrementRenderId();\r\n scene.resetCachedMaterial();\r\n texture.render(true);\r\n\r\n // re-render the scene after the camera has been reset to the original camera to avoid a flicker that could occur\r\n // if the camera used for the RTT rendering stays in effect for the next frame (and if that camera was different from the original camera)\r\n scene.incrementRenderId();\r\n scene.resetCachedMaterial();\r\n engine.setSize(originalSize.width, originalSize.height);\r\n camera.getProjectionMatrix(true); // Force cache refresh;\r\n scene.render();\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 if (!fxaaPostProcess.getEffect().isReady()) {\r\n fxaaPostProcess.getEffect().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 } 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 * @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: Engine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n mimeType: string = \"image/png\",\r\n samples: number = 1,\r\n antialiasing: boolean = false,\r\n fileName?: string,\r\n renderSprites: boolean = false,\r\n enableStencilBuffer: boolean = false,\r\n useLayerMask: boolean = true\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 );\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: Engine, camera: Camera, size: IScreenshotSize | number): { height: number; width: number } {\r\n let height = 0;\r\n let width = 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 //Assuming here that \"size\" parameter is a number\r\n else if (!isNaN(size)) {\r\n height = size;\r\n width = 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\r\n return { height: height | 0, width: width | 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 */\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 * @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 * @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 */\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 * @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":["../../../../lts/core/generated/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,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;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WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;KACzC;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;;;;;;;;;;;;;;;;OAgBG;IACH,gBAAgB;IAEhB;;;;;;;;;;;;;;OAcG;IACH,qBAAqB;IAErB;;;;;;;;;;;OAWG;IACH,+BAA+B;IAE/B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,iCAAiC;IAEjC;;;;;;;;;;;;;;;;;;OAkBG;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 { DumpTools } from \"./dumpTools\";\r\nimport type { Nullable } from \"../types\";\r\nimport { ApplyPostProcess } from \"./textureTools\";\r\n\r\ndeclare type Engine = import(\"../Engines/engine\").Engine;\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 */\r\nexport function CreateScreenshot(\r\n engine: Engine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n successCallback?: (data: string) => void,\r\n mimeType: string = \"image/png\",\r\n forceDownload = 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 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,\r\n engine.getCreationOptions().antialias\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);\r\n if (successCallback) {\r\n successCallback(\"\");\r\n }\r\n } else {\r\n Tools.EncodeScreenshotCanvasData(screenshotCanvas, successCallback, mimeType);\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 * @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: Engine, camera: Camera, size: IScreenshotSize | number, mimeType: string = \"image/png\"): 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 );\r\n });\r\n}\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 * @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 CreateScreenshotWithResizeAsync(engine: Engine, camera: Camera, width: number, height: number, mimeType: string = \"image/png\"): 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 );\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 */\r\nexport function CreateScreenshotUsingRenderTarget(\r\n engine: Engine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n successCallback?: (data: string) => void,\r\n mimeType: string = \"image/png\",\r\n samples: number = 1,\r\n antialiasing: boolean = false,\r\n fileName?: string,\r\n renderSprites: boolean = false,\r\n enableStencilBuffer: boolean = false,\r\n useLayerMask: boolean = true\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_INT,\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\r\n const renderToTexture = () => {\r\n engine.onEndFrameObservable.addOnce(() => {\r\n if (finalWidth === width && finalHeight === height) {\r\n texture.readPixels(undefined, undefined, undefined, false)!.then((data) => {\r\n DumpTools.DumpData(width, height, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true);\r\n texture.dispose();\r\n });\r\n } else {\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 DumpTools.DumpData(finalWidth, finalHeight, data, successCallback as (data: string | ArrayBuffer) => void, mimeType, fileName, true);\r\n texture.dispose();\r\n });\r\n });\r\n }\r\n });\r\n\r\n // render the RTT\r\n scene.incrementRenderId();\r\n scene.resetCachedMaterial();\r\n texture.render(true);\r\n\r\n // re-render the scene after the camera has been reset to the original camera to avoid a flicker that could occur\r\n // if the camera used for the RTT rendering stays in effect for the next frame (and if that camera was different from the original camera)\r\n scene.incrementRenderId();\r\n scene.resetCachedMaterial();\r\n engine.setSize(originalSize.width, originalSize.height);\r\n camera.getProjectionMatrix(true); // Force cache refresh;\r\n scene.render();\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 if (!fxaaPostProcess.getEffect().isReady()) {\r\n fxaaPostProcess.getEffect().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 } 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 * @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: Engine,\r\n camera: Camera,\r\n size: IScreenshotSize | number,\r\n mimeType: string = \"image/png\",\r\n samples: number = 1,\r\n antialiasing: boolean = false,\r\n fileName?: string,\r\n renderSprites: boolean = false,\r\n enableStencilBuffer: boolean = false,\r\n useLayerMask: boolean = true\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 );\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: Engine, 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 */\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 * @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 * @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 */\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 * @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/textureTools.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare function CreateResizedCopy(texture: Texture, width: number, heigh
|
|
|
20
20
|
* @param format format of the output texture. If not provided, use the one from internalTexture
|
|
21
21
|
* @returns a promise with the internalTexture having its texture replaced by the result of the processing
|
|
22
22
|
*/
|
|
23
|
-
export declare function ApplyPostProcess(postProcessName: string, internalTexture: InternalTexture, scene: Scene, type?: number, samplingMode?: number, format?: number): Promise<InternalTexture>;
|
|
23
|
+
export declare function ApplyPostProcess(postProcessName: string, internalTexture: InternalTexture, scene: Scene, type?: number, samplingMode?: number, format?: number, width?: number, height?: number): Promise<InternalTexture>;
|
|
24
24
|
/**
|
|
25
25
|
* Converts a number to half float
|
|
26
26
|
* @param value number to convert
|
package/Misc/textureTools.js
CHANGED
|
@@ -57,13 +57,15 @@ export function CreateResizedCopy(texture, width, height, useBilinearMode = true
|
|
|
57
57
|
* @param format format of the output texture. If not provided, use the one from internalTexture
|
|
58
58
|
* @returns a promise with the internalTexture having its texture replaced by the result of the processing
|
|
59
59
|
*/
|
|
60
|
-
export function ApplyPostProcess(postProcessName, internalTexture, scene, type, samplingMode, format) {
|
|
60
|
+
export function ApplyPostProcess(postProcessName, internalTexture, scene, type, samplingMode, format, width, height) {
|
|
61
61
|
// Gets everything ready.
|
|
62
62
|
const engine = internalTexture.getEngine();
|
|
63
63
|
internalTexture.isReady = false;
|
|
64
64
|
samplingMode = samplingMode !== null && samplingMode !== void 0 ? samplingMode : internalTexture.samplingMode;
|
|
65
65
|
type = type !== null && type !== void 0 ? type : internalTexture.type;
|
|
66
66
|
format = format !== null && format !== void 0 ? format : internalTexture.format;
|
|
67
|
+
width = width !== null && width !== void 0 ? width : internalTexture.width;
|
|
68
|
+
height = height !== null && height !== void 0 ? height : internalTexture.height;
|
|
67
69
|
if (type === -1) {
|
|
68
70
|
type = 0;
|
|
69
71
|
}
|
|
@@ -72,7 +74,7 @@ export function ApplyPostProcess(postProcessName, internalTexture, scene, type,
|
|
|
72
74
|
const postProcess = new PostProcess("postprocess", postProcessName, null, null, 1, null, samplingMode, engine, false, undefined, type, undefined, null, false, format);
|
|
73
75
|
postProcess.externalTextureSamplerBinding = true;
|
|
74
76
|
// Hold the output of the decoding.
|
|
75
|
-
const encodedTexture = engine.createRenderTargetTexture({ width:
|
|
77
|
+
const encodedTexture = engine.createRenderTargetTexture({ width: width, height: height }, {
|
|
76
78
|
generateDepthBuffer: false,
|
|
77
79
|
generateMipMaps: false,
|
|
78
80
|
generateStencilBuffer: false,
|
package/Misc/textureTools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textureTools.js","sourceRoot":"","sources":["../../../../lts/core/generated/Misc/textureTools.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,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAG3D;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAAE,KAAa,EAAE,MAAc,EAAE,kBAA2B,IAAI;IAC9G,MAAM,KAAK,GAAU,OAAO,CAAC,QAAQ,EAAE,CAAC;IACxC,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;IAEjC,MAAM,GAAG,GAAG,IAAI,mBAAmB,CAC/B,SAAS,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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB;;;;;;;OAOG;IACH,iBAAiB;IAEjB;;;;;;;;;OASG;IACH,gBAAgB;IAChB;;;;OAIG;IACH,WAAW;IAEX;;;;OAIG;IACH,aAAa;CAChB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { PassPostProcess } from \"../PostProcesses/passPostProcess\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Scene } from \"../scene\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport type { Engine } from \"../Engines/engine\";\r\n\r\n/**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\nexport function CreateResizedCopy(texture: Texture, width: number, height: number, useBilinearMode: boolean = true): Texture {\r\n const scene = <Scene>texture.getScene();\r\n const engine = scene.getEngine();\r\n\r\n const rtt = new RenderTargetTexture(\r\n \"resized\" + texture.name,\r\n { width: width, height: height },\r\n scene,\r\n !texture.noMipmap,\r\n true,\r\n (<InternalTexture>texture._texture).type,\r\n false,\r\n texture.samplingMode,\r\n false\r\n );\r\n\r\n rtt.wrapU = texture.wrapU;\r\n rtt.wrapV = texture.wrapV;\r\n rtt.uOffset = texture.uOffset;\r\n rtt.vOffset = texture.vOffset;\r\n rtt.uScale = texture.uScale;\r\n rtt.vScale = texture.vScale;\r\n rtt.uAng = texture.uAng;\r\n rtt.vAng = texture.vAng;\r\n rtt.wAng = texture.wAng;\r\n rtt.coordinatesIndex = texture.coordinatesIndex;\r\n rtt.level = texture.level;\r\n rtt.anisotropicFilteringLevel = texture.anisotropicFilteringLevel;\r\n (<InternalTexture>rtt._texture).isReady = false;\r\n\r\n texture.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n texture.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n const passPostProcess = new PassPostProcess(\r\n \"pass\",\r\n 1,\r\n null,\r\n useBilinearMode ? Texture.BILINEAR_SAMPLINGMODE : Texture.NEAREST_SAMPLINGMODE,\r\n engine,\r\n false,\r\n Constants.TEXTURETYPE_UNSIGNED_INT\r\n );\r\n passPostProcess.externalTextureSamplerBinding = true;\r\n passPostProcess.getEffect().executeWhenCompiled(() => {\r\n passPostProcess.onApply = function (effect) {\r\n effect.setTexture(\"textureSampler\", texture);\r\n };\r\n\r\n const internalTexture = rtt.renderTarget;\r\n\r\n if (internalTexture) {\r\n scene.postProcessManager.directRender([passPostProcess], internalTexture);\r\n\r\n engine.unBindFramebuffer(internalTexture);\r\n rtt.disposeFramebufferObjects();\r\n passPostProcess.dispose();\r\n\r\n rtt.getInternalTexture()!.isReady = true;\r\n }\r\n });\r\n\r\n return rtt;\r\n}\r\n\r\n/**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\nexport function ApplyPostProcess(\r\n postProcessName: string,\r\n internalTexture: InternalTexture,\r\n scene: Scene,\r\n type?: number,\r\n samplingMode?: number,\r\n format?: number\r\n): Promise<InternalTexture> {\r\n // Gets everything ready.\r\n const engine = internalTexture.getEngine() as Engine;\r\n\r\n internalTexture.isReady = false;\r\n\r\n samplingMode = samplingMode ?? internalTexture.samplingMode;\r\n type = type ?? internalTexture.type;\r\n format = format ?? internalTexture.format;\r\n\r\n if (type === -1) {\r\n type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n }\r\n\r\n return new Promise((resolve) => {\r\n // Create the post process\r\n const postProcess = new PostProcess(\"postprocess\", postProcessName, null, null, 1, null, samplingMode, engine, false, undefined, type, undefined, null, false, format);\r\n postProcess.externalTextureSamplerBinding = true;\r\n\r\n // Hold the output of the decoding.\r\n const encodedTexture = engine.createRenderTargetTexture(\r\n { width: internalTexture.width, height: internalTexture.height },\r\n {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n generateStencilBuffer: false,\r\n samplingMode,\r\n type,\r\n format,\r\n }\r\n );\r\n\r\n postProcess.getEffect().executeWhenCompiled(() => {\r\n // PP Render Pass\r\n postProcess.onApply = (effect) => {\r\n effect._bindTexture(\"textureSampler\", internalTexture);\r\n effect.setFloat2(\"scale\", 1, 1);\r\n };\r\n scene.postProcessManager.directRender([postProcess!], encodedTexture, true);\r\n\r\n // Cleanup\r\n engine.restoreDefaultFramebuffer();\r\n engine._releaseTexture(internalTexture);\r\n if (postProcess) {\r\n postProcess.dispose();\r\n }\r\n\r\n // Internal Swap\r\n encodedTexture._swapAndDie(internalTexture);\r\n\r\n // Ready to get rolling again.\r\n internalTexture.type = type!;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.isReady = true;\r\n\r\n resolve(internalTexture);\r\n });\r\n });\r\n}\r\n\r\n// ref: http://stackoverflow.com/questions/32633585/how-do-you-convert-to-half-floats-in-javascript\r\nlet floatView: Float32Array;\r\nlet int32View: Int32Array;\r\n/**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\nexport function ToHalfFloat(value: number): number {\r\n if (!floatView) {\r\n floatView = new Float32Array(1);\r\n int32View = new Int32Array(floatView.buffer);\r\n }\r\n\r\n floatView[0] = value;\r\n const x = int32View[0];\r\n\r\n let bits = (x >> 16) & 0x8000; /* Get the sign */\r\n let m = (x >> 12) & 0x07ff; /* Keep one extra bit for rounding */\r\n const e = (x >> 23) & 0xff; /* Using int is faster here */\r\n\r\n /* If zero, or denormal, or exponent underflows too much for a denormal\r\n * half, return signed zero. */\r\n if (e < 103) {\r\n return bits;\r\n }\r\n\r\n /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */\r\n if (e > 142) {\r\n bits |= 0x7c00;\r\n /* If exponent was 0xff and one mantissa bit was set, it means NaN,\r\n * not Inf, so make sure we set one mantissa bit too. */\r\n bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;\r\n return bits;\r\n }\r\n\r\n /* If exponent underflows but not too much, return a denormal */\r\n if (e < 113) {\r\n m |= 0x0800;\r\n /* Extra rounding may overflow and set mantissa to 0 and exponent\r\n * to 1, which is OK. */\r\n bits |= (m >> (114 - e)) + ((m >> (113 - e)) & 1);\r\n return bits;\r\n }\r\n\r\n bits |= ((e - 112) << 10) | (m >> 1);\r\n bits += m & 1;\r\n return bits;\r\n}\r\n\r\n/**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\nexport function FromHalfFloat(value: number): number {\r\n const s = (value & 0x8000) >> 15;\r\n const e = (value & 0x7c00) >> 10;\r\n const f = value & 0x03ff;\r\n\r\n if (e === 0) {\r\n return (s ? -1 : 1) * Math.pow(2, -14) * (f / Math.pow(2, 10));\r\n } else if (e == 0x1f) {\r\n return f ? NaN : (s ? -1 : 1) * Infinity;\r\n }\r\n\r\n return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / Math.pow(2, 10));\r\n}\r\n\r\n/**\r\n * Class used to host texture specific utilities\r\n */\r\nexport const TextureTools = {\r\n /**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\n CreateResizedCopy,\r\n\r\n /**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\n ApplyPostProcess,\r\n /**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\n ToHalfFloat,\r\n\r\n /**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\n FromHalfFloat,\r\n};\r\n"]}
|
|
1
|
+
{"version":3,"file":"textureTools.js","sourceRoot":"","sources":["../../../../lts/core/generated/Misc/textureTools.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,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAG3D;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB,EAAE,KAAa,EAAE,MAAc,EAAE,kBAA2B,IAAI;IAC9G,MAAM,KAAK,GAAU,OAAO,CAAC,QAAQ,EAAE,CAAC;IACxC,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;IAEjC,MAAM,GAAG,GAAG,IAAI,mBAAmB,CAC/B,SAAS,GAAG,OAAO,CAAC,IAAI,EACxB,EAAE,KAAK,EAAE,KAAK,EA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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC;KAC5C;IAED,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IACxB;;;;;;;OAOG;IACH,iBAAiB;IAEjB;;;;;;;;;OASG;IACH,gBAAgB;IAChB;;;;OAIG;IACH,WAAW;IAEX;;;;OAIG;IACH,aAAa;CAChB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { PassPostProcess } from \"../PostProcesses/passPostProcess\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Scene } from \"../scene\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport type { Engine } from \"../Engines/engine\";\r\n\r\n/**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\nexport function CreateResizedCopy(texture: Texture, width: number, height: number, useBilinearMode: boolean = true): Texture {\r\n const scene = <Scene>texture.getScene();\r\n const engine = scene.getEngine();\r\n\r\n const rtt = new RenderTargetTexture(\r\n \"resized\" + texture.name,\r\n { width: width, height: height },\r\n scene,\r\n !texture.noMipmap,\r\n true,\r\n (<InternalTexture>texture._texture).type,\r\n false,\r\n texture.samplingMode,\r\n false\r\n );\r\n\r\n rtt.wrapU = texture.wrapU;\r\n rtt.wrapV = texture.wrapV;\r\n rtt.uOffset = texture.uOffset;\r\n rtt.vOffset = texture.vOffset;\r\n rtt.uScale = texture.uScale;\r\n rtt.vScale = texture.vScale;\r\n rtt.uAng = texture.uAng;\r\n rtt.vAng = texture.vAng;\r\n rtt.wAng = texture.wAng;\r\n rtt.coordinatesIndex = texture.coordinatesIndex;\r\n rtt.level = texture.level;\r\n rtt.anisotropicFilteringLevel = texture.anisotropicFilteringLevel;\r\n (<InternalTexture>rtt._texture).isReady = false;\r\n\r\n texture.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n texture.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n const passPostProcess = new PassPostProcess(\r\n \"pass\",\r\n 1,\r\n null,\r\n useBilinearMode ? Texture.BILINEAR_SAMPLINGMODE : Texture.NEAREST_SAMPLINGMODE,\r\n engine,\r\n false,\r\n Constants.TEXTURETYPE_UNSIGNED_INT\r\n );\r\n passPostProcess.externalTextureSamplerBinding = true;\r\n passPostProcess.getEffect().executeWhenCompiled(() => {\r\n passPostProcess.onApply = function (effect) {\r\n effect.setTexture(\"textureSampler\", texture);\r\n };\r\n\r\n const internalTexture = rtt.renderTarget;\r\n\r\n if (internalTexture) {\r\n scene.postProcessManager.directRender([passPostProcess], internalTexture);\r\n\r\n engine.unBindFramebuffer(internalTexture);\r\n rtt.disposeFramebufferObjects();\r\n passPostProcess.dispose();\r\n\r\n rtt.getInternalTexture()!.isReady = true;\r\n }\r\n });\r\n\r\n return rtt;\r\n}\r\n\r\n/**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\nexport function ApplyPostProcess(\r\n postProcessName: string,\r\n internalTexture: InternalTexture,\r\n scene: Scene,\r\n type?: number,\r\n samplingMode?: number,\r\n format?: number,\r\n width?: number,\r\n height?: number\r\n): Promise<InternalTexture> {\r\n // Gets everything ready.\r\n const engine = internalTexture.getEngine() as Engine;\r\n\r\n internalTexture.isReady = false;\r\n\r\n samplingMode = samplingMode ?? internalTexture.samplingMode;\r\n type = type ?? internalTexture.type;\r\n format = format ?? internalTexture.format;\r\n width = width ?? internalTexture.width;\r\n height = height ?? internalTexture.height;\r\n\r\n if (type === -1) {\r\n type = Constants.TEXTURETYPE_UNSIGNED_BYTE;\r\n }\r\n\r\n return new Promise((resolve) => {\r\n // Create the post process\r\n const postProcess = new PostProcess(\"postprocess\", postProcessName, null, null, 1, null, samplingMode, engine, false, undefined, type, undefined, null, false, format);\r\n postProcess.externalTextureSamplerBinding = true;\r\n\r\n // Hold the output of the decoding.\r\n const encodedTexture = engine.createRenderTargetTexture(\r\n { width: width as number, height: height as number },\r\n {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n generateStencilBuffer: false,\r\n samplingMode,\r\n type,\r\n format,\r\n }\r\n );\r\n\r\n postProcess.getEffect().executeWhenCompiled(() => {\r\n // PP Render Pass\r\n postProcess.onApply = (effect) => {\r\n effect._bindTexture(\"textureSampler\", internalTexture);\r\n effect.setFloat2(\"scale\", 1, 1);\r\n };\r\n scene.postProcessManager.directRender([postProcess!], encodedTexture, true);\r\n\r\n // Cleanup\r\n engine.restoreDefaultFramebuffer();\r\n engine._releaseTexture(internalTexture);\r\n if (postProcess) {\r\n postProcess.dispose();\r\n }\r\n\r\n // Internal Swap\r\n encodedTexture._swapAndDie(internalTexture);\r\n\r\n // Ready to get rolling again.\r\n internalTexture.type = type!;\r\n internalTexture.format = Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.isReady = true;\r\n\r\n resolve(internalTexture);\r\n });\r\n });\r\n}\r\n\r\n// ref: http://stackoverflow.com/questions/32633585/how-do-you-convert-to-half-floats-in-javascript\r\nlet floatView: Float32Array;\r\nlet int32View: Int32Array;\r\n/**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\nexport function ToHalfFloat(value: number): number {\r\n if (!floatView) {\r\n floatView = new Float32Array(1);\r\n int32View = new Int32Array(floatView.buffer);\r\n }\r\n\r\n floatView[0] = value;\r\n const x = int32View[0];\r\n\r\n let bits = (x >> 16) & 0x8000; /* Get the sign */\r\n let m = (x >> 12) & 0x07ff; /* Keep one extra bit for rounding */\r\n const e = (x >> 23) & 0xff; /* Using int is faster here */\r\n\r\n /* If zero, or denormal, or exponent underflows too much for a denormal\r\n * half, return signed zero. */\r\n if (e < 103) {\r\n return bits;\r\n }\r\n\r\n /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */\r\n if (e > 142) {\r\n bits |= 0x7c00;\r\n /* If exponent was 0xff and one mantissa bit was set, it means NaN,\r\n * not Inf, so make sure we set one mantissa bit too. */\r\n bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;\r\n return bits;\r\n }\r\n\r\n /* If exponent underflows but not too much, return a denormal */\r\n if (e < 113) {\r\n m |= 0x0800;\r\n /* Extra rounding may overflow and set mantissa to 0 and exponent\r\n * to 1, which is OK. */\r\n bits |= (m >> (114 - e)) + ((m >> (113 - e)) & 1);\r\n return bits;\r\n }\r\n\r\n bits |= ((e - 112) << 10) | (m >> 1);\r\n bits += m & 1;\r\n return bits;\r\n}\r\n\r\n/**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\nexport function FromHalfFloat(value: number): number {\r\n const s = (value & 0x8000) >> 15;\r\n const e = (value & 0x7c00) >> 10;\r\n const f = value & 0x03ff;\r\n\r\n if (e === 0) {\r\n return (s ? -1 : 1) * Math.pow(2, -14) * (f / Math.pow(2, 10));\r\n } else if (e == 0x1f) {\r\n return f ? NaN : (s ? -1 : 1) * Infinity;\r\n }\r\n\r\n return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + f / Math.pow(2, 10));\r\n}\r\n\r\n/**\r\n * Class used to host texture specific utilities\r\n */\r\nexport const TextureTools = {\r\n /**\r\n * Uses the GPU to create a copy texture rescaled at a given size\r\n * @param texture Texture to copy from\r\n * @param width defines the desired width\r\n * @param height defines the desired height\r\n * @param useBilinearMode defines if bilinear mode has to be used\r\n * @returns the generated texture\r\n */\r\n CreateResizedCopy,\r\n\r\n /**\r\n * Apply a post process to a texture\r\n * @param postProcessName name of the fragment post process\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param type type of the output texture. If not provided, use the one from internalTexture\r\n * @param samplingMode sampling mode to use to sample the source texture. If not provided, use the one from internalTexture\r\n * @param format format of the output texture. If not provided, use the one from internalTexture\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\n ApplyPostProcess,\r\n /**\r\n * Converts a number to half float\r\n * @param value number to convert\r\n * @returns converted number\r\n */\r\n ToHalfFloat,\r\n\r\n /**\r\n * Converts a half float to a number\r\n * @param value half float to convert\r\n * @returns converted half float\r\n */\r\n FromHalfFloat,\r\n};\r\n"]}
|
|
@@ -613,6 +613,7 @@ export class DefaultRenderingPipeline extends PostProcessRenderPipeline {
|
|
|
613
613
|
this.onBuildObservable.clear();
|
|
614
614
|
this._disposePostProcesses(true);
|
|
615
615
|
this._scene.postProcessRenderPipelineManager.detachCamerasFromRenderPipeline(this._name, this._cameras);
|
|
616
|
+
this._scene._postProcessRenderPipelineManager.removePipeline(this.name);
|
|
616
617
|
this._scene.autoClear = true;
|
|
617
618
|
if (this._resizeObserver) {
|
|
618
619
|
this._scene.getEngine().onResizeObservable.remove(this._resizeObserver);
|