@babylonjs/core 5.49.1 → 5.49.2
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/Engines/Native/nativeInterfaces.d.ts +1 -0
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/Native/nativePipelineContext.d.ts +6 -2
- package/Engines/Native/nativePipelineContext.js +12 -3
- package/Engines/Native/nativePipelineContext.js.map +1 -1
- package/Engines/nativeEngine.d.ts +2 -5
- package/Engines/nativeEngine.js +44 -12
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Materials/material.decalMapConfiguration.js.map +1 -1
- package/Meshes/meshUVSpaceRenderer.js.map +1 -1
- package/XR/features/WebXRDepthSensing.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"material.decalMapConfiguration.js","sourceRoot":"","sources":["../../../../lts/core/generated/Materials/material.decalMapConfiguration.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAKhD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAKlD;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,eAAe;IAApD;;QACI,UAAK,GAAG,KAAK,CAAC;QACd,kBAAa,GAAG,CAAC,CAAC;QAClB,sBAAiB,GAAG,KAAK,CAAC;QAC1B,eAAU,GAAG,KAAK,CAAC;IACvB,CAAC;CAAA;AAED;;;GAGG;AACH,MAAM,OAAO,qBAAsB,SAAQ,kBAAkB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Aa,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC7E,cAAc,CAAC,iBAAiB,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;SACrE;QAED,aAAa,CAAC,UAAU,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;IAEM,YAAY;QACf,OAAO,uBAAuB,CAAC;IACnC,CAAC;IAEM,WAAW,CAAC,QAAkB;QACjC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAClC,CAAC;IAEM,WAAW;QACd,OAAO;YACH,GAAG,EAAE;gBACD,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;gBAC9C,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;aAClD;SACJ,CAAC;IACN,CAAC;CACJ;AAtGG;IAFC,SAAS,EAAE;IACX,gBAAgB,CAAC,kCAAkC,CAAC;wDAC5B;AAUzB;IAFC,SAAS,EAAE;IACX,gBAAgB,CAAC,kCAAkC,CAAC;0DAC1B","sourcesContent":["import { serialize, expandToProperty } from \"../Misc/decorators\";\nimport { MaterialDefines } from \"./materialDefines\";\nimport { MaterialPluginBase } from \"./materialPluginBase\";\nimport { Constants } from \"../Engines/constants\";\nimport { MaterialFlags } from \"./materialFlags\";\nimport type { Scene } from \"core/scene\";\nimport type { Engine } from \"core/Engines/engine\";\nimport type { SubMesh } from \"core/Meshes/subMesh\";\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\nimport { MaterialHelper } from \"./materialHelper\";\nimport type { UniformBuffer } from \"./uniformBuffer\";\nimport type { PBRBaseMaterial } from \"./PBR/pbrBaseMaterial\";\nimport type { StandardMaterial } from \"./standardMaterial\";\n\n/**\n * @internal\n */\nexport class DecalMapDefines extends MaterialDefines {\n DECAL = false;\n DECALDIRECTUV = 0;\n DECAL_SMOOTHALPHA = false;\n GAMMADECAL = false;\n}\n\n/**\n * Plugin that implements the decal map component of a material\n * @since 5.49.1\n */\nexport class DecalMapConfiguration extends MaterialPluginBase {\n private _isEnabled = false;\n /**\n * Enables or disables the decal map on this material\n */\n @serialize()\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n public isEnabled = false;\n\n private _smoothAlpha = false;\n\n /**\n * Enables or disables the smooth alpha mode on this material. Default: false.\n * When enabled, the alpha value used to blend the decal map will be the squared value and will produce a smoother result.\n */\n @serialize()\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\n public smoothAlpha = false;\n\n private _internalMarkAllSubMeshesAsTexturesDirty: () => void;\n\n /** @internal */\n public _markAllSubMeshesAsTexturesDirty(): void {\n this._enable(this._isEnabled);\n this._internalMarkAllSubMeshesAsTexturesDirty();\n }\n\n /**\n * Creates a new DecalMapConfiguration\n * @param material The material to attach the decal map plugin to\n * @param addToPluginList If the plugin should be added to the material plugin list\n */\n constructor(material: PBRBaseMaterial | StandardMaterial, addToPluginList = true) {\n super(material, \"DecalMap\", 150, new DecalMapDefines(), addToPluginList);\n\n this.registerForExtraEvents = true; // because we override the hardBindForSubMesh method\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];\n }\n\n public isReadyForSubMesh(defines: DecalMapDefines, scene: Scene, engine: Engine, subMesh: SubMesh): boolean {\n const decalMap = subMesh.getMesh().decalMap;\n\n if (!this._isEnabled || !decalMap?.texture || !MaterialFlags.DecalMapEnabled || !scene.texturesEnabled) {\n return true;\n }\n\n return decalMap.isReady();\n }\n\n public prepareDefines(defines: DecalMapDefines, scene: Scene, mesh: AbstractMesh): void {\n const decalMap = mesh.decalMap;\n\n if (!this._isEnabled || !decalMap?.texture || !MaterialFlags.DecalMapEnabled || !scene.texturesEnabled) {\n const isDirty = defines.DECAL;\n if (isDirty) {\n defines.markAsTexturesDirty();\n }\n defines.DECAL = false;\n } else {\n const isDirty = !defines.DECAL || defines.GAMMADECAL !== decalMap.texture.gammaSpace;\n if (isDirty) {\n defines.markAsTexturesDirty();\n }\n defines.DECAL = true;\n defines.GAMMADECAL = decalMap.texture.gammaSpace;\n defines.DECAL_SMOOTHALPHA = this._smoothAlpha;\n MaterialHelper.PrepareDefinesForMergedUV(decalMap.texture, defines, \"DECAL\");\n }\n }\n\n /**\n * Note that we override hardBindForSubMesh and not bindForSubMesh because the material can be shared by multiple meshes,\n * in which case mustRebind could return false even though the decal map is different for each mesh: that's because the decal map\n * is not part of the material but hosted by the decalMap of the mesh instead.\n */\n public hardBindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, _engine: Engine, subMesh: SubMesh): void {\n const decalMap = subMesh.getMesh().decalMap;\n\n if (!this._isEnabled || !decalMap?.texture || !MaterialFlags.DecalMapEnabled || !scene.texturesEnabled) {\n return;\n }\n\n const isFrozen = this._material.isFrozen;\n const texture = decalMap.texture;\n\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\n uniformBuffer.updateFloat4(\"vDecalInfos\", texture.coordinatesIndex, 0, 0, 0);\n MaterialHelper.BindTextureMatrix(texture, uniformBuffer, \"decal\");\n }\n\n uniformBuffer.setTexture(\"decalSampler\", texture);\n }\n\n public getClassName(): string {\n return \"DecalMapConfiguration\";\n }\n\n public getSamplers(samplers: string[]): void {\n samplers.push(\"decalSampler\");\n }\n\n public getUniforms(): { ubo?: Array<{ name: string; size: number; type: string }>; vertex?: string; fragment?: string } {\n return {\n ubo: [\n { name: \"vDecalInfos\", size: 4, type: \"vec4\" },\n { name: \"decalMatrix\", size: 16, type: \"mat4\" },\n ],\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"material.decalMapConfiguration.js","sourceRoot":"","sources":["../../../../lts/core/generated/Materials/material.decalMapConfiguration.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,E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DAC5B;AAUzB;IAFC,SAAS,EAAE;IACX,gBAAgB,CAAC,kCAAkC,CAAC;0DAC1B","sourcesContent":["import { serialize, expandToProperty } from \"../Misc/decorators\";\r\nimport { MaterialDefines } from \"./materialDefines\";\r\nimport { MaterialPluginBase } from \"./materialPluginBase\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { MaterialFlags } from \"./materialFlags\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { Engine } from \"core/Engines/engine\";\r\nimport type { SubMesh } from \"core/Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport { MaterialHelper } from \"./materialHelper\";\r\nimport type { UniformBuffer } from \"./uniformBuffer\";\r\nimport type { PBRBaseMaterial } from \"./PBR/pbrBaseMaterial\";\r\nimport type { StandardMaterial } from \"./standardMaterial\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class DecalMapDefines extends MaterialDefines {\r\n DECAL = false;\r\n DECALDIRECTUV = 0;\r\n DECAL_SMOOTHALPHA = false;\r\n GAMMADECAL = false;\r\n}\r\n\r\n/**\r\n * Plugin that implements the decal map component of a material\r\n * @since 5.49.1\r\n */\r\nexport class DecalMapConfiguration extends MaterialPluginBase {\r\n private _isEnabled = false;\r\n /**\r\n * Enables or disables the decal map on this material\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public isEnabled = false;\r\n\r\n private _smoothAlpha = false;\r\n\r\n /**\r\n * Enables or disables the smooth alpha mode on this material. Default: false.\r\n * When enabled, the alpha value used to blend the decal map will be the squared value and will produce a smoother result.\r\n */\r\n @serialize()\r\n @expandToProperty(\"_markAllSubMeshesAsTexturesDirty\")\r\n public smoothAlpha = false;\r\n\r\n private _internalMarkAllSubMeshesAsTexturesDirty: () => void;\r\n\r\n /** @internal */\r\n public _markAllSubMeshesAsTexturesDirty(): void {\r\n this._enable(this._isEnabled);\r\n this._internalMarkAllSubMeshesAsTexturesDirty();\r\n }\r\n\r\n /**\r\n * Creates a new DecalMapConfiguration\r\n * @param material The material to attach the decal map plugin to\r\n * @param addToPluginList If the plugin should be added to the material plugin list\r\n */\r\n constructor(material: PBRBaseMaterial | StandardMaterial, addToPluginList = true) {\r\n super(material, \"DecalMap\", 150, new DecalMapDefines(), addToPluginList);\r\n\r\n this.registerForExtraEvents = true; // because we override the hardBindForSubMesh method\r\n this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];\r\n }\r\n\r\n public isReadyForSubMesh(defines: DecalMapDefines, scene: Scene, engine: Engine, subMesh: SubMesh): boolean {\r\n const decalMap = subMesh.getMesh().decalMap;\r\n\r\n if (!this._isEnabled || !decalMap?.texture || !MaterialFlags.DecalMapEnabled || !scene.texturesEnabled) {\r\n return true;\r\n }\r\n\r\n return decalMap.isReady();\r\n }\r\n\r\n public prepareDefines(defines: DecalMapDefines, scene: Scene, mesh: AbstractMesh): void {\r\n const decalMap = mesh.decalMap;\r\n\r\n if (!this._isEnabled || !decalMap?.texture || !MaterialFlags.DecalMapEnabled || !scene.texturesEnabled) {\r\n const isDirty = defines.DECAL;\r\n if (isDirty) {\r\n defines.markAsTexturesDirty();\r\n }\r\n defines.DECAL = false;\r\n } else {\r\n const isDirty = !defines.DECAL || defines.GAMMADECAL !== decalMap.texture.gammaSpace;\r\n if (isDirty) {\r\n defines.markAsTexturesDirty();\r\n }\r\n defines.DECAL = true;\r\n defines.GAMMADECAL = decalMap.texture.gammaSpace;\r\n defines.DECAL_SMOOTHALPHA = this._smoothAlpha;\r\n MaterialHelper.PrepareDefinesForMergedUV(decalMap.texture, defines, \"DECAL\");\r\n }\r\n }\r\n\r\n /**\r\n * Note that we override hardBindForSubMesh and not bindForSubMesh because the material can be shared by multiple meshes,\r\n * in which case mustRebind could return false even though the decal map is different for each mesh: that's because the decal map\r\n * is not part of the material but hosted by the decalMap of the mesh instead.\r\n */\r\n public hardBindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, _engine: Engine, subMesh: SubMesh): void {\r\n const decalMap = subMesh.getMesh().decalMap;\r\n\r\n if (!this._isEnabled || !decalMap?.texture || !MaterialFlags.DecalMapEnabled || !scene.texturesEnabled) {\r\n return;\r\n }\r\n\r\n const isFrozen = this._material.isFrozen;\r\n const texture = decalMap.texture;\r\n\r\n if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {\r\n uniformBuffer.updateFloat4(\"vDecalInfos\", texture.coordinatesIndex, 0, 0, 0);\r\n MaterialHelper.BindTextureMatrix(texture, uniformBuffer, \"decal\");\r\n }\r\n\r\n uniformBuffer.setTexture(\"decalSampler\", texture);\r\n }\r\n\r\n public getClassName(): string {\r\n return \"DecalMapConfiguration\";\r\n }\r\n\r\n public getSamplers(samplers: string[]): void {\r\n samplers.push(\"decalSampler\");\r\n }\r\n\r\n public getUniforms(): { ubo?: Array<{ name: string; size: number; type: string }>; vertex?: string; fragment?: string } {\r\n return {\r\n ubo: [\r\n { name: \"vDecalInfos\", size: 4, type: \"vec4\" },\r\n { name: \"decalMatrix\", size: 16, type: \"mat4\" },\r\n ],\r\n };\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meshUVSpaceRenderer.js","sourceRoot":"","sources":["../../../../lts/core/generated/Meshes/meshUVSpaceRenderer.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,gCAA+B;AAChD,OAAO,EAAE,SAAS,EAAE,gCAA+B;AACnD,OAAO,EAAE,cAAc,EAAE,uCAAsC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,qDAAoD;AAClF,OAAO,EAAE,MAAM,EAAE,+BAA8B;AAE/C,OAAO,uCAAuC,CAAC;AAC/C,OAAO,yCAAyC,CAAC;AA8BjD;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAQpB,MAAM,CAAC,UAAU,CAAC,KAAY;QAClC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE;YAC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,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAE9D,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAEjH,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QAElG,OAAO,sBAAsB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC9E,CAAC;;AAxLc,2BAAO,GAA6B,IAAI,CAAC","sourcesContent":["import type { Texture } from \"core/Materials/Textures/texture\";\nimport type { Vector3 } from \"core/Maths/math.vector\";\nimport type { Scene } from \"core/scene\";\nimport type { AbstractMesh } from \"./abstractMesh\";\nimport type { ThinTexture } from \"core/Materials/Textures/thinTexture\";\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\nimport type { Nullable } from \"core/types\";\nimport { Matrix } from \"core/Maths/math.vector\";\nimport { Constants } from \"core/Engines/constants\";\nimport { ShaderMaterial } from \"core/Materials/shaderMaterial\";\nimport { RenderTargetTexture } from \"core/Materials/Textures/renderTargetTexture\";\nimport { Color4 } from \"core/Maths/math.color\";\n\nimport \"../Shaders/meshUVSpaceRenderer.vertex\";\nimport \"../Shaders/meshUVSpaceRenderer.fragment\";\n\n/**\n * Options for the MeshUVSpaceRenderer\n * @since 5.49.1\n */\nexport interface IMeshUVSpaceRendererOptions {\n /**\n * Width of the texture. Default: 1024\n */\n width?: number;\n /**\n * Height of the texture. Default: 1024\n */\n height?: number;\n /**\n * Type of the texture. Default: Constants.TEXTURETYPE_UNSIGNED_BYTE\n */\n textureType?: number;\n /**\n * Generate mip maps. Default: true\n */\n generateMipMaps?: boolean;\n /**\n * Optimize UV allocation. Default: true\n * If you plan to use the texture as a decal map and rotate / offset the texture, you should set this to false\n */\n optimizeUVAllocation?: boolean;\n}\n\n/**\n * Class used to render in the mesh UV space\n * @since 5.49.1\n */\nexport class MeshUVSpaceRenderer {\n private static _Shader: Nullable<ShaderMaterial> = null;\n\n private _mesh: AbstractMesh;\n private _scene: Scene;\n private _options: Required<IMeshUVSpaceRendererOptions>;\n private _textureCreatedInternally = false;\n\n private static _GetShader(scene: Scene): ShaderMaterial {\n if (!MeshUVSpaceRenderer._Shader) {\n const shader = new ShaderMaterial(\n \"meshUVSpaceRendererShader\",\n scene,\n {\n vertex: \"meshUVSpaceRenderer\",\n fragment: \"meshUVSpaceRenderer\",\n },\n {\n attributes: [\"position\", \"normal\", \"uv\"],\n uniforms: [\"world\", \"worldView\", \"worldViewProjection\", \"view\", \"projection\"],\n needAlphaBlending: true,\n }\n );\n shader.backFaceCulling = false;\n shader.alphaMode = Constants.ALPHA_COMBINE;\n\n MeshUVSpaceRenderer._Shader = shader;\n }\n\n return MeshUVSpaceRenderer._Shader;\n }\n\n private static _IsRenderTargetTexture(texture: ThinTexture | RenderTargetTexture): texture is RenderTargetTexture {\n return (texture as RenderTargetTexture).renderList !== undefined;\n }\n\n /**\n * Disposes of the global resources created by the MeshUVSpaceRenderer class\n */\n public static Dispose(): void {\n if (MeshUVSpaceRenderer._Shader) {\n MeshUVSpaceRenderer._Shader.dispose();\n MeshUVSpaceRenderer._Shader = null;\n }\n }\n\n /**\n * Clear color of the texture\n */\n public clearColor = new Color4(0, 0, 0, 0);\n\n /**\n * Target texture used for rendering\n * If you don't set the property, a RenderTargetTexture will be created internally given the options provided to the constructor.\n * If you provide a RenderTargetTexture, it will be used directly.\n */\n public texture: Texture;\n\n /**\n * Creates a new MeshUVSpaceRenderer\n * @param mesh The mesh used for the source UV space\n * @param scene The scene the mesh belongs to\n * @param options The options to use when creating the texture\n */\n constructor(mesh: AbstractMesh, scene: Scene, options?: IMeshUVSpaceRendererOptions) {\n this._mesh = mesh;\n this._scene = scene;\n this._options = {\n width: 1024,\n height: 1024,\n textureType: Constants.TEXTURETYPE_UNSIGNED_BYTE,\n generateMipMaps: true,\n optimizeUVAllocation: true,\n ...options,\n };\n }\n\n /**\n * Checks if the texture is ready to be used\n * @returns true if the texture is ready to be used\n */\n public isReady(): boolean {\n return MeshUVSpaceRenderer._GetShader(this._scene).isReady() && (this.texture?.isReady() ?? true);\n }\n\n /**\n * Projects and renders a texture in the mesh UV space\n * @param texture The texture\n * @param position The position of the center of projection (world space coordinates)\n * @param normal The direction of the projection (world space coordinates)\n * @param size The size of the projection\n * @param angle The rotation angle around the direction of the projection\n */\n public renderTexture(texture: BaseTexture, position: Vector3, normal: Vector3, size: Vector3, angle = 0): void {\n if (!this.texture) {\n this._createDiffuseRTT();\n }\n\n if (MeshUVSpaceRenderer._IsRenderTargetTexture(this.texture)) {\n const matrix = this._createProjectionMatrix(position, normal, size, angle);\n const shader = MeshUVSpaceRenderer._GetShader(this._scene);\n\n shader.setTexture(\"textureSampler\", texture);\n shader.setMatrix(\"projMatrix\", matrix);\n\n this.texture.render();\n }\n }\n\n /**\n * Clears the texture map\n */\n public clear(): void {\n if (MeshUVSpaceRenderer._IsRenderTargetTexture(this.texture) && this.texture.renderTarget) {\n const engine = this._scene.getEngine();\n\n engine.bindFramebuffer(this.texture.renderTarget);\n engine.clear(this.clearColor, true, true, true);\n engine.unBindFramebuffer(this.texture.renderTarget);\n }\n }\n\n /**\n * Disposes of the ressources\n */\n public dispose() {\n if (this._textureCreatedInternally) {\n this.texture.dispose();\n this._textureCreatedInternally = false;\n }\n }\n\n private _createDiffuseRTT(): void {\n this._textureCreatedInternally = true;\n\n const texture = this._createRenderTargetTexture(this._options.width, this._options.height);\n\n texture.setMaterialForRendering(this._mesh, MeshUVSpaceRenderer._GetShader(this._scene));\n\n this.texture = texture;\n }\n\n private _createRenderTargetTexture(width: number, height: number): RenderTargetTexture {\n const rtt = new RenderTargetTexture(\n this._mesh.name + \"_uvspaceTexture\",\n { width, height },\n this._scene,\n this._options.generateMipMaps,\n true,\n this._options.textureType,\n false,\n this._options.generateMipMaps ? Constants.TEXTURE_TRILINEAR_SAMPLINGMODE : Constants.TEXTURE_BILINEAR_SAMPLINGMODE,\n false,\n false,\n false,\n Constants.TEXTUREFORMAT_RGBA\n );\n\n rtt.optimizeUVAllocation = !!this._options.optimizeUVAllocation;\n\n rtt.onClearObservable.addOnce(() => {\n this._scene.getEngine().clear(this.clearColor, true, true, true);\n rtt.onClearObservable.add(() => {}); // this disables clearing the texture for the next frames\n });\n\n rtt.renderList = [this._mesh];\n\n return rtt;\n }\n\n private _createProjectionMatrix(position: Vector3, normal: Vector3, size: Vector3, angle = 0): Matrix {\n const yaw = -Math.atan2(normal.z, normal.x) - Math.PI / 2;\n const len = Math.sqrt(normal.x * normal.x + normal.z * normal.z);\n const pitch = Math.atan2(normal.y, len);\n\n const p = position.add(normal.scale(size.z * 0.5));\n\n const projWorldMatrix = Matrix.RotationYawPitchRoll(yaw, pitch, angle).multiply(Matrix.Translation(p.x, p.y, p.z));\n const inverseProjWorldMatrix = Matrix.Invert(projWorldMatrix);\n\n const projMatrix = Matrix.FromArray([2 / size.x, 0, 0, 0, 0, 2 / size.y, 0, 0, 0, 0, 1 / size.z, 0, 0, 0, 0, 1]);\n\n const screenMatrix = Matrix.FromArray([0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1, 0, 0.5, 0.5, 0.0, 1]);\n\n return inverseProjWorldMatrix.multiply(projMatrix).multiply(screenMatrix);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"meshUVSpaceRenderer.js","sourceRoot":"","sources":["../../../../lts/core/generated/Meshes/meshUVSpaceRenderer.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,gCAA+B;AAChD,OAAO,EAAE,SAAS,EAAE,gCAA+B;AACnD,OAAO,EAAE,cAAc,EAAE,uCAAsC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,qDAAoD;AAClF,OAAO,EAAE,MAAM,EAAE,+BAA8B;AAE/C,OAAO,uCAAuC,CAAC;AAC/C,OAAO,yCAAyC,CAAC;AA8BjD;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAQpB,MAAM,CAAC,UAAU,CAAC,KAAY;QAClC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE;YAC9B,MAAM,MAAM,GAAG,IAAI,cAAc,CAC7B,2BAA2B,EAC3B,KAAK,EACL;gBACI,MAAM,EAAE,qBAAqB;gBAC7B,QAAQ,EAAE,qBAAqB;aAClC,EACD;gBACI,UAAU,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC;gBACxC,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,EAAE,YAAY,CAAC;gBAC7E,iBAAiB,EAAE,IAAI;aAC1B,CACJ,CAAC;YACF,MAAM,CAAC,eAAe,GAAG,KAAK,CAAC;YAC/B,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC,aAAa,CAAC;YAE3C,mBAAmB,CAAC,OAAO,GAAG,MAAM,CAAC;SACxC;QAED,OAAO,mBAAmB,CAAC,OAAO,CAAC;IACvC,CAAC;IAEO,MAAM,CAAC,sBAAsB,CAAC,OAA0C;QAC5E,OAAQ,OAA+B,CAAC,UAAU,KAAK,SAAS,CAAC;IACrE,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,OAAO;QACjB,IAAI,mBAAmB,CAAC,OAAO,EAAE;YAC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Q,CAAC,YAAY,CAAC,CAAC;IAC9E,CAAC;;AAxLc,2BAAO,GAA6B,IAAI,CAAC","sourcesContent":["import type { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Vector3 } from \"core/Maths/math.vector\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { AbstractMesh } from \"./abstractMesh\";\r\nimport type { ThinTexture } from \"core/Materials/Textures/thinTexture\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Matrix } from \"core/Maths/math.vector\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { ShaderMaterial } from \"core/Materials/shaderMaterial\";\r\nimport { RenderTargetTexture } from \"core/Materials/Textures/renderTargetTexture\";\r\nimport { Color4 } from \"core/Maths/math.color\";\r\n\r\nimport \"../Shaders/meshUVSpaceRenderer.vertex\";\r\nimport \"../Shaders/meshUVSpaceRenderer.fragment\";\r\n\r\n/**\r\n * Options for the MeshUVSpaceRenderer\r\n * @since 5.49.1\r\n */\r\nexport interface IMeshUVSpaceRendererOptions {\r\n /**\r\n * Width of the texture. Default: 1024\r\n */\r\n width?: number;\r\n /**\r\n * Height of the texture. Default: 1024\r\n */\r\n height?: number;\r\n /**\r\n * Type of the texture. Default: Constants.TEXTURETYPE_UNSIGNED_BYTE\r\n */\r\n textureType?: number;\r\n /**\r\n * Generate mip maps. Default: true\r\n */\r\n generateMipMaps?: boolean;\r\n /**\r\n * Optimize UV allocation. Default: true\r\n * If you plan to use the texture as a decal map and rotate / offset the texture, you should set this to false\r\n */\r\n optimizeUVAllocation?: boolean;\r\n}\r\n\r\n/**\r\n * Class used to render in the mesh UV space\r\n * @since 5.49.1\r\n */\r\nexport class MeshUVSpaceRenderer {\r\n private static _Shader: Nullable<ShaderMaterial> = null;\r\n\r\n private _mesh: AbstractMesh;\r\n private _scene: Scene;\r\n private _options: Required<IMeshUVSpaceRendererOptions>;\r\n private _textureCreatedInternally = false;\r\n\r\n private static _GetShader(scene: Scene): ShaderMaterial {\r\n if (!MeshUVSpaceRenderer._Shader) {\r\n const shader = new ShaderMaterial(\r\n \"meshUVSpaceRendererShader\",\r\n scene,\r\n {\r\n vertex: \"meshUVSpaceRenderer\",\r\n fragment: \"meshUVSpaceRenderer\",\r\n },\r\n {\r\n attributes: [\"position\", \"normal\", \"uv\"],\r\n uniforms: [\"world\", \"worldView\", \"worldViewProjection\", \"view\", \"projection\"],\r\n needAlphaBlending: true,\r\n }\r\n );\r\n shader.backFaceCulling = false;\r\n shader.alphaMode = Constants.ALPHA_COMBINE;\r\n\r\n MeshUVSpaceRenderer._Shader = shader;\r\n }\r\n\r\n return MeshUVSpaceRenderer._Shader;\r\n }\r\n\r\n private static _IsRenderTargetTexture(texture: ThinTexture | RenderTargetTexture): texture is RenderTargetTexture {\r\n return (texture as RenderTargetTexture).renderList !== undefined;\r\n }\r\n\r\n /**\r\n * Disposes of the global resources created by the MeshUVSpaceRenderer class\r\n */\r\n public static Dispose(): void {\r\n if (MeshUVSpaceRenderer._Shader) {\r\n MeshUVSpaceRenderer._Shader.dispose();\r\n MeshUVSpaceRenderer._Shader = null;\r\n }\r\n }\r\n\r\n /**\r\n * Clear color of the texture\r\n */\r\n public clearColor = new Color4(0, 0, 0, 0);\r\n\r\n /**\r\n * Target texture used for rendering\r\n * If you don't set the property, a RenderTargetTexture will be created internally given the options provided to the constructor.\r\n * If you provide a RenderTargetTexture, it will be used directly.\r\n */\r\n public texture: Texture;\r\n\r\n /**\r\n * Creates a new MeshUVSpaceRenderer\r\n * @param mesh The mesh used for the source UV space\r\n * @param scene The scene the mesh belongs to\r\n * @param options The options to use when creating the texture\r\n */\r\n constructor(mesh: AbstractMesh, scene: Scene, options?: IMeshUVSpaceRendererOptions) {\r\n this._mesh = mesh;\r\n this._scene = scene;\r\n this._options = {\r\n width: 1024,\r\n height: 1024,\r\n textureType: Constants.TEXTURETYPE_UNSIGNED_BYTE,\r\n generateMipMaps: true,\r\n optimizeUVAllocation: true,\r\n ...options,\r\n };\r\n }\r\n\r\n /**\r\n * Checks if the texture is ready to be used\r\n * @returns true if the texture is ready to be used\r\n */\r\n public isReady(): boolean {\r\n return MeshUVSpaceRenderer._GetShader(this._scene).isReady() && (this.texture?.isReady() ?? true);\r\n }\r\n\r\n /**\r\n * Projects and renders a texture in the mesh UV space\r\n * @param texture The texture\r\n * @param position The position of the center of projection (world space coordinates)\r\n * @param normal The direction of the projection (world space coordinates)\r\n * @param size The size of the projection\r\n * @param angle The rotation angle around the direction of the projection\r\n */\r\n public renderTexture(texture: BaseTexture, position: Vector3, normal: Vector3, size: Vector3, angle = 0): void {\r\n if (!this.texture) {\r\n this._createDiffuseRTT();\r\n }\r\n\r\n if (MeshUVSpaceRenderer._IsRenderTargetTexture(this.texture)) {\r\n const matrix = this._createProjectionMatrix(position, normal, size, angle);\r\n const shader = MeshUVSpaceRenderer._GetShader(this._scene);\r\n\r\n shader.setTexture(\"textureSampler\", texture);\r\n shader.setMatrix(\"projMatrix\", matrix);\r\n\r\n this.texture.render();\r\n }\r\n }\r\n\r\n /**\r\n * Clears the texture map\r\n */\r\n public clear(): void {\r\n if (MeshUVSpaceRenderer._IsRenderTargetTexture(this.texture) && this.texture.renderTarget) {\r\n const engine = this._scene.getEngine();\r\n\r\n engine.bindFramebuffer(this.texture.renderTarget);\r\n engine.clear(this.clearColor, true, true, true);\r\n engine.unBindFramebuffer(this.texture.renderTarget);\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the ressources\r\n */\r\n public dispose() {\r\n if (this._textureCreatedInternally) {\r\n this.texture.dispose();\r\n this._textureCreatedInternally = false;\r\n }\r\n }\r\n\r\n private _createDiffuseRTT(): void {\r\n this._textureCreatedInternally = true;\r\n\r\n const texture = this._createRenderTargetTexture(this._options.width, this._options.height);\r\n\r\n texture.setMaterialForRendering(this._mesh, MeshUVSpaceRenderer._GetShader(this._scene));\r\n\r\n this.texture = texture;\r\n }\r\n\r\n private _createRenderTargetTexture(width: number, height: number): RenderTargetTexture {\r\n const rtt = new RenderTargetTexture(\r\n this._mesh.name + \"_uvspaceTexture\",\r\n { width, height },\r\n this._scene,\r\n this._options.generateMipMaps,\r\n true,\r\n this._options.textureType,\r\n false,\r\n this._options.generateMipMaps ? Constants.TEXTURE_TRILINEAR_SAMPLINGMODE : Constants.TEXTURE_BILINEAR_SAMPLINGMODE,\r\n false,\r\n false,\r\n false,\r\n Constants.TEXTUREFORMAT_RGBA\r\n );\r\n\r\n rtt.optimizeUVAllocation = !!this._options.optimizeUVAllocation;\r\n\r\n rtt.onClearObservable.addOnce(() => {\r\n this._scene.getEngine().clear(this.clearColor, true, true, true);\r\n rtt.onClearObservable.add(() => {}); // this disables clearing the texture for the next frames\r\n });\r\n\r\n rtt.renderList = [this._mesh];\r\n\r\n return rtt;\r\n }\r\n\r\n private _createProjectionMatrix(position: Vector3, normal: Vector3, size: Vector3, angle = 0): Matrix {\r\n const yaw = -Math.atan2(normal.z, normal.x) - Math.PI / 2;\r\n const len = Math.sqrt(normal.x * normal.x + normal.z * normal.z);\r\n const pitch = Math.atan2(normal.y, len);\r\n\r\n const p = position.add(normal.scale(size.z * 0.5));\r\n\r\n const projWorldMatrix = Matrix.RotationYawPitchRoll(yaw, pitch, angle).multiply(Matrix.Translation(p.x, p.y, p.z));\r\n const inverseProjWorldMatrix = Matrix.Invert(projWorldMatrix);\r\n\r\n const projMatrix = Matrix.FromArray([2 / size.x, 0, 0, 0, 0, 2 / size.y, 0, 0, 0, 0, 1 / size.z, 0, 0, 0, 0, 1]);\r\n\r\n const screenMatrix = Matrix.FromArray([0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1, 0, 0.5, 0.5, 0.0, 1]);\r\n\r\n return inverseProjWorldMatrix.multiply(projMatrix).multiply(screenMatrix);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebXRDepthSensing.js","sourceRoot":"","sources":["../../../../../lts/core/generated/XR/features/WebXRDepthSensing.ts"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AO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC3B,IAAI,oBAAoB,IAAI,oBAAoB,EAAE;gBAC9C,MAAM,MAAM,GAAmB,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;oBACtE,QAAQ,KAAK,EAAE;wBACX,KAAK,KAAK;4BACN,OAAO,eAAe,CAAC;wBAC3B,KAAK,KAAK;4BACN,OAAO,eAAe,CAAC;qBAC9B;gBACL,CAAC,CAAC,CAAC;gBACH,MAAM,WAAW,GAAwB,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;oBACtF,QAAQ,MAAM,EAAE;wBACZ,KAAK,QAAQ;4BACT,OAAO,iBAAiB,CAAC;wBAC7B,KAAK,OAAO;4BACR,OAAO,SAAS,CAAC;qBACxB;gBACL,CAAC,CAAC,CAAC;gBAEH,OAAO,CAAC;oBACJ,YAAY,EAAE;wBACV,eAAe,EAAE,MAAM;wBACvB,oBAAoB,EAAE,WAAW;qBACpC;iBACJ,CAAC,CAAC;aACN;iBAAM;gBACH,OAAO,CAAC,EAAE,CAAC,CAAC;aACf;QACL,CAAC,CAAC,CAAC;IACP,CAAC;;AAnMD;;GAEG;AACoB,sBAAI,GAAG,gBAAgB,CAAC,aAAa,CAAC;AAE7D;;;;GAIG;AACoB,yBAAO,GAAG,CAAC,CAAC;AA4LvC,oBAAoB,CAAC,eAAe,CAChC,iBAAiB,CAAC,IAAI,EACtB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,iBAAiB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC,EACD,iBAAiB,CAAC,OAAO,EACzB,KAAK,CACR,CAAC","sourcesContent":["import { RawTexture } from \"../../Materials/Textures/rawTexture\";\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\nimport { Tools } from \"../../Misc/tools\";\nimport { Texture } from \"../../Materials/Textures/texture\";\nimport { Engine } from \"../../Engines/engine\";\nimport { Observable } from \"../../Misc/observable\";\nimport type { Nullable } from \"../../types\";\nimport { Constants } from \"../../Engines/constants\";\nimport { WebGLHardwareTexture } from \"../../Engines/WebGL/webGLHardwareTexture\";\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\n\nexport type WebXRDepthUsage = \"cpu\" | \"gpu\";\nexport type WebXRDepthDataFormat = \"ushort\" | \"float\";\n\n/**\n * Options for Depth Sensing feature\n */\nexport interface IWebXRDepthSensingOptions {\n /**\n * The desired depth sensing usage for the session\n */\n usagePreference: WebXRDepthUsage[];\n /**\n * The desired depth sensing data format for the session\n */\n dataFormatPreference: WebXRDepthDataFormat[];\n}\n\ntype GetDepthInMetersType = (x: number, y: number) => number;\n\n/**\n * WebXR Feature for WebXR Depth Sensing Module\n * @since 5.49.1\n */\nexport class WebXRDepthSensing extends WebXRAbstractFeature {\n private _width: Nullable<number> = null;\n private _height: Nullable<number> = null;\n private _rawValueToMeters: Nullable<number> = null;\n private _normDepthBufferFromNormView: Nullable<XRRigidTransform> = null;\n private _cachedDepthBuffer: Nullable<ArrayBuffer> = null;\n private _cachedWebGLTexture: Nullable<WebGLTexture> = null;\n private _cachedDepthImageTexture: Nullable<RawTexture> = null;\n\n /**\n * Width of depth data. If depth data is not exist, returns null.\n */\n public get width(): Nullable<number> {\n return this._width;\n }\n\n /**\n * Height of depth data. If depth data is not exist, returns null.\n */\n public get height(): Nullable<number> {\n return this._height;\n }\n\n /**\n * Scale factor by which the raw depth values must be multiplied in order to get the depths in meters.\n */\n public get rawValueToMeters(): Nullable<number> {\n return this._rawValueToMeters;\n }\n\n /**\n * An XRRigidTransform that needs to be applied when indexing into the depth buffer.\n */\n public get normDepthBufferFromNormView(): Nullable<XRRigidTransform> {\n return this._normDepthBufferFromNormView;\n }\n\n /**\n * Describes which depth-sensing usage (\"cpu\" or \"gpu\") is used.\n */\n public get depthUsage(): WebXRDepthUsage {\n switch (this._xrSessionManager.session.depthUsage) {\n case \"cpu-optimized\":\n return \"cpu\";\n case \"gpu-optimized\":\n return \"gpu\";\n }\n }\n\n /**\n * Describes which depth sensing data format (\"ushort\" or \"float\") is used.\n */\n public get depthDataFormat(): WebXRDepthDataFormat {\n switch (this._xrSessionManager.session.depthDataFormat) {\n case \"luminance-alpha\":\n return \"ushort\";\n case \"float32\":\n return \"float\";\n }\n }\n\n /**\n * Latest cached InternalTexture which containing depth buffer information.\n * This can be used when the depth usage is \"gpu\".\n */\n public get latestInternalTexture(): Nullable<InternalTexture> {\n if (!this._cachedWebGLTexture) {\n return null;\n }\n\n const engine = this._xrSessionManager.scene.getEngine();\n const internalTexture = new InternalTexture(engine, InternalTextureSource.Unknown);\n internalTexture.isCube = false;\n internalTexture.invertY = false;\n internalTexture._useSRGBBuffer = false;\n internalTexture.format = this.depthDataFormat === \"ushort\" ? Constants.TEXTUREFORMAT_LUMINANCE_ALPHA : Constants.TEXTUREFORMAT_RGBA;\n internalTexture.generateMipMaps = false;\n internalTexture.type = this.depthDataFormat === \"ushort\" ? Constants.TEXTURETYPE_UNSIGNED_SHORT : Constants.TEXTURETYPE_FLOAT;\n internalTexture.samplingMode = Constants.TEXTURE_NEAREST_LINEAR;\n internalTexture.width = this.width ?? 0;\n internalTexture.height = this.height ?? 0;\n internalTexture._cachedWrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;\n internalTexture._cachedWrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;\n internalTexture._hardwareTexture = new WebGLHardwareTexture(this._cachedWebGLTexture, engine._gl);\n\n return internalTexture;\n }\n\n /**\n * cached depth buffer\n */\n public get latestDepthBuffer(): Nullable<ArrayBufferView> {\n if (!this._cachedDepthBuffer) {\n return null;\n }\n\n return this.depthDataFormat === \"ushort\" ? new Uint16Array(this._cachedDepthBuffer) : new Float32Array(this._cachedDepthBuffer);\n }\n\n /**\n * Event that notify when `DepthInformation.getDepthInMeters` is available.\n * `getDepthInMeters` method needs active XRFrame (not available for cached XRFrame)\n */\n public onGetDepthInMetersAvailable: Observable<GetDepthInMetersType> = new Observable<GetDepthInMetersType>();\n\n /**\n * Latest cached Texture of depth image which is made from the depth buffer data.\n */\n public get latestDepthImageTexture(): Nullable<RawTexture> {\n return this._cachedDepthImageTexture;\n }\n\n /**\n * XRWebGLBinding which is used for acquiring WebGLDepthInformation\n */\n private _glBinding?: XRWebGLBinding;\n\n /**\n * The module's name\n */\n public static readonly Name = WebXRFeatureName.DEPTH_SENSING;\n\n /**\n * The (Babylon) version of this module.\n * This is an integer representing the implementation version.\n * This number does not correspond to the WebXR specs version\n */\n public static readonly Version = 1;\n\n /**\n * Creates a new instance of the depth sensing feature\n * @param _xrSessionManager the WebXRSessionManager\n * @param options options for WebXR Depth Sensing Feature\n */\n constructor(_xrSessionManager: WebXRSessionManager, public readonly options: IWebXRDepthSensingOptions) {\n super(_xrSessionManager);\n this.xrNativeFeatureName = \"depth-sensing\";\n\n // https://immersive-web.github.io/depth-sensing/\n Tools.Warn(\"depth-sensing is an experimental and unstable feature.\");\n }\n\n /**\n * attach this feature\n * Will usually be called by the features manager\n *\n * @returns true if successful.\n */\n public attach(force?: boolean | undefined): boolean {\n if (!super.attach(force)) {\n return false;\n }\n\n const isBothDepthUsageAndFormatNull = this._xrSessionManager.session.depthDataFormat == null || this._xrSessionManager.session.depthUsage == null;\n if (isBothDepthUsageAndFormatNull) {\n return false;\n }\n\n this._glBinding = new XRWebGLBinding(this._xrSessionManager.session, this._xrSessionManager.scene.getEngine()._gl);\n\n return true;\n }\n\n /**\n * Dispose this feature and all of the resources attached\n */\n public dispose(): void {\n this._cachedDepthImageTexture?.dispose();\n }\n\n protected _onXRFrame(_xrFrame: XRFrame): void {\n const referenceSPace = this._xrSessionManager.referenceSpace;\n\n const pose = _xrFrame.getViewerPose(referenceSPace);\n if (pose == null) {\n return;\n }\n\n for (const view of pose.views) {\n switch (this.depthUsage) {\n case \"cpu\":\n this._updateDepthInformationAndTextureCPUDepthUsage(_xrFrame, view, this.depthDataFormat);\n break;\n\n case \"gpu\":\n if (!this._glBinding) {\n break;\n }\n\n this._updateDepthInformationAndTextureWebGLDepthUsage(this._glBinding, view, this.depthDataFormat);\n break;\n\n default:\n Tools.Error(\"Unknown depth usage\");\n this.detach();\n break;\n }\n }\n }\n\n private _updateDepthInformationAndTextureCPUDepthUsage(frame: XRFrame, view: XRView, dataFormat: WebXRDepthDataFormat): void {\n const depthInfo = frame.getDepthInformation(view);\n if (depthInfo === null) {\n return;\n }\n\n const { data, width, height, rawValueToMeters, getDepthInMeters } = depthInfo as XRCPUDepthInformation;\n\n this._width = width;\n this._height = height;\n this._rawValueToMeters = rawValueToMeters;\n this._cachedDepthBuffer = data;\n\n // to avoid Illegal Invocation error, bind `this`\n this.onGetDepthInMetersAvailable.notifyObservers(getDepthInMeters.bind(depthInfo));\n\n if (!this._cachedDepthImageTexture) {\n this._cachedDepthImageTexture = RawTexture.CreateRTexture(\n null,\n width,\n height,\n this._xrSessionManager.scene,\n false,\n true,\n Texture.NEAREST_SAMPLINGMODE,\n Engine.TEXTURETYPE_FLOAT\n );\n }\n\n switch (dataFormat) {\n case \"ushort\":\n this._cachedDepthImageTexture.update(Float32Array.from(new Uint16Array(data)).map((value) => value * rawValueToMeters));\n break;\n\n case \"float\":\n this._cachedDepthImageTexture.update(new Float32Array(data).map((value) => value * rawValueToMeters));\n break;\n\n default:\n break;\n }\n }\n\n private _updateDepthInformationAndTextureWebGLDepthUsage(webglBinding: XRWebGLBinding, view: XRView, dataFormat: WebXRDepthDataFormat): void {\n const depthInfo = webglBinding.getDepthInformation(view);\n if (depthInfo === null) {\n return;\n }\n\n const { texture, width, height } = depthInfo as XRWebGLDepthInformation;\n\n this._width = width;\n this._height = height;\n this._cachedWebGLTexture = texture;\n\n const scene = this._xrSessionManager.scene;\n const engine = scene.getEngine();\n const internalTexture = engine.wrapWebGLTexture(texture);\n\n if (!this._cachedDepthImageTexture) {\n this._cachedDepthImageTexture = RawTexture.CreateRTexture(\n null,\n width,\n height,\n scene,\n false,\n true,\n Texture.NEAREST_SAMPLINGMODE,\n dataFormat === \"ushort\" ? Engine.TEXTURETYPE_UNSIGNED_BYTE : Engine.TEXTURETYPE_FLOAT\n );\n }\n\n this._cachedDepthImageTexture._texture = internalTexture;\n }\n\n /**\n * Extends the session init object if needed\n * @returns augmentation object for the xr session init object.\n */\n public getXRSessionInitExtension(): Promise<Partial<XRSessionInit>> {\n const isDepthUsageDeclared = this.options.usagePreference != null && this.options.usagePreference.length !== 0;\n const isDataFormatDeclared = this.options.dataFormatPreference != null && this.options.dataFormatPreference.length !== 0;\n\n return new Promise((resolve) => {\n if (isDepthUsageDeclared && isDataFormatDeclared) {\n const usages: XRDepthUsage[] = this.options.usagePreference.map((usage) => {\n switch (usage) {\n case \"cpu\":\n return \"cpu-optimized\";\n case \"gpu\":\n return \"gpu-optimized\";\n }\n });\n const dataFormats: XRDepthDataFormat[] = this.options.dataFormatPreference.map((format) => {\n switch (format) {\n case \"ushort\":\n return \"luminance-alpha\";\n case \"float\":\n return \"float32\";\n }\n });\n\n resolve({\n depthSensing: {\n usagePreference: usages,\n dataFormatPreference: dataFormats,\n },\n });\n } else {\n resolve({});\n }\n });\n }\n}\n\nWebXRFeaturesManager.AddWebXRFeature(\n WebXRDepthSensing.Name,\n (xrSessionManager, options) => {\n return () => new WebXRDepthSensing(xrSessionManager, options);\n },\n WebXRDepthSensing.Version,\n false\n);\n"]}
|
|
1
|
+
{"version":3,"file":"WebXRDepthSensing.js","sourceRoot":"","sources":["../../../../../lts/core/generated/XR/features/WebXRDepthSensing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC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e,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;oBACtE,QAAQ,KAAK,EAAE;wBACX,KAAK,KAAK;4BACN,OAAO,eAAe,CAAC;wBAC3B,KAAK,KAAK;4BACN,OAAO,eAAe,CAAC;qBAC9B;gBACL,CAAC,CAAC,CAAC;gBACH,MAAM,WAAW,GAAwB,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;oBACtF,QAAQ,MAAM,EAAE;wBACZ,KAAK,QAAQ;4BACT,OAAO,iBAAiB,CAAC;wBAC7B,KAAK,OAAO;4BACR,OAAO,SAAS,CAAC;qBACxB;gBACL,CAAC,CAAC,CAAC;gBAEH,OAAO,CAAC;oBACJ,YAAY,EAAE;wBACV,eAAe,EAAE,MAAM;wBACvB,oBAAoB,EAAE,WAAW;qBACpC;iBACJ,CAAC,CAAC;aACN;iBAAM;gBACH,OAAO,CAAC,EAAE,CAAC,CAAC;aACf;QACL,CAAC,CAAC,CAAC;IACP,CAAC;;AAnMD;;GAEG;AACoB,sBAAI,GAAG,gBAAgB,CAAC,aAAa,CAAC;AAE7D;;;;GAIG;AACoB,yBAAO,GAAG,CAAC,CAAC;AA4LvC,oBAAoB,CAAC,eAAe,CAChC,iBAAiB,CAAC,IAAI,EACtB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,iBAAiB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC,EACD,iBAAiB,CAAC,OAAO,EACzB,KAAK,CACR,CAAC","sourcesContent":["import { RawTexture } from \"../../Materials/Textures/rawTexture\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { Texture } from \"../../Materials/Textures/texture\";\r\nimport { Engine } from \"../../Engines/engine\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport { WebGLHardwareTexture } from \"../../Engines/WebGL/webGLHardwareTexture\";\r\nimport { InternalTexture, InternalTextureSource } from \"../../Materials/Textures/internalTexture\";\r\n\r\nexport type WebXRDepthUsage = \"cpu\" | \"gpu\";\r\nexport type WebXRDepthDataFormat = \"ushort\" | \"float\";\r\n\r\n/**\r\n * Options for Depth Sensing feature\r\n */\r\nexport interface IWebXRDepthSensingOptions {\r\n /**\r\n * The desired depth sensing usage for the session\r\n */\r\n usagePreference: WebXRDepthUsage[];\r\n /**\r\n * The desired depth sensing data format for the session\r\n */\r\n dataFormatPreference: WebXRDepthDataFormat[];\r\n}\r\n\r\ntype GetDepthInMetersType = (x: number, y: number) => number;\r\n\r\n/**\r\n * WebXR Feature for WebXR Depth Sensing Module\r\n * @since 5.49.1\r\n */\r\nexport class WebXRDepthSensing extends WebXRAbstractFeature {\r\n private _width: Nullable<number> = null;\r\n private _height: Nullable<number> = null;\r\n private _rawValueToMeters: Nullable<number> = null;\r\n private _normDepthBufferFromNormView: Nullable<XRRigidTransform> = null;\r\n private _cachedDepthBuffer: Nullable<ArrayBuffer> = null;\r\n private _cachedWebGLTexture: Nullable<WebGLTexture> = null;\r\n private _cachedDepthImageTexture: Nullable<RawTexture> = null;\r\n\r\n /**\r\n * Width of depth data. If depth data is not exist, returns null.\r\n */\r\n public get width(): Nullable<number> {\r\n return this._width;\r\n }\r\n\r\n /**\r\n * Height of depth data. If depth data is not exist, returns null.\r\n */\r\n public get height(): Nullable<number> {\r\n return this._height;\r\n }\r\n\r\n /**\r\n * Scale factor by which the raw depth values must be multiplied in order to get the depths in meters.\r\n */\r\n public get rawValueToMeters(): Nullable<number> {\r\n return this._rawValueToMeters;\r\n }\r\n\r\n /**\r\n * An XRRigidTransform that needs to be applied when indexing into the depth buffer.\r\n */\r\n public get normDepthBufferFromNormView(): Nullable<XRRigidTransform> {\r\n return this._normDepthBufferFromNormView;\r\n }\r\n\r\n /**\r\n * Describes which depth-sensing usage (\"cpu\" or \"gpu\") is used.\r\n */\r\n public get depthUsage(): WebXRDepthUsage {\r\n switch (this._xrSessionManager.session.depthUsage) {\r\n case \"cpu-optimized\":\r\n return \"cpu\";\r\n case \"gpu-optimized\":\r\n return \"gpu\";\r\n }\r\n }\r\n\r\n /**\r\n * Describes which depth sensing data format (\"ushort\" or \"float\") is used.\r\n */\r\n public get depthDataFormat(): WebXRDepthDataFormat {\r\n switch (this._xrSessionManager.session.depthDataFormat) {\r\n case \"luminance-alpha\":\r\n return \"ushort\";\r\n case \"float32\":\r\n return \"float\";\r\n }\r\n }\r\n\r\n /**\r\n * Latest cached InternalTexture which containing depth buffer information.\r\n * This can be used when the depth usage is \"gpu\".\r\n */\r\n public get latestInternalTexture(): Nullable<InternalTexture> {\r\n if (!this._cachedWebGLTexture) {\r\n return null;\r\n }\r\n\r\n const engine = this._xrSessionManager.scene.getEngine();\r\n const internalTexture = new InternalTexture(engine, InternalTextureSource.Unknown);\r\n internalTexture.isCube = false;\r\n internalTexture.invertY = false;\r\n internalTexture._useSRGBBuffer = false;\r\n internalTexture.format = this.depthDataFormat === \"ushort\" ? Constants.TEXTUREFORMAT_LUMINANCE_ALPHA : Constants.TEXTUREFORMAT_RGBA;\r\n internalTexture.generateMipMaps = false;\r\n internalTexture.type = this.depthDataFormat === \"ushort\" ? Constants.TEXTURETYPE_UNSIGNED_SHORT : Constants.TEXTURETYPE_FLOAT;\r\n internalTexture.samplingMode = Constants.TEXTURE_NEAREST_LINEAR;\r\n internalTexture.width = this.width ?? 0;\r\n internalTexture.height = this.height ?? 0;\r\n internalTexture._cachedWrapU = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._cachedWrapV = Constants.TEXTURE_WRAP_ADDRESSMODE;\r\n internalTexture._hardwareTexture = new WebGLHardwareTexture(this._cachedWebGLTexture, engine._gl);\r\n\r\n return internalTexture;\r\n }\r\n\r\n /**\r\n * cached depth buffer\r\n */\r\n public get latestDepthBuffer(): Nullable<ArrayBufferView> {\r\n if (!this._cachedDepthBuffer) {\r\n return null;\r\n }\r\n\r\n return this.depthDataFormat === \"ushort\" ? new Uint16Array(this._cachedDepthBuffer) : new Float32Array(this._cachedDepthBuffer);\r\n }\r\n\r\n /**\r\n * Event that notify when `DepthInformation.getDepthInMeters` is available.\r\n * `getDepthInMeters` method needs active XRFrame (not available for cached XRFrame)\r\n */\r\n public onGetDepthInMetersAvailable: Observable<GetDepthInMetersType> = new Observable<GetDepthInMetersType>();\r\n\r\n /**\r\n * Latest cached Texture of depth image which is made from the depth buffer data.\r\n */\r\n public get latestDepthImageTexture(): Nullable<RawTexture> {\r\n return this._cachedDepthImageTexture;\r\n }\r\n\r\n /**\r\n * XRWebGLBinding which is used for acquiring WebGLDepthInformation\r\n */\r\n private _glBinding?: XRWebGLBinding;\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.DEPTH_SENSING;\r\n\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Creates a new instance of the depth sensing feature\r\n * @param _xrSessionManager the WebXRSessionManager\r\n * @param options options for WebXR Depth Sensing Feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, public readonly options: IWebXRDepthSensingOptions) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"depth-sensing\";\r\n\r\n // https://immersive-web.github.io/depth-sensing/\r\n Tools.Warn(\"depth-sensing is an experimental and unstable feature.\");\r\n }\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(force?: boolean | undefined): boolean {\r\n if (!super.attach(force)) {\r\n return false;\r\n }\r\n\r\n const isBothDepthUsageAndFormatNull = this._xrSessionManager.session.depthDataFormat == null || this._xrSessionManager.session.depthUsage == null;\r\n if (isBothDepthUsageAndFormatNull) {\r\n return false;\r\n }\r\n\r\n this._glBinding = new XRWebGLBinding(this._xrSessionManager.session, this._xrSessionManager.scene.getEngine()._gl);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n this._cachedDepthImageTexture?.dispose();\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: XRFrame): void {\r\n const referenceSPace = this._xrSessionManager.referenceSpace;\r\n\r\n const pose = _xrFrame.getViewerPose(referenceSPace);\r\n if (pose == null) {\r\n return;\r\n }\r\n\r\n for (const view of pose.views) {\r\n switch (this.depthUsage) {\r\n case \"cpu\":\r\n this._updateDepthInformationAndTextureCPUDepthUsage(_xrFrame, view, this.depthDataFormat);\r\n break;\r\n\r\n case \"gpu\":\r\n if (!this._glBinding) {\r\n break;\r\n }\r\n\r\n this._updateDepthInformationAndTextureWebGLDepthUsage(this._glBinding, view, this.depthDataFormat);\r\n break;\r\n\r\n default:\r\n Tools.Error(\"Unknown depth usage\");\r\n this.detach();\r\n break;\r\n }\r\n }\r\n }\r\n\r\n private _updateDepthInformationAndTextureCPUDepthUsage(frame: XRFrame, view: XRView, dataFormat: WebXRDepthDataFormat): void {\r\n const depthInfo = frame.getDepthInformation(view);\r\n if (depthInfo === null) {\r\n return;\r\n }\r\n\r\n const { data, width, height, rawValueToMeters, getDepthInMeters } = depthInfo as XRCPUDepthInformation;\r\n\r\n this._width = width;\r\n this._height = height;\r\n this._rawValueToMeters = rawValueToMeters;\r\n this._cachedDepthBuffer = data;\r\n\r\n // to avoid Illegal Invocation error, bind `this`\r\n this.onGetDepthInMetersAvailable.notifyObservers(getDepthInMeters.bind(depthInfo));\r\n\r\n if (!this._cachedDepthImageTexture) {\r\n this._cachedDepthImageTexture = RawTexture.CreateRTexture(\r\n null,\r\n width,\r\n height,\r\n this._xrSessionManager.scene,\r\n false,\r\n true,\r\n Texture.NEAREST_SAMPLINGMODE,\r\n Engine.TEXTURETYPE_FLOAT\r\n );\r\n }\r\n\r\n switch (dataFormat) {\r\n case \"ushort\":\r\n this._cachedDepthImageTexture.update(Float32Array.from(new Uint16Array(data)).map((value) => value * rawValueToMeters));\r\n break;\r\n\r\n case \"float\":\r\n this._cachedDepthImageTexture.update(new Float32Array(data).map((value) => value * rawValueToMeters));\r\n break;\r\n\r\n default:\r\n break;\r\n }\r\n }\r\n\r\n private _updateDepthInformationAndTextureWebGLDepthUsage(webglBinding: XRWebGLBinding, view: XRView, dataFormat: WebXRDepthDataFormat): void {\r\n const depthInfo = webglBinding.getDepthInformation(view);\r\n if (depthInfo === null) {\r\n return;\r\n }\r\n\r\n const { texture, width, height } = depthInfo as XRWebGLDepthInformation;\r\n\r\n this._width = width;\r\n this._height = height;\r\n this._cachedWebGLTexture = texture;\r\n\r\n const scene = this._xrSessionManager.scene;\r\n const engine = scene.getEngine();\r\n const internalTexture = engine.wrapWebGLTexture(texture);\r\n\r\n if (!this._cachedDepthImageTexture) {\r\n this._cachedDepthImageTexture = RawTexture.CreateRTexture(\r\n null,\r\n width,\r\n height,\r\n scene,\r\n false,\r\n true,\r\n Texture.NEAREST_SAMPLINGMODE,\r\n dataFormat === \"ushort\" ? Engine.TEXTURETYPE_UNSIGNED_BYTE : Engine.TEXTURETYPE_FLOAT\r\n );\r\n }\r\n\r\n this._cachedDepthImageTexture._texture = internalTexture;\r\n }\r\n\r\n /**\r\n * Extends the session init object if needed\r\n * @returns augmentation object for the xr session init object.\r\n */\r\n public getXRSessionInitExtension(): Promise<Partial<XRSessionInit>> {\r\n const isDepthUsageDeclared = this.options.usagePreference != null && this.options.usagePreference.length !== 0;\r\n const isDataFormatDeclared = this.options.dataFormatPreference != null && this.options.dataFormatPreference.length !== 0;\r\n\r\n return new Promise((resolve) => {\r\n if (isDepthUsageDeclared && isDataFormatDeclared) {\r\n const usages: XRDepthUsage[] = this.options.usagePreference.map((usage) => {\r\n switch (usage) {\r\n case \"cpu\":\r\n return \"cpu-optimized\";\r\n case \"gpu\":\r\n return \"gpu-optimized\";\r\n }\r\n });\r\n const dataFormats: XRDepthDataFormat[] = this.options.dataFormatPreference.map((format) => {\r\n switch (format) {\r\n case \"ushort\":\r\n return \"luminance-alpha\";\r\n case \"float\":\r\n return \"float32\";\r\n }\r\n });\r\n\r\n resolve({\r\n depthSensing: {\r\n usagePreference: usages,\r\n dataFormatPreference: dataFormats,\r\n },\r\n });\r\n } else {\r\n resolve({});\r\n }\r\n });\r\n }\r\n}\r\n\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRDepthSensing.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRDepthSensing(xrSessionManager, options);\r\n },\r\n WebXRDepthSensing.Version,\r\n false\r\n);\r\n"]}
|