Skip to content

The native runtime for three.js: three.js, down to the metal. 45× smaller than Electron, on a Sony PS3, and path-traced at 60 fps on ray-tracing GPUs.

Landing page: camera-move players honour reduced motion, stop off-screen, end drags on cancel; keyboard holds the reel (Bugbot)

Evan (Yifeng) Wang7888aba473c1
diff --git a/site/index.html b/site/index.html
index 1252c7e..6e86aaa 100644
--- a/site/index.html
+++ b/site/index.html
@@ -81,6 +81,7 @@
.tricks .no s { text-decoration-thickness: 2px; text-decoration-color: var(--ember); }
.tricks .yes { margin-top: 26px; font: 640 clamp(56px, 8vw, 116px)/1 var(--font-sans); letter-spacing: -.055em; }
.tricks svg.orbit { width: 150px; height: 150px; margin: 0 auto 40px; display: block; overflow: visible; }
+ @media (prefers-reduced-motion: reduce) { .tricks svg.orbit .pulse { display: none; } }
/* ---- Everywhere: one scene, a rail to two renderers, every screen ---- */
.root { display: inline-flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--ink-2); font: 500 13px var(--font-mono); color: var(--bone); position: relative; z-index: 1; }
@@ -278,7 +279,7 @@
<defs><linearGradient id="ry" x1="10" y1="56" x2="54" y2="20" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#FF6A13"/><stop offset=".5" stop-color="#FFB454"/><stop offset="1" stop-color="#FFEBC4"/></linearGradient><filter id="gl"><feGaussianBlur stdDeviation="1.4"/></filter></defs>
<path d="M32 8.967 L58 54 L6 54 Z" fill="none" stroke="#ECE8E1" stroke-width="2" stroke-linejoin="round" opacity=".9"/>
<path d="M23.333 54 L40.667 23.978 L23.333 23.978 L40.667 54 L49.333 38.989 L14.667 38.989 Z" fill="none" stroke="url(#ry)" stroke-width="1.8" stroke-linejoin="round" opacity=".35"/>
- <path d="M23.333 54 L40.667 23.978 L23.333 23.978 L40.667 54 L49.333 38.989 L14.667 38.989 Z" fill="none" stroke="#FFEBC4" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round" pathLength="100" stroke-dasharray="9 91" filter="url(#gl)"><animate attributeName="stroke-dashoffset" from="100" to="0" dur="2.4s" repeatCount="indefinite"/></path>
+ <path class="pulse" d="M23.333 54 L40.667 23.978 L23.333 23.978 L40.667 54 L49.333 38.989 L14.667 38.989 Z" fill="none" stroke="#FFEBC4" stroke-width="2.6" stroke-linecap="round" stroke-linejoin="round" pathLength="100" stroke-dasharray="9 91" filter="url(#gl)"><animate attributeName="stroke-dashoffset" from="100" to="0" dur="2.4s" repeatCount="indefinite"/></path>
</svg>
<div class="wrap">
<div class="no rv"><s>Shadow maps.</s> <s>Light probes.</s> <s>Lightmaps.</s><br><s>Screen-space GI.</s> <s>Baking.</s></div>
@@ -366,6 +367,7 @@
// that ends in a release (a tap or a drag) keeps the reader's position for the slide; a touch the browser turns
// into a scroll ends in pointercancel instead, and the sweep goes on.
cmpEl.addEventListener("pointerdown", () => { dragging = true; });
+ cmpEl.addEventListener("keydown", (e) => { if (e.key === "ArrowLeft" || e.key === "ArrowRight") touched = true; }); // keyboard slider
addEventListener("pointerup", () => { if (dragging) touched = true; dragging = false; });
addEventListener("pointercancel", () => (dragging = false));
new IntersectionObserver(([e]) => (visible = e.isIntersecting), { threshold: 0.35 }).observe($("#reel"));
diff --git a/site/js/threert.js b/site/js/threert.js
index 5e2853c..b1e278f 100644
--- a/site/js/threert.js
+++ b/site/js/threert.js
@@ -46,7 +46,7 @@ export function compare(el) {
if (e.key === "ArrowLeft" || e.key === "ArrowRight") { setX(x + (e.key === "ArrowLeft" ? -4 : 4)); e.preventDefault(); }
});
// A gentle first sweep so the reader sees it is interactive.
- if (d.intro !== undefined) {
+ if (d.intro !== undefined && !matchMedia("(prefers-reduced-motion: reduce)").matches) {
const io = new IntersectionObserver(([en]) => {
if (!en.isIntersecting) return;
io.disconnect();
@@ -71,12 +71,15 @@ export function sequence(el) {
el.innerHTML = `<canvas></canvas><div class="bar"></div>${label("a", d.la, d.sa)}${label("b", d.lb, d.sb)}<div class="loading">loading 120 frames…</div>
<div class="ctl"><button class="pp" aria-label="Play / pause"></button><div class="track"><b></b></div><span class="t">0.0 s</span></div>`;
const cv = $("canvas", el), cx = cv.getContext("2d"), bar = $(".bar", el), pp = $(".pp", el), fill = $(".track b", el), tl = $(".t", el);
- let x = 50, k = 0, dir = 1, playing = true, last = 0, ready = false, frames = null;
+ // Autoplay unless the reader asked for reduced motion (the play button still works).
+ let x = 50, k = 0, dir = 1, playing = !matchMedia("(prefers-reduced-motion: reduce)").matches, last = 0, ready = false, frames = null, visible = false, raf = 0;
const icon = () => (pp.innerHTML = playing ? `<svg width="12" height="12" viewBox="0 0 12 12"><rect x="2" y="1.5" width="3" height="9" fill="currentColor"/><rect x="7" y="1.5" width="3" height="9" fill="currentColor"/></svg>` : `<svg width="12" height="12" viewBox="0 0 12 12"><path d="M3 1.5v9l7.5-4.5z" fill="currentColor"/></svg>`);
icon();
const draw = () => {
if (!ready) return;
- const w = (cv.width = el.clientWidth * devicePixelRatio), h = (cv.height = el.clientHeight * devicePixelRatio);
+ // Resize the backing store only when the box changed (assigning width / height clears it).
+ const w = Math.round(el.clientWidth * devicePixelRatio), h = Math.round(el.clientHeight * devicePixelRatio);
+ if (cv.width !== w || cv.height !== h) { cv.width = w; cv.height = h; }
const [three, rt] = [frames.three[k], frames.rt[k]];
cx.drawImage(three, 0, 0, w, h);
const cut = (x / 100) * w;
@@ -103,15 +106,20 @@ export function sequence(el) {
k = clamp(k, 0, n - 1);
draw();
}
- requestAnimationFrame(loop);
+ raf = visible ? requestAnimationFrame(loop) : 0; // stops off-screen
};
- const io = new IntersectionObserver(([en]) => { if (en.isIntersecting && !frames) { load(); requestAnimationFrame(loop); } }, { rootMargin: "400px" });
+ const io = new IntersectionObserver(([en]) => {
+ visible = en.isIntersecting;
+ if (visible && !frames) load();
+ if (visible && !raf) raf = requestAnimationFrame(loop);
+ }, { rootMargin: "400px" });
io.observe(el);
let drag = false;
const at = (e) => { x = clamp(((e.clientX - el.getBoundingClientRect().left) / el.clientWidth) * 100, 0, 100); draw(); };
el.addEventListener("pointerdown", (e) => { if (e.target.closest(".ctl")) return; drag = true; el.setPointerCapture(e.pointerId); at(e); });
el.addEventListener("pointermove", (e) => drag && at(e));
el.addEventListener("pointerup", () => (drag = false));
+ el.addEventListener("pointercancel", () => (drag = false)); // a touch the browser took as a scroll
pp.addEventListener("click", () => { playing = !playing; icon(); });
$(".track", el).addEventListener("click", (e) => {
const r = e.currentTarget.getBoundingClientRect();