Prompt specification
Build or customize the Three.js 3D scene "Storage bench hinged section" 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: Storage bench hinged section
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/storage-bench-hinged-section-x0169
Scene Description Prompt:
Use Three.js from cdnjs to build a bench with raised seat lid and visible interior compartments; show the hinge axis and keep the supporting frame distinct from the movable cover. Deliver one self-contained HTML file with stylized solid shapes.
Working Three.js Starter (storage-bench-hinged-section-x0169):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hinged Storage Bench</title>
<style>
:root {
color-scheme: light;
--ink: #22343d;
--muted: #62747c;
--frame: #315866;
--cover: #e87542;
--hinge: #df3f46;
--paper: rgba(255, 255, 255, 0.92);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e5dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
z-index: 5;
pointer-events: none;
}
.title-block {
top: 24px;
left: 28px;
max-width: 360px;
}
.eyebrow {
margin: 0 0 7px;
color: #66808a;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 40px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.controls {
top: 24px;
right: 24px;
display: flex;
gap: 9px;
pointer-events: auto;
}
button {
border: 1px solid rgba(34, 52, 61, 0.14);
border-radius: 11px;
padding: 10px 14px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 24px rgba(40, 52, 58, 0.10);
font: inherit;
font-size: 13px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(8px);
transition: transform 150ms ease, box-shadow 150ms ease;
}
button:hover {
transform: translateY(-1px);
box-shadow: 0 10px 28px rgba(40, 52, 58, 0.16);
}
button:active { transform: translateY(0); }
.legend {
left: 28px;
bottom: 24px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: calc(100vw - 56px);
}
.legend-item,
.tag {
display: inline-flex;
align-items: center;
gap: 8px;
border: 1px solid rgba(34, 52, 61, 0.11);
border-radius: 999px;
background: var(--paper);
box-shadow: 0 7px 20px rgba(40, 52, 58, 0.09);
backdrop-filter: blur(8px);
}
.legend-item {
padding: 8px 12px;
color: #4e626b;
font-size: 12px;
font-weight: 700;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.frame { background: var(--frame); }
.swatch.cover { background: var(--cover); }
.swatch.hinge { background: var(--hinge); }
.help {
right: 26px;
bottom: 25px;
color: #6a7b82;
font-size: 12px;
font-weight: 650;
text-align: right;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.tag {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
color: #30434b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.015em;
transform: translate(-50%, -50%);
white-space: nowrap;
transition: opacity 100ms linear;
}
.tag::before {
content: "";
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.60);
}
.tag.axis { color: var(--hinge); }
.tag.cover { color: #c95a2d; }
.tag.frame { color: var(--frame); }
.tag.bays { color: #8a684e; }
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e9e5dc;
color: #40565f;
font-weight: 750;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.title-block { top: 18px; left: 18px; }
.subtitle { display: none; }
.controls { top: 16px; right: 16px; }
button { padding: 9px 11px; }
.legend { left: 16px; bottom: 16px; }
.help { display: none; }
.tag { font-size: 10px; padding: 6px 8px; }
}
</style>
</head>
<body>
<div id="app"></div>
<div class="hud title-block">
<p class="eyebrow">Exploded structural study</p>
<h1>Hinged Storage Bench</h1>
<p class="subtitle">A raised movable cover, three visible storage bays, and an emphasized pivot axle.</p>
</div>
<div class="hud controls">
<button id="lidButton" type="button" aria-live="polite">Lower lid</button>
<button id="resetButton" type="button">Reset view</button>
</div>
<div id="labels">
<div id="hingeTag" class="tag axis">Hinge axis</div>
<div id="coverTag" class="tag cover">Movable cover</div>
<div id="frameTag" class="tag frame">Supporting frame</div>
<div id="baysTag" class="tag bays">Interior compartments</div>
</div>
<div class="hud legend">
<div class="legend-item"><span class="swatch frame"></span>Support frame</div>
<div class="legend-item"><span class="swatch cover"></span>Movable cover</div>
<div class="legend-item"><span class="swatch hinge"></span>Hinge axis</div>
</div>
<div class="hud help">Drag to orbit · Scroll or pinch to zoom</div>
<div id="loading">Building the bench…</div>
<script type="module">
const loading = document.getElementById("loading");
let THREE;
try {
THREE = await import(
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"
);
} catch (error) {
loading.textContent = "Unable to load Three.js. Check your internet connection.";
throw error;
}
const app = document.getElementById("app");
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
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 three-dimensional storage bench");
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e5dc);
scene.fog = new THREE.Fog(0xe9e5dc, 12, 25);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
60
);
const target = new THREE.Vector3(0, 1.48, 0);
let azimuth = 0.68;
let polar = 1.12;
let radius = 9.2;
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff7e8, 0x71838c, 2.15));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(4.5, 8.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d9ff, 1.15);
fillLight.position.set(-5, 4, 2);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffc98c, 1.4);
rimLight.position.set(1, 5, -6);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Solid-color materials
// -------------------------------------------------------------------------
const material = (color, roughness = 0.72, metalness = 0.02) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const frameMaterial = material(0x315866, 0.72, 0.08);
const frameEdgeMaterial = material(0x3e6a78, 0.68, 0.08);
const footMaterial = material(0x26363b, 0.82);
const coverMaterial = material(0xe87542, 0.57, 0.02);
const coverStripeMaterial = material(0xc95a2e, 0.62);
const undersideMaterial = material(0xf0dfc0, 0.86);
const wallMaterial = material(0x956d4d, 0.82);
const dividerMaterial = material(0x684c3a, 0.88);
const padMaterials = [
material(0xb98b61, 0.9),
material(0xc5966d, 0.9),
material(0xaa7d58, 0.9)
];
const hingeMaterial = material(0xdf3f46, 0.32, 0.48);
const brassMaterial = material(0xd5a950, 0.34, 0.55);
const handleMaterial = material(0x34464c, 0.48, 0.25);
const stageMaterial = material(0xddd6c8, 0.95);
const floorMaterial = material(0xe9e5dc, 0.98);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function box(parent, size, position, mat) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), mat);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radius, height, position, mat, segments = 28) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
mat
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Ground and display plinth
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.09;
floor.receiveShadow = true;
scene.add(floor);
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(6.25, 6.25, 0.08, 96),
stageMaterial
);
plinth.position.y = -0.04;
plinth.receiveShadow = true;
scene.add(plinth);
const plinthRing = new THREE.Mesh(
new THREE.TorusGeometry(6.17, 0.018, 8, 128),
material(0xc7bfb0, 0.9)
);
plinthRing.rotation.x = Math.PI / 2;
plinthRing.position.y = 0.006;
scene.add(plinthRing);
// -------------------------------------------------------------------------
// Supporting frame: intentionally separate from the movable lid
// -------------------------------------------------------------------------
const frame = new THREE.Group();
frame.name = "Supporting frame";
scene.add(frame);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(
frame,
[0.34, 1.14, 0.34],
[sx * 2.17, 0.64, sz * 0.70],
frameMaterial
);
box(
frame,
[0.40, 0.14, 0.40],
[sx * 2.17, 0.07, sz * 0.70],
footMaterial
);
}
}
// Upper perimeter rails.
for (const sz of [-1, 1]) {
box(
frame,
[4.70, 0.22, 0.18],
[0, 1.27, sz * 0.84],
frameEdgeMaterial
);
}
for (const sx of [-1, 1]) {
box(
frame,
[0.18, 0.22, 1.68],
[sx * 2.35, 1.27, 0],
frameEdgeMaterial
);
}
// Lower stretchers.
for (const sz of [-1, 1]) {
box(
frame,
[4.34, 0.18, 0.18],
[0, 0.36, sz * 0.70],
frameMaterial
);
}
for (const sx of [-1, 1]) {
box(
frame,
[0.18, 0.18, 1.40],
[sx * 2.17, 0.36, 0],
frameMaterial
);
}
// -------------------------------------------------------------------------
// Storage tub and three visible interior bays
// -------------------------------------------------------------------------
const storage = new THREE.Group();
storage.name = "Interior compartments";
scene.add(storage);
box(storage, [4.66, 0.14, 1.58], [0, 1.33, 0], wallMaterial);
for (const sx of [-1, 1]) {
box(
storage,
[0.14, 0.32, 1.58],
[sx * 2.27, 1.55, 0],
wallMaterial
);
}
for (const sz of [-1, 1]) {
box(
storage,
[4.42, 0.32, 0.14],
[0, 1.55, sz * 0.74],
wallMaterial
);
}
// Two dividers create three distinct compartments.
for (const x of [-0.74, 0.74]) {
box(
storage,
[0.11, 0.30, 1.44],
[x, 1.55, 0],
dividerMaterial
);
}
// Colored floor inserts make each bay easy to read.
box(storage, [1.36, 0.025, 1.40], [-1.49, 1.415, 0], padMaterials[0]);
box(storage, [1.36, 0.025, 1.40], [0, 1.415, 0], padMaterials[1]);
box(storage, [1.36, 0.025, 1.40], [1.49, 1.415, 0], padMaterials[2]);
// -------------------------------------------------------------------------
// Movable cover, pivoted around the rear X-axis
// -------------------------------------------------------------------------
const hingeY = 1.88;
const hingeZ = -0.94;
const lid = new THREE.Group();
lid.name = "Movable cover";
lid.position.set(0, hingeY, hingeZ);
scene.add(lid);
// Main cover slab.
box(lid, [5.15, 0.18, 1.94], [0, 0, 0.97], coverMaterial);
// Visible underside panel.
box(lid, [4.72, 0.035, 1.53], [0, -0.10, 1.00], undersideMaterial);
// Shallow underside braces.
box(lid, [4.48, 0.025, 0.09], [0, -0.135, 0.48], frameMaterial);
box(lid, [4.48, 0.025, 0.09], [0, -0.135, 1.52], frameMaterial);
box(lid, [0.10, 0.025, 1.10], [0, -0.135, 1.00], frameMaterial);
// Exterior battens.
for (const z of [0.44, 0.97, 1.50]) {
box(lid, [4.58, 0.025, 0.10], [0, 0.102, z], coverStripeMaterial);
}
// Front handle.
box(lid, [0.15, 0.15, 0.18], [-0.55, 0.01, 1.94], handleMaterial);
box(lid, [0.15, 0.15, 0.18], [0.55, 0.01, 1.94], handleMaterial);
box(lid, [1.25, 0.13, 0.14], [0, 0.01, 1.99], handleMaterial);
// -------------------------------------------------------------------------
// Highlighted hinge axis: bright axle, brass sleeves, and outward arrows
// -------------------------------------------------------------------------
const axle = cylinder(
scene,
0.055,
5.76,
[0, hingeY, hingeZ],
hingeMaterial,
32
);
axle.rotation.z = Math.PI / 2;
for (const x of [-1.78, 0, 1.78]) {
box(
scene,
[0.30, 0.18, 0.25],
[x, 1.72, hingeZ + 0.03],
frameMaterial
);
const sleeve = cylinder(
scene,
0.095,
0.36,
[x, hingeY, hingeZ],
brassMaterial,
28
);
sleeve.rotation.z = Math.PI / 2;
}
const leftArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.14, 0.30, 24),
hingeMaterial
);
leftArrow.position.set(-2.94, hingeY, hingeZ);
leftArrow.rotation.z = Math.PI / 2;
leftArrow.castShadow = true;
scene.add(leftArrow);
const rightArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.14, 0.30, 24),
hingeMaterial
);
rightArrow.position.set(2.94, hingeY, hingeZ);
rightArrow.rotation.z = -Math.PI / 2;
rightArrow.castShadow = true;
scene.add(rightArrow);
// -------------------------------------------------------------------------
// Lid state and animation
// -------------------------------------------------------------------------
const OPEN_ANGLE = THREE.MathUtils.degToRad(-106);
let lidAngle = OPEN_ANGLE;
let lidTarget = OPEN_ANGLE;
const lidButton = document.getElementById("lidButton");
lidButton.addEventListener("click", () => {
lidTarget = lidTarget < -0.01 ? 0 : OPEN_ANGLE;
lidButton.textContent = lidTarget < -0.01 ? "Lower lid" : "Raise lid";
});
// -------------------------------------------------------------------------
// Camera controls implemented directly, without external control addons
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
const pointers = new Map();
let pinchDistance = 0;
function currentPinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) pinchDistance = currentPinchDistance();
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(polar - dy * 0.005, 0.34, 1.45);
} else if (pointers.size === 2) {
const distance = currentPinchDistance();
if (pinchDistance > 0 && distance > 0) {
radius = THREE.MathUtils.clamp(
radius * (pinchDistance / distance),
5.5,
14
);
}
pinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
pinchDistance = pointers.size === 2 ? currentPinchDistance() : 0;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
5.5,
14
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
azimuth = 0.68;
polar = 1.12;
radius = 9.2;
target.set(0, 1.48, 0);
});
document.getElementById("resetButton").addEventListener("click", () => {
azimuth = 0.68;
polar = 1.12;
radius = 9.2;
target.set(0, 1.48, 0);
});
// -------------------------------------------------------------------------
// Screen-space labels attached to important model points
// -------------------------------------------------------------------------
const tags = {
hinge: {
element: document.getElementById("hingeTag"),
point: new THREE.Vector3(3.04, hingeY, hingeZ),
offset: [38, -34]
},
cover: {
element: document.getElementById("coverTag"),
point: new THREE.Vector3(-1.65, -0.14, 1.18),
offset: [-8, -34],
localToLid: true
},
frame: {
element: document.getElementById("frameTag"),
point: new THREE.Vector3(2.17, 0.66, 0.70),
offset: [58, 16]
},
bays: {
element: document.getElementById("baysTag"),
point: new THREE.Vector3(0, 1.56, 0.04),
offset: [-44, 46]
}
};
const projected = new THREE.Vector3();
function updateTags() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const tag of Object.values(tags)) {
if (tag.localToLid) {
lid.updateMatrixWorld(true);
projected.copy(tag.point);
lid.localToWorld(projected);
} else {
projected.copy(tag.point);
}
projected.project(camera);
const x = (projected.x * 0.5 + 0.5) * width + tag.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + tag.offset[1];
const visible = projected.z > -1 && projected.z < 1 &&
x > -80 && x < width + 80 && y > -50 && y < height + 50;
tag.element.style.left = `${x}px`;
tag.element.style.top = `${y}px`;
tag.element.style.opacity = visible ? "1" : "0";
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
// Smoothly move the cover while preserving its hinge pivot.
lidAngle += (lidTarget - lidAngle) * (1 - Math.exp(-5.5 * delta));
lid.rotation.x = lidAngle;
updateCamera();
updateTags();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 300);
</script>
</body>
</html>
```