Skip to content

Added HTMLTexture#31233

Merged
mrdoob merged 14 commits into
devfrom
htmltexture
Apr 10, 2026
Merged

Added HTMLTexture#31233
mrdoob merged 14 commits into
devfrom
htmltexture

Conversation

@mrdoob

@mrdoob mrdoob commented Jun 6, 2025

Copy link
Copy Markdown
Owner

Description

Adds support for rendering HTML elements as textures on 3D surfaces using the HTML-in-Canvas API. Works with both WebGL and WebGPU renderers.

  • HTMLTexture — A new texture class that renders a live HTML element onto a mesh via the browser's HTML-in-Canvas API. The renderer automatically sets up layoutsubtree on the canvas and appends the element as a child.
  • InteractionManager — A new addon that enables native browser pointer interaction with meshes. For HTMLTexture meshes, it computes a CSS matrix3d transform each frame so the browser handles hit-testing, hover, focus, and input natively — no raycasting or synthetic events needed.
  • Exampleswebgl_materials_texture_html and webgpu_materials_texture_html demonstrate both features with formatted text, images, SVG, an input field, and a button.
image

https://raw.githack.com/mrdoob/three.js/dev/examples/webgl_materials_texture_html.html

Usage

const element = document.createElement( 'div' );
element.innerHTML = 'Hello <b>world</b>! <input type="text">';

const material = new MeshStandardMaterial();
material.map = new HTMLTexture( element );

const mesh = new Mesh( geometry, material );
scene.add( mesh );

const interactions = new InteractionManager();
interactions.connect( renderer, camera );
interactions.add( mesh );

// in animation loop
interactions.update();

(Requires passing --enable-blink-features=CanvasDrawElement to Chrome Canary versions later than 138.0.7175.0)

Here's a jsfiddle for anyone that wants to experiment with this: https://jsfiddle.net/dgw4y3ck/

@github-actions

github-actions Bot commented Jun 6, 2025

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 360.57
85.58
361.21
85.78
+641 B
+197 B
WebGPU 635.48
176.41
636.46
176.71
+974 B
+297 B
WebGPU Nodes 633.6
176.11
634.58
176.41
+974 B
+293 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 492.95
120.2
493.58
120.42
+626 B
+220 B
WebGPU 707.66
191.31
708.63
191.61
+962 B
+305 B
WebGPU Nodes 656.88
178.57
657.85
178.86
+962 B
+296 B

@Makio64

Makio64 commented Jun 24, 2025

Copy link
Copy Markdown
Contributor

so weird, but also so usefull!

@mkeblx

mkeblx commented Aug 25, 2025

Copy link
Copy Markdown
Contributor

When I try out I don't see the inline image drawn.

html_texture_inline

When I switch to a same origin image it works.

html_texture_image_same_origin

This may be expected behavior. Although I see the 2D canvas example working currently with a different origin image.

@mkeblx

mkeblx commented Aug 25, 2025

Copy link
Copy Markdown
Contributor

Also, you can now try this a bit easier.

In the latest Chrome Beta (or Dev, Canary; just not Stable), there is now a 'HTML-in-Canvas' flag (chrome://flags) you can enable.

@mrdoob mrdoob added this to the r??? milestone Aug 28, 2025
… example.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mrdoob

mrdoob commented Apr 10, 2026

Copy link
Copy Markdown
Owner Author

Added interaction support.

Screen.Recording.2026-04-10.at.09.38.51.mov

@mrdoob mrdoob marked this pull request as ready for review April 10, 2026 00:45
@mrdoob mrdoob modified the milestones: r???, r184 Apr 10, 2026
mrdoob and others added 3 commits April 10, 2026 14:52
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…Texture.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
mrdoob and others added 5 commits April 10, 2026 16:16
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mrdoob mrdoob changed the title WebGLRenderer: Added HTMLTexture. WebGLRenderer/WebGPURenderer: Added HTMLTexture. Apr 10, 2026
@mrdoob mrdoob changed the title WebGLRenderer/WebGPURenderer: Added HTMLTexture. Added HTMLTexture. Apr 10, 2026
@mrdoob mrdoob changed the title Added HTMLTexture. Added HTMLTexture Apr 10, 2026
@mrdoob mrdoob merged commit bb42b15 into dev Apr 10, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants