@babylonjs/core 9.12.1 → 9.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Animations/runtimeAnimation.js +11 -0
- package/Animations/runtimeAnimation.js.map +1 -1
- package/AudioV2/abstractAudio/abstractSound.d.ts +2 -1
- package/AudioV2/abstractAudio/abstractSound.js +3 -2
- package/AudioV2/abstractAudio/abstractSound.js.map +1 -1
- package/AudioV2/abstractAudio/abstractSoundInstance.d.ts +1 -1
- package/AudioV2/abstractAudio/abstractSoundInstance.js.map +1 -1
- package/AudioV2/abstractAudio/staticSound.d.ts +6 -0
- package/AudioV2/abstractAudio/staticSound.js +9 -1
- package/AudioV2/abstractAudio/staticSound.js.map +1 -1
- package/AudioV2/abstractAudio/streamingSound.d.ts +6 -0
- package/AudioV2/abstractAudio/streamingSound.js +9 -1
- package/AudioV2/abstractAudio/streamingSound.js.map +1 -1
- package/AudioV2/webAudio/webAudioStaticSound.d.ts +1 -1
- package/AudioV2/webAudio/webAudioStaticSound.js +6 -3
- package/AudioV2/webAudio/webAudioStaticSound.js.map +1 -1
- package/AudioV2/webAudio/webAudioStreamingSound.d.ts +1 -1
- package/AudioV2/webAudio/webAudioStreamingSound.js +7 -4
- package/AudioV2/webAudio/webAudioStreamingSound.js.map +1 -1
- package/Cameras/arcRotateCamera.pure.js +9 -3
- package/Cameras/arcRotateCamera.pure.js.map +1 -1
- package/Cameras/targetCamera.pure.js +18 -18
- package/Cameras/targetCamera.pure.js.map +1 -1
- package/Collisions/gpuPicker.d.ts +111 -4
- package/Collisions/gpuPicker.js +696 -119
- package/Collisions/gpuPicker.js.map +1 -1
- package/Engines/Native/nativeInterfaces.d.ts +4 -2
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/Native/nativeRenderTargetWrapper.d.ts +3 -0
- package/Engines/Native/nativeRenderTargetWrapper.js +24 -1
- package/Engines/Native/nativeRenderTargetWrapper.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.videoTexture.pure.js +16 -3
- package/Engines/WebGPU/Extensions/engine.videoTexture.pure.js.map +1 -1
- package/Engines/abstractEngine.pure.d.ts +8 -1
- package/Engines/abstractEngine.pure.js +4 -3
- package/Engines/abstractEngine.pure.js.map +1 -1
- package/Engines/engine.d.ts +113 -0
- package/Engines/nullEngine.pure.js +5 -1
- package/Engines/nullEngine.pure.js.map +1 -1
- package/Engines/thinNativeEngine.pure.d.ts +5 -0
- package/Engines/thinNativeEngine.pure.js +158 -13
- package/Engines/thinNativeEngine.pure.js.map +1 -1
- package/FlowGraph/flowGraph.js +9 -0
- package/FlowGraph/flowGraph.js.map +1 -1
- package/FlowGraph/flowGraphDataConnection.pure.d.ts +14 -0
- package/FlowGraph/flowGraphDataConnection.pure.js +38 -1
- package/FlowGraph/flowGraphDataConnection.pure.js.map +1 -1
- package/FlowGraph/serialization.d.ts +11 -0
- package/FlowGraph/serialization.js +11 -1
- package/FlowGraph/serialization.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.d.ts +2 -2
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.js +43 -51
- package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.js.map +1 -1
- package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.pure.d.ts +0 -1
- package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.pure.js +63 -35
- package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.pure.js.map +1 -1
- package/Lights/Clustered/clusteredLightContainer.pure.d.ts +1 -1
- package/Lights/Clustered/clusteredLightContainer.pure.js +2 -2
- package/Lights/Clustered/clusteredLightContainer.pure.js.map +1 -1
- package/Lights/areaLight.pure.js +5 -0
- package/Lights/areaLight.pure.js.map +1 -1
- package/Lights/light.d.ts +4 -2
- package/Lights/light.js +10 -4
- package/Lights/light.js.map +1 -1
- package/Lights/rectAreaLight.pure.d.ts +17 -0
- package/Lights/rectAreaLight.pure.js +67 -0
- package/Lights/rectAreaLight.pure.js.map +1 -1
- package/Loading/Plugins/babylonFileLoader.pure.js +1 -1
- package/Loading/Plugins/babylonFileLoader.pure.js.map +1 -1
- package/Loading/sceneLoader.d.ts +5 -1
- package/Loading/sceneLoader.js +298 -401
- package/Loading/sceneLoader.js.map +1 -1
- package/Materials/GaussianSplatting/gaussianSplattingGpuPickingMaterialPlugin.pure.d.ts +15 -0
- package/Materials/GaussianSplatting/gaussianSplattingGpuPickingMaterialPlugin.pure.js +34 -1
- package/Materials/GaussianSplatting/gaussianSplattingGpuPickingMaterialPlugin.pure.js.map +1 -1
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.pure.d.ts +9 -0
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.pure.js +26 -2
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.pure.js.map +1 -1
- package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.pure.js +3 -1
- package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.pure.js.map +1 -1
- package/Materials/Textures/HTML/htmlInCanvasPolyfill.d.ts +43 -0
- package/Materials/Textures/HTML/htmlInCanvasPolyfill.js +64 -0
- package/Materials/Textures/HTML/htmlInCanvasPolyfill.js.map +1 -0
- package/Materials/Textures/HTML/htmlInteractionManager.d.ts +69 -0
- package/Materials/Textures/HTML/htmlInteractionManager.js +130 -0
- package/Materials/Textures/HTML/htmlInteractionManager.js.map +1 -0
- package/Materials/Textures/HTML/htmlRaycastInteractionManager.d.ts +84 -0
- package/Materials/Textures/HTML/htmlRaycastInteractionManager.js +246 -0
- package/Materials/Textures/HTML/htmlRaycastInteractionManager.js.map +1 -0
- package/Materials/Textures/HTML/htmlTexture.d.ts +148 -0
- package/Materials/Textures/HTML/htmlTexture.js +455 -0
- package/Materials/Textures/HTML/htmlTexture.js.map +1 -0
- package/Materials/Textures/HTML/index.d.ts +4 -0
- package/Materials/Textures/HTML/index.js +5 -0
- package/Materials/Textures/HTML/index.js.map +1 -0
- package/Materials/Textures/HTML/pure.d.ts +5 -0
- package/Materials/Textures/HTML/pure.js +6 -0
- package/Materials/Textures/HTML/pure.js.map +1 -0
- package/Materials/Textures/index.d.ts +1 -0
- package/Materials/Textures/index.js +1 -1
- package/Materials/Textures/index.js.map +1 -1
- package/Materials/Textures/pure.d.ts +1 -0
- package/Materials/Textures/pure.js +1 -0
- package/Materials/Textures/pure.js.map +1 -1
- package/Materials/Textures/videoTexture.pure.d.ts +3 -0
- package/Materials/Textures/videoTexture.pure.js +30 -0
- package/Materials/Textures/videoTexture.pure.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.d.ts +36 -0
- package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.js +56 -0
- package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingSortWorker.d.ts +3 -1
- package/Meshes/GaussianSplatting/gaussianSplattingSortWorker.js +210 -48
- package/Meshes/GaussianSplatting/gaussianSplattingSortWorker.js.map +1 -1
- package/Misc/tools.pure.js +1 -1
- package/Misc/tools.pure.js.map +1 -1
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.pure.d.ts +1 -0
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.pure.js +34 -0
- package/Rendering/IBLShadows/iblShadowsVoxelRenderer.pure.js.map +1 -1
- package/Shaders/ShadersInclude/gaussianSplatting.js +1 -0
- package/Shaders/ShadersInclude/gaussianSplatting.js.map +1 -1
- package/Shaders/gaussianSplatting.fragment.js +17 -1
- package/Shaders/gaussianSplatting.fragment.js.map +1 -1
- package/Shaders/gaussianSplatting.vertex.js +1 -1
- package/Shaders/gaussianSplatting.vertex.js.map +1 -1
- package/Shaders/gaussianSplattingDepth.vertex.js +1 -1
- package/Shaders/gaussianSplattingDepth.vertex.js.map +1 -1
- package/Shaders/picking.fragment.js +39 -3
- package/Shaders/picking.fragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/gaussianSplatting.js +3 -1
- package/ShadersWGSL/ShadersInclude/gaussianSplatting.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/openpbrIblFunctions.js +4 -3
- package/ShadersWGSL/ShadersInclude/openpbrIblFunctions.js.map +1 -1
- package/ShadersWGSL/gaussianSplatting.fragment.js +14 -1
- package/ShadersWGSL/gaussianSplatting.fragment.js.map +1 -1
- package/ShadersWGSL/gaussianSplatting.vertex.js +2 -2
- package/ShadersWGSL/gaussianSplatting.vertex.js.map +1 -1
- package/ShadersWGSL/gaussianSplattingDepth.vertex.js +2 -2
- package/ShadersWGSL/gaussianSplattingDepth.vertex.js.map +1 -1
- package/ShadersWGSL/picking.fragment.js +22 -1
- package/ShadersWGSL/picking.fragment.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gaussianSplattingBlock.pure.js","sourceRoot":"","sources":["../../../../../../../dev/core/src/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.pure.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,qCAAqC,EAAE,MAAM,mDAAmD,CAAC;AAE1G,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,iBAAiB;IACzD;;;OAGG;IACH,YAAmB,IAAY;QAC3B,KAAK,CAAC,IAAI,EAAE,wBAAwB,CAAC,MAAM,CAAC,CAAC;QAE7C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAEtB,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,qCAAqC,CAAC,OAAO,EAAE,KAAK,EAAE,wBAAwB,CAAC,M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imports */\r\n\r\nimport { NodeMaterialBlock } from \"../../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport { type NodeMaterialBuildState } from \"../../nodeMaterialBuildState\";\r\nimport { NodeMaterialBlockTargets } from \"../../Enums/nodeMaterialBlockTargets\";\r\nimport { type NodeMaterialConnectionPoint } from \"../../nodeMaterialBlockConnectionPoint\";\r\nimport { VertexBuffer } from \"core/Meshes/buffer\";\r\nimport { type GaussianSplattingMesh } from \"core/Meshes/GaussianSplatting/gaussianSplattingMesh.pure\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\nimport { type AbstractMesh } from \"core/Meshes/abstractMesh.pure\";\r\nimport { type NodeMaterial, type NodeMaterialDefines } from \"../../nodeMaterial.pure\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\n\r\n/**\r\n * Block used for the Gaussian Splatting\r\n */\r\nexport class GaussianSplattingBlock extends NodeMaterialBlock {\r\n /**\r\n * Create a new GaussianSplattingBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Vertex);\r\n\r\n this._isUnique = true;\r\n\r\n this.registerInput(\"splatPosition\", NodeMaterialBlockConnectionPointTypes.Vector3, false, NodeMaterialBlockTargets.Vertex);\r\n this.registerInput(\"splatScale\", NodeMaterialBlockConnectionPointTypes.Vector2, true, NodeMaterialBlockTargets.Vertex);\r\n this.registerInput(\"world\", NodeMaterialBlockConnectionPointTypes.Matrix, false, NodeMaterialBlockTargets.Vertex);\r\n this.registerInput(\"view\", NodeMaterialBlockConnectionPointTypes.Matrix, false, NodeMaterialBlockTargets.Vertex);\r\n this.registerInput(\"projection\", NodeMaterialBlockConnectionPointTypes.Matrix, false, NodeMaterialBlockTargets.Vertex);\r\n\r\n this.registerOutput(\"splatVertex\", NodeMaterialBlockConnectionPointTypes.Vector4, NodeMaterialBlockTargets.Vertex);\r\n this.registerOutput(\"SH\", NodeMaterialBlockConnectionPointTypes.Color3, NodeMaterialBlockTargets.Vertex);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public override getClassName() {\r\n return \"GaussianSplattingBlock\";\r\n }\r\n\r\n /**\r\n * Gets the position input component\r\n */\r\n public get splatPosition(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the scale input component\r\n */\r\n public get splatScale(): NodeMaterialConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the View matrix input component\r\n */\r\n public get world(): NodeMaterialConnectionPoint {\r\n return this._inputs[2];\r\n }\r\n\r\n /**\r\n * Gets the View matrix input component\r\n */\r\n public get view(): NodeMaterialConnectionPoint {\r\n return this._inputs[3];\r\n }\r\n\r\n /**\r\n * Gets the projection matrix input component\r\n */\r\n public get projection(): NodeMaterialConnectionPoint {\r\n return this._inputs[4];\r\n }\r\n\r\n /**\r\n * Gets the splatVertex output component\r\n */\r\n public get splatVertex(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Gets the SH output contribution\r\n */\r\n public get SH(): NodeMaterialConnectionPoint {\r\n return this._outputs[1];\r\n }\r\n\r\n /**\r\n * Initialize the block and prepare the context for build\r\n * @param state defines the state that will be used for the build\r\n */\r\n public override initialize(state: NodeMaterialBuildState) {\r\n state._excludeVariableName(\"focal\");\r\n state._excludeVariableName(\"invViewport\");\r\n state._excludeVariableName(\"kernelSize\");\r\n state._excludeVariableName(\"eyePosition\");\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this._initShaderSourceAsync(state.shaderLanguage);\r\n }\r\n\r\n private async _initShaderSourceAsync(shaderLanguage: ShaderLanguage) {\r\n this._codeIsReady = false;\r\n\r\n if (shaderLanguage === ShaderLanguage.WGSL) {\r\n await Promise.all([\r\n import(\"../../../../ShadersWGSL/ShadersInclude/gaussianSplattingVertexDeclaration\"),\r\n import(\"../../../../ShadersWGSL/ShadersInclude/gaussianSplatting\"),\r\n import(\"../../../../ShadersWGSL/ShadersInclude/helperFunctions\"),\r\n ]);\r\n } else {\r\n await Promise.all([\r\n import(\"../../../../Shaders/ShadersInclude/gaussianSplattingVertexDeclaration\"),\r\n import(\"../../../../Shaders/ShadersInclude/gaussianSplatting\"),\r\n import(\"../../../../Shaders/ShadersInclude/helperFunctions\"),\r\n ]);\r\n }\r\n\r\n this._codeIsReady = true;\r\n this.onCodeIsReadyObservable.notifyObservers(this);\r\n }\r\n /**\r\n * Update defines for shader compilation\r\n * @param defines defines the material defines to update\r\n * @param nodeMaterial defines the node material requesting the update\r\n * @param mesh defines the mesh to be rendered\r\n */\r\n public override prepareDefines(defines: NodeMaterialDefines, nodeMaterial: NodeMaterial, mesh?: AbstractMesh) {\r\n if (!mesh) {\r\n return;\r\n }\r\n\r\n if (mesh.getClassName() == \"GaussianSplattingMesh\") {\r\n defines.setValue(\"SH_DEGREE\", (<GaussianSplattingMesh>mesh).shDegree, true);\r\n }\r\n }\r\n\r\n protected override _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n if (state.target === NodeMaterialBlockTargets.Fragment) {\r\n return;\r\n }\r\n\r\n state.sharedData.blocksWithDefines.push(this);\r\n\r\n const comments = `//${this.name}`;\r\n state._emitFunctionFromInclude(\"gaussianSplattingVertexDeclaration\", comments);\r\n state._emitFunctionFromInclude(\"gaussianSplatting\", comments);\r\n state._emitFunctionFromInclude(\"helperFunctions\", comments);\r\n state._emitUniformFromString(\"focal\", NodeMaterialBlockConnectionPointTypes.Vector2);\r\n state._emitUniformFromString(\"invViewport\", NodeMaterialBlockConnectionPointTypes.Vector2);\r\n state._emitUniformFromString(\"kernelSize\", NodeMaterialBlockConnectionPointTypes.Float);\r\n state._emitUniformFromString(\"eyePosition\", NodeMaterialBlockConnectionPointTypes.Vector3);\r\n state.attributes.push(VertexBuffer.PositionKind);\r\n state.attributes.push(\"splatIndex0\");\r\n state.attributes.push(\"splatIndex1\");\r\n state.attributes.push(\"splatIndex2\");\r\n state.attributes.push(\"splatIndex3\");\r\n state.sharedData.nodeMaterial.backFaceCulling = false;\r\n\r\n const splatPosition = this.splatPosition;\r\n const splatScale = this.splatScale;\r\n const world = this.world;\r\n const view = this.view;\r\n const projection = this.projection;\r\n const output = this.splatVertex;\r\n const sh = this.SH;\r\n\r\n const addF = state.fSuffix;\r\n let splatScaleParameter = `vec2${addF}(1.,1.)`;\r\n if (splatScale.isConnected) {\r\n splatScaleParameter = splatScale.associatedVariableName;\r\n }\r\n\r\n let input = \"position\";\r\n let uniforms = \"\";\r\n if (state.shaderLanguage === ShaderLanguage.WGSL) {\r\n input = \"input.position\";\r\n uniforms = \", uniforms.focal, uniforms.invViewport, uniforms.kernelSize\";\r\n }\r\n if (this.SH.isConnected) {\r\n state.compilationString += `#if SH_DEGREE > 0\\n`;\r\n\r\n if (state.shaderLanguage === ShaderLanguage.WGSL) {\r\n state.compilationString += `let worldRot: mat3x3f = mat3x3f(${world.associatedVariableName}[0].xyz, ${world.associatedVariableName}[1].xyz, ${world.associatedVariableName}[2].xyz);`;\r\n state.compilationString += `let normWorldRot: mat3x3f = inverseMat3(worldRot);`;\r\n state.compilationString += `var eyeToSplatLocalSpace: vec3f = normalize(normWorldRot * (${splatPosition.associatedVariableName}.xyz - uniforms.eyePosition));\\n`;\r\n } else {\r\n state.compilationString += `mat3 worldRot = mat3(${world.associatedVariableName});`;\r\n state.compilationString += `mat3 normWorldRot = inverseMat3(worldRot);`;\r\n state.compilationString += `vec3 eyeToSplatLocalSpace = normalize(normWorldRot * (${splatPosition.associatedVariableName}.xyz - eyePosition));\\n`;\r\n }\r\n\r\n state.compilationString += `${state._declareOutput(sh)} = computeSH(splat, eyeToSplatLocalSpace);\\n`;\r\n state.compilationString += `#else\\n`;\r\n state.compilationString += `${state._declareOutput(sh)} = vec3${addF}(0.,0.,0.);\\n`;\r\n state.compilationString += `#endif;\\n`;\r\n } else {\r\n state.compilationString += `${state._declareOutput(sh)} = vec3${addF}(0.,0.,0.);`;\r\n }\r\n\r\n state.compilationString += `${state._declareOutput(output)} = gaussianSplatting(${input}.xy, ${splatPosition.associatedVariableName}, ${splatScaleParameter}, covA, covB, ${world.associatedVariableName}, ${view.associatedVariableName}, ${projection.associatedVariableName}${uniforms});\\n`;\r\n return this;\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Register side effects for gaussianSplattingBlock.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\nexport function RegisterGaussianSplattingBlock(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n RegisterClass(\"BABYLON.GaussianSplattingBlock\", GaussianSplattingBlock);\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"gaussianSplattingBlock.pure.js","sourceRoot":"","sources":["../../../../../../../dev/core/src/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.pure.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,qCAAqC,EAAE,MAAM,mDAAmD,CAAC;AAE1G,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,iBAAiB;IACzD;;;OAGG;IACH,YAAmB,IAAY;QAC3B,KAAK,CAAC,IAAI,EAAE,wBAAwB,CAAC,MAAM,CAAC,CAAC;QAE7C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAEtB,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,qCAAqC,CAAC,OAAO,EAAE,KAAK,EAAE,wBAAwB,CAAC,MAAM,CAAC,CAAC;QAC3H,IAAI,CAAC,aAAa,CA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Aa,CAAC,gCAAgC,EAAE,sBAAsB,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["/** This file must only contain pure code and pure imports */\r\n\r\nimport { NodeMaterialBlock } from \"../../nodeMaterialBlock\";\r\nimport { NodeMaterialBlockConnectionPointTypes } from \"../../Enums/nodeMaterialBlockConnectionPointTypes\";\r\nimport { type NodeMaterialBuildState } from \"../../nodeMaterialBuildState\";\r\nimport { NodeMaterialBlockTargets } from \"../../Enums/nodeMaterialBlockTargets\";\r\nimport { type NodeMaterialConnectionPoint } from \"../../nodeMaterialBlockConnectionPoint\";\r\nimport { VertexBuffer } from \"core/Meshes/buffer\";\r\nimport { type GaussianSplattingMesh } from \"core/Meshes/GaussianSplatting/gaussianSplattingMesh.pure\";\r\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\r\nimport { type AbstractMesh } from \"core/Meshes/abstractMesh.pure\";\r\nimport { type NodeMaterial, type NodeMaterialDefines } from \"../../nodeMaterial.pure\";\r\nimport { RegisterClass } from \"../../../../Misc/typeStore\";\r\n\r\n/**\r\n * Block used for the Gaussian Splatting\r\n */\r\nexport class GaussianSplattingBlock extends NodeMaterialBlock {\r\n /**\r\n * Create a new GaussianSplattingBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name, NodeMaterialBlockTargets.Vertex);\r\n\r\n this._isUnique = true;\r\n\r\n this.registerInput(\"splatPosition\", NodeMaterialBlockConnectionPointTypes.Vector3, false, NodeMaterialBlockTargets.Vertex);\r\n this.registerInput(\"splatScale\", NodeMaterialBlockConnectionPointTypes.Vector2, true, NodeMaterialBlockTargets.Vertex);\r\n this.registerInput(\"world\", NodeMaterialBlockConnectionPointTypes.Matrix, false, NodeMaterialBlockTargets.Vertex);\r\n this.registerInput(\"view\", NodeMaterialBlockConnectionPointTypes.Matrix, false, NodeMaterialBlockTargets.Vertex);\r\n this.registerInput(\"projection\", NodeMaterialBlockConnectionPointTypes.Matrix, false, NodeMaterialBlockTargets.Vertex);\r\n\r\n this.registerOutput(\"splatVertex\", NodeMaterialBlockConnectionPointTypes.Vector4, NodeMaterialBlockTargets.Vertex);\r\n this.registerOutput(\"SH\", NodeMaterialBlockConnectionPointTypes.Color3, NodeMaterialBlockTargets.Vertex);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public override getClassName() {\r\n return \"GaussianSplattingBlock\";\r\n }\r\n\r\n /**\r\n * Gets the position input component\r\n */\r\n public get splatPosition(): NodeMaterialConnectionPoint {\r\n return this._inputs[0];\r\n }\r\n\r\n /**\r\n * Gets the scale input component\r\n */\r\n public get splatScale(): NodeMaterialConnectionPoint {\r\n return this._inputs[1];\r\n }\r\n\r\n /**\r\n * Gets the View matrix input component\r\n */\r\n public get world(): NodeMaterialConnectionPoint {\r\n return this._inputs[2];\r\n }\r\n\r\n /**\r\n * Gets the View matrix input component\r\n */\r\n public get view(): NodeMaterialConnectionPoint {\r\n return this._inputs[3];\r\n }\r\n\r\n /**\r\n * Gets the projection matrix input component\r\n */\r\n public get projection(): NodeMaterialConnectionPoint {\r\n return this._inputs[4];\r\n }\r\n\r\n /**\r\n * Gets the splatVertex output component\r\n */\r\n public get splatVertex(): NodeMaterialConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Gets the SH output contribution\r\n */\r\n public get SH(): NodeMaterialConnectionPoint {\r\n return this._outputs[1];\r\n }\r\n\r\n /**\r\n * Initialize the block and prepare the context for build\r\n * @param state defines the state that will be used for the build\r\n */\r\n public override initialize(state: NodeMaterialBuildState) {\r\n state._excludeVariableName(\"focal\");\r\n state._excludeVariableName(\"invViewport\");\r\n state._excludeVariableName(\"kernelSize\");\r\n state._excludeVariableName(\"minPixelSize\");\r\n state._excludeVariableName(\"eyePosition\");\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this._initShaderSourceAsync(state.shaderLanguage);\r\n }\r\n\r\n private async _initShaderSourceAsync(shaderLanguage: ShaderLanguage) {\r\n this._codeIsReady = false;\r\n\r\n if (shaderLanguage === ShaderLanguage.WGSL) {\r\n await Promise.all([\r\n import(\"../../../../ShadersWGSL/ShadersInclude/gaussianSplattingVertexDeclaration\"),\r\n import(\"../../../../ShadersWGSL/ShadersInclude/gaussianSplatting\"),\r\n import(\"../../../../ShadersWGSL/ShadersInclude/helperFunctions\"),\r\n ]);\r\n } else {\r\n await Promise.all([\r\n import(\"../../../../Shaders/ShadersInclude/gaussianSplattingVertexDeclaration\"),\r\n import(\"../../../../Shaders/ShadersInclude/gaussianSplatting\"),\r\n import(\"../../../../Shaders/ShadersInclude/helperFunctions\"),\r\n ]);\r\n }\r\n\r\n this._codeIsReady = true;\r\n this.onCodeIsReadyObservable.notifyObservers(this);\r\n }\r\n /**\r\n * Update defines for shader compilation\r\n * @param defines defines the material defines to update\r\n * @param nodeMaterial defines the node material requesting the update\r\n * @param mesh defines the mesh to be rendered\r\n */\r\n public override prepareDefines(defines: NodeMaterialDefines, nodeMaterial: NodeMaterial, mesh?: AbstractMesh) {\r\n if (!mesh) {\r\n return;\r\n }\r\n\r\n if (mesh.getClassName() == \"GaussianSplattingMesh\") {\r\n defines.setValue(\"SH_DEGREE\", (<GaussianSplattingMesh>mesh).shDegree, true);\r\n }\r\n }\r\n\r\n protected override _buildBlock(state: NodeMaterialBuildState) {\r\n super._buildBlock(state);\r\n\r\n if (state.target === NodeMaterialBlockTargets.Fragment) {\r\n return;\r\n }\r\n\r\n state.sharedData.blocksWithDefines.push(this);\r\n\r\n const comments = `//${this.name}`;\r\n state._emitFunctionFromInclude(\"gaussianSplattingVertexDeclaration\", comments);\r\n state._emitFunctionFromInclude(\"gaussianSplatting\", comments);\r\n state._emitFunctionFromInclude(\"helperFunctions\", comments);\r\n state._emitUniformFromString(\"focal\", NodeMaterialBlockConnectionPointTypes.Vector2);\r\n state._emitUniformFromString(\"invViewport\", NodeMaterialBlockConnectionPointTypes.Vector2);\r\n state._emitUniformFromString(\"kernelSize\", NodeMaterialBlockConnectionPointTypes.Float);\r\n state._emitUniformFromString(\"minPixelSize\", NodeMaterialBlockConnectionPointTypes.Float);\r\n state._emitUniformFromString(\"eyePosition\", NodeMaterialBlockConnectionPointTypes.Vector3);\r\n state.attributes.push(VertexBuffer.PositionKind);\r\n state.attributes.push(\"splatIndex0\");\r\n state.attributes.push(\"splatIndex1\");\r\n state.attributes.push(\"splatIndex2\");\r\n state.attributes.push(\"splatIndex3\");\r\n state.sharedData.nodeMaterial.backFaceCulling = false;\r\n\r\n const splatPosition = this.splatPosition;\r\n const splatScale = this.splatScale;\r\n const world = this.world;\r\n const view = this.view;\r\n const projection = this.projection;\r\n const output = this.splatVertex;\r\n const sh = this.SH;\r\n\r\n const addF = state.fSuffix;\r\n let splatScaleParameter = `vec2${addF}(1.,1.)`;\r\n if (splatScale.isConnected) {\r\n splatScaleParameter = splatScale.associatedVariableName;\r\n }\r\n\r\n let input = \"position\";\r\n let uniforms = \"\";\r\n if (state.shaderLanguage === ShaderLanguage.WGSL) {\r\n input = \"input.position\";\r\n uniforms = \", uniforms.focal, uniforms.invViewport, uniforms.kernelSize, uniforms.minPixelSize\";\r\n }\r\n if (this.SH.isConnected) {\r\n state.compilationString += `#if SH_DEGREE > 0\\n`;\r\n\r\n if (state.shaderLanguage === ShaderLanguage.WGSL) {\r\n state.compilationString += `let worldRot: mat3x3f = mat3x3f(${world.associatedVariableName}[0].xyz, ${world.associatedVariableName}[1].xyz, ${world.associatedVariableName}[2].xyz);`;\r\n state.compilationString += `let normWorldRot: mat3x3f = inverseMat3(worldRot);`;\r\n state.compilationString += `var eyeToSplatLocalSpace: vec3f = normalize(normWorldRot * (${splatPosition.associatedVariableName}.xyz - uniforms.eyePosition));\\n`;\r\n } else {\r\n state.compilationString += `mat3 worldRot = mat3(${world.associatedVariableName});`;\r\n state.compilationString += `mat3 normWorldRot = inverseMat3(worldRot);`;\r\n state.compilationString += `vec3 eyeToSplatLocalSpace = normalize(normWorldRot * (${splatPosition.associatedVariableName}.xyz - eyePosition));\\n`;\r\n }\r\n\r\n state.compilationString += `${state._declareOutput(sh)} = computeSH(splat, eyeToSplatLocalSpace);\\n`;\r\n state.compilationString += `#else\\n`;\r\n state.compilationString += `${state._declareOutput(sh)} = vec3${addF}(0.,0.,0.);\\n`;\r\n state.compilationString += `#endif;\\n`;\r\n } else {\r\n state.compilationString += `${state._declareOutput(sh)} = vec3${addF}(0.,0.,0.);`;\r\n }\r\n\r\n state.compilationString += `${state._declareOutput(output)} = gaussianSplatting(${input}.xy, ${splatPosition.associatedVariableName}, ${splatScaleParameter}, covA, covB, ${world.associatedVariableName}, ${view.associatedVariableName}, ${projection.associatedVariableName}${uniforms});\\n`;\r\n return this;\r\n }\r\n}\r\n\r\nlet _Registered = false;\r\n/**\r\n * Register side effects for gaussianSplattingBlock.\r\n * Safe to call multiple times; only the first call has an effect.\r\n */\r\nexport function RegisterGaussianSplattingBlock(): void {\r\n if (_Registered) {\r\n return;\r\n }\r\n _Registered = true;\r\n\r\n RegisterClass(\"BABYLON.GaussianSplattingBlock\", GaussianSplattingBlock);\r\n}\r\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** This module has no top-level side effects: it only declares the optional HTML-in-Canvas polyfill installer */
|
|
2
|
+
/**
|
|
3
|
+
* Shape of the `three-html-render` polyfill module (only the parts this wrapper uses).
|
|
4
|
+
*/
|
|
5
|
+
export interface IHtmlInCanvasPolyfillModule {
|
|
6
|
+
/** Installs the WICG HTML-in-Canvas polyfill onto the relevant DOM prototypes. */
|
|
7
|
+
installHtmlInCanvasPolyfill?: (options?: {
|
|
8
|
+
force?: boolean;
|
|
9
|
+
}) => void;
|
|
10
|
+
/** Removes a previously installed polyfill. */
|
|
11
|
+
uninstallHtmlInCanvasPolyfill?: () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Options for {@link InstallHtmlInCanvasPolyfill}.
|
|
15
|
+
*/
|
|
16
|
+
export interface IInstallHtmlInCanvasPolyfillOptions {
|
|
17
|
+
/** Install the polyfill even when the browser already supports the API natively (default false). */
|
|
18
|
+
force?: boolean;
|
|
19
|
+
/** Module specifier to lazily import the polyfill from (default `"three-html-render"`). */
|
|
20
|
+
moduleSpecifier?: string;
|
|
21
|
+
/** A pre-imported polyfill module to use instead of dynamically importing one. */
|
|
22
|
+
polyfillModule?: IHtmlInCanvasPolyfillModule;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Detects whether the browser supports the WICG HTML-in-Canvas API natively (or already has it installed).
|
|
26
|
+
* @returns true when an HTMLCanvasElement exposes `captureElementImage`
|
|
27
|
+
*/
|
|
28
|
+
export declare function IsHtmlInCanvasSupportedNatively(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Lazily installs the WICG HTML-in-Canvas polyfill (`three-html-render`) so that {@link HtmlTexture} and the
|
|
31
|
+
* interaction managers work in browsers that do not yet ship the native API.
|
|
32
|
+
*
|
|
33
|
+
* The polyfill is an optional dependency: it is imported on demand and never bundled into Babylon. When the
|
|
34
|
+
* browser already supports the API natively, this is a no-op unless `force` is set or the `?polyfillHIC` URL
|
|
35
|
+
* flag is present.
|
|
36
|
+
* @param options optional installation configuration
|
|
37
|
+
* @returns a promise that resolves to true when the polyfill was installed, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
export declare function InstallHtmlInCanvasPolyfill(options?: IInstallHtmlInCanvasPolyfillOptions): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Removes a polyfill previously installed by {@link InstallHtmlInCanvasPolyfill}.
|
|
42
|
+
*/
|
|
43
|
+
export declare function UninstallHtmlInCanvasPolyfill(): void;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** This module has no top-level side effects: it only declares the optional HTML-in-Canvas polyfill installer */
|
|
2
|
+
import { Logger } from "../../../Misc/logger.js";
|
|
3
|
+
let _InstalledModule = null;
|
|
4
|
+
/**
|
|
5
|
+
* Detects whether the browser supports the WICG HTML-in-Canvas API natively (or already has it installed).
|
|
6
|
+
* @returns true when an HTMLCanvasElement exposes `captureElementImage`
|
|
7
|
+
*/
|
|
8
|
+
export function IsHtmlInCanvasSupportedNatively() {
|
|
9
|
+
if (typeof document === "undefined") {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const canvas = document.createElement("canvas");
|
|
13
|
+
return typeof canvas.captureElementImage === "function";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Lazily installs the WICG HTML-in-Canvas polyfill (`three-html-render`) so that {@link HtmlTexture} and the
|
|
17
|
+
* interaction managers work in browsers that do not yet ship the native API.
|
|
18
|
+
*
|
|
19
|
+
* The polyfill is an optional dependency: it is imported on demand and never bundled into Babylon. When the
|
|
20
|
+
* browser already supports the API natively, this is a no-op unless `force` is set or the `?polyfillHIC` URL
|
|
21
|
+
* flag is present.
|
|
22
|
+
* @param options optional installation configuration
|
|
23
|
+
* @returns a promise that resolves to true when the polyfill was installed, false otherwise
|
|
24
|
+
*/
|
|
25
|
+
export async function InstallHtmlInCanvasPolyfill(options = {}) {
|
|
26
|
+
const force = options.force ?? _HasPolyfillUrlFlag();
|
|
27
|
+
if (!force && IsHtmlInCanvasSupportedNatively()) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const module = options.polyfillModule ?? (await _ImportPolyfill(options.moduleSpecifier ?? "three-html-render"));
|
|
31
|
+
if (!module || typeof module.installHtmlInCanvasPolyfill !== "function") {
|
|
32
|
+
Logger.Warn("HTML-in-Canvas: the polyfill module does not expose installHtmlInCanvasPolyfill; nothing was installed.");
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
module.installHtmlInCanvasPolyfill(force ? { force: true } : undefined);
|
|
36
|
+
_InstalledModule = module;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Removes a polyfill previously installed by {@link InstallHtmlInCanvasPolyfill}.
|
|
41
|
+
*/
|
|
42
|
+
export function UninstallHtmlInCanvasPolyfill() {
|
|
43
|
+
if (_InstalledModule && typeof _InstalledModule.uninstallHtmlInCanvasPolyfill === "function") {
|
|
44
|
+
_InstalledModule.uninstallHtmlInCanvasPolyfill();
|
|
45
|
+
}
|
|
46
|
+
_InstalledModule = null;
|
|
47
|
+
}
|
|
48
|
+
async function _ImportPolyfill(specifier) {
|
|
49
|
+
try {
|
|
50
|
+
// The specifier is a variable so bundlers leave this as a runtime import and the optional package is
|
|
51
|
+
// not required to be installed at build time. The UMD/global build cannot resolve a bare module
|
|
52
|
+
// specifier, so this dynamic import is neutralized there (see rewriteDynamicExternalImportsPlugin);
|
|
53
|
+
// UMD consumers should pass `polyfillModule` instead.
|
|
54
|
+
return (await import(/* @vite-ignore */ /* webpackIgnore: true */ specifier));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
Logger.Warn(`HTML-in-Canvas: could not load polyfill module "${specifier}". Install three-html-render or pass a polyfillModule.`);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function _HasPolyfillUrlFlag() {
|
|
62
|
+
return typeof window !== "undefined" && !!window.location && /[?&]polyfillHIC\b/i.test(window.location.search);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=htmlInCanvasPolyfill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"htmlInCanvasPolyfill.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Materials/Textures/HTML/htmlInCanvasPolyfill.ts"],"names":[],"mappings":"AAAA,iHAAiH;AAGjH,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AA2B9C,IAAI,gBAAgB,GAA0C,IAAI,CAAC;AAEnE;;;GAGG;AACH,MAAM,UAAU,+BAA+B;IAC3C,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAA0D,CAAC;IACzG,OAAO,OAAO,M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C,IAAI,CAAC,mDAAmD,SAAS,wDAAwD,CAAC,CAAC;QAClI,OAAO,IAAI,CAAC;IAChB,CAAC;AACL,CAAC;AAED,SAAS,mBAAmB;IACxB,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,IAAI,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACnH,CAAC","sourcesContent":["/** This module has no top-level side effects: it only declares the optional HTML-in-Canvas polyfill installer */\n\nimport { type Nullable } from \"../../../types\";\nimport { Logger } from \"../../../Misc/logger\";\n\n// Attribution: the WICG HTML-in-Canvas polyfill is `three-html-render` by Palash Bansal (`repalash`),\n// MIT. It is consumed as an optional, lazily-imported dependency and is never bundled into Babylon.\n\n/**\n * Shape of the `three-html-render` polyfill module (only the parts this wrapper uses).\n */\nexport interface IHtmlInCanvasPolyfillModule {\n /** Installs the WICG HTML-in-Canvas polyfill onto the relevant DOM prototypes. */\n installHtmlInCanvasPolyfill?: (options?: { force?: boolean }) => void;\n /** Removes a previously installed polyfill. */\n uninstallHtmlInCanvasPolyfill?: () => void;\n}\n\n/**\n * Options for {@link InstallHtmlInCanvasPolyfill}.\n */\nexport interface IInstallHtmlInCanvasPolyfillOptions {\n /** Install the polyfill even when the browser already supports the API natively (default false). */\n force?: boolean;\n /** Module specifier to lazily import the polyfill from (default `\"three-html-render\"`). */\n moduleSpecifier?: string;\n /** A pre-imported polyfill module to use instead of dynamically importing one. */\n polyfillModule?: IHtmlInCanvasPolyfillModule;\n}\n\nlet _InstalledModule: Nullable<IHtmlInCanvasPolyfillModule> = null;\n\n/**\n * Detects whether the browser supports the WICG HTML-in-Canvas API natively (or already has it installed).\n * @returns true when an HTMLCanvasElement exposes `captureElementImage`\n */\nexport function IsHtmlInCanvasSupportedNatively(): boolean {\n if (typeof document === \"undefined\") {\n return false;\n }\n const canvas = document.createElement(\"canvas\") as HTMLCanvasElement & { captureElementImage?: unknown };\n return typeof canvas.captureElementImage === \"function\";\n}\n\n/**\n * Lazily installs the WICG HTML-in-Canvas polyfill (`three-html-render`) so that {@link HtmlTexture} and the\n * interaction managers work in browsers that do not yet ship the native API.\n *\n * The polyfill is an optional dependency: it is imported on demand and never bundled into Babylon. When the\n * browser already supports the API natively, this is a no-op unless `force` is set or the `?polyfillHIC` URL\n * flag is present.\n * @param options optional installation configuration\n * @returns a promise that resolves to true when the polyfill was installed, false otherwise\n */\nexport async function InstallHtmlInCanvasPolyfill(options: IInstallHtmlInCanvasPolyfillOptions = {}): Promise<boolean> {\n const force = options.force ?? _HasPolyfillUrlFlag();\n\n if (!force && IsHtmlInCanvasSupportedNatively()) {\n return false;\n }\n\n const module = options.polyfillModule ?? (await _ImportPolyfill(options.moduleSpecifier ?? \"three-html-render\"));\n if (!module || typeof module.installHtmlInCanvasPolyfill !== \"function\") {\n Logger.Warn(\"HTML-in-Canvas: the polyfill module does not expose installHtmlInCanvasPolyfill; nothing was installed.\");\n return false;\n }\n\n module.installHtmlInCanvasPolyfill(force ? { force: true } : undefined);\n _InstalledModule = module;\n return true;\n}\n\n/**\n * Removes a polyfill previously installed by {@link InstallHtmlInCanvasPolyfill}.\n */\nexport function UninstallHtmlInCanvasPolyfill(): void {\n if (_InstalledModule && typeof _InstalledModule.uninstallHtmlInCanvasPolyfill === \"function\") {\n _InstalledModule.uninstallHtmlInCanvasPolyfill();\n }\n _InstalledModule = null;\n}\n\nasync function _ImportPolyfill(specifier: string): Promise<Nullable<IHtmlInCanvasPolyfillModule>> {\n try {\n // The specifier is a variable so bundlers leave this as a runtime import and the optional package is\n // not required to be installed at build time. The UMD/global build cannot resolve a bare module\n // specifier, so this dynamic import is neutralized there (see rewriteDynamicExternalImportsPlugin);\n // UMD consumers should pass `polyfillModule` instead.\n return (await import(/* @vite-ignore */ /* webpackIgnore: true */ specifier)) as IHtmlInCanvasPolyfillModule;\n } catch {\n Logger.Warn(`HTML-in-Canvas: could not load polyfill module \"${specifier}\". Install three-html-render or pass a polyfillModule.`);\n return null;\n }\n}\n\nfunction _HasPolyfillUrlFlag(): boolean {\n return typeof window !== \"undefined\" && !!window.location && /[?&]polyfillHIC\\b/i.test(window.location.search);\n}\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type Scene } from "../../../scene.pure.js";
|
|
2
|
+
import { type AbstractMesh } from "../../../Meshes/abstractMesh.pure.js";
|
|
3
|
+
import { type HtmlTexture } from "./htmlTexture.js";
|
|
4
|
+
/**
|
|
5
|
+
* Builds the CSS `transform` string that positions an overlay element over the projected face of a mesh.
|
|
6
|
+
*
|
|
7
|
+
* The transform is applied with `transform-origin: 0 0`. Reading right to left it centers the element on
|
|
8
|
+
* its own origin, scales and rotates it to match the projected face, then translates it to the projected
|
|
9
|
+
* center (in CSS pixels, top-left origin).
|
|
10
|
+
* @param centerX projected center X in CSS pixels
|
|
11
|
+
* @param centerY projected center Y in CSS pixels
|
|
12
|
+
* @param scaleX horizontal scale to apply to the element
|
|
13
|
+
* @param scaleY vertical scale to apply to the element
|
|
14
|
+
* @param rotation in-plane rotation in radians
|
|
15
|
+
* @param elementWidth element width in pixels
|
|
16
|
+
* @param elementHeight element height in pixels
|
|
17
|
+
* @returns the CSS transform string
|
|
18
|
+
*/
|
|
19
|
+
export declare function ComputeOverlayCssTransform(centerX: number, centerY: number, scaleX: number, scaleY: number, rotation: number, elementWidth: number, elementHeight: number): string;
|
|
20
|
+
/**
|
|
21
|
+
* Options for {@link HtmlInteractionManager}.
|
|
22
|
+
*/
|
|
23
|
+
export interface IHtmlInteractionManagerOptions {
|
|
24
|
+
/** The DOM element to overlay (defaults to the texture's element). */
|
|
25
|
+
targetElement?: HTMLElement;
|
|
26
|
+
/** Whether the overlay element captures pointer events so the browser hit-tests it natively (default true). */
|
|
27
|
+
enablePointerEvents?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Overlays the live HTML element of an {@link HtmlTexture} on top of the projected face of a planar mesh,
|
|
31
|
+
* so the browser hit-tests the real DOM element natively (enabling focus, text selection and form input).
|
|
32
|
+
*
|
|
33
|
+
* Each frame the mesh face is projected to screen space and the element is translated, scaled and rotated
|
|
34
|
+
* to match. This is best suited to planar, camera-facing surfaces. For arbitrary or curved meshes, use the
|
|
35
|
+
* UV-based {@link HtmlRaycastInteractionManager} instead.
|
|
36
|
+
*
|
|
37
|
+
* The overlay is screen-aligned (position, size and in-plane rotation); it does not apply a full
|
|
38
|
+
* perspective skew, so steeply oblique faces will not be perspective-correct.
|
|
39
|
+
*/
|
|
40
|
+
export declare class HtmlInteractionManager {
|
|
41
|
+
private readonly _scene;
|
|
42
|
+
private readonly _mesh;
|
|
43
|
+
private readonly _element;
|
|
44
|
+
private _observer;
|
|
45
|
+
private _previousTransform;
|
|
46
|
+
private readonly _viewport;
|
|
47
|
+
private readonly _center;
|
|
48
|
+
private readonly _xAxis;
|
|
49
|
+
private readonly _yAxis;
|
|
50
|
+
private readonly _projectedCenter;
|
|
51
|
+
private readonly _projectedX;
|
|
52
|
+
private readonly _projectedY;
|
|
53
|
+
private readonly _corner;
|
|
54
|
+
private _restoreInertOnDispose;
|
|
55
|
+
/**
|
|
56
|
+
* Creates an overlay interaction manager.
|
|
57
|
+
* @param scene the scene whose camera drives the projection
|
|
58
|
+
* @param texture the HTML texture whose element should be overlaid
|
|
59
|
+
* @param mesh the planar mesh displaying the texture
|
|
60
|
+
* @param options optional configuration
|
|
61
|
+
*/
|
|
62
|
+
constructor(scene: Scene, texture: HtmlTexture, mesh: AbstractMesh, options?: IHtmlInteractionManagerOptions);
|
|
63
|
+
private _update;
|
|
64
|
+
private _setTransform;
|
|
65
|
+
/**
|
|
66
|
+
* Detaches the manager and stops updating the overlay.
|
|
67
|
+
*/
|
|
68
|
+
dispose(): void;
|
|
69
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Matrix, Vector3 } from "../../../Maths/math.vector.pure.js";
|
|
2
|
+
import { Viewport } from "../../../Maths/math.viewport.js";
|
|
3
|
+
// Attribution: the overlay-and-hit-test technique used here is prior art from `three-html-render`
|
|
4
|
+
// (Palash Bansal, MIT), three.js' `InteractionManager`, and Jake Archibald's `curved-markup` demo.
|
|
5
|
+
// The implementation below is a clean-room rewrite against Babylon.js' own projection APIs.
|
|
6
|
+
/**
|
|
7
|
+
* Builds the CSS `transform` string that positions an overlay element over the projected face of a mesh.
|
|
8
|
+
*
|
|
9
|
+
* The transform is applied with `transform-origin: 0 0`. Reading right to left it centers the element on
|
|
10
|
+
* its own origin, scales and rotates it to match the projected face, then translates it to the projected
|
|
11
|
+
* center (in CSS pixels, top-left origin).
|
|
12
|
+
* @param centerX projected center X in CSS pixels
|
|
13
|
+
* @param centerY projected center Y in CSS pixels
|
|
14
|
+
* @param scaleX horizontal scale to apply to the element
|
|
15
|
+
* @param scaleY vertical scale to apply to the element
|
|
16
|
+
* @param rotation in-plane rotation in radians
|
|
17
|
+
* @param elementWidth element width in pixels
|
|
18
|
+
* @param elementHeight element height in pixels
|
|
19
|
+
* @returns the CSS transform string
|
|
20
|
+
*/
|
|
21
|
+
export function ComputeOverlayCssTransform(centerX, centerY, scaleX, scaleY, rotation, elementWidth, elementHeight) {
|
|
22
|
+
return `translate(${centerX}px, ${centerY}px) rotate(${rotation}rad) scale(${scaleX}, ${scaleY}) translate(${-elementWidth / 2}px, ${-elementHeight / 2}px)`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Overlays the live HTML element of an {@link HtmlTexture} on top of the projected face of a planar mesh,
|
|
26
|
+
* so the browser hit-tests the real DOM element natively (enabling focus, text selection and form input).
|
|
27
|
+
*
|
|
28
|
+
* Each frame the mesh face is projected to screen space and the element is translated, scaled and rotated
|
|
29
|
+
* to match. This is best suited to planar, camera-facing surfaces. For arbitrary or curved meshes, use the
|
|
30
|
+
* UV-based {@link HtmlRaycastInteractionManager} instead.
|
|
31
|
+
*
|
|
32
|
+
* The overlay is screen-aligned (position, size and in-plane rotation); it does not apply a full
|
|
33
|
+
* perspective skew, so steeply oblique faces will not be perspective-correct.
|
|
34
|
+
*/
|
|
35
|
+
export class HtmlInteractionManager {
|
|
36
|
+
/**
|
|
37
|
+
* Creates an overlay interaction manager.
|
|
38
|
+
* @param scene the scene whose camera drives the projection
|
|
39
|
+
* @param texture the HTML texture whose element should be overlaid
|
|
40
|
+
* @param mesh the planar mesh displaying the texture
|
|
41
|
+
* @param options optional configuration
|
|
42
|
+
*/
|
|
43
|
+
constructor(scene, texture, mesh, options = {}) {
|
|
44
|
+
this._previousTransform = "";
|
|
45
|
+
// Reused across frames to avoid per-frame allocations.
|
|
46
|
+
this._viewport = new Viewport(0, 0, 0, 0);
|
|
47
|
+
this._center = new Vector3();
|
|
48
|
+
this._xAxis = new Vector3();
|
|
49
|
+
this._yAxis = new Vector3();
|
|
50
|
+
this._projectedCenter = new Vector3();
|
|
51
|
+
this._projectedX = new Vector3();
|
|
52
|
+
this._projectedY = new Vector3();
|
|
53
|
+
this._corner = new Vector3();
|
|
54
|
+
this._restoreInertOnDispose = false;
|
|
55
|
+
this._scene = scene;
|
|
56
|
+
this._mesh = mesh;
|
|
57
|
+
this._element = options.targetElement ?? texture.element;
|
|
58
|
+
this._element.style.position = "absolute";
|
|
59
|
+
this._element.style.left = "0px";
|
|
60
|
+
this._element.style.top = "0px";
|
|
61
|
+
this._element.style.transformOrigin = "0 0";
|
|
62
|
+
this._element.style.pointerEvents = (options.enablePointerEvents ?? true) ? "auto" : "none";
|
|
63
|
+
// This manager relies on native browser hit testing of the element. HtmlTexture marks the element
|
|
64
|
+
// `inert` while hosting it inside the rendering canvas (so it does not steal input from the canvas);
|
|
65
|
+
// clear that here so native interaction works, and restore it on dispose.
|
|
66
|
+
this._restoreInertOnDispose = this._element.hasAttribute("inert");
|
|
67
|
+
if (this._restoreInertOnDispose) {
|
|
68
|
+
this._element.removeAttribute("inert");
|
|
69
|
+
}
|
|
70
|
+
this._observer = scene.onAfterRenderObservable.add(() => this._update());
|
|
71
|
+
}
|
|
72
|
+
_update() {
|
|
73
|
+
const camera = this._scene.activeCamera;
|
|
74
|
+
const engine = this._scene.getEngine();
|
|
75
|
+
if (!camera) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const boundingBox = this._mesh.getBoundingInfo().boundingBox;
|
|
79
|
+
const world = this._mesh.getWorldMatrix();
|
|
80
|
+
const extend = boundingBox.extendSize;
|
|
81
|
+
this._center.copyFrom(boundingBox.centerWorld);
|
|
82
|
+
// World-space half-axis directions of the mesh face.
|
|
83
|
+
Vector3.TransformNormalFromFloatsToRef(extend.x, 0, 0, world, this._xAxis);
|
|
84
|
+
Vector3.TransformNormalFromFloatsToRef(0, extend.y, 0, world, this._yAxis);
|
|
85
|
+
const transform = this._scene.getTransformMatrix();
|
|
86
|
+
camera.viewport.toGlobalToRef(engine.getRenderWidth(), engine.getRenderHeight(), this._viewport);
|
|
87
|
+
Vector3.ProjectToRef(this._center, Matrix.IdentityReadOnly, transform, this._viewport, this._projectedCenter);
|
|
88
|
+
this._center.addToRef(this._xAxis, this._corner);
|
|
89
|
+
Vector3.ProjectToRef(this._corner, Matrix.IdentityReadOnly, transform, this._viewport, this._projectedX);
|
|
90
|
+
this._center.addToRef(this._yAxis, this._corner);
|
|
91
|
+
Vector3.ProjectToRef(this._corner, Matrix.IdentityReadOnly, transform, this._viewport, this._projectedY);
|
|
92
|
+
// Hide the overlay when the face is behind the camera.
|
|
93
|
+
if (this._projectedCenter.z < 0 || this._projectedCenter.z > 1) {
|
|
94
|
+
this._setTransform("translate(-99999px, -99999px)");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const dpr = engine.getHardwareScalingLevel();
|
|
98
|
+
const centerX = this._projectedCenter.x * dpr;
|
|
99
|
+
const centerY = this._projectedCenter.y * dpr;
|
|
100
|
+
const halfWidth = Math.hypot(this._projectedX.x - this._projectedCenter.x, this._projectedX.y - this._projectedCenter.y) * dpr;
|
|
101
|
+
const halfHeight = Math.hypot(this._projectedY.x - this._projectedCenter.x, this._projectedY.y - this._projectedCenter.y) * dpr;
|
|
102
|
+
const rotation = Math.atan2(this._projectedX.y - this._projectedCenter.y, this._projectedX.x - this._projectedCenter.x);
|
|
103
|
+
const elementWidth = this._element.offsetWidth || 1;
|
|
104
|
+
const elementHeight = this._element.offsetHeight || 1;
|
|
105
|
+
const scaleX = (2 * halfWidth) / elementWidth;
|
|
106
|
+
const scaleY = (2 * halfHeight) / elementHeight;
|
|
107
|
+
this._setTransform(ComputeOverlayCssTransform(centerX, centerY, scaleX, scaleY, rotation, elementWidth, elementHeight));
|
|
108
|
+
}
|
|
109
|
+
_setTransform(transform) {
|
|
110
|
+
if (transform === this._previousTransform) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this._previousTransform = transform;
|
|
114
|
+
this._element.style.transform = transform;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Detaches the manager and stops updating the overlay.
|
|
118
|
+
*/
|
|
119
|
+
dispose() {
|
|
120
|
+
if (this._restoreInertOnDispose) {
|
|
121
|
+
this._element.setAttribute("inert", "");
|
|
122
|
+
this._restoreInertOnDispose = false;
|
|
123
|
+
}
|
|
124
|
+
if (this._observer) {
|
|
125
|
+
this._scene.onAfterRenderObservable.remove(this._observer);
|
|
126
|
+
this._observer = null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=htmlInteractionManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"htmlInteractionManager.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Materials/Textures/HTML/htmlInteractionManager.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,kGAAkG;AAClG,mGAAmG;AACnG,4FAA4F;AAE5F;;;;;;;;;;;;;;GAcG;AACH,MAAM,U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C,SAAiB;QACnC,IAAI,SAAS,KAAK,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACxC,OAAO;QACX,CAAC;QACD,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;QACpC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC;IAC9C,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAC9B,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACxC,IAAI,CAAC,sBAAsB,GAAG,KAAK,CAAC;QACxC,CAAC;QACD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC3D,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAC1B,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { type Scene } from \"../../../scene.pure\";\nimport { type AbstractMesh } from \"../../../Meshes/abstractMesh.pure\";\nimport { type HtmlTexture } from \"./htmlTexture\";\nimport { type Observer } from \"../../../Misc/observable.pure\";\nimport { type Nullable } from \"../../../types\";\n\nimport { Matrix, Vector3 } from \"../../../Maths/math.vector.pure\";\nimport { Viewport } from \"../../../Maths/math.viewport\";\n\n// Attribution: the overlay-and-hit-test technique used here is prior art from `three-html-render`\n// (Palash Bansal, MIT), three.js' `InteractionManager`, and Jake Archibald's `curved-markup` demo.\n// The implementation below is a clean-room rewrite against Babylon.js' own projection APIs.\n\n/**\n * Builds the CSS `transform` string that positions an overlay element over the projected face of a mesh.\n *\n * The transform is applied with `transform-origin: 0 0`. Reading right to left it centers the element on\n * its own origin, scales and rotates it to match the projected face, then translates it to the projected\n * center (in CSS pixels, top-left origin).\n * @param centerX projected center X in CSS pixels\n * @param centerY projected center Y in CSS pixels\n * @param scaleX horizontal scale to apply to the element\n * @param scaleY vertical scale to apply to the element\n * @param rotation in-plane rotation in radians\n * @param elementWidth element width in pixels\n * @param elementHeight element height in pixels\n * @returns the CSS transform string\n */\nexport function ComputeOverlayCssTransform(\n centerX: number,\n centerY: number,\n scaleX: number,\n scaleY: number,\n rotation: number,\n elementWidth: number,\n elementHeight: number\n): string {\n return `translate(${centerX}px, ${centerY}px) rotate(${rotation}rad) scale(${scaleX}, ${scaleY}) translate(${-elementWidth / 2}px, ${-elementHeight / 2}px)`;\n}\n\n/**\n * Options for {@link HtmlInteractionManager}.\n */\nexport interface IHtmlInteractionManagerOptions {\n /** The DOM element to overlay (defaults to the texture's element). */\n targetElement?: HTMLElement;\n /** Whether the overlay element captures pointer events so the browser hit-tests it natively (default true). */\n enablePointerEvents?: boolean;\n}\n\n/**\n * Overlays the live HTML element of an {@link HtmlTexture} on top of the projected face of a planar mesh,\n * so the browser hit-tests the real DOM element natively (enabling focus, text selection and form input).\n *\n * Each frame the mesh face is projected to screen space and the element is translated, scaled and rotated\n * to match. This is best suited to planar, camera-facing surfaces. For arbitrary or curved meshes, use the\n * UV-based {@link HtmlRaycastInteractionManager} instead.\n *\n * The overlay is screen-aligned (position, size and in-plane rotation); it does not apply a full\n * perspective skew, so steeply oblique faces will not be perspective-correct.\n */\nexport class HtmlInteractionManager {\n private readonly _scene: Scene;\n private readonly _mesh: AbstractMesh;\n private readonly _element: HTMLElement;\n private _observer: Nullable<Observer<Scene>>;\n private _previousTransform: string = \"\";\n\n // Reused across frames to avoid per-frame allocations.\n private readonly _viewport = new Viewport(0, 0, 0, 0);\n private readonly _center = new Vector3();\n private readonly _xAxis = new Vector3();\n private readonly _yAxis = new Vector3();\n private readonly _projectedCenter = new Vector3();\n private readonly _projectedX = new Vector3();\n private readonly _projectedY = new Vector3();\n private readonly _corner = new Vector3();\n private _restoreInertOnDispose: boolean = false;\n\n /**\n * Creates an overlay interaction manager.\n * @param scene the scene whose camera drives the projection\n * @param texture the HTML texture whose element should be overlaid\n * @param mesh the planar mesh displaying the texture\n * @param options optional configuration\n */\n constructor(scene: Scene, texture: HtmlTexture, mesh: AbstractMesh, options: IHtmlInteractionManagerOptions = {}) {\n this._scene = scene;\n this._mesh = mesh;\n this._element = options.targetElement ?? texture.element;\n\n this._element.style.position = \"absolute\";\n this._element.style.left = \"0px\";\n this._element.style.top = \"0px\";\n this._element.style.transformOrigin = \"0 0\";\n this._element.style.pointerEvents = (options.enablePointerEvents ?? true) ? \"auto\" : \"none\";\n\n // This manager relies on native browser hit testing of the element. HtmlTexture marks the element\n // `inert` while hosting it inside the rendering canvas (so it does not steal input from the canvas);\n // clear that here so native interaction works, and restore it on dispose.\n this._restoreInertOnDispose = this._element.hasAttribute(\"inert\");\n if (this._restoreInertOnDispose) {\n this._element.removeAttribute(\"inert\");\n }\n\n this._observer = scene.onAfterRenderObservable.add(() => this._update());\n }\n\n private _update(): void {\n const camera = this._scene.activeCamera;\n const engine = this._scene.getEngine();\n if (!camera) {\n return;\n }\n\n const boundingBox = this._mesh.getBoundingInfo().boundingBox;\n const world = this._mesh.getWorldMatrix();\n const extend = boundingBox.extendSize;\n\n this._center.copyFrom(boundingBox.centerWorld);\n // World-space half-axis directions of the mesh face.\n Vector3.TransformNormalFromFloatsToRef(extend.x, 0, 0, world, this._xAxis);\n Vector3.TransformNormalFromFloatsToRef(0, extend.y, 0, world, this._yAxis);\n\n const transform = this._scene.getTransformMatrix();\n camera.viewport.toGlobalToRef(engine.getRenderWidth(), engine.getRenderHeight(), this._viewport);\n\n Vector3.ProjectToRef(this._center, Matrix.IdentityReadOnly, transform, this._viewport, this._projectedCenter);\n this._center.addToRef(this._xAxis, this._corner);\n Vector3.ProjectToRef(this._corner, Matrix.IdentityReadOnly, transform, this._viewport, this._projectedX);\n this._center.addToRef(this._yAxis, this._corner);\n Vector3.ProjectToRef(this._corner, Matrix.IdentityReadOnly, transform, this._viewport, this._projectedY);\n\n // Hide the overlay when the face is behind the camera.\n if (this._projectedCenter.z < 0 || this._projectedCenter.z > 1) {\n this._setTransform(\"translate(-99999px, -99999px)\");\n return;\n }\n\n const dpr = engine.getHardwareScalingLevel();\n const centerX = this._projectedCenter.x * dpr;\n const centerY = this._projectedCenter.y * dpr;\n\n const halfWidth = Math.hypot(this._projectedX.x - this._projectedCenter.x, this._projectedX.y - this._projectedCenter.y) * dpr;\n const halfHeight = Math.hypot(this._projectedY.x - this._projectedCenter.x, this._projectedY.y - this._projectedCenter.y) * dpr;\n const rotation = Math.atan2(this._projectedX.y - this._projectedCenter.y, this._projectedX.x - this._projectedCenter.x);\n\n const elementWidth = this._element.offsetWidth || 1;\n const elementHeight = this._element.offsetHeight || 1;\n const scaleX = (2 * halfWidth) / elementWidth;\n const scaleY = (2 * halfHeight) / elementHeight;\n\n this._setTransform(ComputeOverlayCssTransform(centerX, centerY, scaleX, scaleY, rotation, elementWidth, elementHeight));\n }\n\n private _setTransform(transform: string): void {\n if (transform === this._previousTransform) {\n return;\n }\n this._previousTransform = transform;\n this._element.style.transform = transform;\n }\n\n /**\n * Detaches the manager and stops updating the overlay.\n */\n public dispose(): void {\n if (this._restoreInertOnDispose) {\n this._element.setAttribute(\"inert\", \"\");\n this._restoreInertOnDispose = false;\n }\n if (this._observer) {\n this._scene.onAfterRenderObservable.remove(this._observer);\n this._observer = null;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type Scene } from "../../../scene.pure.js";
|
|
2
|
+
import { type AbstractMesh } from "../../../Meshes/abstractMesh.pure.js";
|
|
3
|
+
import { type HtmlTexture } from "./htmlTexture.js";
|
|
4
|
+
/**
|
|
5
|
+
* Maps a UV coordinate sampled from an {@link HtmlTexture} to a pixel position inside the source element.
|
|
6
|
+
*
|
|
7
|
+
* When `invertY` is true (the default, matching {@link HtmlTexture}'s default upload orientation) the V
|
|
8
|
+
* axis is flipped so that `v = 1` maps to the top of the element, matching the top-left origin used by
|
|
9
|
+
* DOM layout.
|
|
10
|
+
* @param u horizontal texture coordinate, normally in [0, 1]
|
|
11
|
+
* @param v vertical texture coordinate, normally in [0, 1]
|
|
12
|
+
* @param width element width in pixels
|
|
13
|
+
* @param height element height in pixels
|
|
14
|
+
* @param invertY whether the texture content is stored Y-inverted (default true)
|
|
15
|
+
* @returns the pixel position `{ x, y }` within the element
|
|
16
|
+
*/
|
|
17
|
+
export declare function GetElementPixelFromUv(u: number, v: number, width: number, height: number, invertY?: boolean): {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Options for {@link HtmlRaycastInteractionManager}.
|
|
23
|
+
*/
|
|
24
|
+
export interface IHtmlRaycastInteractionManagerOptions {
|
|
25
|
+
/** The DOM element that receives the forwarded pointer events (defaults to the texture's element). */
|
|
26
|
+
targetElement?: HTMLElement;
|
|
27
|
+
/** Whether hits on back-facing geometry are ignored (default true). */
|
|
28
|
+
backFaceCulling?: boolean;
|
|
29
|
+
/** Whether the texture content is stored Y-inverted, used when mapping UVs to element pixels (default true). */
|
|
30
|
+
invertY?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Routes Babylon pointer events to a live HTML element rendered through an {@link HtmlTexture}.
|
|
34
|
+
*
|
|
35
|
+
* On every pointer event the scene is picked; when the configured mesh is hit, the picked UV is mapped to
|
|
36
|
+
* a pixel inside the source element and an equivalent DOM pointer (and mouse) event is dispatched there.
|
|
37
|
+
* This works for arbitrary meshes (planes, boxes, curved surfaces) because it relies on UV coordinates
|
|
38
|
+
* rather than a flat CSS overlay. For a perspective-correct overlay on planar surfaces, see
|
|
39
|
+
* {@link HtmlInteractionManager}.
|
|
40
|
+
*/
|
|
41
|
+
export declare class HtmlRaycastInteractionManager {
|
|
42
|
+
private readonly _scene;
|
|
43
|
+
private readonly _mesh;
|
|
44
|
+
private readonly _element;
|
|
45
|
+
private readonly _backFaceCulling;
|
|
46
|
+
private readonly _invertY;
|
|
47
|
+
private _observer;
|
|
48
|
+
private _downTarget;
|
|
49
|
+
private readonly _containHandler;
|
|
50
|
+
private readonly _rectCache;
|
|
51
|
+
private _rectCacheValid;
|
|
52
|
+
private readonly _invalidateRectCache;
|
|
53
|
+
private _resizeObserver;
|
|
54
|
+
private _mutationObserver;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a raycast interaction manager.
|
|
57
|
+
* @param scene the scene to listen to for pointer events
|
|
58
|
+
* @param texture the HTML texture whose element should receive the forwarded events
|
|
59
|
+
* @param mesh the mesh displaying the texture; only hits on this mesh are forwarded
|
|
60
|
+
* @param options optional configuration
|
|
61
|
+
*/
|
|
62
|
+
constructor(scene: Scene, texture: HtmlTexture, mesh: AbstractMesh, options?: IHtmlRaycastInteractionManagerOptions);
|
|
63
|
+
private _onPointer;
|
|
64
|
+
private _isBackFace;
|
|
65
|
+
private _dispatch;
|
|
66
|
+
/**
|
|
67
|
+
* Resolves the deepest descendant of the hosted element whose layout box contains the given client point.
|
|
68
|
+
* @param clientX horizontal client coordinate
|
|
69
|
+
* @param clientY vertical client coordinate
|
|
70
|
+
* @returns the deepest matching element, or the hosted element itself when no descendant matches
|
|
71
|
+
*/
|
|
72
|
+
private _resolveTarget;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the client rect of an element, served from a cache that is rebuilt only when layout may have
|
|
75
|
+
* changed (see the constructor). This keeps pointer routing free of per-event layout reads.
|
|
76
|
+
* @param element the element whose bounding rect is needed
|
|
77
|
+
* @returns the element's cached {@link DOMRect}
|
|
78
|
+
*/
|
|
79
|
+
private _getRect;
|
|
80
|
+
/**
|
|
81
|
+
* Detaches the manager and stops forwarding pointer events.
|
|
82
|
+
*/
|
|
83
|
+
dispose(): void;
|
|
84
|
+
}
|