Prompt specification
Build or customize the Three.js 3D scene "Wooden toy refinishing bench" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Wooden toy refinishing bench
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/wooden-toy-refinishing-bench-x0299
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing sandpaper grit. Compose a toy block, sanding pads, dust tray, and finish samples; a sequence reveals progressively smoother surfaces without changing the toy's defining silhouette. Voxel style.
Working Three.js Starter (wooden-toy-refinishing-bench-x0299):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Sanding Study</title>
<style>
:root {
--ink: #2f2924;
--paper: #f4eee4;
--paper-dark: #ded3c2;
--accent: #c96845;
--accent-soft: #e9b89b;
--green: #64785c;
--shadow: rgba(60, 43, 30, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d0c4;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.header {
position: fixed;
z-index: 10;
top: 24px;
left: 28px;
pointer-events: none;
user-select: none;
}
.kicker {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
padding: 6px 9px;
border: 1px solid rgba(47, 41, 36, 0.28);
background: rgba(244, 238, 228, 0.72);
box-shadow: 3px 3px 0 rgba(47, 41, 36, 0.12);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.kicker::before {
content: "";
width: 7px;
height: 7px;
background: var(--accent);
box-shadow: 2px 2px 0 rgba(47, 41, 36, 0.22);
}
h1 {
margin: 0;
font-size: clamp(24px, 3.2vw, 44px);
line-height: 0.98;
letter-spacing: -0.07em;
text-transform: uppercase;
}
.subtitle {
max-width: 430px;
margin: 10px 0 0;
color: rgba(47, 41, 36, 0.72);
font-size: 11px;
line-height: 1.55;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.info-card {
position: fixed;
z-index: 10;
top: 24px;
right: 24px;
width: min(300px, calc(100vw - 48px));
padding: 18px;
border: 1px solid rgba(47, 41, 36, 0.28);
background: rgba(244, 238, 228, 0.88);
box-shadow: 6px 6px 0 rgba(47, 41, 36, 0.13);
backdrop-filter: blur(10px);
}
.card-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.lock {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--green);
}
.lock::before {
content: "";
width: 8px;
height: 8px;
background: var(--green);
box-shadow: 2px 2px 0 rgba(47, 41, 36, 0.18);
}
.stage-title {
margin: 0 0 8px;
font-size: 23px;
line-height: 1.05;
letter-spacing: -0.055em;
text-transform: uppercase;
}
.stage-copy {
min-height: 48px;
margin: 0;
color: rgba(47, 41, 36, 0.72);
font-size: 10px;
line-height: 1.6;
}
.metric {
margin-top: 16px;
}
.metric-line {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.meter {
height: 8px;
padding: 2px;
border: 1px solid rgba(47, 41, 36, 0.25);
background: rgba(47, 41, 36, 0.08);
}
.meter > span {
display: block;
width: 0%;
height: 100%;
background: var(--accent);
transition: width 0.12s linear;
}
.form-meter > span {
width: 100%;
background: var(--green);
}
.controls {
position: fixed;
z-index: 20;
left: 50%;
bottom: 24px;
display: flex;
align-items: stretch;
gap: 8px;
width: max-content;
max-width: calc(100vw - 28px);
padding: 8px;
transform: translateX(-50%);
border: 1px solid rgba(47, 41, 36, 0.3);
background: rgba(244, 238, 228, 0.92);
box-shadow: 6px 6px 0 rgba(47, 41, 36, 0.15);
backdrop-filter: blur(10px);
}
button {
min-height: 42px;
border: 1px solid rgba(47, 41, 36, 0.3);
border-radius: 0;
padding: 0 13px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition:
background 0.15s ease,
color 0.15s ease,
transform 0.15s ease,
box-shadow 0.15s ease;
}
button:hover {
background: rgba(47, 41, 36, 0.08);
}
button:active {
transform: translateY(2px);
}
button.primary {
min-width: 96px;
background: var(--ink);
color: var(--paper);
}
button.primary:hover {
background: var(--accent);
}
.stage-button {
position: relative;
min-width: 86px;
text-align: left;
}
.stage-button span {
display: block;
margin-top: 3px;
color: rgba(47, 41, 36, 0.5);
font-size: 7px;
letter-spacing: 0.1em;
}
.stage-button.active {
background: var(--accent);
color: #fff7ef;
box-shadow: inset 4px 0 0 rgba(47, 41, 36, 0.25);
}
.stage-button.active span {
color: rgba(255, 247, 239, 0.72);
}
.reset {
font-size: 18px;
line-height: 1;
}
.camera-hint {
position: fixed;
z-index: 8;
right: 28px;
bottom: 28px;
pointer-events: none;
color: rgba(47, 41, 36, 0.6);
font-size: 9px;
line-height: 1.6;
letter-spacing: 0.09em;
text-align: right;
text-transform: uppercase;
}
@media (max-width: 850px) {
.header {
top: 16px;
left: 16px;
}
.header .subtitle {
display: none;
}
.info-card {
top: 16px;
right: 16px;
width: 250px;
padding: 14px;
}
.stage-copy {
min-height: 0;
}
.controls {
bottom: 12px;
overflow-x: auto;
}
.stage-button {
min-width: 74px;
}
.camera-hint {
display: none;
}
}
@media (max-width: 580px) {
.header h1 {
max-width: 170px;
font-size: 22px;
}
.header .kicker {
font-size: 7px;
}
.info-card {
top: 92px;
right: 12px;
width: 205px;
}
.info-card .card-top {
margin-bottom: 8px;
font-size: 7px;
}
.stage-title {
font-size: 18px;
}
.stage-copy {
font-size: 8px;
}
.metric {
margin-top: 10px;
}
.controls {
gap: 4px;
width: calc(100vw - 16px);
padding: 5px;
}
button {
min-height: 39px;
padding: 0 8px;
font-size: 7px;
}
button.primary {
min-width: 70px;
}
.stage-button {
min-width: 68px;
}
}
</style>
</head>
<body>
<header class="header">
<div class="kicker">Voxel workshop · surface study 04</div>
<h1>Sand the form.<br />Keep the shape.</h1>
<p class="subtitle">
A four-stage grit sequence applied to one fixed toy-block silhouette.
</p>
</header>
<aside class="info-card">
<div class="card-top">
<span>Current surface</span>
<span class="lock">Form locked</span>
</div>
<h2 class="stage-title" id="stageTitle">Raw / 80 grit</h2>
<p class="stage-copy" id="stageCopy">
Open pores and stubborn fibers. The block still reads dry and coarse.
</p>
<div class="metric">
<div class="metric-line">
<span>Roughness</span>
<span id="roughnessValue">96%</span>
</div>
<div class="meter">
<span id="roughnessBar"></span>
</div>
</div>
<div class="metric">
<div class="metric-line">
<span>Silhouette</span>
<span>100%</span>
</div>
<div class="meter form-meter">
<span></span>
</div>
</div>
</aside>
<nav class="controls" aria-label="Sanding sequence controls">
<button class="primary" id="playButton" type="button">Pause</button>
<button class="stage-button active" data-stage="0" type="button">
Raw
<span>80 GRIT</span>
</button>
<button class="stage-button" data-stage="1" type="button">
Coarse
<span>120 GRIT</span>
</button>
<button class="stage-button" data-stage="2" type="button">
Fine
<span>220 GRIT</span>
</button>
<button class="stage-button" data-stage="3" type="button">
Satin
<span>320 GRIT</span>
</button>
<button class="reset" id="resetButton" type="button" aria-label="Restart">
↺
</button>
</nav>
<div class="camera-hint">
Drag to orbit · scroll to zoom<br />
Arrow keys change grit · space pauses
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, camera, lighting
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel sanding workshop"
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d0c4);
scene.fog = new THREE.Fog(0xd8d0c4, 15, 30);
const camera = new THREE.OrthographicCamera(-6, 6, 4, -4, 0.1, 80);
const cameraTarget = new THREE.Vector3(0.15, 1.35, 0);
let cameraYaw = 0.61;
let cameraPitch = 0.55;
let cameraZoom = 1;
function updateCamera() {
const horizontal = Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + 12 * horizontal * Math.sin(cameraYaw),
cameraTarget.y + 12 * Math.sin(cameraPitch),
cameraTarget.z + 12 * horizontal * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function resize() {
const aspect = window.innerWidth / window.innerHeight;
const halfHeight = aspect < 1 ? 4.7 / aspect : 3.65;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const hemisphere = new THREE.HemisphereLight(
0xfff7e8,
0x756a5d,
2.1
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d7, 4.3);
keyLight.position.set(-3.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xc7d7d5, 1.8);
rimLight.position.set(6, 4, -5);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffb979, 1.1, 13);
warmFill.position.set(1, 3.8, 4);
scene.add(warmFill);
// ------------------------------------------------------------
// Utilities and procedural pixel textures
// ------------------------------------------------------------
let randomSeed = 81273;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function hash(x, y, seed = 0) {
const value = Math.sin(
x * 127.1 + y * 311.7 + seed * 74.7
) * 43758.5453123;
return value - Math.floor(value);
}
function mix(a, b, t) {
return a + (b - a) * t;
}
function createCanvas(size = 128) {
const canvas = document.createElement("canvas");
canvas.width = size;
canvas.height = size;
return canvas;
}
function makeTexture(canvas, nearest = true) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
if (nearest) {
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.NearestFilter;
}
texture.generateMipmaps = false;
return texture;
}
// The wood texture becomes cleaner while the geometry remains untouched.
function paintWood(canvas, smoothness, seed = 0) {
const context = canvas.getContext("2d", {
willReadFrequently: true
});
const image = context.createImageData(
canvas.width,
canvas.height
);
const data = image.data;
const roughColor = [139, 93, 51];
const smoothColor = [229, 172, 101];
for (let y = 0; y < canvas.height; y++) {
for (let x = 0; x < canvas.width; x++) {
const index = (y * canvas.width + x) * 4;
const broadGrain =
Math.sin(y * 0.22 + Math.sin(x * 0.045) * 1.8) *
mix(13, 2.2, smoothness);
const fineFiber =
Math.sin(y * 0.82 + hash(x, y, seed) * 2.4) *
mix(4, 0.7, smoothness);
const grit =
(hash(x, y, seed + 8) - 0.5) *
mix(31, 4, smoothness);
const pit =
hash(x, y, seed + 19) < mix(0.055, 0.002, smoothness)
? -mix(54, 8, smoothness)
: 0;
data[index] =
mix(roughColor[0], smoothColor[0], smoothness) +
broadGrain +
fineFiber +
grit +
pit;
data[index + 1] =
mix(roughColor[1], smoothColor[1], smoothness) +
broadGrain * 0.82 +
fineFiber * 0.75 +
grit * 0.72 +
pit;
data[index + 2] =
mix(roughColor[2], smoothColor[2], smoothness) +
broadGrain * 0.58 +
fineFiber * 0.52 +
grit * 0.48 +
pit * 0.7;
data[index + 3] = 255;
}
}
context.putImageData(image, 0, 0);
}
function paintGrit(canvas, baseColor, seed) {
const context = canvas.getContext("2d");
const image = context.createImageData(
canvas.width,
canvas.height
);
const data = image.data;
for (let y = 0; y < canvas.height; y++) {
for (let x = 0; x < canvas.width; x++) {
const index = (y * canvas.width + x) * 4;
const noise = hash(x, y, seed);
const fleck = hash(x, y, seed + 41);
let shift = (noise - 0.5) * 65;
if (fleck > 0.84) {
shift += 60;
} else if (fleck < 0.08) {
shift -= 45;
}
data[index] = Math.max(
0,
Math.min(255, baseColor[0] + shift)
);
data[index + 1] = Math.max(
0,
Math.min(255, baseColor[1] + shift * 0.8)
);
data[index + 2] = Math.max(
0,
Math.min(255, baseColor[2] + shift * 0.55)
);
data[index + 3] = 255;
}
}
context.putImageData(image, 0, 0);
}
function makeLabel(text, worldWidth = 1.55) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(244,238,228,0.94)";
context.fillRect(2, 2, 508, 92);
context.strokeStyle = "rgba(47,41,36,0.48)";
context.lineWidth = 4;
context.strokeRect(2, 2, 508, 92);
context.fillStyle = "#2f2924";
context.font =
"800 27px ui-monospace, SFMono-Regular, Menlo, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 49);
const texture = makeTexture(canvas, false);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldWidth * 96 / 512, 1);
sprite.renderOrder = 20;
return sprite;
}
function addEdges(mesh, color = 0x4a3527, opacity = 0.34) {
const edges = new THREE.EdgesGeometry(mesh.geometry);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
const outline = new THREE.LineSegments(edges, material);
outline.renderOrder = 2;
mesh.add(outline);
return outline;
}
function makeBox(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = scene,
outlined = false
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outlined) {
addEdges(mesh);
}
return mesh;
}
// ------------------------------------------------------------
// Workbench, wall, tray, and fixed voxel toy
// ------------------------------------------------------------
const benchMaterial = new THREE.MeshStandardMaterial({
color: 0x9d8060,
roughness: 0.93
});
const bench = makeBox(
11.5,
0.42,
8.2,
benchMaterial,
0,
-0.25,
-0.2
);
addEdges(bench, 0x4d392c, 0.18);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xddd5c8,
roughness: 1
});
const wall = makeBox(
18,
8,
0.2,
wallMaterial,
0,
3.4,
-3.75
);
wall.receiveShadow = true;
const trayMaterial = new THREE.MeshStandardMaterial({
color: 0x756f63,
roughness: 0.85
});
const tray = new THREE.Group();
tray.position.set(-1.55, 0, 0.12);
scene.add(tray);
makeBox(3.75, 0.14, 3.0, trayMaterial, 0, 0.07, 0, tray, true);
makeBox(3.85, 0.22, 0.15, trayMaterial, 0, 0.19, 1.5, tray, true);
makeBox(3.85, 0.22, 0.15, trayMaterial, 0, 0.19, -1.5, tray, true);
makeBox(0.15, 0.22, 3.05, trayMaterial, -1.85, 0.19, 0, tray, true);
makeBox(0.15, 0.22, 3.05, trayMaterial, 1.85, 0.19, 0, tray, true);
const toyCanvas = createCanvas(128);
const toyTexture = makeTexture(toyCanvas);
paintWood(toyCanvas, 0);
const toyWood = new THREE.MeshPhysicalMaterial({
map: toyTexture,
bumpMap: toyTexture,
bumpScale: 0.095,
roughness: 0.96,
metalness: 0,
clearcoat: 0.02,
clearcoatRoughness: 0.62
});
const darkWood = new THREE.MeshStandardMaterial({
color: 0x38271d,
roughness: 0.72
});
const paintedRed = new THREE.MeshStandardMaterial({
color: 0xb85e42,
roughness: 0.62
});
const toy = new THREE.Group();
toy.position.set(-1.55, 0, 0.05);
scene.add(toy);
// IMPORTANT: this geometry is never scaled, moved, or replaced
// by the sanding stages. Only materials and textures change.
makeBox(2.25, 1.9, 2.05, toyWood, 0, 1.32, 0, toy, true);
makeBox(0.52, 0.38, 0.72, toyWood, -0.72, 0.31, 0, toy, true);
makeBox(0.52, 0.38, 0.72, toyWood, 0.72, 0.31, 0, toy, true);
makeBox(0.42, 0.25, 0.42, toyWood, 0, 2.39, 0, toy, true);
makeBox(0.78, 0.35, 0.78, toyWood, 0, 2.66, 0, toy, true);
makeBox(0.16, 0.42, 0.42, toyWood, 1.205, 1.3, 0, toy, true);
const letterPixels = [
"11110",
"10001",
"10001",
"11110",
"10001",
"10001",
"11110"
];
const pixelSize = 0.115;
letterPixels.forEach((row, rowIndex) => {
[...row].forEach((pixel, columnIndex) => {
if (pixel !== "1") return;
makeBox(
0.102,
0.102,
0.055,
darkWood,
(columnIndex - 2) * pixelSize,
1.32 + (3 - rowIndex) * pixelSize,
1.047,
toy
);
});
});
makeBox(
0.07,
0.38,
0.38,
paintedRed,
-1.155,
1.35,
0,
toy
);
// ------------------------------------------------------------
// Sandpaper pads, visible grit, and an animated working pad
// ------------------------------------------------------------
const padColors = [
[142, 91, 55],
[165, 113, 70],
[190, 139, 91]
];
const gritMaterials = [];
for (let index = 0; index < 3; index++) {
const gritCanvas = createCanvas(64);
paintGrit(gritCanvas, padColors[index], 40 + index * 19);
const gritTexture = makeTexture(gritCanvas);
const gritMaterial = new THREE.MeshStandardMaterial({
map: gritTexture,
roughness: 1,
metalness: 0
});
gritMaterials.push(gritMaterial);
const backingMaterial = new THREE.MeshStandardMaterial({
color: 0x51463d,
roughness: 0.92
});
const pad = new THREE.Group();
pad.position.set(
1.82 + index * 0.76,
0.57,
0.62 + Math.sin(index * 1.7) * 0.08
);
pad.rotation.set(
-0.09,
-0.18 + index * 0.2,
index === 1 ? -0.045 : 0.025
);
scene.add(pad);
makeBox(
1.07,
0.82,
0.07,
backingMaterial,
0,
0,
-0.065,
pad,
true
);
makeBox(
1.0,
0.75,
0.055,
gritMaterial,
0,
0,
0.005,
pad,
true
);
// Actual voxel grit sitting on the paper face.
const lightGrit = new THREE.MeshStandardMaterial({
color: index === 0 ? 0xd6b080 : 0xe2c49a,
roughness: 1
});
const darkGrit = new THREE.MeshStandardMaterial({
color: index === 0 ? 0x5a3928 : 0x77513a,
roughness: 1
});
for (let grainIndex = 0; grainIndex < 22; grainIndex++) {
const size = 0.018 + random() * 0.026;
makeBox(
size,
size,
size * 0.65,
random() > 0.45 ? lightGrit : darkGrit,
(random() - 0.5) * 0.9,
(random() - 0.5) * 0.65,
0.045 + random() * 0.012,
pad
);
}
}
const activeGritCanvas = createCanvas(64);
paintGrit(activeGritCanvas, [178, 119, 72], 91);
const activeGritTexture = makeTexture(activeGritCanvas);
const activePadMaterial = new THREE.MeshStandardMaterial({
map: activeGritTexture,
roughness: 1,
transparent: true,
opacity: 1
});
const activePadBack = new THREE.MeshStandardMaterial({
color: 0x55473c,
roughness: 0.9,
transparent: true,
opacity: 1
});
const activePad = new THREE.Group();
scene.add(activePad);
makeBox(
1.03,
0.77,
0.06,
activePadBack,
0,
0,
-0.06,
activePad,
true
);
makeBox(
0.97,
0.71,
0.065,
activePadMaterial,
0,
0,
0,
activePad,
true
);
// ------------------------------------------------------------
// Finish samples and selection marker
// ------------------------------------------------------------
const stageData = [
{
title: "Raw / 80 grit",
copy:
"Open pores and stubborn fibers. The block still reads dry and coarse.",
smoothness: 0,
roughness: 0.96
},
{
title: "Coarse / 120 grit",
copy:
"The first pass knocks down high spots while leaving the warm grain intact.",
smoothness: 0.34,
roughness: 0.72
},
{
title: "Fine / 220 grit",
copy:
"The texture tightens. Scratches become finer and the block starts to glow.",
smoothness: 0.68,
roughness: 0.46
},
{
title: "Satin / 320 grit",
copy:
"A clean satin finish. The surface changes; the familiar silhouette does not.",
smoothness: 1,
roughness: 0.22
}
];
const sampleMaterials = [];
const sampleMeshes = [];
const shelfMaterial = new THREE.MeshStandardMaterial({
color: 0x74685c,
roughness: 0.86
});
makeBox(
3.5,
0.16,
0.84,
shelfMaterial,
1.92,
1.03,
-1.72,
scene,
true
);
stageData.forEach((stage, index) => {
const sampleCanvas = createCanvas(128);
paintWood(sampleCanvas, stage.smoothness, index * 31 + 4);
const sampleTexture = makeTexture(sampleCanvas);
const material = new THREE.MeshPhysicalMaterial({
map: sampleTexture,
bumpMap: sampleTexture,
bumpScale: mix(0.075, 0.008, stage.smoothness),
roughness: stage.roughness,
metalness: 0,
clearcoat: mix(0.02, 0.58, stage.smoothness),
clearcoatRoughness: mix(0.6, 0.16, stage.smoothness)
});
sampleMaterials.push(material);
const sample = makeBox(
0.54,
0.54,
0.54,
material,
0.62 + index * 0.87,
1.4,
-1.72,
scene,
true
);
sampleMeshes.push(sample);
const gritLabel = makeLabel(
["80", "120", "220", "320"][index],
0.39
);
gritLabel.position.set(
0.62 + index * 0.87,
1.02,
-1.28
);
scene.add(gritLabel);
});
const selectionMarker = new THREE.Mesh(
new THREE.BoxGeometry(0.62, 0.62, 0.62),
new THREE.MeshBasicMaterial({
color: 0xd56f49,
wireframe: true,
transparent: true,
opacity: 0.82
})
);
scene.add(selectionMarker);
// ------------------------------------------------------------
// Dust tray particles and airborne sanding dust
// ------------------------------------------------------------
const dustMaterial = new THREE.MeshStandardMaterial({
color: 0xc39762,
roughness: 1,
metalness: 0
});
const settledDust = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.035, 0.035, 0.035),
dustMaterial,
58
);
settledDust.receiveShadow = true;
scene.add(settledDust);
const dummy = new THREE.Object3D();
for (let index = 0; index < settledDust.count; index++) {
dummy.position.set(
-1.55 + (random() - 0.5) * 3.35,
0.17 + random() * 0.025,
0.12 + (random() - 0.5) * 2.55
);
dummy.rotation.set(
random() * Math.PI,
random() * Math.PI,
random() * Math.PI
);
const size = 0.6 + random() * 1.4;
dummy.scale.setScalar(size);
dummy.updateMatrix();
settledDust.setMatrixAt(index, dummy.matrix);
}
settledDust.instanceMatrix.needsUpdate = true;
const airborneCount = 72;
const airborneDust = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.04, 0.04, 0.04),
new THREE.MeshStandardMaterial({
color: 0xd4a66d,
roughness: 1,
vertexColors: true
}),
airborneCount
);
airborneDust.instanceMatrix.setUsage(
THREE.DynamicDrawUsage
);
airborneDust.frustumCulled = false;
scene.add(airborneDust);
const dustParticles = Array.from(
{ length: airborneCount },
() => ({
alive: false,
position: new THREE.Vector3(),
velocity: new THREE.Vector3(),
life: 0,
maxLife: 1
})
);
const particleColor = new THREE.Color();
for (let index = 0; index < airborneCount; index++) {
dummy.scale.setScalar(0);
dummy.updateMatrix();
airborneDust.setMatrixAt(index, dummy.matrix);
particleColor.setHSL(
0.085 + random() * 0.035,
0.4,
0.48 + random() * 0.18
);
airborneDust.setColorAt(index, particleColor);
}
airborneDust.instanceColor.needsUpdate = true;
let dustCursor = 0;
function spawnDust(amount = 26, originX = -1.65) {
for (let count = 0; count < amount; count++) {
const particle = dustParticles[dustCursor];
dustCursor = (dustCursor + 1) % airborneCount;
particle.alive = true;
particle.maxLife = 0.65 + random() * 1.25;
particle.life = particle.maxLife;
particle.position.set(
originX + (random() - 0.5) * 0.85,
1.22 + random() * 0.6,
1.02 + random() * 0.25
);
particle.velocity.set(
(random() - 0.5) * 1.3,
0.25 + random() * 1.0,
(random() - 0.25) * 0.75
);
}
}
function updateDust(delta) {
for (let index = 0; index < airborneCount; index++) {
const particle = dustParticles[index];
if (particle.alive) {
particle.life -= delta;
particle.velocity.y -= 2.1 * delta;
particle.position.addScaledVector(
particle.velocity,
delta
);
if (particle.position.y < 0.18) {
particle.position.y = 0.18;
particle.velocity.y = Math.abs(
particle.velocity.y
) * 0.22;
particle.velocity.x *= 0.72;
particle.velocity.z *= 0.72;
}
if (particle.life <= 0) {
particle.alive = false;
}
}
if (particle.alive) {
dummy.position.copy(particle.position);
dummy.rotation.set(
particle.life * 4,
particle.life * 3,
particle.life * 5
);
dummy.scale.setScalar(
Math.min(1, particle.life * 2.5)
);
} else {
dummy.scale.setScalar(0);
}
dummy.updateMatrix();
airborneDust.setMatrixAt(index, dummy.matrix);
}
airborneDust.instanceMatrix.needsUpdate = true;
}
// ------------------------------------------------------------
// Scene labels
// ------------------------------------------------------------
const toyLabel = makeLabel("TOY BLOCK", 1.55);
toyLabel.position.set(-1.55, 3.2, 0.05);
scene.add(toyLabel);
const trayLabel = makeLabel("DUST TRAY", 1.45);
trayLabel.position.set(-1.55, 0.33, 1.78);
scene.add(trayLabel);
const padsLabel = makeLabel("SANDING PADS", 1.75);
padsLabel.position.set(2.65, 1.32, 0.75);
scene.add(padsLabel);
const finishLabel = makeLabel("FINISH SAMPLES", 1.85);
finishLabel.position.set(1.92, 2.08, -1.72);
scene.add(finishLabel);
// ------------------------------------------------------------
// Sequence state and interface
// ------------------------------------------------------------
const stageButtons = [
...document.querySelectorAll(".stage-button")
];
const playButton = document.getElementById("playButton");
const resetButton = document.getElementById("resetButton");
const stageTitle = document.getElementById("stageTitle");
const stageCopy = document.getElementById("stageCopy");
const roughnessValue = document.getElementById(
"roughnessValue"
);
const roughnessBar = document.getElementById("roughnessBar");
let currentStage = 0;
let playing = true;
let timeInStage = 0;
let transition = 1;
let smoothCurrent = 0;
let smoothTarget = 0;
let lastTexturePaint = -1;
let dustAccumulator = 0;
function updatePlayLabel() {
if (playing) {
playButton.textContent = "Pause";
} else if (currentStage === 3) {
playButton.textContent = "↻ Replay";
} else {
playButton.textContent = "Play";
}
}
function setStage(index, burst = true) {
currentStage = index;
timeInStage = 0;
transition = 0;
const stage = stageData[index];
smoothTarget = stage.smoothness;
stageTitle.textContent = stage.title;
stageCopy.textContent = stage.copy;
stageButtons.forEach((button, buttonIndex) => {
button.classList.toggle(
"active",
buttonIndex === currentStage
);
});
if (index === 3) {
playing = false;
}
if (burst) {
spawnDust(34);
}
updatePlayLabel();
}
stageButtons.forEach((button) => {
button.addEventListener("click", () => {
const index = Number(button.dataset.stage);
setStage(index, true);
});
});
playButton.addEventListener("click", () => {
if (playing) {
playing = false;
} else {
if (currentStage === 3) {
setStage(0, true);
}
playing = true;
}
updatePlayLabel();
});
resetButton.addEventListener("click", () => {
setStage(0, true);
playing = true;
updatePlayLabel();
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.code === "ArrowRight") {
setStage(
Math.min(3, currentStage + 1),
true
);
}
if (event.code === "ArrowLeft") {
setStage(
Math.max(0, currentStage - 1),
true
);
}
});
// ------------------------------------------------------------
// Direct camera controls — no addons or examples modules
// ------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraYaw -= deltaX * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch - deltaY * 0.005,
0.22,
1.12
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(
event.pointerId
);
}
}
renderer.domElement.addEventListener(
"pointerup",
endDrag
);
renderer.domElement.addEventListener(
"pointercancel",
endDrag
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.65
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraYaw = 0.61;
cameraPitch = 0.55;
cameraZoom = 1;
updateCamera();
});
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (playing && currentStage < 3) {
timeInStage += delta;
if (timeInStage >= 3.35) {
setStage(currentStage + 1, true);
}
}
transition = Math.min(1, transition + delta / 1.45);
const smoothing = 1 - Math.exp(-5.4 * delta);
smoothCurrent +=
(smoothTarget - smoothCurrent) * smoothing;
toyWood.roughness = mix(
0.96,
0.22,
smoothCurrent
);
toyWood.bumpScale = mix(
0.095,
0.008,
smoothCurrent
);
toyWood.clearcoat = mix(
0.02,
0.58,
smoothCurrent
);
toyWood.clearcoatRoughness = mix(
0.62,
0.16,
smoothCurrent
);
if (
lastTexturePaint < 0 ||
elapsed - lastTexturePaint > 0.075
) {
paintWood(toyCanvas, smoothCurrent, 3);
toyTexture.needsUpdate = true;
lastTexturePaint = elapsed;
}
const roughness = Math.round(
toyWood.roughness * 100
);
roughnessValue.textContent = `${roughness}%`;
roughnessBar.style.width = `${roughness}%`;
// The moving pad is the only active sanding object.
// It never changes the toy's geometry.
if (transition < 1) {
const t = transition;
activePad.visible = true;
activePad.position.set(
-2.42 + t * 1.72,
1.28 + Math.sin(t * Math.PI) * 0.32,
1.18 + Math.sin(t * Math.PI) * 0.045
);
activePad.rotation.set(
-0.08,
-0.08 + Math.sin(t * Math.PI) * 0.12,
-0.07 + Math.sin(t * Math.PI * 2) * 0.06
);
const opacity = Math.min(
1,
Math.sin(Math.min(1, t * 1.35) * Math.PI) * 2
);
activePadMaterial.opacity = opacity;
activePadBack.opacity = opacity;
dustAccumulator += delta;
if (dustAccumulator > 0.07) {
dustAccumulator = 0;
spawnDust(
3,
activePad.position.x
);
}
} else {
activePad.visible = false;
activePadMaterial.opacity = 1;
activePadBack.opacity = 1;
}
const selectedSample = sampleMeshes[currentStage];
selectionMarker.position.copy(
selectedSample.position
);
selectionMarker.rotation.y =
Math.sin(elapsed * 0.8) * 0.08;
selectionMarker.scale.setScalar(
1.055 + Math.sin(elapsed * 3.2) * 0.025
);
updateDust(delta);
renderer.render(scene, camera);
}
setStage(0, false);
updateCamera();
animate();
</script>
</body>
</html>
```