3D objects inside selectable prose

I wanted to see if CSS float and inline slots inside an article can reserve room for lit Three.js polyhedra that slice right through the depth plane of the page, follow font-size reflow automatically, and keep every word selectable. Drag across words to select text, tilt the sheet, or adjust the font size.

3 meshes synced

Starting Three.js prose scene...

Editorial geometry · Issue 04

Typography that yields to solid light

Ordinary layout engines pack lines round floats without knowing anything about WebGL depth buffers. Because this article lives inside a drawable canvas, CSS computes the wrap around the empty circle on the left while Three.js draws a lit icosahedron centred on z = 0 so its front facets emerge from the paper and its back faces disappear behind it.

Changing the base font size forces every line break to shift. Reading each placeholder's untransformed layout offsets keeps every mesh anchored inside its opening even when text reflows or the whole sheet tilts toward you. Try dragging over these lines to select text directly across the tilted surface, or switch paper stock below.

Even an inline aperture travels inside the flow of a single sentence. Open the note to check hit testing right beside the spinning octahedron.

Show the code CSS float slots, layout-offset mesh sync and Three.js depth
  1. Prose with CSS float and inline apertures. Empty .obj-slot elements reserve wrapping space in normal CSS flow alongside selectable text, a footnote button and a paper selector.
  2. Measuring untransformed layout offsets. Walks offsetLeft and offsetTop relative to #prose-doc rather than getBoundingClientRect(), then rebuilds the plane when font size changes document height.
  3. Interleaving meshes at z = 0. Parents both the prose plane and lit meshes under one rotating group so front halves render above text while rear halves sit occluded behind the paper.

How it works

This experiment rebuilds Yomotsu's 3D objects within prose (CodeGrid #12) using HTMLSurfaces from /lib/html3d.js. The article stays ordinary HTML in the tray if HTML-in-canvas is missing, and moves into the Three.js canvas when WebGL texture upload is available.

Because Chromium applies updateElementGeometry() to the article element, calling getBoundingClientRect() on a slot inside the page returns transformed screen coordinates instead of layout coordinates on the sheet. Instead, layoutBoxIn() sums offsetLeft and offsetTop up to #prose-doc, maps each slot centre onto the plane's local XY coordinates at z = 0, and updates PlaneGeometry height whenever font-size reflow changes offsetHeight (clearing surface.frame so hit testing matches the resized plane).

Live checks

These checks wait for a tap so the page keeps one WebGL context until requested. Each check runs inside its own isolated fixture on the test stage and retires its canvas afterwards.

Findings