Prompt specification
Build or customize the Three.js 3D scene "Door removal and protected storage" 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: Door removal and protected storage
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/door-removal-and-protected-storage-x2182
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing recovered construction materials and component reuse. Animate a door being removed from its hinges and placed in a supported storage rack. Preserve hardware as separate pieces and avoid damaging the reusable frame. Low-poly.
Working Three.js Starter (door-removal-and-protected-storage-x2182):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Recovered Materials — Component Reuse</title>
<style>
:root {
--ink: #eef5f2;
--muted: #b8cbc7;
--accent: #55d6bd;
--accent-2: #f4b860;
--panel: rgba(15, 31, 35, 0.88);
--line: rgba(202, 235, 226, 0.18);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #d9d1bd;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 50px rgba(8, 20, 22, 0.2);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#intro {
top: 22px;
left: 22px;
width: min(410px, calc(100vw - 44px));
padding: 18px 20px 16px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 26px;
height: 3px;
border-radius: 4px;
background: var(--accent);
}
h1 {
margin: 9px 0 7px;
font-size: clamp(23px, 3vw, 34px);
line-height: 1.05;
letter-spacing: -0.035em;
}
#intro p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 14px;
}
.chip {
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 999px;
color: #dcebe7;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
}
.chip::before {
content: "✓";
margin-right: 5px;
color: var(--accent);
}
#steps {
top: 22px;
right: 22px;
width: 255px;
padding: 16px 17px;
border-radius: 18px;
}
.section-title {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
margin-bottom: 11px;
}
.step {
position: relative;
display: grid;
grid-template-columns: 24px 1fr;
gap: 9px;
min-height: 43px;
color: #829a95;
font-size: 12px;
line-height: 1.3;
}
.step:not(:last-child)::after {
content: "";
position: absolute;
left: 10px;
top: 23px;
width: 2px;
height: 24px;
background: rgba(255,255,255,0.11);
}
.step .dot {
position: relative;
z-index: 1;
display: grid;
place-items: center;
width: 21px;
height: 21px;
border: 2px solid rgba(255,255,255,0.16);
border-radius: 50%;
background: #102226;
font-size: 9px;
font-weight: 900;
}
.step strong {
display: block;
margin: 1px 0 3px;
color: inherit;
font-size: 12px;
}
.step.active { color: #edf9f5; }
.step.active .dot {
color: #102226;
border-color: var(--accent);
background: var(--accent);
box-shadow: 0 0 0 5px rgba(85,214,189,0.1);
}
.step.done { color: #9ebbb4; }
.step.done .dot {
color: var(--accent);
border-color: rgba(85,214,189,0.55);
}
#status {
margin-top: 6px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--accent-2);
font-size: 11px;
line-height: 1.45;
}
#controls {
left: 50%;
bottom: 20px;
transform: translateX(-50%);
width: min(760px, calc(100vw - 32px));
padding: 13px 15px 12px;
border-radius: 17px;
}
.control-row {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 12px;
}
button {
border: 0;
color: #102226;
background: var(--accent);
border-radius: 10px;
padding: 9px 13px;
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
}
button:hover { filter: brightness(1.07); }
button:active { transform: translateY(1px); }
#replay {
color: var(--ink);
background: rgba(255,255,255,0.1);
border: 1px solid var(--line);
}
input[type="range"] {
width: 100%;
accent-color: var(--accent);
cursor: pointer;
}
#time {
min-width: 74px;
color: var(--muted);
font: 700 11px ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
}
.hint {
margin-top: 8px;
color: #8fa7a2;
font-size: 10px;
text-align: center;
letter-spacing: 0.025em;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
left: 0;
top: 0;
padding: 6px 9px;
border: 1px solid rgba(255,255,255,0.42);
border-radius: 7px;
background: rgba(15,31,35,0.84);
color: #f6fbf8;
box-shadow: 0 5px 18px rgba(0,0,0,0.15);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.075em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -115%);
transition: opacity 160ms ease;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 13px;
background: rgba(255,255,255,0.5);
}
.world-label.green { border-color: rgba(85,214,189,0.68); }
.world-label.gold { border-color: rgba(244,184,96,0.75); }
@media (max-width: 760px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
#intro p { display: none; }
.chips { margin-top: 9px; }
#steps { display: none; }
#controls { bottom: 10px; width: calc(100vw - 20px); }
.world-label { font-size: 8px; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels" aria-hidden="true"></div>
<section id="intro" class="panel">
<div class="eyebrow">Recovered construction materials</div>
<h1>Door recovery & component reuse</h1>
<p>
A reversible lift-off removal: open the hinge axis, withdraw the pins,
retain every hardware piece separately, and place the reusable door on
four padded rack supports.
</p>
<div class="chips">
<span class="chip">Frame retained</span>
<span class="chip">Hardware separated</span>
<span class="chip">Four-point support</span>
<span class="chip">Ready for reuse</span>
</div>
</section>
<aside id="steps" class="panel">
<div class="section-title">Recovery sequence</div>
<div class="step" data-at="0">
<span class="dot">1</span>
<div><strong>Inspect & open</strong>Expose the reusable hinge axis.</div>
</div>
<div class="step" data-at="2">
<span class="dot">2</span>
<div><strong>Lift clear</strong>Raise the door without loading the frame.</div>
</div>
<div class="step" data-at="4.2">
<span class="dot">3</span>
<div><strong>Separate hardware</strong>Pins, leaves and handle remain intact.</div>
</div>
<div class="step" data-at="6.2">
<span class="dot">4</span>
<div><strong>Transfer safely</strong>Carry the leaf to the storage rack.</div>
</div>
<div class="step" data-at="8.8">
<span class="dot">5</span>
<div><strong>Seat on supports</strong>Lower onto four non-damaging pads.</div>
</div>
<div class="step" data-at="10.6">
<span class="dot">6</span>
<div><strong>Stored for reuse</strong>Frame stays reusable; parts stay sorted.</div>
</div>
<div id="status">Preparing the recovered-material bay…</div>
</aside>
<section id="controls" class="panel">
<div class="control-row">
<button id="play" type="button">Pause</button>
<input id="timeline" type="range" min="0" max="14" step="0.01" value="0"
aria-label="Animation timeline" />
<div id="time">00.0 / 14</div>
<button id="replay" type="button">Replay</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset the camera</div>
</section>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const DURATION = 14;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9d1bd);
scene.fog = new THREE.Fog(0xd9d1bd, 15, 28);
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.05;
document.getElementById("scene").appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemi = new THREE.HemisphereLight(0xf5f4e9, 0x69706a, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3d4, 3.1);
sun.position.set(-4, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa9d9d2, 0.9);
fill.position.set(8, 5, -5);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
}
const MAT = {
ground: material(0xd7cfba),
groundDark: material(0xb8b19f),
zoneFrame: material(0x9bb8ae),
zoneStock: material(0xbba77c),
zoneRack: material(0x93aaa6),
frame: material(0x2d716e, { roughness: 0.62 }),
frameEdge: material(0x174f50),
wood: material(0xc78a50),
woodLight: material(0xd9a768),
woodDark: material(0x8e5939),
woodAlt: material(0xb77847),
rack: material(0x315762, { roughness: 0.58, metalness: 0.18 }),
rackLight: material(0x52737a, { roughness: 0.58, metalness: 0.15 }),
rubber: material(0x283334, { roughness: 0.96 }),
metal: material(0x849398, { roughness: 0.35, metalness: 0.72 }),
metalDark: material(0x4b555a, { roughness: 0.42, metalness: 0.65 }),
brick: material(0xb96846),
brickAlt: material(0x9c5037),
pallet: material(0x8b6745),
cream: material(0xe9e3d2),
amber: material(0xf4b860)
};
function box(w, h, d, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(radius, height, mat, x = 0, y = 0, z = 0, parent = scene, segments = 12) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function plane(w, d, mat, x, z, y = 0.003) {
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(w, d), mat);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, y, z);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function smooth(t, a, b) {
const u = THREE.MathUtils.clamp((t - a) / (b - a), 0, 1);
return u * u * (3 - 2 * u);
}
function mix(a, b, u) {
return a + (b - a) * u;
}
function bezier(out, p0, p1, p2, u) {
const v = 1 - u;
out.set(
v*v*p0.x + 2*v*u*p1.x + u*u*p2.x,
v*v*p0.y + 2*v*u*p1.y + u*u*p2.y,
v*v*p0.z + 2*v*u*p1.z + u*u*p2.z
);
return out;
}
/* -------------------------- Recovery bay -------------------------- */
box(14, 0.22, 10, MAT.ground, 0, -0.13, 0);
box(13.7, 0.16, 9.7, MAT.groundDark, 0, -0.26, 0);
plane(3.5, 4.2, MAT.zoneFrame, -1.1, -0.25);
plane(3.0, 3.4, MAT.zoneStock, -4.0, -0.75);
plane(4.6, 4.9, MAT.zoneRack, 3.0, -0.45);
// Pallet and recovered bricks.
box(2.6, 0.14, 1.65, MAT.pallet, -4.0, 0.10, -1.0);
for (let i = 0; i < 6; i++) {
box(0.32, 0.08, 1.55, MAT.pallet, -5.08 + i * 0.43, 0.21, -1.0);
}
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 4; col++) {
const brick = box(
0.48, 0.23, 0.72,
(row + col) % 2 ? MAT.brick : MAT.brickAlt,
-4.92 + col * 0.61,
0.38 + row * 0.245,
-1.23 + (row % 2) * 0.08
);
brick.rotation.y = ((row * 7 + col * 3) % 5 - 2) * 0.012;
}
}
// Reclaimed timber offcuts.
box(2.35, 0.13, 0.34, MAT.woodDark, -4.15, 0.30, 0.55);
box(2.15, 0.13, 0.31, MAT.wood, -4.05, 0.47, 0.57, scene).rotation.y = 0.025;
box(1.95, 0.12, 0.30, MAT.woodAlt, -4.20, 0.63, 0.53, scene).rotation.y = -0.02;
// Small stack of recovered panels.
for (let i = 0; i < 3; i++) {
box(1.1, 0.07, 0.8, i % 2 ? MAT.cream : MAT.woodLight,
-5.0, 0.06 + i * 0.09, 1.42).rotation.y = i * 0.018;
}
/* -------------------------- Reusable frame -------------------------- */
const frame = new THREE.Group();
scene.add(frame);
box(0.18, 3.22, 0.25, MAT.frame, -1.27, 1.61, 0, frame);
box(0.18, 3.22, 0.25, MAT.frame, 1.17, 1.61, 0, frame);
box(2.62, 0.20, 0.25, MAT.frame, -0.05, 3.22, 0, frame);
box(2.44, 0.11, 0.28, MAT.frameEdge, -0.05, 0.07, 0, frame);
box(0.31, 0.07, 0.40, MAT.rubber, -1.27, 0.035, 0, frame);
box(0.31, 0.07, 0.40, MAT.rubber, 1.17, 0.035, 0, frame);
for (let i = 0; i < 3; i++) {
const y = 0.62 + i * 0.93;
box(0.045, 0.18, 0.04, MAT.cream, -1.184, y, 0.135, frame);
box(0.045, 0.18, 0.04, MAT.cream, 1.084, y, 0.135, frame);
}
/* -------------------------- Storage rack -------------------------- */
const rack = new THREE.Group();
scene.add(rack);
const rackX1 = 1.28;
const rackX2 = 4.72;
const rackZ1 = -2.25;
const rackZ2 = 1.35;
for (const x of [rackX1, rackX2]) {
for (const z of [rackZ1, rackZ2]) {
box(0.13, 2.25, 0.13, MAT.rack, x, 1.125, z, rack);
box(0.25, 0.06, 0.25, MAT.rubber, x, 0.03, z, rack);
}
}
box(3.58, 0.12, 3.72, MAT.rackLight, 3.0, 1.48, -0.45, rack);
box(3.58, 0.10, 3.72, MAT.rack, 3.0, 0.56, -0.45, rack);
box(3.58, 0.13, 0.13, MAT.rack, 3.0, 1.26, rackZ2, rack);
box(3.58, 0.13, 0.13, MAT.rack, 3.0, 0.38, rackZ2, rack);
const rearBrace = box(3.44, 0.08, 0.08, MAT.rack, 3.0, 1.08, rackZ1, rack);
rearBrace.rotation.z = 0.49;
const rearBrace2 = box(3.44, 0.08, 0.08, MAT.rack, 3.0, 1.08, rackZ1, rack);
rearBrace2.rotation.z = -0.49;
// Rear stop and four padded support points.
box(2.55, 0.13, 0.09, MAT.rack, 2.66, 1.71, -2.16, rack);
for (const x of [1.70, 3.62]) {
for (const z of [0.48, -1.76]) {
box(0.24, 0.05, 0.24, MAT.rubber, x, 1.565, z, rack);
}
}
// Dedicated parts tray, separate from the door.
box(0.86, 0.07, 1.85, MAT.cream, 4.24, 1.585, -0.08, rack);
box(0.045, 0.12, 1.85, MAT.rackLight, 3.81, 1.65, -0.08, rack);
box(0.045, 0.12, 1.85, MAT.rackLight, 4.67, 1.65, -0.08, rack);
box(0.86, 0.12, 0.045, MAT.rackLight, 4.24, 1.65, -1.005, rack);
box(0.86, 0.12, 0.045, MAT.rackLight, 4.24, 1.65, 0.845, rack);
/* -------------------------- Reusable door -------------------------- */
const doorCarrier = new THREE.Group();
const doorSwing = new THREE.Group();
doorCarrier.add(doorSwing);
scene.add(doorCarrier);
const DOOR_WIDTH = 2.18;
const DOOR_HEIGHT = 2.76;
const doorGroup = new THREE.Group();
doorSwing.add(doorGroup);
// Leaf, stiles, rails and inset panels are separate visible components.
box(DOOR_WIDTH - 0.03, DOOR_HEIGHT - 0.03, 0.09, MAT.wood,
DOOR_WIDTH / 2, DOOR_HEIGHT / 2 + 0.02, 0, doorGroup);
box(0.17, DOOR_HEIGHT, 0.065, MAT.woodLight,
0.105, DOOR_HEIGHT / 2 + 0.02, 0.066, doorGroup);
box(0.17, DOOR_HEIGHT, 0.065, MAT.woodLight,
DOOR_WIDTH - 0.105, DOOR_HEIGHT / 2 + 0.02, 0.066, doorGroup);
box(DOOR_WIDTH - 0.18, 0.18, 0.065, MAT.woodLight,
DOOR_WIDTH / 2, 0.14, 0.066, doorGroup);
box(DOOR_WIDTH - 0.18, 0.18, 0.065, MAT.woodLight,
DOOR_WIDTH / 2, DOOR_HEIGHT - 0.08, 0.066, doorGroup);
const panelPositions = [0.58, 1.38, 2.18];
for (const y of panelPositions) {
box(0.78, 0.59, 0.025, MAT.woodDark, 0.61, y, 0.061, doorGroup);
box(0.78, 0.59, 0.025, MAT.woodAlt, 1.57, y, 0.061, doorGroup);
}
const doorAnchor = new THREE.Group();
doorAnchor.position.set(-1.10, 0, 0.08);
scene.add(doorAnchor);
/* -------------------------- Separate hardware -------------------------- */
function makeHingeLeaf() {
const group = new THREE.Group();
box(0.18, 0.24, 0.035, MAT.metal, 0, 0, 0, group);
for (const y of [-0.067, 0.067]) {
const screw = cylinder(0.017, 0.009, MAT.metalDark, 0, y, 0.024, group, 10);
screw.rotation.x = Math.PI / 2;
}
scene.add(group);
return group;
}
function makePin() {
const group = new THREE.Group();
cylinder(0.032, 0.35, MAT.metal, 0, 0, 0, group, 12);
cylinder(0.043, 0.035, MAT.metalDark, 0, 0.165, 0, group, 12);
cylinder(0.043, 0.035, MAT.metalDark, 0, -0.165, 0, group, 12);
scene.add(group);
return group;
}
function makeHandle() {
const group = new THREE.Group();
const rose = cylinder(0.083, 0.04, MAT.metal, 0, 0, 0, group, 14);
rose.rotation.x = Math.PI / 2;
box(0.23, 0.055, 0.065, MAT.metal, 0.105, 0, 0.062, group);
box(0.045, 0.045, 0.085, MAT.metalDark, 0.21, 0, 0.055, group);
scene.add(group);
return group;
}
const hingeY = [0.62, 1.55, 2.48];
const hardwareItems = [];
const flatQ = new THREE.Quaternion().setFromEuler(new THREE.Euler(-Math.PI / 2, 0, 0));
for (let i = 0; i < 3; i++) {
const y = hingeY[i];
hardwareItems.push({
obj: makeHingeLeaf(),
attach: doorSwing,
local: new THREE.Vector3(0.105, y, 0.112),
localQ: new THREE.Quaternion(),
moveStart: 5.25 + i * 0.035,
moveEnd: 8.42 + i * 0.035,
target: new THREE.Vector3(4.07, 1.655, -0.70 + i * 0.29),
targetQ: flatQ.clone(),
kind: "leaf"
});
hardwareItems.push({
obj: makeHingeLeaf(),
attach: frame,
local: new THREE.Vector3(-1.245, y, 0.148),
localQ: new THREE.Quaternion(),
moveStart: 5.34 + i * 0.035,
moveEnd: 8.52 + i * 0.035,
target: new THREE.Vector3(4.35, 1.655, -0.70 + i * 0.29),
targetQ: flatQ.clone(),
kind: "leaf"
});
hardwareItems.push({
obj: makePin(),
attach: doorAnchor,
local: new THREE.Vector3(0, y, 0),
localQ: new THREE.Quaternion(),
moveStart: 5.12 + i * 0.025,
moveEnd: 8.28 + i * 0.025,
target: new THREE.Vector3(4.54, 1.695, -0.58 + i * 0.39),
targetQ: new THREE.Quaternion().setFromEuler(new THREE.Euler(Math.PI / 2, 0, 0)),
kind: "pin"
});
}
hardwareItems.push({
obj: makeHandle(),
attach: doorSwing,
local: new THREE.Vector3(1.98, 1.28, 0.17),
localQ: new THREE.Quaternion(),
moveStart: 5.37,
moveEnd: 8.48,
target: new THREE.Vector3(4.21, 1.73, 0.48),
targetQ: flatQ.clone(),
kind: "handle"
});
/* -------------------------- Animation state -------------------------- */
const BASE_DOOR = new THREE.Vector3(-1.10, 0, 0.08);
const LIFTED_DOOR = new THREE.Vector3(-1.17, 0.43, 0.23);
const PATH_START = LIFTED_DOOR.clone();
const PATH_END = new THREE.Vector3(1.55, 2.45, 0.72);
const PATH_CONTROL = new THREE.Vector3(-0.15, 2.85, 2.25);
const FINAL_DOOR = new THREE.Vector3(1.55, 1.64, 0.72);
function doorSwingAngle(t) {
if (t < 2.05) return 0;
if (t < 4.05) return mix(0, -1.64, smooth(t, 2.05, 4.05));
if (t < 5.22) return -1.64;
if (t < 6.18) return mix(-1.64, 0, smooth(t, 5.22, 6.18));
return 0;
}
function computeDoorState(t) {
const position = BASE_DOOR.clone();
const quaternion = new THREE.Quaternion();
if (t >= 4.05 && t < 5.22) {
position.lerpVectors(BASE_DOOR, LIFTED_DOOR, smooth(t, 4.05, 5.22));
} else if (t >= 5.22 && t < 6.18) {
position.copy(LIFTED_DOOR);
} else if (t >= 6.18 && t < 8.80) {
const u = smooth(t, 6.18, 8.80);
bezier(position, PATH_START, PATH_CONTROL, PATH_END, u);
} else if (t >= 8.80) {
position.copy(PATH_END);
if (t < 10.50) {
position.lerpVectors(PATH_END, FINAL_DOOR, smooth(t, 8.80, 10.50));
} else {
position.copy(FINAL_DOOR);
}
}
if (t >= 6.35 && t < 8.55) {
quaternion.identity().slerp(flatQ, smooth(t, 6.35, 8.55));
} else if (t >= 8.55) {
quaternion.copy(flatQ);
}
return { position, quaternion, angle: doorSwingAngle(t) };
}
function releaseOffset(item, t) {
if (item.kind === "pin") {
return new THREE.Vector3(0, 0.42 * smooth(t, 4.35, 5.02), 0);
}
if (item.kind === "leaf") {
return new THREE.Vector3(0, 0, 0.18 * smooth(t, 4.93, 5.22));
}
return new THREE.Vector3(0, 0, 0.24 * smooth(t, 4.98, 5.25));
}
function hardwareStartMatrix(item) {
const state = computeDoorState(item.moveStart);
const local = item.local.clone().add(releaseOffset(item, item.moveStart));
const localMatrix = new THREE.Matrix4().compose(
local,
item.localQ,
new THREE.Vector3(1, 1, 1)
);
let attachmentMatrix;
if (item.attach === doorSwing) {
attachmentMatrix = new THREE.Matrix4().compose(
state.position,
state.quaternion,
new THREE.Vector3(1, 1, 1)
);
attachmentMatrix.multiply(
new THREE.Matrix4().makeRotationY(state.angle)
);
} else if (item.attach === doorAnchor) {
attachmentMatrix = new THREE.Matrix4().makeTranslation(
doorAnchor.position.x,
doorAnchor.position.y,
doorAnchor.position.z
);
} else {
attachmentMatrix = new THREE.Matrix4();
}
return attachmentMatrix.multiply(localMatrix);
}
const tempMatrix = new THREE.Matrix4();
const tempPosition = new THREE.Vector3();
const tempQuaternion = new THREE.Quaternion();
const tempScale = new THREE.Vector3();
const transferStart = new THREE.Vector3();
const transferEnd = new THREE.Vector3();
const transferQ1 = new THREE.Quaternion();
const transferQ2 = new THREE.Quaternion();
function updateHardware(t) {
for (const item of hardwareItems) {
if (t < item.moveStart) {
item.attach.updateWorldMatrix(true, false);
const local = item.local.clone().add(releaseOffset(item, t));
const localMatrix = new THREE.Matrix4().compose(
local,
item.localQ,
new THREE.Vector3(1, 1, 1)
);
tempMatrix.multiplyMatrices(item.attach.matrixWorld, localMatrix);
tempMatrix.decompose(item.obj.position, item.obj.quaternion, tempScale);
} else {
const u = smooth(t, item.moveStart, item.moveEnd);
hardwareStartMatrix(item).decompose(transferStart, transferQ1, tempScale);
transferEnd.copy(item.target);
transferEnd.y += Math.sin(Math.PI * u) * 0.42;
item.obj.position.lerpVectors(transferStart, transferEnd, u);
transferQ2.copy(item.targetQ);
item.obj.quaternion.copy(transferQ1).slerp(transferQ2, u);
}
}
}
function updateSceneAt(t) {
const state = computeDoorState(t);
doorCarrier.position.copy(state.position);
doorCarrier.quaternion.copy(state.quaternion);
doorSwing.rotation.y = state.angle;
scene.updateMatrixWorld(true);
updateHardware(t);
}
/* -------------------------- Camera controls -------------------------- */
const cameraState = {
yaw: 0.57,
pitch: 1.03,
radius: 12.8,
target: new THREE.Vector3(0.15, 1.35, -0.35),
goalYaw: 0.57,
goalPitch: 1.03,
goalRadius: 12.8
};
function resetCamera() {
cameraState.goalYaw = 0.57;
cameraState.goalPitch = 1.03;
cameraState.goalRadius = 12.8;
cameraState.target.set(0.15, 1.35, -0.35);
}
function updateCamera(dt) {
const damp = 1 - Math.exp(-dt * 9);
cameraState.yaw = THREE.MathUtils.lerp(cameraState.yaw, cameraState.goalYaw, damp);
cameraState.pitch = THREE.MathUtils.lerp(cameraState.pitch, cameraState.goalPitch, damp);
cameraState.radius = THREE.MathUtils.lerp(cameraState.radius, cameraState.goalRadius, damp);
const s = Math.sin(cameraState.pitch);
camera.position.set(
cameraState.target.x + cameraState.radius * s * Math.sin(cameraState.yaw),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.pitch),
cameraState.target.z + cameraState.radius * s * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.goalYaw -= dx * 0.0055;
cameraState.goalPitch = THREE.MathUtils.clamp(
cameraState.goalPitch + dy * 0.0045,
0.43,
1.35
);
});
function endDrag(event) {
dragging = false;
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();
cameraState.goalRadius = THREE.MathUtils.clamp(
cameraState.goalRadius + event.deltaY * 0.008,
7.2,
18
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
/* -------------------------- Projected labels -------------------------- */
const labelRoot = document.getElementById("labels");
function addLabel(text, className, positionFn, visibleFn = () => true) {
const element = document.createElement("div");
element.className = `world-label ${className || ""}`;
element.textContent = text;
labelRoot.appendChild(element);
return { element, positionFn, visibleFn };
}
const worldLabels = [
addLabel("Recovered brick & timber", "gold",
() => new THREE.Vector3(-4.0, 1.25, -0.65)),
addLabel("Reusable frame retained", "green",
() => new THREE.Vector3(-1.28, 3.52, 0)),
addLabel("Reusable door leaf", "green",
() => doorSwing.localToWorld(new THREE.Vector3(1.08, 2.88, 0.08))),
addLabel("Hardware kept separate", "gold",
() => new THREE.Vector3(4.22, 1.97, -0.05),
(t) => t > 5.35),
addLabel("Supported storage rack", "green",
() => new THREE.Vector3(4.72, 2.38, 1.28),
(t) => t > 7.3)
];
const projected = new THREE.Vector3();
function updateLabels(t) {
for (const label of worldLabels) {
if (!label.visibleFn(t)) {
label.element.style.opacity = "0";
continue;
}
projected.copy(label.positionFn()).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.12 &&
Math.abs(projected.y) < 1.12;
label.element.style.opacity = visible ? "1" : "0";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.transform = `translate(${x}px, ${y}px) translate(-50%, -115%)`;
}
}
}
/* -------------------------- Timeline UI -------------------------- */
const playButton = document.getElementById("play");
const replayButton = document.getElementById("replay");
const timeline = document.getElementById("timeline");
const timeDisplay = document.getElementById("time");
const status = document.getElementById("status");
const stepElements = [...document.querySelectorAll(".step")];
let time = 0;
let playing = true;
function setPlaying(value) {
playing = value;
playButton.textContent = playing ? "Pause" : "Play";
}
playButton.addEventListener("click", () => {
if (!playing && time >= DURATION) time = 0;
setPlaying(!playing);
});
replayButton.addEventListener("click", () => {
time = 0;
setPlaying(true);
});
timeline.addEventListener("input", () => {
time = Number(timeline.value);
setPlaying(false);
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target.tagName !== "INPUT") {
event.preventDefault();
if (!playing && time >= DURATION) time = 0;
setPlaying(!playing);
}
});
function phaseInfo(t) {
if (t < 2.05) return [0, "Inspect the recovered door and its reusable frame."];
if (t < 4.05) return [1, "Open the door to expose the hinge axis without loading the frame."];
if (t < 5.22) return [2, "Lift the leaf clear and withdraw the hinge pins vertically."];
if (t < 6.18) return [3, "Keep hinge leaves and the handle as separate, recoverable pieces."];
if (t < 8.80) return [4, "Transfer the detached door toward the storage rack."];
if (t < 10.50) return [5, "Lower the door onto four padded, non-damaging supports."];
return [6, "The door, frame and hardware are now stored for future reuse."];
}
function updateUI() {
const [active, message] = phaseInfo(time);
timeline.value = time;
timeDisplay.textContent = `${time.toFixed(1).padStart(4, "0")} / ${DURATION}`;
status.textContent = message;
stepElements.forEach((element, index) => {
element.classList.toggle("active", index === active);
element.classList.toggle("done", index < active);
});
}
/* -------------------------- Resize and render -------------------------- */
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (playing) {
time = Math.min(DURATION, time + dt);
if (time >= DURATION) setPlaying(false);
}
updateSceneAt(time);
updateCamera(dt);
camera.updateMatrixWorld();
updateLabels(time);
updateUI();
renderer.render(scene, camera);
}
updateSceneAt(0);
updateCamera(1);
updateLabels(0);
updateUI();
animate();
</script>
</body>
</html>
```