@babylonjs/core 5.0.4 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Audio/audioSceneComponent.d.ts +2 -0
- package/Audio/audioSceneComponent.js +9 -7
- package/Audio/audioSceneComponent.js.map +1 -1
- package/Behaviors/Meshes/pointerDragBehavior.js +1 -0
- package/Behaviors/Meshes/pointerDragBehavior.js.map +1 -1
- package/Bones/skeleton.js +2 -0
- package/Bones/skeleton.js.map +1 -1
- package/Cameras/arcRotateCamera.d.ts +5 -0
- package/Cameras/arcRotateCamera.js +5 -0
- package/Cameras/arcRotateCamera.js.map +1 -1
- package/Cameras/camera.d.ts +5 -1
- package/Cameras/camera.js +7 -7
- package/Cameras/camera.js.map +1 -1
- package/Debug/debugLayer.d.ts +5 -0
- package/Debug/debugLayer.js +24 -0
- package/Debug/debugLayer.js.map +1 -1
- package/DeviceInput/Helpers/eventFactory.js +14 -3
- package/DeviceInput/Helpers/eventFactory.js.map +1 -1
- package/DeviceInput/InputDevices/deviceTypes.d.ts +1 -1
- package/DeviceInput/InputDevices/deviceTypes.js.map +1 -1
- package/DeviceInput/InputDevices/nativeDeviceInputSystem.js +2 -8
- package/DeviceInput/InputDevices/nativeDeviceInputSystem.js.map +1 -1
- package/Engines/Processors/shaderCodeCursor.js +5 -0
- package/Engines/Processors/shaderCodeCursor.js.map +1 -1
- package/Engines/constants.d.ts +25 -1
- package/Engines/constants.js +25 -1
- package/Engines/constants.js.map +1 -1
- package/Engines/engine.d.ts +1 -1
- package/Engines/engine.js +2 -1
- package/Engines/engine.js.map +1 -1
- package/Engines/nativeEngine.d.ts +1 -1
- package/Engines/nativeEngine.js +7 -8
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.d.ts +4 -0
- package/Engines/webgpuEngine.js +2 -0
- package/Engines/webgpuEngine.js.map +1 -1
- package/Gizmos/axisScaleGizmo.js +3 -2
- package/Gizmos/axisScaleGizmo.js.map +1 -1
- package/Gizmos/boundingBoxGizmo.js +11 -11
- package/Gizmos/boundingBoxGizmo.js.map +1 -1
- package/Gizmos/gizmo.d.ts +5 -0
- package/Gizmos/gizmo.js +11 -4
- package/Gizmos/gizmo.js.map +1 -1
- package/Gizmos/planeRotationGizmo.js +3 -3
- package/Gizmos/planeRotationGizmo.js.map +1 -1
- package/Inputs/scene.inputManager.js +7 -1
- package/Inputs/scene.inputManager.js.map +1 -1
- package/Lights/Shadows/shadowGenerator.d.ts +9 -0
- package/Lights/Shadows/shadowGenerator.js +25 -3
- package/Lights/Shadows/shadowGenerator.js.map +1 -1
- package/Loading/Plugins/babylonFileLoader.js +10 -8
- package/Loading/Plugins/babylonFileLoader.js.map +1 -1
- package/Materials/Node/Blocks/PBR/clearCoatBlock.d.ts +4 -0
- package/Materials/Node/Blocks/PBR/clearCoatBlock.js +19 -1
- package/Materials/Node/Blocks/PBR/clearCoatBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/iridescenceBlock.d.ts +54 -0
- package/Materials/Node/Blocks/PBR/iridescenceBlock.js +135 -0
- package/Materials/Node/Blocks/PBR/iridescenceBlock.js.map +1 -0
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.d.ts +4 -0
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +42 -24
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
- package/Materials/PBR/index.d.ts +1 -0
- package/Materials/PBR/index.js +1 -0
- package/Materials/PBR/index.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.d.ts +5 -0
- package/Materials/PBR/pbrBaseMaterial.js +2 -0
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/PBR/pbrIridescenceConfiguration.d.ts +102 -0
- package/Materials/PBR/pbrIridescenceConfiguration.js +257 -0
- package/Materials/PBR/pbrIridescenceConfiguration.js.map +1 -0
- package/Materials/Textures/Loaders/ktxTextureLoader.js +31 -0
- package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
- package/Materials/Textures/videoTexture.js +12 -12
- package/Materials/Textures/videoTexture.js.map +1 -1
- package/Materials/materialFlags.d.ts +6 -0
- package/Materials/materialFlags.js +18 -0
- package/Materials/materialFlags.js.map +1 -1
- package/Materials/materialPluginFactoryExport.d.ts +6 -0
- package/Materials/materialPluginFactoryExport.js +12 -0
- package/Materials/materialPluginFactoryExport.js.map +1 -1
- package/Materials/uniformBuffer.d.ts +2 -1
- package/Materials/uniformBuffer.js +2 -1
- package/Materials/uniformBuffer.js.map +1 -1
- package/Meshes/abstractMesh.d.ts +1 -1
- package/Meshes/abstractMesh.js +5 -2
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/mesh.d.ts +2 -2
- package/Meshes/mesh.js +11 -3
- package/Meshes/mesh.js.map +1 -1
- package/Misc/khronosTextureContainer.js +1 -1
- package/Misc/khronosTextureContainer.js.map +1 -1
- package/Misc/screenshotTools.js +6 -6
- package/Misc/screenshotTools.js.map +1 -1
- package/Physics/physicsImpostor.js +1 -1
- package/Physics/physicsImpostor.js.map +1 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.js +6 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
- package/Rendering/boundingBoxRenderer.js +4 -4
- package/Rendering/boundingBoxRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/boundingBoxRendererUboDeclaration.js +1 -1
- package/Shaders/ShadersInclude/boundingBoxRendererUboDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/helperFunctions.js +1 -1
- package/Shaders/ShadersInclude/helperFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/lightFragment.js +1 -1
- package/Shaders/ShadersInclude/lightFragment.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBRDFFunctions.js +1 -1
- package/Shaders/ShadersInclude/pbrBRDFFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockIridescence.d.ts +5 -0
- package/Shaders/ShadersInclude/pbrBlockIridescence.js +9 -0
- package/Shaders/ShadersInclude/pbrBlockIridescence.js.map +1 -0
- package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js +1 -1
- package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/pbrDirectLightingSetupFunctions.js +1 -1
- package/Shaders/ShadersInclude/pbrDirectLightingSetupFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/pbrFragmentDeclaration.js +1 -1
- package/Shaders/ShadersInclude/pbrFragmentDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/pbrFragmentSamplersDeclaration.js +1 -1
- package/Shaders/ShadersInclude/pbrFragmentSamplersDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/pbrVertexDeclaration.js +1 -1
- package/Shaders/ShadersInclude/pbrVertexDeclaration.js.map +1 -1
- package/Shaders/pbr.fragment.d.ts +1 -0
- package/Shaders/pbr.fragment.js +2 -1
- package/Shaders/pbr.fragment.js.map +1 -1
- package/Shaders/pbr.vertex.js +1 -1
- package/Shaders/pbr.vertex.js.map +1 -1
- package/Shaders/spriteMap.fragment.js +1 -1
- package/Shaders/spriteMap.fragment.js.map +1 -1
- package/XR/features/WebXRImageTracking.d.ts +0 -5
- package/XR/features/WebXRImageTracking.js +5 -8
- package/XR/features/WebXRImageTracking.js.map +1 -1
- package/XR/native/nativeXRFrame.d.ts +2 -1
- package/XR/native/nativeXRFrame.js +5 -1
- package/XR/native/nativeXRFrame.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +4 -0
- package/scene.js +4 -0
- package/scene.js.map +1 -1
|
@@ -94,7 +94,7 @@ var KhronosTextureContainer = /** @class */ (function () {
|
|
|
94
94
|
for (var face = 0; face < this.numberOfFaces; face++) {
|
|
95
95
|
var byteArray = new Uint8Array(this.data.buffer, this.data.byteOffset + dataOffset, imageSize);
|
|
96
96
|
var engine = texture.getEngine();
|
|
97
|
-
engine._uploadCompressedDataToTextureDirectly(texture,
|
|
97
|
+
engine._uploadCompressedDataToTextureDirectly(texture, texture.format, width, height, byteArray, face, level);
|
|
98
98
|
dataOffset += imageSize; // add size of the image for the next face/mipmap
|
|
99
99
|
dataOffset += 3 - ((imageSize + 3) % 4); // add padding for odd sized image
|
|
100
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"khronosTextureContainer.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Misc/khronosTextureContainer.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;;GAGG;AACH;IAmEI;;;;OAIG;IACH;IACI,yCAAyC;IAClC,IAAqB,EAC5B,aAAqB;QADd,SAAI,GAAJ,IAAI,CAAiB;QAZhC;;WAEG;QACI,cAAS,GAAG,KAAK,CAAC;QAYrB,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACxC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAC;YAC/C,OAAO;SACV;QAED,qDAAqD;QACrD,IAAM,QAAQ,GAAG,WAAW,CAAC,iBAAiB,CAAC;QAC/C,IAAM,cAAc,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,EAAE,EAAE,EAAE,GAAG,QAAQ,CAAC,CAAC;QAChG,IAAM,UAAU,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACrD,IAAM,YAAY,GAAG,UAAU,KAAK,UAAU,CAAC;QAE/C,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC,GAAG,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,oCAAoC;QACxG,IAAI,CAAC,UAAU,GA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ourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Logger } from \"../Misc/logger\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\n\r\n/**\r\n * for description see https://www.khronos.org/opengles/sdk/tools/KTX/\r\n * for file layout see https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/\r\n */\r\nexport class KhronosTextureContainer {\r\n private static HEADER_LEN = 12 + 13 * 4; // identifier + header elements (not including key value meta-data pairs)\r\n\r\n // load types\r\n private static COMPRESSED_2D = 0; // uses a gl.compressedTexImage2D()\r\n private static COMPRESSED_3D = 1; // uses a gl.compressedTexImage3D()\r\n private static TEX_2D = 2; // uses a gl.texImage2D()\r\n private static TEX_3D = 3; // uses a gl.texImage3D()\r\n\r\n // elements of the header\r\n /**\r\n * Gets the openGL type\r\n */\r\n public glType: number;\r\n /**\r\n * Gets the openGL type size\r\n */\r\n public glTypeSize: number;\r\n /**\r\n * Gets the openGL format\r\n */\r\n public glFormat: number;\r\n /**\r\n * Gets the openGL internal format\r\n */\r\n public glInternalFormat: number;\r\n /**\r\n * Gets the base internal format\r\n */\r\n public glBaseInternalFormat: number;\r\n /**\r\n * Gets image width in pixel\r\n */\r\n public pixelWidth: number;\r\n /**\r\n * Gets image height in pixel\r\n */\r\n public pixelHeight: number;\r\n /**\r\n * Gets image depth in pixels\r\n */\r\n public pixelDepth: number;\r\n /**\r\n * Gets the number of array elements\r\n */\r\n public numberOfArrayElements: number;\r\n /**\r\n * Gets the number of faces\r\n */\r\n public numberOfFaces: number;\r\n /**\r\n * Gets the number of mipmap levels\r\n */\r\n public numberOfMipmapLevels: number;\r\n /**\r\n * Gets the bytes of key value data\r\n */\r\n public bytesOfKeyValueData: number;\r\n /**\r\n * Gets the load type\r\n */\r\n public loadType: number;\r\n /**\r\n * If the container has been made invalid (eg. constructor failed to correctly load array buffer)\r\n */\r\n public isInvalid = false;\r\n\r\n /**\r\n * Creates a new KhronosTextureContainer\r\n * @param data contents of the KTX container file\r\n * @param facesExpected should be either 1 or 6, based whether a cube texture or or\r\n */\r\n public constructor(\r\n /** contents of the KTX container file */\r\n public data: ArrayBufferView,\r\n facesExpected: number\r\n ) {\r\n if (!KhronosTextureContainer.IsValid(data)) {\r\n this.isInvalid = true;\r\n Logger.Error(\"texture missing KTX identifier\");\r\n return;\r\n }\r\n\r\n // load the reset of the header in native 32 bit uint\r\n const dataSize = Uint32Array.BYTES_PER_ELEMENT;\r\n const headerDataView = new DataView(this.data.buffer, this.data.byteOffset + 12, 13 * dataSize);\r\n const endianness = headerDataView.getUint32(0, true);\r\n const littleEndian = endianness === 0x04030201;\r\n\r\n this.glType = headerDataView.getUint32(1 * dataSize, littleEndian); // must be 0 for compressed textures\r\n this.glTypeSize = headerDataView.getUint32(2 * dataSize, littleEndian); // must be 1 for compressed textures\r\n this.glFormat = headerDataView.getUint32(3 * dataSize, littleEndian); // must be 0 for compressed textures\r\n this.glInternalFormat = headerDataView.getUint32(4 * dataSize, littleEndian); // the value of arg passed to gl.compressedTexImage2D(,,x,,,,)\r\n this.glBaseInternalFormat = headerDataView.getUint32(5 * dataSize, littleEndian); // specify GL_RGB, GL_RGBA, GL_ALPHA, etc (un-compressed only)\r\n this.pixelWidth = headerDataView.getUint32(6 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage2D(,,,x,,,)\r\n this.pixelHeight = headerDataView.getUint32(7 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage2D(,,,,x,,)\r\n this.pixelDepth = headerDataView.getUint32(8 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage3D(,,,,,x,,)\r\n this.numberOfArrayElements = headerDataView.getUint32(9 * dataSize, littleEndian); // used for texture arrays\r\n this.numberOfFaces = headerDataView.getUint32(10 * dataSize, littleEndian); // used for cubemap textures, should either be 1 or 6\r\n this.numberOfMipmapLevels = headerDataView.getUint32(11 * dataSize, littleEndian); // number of levels; disregard possibility of 0 for compressed textures\r\n this.bytesOfKeyValueData = headerDataView.getUint32(12 * dataSize, littleEndian); // the amount of space after the header for meta-data\r\n\r\n // Make sure we have a compressed type. Not only reduces work, but probably better to let dev know they are not compressing.\r\n if (this.glType !== 0) {\r\n Logger.Error(\"only compressed formats currently supported\");\r\n return;\r\n } else {\r\n // value of zero is an indication to generate mipmaps @ runtime. Not usually allowed for compressed, so disregard.\r\n this.numberOfMipmapLevels = Math.max(1, this.numberOfMipmapLevels);\r\n }\r\n\r\n if (this.pixelHeight === 0 || this.pixelDepth !== 0) {\r\n Logger.Error(\"only 2D textures currently supported\");\r\n return;\r\n }\r\n\r\n if (this.numberOfArrayElements !== 0) {\r\n Logger.Error(\"texture arrays not currently supported\");\r\n return;\r\n }\r\n\r\n if (this.numberOfFaces !== facesExpected) {\r\n Logger.Error(\"number of faces expected\" + facesExpected + \", but found \" + this.numberOfFaces);\r\n return;\r\n }\r\n\r\n // we now have a completely validated file, so could use existence of loadType as success\r\n // would need to make this more elaborate & adjust checks above to support more than one load type\r\n this.loadType = KhronosTextureContainer.COMPRESSED_2D;\r\n }\r\n\r\n /**\r\n * Uploads KTX content to a Babylon Texture.\r\n * It is assumed that the texture has already been created & is currently bound\r\n * @param texture\r\n * @param loadMipmaps\r\n * @hidden\r\n */\r\n public uploadLevels(texture: InternalTexture, loadMipmaps: boolean): void {\r\n switch (this.loadType) {\r\n case KhronosTextureContainer.COMPRESSED_2D:\r\n this._upload2DCompressedLevels(texture, loadMipmaps);\r\n break;\r\n\r\n case KhronosTextureContainer.TEX_2D:\r\n case KhronosTextureContainer.COMPRESSED_3D:\r\n case KhronosTextureContainer.TEX_3D:\r\n }\r\n }\r\n\r\n private _upload2DCompressedLevels(texture: InternalTexture, loadMipmaps: boolean): void {\r\n // initialize width & height for level 1\r\n let dataOffset = KhronosTextureContainer.HEADER_LEN + this.bytesOfKeyValueData;\r\n let width = this.pixelWidth;\r\n let height = this.pixelHeight;\r\n\r\n const mipmapCount = loadMipmaps ? this.numberOfMipmapLevels : 1;\r\n for (let level = 0; level < mipmapCount; level++) {\r\n const imageSize = new Int32Array(this.data.buffer, this.data.byteOffset + dataOffset, 1)[0]; // size per face, since not supporting array cubemaps\r\n dataOffset += 4; //image data starts from next multiple of 4 offset. Each face refers to same imagesize field above.\r\n for (let face = 0; face < this.numberOfFaces; face++) {\r\n const byteArray = new Uint8Array(this.data.buffer, this.data.byteOffset + dataOffset, imageSize);\r\n\r\n const engine = texture.getEngine();\r\n engine._uploadCompressedDataToTextureDirectly(texture, this.glInternalFormat, width, height, byteArray, face, level);\r\n\r\n dataOffset += imageSize; // add size of the image for the next face/mipmap\r\n dataOffset += 3 - ((imageSize + 3) % 4); // add padding for odd sized image\r\n }\r\n width = Math.max(1.0, width * 0.5);\r\n height = Math.max(1.0, height * 0.5);\r\n }\r\n }\r\n\r\n /**\r\n * Checks if the given data starts with a KTX file identifier.\r\n * @param data the data to check\r\n * @returns true if the data is a KTX file or false otherwise\r\n */\r\n public static IsValid(data: ArrayBufferView): boolean {\r\n if (data.byteLength >= 12) {\r\n // '«', 'K', 'T', 'X', ' ', '1', '1', '»', '\\r', '\\n', '\\x1A', '\\n'\r\n const identifier = new Uint8Array(data.buffer, data.byteOffset, 12);\r\n if (\r\n identifier[0] === 0xab &&\r\n identifier[1] === 0x4b &&\r\n identifier[2] === 0x54 &&\r\n identifier[3] === 0x58 &&\r\n identifier[4] === 0x20 &&\r\n identifier[5] === 0x31 &&\r\n identifier[6] === 0x31 &&\r\n identifier[7] === 0xbb &&\r\n identifier[8] === 0x0d &&\r\n identifier[9] === 0x0a &&\r\n identifier[10] === 0x1a &&\r\n identifier[11] === 0x0a\r\n ) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"khronosTextureContainer.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Misc/khronosTextureContainer.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC;;;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AAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI;gBACtB,UAAU,CAAC,EAAE,CAAC,KAAK,IAAI;gBACvB,UAAU,CAAC,EAAE,CAAC,KAAK,IAAI,EACzB;gBACE,OAAO,IAAI,CAAC;aACf;SACJ;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAzMc,kCAAU,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,yEAAyE;IAElH,aAAa;IACE,qCAAa,GAAG,CAAC,CAAC,CAAC,mCAAmC;IACtD,qCAAa,GAAG,CAAC,CAAC,CAAC,mCAAmC;IACtD,8BAAM,GAAG,CAAC,CAAC,CAAC,yBAAyB;IACrC,8BAAM,GAAG,CAAC,CAAC,CAAC,yBAAyB;IAoMxD,8BAAC;CAAA,AA3MD,IA2MC;SA3MY,uBAAuB","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Logger } from \"../Misc/logger\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\n\r\n/**\r\n * for description see https://www.khronos.org/opengles/sdk/tools/KTX/\r\n * for file layout see https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/\r\n */\r\nexport class KhronosTextureContainer {\r\n private static HEADER_LEN = 12 + 13 * 4; // identifier + header elements (not including key value meta-data pairs)\r\n\r\n // load types\r\n private static COMPRESSED_2D = 0; // uses a gl.compressedTexImage2D()\r\n private static COMPRESSED_3D = 1; // uses a gl.compressedTexImage3D()\r\n private static TEX_2D = 2; // uses a gl.texImage2D()\r\n private static TEX_3D = 3; // uses a gl.texImage3D()\r\n\r\n // elements of the header\r\n /**\r\n * Gets the openGL type\r\n */\r\n public glType: number;\r\n /**\r\n * Gets the openGL type size\r\n */\r\n public glTypeSize: number;\r\n /**\r\n * Gets the openGL format\r\n */\r\n public glFormat: number;\r\n /**\r\n * Gets the openGL internal format\r\n */\r\n public glInternalFormat: number;\r\n /**\r\n * Gets the base internal format\r\n */\r\n public glBaseInternalFormat: number;\r\n /**\r\n * Gets image width in pixel\r\n */\r\n public pixelWidth: number;\r\n /**\r\n * Gets image height in pixel\r\n */\r\n public pixelHeight: number;\r\n /**\r\n * Gets image depth in pixels\r\n */\r\n public pixelDepth: number;\r\n /**\r\n * Gets the number of array elements\r\n */\r\n public numberOfArrayElements: number;\r\n /**\r\n * Gets the number of faces\r\n */\r\n public numberOfFaces: number;\r\n /**\r\n * Gets the number of mipmap levels\r\n */\r\n public numberOfMipmapLevels: number;\r\n /**\r\n * Gets the bytes of key value data\r\n */\r\n public bytesOfKeyValueData: number;\r\n /**\r\n * Gets the load type\r\n */\r\n public loadType: number;\r\n /**\r\n * If the container has been made invalid (eg. constructor failed to correctly load array buffer)\r\n */\r\n public isInvalid = false;\r\n\r\n /**\r\n * Creates a new KhronosTextureContainer\r\n * @param data contents of the KTX container file\r\n * @param facesExpected should be either 1 or 6, based whether a cube texture or or\r\n */\r\n public constructor(\r\n /** contents of the KTX container file */\r\n public data: ArrayBufferView,\r\n facesExpected: number\r\n ) {\r\n if (!KhronosTextureContainer.IsValid(data)) {\r\n this.isInvalid = true;\r\n Logger.Error(\"texture missing KTX identifier\");\r\n return;\r\n }\r\n\r\n // load the reset of the header in native 32 bit uint\r\n const dataSize = Uint32Array.BYTES_PER_ELEMENT;\r\n const headerDataView = new DataView(this.data.buffer, this.data.byteOffset + 12, 13 * dataSize);\r\n const endianness = headerDataView.getUint32(0, true);\r\n const littleEndian = endianness === 0x04030201;\r\n\r\n this.glType = headerDataView.getUint32(1 * dataSize, littleEndian); // must be 0 for compressed textures\r\n this.glTypeSize = headerDataView.getUint32(2 * dataSize, littleEndian); // must be 1 for compressed textures\r\n this.glFormat = headerDataView.getUint32(3 * dataSize, littleEndian); // must be 0 for compressed textures\r\n this.glInternalFormat = headerDataView.getUint32(4 * dataSize, littleEndian); // the value of arg passed to gl.compressedTexImage2D(,,x,,,,)\r\n this.glBaseInternalFormat = headerDataView.getUint32(5 * dataSize, littleEndian); // specify GL_RGB, GL_RGBA, GL_ALPHA, etc (un-compressed only)\r\n this.pixelWidth = headerDataView.getUint32(6 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage2D(,,,x,,,)\r\n this.pixelHeight = headerDataView.getUint32(7 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage2D(,,,,x,,)\r\n this.pixelDepth = headerDataView.getUint32(8 * dataSize, littleEndian); // level 0 value of arg passed to gl.compressedTexImage3D(,,,,,x,,)\r\n this.numberOfArrayElements = headerDataView.getUint32(9 * dataSize, littleEndian); // used for texture arrays\r\n this.numberOfFaces = headerDataView.getUint32(10 * dataSize, littleEndian); // used for cubemap textures, should either be 1 or 6\r\n this.numberOfMipmapLevels = headerDataView.getUint32(11 * dataSize, littleEndian); // number of levels; disregard possibility of 0 for compressed textures\r\n this.bytesOfKeyValueData = headerDataView.getUint32(12 * dataSize, littleEndian); // the amount of space after the header for meta-data\r\n\r\n // Make sure we have a compressed type. Not only reduces work, but probably better to let dev know they are not compressing.\r\n if (this.glType !== 0) {\r\n Logger.Error(\"only compressed formats currently supported\");\r\n return;\r\n } else {\r\n // value of zero is an indication to generate mipmaps @ runtime. Not usually allowed for compressed, so disregard.\r\n this.numberOfMipmapLevels = Math.max(1, this.numberOfMipmapLevels);\r\n }\r\n\r\n if (this.pixelHeight === 0 || this.pixelDepth !== 0) {\r\n Logger.Error(\"only 2D textures currently supported\");\r\n return;\r\n }\r\n\r\n if (this.numberOfArrayElements !== 0) {\r\n Logger.Error(\"texture arrays not currently supported\");\r\n return;\r\n }\r\n\r\n if (this.numberOfFaces !== facesExpected) {\r\n Logger.Error(\"number of faces expected\" + facesExpected + \", but found \" + this.numberOfFaces);\r\n return;\r\n }\r\n\r\n // we now have a completely validated file, so could use existence of loadType as success\r\n // would need to make this more elaborate & adjust checks above to support more than one load type\r\n this.loadType = KhronosTextureContainer.COMPRESSED_2D;\r\n }\r\n\r\n /**\r\n * Uploads KTX content to a Babylon Texture.\r\n * It is assumed that the texture has already been created & is currently bound\r\n * @param texture\r\n * @param loadMipmaps\r\n * @hidden\r\n */\r\n public uploadLevels(texture: InternalTexture, loadMipmaps: boolean): void {\r\n switch (this.loadType) {\r\n case KhronosTextureContainer.COMPRESSED_2D:\r\n this._upload2DCompressedLevels(texture, loadMipmaps);\r\n break;\r\n\r\n case KhronosTextureContainer.TEX_2D:\r\n case KhronosTextureContainer.COMPRESSED_3D:\r\n case KhronosTextureContainer.TEX_3D:\r\n }\r\n }\r\n\r\n private _upload2DCompressedLevels(texture: InternalTexture, loadMipmaps: boolean): void {\r\n // initialize width & height for level 1\r\n let dataOffset = KhronosTextureContainer.HEADER_LEN + this.bytesOfKeyValueData;\r\n let width = this.pixelWidth;\r\n let height = this.pixelHeight;\r\n\r\n const mipmapCount = loadMipmaps ? this.numberOfMipmapLevels : 1;\r\n for (let level = 0; level < mipmapCount; level++) {\r\n const imageSize = new Int32Array(this.data.buffer, this.data.byteOffset + dataOffset, 1)[0]; // size per face, since not supporting array cubemaps\r\n dataOffset += 4; //image data starts from next multiple of 4 offset. Each face refers to same imagesize field above.\r\n for (let face = 0; face < this.numberOfFaces; face++) {\r\n const byteArray = new Uint8Array(this.data.buffer, this.data.byteOffset + dataOffset, imageSize);\r\n\r\n const engine = texture.getEngine();\r\n engine._uploadCompressedDataToTextureDirectly(texture, texture.format, width, height, byteArray, face, level);\r\n\r\n dataOffset += imageSize; // add size of the image for the next face/mipmap\r\n dataOffset += 3 - ((imageSize + 3) % 4); // add padding for odd sized image\r\n }\r\n width = Math.max(1.0, width * 0.5);\r\n height = Math.max(1.0, height * 0.5);\r\n }\r\n }\r\n\r\n /**\r\n * Checks if the given data starts with a KTX file identifier.\r\n * @param data the data to check\r\n * @returns true if the data is a KTX file or false otherwise\r\n */\r\n public static IsValid(data: ArrayBufferView): boolean {\r\n if (data.byteLength >= 12) {\r\n // '«', 'K', 'T', 'X', ' ', '1', '1', '»', '\\r', '\\n', '\\x1A', '\\n'\r\n const identifier = new Uint8Array(data.buffer, data.byteOffset, 12);\r\n if (\r\n identifier[0] === 0xab &&\r\n identifier[1] === 0x4b &&\r\n identifier[2] === 0x54 &&\r\n identifier[3] === 0x58 &&\r\n identifier[4] === 0x20 &&\r\n identifier[5] === 0x31 &&\r\n identifier[6] === 0x31 &&\r\n identifier[7] === 0xbb &&\r\n identifier[8] === 0x0d &&\r\n identifier[9] === 0x0a &&\r\n identifier[10] === 0x1a &&\r\n identifier[11] === 0x0a\r\n ) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n}\r\n"]}
|
package/Misc/screenshotTools.js
CHANGED
|
@@ -155,13 +155,13 @@ export function CreateScreenshotUsingRenderTarget(engine, camera, size, successC
|
|
|
155
155
|
texture.renderList = null;
|
|
156
156
|
texture.samples = samples;
|
|
157
157
|
texture.renderSprites = renderSprites;
|
|
158
|
-
engine.onEndFrameObservable.addOnce(function () {
|
|
159
|
-
texture.readPixels(undefined, undefined, undefined, false).then(function (data) {
|
|
160
|
-
Tools.DumpData(width, height, data, successCallback, mimeType, fileName, true);
|
|
161
|
-
texture.dispose();
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
158
|
var renderToTexture = function () {
|
|
159
|
+
engine.onEndFrameObservable.addOnce(function () {
|
|
160
|
+
texture.readPixels(undefined, undefined, undefined, false).then(function (data) {
|
|
161
|
+
Tools.DumpData(width, height, data, successCallback, mimeType, fileName, true);
|
|
162
|
+
texture.dispose();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
165
|
// render the RTT
|
|
166
166
|
scene.incrementRenderId();
|
|
167
167
|
scene.resetCachedMaterial();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshotTools.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Misc/screenshotTools.ts"],"names":[],"mappings":"AAGA,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;AAKhC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAC5B,MAAc,EACd,MAAc,EACd,IAA8B,EAC9B,eAAwC,EACxC,QAA8B,EAC9B,aAAqB;IADrB,yBAAA,EAAA,sBAA8B;IAC9B,8BAAA,EAAA,qBAAqB;IAEf,IAAA,KAAoB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAA1D,MAAM,YAAA,EAAE,KAAK,WAA6C,CAAC;IAEnE,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,EAAE;QACpB,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC3C,OAAO;KACV;IAED,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE;QAC1B,KAAK,CAAC,iBAAiB,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;KAC9D;IAED,KAAK,CAAC,iBAAiB,CAAC,KAAK,GAAG,KAAK,CAAC;IACtC,KAAK,CAAC,iBAAiB,CAAC,MAAM,GAAG,MAAM,CAAC;IAExC,IAAM,aAAa,GAAG,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAE/D,IAAM,KAAK,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G,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 { Nullable } from \"../types\";\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\n\r\ndeclare type Engine = import(\"../Engines/engine\").Engine;\r\n\r\n/**\r\n * Captures a screenshot of the current rendering\r\n * @see https://doc.babylonjs.com/how_to/render_scene_on_a_png\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 (!Tools._ScreenshotCanvas) {\r\n Tools._ScreenshotCanvas = document.createElement(\"canvas\");\r\n }\r\n\r\n Tools._ScreenshotCanvas.width = width;\r\n Tools._ScreenshotCanvas.height = height;\r\n\r\n const renderContext = Tools._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 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 (forceDownload) {\r\n Tools.EncodeScreenshotCanvasData(undefined, mimeType);\r\n if (successCallback) {\r\n successCallback(\"\");\r\n }\r\n } else {\r\n Tools.EncodeScreenshotCanvasData(successCallback, mimeType);\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/how_to/render_scene_on_a_png\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/how_to/render_scene_on_a_png\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/how_to/render_scene_on_a_png\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\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): 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 scene = camera.getScene();\r\n let previousCamera: Nullable<Camera> = null;\r\n const previousCameras = scene.activeCameras;\r\n\r\n scene.activeCameras = null;\r\n\r\n if (scene.activeCamera !== camera) {\r\n previousCamera = scene.activeCamera;\r\n scene.activeCamera = camera;\r\n }\r\n\r\n scene.render(); // make sure the scene is ready to be rendered in the RTT with the right list of active meshes (which depends on the camera, that may have been changed above)\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 = null;\r\n texture.samples = samples;\r\n texture.renderSprites = renderSprites;\r\n\r\n engine.onEndFrameObservable.addOnce(() => {\r\n texture.readPixels(undefined, undefined, undefined, false)!.then((data) => {\r\n Tools.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 const renderToTexture = () => {\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 if (previousCamera) {\r\n scene.activeCamera = previousCamera;\r\n }\r\n scene.activeCameras = previousCameras;\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/how_to/render_scene_on_a_png\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\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): 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 );\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/how_to/render_scene_on_a_png\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/how_to/render_scene_on_a_png\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/how_to/render_scene_on_a_png\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/how_to/render_scene_on_a_png\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/how_to/render_scene_on_a_png\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 * @hidden\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":"AAGA,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;AAKhC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,gBAAgB,CAC5B,MAAc,EACd,MAAc,EACd,IAA8B,EAC9B,eAAwC,EACxC,QAA8B,EAC9B,aAAqB;IADrB,yBAAA,EAAA,sBAA8B;IAC9B,8BAAA,EAAA,qBAAqB;IAEf,IAAA,KAAoB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAA1D,MAAM,YAAA,EAAE,KAAK,WAA6C,CAAC;IAEnE,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,EAAE;QACpB,MAAM,CAAC,KAAK,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MAAM,CAAC,IAAM,eAAe,GAAG;IAC3B;;;;;;;;;;;;;;;;OAgBG;IACH,gBAAgB,kBAAA;IAEhB;;;;;;;;;;;;;;OAcG;IACH,qBAAqB,uBAAA;IAErB;;;;;;;;;;;OAWG;IACH,+BAA+B,iCAAA;IAE/B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,iCAAiC,mCAAA;IAEjC;;;;;;;;;;;;;;;;;;OAkBG;IACH,sCAAsC,wCAAA;CACzC,CAAC;AAEF;;;;;GAKG;AACH,IAAM,eAAe,GAAG;IACpB,+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 { Nullable } from \"../types\";\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\n\r\ndeclare type Engine = import(\"../Engines/engine\").Engine;\r\n\r\n/**\r\n * Captures a screenshot of the current rendering\r\n * @see https://doc.babylonjs.com/how_to/render_scene_on_a_png\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 (!Tools._ScreenshotCanvas) {\r\n Tools._ScreenshotCanvas = document.createElement(\"canvas\");\r\n }\r\n\r\n Tools._ScreenshotCanvas.width = width;\r\n Tools._ScreenshotCanvas.height = height;\r\n\r\n const renderContext = Tools._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 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 (forceDownload) {\r\n Tools.EncodeScreenshotCanvasData(undefined, mimeType);\r\n if (successCallback) {\r\n successCallback(\"\");\r\n }\r\n } else {\r\n Tools.EncodeScreenshotCanvasData(successCallback, mimeType);\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/how_to/render_scene_on_a_png\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/how_to/render_scene_on_a_png\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/how_to/render_scene_on_a_png\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\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): 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 scene = camera.getScene();\r\n let previousCamera: Nullable<Camera> = null;\r\n const previousCameras = scene.activeCameras;\r\n\r\n scene.activeCameras = null;\r\n\r\n if (scene.activeCamera !== camera) {\r\n previousCamera = scene.activeCamera;\r\n scene.activeCamera = camera;\r\n }\r\n\r\n scene.render(); // make sure the scene is ready to be rendered in the RTT with the right list of active meshes (which depends on the camera, that may have been changed above)\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 = null;\r\n texture.samples = samples;\r\n texture.renderSprites = renderSprites;\r\n\r\n const renderToTexture = () => {\r\n engine.onEndFrameObservable.addOnce(() => {\r\n texture.readPixels(undefined, undefined, undefined, false)!.then((data) => {\r\n Tools.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 if (previousCamera) {\r\n scene.activeCamera = previousCamera;\r\n }\r\n scene.activeCameras = previousCameras;\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/how_to/render_scene_on_a_png\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\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): 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 );\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/how_to/render_scene_on_a_png\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/how_to/render_scene_on_a_png\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/how_to/render_scene_on_a_png\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/how_to/render_scene_on_a_png\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/how_to/render_scene_on_a_png\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 * @hidden\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"]}
|
|
@@ -411,7 +411,7 @@ var PhysicsImpostor = /** @class */ (function () {
|
|
|
411
411
|
* @returns boolean specifying if body initialization is required
|
|
412
412
|
*/
|
|
413
413
|
PhysicsImpostor.prototype.isBodyInitRequired = function () {
|
|
414
|
-
return this._bodyUpdateRequired || (!this._physicsBody && !this._parent);
|
|
414
|
+
return this._bodyUpdateRequired || (!this._physicsBody && (!this._parent || !!this._options.ignoreParent));
|
|
415
415
|
};
|
|
416
416
|
/**
|
|
417
417
|
* Sets the updated scaling
|