Prompt specification
Build or customize the Three.js 3D scene "Chair stack assembly" 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: Chair stack assembly
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/chair-stack-assembly-x0178
Scene Description Prompt:
Please make a low-poly Three.js scene in one standalone HTML file using cdnjs. Animate four chairs joining a stack along one vertical path; show each stopping at its intended contact points while the remaining stack stays stationary.
Working Three.js Starter (chair-stack-assembly-x0178):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Four-Chair Stack — Three.js</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(14, 21, 36, 0.86);
--border: rgba(255, 255, 255, 0.12);
--muted: #9ba9bd;
--text: #f4f7fb;
--accent: #67e8f9;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0b1120;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
width: min(340px, calc(100vw - 40px));
padding: 18px;
border: 1px solid var(--border);
border-radius: 16px;
color: var(--text);
background: var(--panel);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
user-select: none;
}
h1 {
margin: 0 0 5px;
font-size: 20px;
letter-spacing: -0.02em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.progress {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin: 17px 0 13px;
}
.progress span {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.12);
transition: background 180ms ease, box-shadow 180ms ease;
}
.progress span.active {
background: var(--accent);
box-shadow: 0 0 12px rgba(103, 232, 249, 0.75);
}
.progress span.done {
background: #73e2a1;
}
#status {
min-height: 40px;
margin-bottom: 12px;
color: #dce7f5;
font-size: 13px;
line-height: 1.45;
}
.contacts-title {
margin: 14px 0 8px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.contact {
display: grid;
grid-template-columns: 20px 1fr auto;
align-items: center;
gap: 8px;
padding: 7px 0;
border-top: 1px solid rgba(255, 255, 255, 0.07);
color: #76849a;
font-size: 11px;
transition: color 180ms ease;
}
.contact:last-child {
padding-bottom: 0;
}
.contact.active {
color: var(--accent);
}
.contact.done {
color: #73e2a1;
}
.contact .dot {
width: 7px;
height: 7px;
margin-left: 3px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 8px currentColor;
}
.contact .height {
color: #758299;
font-variant-numeric: tabular-nums;
}
button {
width: 100%;
margin-top: 15px;
padding: 10px 12px;
border: 1px solid rgba(103, 232, 249, 0.3);
border-radius: 10px;
color: #dffbff;
background: rgba(103, 232, 249, 0.1);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(103, 232, 249, 0.18);
}
button:active {
transform: translateY(1px);
}
.help {
position: fixed;
right: 20px;
bottom: 18px;
z-index: 10;
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 999px;
color: #aab7c8;
background: rgba(14, 21, 36, 0.7);
font-size: 11px;
backdrop-filter: blur(10px);
pointer-events: none;
}
@media (max-width: 650px) {
.panel {
top: 12px;
left: 12px;
width: min(310px, calc(100vw - 24px));
padding: 14px;
}
h1 {
font-size: 17px;
}
.help {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<section class="panel">
<h1>Four-Chair Stack</h1>
<p class="subtitle">
Each chair descends independently along one vertical guide.
Already-placed chairs remain completely stationary.
</p>
<div class="progress" aria-hidden="true">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<div id="status" role="status" aria-live="polite"></div>
<div class="contacts-title">Intended contact points</div>
<div id="contact-list"></div>
<button id="replay" type="button">Replay stacking sequence</button>
</section>
<div class="help">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const statusElement = document.querySelector("#status");
const replayButton = document.querySelector("#replay");
const progressElements = [
...document.querySelectorAll(".progress span")
];
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1120);
scene.fog = new THREE.Fog(0x0b1120, 18, 35);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// -------------------------------------------------------------------------
// Direct camera controls: no addons or examples are imported.
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 4.8, 0);
const orbit = {
azimuth: 0.72,
polar: 1.24,
radius: 15.3
};
function updateCamera() {
const sinPolar = Math.sin(orbit.polar);
const cosPolar = Math.cos(orbit.polar);
camera.position.set(
cameraTarget.x + orbit.radius * sinPolar * Math.cos(orbit.azimuth),
cameraTarget.y + orbit.radius * cosPolar,
cameraTarget.z + orbit.radius * sinPolar * Math.sin(orbit.azimuth)
);
camera.lookAt(cameraTarget);
}
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
orbit.azimuth -= deltaX * 0.006;
orbit.polar = THREE.MathUtils.clamp(
orbit.polar + deltaY * 0.006,
0.38,
1.47
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (
event.pointerType !== "mouse" &&
canvas.hasPointerCapture?.(event.pointerId)
) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
7,
24
);
updateCamera();
},
{ passive: false }
);
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xc8e8ff,
0x202333,
1.8
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3df, 3.2);
keyLight.position.set(7, 12, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 14;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 32;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x65d9ff, 1.5);
rimLight.position.set(-8, 7, -6);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0xf06cff, 18, 20, 2);
fillLight.position.set(0, 7, 4);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Ground and the one vertical stacking path
// -------------------------------------------------------------------------
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(5.8, 6.1, 0.22, 32),
new THREE.MeshStandardMaterial({
color: 0x182338,
roughness: 0.92,
metalness: 0.03,
flatShading: true
})
);
platform.position.y = -0.11;
platform.receiveShadow = true;
scene.add(platform);
const grid = new THREE.GridHelper(10, 20, 0x3a5675, 0x263751);
grid.position.y = 0.006;
grid.material.transparent = true;
grid.material.opacity = 0.38;
scene.add(grid);
const pathGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.08, 0),
new THREE.Vector3(0, 11.8, 0)
]);
const pathMaterial = new THREE.LineDashedMaterial({
color: 0x67e8f9,
transparent: true,
opacity: 0.42,
dashSize: 0.17,
gapSize: 0.12,
depthWrite: false
});
const path = new THREE.Line(pathGeometry, pathMaterial);
path.computeLineDistances();
scene.add(path);
// -------------------------------------------------------------------------
// Low-poly chair construction
//
// Local chair bounds:
// lowest point = -0.90 (feet)
// highest point = 1.08 (top of backrest)
//
// Therefore each upright chair adds exactly 1.98 world units to the stack.
// -------------------------------------------------------------------------
const CHAIR_HEIGHT = 1.98;
const FIRST_TARGET = 0.9;
const chairColors = [
0xf06f61,
0x46c6b5,
0xf2bf58,
0x9b7bea
];
const chairStarts = [
4.5,
6.48,
8.46,
10.44
];
const chairTargets = chairStarts.map((_, index) => {
return FIRST_TARGET + index * CHAIR_HEIGHT;
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x182132,
roughness: 0.78,
metalness: 0.08,
flatShading: true
});
function addBox(group, width, height, depth, position, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color: 0x101827,
transparent: true,
opacity: 0.5
})
);
mesh.add(edges);
return mesh;
}
function createChair(color, index) {
const group = new THREE.Group();
const coloredMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.68,
metalness: 0.04,
flatShading: true
});
const seatTopMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(color).offsetHSL(0, -0.04, 0.08),
roughness: 0.78,
metalness: 0.02,
flatShading: true
});
// Seat: local y range -0.08 to 0.08.
addBox(
group,
1.2,
0.16,
1.0,
new THREE.Vector3(0, 0, 0),
coloredMaterial
);
// Thin top surface for a slightly layered low-poly look.
addBox(
group,
1.12,
0.035,
0.92,
new THREE.Vector3(0, 0.095, 0),
seatTopMaterial
);
// Four five-sided tapered legs.
const legGeometry = new THREE.CylinderGeometry(
0.055,
0.078,
0.82,
5
);
const legPositions = [
[-0.47, -0.38],
[0.47, -0.38],
[-0.47, 0.38],
[0.47, 0.38]
];
for (const [x, z] of legPositions) {
const leg = new THREE.Mesh(legGeometry, darkMaterial);
leg.position.set(x, -0.49, z);
leg.rotation.y = Math.PI / 4;
leg.castShadow = true;
leg.receiveShadow = true;
group.add(leg);
}
// Rear uprights.
for (const x of [-0.47, 0.47]) {
addBox(
group,
0.1,
0.5,
0.1,
new THREE.Vector3(x, 0.23, -0.43),
darkMaterial
);
}
// Backrest: local top is exactly y = 1.08.
addBox(
group,
1.2,
0.7,
0.14,
new THREE.Vector3(0, 0.73, -0.43),
coloredMaterial
);
// Small lower back rail.
addBox(
group,
0.98,
0.09,
0.1,
new THREE.Vector3(0, 0.38, -0.43),
darkMaterial
);
group.position.set(0, chairStarts[index], 0);
group.userData.index = index;
scene.add(group);
return group;
}
const chairs = chairColors.map((color, index) => {
return createChair(color, index);
});
// -------------------------------------------------------------------------
// Contact indicators
//
// Two small rings mark where the next chair's rear feet meet the previous
// chair's backrest. The first pair marks the floor contact.
// -------------------------------------------------------------------------
const contactMarkers = [];
for (let index = 0; index < chairs.length; index++) {
const contactY =
index === 0 ? 0 : chairTargets[index - 1] + 1.08;
const markerGroup = new THREE.Group();
const markerMaterials = [];
for (const x of [-0.47, 0.47]) {
const material = new THREE.MeshBasicMaterial({
color: 0x67e8f9,
transparent: true,
opacity: 0.14,
depthWrite: false,
depthTest: false
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.105, 0.018, 6, 18),
material
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, contactY + 0.012, -0.4);
ring.renderOrder = 20;
markerMaterials.push(material);
markerGroup.add(ring);
}
scene.add(markerGroup);
contactMarkers.push({
group: markerGroup,
materials: markerMaterials,
y: contactY
});
}
// -------------------------------------------------------------------------
// Contact log UI
// -------------------------------------------------------------------------
const contactNames = [
"Floor",
"Chair 1 → Chair 2",
"Chair 2 → Chair 3",
"Chair 3 → Chair 4"
];
const contactRows = contactNames.map((name, index) => {
const row = document.createElement("div");
row.className = "contact";
const y =
index === 0 ? 0 : chairTargets[index - 1] + 1.08;
row.innerHTML = `
<span class="dot"></span>
<span>${name}</span>
<span class="height">y ${y.toFixed(2)}</span>
`;
document.querySelector("#contact-list").appendChild(row);
return row;
});
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
const DROP_DURATION = 1.35;
const CONTACT_HOLD = 0.5;
let activeChair = 0;
let phaseTime = 0;
let landingFlash = 0;
let complete = false;
function dropEase(t) {
// Accelerate during the first part, then decelerate into the contact.
if (t < 0.68) {
const q = t / 0.68;
return 0.36 * q * q;
}
const q = (t - 0.68) / 0.32;
return 0.36 + 0.64 * (1 - Math.pow(1 - q, 3));
}
function updateInterface() {
progressElements.forEach((element, index) => {
element.className = "";
if (index < activeChair) {
element.classList.add("done");
} else if (index === activeChair && !complete) {
element.classList.add("active");
} else if (complete) {
element.classList.add("done");
}
});
contactRows.forEach((row, index) => {
row.className = "contact";
if (index < activeChair) {
row.classList.add("done");
} else if (index === activeChair && !complete) {
row.classList.add("active");
} else if (complete) {
row.classList.add("done");
}
});
if (complete) {
statusElement.textContent =
"Stack complete — 4 chairs locked at their intended contacts.";
} else {
const destination =
activeChair === 0
? "the floor contact"
: `chair ${activeChair}'s backrest`;
statusElement.textContent =
`Chair ${activeChair + 1} of 4 — descending to ${destination}.`;
}
}
function beginChair(index) {
activeChair = index;
phaseTime = 0;
landingFlash = 0;
chairs[index].userData.landed = false;
updateInterface();
}
function resetAnimation() {
activeChair = 0;
phaseTime = 0;
landingFlash = 0;
complete = false;
chairs.forEach((chair, index) => {
chair.position.set(0, chairStarts[index], 0);
chair.userData.landed = false;
});
beginChair(0);
}
function animateStack(deltaTime) {
if (!complete) {
phaseTime += deltaTime;
const chair = chairs[activeChair];
const startY = chairStarts[activeChair];
const targetY = chairTargets[activeChair];
const progress = Math.min(
phaseTime / DROP_DURATION,
1
);
// Only the active chair's position is changed. Every previously
// placed chair remains exactly stationary.
chair.position.y = THREE.MathUtils.lerp(
startY,
targetY,
dropEase(progress)
);
if (progress >= 1) {
chair.position.y = targetY;
if (!chair.userData.landed) {
chair.userData.landed = true;
landingFlash = 1;
const contactText =
activeChair === 0
? "Floor contact locked."
: `Chair ${activeChair + 1} seated on chair ${activeChair}.`;
statusElement.textContent = contactText;
}
if (phaseTime >= DROP_DURATION + CONTACT_HOLD) {
if (activeChair === chairs.length - 1) {
complete = true;
updateInterface();
} else {
beginChair(activeChair + 1);
}
}
}
}
landingFlash = Math.max(0, landingFlash - deltaTime * 1.8);
// Contact rings pulse independently; the stack itself never moves.
const pulse = 0.5 + Math.sin(performance.now() * 0.004) * 0.5;
contactMarkers.forEach((marker, index) => {
let opacity = 0.12;
if (index < activeChair || complete) {
opacity = 0.68;
} else if (index === activeChair) {
opacity = 0.3 + pulse * 0.28;
}
if (index === activeChair) {
opacity += landingFlash * 0.35;
}
marker.materials.forEach((material) => {
material.opacity = Math.min(1, opacity);
});
});
}
replayButton.addEventListener("click", resetAnimation);
// -------------------------------------------------------------------------
// Render loop and resize handling
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const deltaTime = Math.min(clock.getDelta(), 0.05);
animateStack(deltaTime);
renderer.render(scene, camera);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
resetAnimation();
</script>
</body>
</html>
```