Prompt specification
Build or customize the Three.js 3D scene "Seat clearance and lid motion" 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: Seat clearance and lid motion
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/seat-clearance-and-lid-motion-x0170
Scene Description Prompt:
Open a voxel storage bench beside a wall and hanging coat; highlight the lid's sweep and stop before contact. Standalone HTML using Three.js from cdnjs.
Working Three.js Starter (seat-clearance-and-lid-motion-x0170):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Storage Bench — Safe Lid Sweep</title>
<style>
:root {
color-scheme: light;
--ink: #252a2d;
--muted: #626b6c;
--amber: #f3a62f;
--green: #39a875;
--red: #dc554d;
--panel: rgba(250, 248, 241, 0.9);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d6cd;
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;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(55, 58, 56, 0.15);
background: var(--panel);
box-shadow: 0 12px 36px rgba(46, 42, 34, 0.13);
backdrop-filter: blur(12px);
}
#intro {
top: 24px;
left: 24px;
width: min(350px, calc(100vw - 48px));
padding: 17px 19px 16px;
border-radius: 16px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: #8d5b16;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--amber);
content: "";
box-shadow: 0 0 0 4px rgba(243, 166, 47, 0.14);
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 30px);
line-height: 1.05;
letter-spacing: -0.035em;
}
#intro p {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
#legend {
top: 24px;
right: 24px;
padding: 13px 15px;
border-radius: 13px;
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 4px 0;
color: #525958;
font-size: 12px;
font-weight: 650;
}
.swatch {
width: 18px;
height: 5px;
border-radius: 5px;
background: var(--amber);
}
.swatch.safe { background: var(--green); }
.swatch.limit { background: var(--red); }
#controls {
bottom: 22px;
left: 50%;
width: min(560px, calc(100vw - 28px));
padding: 13px 15px;
border-radius: 16px;
transform: translateX(-50%);
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 13px;
}
button {
min-height: 39px;
padding: 0 15px;
border: 0;
border-radius: 10px;
background: #273335;
color: white;
font: inherit;
font-size: 13px;
font-weight: 750;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
button:hover { background: #172224; }
button:active { transform: translateY(1px); }
button.secondary {
background: rgba(40, 50, 51, 0.09);
color: #354042;
}
.slider-wrap {
display: flex;
align-items: center;
min-width: 0;
gap: 10px;
}
input[type="range"] {
width: 100%;
accent-color: var(--amber);
cursor: pointer;
}
#angle {
width: 48px;
color: #555e5e;
font-size: 12px;
font-variant-numeric: tabular-nums;
text-align: right;
}
#status {
position: fixed;
z-index: 9;
left: 50%;
bottom: 92px;
padding: 7px 11px;
border: 1px solid rgba(57, 168, 117, 0.3);
border-radius: 999px;
background: rgba(241, 252, 246, 0.92);
color: #277e5a;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
transform: translateX(-50%);
pointer-events: none;
transition: opacity 180ms ease;
}
#hint {
position: fixed;
z-index: 8;
right: 24px;
bottom: 25px;
color: rgba(38, 46, 47, 0.62);
font-size: 11px;
font-weight: 650;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 8;
padding: 6px 9px;
border-radius: 8px;
color: white;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
box-shadow: 0 5px 16px rgba(0, 0, 0, 0.14);
}
#safe-label { background: var(--green); }
#limit-label { background: var(--red); }
@media (max-width: 700px) {
#legend, #hint { display: none; }
#intro { top: 14px; left: 14px; }
#controls {
bottom: 14px;
grid-template-columns: auto 1fr;
}
#replay { display: none; }
#status { bottom: 83px; }
}
</style>
</head>
<body>
<section id="intro" class="panel">
<div class="eyebrow">Collision-aware demonstration</div>
<h1>Storage Bench Lid</h1>
<p>The amber arc maps the lid’s sweep. It stops at 88°, leaving a visible gap before the wall-contact limit.</p>
</section>
<aside id="legend" class="panel">
<div class="legend-row"><span class="swatch"></span> Lid sweep</div>
<div class="legend-row"><span class="swatch safe"></span> Safe stop</div>
<div class="legend-row"><span class="swatch limit"></span> Wall limit</div>
</aside>
<div id="status">Opening lid</div>
<div class="world-label" id="safe-label">Safe stop · 88°</div>
<div class="world-label" id="limit-label">Wall limit · 94°</div>
<section id="controls" class="panel">
<button id="toggle" type="button">Close lid</button>
<div class="slider-wrap">
<input id="angle-slider" type="range" min="0" max="88" value="0" aria-label="Lid opening angle" />
<span id="angle">0°</span>
</div>
<button id="replay" class="secondary" type="button">Replay</button>
</section>
<div id="hint">Drag to orbit · Scroll to zoom</div>
<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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d6cd);
scene.fog = new THREE.Fog(0xd8d6cd, 10, 18);
const camera = new THREE.PerspectiveCamera(38, innerWidth / innerHeight, 0.1, 50);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xf8f3df, 0x697477, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffedcf, 3.2);
sun.position.set(4.5, 8, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -7;
sun.shadow.camera.right = 7;
sun.shadow.camera.top = 7;
sun.shadow.camera.bottom = -5;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 20;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbad9e6, 0.75);
fill.position.set(-5, 4, 2);
scene.add(fill);
const mat = (color, roughness = 0.8, metalness = 0) =>
new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
});
const materials = {
floor: mat(0xb9b0a1),
floorAlt: mat(0xc4bbac),
grout: mat(0x9e978c),
wall: mat(0xe7e2d5),
wallAlt: mat(0xded8ca),
wallLine: mat(0xc9c1b2),
trim: mat(0xf0ebdf),
wood: mat(0x9b5f35),
woodLight: mat(0xb97846),
woodDark: mat(0x704329),
metal: mat(0x485052, 0.48, 0.48),
brass: mat(0xb18a47, 0.42, 0.55),
coat: mat(0x315b61),
coatLight: mat(0x416f73),
coatDark: mat(0x24474d),
cream: mat(0xd8c6a2),
green: mat(0x39a875, 0.45),
red: mat(0xdc554d, 0.45),
amber: mat(0xf3a62f, 0.38),
dark: mat(0x252a2d)
};
function box(w, h, d, material, x, y, z, parent = scene, edges = false) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (edges) {
const line = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color: 0x302820,
transparent: true,
opacity: 0.22
})
);
mesh.add(line);
}
return mesh;
}
// -------------------------------------------------------------------------
// Voxel room
// -------------------------------------------------------------------------
box(10, 0.18, 8, materials.floor, 0, -0.09, 1.0);
const tileSize = 1.95;
for (let x = -4; x <= 4; x += 2) {
for (let z = -2; z <= 4; z += 2) {
const tile = box(
1.88,
0.035,
1.88,
(x + z) % 4 === 0 ? materials.floorAlt : materials.floor,
x + (x % 4 === 0 ? 0.05 : -0.05),
0.01,
z,
scene,
false
);
tile.receiveShadow = true;
}
}
// Rear wall. Its front face is the collision plane.
const WALL_FRONT_Z = -1.0;
box(9.2, 4.4, 0.4, materials.wall, 0, 2.2, WALL_FRONT_Z - 0.2);
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 6; col++) {
const offset = row % 2 === 0 ? 0 : 0.38;
box(
1.39,
0.74,
0.025,
(row + col) % 3 === 0 ? materials.wallAlt : materials.wall,
-3.15 + col * 1.26 + offset,
0.42 + row * 0.78,
WALL_FRONT_Z + 0.012
);
}
}
box(9.1, 0.22, 0.12, materials.trim, 0, 0.11, WALL_FRONT_Z + 0.04);
box(9.1, 0.12, 0.16, materials.wallLine, 0, 4.28, WALL_FRONT_Z + 0.05);
// -------------------------------------------------------------------------
// Storage bench
// -------------------------------------------------------------------------
const BENCH_X = -0.75;
const BENCH_WIDTH = 3.2;
const BENCH_DEPTH = 1.5;
const HINGE_Y = 1.12;
const HINGE_Z = -0.75;
// Four voxel feet.
for (const dx of [-1.27, 1.27]) {
for (const dz of [-0.51, 0.51]) {
box(0.31, 0.57, 0.31, materials.woodDark,
BENCH_X + dx, 0.285, dz, scene, true);
}
}
// Lower frame and storage body.
box(BENCH_WIDTH, 0.18, BENCH_DEPTH, materials.woodDark,
BENCH_X, 0.62, 0, scene, true);
box(BENCH_WIDTH - 0.08, 0.42, BENCH_DEPTH - 0.05, materials.wood,
BENCH_X, 0.89, 0, scene, true);
// Front storage panels and handles.
for (let i = -1; i <= 1; i++) {
box(0.94, 0.29, 0.055, materials.woodLight,
BENCH_X + i * 1.01, 0.89, 0.762, scene, true);
box(0.24, 0.055, 0.075, materials.brass,
BENCH_X + i * 1.01, 0.9, 0.815);
}
// Top rails remain visible beneath the opened lid.
box(BENCH_WIDTH, 0.11, 0.10, materials.woodDark,
BENCH_X, 1.075, 0.69);
box(BENCH_WIDTH, 0.11, 0.10, materials.woodDark,
BENCH_X, 1.075, -0.69);
// Hinge blocks.
for (const dx of [-1.12, 1.12]) {
box(0.30, 0.15, 0.23, materials.metal,
BENCH_X + dx, HINGE_Y, HINGE_Z - 0.015, scene, true);
box(0.12, 0.10, 0.27, materials.brass,
BENCH_X + dx, HINGE_Y + 0.015, HINGE_Z + 0.015);
}
// Lid pivot. Local +Z runs from the rear hinge toward the front.
const lidPivot = new THREE.Group();
lidPivot.position.set(BENCH_X, HINGE_Y, HINGE_Z);
scene.add(lidPivot);
box(BENCH_WIDTH, 0.16, BENCH_DEPTH, materials.woodLight,
0, 0.08, BENCH_DEPTH / 2, lidPivot, true);
// Voxel plank seams on the lid.
for (const x of [-1.05, -0.52, 0, 0.52, 1.05]) {
box(0.025, 0.012, 1.42, materials.wood,
x, 0.166, BENCH_DEPTH / 2, lidPivot);
}
// Raised front handle.
box(0.62, 0.09, 0.09, materials.metal,
0, 0.22, 1.33, lidPivot, true);
box(0.09, 0.12, 0.09, materials.brass,
-0.26, 0.18, 1.33, lidPivot);
box(0.09, 0.12, 0.09, materials.brass,
0.26, 0.18, 1.33, lidPivot);
// -------------------------------------------------------------------------
// Hanging voxel coat beside the bench
// -------------------------------------------------------------------------
const coat = new THREE.Group();
coat.position.set(2.45, 0, 0);
scene.add(coat);
box(1.75, 0.11, 0.13, materials.woodDark,
0, 2.77, -0.88, coat, true);
for (const x of [-0.68, 0.68]) {
box(0.12, 0.18, 0.14, materials.brass,
x, 2.69, -0.82, coat, true);
}
// Coat silhouette.
box(0.82, 1.18, 0.25, materials.coat,
0, 1.93, -0.72, coat, true);
box(1.08, 0.25, 0.29, materials.coatLight,
0, 2.44, -0.71, coat, true);
box(0.92, 0.55, 0.28, materials.coat,
0, 1.23, -0.72, coat, true);
const leftSleeve = box(0.29, 0.92, 0.29, materials.coatDark,
-0.61, 2.02, -0.71, coat, true);
leftSleeve.rotation.z = -0.10;
const rightSleeve = box(0.29, 0.92, 0.29, materials.coatDark,
0.61, 2.02, -0.71, coat, true);
rightSleeve.rotation.z = 0.10;
box(0.24, 0.11, 0.28, materials.coatLight,
-0.19, 2.48, -0.69, coat);
box(0.24, 0.11, 0.28, materials.coatLight,
0.19, 2.48, -0.69, coat);
box(0.36, 0.27, 0.05, materials.coatDark,
0, 1.73, -0.575, coat, true);
for (let i = 0; i < 3; i++) {
box(0.07, 0.07, 0.055, materials.cream,
0, 2.24 - i * 0.24, -0.565, coat);
}
// -------------------------------------------------------------------------
// Sweep visualization
// -------------------------------------------------------------------------
const SAFE_ANGLE = 88;
const CONTACT_ANGLE = 94.4;
const SWEEP_X = BENCH_X + BENCH_WIDTH / 2 + 0.05;
const SWEEP_RADIUS = BENCH_DEPTH;
function sweepPoint(degrees, radius = SWEEP_RADIUS, x = SWEEP_X) {
const a = THREE.MathUtils.degToRad(degrees);
return new THREE.Vector3(
x,
HINGE_Y + radius * Math.sin(a),
HINGE_Z + radius * Math.cos(a)
);
}
// A translucent side-plane sector representing the lid's swept area.
const sectorVertices = [SWEEP_X, HINGE_Y, HINGE_Z];
const sectorIndices = [];
const arcSteps = 48;
for (let i = 0; i <= arcSteps; i++) {
const p = sweepPoint(SAFE_ANGLE * i / arcSteps);
sectorVertices.push(p.x, p.y, p.z);
if (i > 0) sectorIndices.push(0, i, i + 1);
}
const sectorGeometry = new THREE.BufferGeometry();
sectorGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(sectorVertices, 3)
);
sectorGeometry.setIndex(sectorIndices);
sectorGeometry.computeVertexNormals();
const sectorMaterial = new THREE.MeshBasicMaterial({
color: 0xf3a62f,
transparent: true,
opacity: 0.10,
side: THREE.DoubleSide,
depthWrite: false
});
const sweepSector = new THREE.Mesh(sectorGeometry, sectorMaterial);
scene.add(sweepSector);
// Bright amber swept arc.
const safeArcPoints = [];
for (let i = 0; i <= 60; i++) {
safeArcPoints.push(sweepPoint(SAFE_ANGLE * i / 60));
}
const safeCurve = new THREE.CatmullRomCurve3(safeArcPoints);
const safeArc = new THREE.Mesh(
new THREE.TubeGeometry(safeCurve, 64, 0.026, 6, false),
new THREE.MeshBasicMaterial({ color: 0xf3a62f })
);
scene.add(safeArc);
// Red dashed continuation showing the forbidden contact zone.
const limitPoints = [];
for (let i = 0; i <= 30; i++) {
limitPoints.push(sweepPoint(
SAFE_ANGLE + (CONTACT_ANGLE - SAFE_ANGLE) * i / 30
));
}
const limitGeometry = new THREE.BufferGeometry().setFromPoints(limitPoints);
const limitLine = new THREE.Line(
limitGeometry,
new THREE.LineDashedMaterial({
color: 0xdc554d,
dashSize: 0.09,
gapSize: 0.055,
transparent: true,
opacity: 0.95
})
);
limitLine.computeLineDistances();
scene.add(limitLine);
// Safe-stop marker.
const safePoint = sweepPoint(SAFE_ANGLE);
const safeMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 12, 8),
new THREE.MeshBasicMaterial({ color: 0x39a875 })
);
safeMarker.position.copy(safePoint);
scene.add(safeMarker);
const safeRing = new THREE.Mesh(
new THREE.TorusGeometry(0.13, 0.018, 8, 28),
new THREE.MeshBasicMaterial({ color: 0x39a875 })
);
safeRing.position.copy(safePoint);
safeRing.rotation.y = Math.PI / 2;
scene.add(safeRing);
// Wall-contact marker.
const limitPoint = sweepPoint(CONTACT_ANGLE);
const limitMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 10, 8),
new THREE.MeshBasicMaterial({ color: 0xdc554d })
);
limitMarker.position.copy(limitPoint);
scene.add(limitMarker);
const limitRing = new THREE.Mesh(
new THREE.TorusGeometry(0.12, 0.018, 8, 28),
new THREE.MeshBasicMaterial({ color: 0xdc554d })
);
limitRing.position.copy(limitPoint);
limitRing.rotation.y = Math.PI / 2;
scene.add(limitRing);
// -------------------------------------------------------------------------
// Direct camera controls — no external control addons
// -------------------------------------------------------------------------
const target = new THREE.Vector3(-0.05, 1.42, -0.05);
let yaw = 0.72;
let pitch = 0.39;
let radius = 7.25;
let dragging = false;
let lastX = 0;
let lastY = 0;
function updateCamera() {
const horizontal = radius * Math.cos(pitch);
camera.position.set(
target.x + horizontal * Math.sin(yaw),
target.y + radius * Math.sin(pitch),
target.z + horizontal * Math.cos(yaw)
);
camera.lookAt(target);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.005, 0.12, 1.08);
updateCamera();
});
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();
radius = THREE.MathUtils.clamp(radius + event.deltaY * 0.005, 4.7, 10.5);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
yaw = 0.72;
pitch = 0.39;
radius = 7.25;
updateCamera();
});
updateCamera();
// -------------------------------------------------------------------------
// Lid animation and UI
// -------------------------------------------------------------------------
const slider = document.getElementById("angle-slider");
const angleReadout = document.getElementById("angle");
const toggleButton = document.getElementById("toggle");
const replayButton = document.getElementById("replay");
const status = document.getElementById("status");
let currentAngle = 0;
let animation = null;
function applyAngle(angle) {
currentAngle = angle;
lidPivot.rotation.x = -THREE.MathUtils.degToRad(angle);
slider.value = angle.toFixed(1);
angleReadout.textContent = `${Math.round(angle)}°`;
const reveal = 0.07 + 0.10 * (angle / SAFE_ANGLE);
sectorMaterial.opacity = reveal;
safeArc.material.opacity = 0.72 + 0.28 * (angle / SAFE_ANGLE);
safeArc.material.transparent = true;
}
function animateTo(targetAngle, duration = 1800) {
animation = {
from: currentAngle,
to: targetAngle,
start: performance.now(),
duration
};
status.textContent = targetAngle > currentAngle ? "Opening lid" : "Closing lid";
status.style.opacity = "1";
toggleButton.textContent = targetAngle > currentAngle ? "Close lid" : "Open lid";
}
toggleButton.addEventListener("click", () => {
if (currentAngle > SAFE_ANGLE * 0.45) {
animateTo(0);
} else {
animateTo(SAFE_ANGLE);
}
});
replayButton.addEventListener("click", () => {
animateTo(0, 650);
setTimeout(() => animateTo(SAFE_ANGLE, 1900), 700);
});
slider.addEventListener("input", () => {
animation = null;
applyAngle(Number(slider.value));
status.textContent = currentAngle >= SAFE_ANGLE - 0.5
? "Stopped safely before contact"
: "Manual lid control";
status.style.opacity = "1";
toggleButton.textContent = currentAngle > SAFE_ANGLE * 0.45
? "Close lid"
: "Open lid";
});
// Project the 3D markers into screen-space HTML labels.
const safeLabel = document.getElementById("safe-label");
const limitLabel = document.getElementById("limit-label");
function positionLabel(element, point) {
const projected = point.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
// Start with a short pause, then open automatically and stop safely.
setTimeout(() => animateTo(SAFE_ANGLE, 2100), 650);
function render(now) {
requestAnimationFrame(render);
if (animation) {
const t = THREE.MathUtils.clamp(
(now - animation.start) / animation.duration,
0,
1
);
const eased = 1 - Math.pow(1 - t, 3);
applyAngle(THREE.MathUtils.lerp(animation.from, animation.to, eased));
if (t >= 1) {
const finishedAt = animation.to;
animation = null;
if (Math.abs(finishedAt - SAFE_ANGLE) < 0.01) {
status.textContent = "Stopped safely before contact";
toggleButton.textContent = "Close lid";
} else {
status.textContent = "Lid closed";
toggleButton.textContent = "Open lid";
}
}
}
positionLabel(safeLabel, safePoint);
positionLabel(limitLabel, limitPoint);
renderer.render(scene, camera);
}
requestAnimationFrame(render);
</script>
</body>
</html>
```