Prompt specification
Build or customize the Three.js 3D scene "Mop reaches beneath cabinet" 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: Mop reaches beneath cabinet
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mop-reaches-beneath-cabinet-x0062
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a reusable flat mop. Animate the head sliding under a low cabinet while the handle tilts through its joint; keep the cleaning pad in continuous contact with the floor. Low-poly.
Working Three.js Starter (mop-reaches-beneath-cabinet-x0062):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Low-Poly Flat Mop</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(17, 24, 32, 0.88);
--line: rgba(255, 255, 255, 0.13);
--accent: #61dfca;
--accent-warm: #ffb45e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d1c5;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 22px;
left: 22px;
z-index: 5;
width: min(360px, calc(100vw - 44px));
padding: 18px 20px;
color: #f5f8fa;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 16px 45px rgba(20, 25, 30, 0.2);
backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 4vw, 30px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
color: #b9c2ca;
font-size: 12px;
line-height: 1.5;
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 6;
width: min(350px, calc(100vw - 44px));
padding: 16px;
color: #f5f8fa;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 16px 45px rgba(20, 25, 30, 0.2);
backdrop-filter: blur(14px);
}
.control-row {
display: flex;
align-items: center;
gap: 9px;
}
button {
min-height: 36px;
padding: 0 13px;
color: #f7fafc;
background: rgba(255, 255, 255, 0.09);
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 8px;
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
}
button:hover {
background: rgba(255, 255, 255, 0.15);
}
#play {
color: #0e2723;
background: var(--accent);
border-color: transparent;
}
#reset {
margin-left: auto;
}
.timeline {
margin-top: 14px;
}
.timeline-label {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: #b9c2ca;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
accent-color: var(--accent);
cursor: pointer;
}
.status {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
color: #cdd5db;
font-size: 11px;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent-warm);
box-shadow: 0 0 12px rgba(255, 180, 94, 0.65);
}
.hint {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #89949e;
font-size: 10px;
line-height: 1.5;
}
@media (max-width: 640px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
}
.subtitle {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section class="title-card">
<div class="eyebrow">Low-poly motion study</div>
<h1>Reusable Flat Mop</h1>
<p class="subtitle">
The head slides beneath the cabinet while the swivel joint folds the
handle out of the way. The segmented cleaning pad remains on the floor.
</p>
</section>
<section class="controls" aria-label="Animation controls">
<div class="control-row">
<button id="play" type="button">Pause</button>
<button id="reset" type="button">Reset</button>
<label class="timeline-label" for="speed" style="margin: 0 0 0 auto;">
Speed
</label>
<select
id="speed"
aria-label="Playback speed"
style="
height: 36px;
color: #f5f8fa;
background: #26313a;
border: 1px solid rgba(255,255,255,.14);
border-radius: 8px;
padding: 0 8px;
"
>
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="1.5">1.5×</option>
<option value="2">2×</option>
</select>
</div>
<div class="timeline">
<div class="timeline-label">
<span>Timeline</span>
<span id="time-label">0.0s</span>
</div>
<input
id="timeline"
type="range"
min="0"
max="1000"
value="0"
step="1"
aria-label="Animation timeline"
/>
</div>
<div class="status">
<span class="status-dot"></span>
<span id="status">Ready</span>
</div>
<div class="hint">
Drag to orbit · Wheel to zoom · Shift-drag or right-drag to pan
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and lighting
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
});
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.12;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d1c5);
scene.fog = new THREE.Fog(0xd8d1c5, 9, 17);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.05,
40
);
const hemiLight = new THREE.HemisphereLight(
0xfff4de,
0x64727a,
2.15
);
scene.add(hemiLight);
const keyLight = new THREE.DirectionalLight(0xfff0d0, 3.25);
keyLight.position.set(4.5, 7, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9dcff, 1.1);
fillLight.position.set(-5, 3.5, 2);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Geometry and material helpers
// -------------------------------------------------------------------------
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0xc8c0b2,
roughness: 0.94,
metalness: 0,
}),
wall: new THREE.MeshStandardMaterial({
color: 0xe4ded3,
roughness: 1,
}),
cabinet: new THREE.MeshStandardMaterial({
color: 0xb47b4b,
roughness: 0.78,
flatShading: true,
}),
cabinetDark: new THREE.MeshStandardMaterial({
color: 0x69452f,
roughness: 0.82,
flatShading: true,
}),
drawer: new THREE.MeshStandardMaterial({
color: 0xc7905b,
roughness: 0.74,
flatShading: true,
}),
black: new THREE.MeshStandardMaterial({
color: 0x26323a,
roughness: 0.58,
flatShading: true,
}),
shaft: new THREE.MeshStandardMaterial({
color: 0x8d9ca4,
roughness: 0.38,
metalness: 0.52,
flatShading: true,
}),
teal: new THREE.MeshStandardMaterial({
color: 0x31b8aa,
roughness: 0.46,
metalness: 0.12,
flatShading: true,
}),
orange: new THREE.MeshStandardMaterial({
color: 0xffa347,
roughness: 0.48,
flatShading: true,
}),
pad: new THREE.MeshStandardMaterial({
color: 0x3c94bd,
roughness: 0.95,
flatShading: true,
}),
padEdge: new THREE.MeshStandardMaterial({
color: 0x246d91,
roughness: 0.98,
flatShading: true,
}),
};
function box(parent, size, position, material, castShadow = true) {
const geometry = new THREE.BoxGeometry(...size);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
material,
segments = 8
) {
const geometry = new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x26323a, opacity = 0.32) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
})
);
mesh.add(edges);
}
// -------------------------------------------------------------------------
// Room and low cabinet
// -------------------------------------------------------------------------
const room = new THREE.Group();
scene.add(room);
// The floor's top surface is exactly y = 0.
box(room, [14, 0.12, 12], [0, -0.06, 0], materials.floor, false);
box(room, [12, 5, 0.12], [0, 2.5, -2.6], materials.wall, false);
const grid = new THREE.GridHelper(
12,
24,
0x8d857a,
0xaaa296
);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.18;
room.add(grid);
const cabinet = new THREE.Group();
cabinet.position.z = -0.02;
scene.add(cabinet);
// Upper cabinet body. Its lower edge is above the mop head.
const top = box(
cabinet,
[2.58, 0.12, 1.34],
[0, 1.36, -0.01],
materials.cabinet
);
addEdges(top, 0x5d402e, 0.22);
const leftSide = box(
cabinet,
[0.12, 0.72, 1.22],
[-1.18, 0.94, -0.02],
materials.cabinetDark
);
addEdges(leftSide, 0x4b3022, 0.2);
const rightSide = box(
cabinet,
[0.12, 0.72, 1.22],
[1.18, 0.94, -0.02],
materials.cabinetDark
);
addEdges(rightSide, 0x4b3022, 0.2);
const back = box(
cabinet,
[2.25, 0.72, 0.08],
[0, 0.94, -0.59],
materials.cabinetDark
);
// Two drawer faces with a narrow dark gap between them.
const drawerA = box(
cabinet,
[1.075, 0.315, 0.08],
[-0.55, 1.115, 0.62],
materials.drawer
);
addEdges(drawerA, 0x69452f, 0.2);
const drawerB = box(
cabinet,
[1.075, 0.315, 0.08],
[0.55, 1.115, 0.62],
materials.drawer
);
addEdges(drawerB, 0x69452f, 0.2);
box(cabinet, [0.30, 0.035, 0.04], [-0.55, 1.10, 0.685], materials.black);
box(cabinet, [0.30, 0.035, 0.04], [0.55, 1.10, 0.685], materials.black);
// Four faceted legs leave an open lower bay for the mop.
for (const x of [-1.08, 1.08]) {
for (const z of [-0.48, 0.46]) {
cylinder(
cabinet,
0.052,
0.068,
0.58,
[x, 0.29, z],
materials.cabinetDark,
6
);
}
}
// A few low-poly objects provide scale without distracting from the mop.
const bookA = box(
cabinet,
[0.52, 0.055, 0.34],
[-0.58, 1.445, 0.02],
new THREE.MeshStandardMaterial({
color: 0xd96f58,
roughness: 0.9,
})
);
bookA.rotation.y = -0.08;
const bookB = box(
cabinet,
[0.44, 0.045, 0.30],
[-0.57, 1.495, 0.01],
new THREE.MeshStandardMaterial({
color: 0x4f8290,
roughness: 0.9,
})
);
bookB.rotation.y = 0.05;
const pot = cylinder(
cabinet,
0.15,
0.11,
0.23,
[0.64, 1.535, -0.02],
materials.orange,
7
);
cylinder(
cabinet,
0.018,
0.025,
0.42,
[0.64, 1.84, -0.02],
materials.cabinetDark,
5
);
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x4d9b69,
roughness: 0.92,
flatShading: true,
});
const leafGeometry = new THREE.ConeGeometry(0.13, 0.38, 5);
for (let i = 0; i < 5; i++) {
const leaf = new THREE.Mesh(leafGeometry, leafMaterial);
const angle = (i / 5) * Math.PI * 2;
leaf.position.set(
0.64 + Math.cos(angle) * 0.10,
1.91 + (i % 2) * 0.08,
-0.02 + Math.sin(angle) * 0.10
);
leaf.rotation.z = Math.cos(angle) * 0.48;
leaf.rotation.x = Math.sin(angle) * 0.48;
leaf.castShadow = true;
cabinet.add(leaf);
}
// -------------------------------------------------------------------------
// Reusable flat-mop factory
// -------------------------------------------------------------------------
/**
* Creates a reusable articulated flat mop.
*
* The mop root is never translated vertically. Every cleaning-pad segment
* has its bottom at local y = 0, so the pad's bottom remains exactly on
* the floor throughout the animation.
*/
function createFlatMop(options = {}) {
const root = new THREE.Group();
root.name = options.name ?? "ReusableFlatMop";
const headMaterial = options.headMaterial ?? materials.black;
const accentMaterial = options.accentMaterial ?? materials.teal;
const padMaterial = options.padMaterial ?? materials.pad;
// Cleaning pad: all five segments touch y = 0.
const padGroup = new THREE.Group();
root.add(padGroup);
const segmentWidth = 0.086;
const segmentGap = 0.011;
const totalWidth = 5 * segmentWidth + 4 * segmentGap;
for (let i = 0; i < 5; i++) {
const x =
-totalWidth / 2 +
segmentWidth / 2 +
i * (segmentWidth + segmentGap);
const segment = box(
padGroup,
[segmentWidth, 0.04, 0.20],
[x, 0.02, 0],
i % 2 === 0 ? padMaterial : materials.padEdge
);
addEdges(segment, 0x153e59, 0.18);
}
// Flat head plate rests directly on top of the cleaning pad.
const head = box(
root,
[0.52, 0.05, 0.22],
[0, 0.065, 0],
headMaterial
);
addEdges(head, 0x111b20, 0.38);
const accent = box(
root,
[0.18, 0.014, 0.225],
[0, 0.098, 0],
accentMaterial
);
addEdges(accent, 0x176d65, 0.25);
// Swivel assembly sits at the front edge of the head.
const swivel = new THREE.Group();
swivel.name = "HandleSwivel";
swivel.position.set(0.12, 0.105, 0.105);
root.add(swivel);
const hingePin = cylinder(
swivel,
0.055,
0.055,
0.115,
[0, 0, 0],
accentMaterial,
10
);
hingePin.rotation.z = Math.PI / 2;
const hingeCap = cylinder(
swivel,
0.067,
0.067,
0.022,
[0.066, 0, 0],
materials.orange,
10
);
hingeCap.rotation.z = Math.PI / 2;
// Pitch group rotates the lower shaft through the hinge.
const pitchGroup = new THREE.Group();
pitchGroup.name = "HandlePitch";
swivel.add(pitchGroup);
const lowerLength = 0.90;
const lowerShaft = cylinder(
pitchGroup,
0.022,
0.025,
lowerLength - 0.035,
[0, 0.035 + (lowerLength - 0.035) / 2, 0],
materials.shaft,
8
);
addEdges(lowerShaft, 0x4d5d66, 0.22);
const lowerCollar = cylinder(
pitchGroup,
0.031,
0.031,
0.11,
[0, 0.15, 0],
accentMaterial,
8
);
// Upper hinge is a child of the pitched lower section.
const upperPivot = new THREE.Group();
upperPivot.name = "UpperHandleHinge";
upperPivot.position.y = lowerLength;
pitchGroup.add(upperPivot);
const upperHinge = cylinder(
upperPivot,
0.042,
0.042,
0.085,
[0, 0, 0],
materials.orange,
10
);
upperHinge.rotation.z = Math.PI / 2;
const upperLength = 0.82;
const upperShaft = cylinder(
upperPivot,
0.018,
0.021,
upperLength - 0.17,
[0, 0.04 + (upperLength - 0.17) / 2, 0],
materials.shaft,
8
);
addEdges(upperShaft, 0x4d5d66, 0.2);
const upperCollar = cylinder(
upperPivot,
0.029,
0.029,
0.10,
[0, 0.13, 0],
accentMaterial,
8
);
const grip = cylinder(
upperPivot,
0.029,
0.033,
0.18,
[0, upperLength - 0.08, 0],
materials.black,
8
);
const gripCap = cylinder(
upperPivot,
0.034,
0.034,
0.025,
[0, upperLength + 0.015, 0],
accentMaterial,
8
);
return {
root,
swivel,
pitchGroup,
upperPivot,
/**
* @param {number} pitch Lower shaft pitch in radians.
* @param {number} upperWorld Upper shaft's world pitch in radians.
* @param {number} swivelYaw Swivel yaw in radians.
*/
setPose(pitch, upperWorld, swivelYaw) {
swivel.rotation.y = swivelYaw;
pitchGroup.rotation.x = pitch;
// upperPivot is nested inside pitchGroup, so its local angle must
// be relative to the lower shaft's pitch.
upperPivot.rotation.x = upperWorld - pitch;
},
};
}
const mop = createFlatMop({ name: "ReusableFlatMop_Main" });
scene.add(mop.root);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const duration = 8.5;
let elapsed = 0;
let playing = true;
let playbackSpeed = 1;
const playButton = document.getElementById("play");
const resetButton = document.getElementById("reset");
const timeline = document.getElementById("timeline");
const timeLabel = document.getElementById("time-label");
const statusLabel = document.getElementById("status");
const speedSelect = document.getElementById("speed");
function smootherStep(edge0, edge1, value) {
const t = THREE.MathUtils.clamp(
(value - edge0) / (edge1 - edge0),
0,
1
);
return t * t * t * (t * (t * 6 - 15) + 10);
}
function poseAt(progress) {
const insertion =
smootherStep(0.055, 0.57, progress) *
(1 - smootherStep(0.72, 0.995, progress));
const tilt =
smootherStep(0.16, 0.69, progress) *
(1 - smootherStep(0.72, 0.985, progress));
// Slide from the open floor into the lower bay of the cabinet.
mop.root.position.z = THREE.MathUtils.lerp(1.62, -0.28, insertion);
// A small lateral cleaning motion occurs only while under the cabinet.
const cleaningMotion =
Math.sin((progress - 0.45) * Math.PI * 8) *
0.035 *
Math.sin(Math.PI * insertion);
mop.root.position.x =
THREE.MathUtils.lerp(0.18, -0.04, insertion) + cleaningMotion;
// Deliberately leave root.position.y at zero. This keeps the pad's
// bottom surface continuously in contact with the floor.
mop.root.position.y = 0;
const lowerPitch = THREE.MathUtils.degToRad(58) * tilt;
const upperPitch = THREE.MathUtils.degToRad(66) * tilt;
const swivelYaw = THREE.MathUtils.degToRad(-7) * tilt;
mop.setPose(lowerPitch, upperPitch, swivelYaw);
let status = "Ready";
if (progress > 0.015 && progress < 0.16) {
status = "Approaching cabinet";
} else if (progress < 0.57) {
status = "Sliding head under cabinet";
} else if (progress < 0.72) {
status = "Handle folded through swivel joint";
} else if (progress < 0.985) {
status = "Returning to ready position";
}
statusLabel.textContent = status;
}
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
});
resetButton.addEventListener("click", () => {
elapsed = 0;
playing = true;
playButton.textContent = "Pause";
});
speedSelect.addEventListener("change", () => {
playbackSpeed = Number(speedSelect.value);
});
// Scrubbing pauses playback so the selected pose remains visible.
timeline.addEventListener("input", () => {
playing = false;
playButton.textContent = "Play";
elapsed = (Number(timeline.value) / 1000) * duration;
});
// -------------------------------------------------------------------------
// Custom camera controls: orbit, pan, and zoom without addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.65, 0.22);
let cameraYaw = 0.61;
let cameraPitch = 0.43;
let cameraRadius = 6.7;
let dragging = false;
let panning = false;
let previousPointerX = 0;
let previousPointerY = 0;
let activePointerId = null;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
dragging = true;
panning = event.shiftKey || event.button === 2;
activePointerId = event.pointerId;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
if (panning) {
const right = new THREE.Vector3(
Math.cos(cameraYaw),
0,
-Math.sin(cameraYaw)
);
const forward = new THREE.Vector3(
-Math.sin(cameraYaw),
0,
-Math.cos(cameraYaw)
);
const panScale = cameraRadius * 0.00115;
cameraTarget.addScaledVector(right, -dx * panScale);
cameraTarget.addScaledVector(forward, -dy * panScale);
cameraTarget.x = THREE.MathUtils.clamp(
cameraTarget.x,
-2.5,
2.5
);
cameraTarget.y = THREE.MathUtils.clamp(
cameraTarget.y,
0.2,
2.0
);
cameraTarget.z = THREE.MathUtils.clamp(
cameraTarget.z,
-2.0,
2.5
);
} else {
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.005,
0.08,
1.18
);
}
});
function endDrag(event) {
if (event.pointerId !== activePointerId) return;
dragging = false;
panning = false;
activePointerId = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
3.25,
10.5
);
},
{ passive: false }
);
function updateCamera() {
const horizontalRadius = Math.cos(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontalRadius,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontalRadius
);
camera.lookAt(cameraTarget);
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
elapsed = (elapsed + delta * playbackSpeed) % duration;
}
const progress = elapsed / duration;
poseAt(progress);
timeline.value = String(Math.round(progress * 1000));
timeLabel.textContent = `${elapsed.toFixed(1)}s`;
updateCamera();
renderer.render(scene, camera);
}
poseAt(0);
updateCamera();
animate();
</script>
</body>
</html>
```