Prompt specification
Build or customize the Three.js 3D scene "Under-bed drawer travel study" 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: Under-bed drawer travel study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/under-bed-drawer-travel-study-x0165
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring under-bed drawers. Show a bed platform with one shallow drawer pulled outward over a marked clearance area; expose runners and keep its storage box separate from the fixed frame. Voxel style.
Working Three.js Starter (under-bed-drawer-travel-study-x0165):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Under-Bed Drawer Study</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101722;
color: #edf4fa;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
touch-action: none;
}
.hud {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
max-width: min(410px, calc(100vw - 44px));
pointer-events: none;
}
.eyebrow {
color: #f5c85b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 8px;
font-size: clamp(24px, 3vw, 38px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 0;
max-width: 370px;
color: #9dafbf;
font-size: 13px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 17px;
}
.chip {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid #334556;
border-radius: 6px;
background: rgba(16, 23, 34, 0.76);
color: #cbd8e2;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.swatch {
width: 8px;
height: 8px;
background: var(--color);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
}
.controls {
position: fixed;
z-index: 20;
right: 22px;
bottom: 22px;
width: min(300px, calc(100vw - 44px));
padding: 15px;
border: 1px solid #344758;
border-radius: 10px;
background: rgba(16, 23, 34, 0.88);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(12px);
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.control-label {
color: #9dafbf;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.travel {
color: #f5c85b;
font: 700 12px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.buttons {
display: flex;
gap: 8px;
}
button {
flex: 1;
min-height: 38px;
border: 1px solid #3d5266;
border-radius: 6px;
background: #202f3e;
color: #edf4fa;
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}
button:hover {
background: #2a3c4e;
border-color: #668096;
}
button:active {
transform: translateY(1px);
}
button.primary {
border-color: #f5c85b;
background: #f5c85b;
color: #17202b;
}
button.primary:hover {
background: #ffda73;
}
.hint {
margin-top: 11px;
color: #718698;
font-size: 10px;
line-height: 1.4;
}
@media (max-width: 650px) {
.hud {
top: 16px;
left: 16px;
}
.subtitle,
.legend {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
width: calc(100vw - 28px);
}
}
</style>
</head>
<body>
<section class="hud">
<div class="eyebrow">Assembly study / 04</div>
<h1>Under-bed<br>mobile storage</h1>
<p class="subtitle">
A shallow drawer travels beyond the platform on exposed telescopic runners.
Its storage box remains a separate assembly from the fixed frame.
</p>
<div class="legend" aria-label="Scene legend">
<div class="chip">
<span class="swatch" style="--color:#6b4431"></span>
Fixed frame
</div>
<div class="chip">
<span class="swatch" style="--color:#c47a49"></span>
Storage box
</div>
<div class="chip">
<span class="swatch" style="--color:#dce8ee"></span>
Runners
</div>
<div class="chip">
<span class="swatch" style="--color:#f5c85b"></span>
Clearance
</div>
</div>
</section>
<aside class="controls">
<div class="control-row">
<span class="control-label">Drawer travel</span>
<span class="travel" id="travelValue">100%</span>
</div>
<div class="buttons">
<button class="primary" id="drawerButton" type="button">Close drawer</button>
<button id="resetButton" type="button">Reset view</button>
</div>
<div class="hint">
Drag to orbit · Scroll to zoom · D toggles drawer · R resets view
</div>
</aside>
<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 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.15;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101722);
scene.fog = new THREE.Fog(0x101722, 14, 31);
const camera = new THREE.OrthographicCamera(-7, 7, 4, -4, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.15, 1.05);
const clock = new THREE.Clock();
const hemisphere = new THREE.HemisphereLight(0xd9efff, 0x28303a, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d1, 3.25);
keyLight.position.set(5.5, 9, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0002;
keyLight.target.position.set(0, 1, 1);
scene.add(keyLight, keyLight.target);
const fillLight = new THREE.DirectionalLight(0x89b9ff, 1.05);
fillLight.position.set(-6, 4, 1);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffc56b, 0.8);
rimLight.position.set(0, 5, -7);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Shared voxel geometry and materials
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
floor: material(0x182331),
frame: material(0x65412f),
frameEdge: material(0x7b5038),
frameDark: material(0x3e2a22),
drawer: material(0xb86c40),
drawerFront: material(0xc77b4c),
drawerInside: material(0x74442d),
metal: material(0x718391, {
metalness: 0.72,
roughness: 0.38
}),
runner: material(0xdce8ee, {
metalness: 0.82,
roughness: 0.24
}),
slider: material(0xf5a84a, {
metalness: 0.35,
roughness: 0.4
}),
handle: material(0x26313b, {
metalness: 0.65,
roughness: 0.34
}),
mattress: material(0xe7dfcf),
sheet: material(0xf3eee3),
duvet: material(0x497f83),
duvetAlt: material(0x558c8e),
pillow: material(0xf5f0e7),
blanket: material(0xd9a65b),
blanketAlt: material(0xe6bd78),
toy: material(0xe77c52),
book: material(0x728fc4)
};
function addBox(parent, size, position, mat, castShadow = true, receiveShadow = true) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Floor and floor grid
// -------------------------------------------------------------------------
addBox(
scene,
[24, 0.12, 24],
[0, -0.075, 0],
materials.floor,
false,
true
);
const grid = new THREE.GridHelper(24, 24, 0x486072, 0x2b3b4b);
grid.position.y = -0.008;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
// -------------------------------------------------------------------------
// Fixed bed frame: deliberately separate from all drawer storage groups
// -------------------------------------------------------------------------
const fixedBedFrame = new THREE.Group();
fixedBedFrame.name = "FIXED_BED_FRAME";
fixedBedFrame.userData.role = "Fixed platform and structural frame";
scene.add(fixedBedFrame);
// Main platform deck.
addBox(
fixedBedFrame,
[5.9, 0.3, 3.55],
[0, 1.62, 0],
materials.frame
);
addBox(
fixedBedFrame,
[5.92, 0.09, 3.58],
[0, 1.79, 0],
materials.frameEdge
);
// Side beams.
for (const x of [-2.78, 2.78]) {
addBox(
fixedBedFrame,
[0.22, 0.4, 3.42],
[x, 1.39, 0],
materials.frameDark
);
}
// Front beam stays above the drawer openings.
addBox(
fixedBedFrame,
[5.55, 0.25, 0.18],
[0, 1.4, 1.7],
materials.frameDark
);
// Back panel and interior side walls.
addBox(
fixedBedFrame,
[5.25, 0.9, 0.12],
[0, 0.84, -1.47],
materials.frameDark
);
for (const x of [-2.49, 2.49]) {
addBox(
fixedBedFrame,
[0.12, 0.92, 2.9],
[x, 0.84, 0],
materials.frameDark
);
}
// Four block legs and feet.
for (const x of [-2.62, 2.62]) {
for (const z of [-1.48, 1.48]) {
addBox(
fixedBedFrame,
[0.3, 1.38, 0.3],
[x, 0.67, z],
materials.frame
);
addBox(
fixedBedFrame,
[0.38, 0.12, 0.38],
[x, 0.04, z],
materials.frameEdge
);
}
}
// -------------------------------------------------------------------------
// Block-built bedding and headboard
// -------------------------------------------------------------------------
addBox(
fixedBedFrame,
[5.3, 0.43, 3.06],
[0, 2.02, 0],
materials.mattress
);
addBox(
fixedBedFrame,
[5.34, 0.09, 3.08],
[0, 2.27, 0],
materials.sheet
);
// Slightly separated blanket blocks create a voxel duvet.
for (let i = 0; i < 5; i++) {
const x = -2.13 + i * 1.065;
addBox(
fixedBedFrame,
[1.045, 0.18, 2.0],
[x, 2.38, 0.43],
i % 2 === 0 ? materials.duvet : materials.duvetAlt
);
}
// Folded section at the foot.
addBox(
fixedBedFrame,
[5.28, 0.13, 0.44],
[0, 2.51, 1.26],
materials.duvetAlt
);
// Two chunky pillows.
for (const x of [-1.28, 1.28]) {
addBox(
fixedBedFrame,
[1.34, 0.24, 0.7],
[x, 2.48, -1.03],
materials.pillow
);
addBox(
fixedBedFrame,
[1.08, 0.08, 0.54],
[x, 2.63, -1.02],
materials.sheet
);
}
// Headboard posts and vertical slats.
for (const x of [-2.66, 2.66]) {
addBox(
fixedBedFrame,
[0.24, 1.56, 0.24],
[x, 2.35, -1.69],
materials.frame
);
}
for (let i = 0; i < 7; i++) {
addBox(
fixedBedFrame,
[0.47, 1.2, 0.15],
[-2.1 + i * 0.7, 2.38, -1.7],
materials.frameEdge
);
}
addBox(
fixedBedFrame,
[5.55, 0.18, 0.26],
[0, 3.0, -1.7],
materials.frame
);
// -------------------------------------------------------------------------
// Drawer construction
// -------------------------------------------------------------------------
function createDrawerShell(parent, width, depth, height, frontMaterial) {
const shell = new THREE.Group();
parent.add(shell);
// Bottom.
addBox(
shell,
[width, 0.08, depth],
[0, 0, 0],
materials.drawerInside
);
// Side walls.
for (const side of [-1, 1]) {
addBox(
shell,
[0.08, height, depth],
[side * (width / 2 - 0.04), height / 2, 0],
materials.drawer
);
}
// Rear wall.
addBox(
shell,
[width, height, 0.08],
[0, height / 2, -depth / 2 + 0.04],
materials.drawerInside
);
// Separate front panel.
addBox(
shell,
[width + 0.05, height + 0.1, 0.12],
[0, height / 2 + 0.02, depth / 2 + 0.035],
frontMaterial
);
// Handle and two small mounts.
for (const x of [-0.16, 0.16]) {
addBox(
shell,
[0.07, 0.07, 0.13],
[x, 0.14, depth / 2 + 0.13],
materials.handle
);
}
addBox(
shell,
[0.44, 0.075, 0.1],
[0, 0.14, depth / 2 + 0.19],
materials.handle
);
return shell;
}
// Three closed under-bed drawers. They are storage assemblies, not part of
// the fixed bed frame.
const closedDrawerCenters = [-2.1, -0.7, 2.1];
for (const x of closedDrawerCenters) {
const closedDrawer = createDrawerShell(
scene,
1.28,
1.45,
0.62,
materials.drawerFront
);
closedDrawer.name = `CLOSED_DRAWER_${x}`;
closedDrawer.position.set(x, 0.35, 0.82);
closedDrawer.userData.role = "Separate closed storage box";
}
// The featured shallow drawer is a direct child of the scene, not the
// fixed frame. This makes its mechanical separation explicit.
const drawerStorageBox = new THREE.Group();
drawerStorageBox.name = "SEPARATE_SHALLOW_DRAWER_STORAGE_BOX";
drawerStorageBox.userData.role = "Independent movable storage box";
scene.add(drawerStorageBox);
const drawerWidth = 1.28;
const drawerDepth = 1.36;
const drawerHeight = 0.46;
const drawerShell = createDrawerShell(
drawerStorageBox,
drawerWidth,
drawerDepth,
drawerHeight,
materials.drawerFront
);
// Contents are also children of the moving storage box.
addBox(
drawerStorageBox,
[0.9, 0.16, 0.8],
[-0.08, 0.14, 0.12],
materials.blanket
);
addBox(
drawerStorageBox,
[0.64, 0.12, 0.59],
[-0.13, 0.27, 0.12],
materials.blanketAlt
);
addBox(
drawerStorageBox,
[0.18, 0.18, 0.18],
[0.37, 0.15, 0.19],
materials.toy
);
addBox(
drawerStorageBox,
[0.32, 0.055, 0.43],
[0.31, 0.075, -0.31],
materials.book
);
// -------------------------------------------------------------------------
// Text label attached to the moving drawer front
// -------------------------------------------------------------------------
function makeTextTexture(text, color = "#f5c85b", background = "rgba(20,29,40,0.92)") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = color;
context.font = "700 42px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
const drawerLabel = new THREE.Mesh(
new THREE.PlaneGeometry(0.72, 0.18),
new THREE.MeshBasicMaterial({
map: makeTextTexture("SHALLOW / 07"),
transparent: true,
depthWrite: false
})
);
drawerLabel.position.set(0, 0.29, drawerDepth / 2 + 0.101);
drawerStorageBox.add(drawerLabel);
// -------------------------------------------------------------------------
// Fixed outer runner rails and moving inner rails
// -------------------------------------------------------------------------
const openDrawerX = 0.7;
for (const side of [-1, 1]) {
const railX = openDrawerX + side * 0.64;
// Outer rail stays with the bed frame.
addBox(
fixedBedFrame,
[0.09, 0.09, 2.0],
[railX, 0.27, 0.68],
materials.metal
);
// Fixed mounting blocks.
for (const z of [-0.18, 1.4]) {
addBox(
fixedBedFrame,
[0.15, 0.15, 0.15],
[railX, 0.28, z],
materials.frameDark
);
}
// Inner rail moves with the separate drawer storage box.
addBox(
drawerStorageBox,
[0.07, 0.07, 2.85],
[side * 0.6, -0.09, 0.12],
materials.runner
);
// Orange slider collars make the telescopic relationship easy to read.
addBox(
drawerStorageBox,
[0.14, 0.13, 0.18],
[side * 0.6, -0.09, -1.08],
materials.slider
);
}
// -------------------------------------------------------------------------
// Marked floor clearance area
// -------------------------------------------------------------------------
const clearanceGroup = new THREE.Group();
clearanceGroup.name = "MARKED_CLEARANCE_AREA";
scene.add(clearanceGroup);
const clearanceWidth = 1.72;
const clearanceDepth = 2.72;
const clearanceCenterX = 0.7;
const clearanceCenterZ = 3.04;
const clearanceMaterial = new THREE.MeshBasicMaterial({
color: 0xf5c85b,
transparent: true,
opacity: 0.1,
depthWrite: false
});
addBox(
clearanceGroup,
[clearanceWidth, 0.025, clearanceDepth],
[clearanceCenterX, 0.012, clearanceCenterZ],
clearanceMaterial,
false,
false
);
const stripeMaterial = new THREE.MeshBasicMaterial({
color: 0xf5c85b
});
const darkStripeMaterial = new THREE.MeshBasicMaterial({
color: 0x26313b
});
// Dashed side borders.
for (const side of [-1, 1]) {
for (let i = 0; i < 8; i++) {
addBox(
clearanceGroup,
[0.065, 0.035, 0.22],
[
clearanceCenterX + side * clearanceWidth / 2,
0.035,
1.79 + i * 0.35
],
stripeMaterial,
false,
false
);
}
}
// Alternating front-edge safety blocks.
for (let i = 0; i < 9; i++) {
addBox(
clearanceGroup,
[0.19, 0.04, 0.1],
[
clearanceCenterX - clearanceWidth / 2 + 0.1 + i * 0.19,
0.039,
clearanceCenterZ + clearanceDepth / 2
],
i % 2 === 0 ? stripeMaterial : darkStripeMaterial,
false,
false
);
}
// Back border.
addBox(
clearanceGroup,
[clearanceWidth, 0.035, 0.065],
[clearanceCenterX, 0.035, clearanceCenterZ - clearanceDepth / 2],
stripeMaterial,
false,
false
);
// Floor label.
const floorLabel = new THREE.Mesh(
new THREE.PlaneGeometry(1.62, 0.38),
new THREE.MeshBasicMaterial({
map: makeTextTexture(
"CLEARANCE",
"#f5c85b",
"rgba(0,0,0,0)"
),
transparent: true,
depthWrite: false
})
);
floorLabel.rotation.x = -Math.PI / 2;
floorLabel.position.set(clearanceCenterX, 0.052, 4.02);
clearanceGroup.add(floorLabel);
// -------------------------------------------------------------------------
// Drawer animation
// -------------------------------------------------------------------------
const CLOSED_Z = 0.82;
const OPEN_Z = 2.82;
let drawerIsOpen = true;
let targetDrawerZ = OPEN_Z;
let currentDrawerZ = OPEN_Z;
drawerStorageBox.position.set(openDrawerX, 0.36, currentDrawerZ);
const drawerButton = document.getElementById("drawerButton");
const resetButton = document.getElementById("resetButton");
const travelValue = document.getElementById("travelValue");
function setDrawerOpen(open) {
drawerIsOpen = open;
targetDrawerZ = open ? OPEN_Z : CLOSED_Z;
drawerButton.textContent = open ? "Close drawer" : "Open drawer";
}
drawerButton.addEventListener("click", () => {
setDrawerOpen(!drawerIsOpen);
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom and reset
// -------------------------------------------------------------------------
let cameraTheta = 0.69;
let cameraPhi = 0.86;
let cameraZoom = 1;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
let pointerTravel = 0;
function updateCamera() {
const radius = 9;
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + radius * Math.cos(cameraPhi),
cameraTarget.z + radius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function resetCamera() {
cameraTheta = 0.69;
cameraPhi = 0.86;
cameraZoom = 1;
updateCamera();
}
resetButton.addEventListener("click", resetCamera);
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerTravel = 0;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
pointerTravel += Math.abs(deltaX) + Math.abs(deltaY);
cameraTheta -= deltaX * 0.006;
cameraPhi -= deltaY * 0.005;
cameraPhi = THREE.MathUtils.clamp(cameraPhi, 0.38, 1.35);
updateCamera();
});
function endPointer(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.62,
1.65
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "d") {
setDrawerOpen(!drawerIsOpen);
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// -------------------------------------------------------------------------
// Responsive orthographic viewport
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = aspect < 1 ? 9.5 : 7.4;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setSize(width, height);
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-delta * 7);
currentDrawerZ = THREE.MathUtils.lerp(
currentDrawerZ,
targetDrawerZ,
smoothing
);
drawerStorageBox.position.z = currentDrawerZ;
const travel =
THREE.MathUtils.clamp(
(currentDrawerZ - CLOSED_Z) / (OPEN_Z - CLOSED_Z),
0,
1
) * 100;
travelValue.textContent = `${Math.round(travel)}%`;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```