@babylonjs/core 9.13.0 → 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.
Files changed (107) hide show
  1. package/Animations/runtimeAnimation.js +11 -0
  2. package/Animations/runtimeAnimation.js.map +1 -1
  3. package/AudioV2/abstractAudio/abstractSound.d.ts +2 -1
  4. package/AudioV2/abstractAudio/abstractSound.js +3 -2
  5. package/AudioV2/abstractAudio/abstractSound.js.map +1 -1
  6. package/AudioV2/abstractAudio/abstractSoundInstance.d.ts +1 -1
  7. package/AudioV2/abstractAudio/abstractSoundInstance.js.map +1 -1
  8. package/AudioV2/abstractAudio/staticSound.d.ts +6 -0
  9. package/AudioV2/abstractAudio/staticSound.js +9 -1
  10. package/AudioV2/abstractAudio/staticSound.js.map +1 -1
  11. package/AudioV2/abstractAudio/streamingSound.d.ts +6 -0
  12. package/AudioV2/abstractAudio/streamingSound.js +9 -1
  13. package/AudioV2/abstractAudio/streamingSound.js.map +1 -1
  14. package/AudioV2/webAudio/webAudioStaticSound.d.ts +1 -1
  15. package/AudioV2/webAudio/webAudioStaticSound.js +6 -3
  16. package/AudioV2/webAudio/webAudioStaticSound.js.map +1 -1
  17. package/AudioV2/webAudio/webAudioStreamingSound.d.ts +1 -1
  18. package/AudioV2/webAudio/webAudioStreamingSound.js +7 -4
  19. package/AudioV2/webAudio/webAudioStreamingSound.js.map +1 -1
  20. package/Cameras/arcRotateCamera.pure.js +9 -3
  21. package/Cameras/arcRotateCamera.pure.js.map +1 -1
  22. package/Cameras/targetCamera.pure.js +18 -18
  23. package/Cameras/targetCamera.pure.js.map +1 -1
  24. package/Collisions/gpuPicker.js +23 -13
  25. package/Collisions/gpuPicker.js.map +1 -1
  26. package/Engines/Native/nativeInterfaces.d.ts +3 -2
  27. package/Engines/Native/nativeInterfaces.js.map +1 -1
  28. package/Engines/Native/nativeRenderTargetWrapper.d.ts +3 -0
  29. package/Engines/Native/nativeRenderTargetWrapper.js +24 -1
  30. package/Engines/Native/nativeRenderTargetWrapper.js.map +1 -1
  31. package/Engines/WebGPU/Extensions/engine.videoTexture.pure.js +16 -3
  32. package/Engines/WebGPU/Extensions/engine.videoTexture.pure.js.map +1 -1
  33. package/Engines/abstractEngine.pure.d.ts +8 -1
  34. package/Engines/abstractEngine.pure.js +4 -3
  35. package/Engines/abstractEngine.pure.js.map +1 -1
  36. package/Engines/engine.d.ts +113 -0
  37. package/Engines/thinNativeEngine.pure.d.ts +2 -0
  38. package/Engines/thinNativeEngine.pure.js +115 -9
  39. package/Engines/thinNativeEngine.pure.js.map +1 -1
  40. package/FlowGraph/flowGraph.js +9 -0
  41. package/FlowGraph/flowGraph.js.map +1 -1
  42. package/FlowGraph/flowGraphDataConnection.pure.d.ts +14 -0
  43. package/FlowGraph/flowGraphDataConnection.pure.js +38 -1
  44. package/FlowGraph/flowGraphDataConnection.pure.js.map +1 -1
  45. package/FlowGraph/serialization.d.ts +11 -0
  46. package/FlowGraph/serialization.js +11 -1
  47. package/FlowGraph/serialization.js.map +1 -1
  48. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.d.ts +2 -2
  49. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.js +43 -51
  50. package/FrameGraph/Tasks/Rendering/iblShadows/iblShadowsAccumulationTask.js.map +1 -1
  51. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.pure.d.ts +0 -1
  52. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.pure.js +63 -35
  53. package/FrameGraph/Tasks/Rendering/iblShadowsRendererTask.pure.js.map +1 -1
  54. package/Lights/Clustered/clusteredLightContainer.pure.d.ts +1 -1
  55. package/Lights/Clustered/clusteredLightContainer.pure.js +2 -2
  56. package/Lights/Clustered/clusteredLightContainer.pure.js.map +1 -1
  57. package/Lights/areaLight.pure.js +5 -0
  58. package/Lights/areaLight.pure.js.map +1 -1
  59. package/Lights/light.d.ts +4 -2
  60. package/Lights/light.js +10 -4
  61. package/Lights/light.js.map +1 -1
  62. package/Lights/rectAreaLight.pure.d.ts +17 -0
  63. package/Lights/rectAreaLight.pure.js +67 -0
  64. package/Lights/rectAreaLight.pure.js.map +1 -1
  65. package/Loading/Plugins/babylonFileLoader.pure.js +1 -1
  66. package/Loading/Plugins/babylonFileLoader.pure.js.map +1 -1
  67. package/Materials/Textures/HTML/htmlInCanvasPolyfill.d.ts +43 -0
  68. package/Materials/Textures/HTML/htmlInCanvasPolyfill.js +64 -0
  69. package/Materials/Textures/HTML/htmlInCanvasPolyfill.js.map +1 -0
  70. package/Materials/Textures/HTML/htmlInteractionManager.d.ts +69 -0
  71. package/Materials/Textures/HTML/htmlInteractionManager.js +130 -0
  72. package/Materials/Textures/HTML/htmlInteractionManager.js.map +1 -0
  73. package/Materials/Textures/HTML/htmlRaycastInteractionManager.d.ts +84 -0
  74. package/Materials/Textures/HTML/htmlRaycastInteractionManager.js +246 -0
  75. package/Materials/Textures/HTML/htmlRaycastInteractionManager.js.map +1 -0
  76. package/Materials/Textures/HTML/htmlTexture.d.ts +148 -0
  77. package/Materials/Textures/HTML/htmlTexture.js +455 -0
  78. package/Materials/Textures/HTML/htmlTexture.js.map +1 -0
  79. package/Materials/Textures/HTML/index.d.ts +4 -0
  80. package/Materials/Textures/HTML/index.js +5 -0
  81. package/Materials/Textures/HTML/index.js.map +1 -0
  82. package/Materials/Textures/HTML/pure.d.ts +5 -0
  83. package/Materials/Textures/HTML/pure.js +6 -0
  84. package/Materials/Textures/HTML/pure.js.map +1 -0
  85. package/Materials/Textures/index.d.ts +1 -0
  86. package/Materials/Textures/index.js +1 -1
  87. package/Materials/Textures/index.js.map +1 -1
  88. package/Materials/Textures/pure.d.ts +1 -0
  89. package/Materials/Textures/pure.js +1 -0
  90. package/Materials/Textures/pure.js.map +1 -1
  91. package/Materials/Textures/videoTexture.pure.d.ts +3 -0
  92. package/Materials/Textures/videoTexture.pure.js +30 -0
  93. package/Materials/Textures/videoTexture.pure.js.map +1 -1
  94. package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.d.ts +9 -0
  95. package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.js +12 -0
  96. package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.js.map +1 -1
  97. package/Meshes/GaussianSplatting/gaussianSplattingSortWorker.d.ts +1 -1
  98. package/Meshes/GaussianSplatting/gaussianSplattingSortWorker.js +20 -6
  99. package/Meshes/GaussianSplatting/gaussianSplattingSortWorker.js.map +1 -1
  100. package/Misc/tools.pure.js +1 -1
  101. package/Misc/tools.pure.js.map +1 -1
  102. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.pure.d.ts +1 -0
  103. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.pure.js +34 -0
  104. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.pure.js.map +1 -1
  105. package/ShadersWGSL/ShadersInclude/openpbrIblFunctions.js +4 -3
  106. package/ShadersWGSL/ShadersInclude/openpbrIblFunctions.js.map +1 -1
  107. package/package.json +1 -1
@@ -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","source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I,OAAO,gBAAgB,CAAC,6BAA6B,KAAK,UAAU,EAAE,CAAC;QAC3F,gBAAgB,CAAC,6BAA6B,EAAE,CAAC;IACrD,CAAC;IACD,gBAAgB,GAAG,IAAI,CAAC;AAC5B,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,SAAiB;IAC5C,IAAI,CAAC;QACD,qGAAqG;QACrG,gGAAgG;QAChG,oGAAoG;QACpG,sDAAsD;QACtD,OAAO,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAgC,CAAC;IACjH,CAAC;IAAC,MAAM,CAAC;QACL,MAAM,CAAC,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,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AC,aAAa,CAAC,0BAA0B,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC;IAC5H,CAAC;IAEO,aAAa,CAAC,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
+ }