diff --git a/examples/files.json b/examples/files.json index a68d269d829064..c4e6b72362c606 100644 --- a/examples/files.json +++ b/examples/files.json @@ -182,6 +182,7 @@ "webgl_multiple_elements_text", "webgl_multiple_scenes_comparison", "webgl_multiple_views", + "webgl_overlay", "webgl_panorama_cube", "webgl_panorama_equirectangular", "webgl_points_billboards", diff --git a/examples/index.html b/examples/index.html index ca3bbf887b3d29..bcdef041904e2b 100644 --- a/examples/index.html +++ b/examples/index.html @@ -187,13 +187,20 @@

three.js

}; - // iOS iframe auto-resize workaround + // Safari iframe auto-resize workaround - if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) { + if ( /^((?!chrome|android).)*safari/i.test( navigator.userAgent ) ) { viewer.style.width = getComputedStyle( viewer ).width; viewer.style.height = getComputedStyle( viewer ).height; - viewer.setAttribute( 'scrolling', 'no' ); + + // Allow scrolling for overlay examples + const currentExample = window.location.hash.substring( 1 ); + if ( ! currentExample.includes( 'overlay' ) ) { + + viewer.setAttribute( 'scrolling', 'no' ); + + } } diff --git a/examples/screenshots/webgl_overlay.jpg b/examples/screenshots/webgl_overlay.jpg new file mode 100644 index 00000000000000..2e49c7b6583687 Binary files /dev/null and b/examples/screenshots/webgl_overlay.jpg differ diff --git a/examples/webgl_overlay.html b/examples/webgl_overlay.html new file mode 100644 index 00000000000000..243b9a1cf20b95 --- /dev/null +++ b/examples/webgl_overlay.html @@ -0,0 +1,366 @@ + + + + three.js webgl - overlay + + + + + + + + + +
+
+ +
+

WebGL Overlay

+

+ This example demonstrates a technique for rendering three.js canvases + that integrate with scrollable HTML content. 3D elements can appear both + in front of and behind HTML elements. +

+ +

How It Works

+

+ The overlay system uses two separate WebGL renderers: one positioned behind + the HTML content (background) and one in front (foreground). By adjusting + the camera's near and far clipping planes for each render pass, objects + closer than a threshold depth render in the foreground, while objects + further away render in the background. +

+

+ The camera position is synchronized with the scroll position of the page, + creating the illusion that the 3D scene exists in the same coordinate + space as the HTML document. A forced pixels-per-meter calculation ensures + consistent sizing across different viewport dimensions. +

+ +

Element Mapping

+

+ HTML elements can be mapped to 3D representations. In this demo, paragraph + elements are visualized as wireframe boxes in 3D space, allowing for + potential interaction between 3D objects and page content. +

+ +

Applications

+

+ This technique enables creative web experiences where 3D graphics seamlessly + blend with traditional HTML layouts. Use cases include decorative page + elements, interactive visualizations embedded in articles, and immersive + scrolling experiences. +

+ +

Scroll to see 3D elements interact with the page.

+
+ + + + + +