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.
Rust electron-alternativegame-engineglobal-illuminationgraphicsjavascript-runtimemetalpath-tracingray-tracingreal-time-renderingrenderingrustthreejstypescriptvoxelvulkanwebgpuwgpu
Landing page: Bugbot fixes (per-shelf materials, redraw on resize, reel yields to a drag)
Evan (Yifeng) Wang62663031b516
diff --git a/site/index.html b/site/index.htmlindex 4edbaeb..4ac0dcc 100644--- a/site/index.html+++ b/site/index.html@@ -329,10 +329,10 @@for (const id of SLIDES) for (const k of ["three", "rt"]) new Image().src = `media/hello/${id}-${k}.webp`;const sts = $$("#story .st"), pp = $("#reelPP"), codeEl = $("#helloCode"), cmpEl = $("#helloCmp");const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;- let cur = -1, elapsed = 0, last = performance.now(), playing = !reduce, hover = false, visible = false;+ let cur = -1, elapsed = 0, last = performance.now(), playing = !reduce, hover = false, visible = false, dragging = false, touched = false;const icon = () => { pp.innerHTML = playing ? '<svg width="10" height="10" viewBox="0 0 10 10"><rect x="1" y="1" width="3" height="8" fill="currentColor"/><rect x="6" y="1" width="3" height="8" fill="currentColor"/></svg>' : '<svg width="10" height="10" viewBox="0 0 10 10"><path d="M2 1v8l7-4z" fill="currentColor"/></svg>'; pp.setAttribute("aria-label", playing ? "Pause" : "Play"); };const show = (i) => {- cur = (i + SLIDES.length) % SLIDES.length; elapsed = 0;+ cur = (i + SLIDES.length) % SLIDES.length; elapsed = 0; touched = false;const id = SLIDES[cur];cmpEl.classList.add("fade"); codeEl.classList.add("fade");setTimeout(() => {@@ -347,10 +347,10 @@const sweep = (p) => p < 0.1 ? 92 : p < 0.5 ? 92 - 82 * ease((p - 0.1) / 0.4) : p < 0.8 ? 10 + 36 * ease((p - 0.5) / 0.3) : 46;const tick = (now) => {const dt = now - last; last = now;- if (playing && !hover && visible && cur >= 0) {+ if (playing && !hover && !dragging && visible && cur >= 0) {elapsed += dt;const p = Math.min(1, elapsed / DUR);- helloCmp.setX(sweep(p));+ if (!touched) helloCmp.setX(sweep(p)); // once the reader moves the divider, the slide keeps their positionconst max = codeEl.scrollHeight - codeEl.clientHeight;if (max > 0) codeEl.scrollTop = max * Math.min(1, Math.max(0, (p - 0.15) / 0.75));if (elapsed >= DUR) show(cur + 1);@@ -362,6 +362,9 @@pp.addEventListener("click", () => { playing = !playing; icon(); });$("#reel").addEventListener("pointerenter", () => (hover = true));$("#reel").addEventListener("pointerleave", () => (hover = false));+ // The divider captures the pointer while dragging, so a drag can leave the reel: pause until it ends.+ cmpEl.addEventListener("pointerdown", () => { dragging = touched = true; });+ for (const ev of ["pointerup", "pointercancel"]) addEventListener(ev, () => (dragging = false));new IntersectionObserver(([e]) => (visible = e.isIntersecting), { threshold: 0.35 }).observe($("#reel"));icon(); show(0); requestAnimationFrame(tick);diff --git a/site/js/devices.js b/site/js/devices.jsindex ac1ffe1..780910a 100644--- a/site/js/devices.js+++ b/site/js/devices.js@@ -60,7 +60,9 @@ function plate(w, h, r) {const mesh = (g, m, x = 0, y = 0, z = 0) => { const o = new THREE.Mesh(g, m); o.position.set(x, y, z); o.castShadow = o.receiveShadow = true; return o; };// ---------- materials -----------const M = {+// One set per shelf: each shelf has its own WebGL context and environment map, so materials (which carry the env map)+// must not be shared between shelves. The builders below read `M`; deviceShelf sets it before it builds its devices.+const makeMaterials = () => ({silver: new THREE.MeshStandardMaterial({ color: 0xc9cbce, metalness: 1, roughness: 0.32 }),graphite: new THREE.MeshStandardMaterial({ color: 0x3a3c41, metalness: 0.85, roughness: 0.42 }),spaceGray: new THREE.MeshStandardMaterial({ color: 0x5d6066, metalness: 1, roughness: 0.38 }),@@ -72,7 +74,8 @@ const M = {glass: new THREE.MeshPhysicalMaterial({ color: 0x030304, metalness: 0, roughness: 0.12, clearcoat: 0.6, clearcoatRoughness: 0.1 }),sheen: new THREE.MeshPhysicalMaterial({ color: 0x000000, metalness: 0, roughness: 0.05, transparent: true, opacity: 0.1, depthWrite: false }),black: new THREE.MeshStandardMaterial({ color: 0x020203, metalness: 0, roughness: 0.3 }),-};+});+let M;// ---------- textures ----------const loader = new THREE.TextureLoader();@@ -253,11 +256,12 @@ export function deviceShelf(el, devices, opt = {}) {renderer.toneMapping = THREE.ACESFilmicToneMapping;renderer.toneMappingExposure = opt.exposure ?? 1.0;renderer.shadowMap.enabled = true;- renderer.shadowMap.type = THREE.PCFSoftShadowMap;+ renderer.shadowMap.type = THREE.PCFShadowMap; // r187: PCFSoftShadowMap was removed; PCF + shadow.radius is softel.appendChild(renderer.domElement);const scene = new THREE.Scene();const pmrem = new THREE.PMREMGenerator(renderer);+ M = makeMaterials();const env = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;scene.environment = env;const ENV = { silver: 1.25, graphite: 0.7, spaceGray: 0.8, titanium: 0.9, monitor: 0.35, deck: 0.12, deckDark: 0.1, deckPad: 0.16, glass: 0.06, sheen: 0.3, black: 0.04 };@@ -346,7 +350,8 @@ export function deviceShelf(el, devices, opt = {}) {renderer.render(scene, camera);};fit(); placeCaps(); renderer.render(scene, camera);- addEventListener("resize", () => { fit(); placeCaps(); });+ // setSize clears the canvas: draw again at once (with reduced motion no animation loop would).+ addEventListener("resize", () => { fit(); placeCaps(); renderer.render(scene, camera); });const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;new IntersectionObserver(([e]) => renderer.setAnimationLoop(e.isIntersecting && !reduce ? frame : null), { rootMargin: "100px" }).observe(el);// textures arrive asynchronously; redraw a few times so a static (reduced-motion) shelf still shows them