Prompt specification
Build or customize the Three.js 3D scene "Adjustable drawer divider" 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: Adjustable drawer divider
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/adjustable-drawer-divider-x0017
Scene Description Prompt:
Show two stylized telescoping drawer dividers, one extended and one compressed, with overlapping bars and padded ends. Three.js from cdnjs in one HTML file.
Working Three.js Starter (adjustable-drawer-divider-x0017):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Telescoping Drawer Dividers</title>
<style>
:root {
--ink: #17343b;
--muted: #607479;
--accent: #ed7256;
--panel: rgba(248, 250, 247, 0.82);
--line: rgba(23, 52, 59, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 20% 10%, #f7f5ec 0, transparent 38%),
radial-gradient(circle at 85% 20%, #dce9e7 0, transparent 42%),
#e6ece8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-panel {
position: fixed;
z-index: 5;
top: 26px;
left: 28px;
max-width: 390px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 30px;
height: 2px;
content: "";
background: var(--accent);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 52px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 340px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.toolbar {
position: fixed;
z-index: 6;
top: 24px;
right: 24px;
display: flex;
gap: 8px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 999px;
padding: 10px 15px;
background: var(--panel);
color: var(--ink);
box-shadow: 0 8px 28px rgba(35, 59, 62, 0.08);
backdrop-filter: blur(12px);
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 750;
transition:
transform 160ms ease,
background 160ms ease;
}
button:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.94);
}
button:active {
transform: translateY(0);
}
.object-label {
position: fixed;
z-index: 4;
min-width: 148px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 13px;
background: rgba(249, 251, 248, 0.8);
box-shadow: 0 10px 30px rgba(35, 59, 62, 0.11);
backdrop-filter: blur(10px);
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 100ms linear;
}
.object-label strong {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.object-label strong::before {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--accent);
content: "";
}
.object-label span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
}
#compressed-label strong::before {
background: #5a8589;
}
.hint {
position: fixed;
z-index: 5;
bottom: 22px;
left: 50%;
padding: 9px 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(248, 250, 247, 0.7);
color: var(--muted);
font-size: 11px;
letter-spacing: 0.03em;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(10px);
white-space: nowrap;
}
.loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #e6ece8;
color: var(--muted);
font-size: 13px;
letter-spacing: 0.08em;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.title-panel {
top: 18px;
left: 18px;
max-width: 250px;
}
.subtitle {
display: none;
}
.toolbar {
top: 16px;
right: 16px;
flex-direction: column;
}
button {
padding: 9px 12px;
}
.hint {
bottom: 14px;
font-size: 10px;
}
.object-label {
min-width: 125px;
padding: 8px 10px;
}
}
</style>
</head>
<body>
<div class="loading" id="loading">Loading 3D scene…</div>
<header class="title-panel">
<div class="eyebrow">Drawer organization system</div>
<h1>Telescoping<br />dividers</h1>
<p class="subtitle">
Two articulated rail assemblies shown at full extension and compressed travel.
Overlapping profiles and soft protective end pads keep the dividers protected.
</p>
</header>
<div class="toolbar">
<button id="demo" type="button">Play telescope</button>
<button id="reset" type="button">Reset view</button>
</div>
<div class="object-label" id="extended-label">
<strong>Extended</strong>
<span>100% travel · open span</span>
</div>
<div class="object-label" id="compressed-label">
<strong>Compressed</strong>
<span>70% travel · nested span</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Right-drag to pan</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.getElementById("loading");
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
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", "Interactive 3D view of telescoping drawer dividers");
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe6ece8, 17, 38);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x879991, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff8eb, 4.2);
keyLight.position.set(-4, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00025;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xcde7ea, 1.8);
fillLight.position.set(8, 4, -5);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xdfe6e0,
roughness: 0.96,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(32, 32, 0xaebdb6, 0xcbd5ce);
grid.position.y = -0.018;
grid.material.transparent = true;
grid.material.opacity = 0.24;
grid.material.depthWrite = false;
scene.add(grid);
// -------------------------------------------------------------------------
// Rounded geometry made with core Three.js ExtrudeGeometry
// -------------------------------------------------------------------------
const geometryCache = new Map();
function roundedBoxGeometry(width, height, depth, radius = 0.08, bevel = 0.02) {
const key = [width, height, depth, radius, bevel]
.map((value) => value.toFixed(4))
.join("|");
if (geometryCache.has(key)) {
return geometryCache.get(key);
}
const r = Math.min(radius, width * 0.48, height * 0.48);
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + height - r);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
shape.lineTo(x + r, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: Math.max(0.002, depth - bevel * 2),
bevelEnabled: true,
bevelThickness: bevel,
bevelSize: bevel,
bevelSegments: 3,
curveSegments: 8
});
geometry.center();
geometry.computeVertexNormals();
geometryCache.set(key, geometry);
return geometry;
}
function roundedMesh(
width,
height,
depth,
radius,
bevel,
material
) {
const mesh = new THREE.Mesh(
roundedBoxGeometry(width, height, depth, radius, bevel),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const materials = {
outer: new THREE.MeshStandardMaterial({
color: 0x183a45,
metalness: 0.48,
roughness: 0.3
}),
middle: new THREE.MeshStandardMaterial({
color: 0xaebfc0,
metalness: 0.68,
roughness: 0.28
}),
inner: new THREE.MeshStandardMaterial({
color: 0xe8e0cd,
metalness: 0.16,
roughness: 0.42
}),
outerInset: new THREE.MeshStandardMaterial({
color: 0x759397,
metalness: 0.55,
roughness: 0.32
}),
middleInset: new THREE.MeshStandardMaterial({
color: 0x31535a,
metalness: 0.48,
roughness: 0.38
}),
innerInset: new THREE.MeshStandardMaterial({
color: 0xd86f55,
metalness: 0.2,
roughness: 0.5
}),
collar: new THREE.MeshStandardMaterial({
color: 0xd0a66e,
metalness: 0.7,
roughness: 0.3
}),
pad: new THREE.MeshStandardMaterial({
color: 0xed7256,
metalness: 0,
roughness: 0.9
}),
padRib: new THREE.MeshStandardMaterial({
color: 0xb84e3a,
metalness: 0,
roughness: 0.95
}),
screw: new THREE.MeshStandardMaterial({
color: 0x334b50,
metalness: 0.8,
roughness: 0.25
})
};
function addScrew(parent, x, z = 0) {
const screw = new THREE.Mesh(
new THREE.CylinderGeometry(0.047, 0.047, 0.022, 18),
materials.screw
);
screw.position.set(x, 0.192, z);
screw.castShadow = true;
parent.add(screw);
}
function addSoftPad(parent, x) {
const pad = roundedMesh(
0.36,
0.52,
0.72,
0.16,
0.045,
materials.pad
);
pad.position.set(x, 0.055, 0);
parent.add(pad);
for (let i = -1; i <= 1; i++) {
const rib = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 0.017, 0.47),
materials.padRib
);
rib.position.set(x + i * 0.075, 0.319, 0);
rib.castShadow = true;
parent.add(rib);
}
}
function createRail(stageIndex, length) {
const group = new THREE.Group();
const bodyMaterial = [
materials.outer,
materials.middle,
materials.inner
][stageIndex];
const insetMaterial = [
materials.outerInset,
materials.middleInset,
materials.innerInset
][stageIndex];
const body = roundedMesh(
length,
0.34,
0.62,
0.115,
0.025,
bodyMaterial
);
group.add(body);
// Recessed top channel.
const topInset = roundedMesh(
length * 0.76,
0.027,
0.24,
0.012,
0.006,
insetMaterial
);
topInset.position.set(0, 0.183, 0);
group.add(topInset);
// Front-face accent groove.
const frontInset = roundedMesh(
length * 0.7,
0.045,
0.018,
0.008,
0.005,
insetMaterial
);
frontInset.position.set(0, 0.015, 0.315);
group.add(frontInset);
// End collars visually reinforce the telescoping construction.
for (const direction of [-1, 1]) {
const collar = roundedMesh(
0.095,
0.41,
0.67,
0.035,
0.012,
materials.collar
);
collar.position.set(direction * (length / 2 - 0.075), 0, 0);
group.add(collar);
}
addScrew(group, -length * 0.34);
addScrew(group, length * 0.34);
if (stageIndex === 2) {
// Small sliding control on the innermost profile.
const control = roundedMesh(
0.52,
0.085,
0.34,
0.04,
0.012,
materials.pad
);
control.position.set(length * 0.23, 0.225, 0);
group.add(control);
addSoftPad(group, length / 2 - 0.055);
}
if (stageIndex === 0) {
addSoftPad(group, -length / 2 + 0.055);
}
return group;
}
function createDivider() {
const divider = new THREE.Group();
const lengths = [4.5, 3.85, 3.15];
const compressedX = [0.05, 0.36, 0.67];
const extendedX = [-0.35, 1.0, 2.35];
const stageZ = [-0.18, 0, 0.18];
const stageY = [0.29, 0.34, 0.39];
const stages = lengths.map((length, index) => {
const rail = createRail(index, length);
rail.position.set(compressedX[index], stageY[index], stageZ[index]);
rail.userData.length = length;
rail.userData.compressedX = compressedX[index];
rail.userData.extendedX = extendedX[index];
divider.add(rail);
return rail;
});
const labelAnchor = new THREE.Object3D();
labelAnchor.position.y = 1.05;
divider.add(labelAnchor);
return {
group: divider,
stages,
labelAnchor
};
}
function setDividerProgress(divider, progress) {
let minX = Infinity;
let maxX = -Infinity;
divider.stages.forEach((stage) => {
stage.position.x = THREE.MathUtils.lerp(
stage.userData.compressedX,
stage.userData.extendedX,
progress
);
minX = Math.min(minX, stage.position.x - stage.userData.length / 2);
maxX = Math.max(maxX, stage.position.x + stage.userData.length / 2);
});
divider.labelAnchor.position.x = (minX + maxX) * 0.5;
}
const extendedDivider = createDivider();
extendedDivider.group.position.set(-3.25, 0, 0.42);
extendedDivider.group.rotation.y = -0.1;
scene.add(extendedDivider.group);
const compressedDivider = createDivider();
compressedDivider.group.position.set(3.25, 0, -0.43);
compressedDivider.group.rotation.y = 0.12;
scene.add(compressedDivider.group);
// -------------------------------------------------------------------------
// DOM labels projected from world-space anchors
// -------------------------------------------------------------------------
const extendedLabel = document.getElementById("extended-label");
const compressedLabel = document.getElementById("compressed-label");
const projected = new THREE.Vector3();
function positionLabel(element, anchor) {
anchor.getWorldPosition(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = visible ? "1" : "0";
}
// -------------------------------------------------------------------------
// Custom camera controls: orbit, zoom, pan, keyboard, and touch gestures
// -------------------------------------------------------------------------
const desired = {
theta: 0.32,
phi: 0.98,
radius: 13,
target: new THREE.Vector3(0, 0.15, 0)
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius,
target: desired.target.clone()
};
const pointerMap = new Map();
let singlePointer = null;
let previousGesture = null;
function fittedRadius() {
const verticalFov = THREE.MathUtils.degToRad(camera.fov);
const horizontalFov = 2 * Math.atan(
Math.tan(verticalFov / 2) * camera.aspect
);
return Math.max(
13,
12.7 / (2 * Math.tan(horizontalFov / 2))
);
}
function clampView() {
desired.phi = THREE.MathUtils.clamp(desired.phi, 0.28, 1.46);
desired.radius = THREE.MathUtils.clamp(desired.radius, 6.5, 38);
}
function panCamera(dx, dy) {
const scale =
(2 * current.radius * Math.tan(THREE.MathUtils.degToRad(camera.fov / 2))) /
window.innerHeight;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
desired.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
}
function gestureData() {
const points = [...pointerMap.values()];
if (points.length < 2) return null;
const dx = points[1].x - points[0].x;
const dy = points[1].y - points[0].y;
return {
distance: Math.hypot(dx, dy),
midX: (points[0].x + points[1].x) * 0.5,
midY: (points[0].y + points[1].y) * 0.5
};
}
renderer.domElement.addEventListener("pointerdown", (event) => {
event.preventDefault();
renderer.domElement.setPointerCapture(event.pointerId);
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerMap.size === 1) {
singlePointer = {
id: event.pointerId,
x: event.clientX,
y: event.clientY
};
} else if (pointerMap.size === 2) {
previousGesture = gestureData();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerMap.has(event.pointerId)) return;
const pointer = pointerMap.get(event.pointerId);
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointerMap.size === 1 && singlePointer) {
const dx = event.clientX - singlePointer.x;
const dy = event.clientY - singlePointer.y;
if (event.button === 2 || event.shiftKey) {
panCamera(dx, dy);
} else {
desired.theta -= dx * 0.006;
desired.phi -= dy * 0.006;
}
singlePointer.x = event.clientX;
singlePointer.y = event.clientY;
clampView();
} else if (pointerMap.size >= 2) {
const gesture = gestureData();
if (gesture && previousGesture) {
desired.radius *=
previousGesture.distance / Math.max(gesture.distance, 1);
panCamera(
gesture.midX - previousGesture.midX,
gesture.midY - previousGesture.midY
);
}
previousGesture = gesture;
clampView();
}
});
function releasePointer(event) {
pointerMap.delete(event.pointerId);
if (pointerMap.size === 1) {
const remaining = [...pointerMap.entries()][0];
singlePointer = {
id: remaining[0],
x: remaining[1].x,
y: remaining[1].y
};
} else {
singlePointer = null;
}
previousGesture = pointerMap.size >= 2 ? gestureData() : null;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius *= Math.exp(event.deltaY * 0.001);
clampView();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
window.addEventListener("keydown", (event) => {
const step = 0.09;
if (event.key === "ArrowLeft") desired.theta += step;
if (event.key === "ArrowRight") desired.theta -= step;
if (event.key === "ArrowUp") desired.phi -= step;
if (event.key === "ArrowDown") desired.phi += step;
if (event.key === "+" || event.key === "=") desired.radius -= 0.6;
if (event.key === "-" || event.key === "_") desired.radius += 0.6;
clampView();
});
document.getElementById("reset").addEventListener("click", () => {
desired.theta = 0.32;
desired.phi = 0.98;
desired.radius = fittedRadius();
desired.target.set(0, 0.15, 0);
});
// -------------------------------------------------------------------------
// Telescoping demonstration
// -------------------------------------------------------------------------
const demoButton = document.getElementById("demo");
let demoActive = false;
let demoStart = 0;
let motion = 0;
function easeInOut(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
demoButton.addEventListener("click", () => {
if (demoActive) return;
demoActive = true;
demoStart = performance.now();
demoButton.textContent = "Resetting…";
});
// -------------------------------------------------------------------------
// 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);
desired.radius = fittedRadius();
clampView();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
const cameraSpherical = new THREE.Spherical();
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (demoActive) {
const elapsed = (now - demoStart) / 1000;
if (elapsed < 2.4) {
motion = easeInOut(elapsed / 2.4);
} else if (elapsed < 3.1) {
motion = 1;
} else if (elapsed < 5.5) {
motion = 1 - easeInOut((elapsed - 3.1) / 2.4);
} else {
motion = 0;
demoActive = false;
demoButton.textContent = "Play telescope";
}
}
setDividerProgress(extendedDivider, 1 - motion);
setDividerProgress(compressedDivider, motion);
extendedLabel.querySelector("span").textContent =
`${Math.round(100 - motion * 30)}% travel · open span`;
compressedLabel.querySelector("span").textContent =
`${Math.round(70 + motion * 30)}% travel · nested span`;
const damping = 1 - Math.exp(-dt * 10);
current.theta = THREE.MathUtils.lerp(
current.theta,
desired.theta,
damping
);
current.phi = THREE.MathUtils.lerp(
current.phi,
desired.phi,
damping
);
current.radius = THREE.MathUtils.lerp(
current.radius,
desired.radius,
damping
);
current.target.lerp(desired.target, damping);
cameraSpherical.set(
current.radius,
current.phi,
current.theta
);
camera.position.setFromSpherical(cameraSpherical).add(current.target);
camera.lookAt(current.target);
positionLabel(extendedLabel, extendedDivider.labelAnchor);
positionLabel(compressedLabel, compressedDivider.labelAnchor);
renderer.render(scene, camera);
}
setDividerProgress(extendedDivider, 1);
setDividerProgress(compressedDivider, 0);
requestAnimationFrame(animate);
loading.classList.add("hidden");
window.setTimeout(() => {
loading.style.display = "none";
}, 400);
</script>
</body>
</html>
```