Prompt specification
Build or customize the Three.js 3D scene "Mixed-height wall hook rail" 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: Mixed-height wall hook rail
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mixed-height-wall-hook-rail-x0005
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a coat-hook rail. Build a wooden rail with three curved hooks at distinct heights, a hanging cap, and a short scarf; keep attachment points visible from the camera. Stylized solid forms.
Working Three.js Starter (mixed-height-wall-hook-rail-x0005):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wooden Coat-Hook Rail</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e1d4;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
padding: 14px 17px;
border: 1px solid rgba(65, 43, 29, 0.13);
border-radius: 14px;
background: rgba(255, 252, 245, 0.78);
box-shadow: 0 10px 30px rgba(65, 43, 29, 0.09);
backdrop-filter: blur(10px);
pointer-events: none;
color: #39281e;
}
.title-card h1 {
margin: 0;
font-size: 14px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.title-card p {
margin: 5px 0 0;
font-size: 12px;
color: #806b5c;
}
.hint {
position: fixed;
right: 20px;
bottom: 18px;
padding: 8px 11px;
border-radius: 999px;
background: rgba(57, 40, 30, 0.72);
color: #fff8eb;
font-size: 11px;
letter-spacing: 0.025em;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 600px) {
.title-card {
top: 14px;
left: 14px;
}
.hint {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div class="title-card">
<h1>Coat-Hook Rail</h1>
<p>Walnut rail · curved brass hooks</p>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e1d4);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
40
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute(
"aria-label",
"A stylized wooden coat-hook rail with three curved hooks, a hanging cap, and a short scarf."
);
document.body.prepend(renderer.domElement);
// ------------------------------------------------------------------
// Materials
// ------------------------------------------------------------------
const materials = {
wall: new THREE.MeshStandardMaterial({
color: 0xe8e1d4,
roughness: 0.96
}),
floor: new THREE.MeshStandardMaterial({
color: 0xd8cdbd,
roughness: 0.94
}),
wood: new THREE.MeshStandardMaterial({
color: 0xa96636,
roughness: 0.72,
metalness: 0.02
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x754126,
roughness: 0.78
}),
grain: new THREE.MeshStandardMaterial({
color: 0x80502d,
roughness: 0.85
}),
brass: new THREE.MeshStandardMaterial({
color: 0xc49443,
roughness: 0.27,
metalness: 0.72
}),
brassDark: new THREE.MeshStandardMaterial({
color: 0x765323,
roughness: 0.42,
metalness: 0.58
}),
cap: new THREE.MeshStandardMaterial({
color: 0x286b70,
roughness: 0.82
}),
capDark: new THREE.MeshStandardMaterial({
color: 0x1c5054,
roughness: 0.86
}),
scarf: new THREE.MeshStandardMaterial({
color: 0xc85f42,
roughness: 0.93
}),
fringe: new THREE.MeshStandardMaterial({
color: 0xf1cb89,
roughness: 0.9
})
};
function addMesh(geometry, material, position = null) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// ------------------------------------------------------------------
// Room
// ------------------------------------------------------------------
const wall = addMesh(
new THREE.PlaneGeometry(14, 9),
materials.wall,
new THREE.Vector3(0, 1.1, -0.34)
);
wall.castShadow = false;
const floor = addMesh(
new THREE.PlaneGeometry(14, 12),
materials.floor,
new THREE.Vector3(0, -1.75, 3)
);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
// ------------------------------------------------------------------
// Rounded wooden rail
// ------------------------------------------------------------------
function roundedRectangleShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
const railDepth = 0.24;
const railGeometry = new THREE.ExtrudeGeometry(
roundedRectangleShape(3.7, 0.34, 0.085),
{
depth: railDepth,
bevelEnabled: true,
bevelSegments: 3,
steps: 1,
bevelSize: 0.035,
bevelThickness: 0.035,
curveSegments: 10
}
);
railGeometry.translate(0, 0, -railDepth / 2);
const rail = addMesh(
railGeometry,
materials.wood,
new THREE.Vector3(0, 1.28, 0.02)
);
// Subtle solid grain lines on the front of the rail.
const grainOffsets = [-0.09, -0.035, 0.035, 0.09];
grainOffsets.forEach((offset, index) => {
const points = [];
for (let i = 0; i <= 12; i++) {
const x = -1.68 + (3.36 * i) / 12;
const wave = Math.sin(i * 1.35 + index * 1.7) * 0.012;
points.push(new THREE.Vector3(x, 1.28 + offset + wave, 0.173));
}
const curve = new THREE.CatmullRomCurve3(points);
const grain = addMesh(
new THREE.TubeGeometry(curve, 48, 0.008, 5, false),
materials.grain
);
grain.castShadow = false;
});
// Two short spacers behind the rail.
[-1.48, 1.48].forEach((x) => {
const spacer = addMesh(
new THREE.CylinderGeometry(0.085, 0.085, 0.19, 20),
materials.darkWood,
new THREE.Vector3(x, 1.28, -0.245)
);
spacer.rotation.x = Math.PI / 2;
});
// ------------------------------------------------------------------
// Three hooks at different heights
// ------------------------------------------------------------------
const hookData = [
{ x: -1.08, drop: 0.56 },
{ x: 0.0, drop: 1.0 },
{ x: 1.08, drop: 1.42 }
];
const hookTips = [];
hookData.forEach(({ x, drop }) => {
const mountY = 1.2;
// Visible circular mounting plate.
const plate = addMesh(
new THREE.CylinderGeometry(0.115, 0.115, 0.045, 28),
materials.brass,
new THREE.Vector3(x, mountY, 0.177)
);
plate.rotation.x = Math.PI / 2;
const screw = addMesh(
new THREE.CylinderGeometry(0.027, 0.027, 0.052, 18),
materials.brassDark,
new THREE.Vector3(x, mountY, 0.211)
);
screw.rotation.x = Math.PI / 2;
const hookPoints = [
new THREE.Vector3(x, mountY, 0.205),
new THREE.Vector3(x, mountY - 0.035, 0.405),
new THREE.Vector3(x, mountY - drop * 0.22, 0.61),
new THREE.Vector3(x, mountY - drop * 0.72, 0.60),
new THREE.Vector3(x, mountY - drop, 0.46),
new THREE.Vector3(x, mountY - drop + 0.13, 0.29)
];
const hookCurve = new THREE.CatmullRomCurve3(
hookPoints,
false,
"catmullrom",
0.35
);
addMesh(
new THREE.TubeGeometry(hookCurve, 72, 0.052, 12, false),
materials.brass
);
// A small rounded cap emphasizes the upward-facing tip.
const tip = hookPoints[hookPoints.length - 1];
const tipBall = addMesh(
new THREE.SphereGeometry(0.055, 16, 12),
materials.brass,
tip
);
tipBall.scale.set(1, 0.85, 1);
hookTips.push(tip.clone());
});
// ------------------------------------------------------------------
// Hanging cap
// ------------------------------------------------------------------
const capGroup = new THREE.Group();
capGroup.position.set(-1.08, -0.20, 0.59);
scene.add(capGroup);
const crown = new THREE.Mesh(
new THREE.SphereGeometry(
0.43,
36,
20,
0,
Math.PI * 2,
0,
Math.PI * 0.53
),
materials.cap
);
crown.scale.set(1.06, 0.76, 0.92);
crown.castShadow = true;
crown.receiveShadow = true;
capGroup.add(crown);
const capBand = new THREE.Mesh(
new THREE.CylinderGeometry(0.435, 0.435, 0.085, 36, 1, true),
materials.capDark
);
capBand.scale.set(1.055, 1, 0.92);
capBand.position.y = -0.015;
capBand.castShadow = true;
capGroup.add(capBand);
// Solid, extruded visor.
const visorShape = new THREE.Shape();
visorShape.moveTo(-0.43, 0);
visorShape.bezierCurveTo(-0.18, 0.5, 0.18, 0.5, 0.43, 0);
visorShape.lineTo(-0.43, 0);
const visorGeometry = new THREE.ExtrudeGeometry(visorShape, {
depth: 0.055,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.018,
bevelThickness: 0.015,
curveSegments: 24
});
visorGeometry.rotateX(Math.PI / 2);
const visor = new THREE.Mesh(visorGeometry, materials.capDark);
visor.position.set(0, -0.045, -0.08);
visor.castShadow = true;
visor.receiveShadow = true;
capGroup.add(visor);
const button = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 18, 12),
materials.capDark
);
button.position.set(0, 0.342, 0);
button.castShadow = true;
capGroup.add(button);
// A subtle crown seam.
const seamCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 0.34, 0),
new THREE.Vector3(0.012, 0.23, 0.22),
new THREE.Vector3(0, 0.025, 0.385)
]);
const seam = new THREE.Mesh(
new THREE.TubeGeometry(seamCurve, 28, 0.009, 6, false),
materials.capDark
);
seam.castShadow = false;
capGroup.add(seam);
// Visible brass attachment ring and two cords.
const capTip = hookTips[0];
const capRing = addMesh(
new THREE.TorusGeometry(0.105, 0.024, 10, 32),
materials.brass,
new THREE.Vector3(capTip.x, capTip.y, capTip.z)
);
capRing.rotation.x = Math.PI / 2;
[-0.052, 0.052].forEach((offset) => {
const cordCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(capTip.x + offset * 0.65, capTip.y - 0.01, capTip.z),
new THREE.Vector3(capTip.x + offset, 0.47, 0.45),
new THREE.Vector3(capTip.x + offset * 0.55, 0.19, 0.56),
new THREE.Vector3(capTip.x + offset * 0.28, 0.15, 0.59)
]);
addMesh(
new THREE.TubeGeometry(cordCurve, 36, 0.017, 7, false),
materials.capDark
);
});
// ------------------------------------------------------------------
// Short, broad ribbon scarf
// ------------------------------------------------------------------
const scarfTip = hookTips[1];
const scarfRing = addMesh(
new THREE.TorusGeometry(0.11, 0.025, 10, 32),
materials.brass,
new THREE.Vector3(scarfTip.x, scarfTip.y, scarfTip.z)
);
scarfRing.rotation.x = Math.PI / 2;
const scarfPoints = [
new THREE.Vector3(0, 0.30, 0.34),
new THREE.Vector3(0, 0.08, 0.42),
new THREE.Vector3(0, -0.17, 0.55),
new THREE.Vector3(0, -0.42, 0.47),
new THREE.Vector3(0, -0.64, 0.59),
new THREE.Vector3(0, -0.84, 0.48),
new THREE.Vector3(0, -0.99, 0.41)
];
function createRibbonGeometry(points, width, thickness, segments = 72) {
const path = new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.35);
const radialSegments = 12;
const positions = [];
const indices = [];
const side = new THREE.Vector3(1, 0, 0);
const normal = new THREE.Vector3();
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const center = path.getPoint(t);
const tangent = path.getTangent(t).normalize();
normal.crossVectors(tangent, side).normalize();
for (let j = 0; j < radialSegments; j++) {
const angle = (j / radialSegments) * Math.PI * 2;
const vertex = center.clone()
.addScaledVector(side, Math.cos(angle) * width * 0.5)
.addScaledVector(normal, Math.sin(angle) * thickness * 0.5);
positions.push(vertex.x, vertex.y, vertex.z);
}
}
for (let i = 0; i < segments; i++) {
for (let j = 0; j < radialSegments; j++) {
const nextJ = (j + 1) % radialSegments;
const a = i * radialSegments + j;
const b = i * radialSegments + nextJ;
const c = (i + 1) * radialSegments + j;
const d = (i + 1) * radialSegments + nextJ;
indices.push(a, c, b);
indices.push(b, c, d);
}
}
const startCenter = positions.length / 3;
const endCenter = startCenter + 1;
const start = path.getPoint(0);
const end = path.getPoint(1);
positions.push(start.x, start.y, start.z);
positions.push(end.x, end.y, end.z);
for (let j = 0; j < radialSegments; j++) {
const nextJ = (j + 1) % radialSegments;
indices.push(startCenter, nextJ, j);
indices.push(
endCenter,
segments * radialSegments + j,
segments * radialSegments + nextJ
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const scarf = addMesh(
createRibbonGeometry(scarfPoints, 0.40, 0.075),
materials.scarf
);
// Light fringe at the lower end.
for (let i = 0; i < 6; i++) {
const x = -0.15 + i * 0.06;
const fringeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(x, -0.97, 0.42),
new THREE.Vector3(x + 0.006, -1.055, 0.425),
new THREE.Vector3(x - 0.005, -1.15 + Math.abs(i - 2.5) * 0.012, 0.43)
]);
addMesh(
new THREE.TubeGeometry(fringeCurve, 16, 0.011, 6, false),
materials.fringe
);
}
// ------------------------------------------------------------------
// Lighting
// ------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfff5df, 0x78675c, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d1, 4.0);
keyLight.position.set(4.5, 7, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -4;
keyLight.shadow.camera.right = 4;
keyLight.shadow.camera.top = 4;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d4df, 1.15);
fillLight.position.set(-5, 3, 4);
scene.add(fillLight);
const warmLight = new THREE.PointLight(0xffc985, 8, 10, 2);
warmLight.position.set(-2.2, 2.6, 3.8);
scene.add(warmLight);
// ------------------------------------------------------------------
// Direct camera controls: orbit, zoom, and reset
// ------------------------------------------------------------------
const target = new THREE.Vector3(0, 0.1, 0.18);
const initialCamera = {
theta: 0.34,
phi: 1.18,
radius: 7.4
};
let theta = initialCamera.theta;
let phi = initialCamera.phi;
let radius = initialCamera.radius;
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
theta = initialCamera.theta;
phi = initialCamera.phi;
radius = initialCamera.radius;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
theta = THREE.MathUtils.clamp(
theta - deltaX * 0.006,
-0.9,
0.9
);
phi = THREE.MathUtils.clamp(
phi + deltaY * 0.005,
0.72,
1.48
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined &&
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();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
5.1,
10.5
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateCamera();
renderer.render(scene, camera);
</script>
</body>
</html>
```