Prompt specification
Build or customize the Three.js 3D scene "Courier Stops With a Swinging Satchel" 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: Courier Stops With a Swinging Satchel
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/courier-stops-with-a-swinging-satchel-x3691
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing anticipation and follow-through in character motion. Build a small original street scene where a courier walks then stops. Animate the satchel's delayed settling while preserving its strap attachment and avoiding body penetration. Voxel style.
Working Three.js Starter (courier-stops-with-a-swinging-satchel-x3691):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Parcel Pause — Anticipation & Follow-Through</title>
<style>
:root {
color-scheme: dark;
--ink: #10232a;
--panel: rgba(12, 29, 35, 0.86);
--line: rgba(255, 255, 255, 0.15);
--cream: #fff5dc;
--mint: #70e0c1;
--orange: #ffb35c;
--pink: #ff6687;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b8d8dd;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--cream);
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
max-width: 340px;
padding: 17px 19px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 16px 50px rgba(10, 30, 35, 0.18);
backdrop-filter: blur(14px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--mint);
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 32px);
line-height: 1;
letter-spacing: -0.04em;
}
.subtitle {
margin: 10px 0 0;
color: rgba(255, 245, 220, 0.72);
font-size: 13px;
line-height: 1.45;
}
.controls {
position: absolute;
top: 24px;
right: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(12, 29, 35, 0.86);
color: var(--cream);
font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
background 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(28, 55, 62, 0.95);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.timeline-card {
position: absolute;
left: 50%;
bottom: 24px;
width: min(760px, calc(100% - 32px));
padding: 15px 18px 14px;
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 16px 50px rgba(10, 30, 35, 0.2);
backdrop-filter: blur(14px);
}
.timeline-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-bottom: 11px;
}
.status {
display: flex;
align-items: center;
gap: 9px;
min-width: 0;
}
.status-dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 0 5px rgba(112, 224, 193, 0.12);
}
#phase {
overflow: hidden;
font: 800 12px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.09em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
#time {
flex: 0 0 auto;
color: rgba(255, 245, 220, 0.55);
font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.track {
position: relative;
height: 7px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.1);
}
#progress {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--mint), var(--orange), var(--pink));
}
.markers {
position: relative;
height: 18px;
margin-top: 5px;
color: rgba(255, 245, 220, 0.48);
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.marker {
position: absolute;
top: 3px;
}
.marker.anticipation {
left: 66%;
}
.marker.follow {
left: 85%;
color: var(--orange);
}
.camera-help {
position: absolute;
right: 24px;
bottom: 24px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(12, 29, 35, 0.68);
color: rgba(255, 245, 220, 0.7);
font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
backdrop-filter: blur(10px);
}
.technical-note {
position: absolute;
left: 24px;
bottom: 24px;
max-width: 270px;
color: rgba(16, 35, 42, 0.74);
font: 700 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
text-transform: uppercase;
text-shadow: 0 1px rgba(255, 255, 255, 0.3);
}
@media (max-width: 800px) {
.title-card {
top: 12px;
left: 12px;
max-width: calc(100% - 24px);
padding: 13px 15px;
}
.subtitle,
.technical-note,
.camera-help {
display: none;
}
.controls {
top: auto;
right: 12px;
bottom: 112px;
}
.timeline-card {
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Character Motion Study / 07</div>
<h1>Parcel Pause</h1>
<p class="subtitle">
Courier Nia brakes, compresses, and settles. The satchel follows
late, then rocks back into equilibrium without releasing its strap.
</p>
</section>
<div class="controls">
<button id="pause" type="button">PAUSE</button>
<button id="replay" type="button">REPLAY</button>
<button id="camera-reset" type="button">CAMERA</button>
</div>
<section class="timeline-card">
<div class="timeline-head">
<div class="status">
<span class="status-dot"></span>
<span id="phase">Walking</span>
</div>
<span id="time">0.0 / 12.5 SEC</span>
</div>
<div class="track">
<div id="progress"></div>
</div>
<div class="markers">
<span class="marker anticipation">Anticipation</span>
<span class="marker follow">Follow-through</span>
</div>
</section>
<div class="technical-note">
Rigid strap constraint<br>
Spring-damped satchel swing<br>
Outward collision clearance
</div>
<div class="camera-help">DRAG TO ORBIT · WHEEL TO ZOOM</div>
</div>
<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 camera
// ---------------------------------------------------------------------
const stage = document.querySelector("#stage");
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.08;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8d8dd);
scene.fog = new THREE.Fog(0xb8d8dd, 16, 34);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(0xe7fbff, 0x806a54, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2cf, 3.0);
sun.position.set(-4, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
scene.add(sun);
// ---------------------------------------------------------------------
// Small utilities and voxel construction helpers
// ---------------------------------------------------------------------
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.0,
...options
})
);
}
return materialCache.get(key);
}
function box(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
typeof color === "number" || typeof color === "string"
? material(color, options)
: color
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function smoothstep(min, max, value) {
const x = clamp((value - min) / (max - min), 0, 1);
return x * x * (3 - 2 * x);
}
function damp(current, target, lambda, dt) {
return THREE.MathUtils.lerp(
current,
target,
1 - Math.exp(-lambda * dt)
);
}
// ---------------------------------------------------------------------
// Voxel street
// ---------------------------------------------------------------------
const world = new THREE.Group();
scene.add(world);
// Sidewalk and road.
box(world, [32, 0.2, 4.2], [0, -0.1, -0.1], 0xd8d0bb);
box(world, [32, 0.16, 6.6], [0, -0.12, 4.0], 0x59686c);
for (let x = -15; x <= 15; x += 1) {
box(
world,
[0.035, 0.012, 3.95],
[x, 0.006, -0.1],
0xbdb6a5,
{ castShadow: false }
);
}
for (let x = -14; x < 16; x += 3.2) {
box(
world,
[1.6, 0.018, 0.11],
[x, -0.025, 4.0],
0xf4e9bf,
{ castShadow: false }
);
}
// Curb blocks.
for (let x = -15.5; x < 16; x += 1.1) {
box(
world,
[1.02, 0.25, 0.22],
[x, 0.02, 2.02],
0xe7dfc9
);
}
// Building row.
const buildingColors = [
0xe78d77,
0x73b6a6,
0xe7bf6d,
0x7899bd,
0xc48ca6,
0x91aa78
];
const buildingX = [-10.8, -6.7, -2.6, 1.5, 5.6, 9.7, 13.8];
const buildingHeights = [5.2, 6.4, 4.8, 7.1, 5.7, 6.5, 4.9];
buildingX.forEach((x, index) => {
const width = 3.45;
const height = buildingHeights[index];
const color = buildingColors[index % buildingColors.length];
box(
world,
[width, height, 2.8],
[x, height / 2, -3.65],
color
);
box(
world,
[width + 0.18, 0.24, 2.95],
[x, height + 0.06, -3.65],
0x40545a
);
// Front-facing door.
box(
world,
[0.78, 1.65, 0.08],
[x - 0.85, 0.83, -2.21],
0x344c54
);
// Windows.
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 2; column++) {
const wx = x + (column === 0 ? -0.48 : 0.72);
const wy = 2.15 + row * 1.35;
if (wy + 0.34 > height - 0.25) continue;
box(
world,
[0.62, 0.68, 0.055],
[wx, wy, -2.215],
row % 2 === 0 ? 0xcdebf0 : 0xffe8a7
);
box(
world,
[0.68, 0.08, 0.09],
[wx, wy, -2.18],
0xf7edda
);
}
}
// Small projecting signs.
if (index === 1 || index === 4) {
box(
world,
[1.0, 0.38, 0.12],
[x + 0.45, 1.75, -2.12],
index === 1 ? 0xffd46a : 0xff7d94
);
}
});
// Planters and block trees.
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
world.add(group);
box(group, [0.9, 0.38, 0.9], [0, 0.19, 0], 0x9d8065);
box(group, [0.32, 1.8, 0.32], [0, 1.1, 0], 0x72523b);
box(group, [1.45, 1.0, 1.2], [0, 2.35, 0], 0x4e8f65);
box(group, [1.0, 0.85, 1.0], [-0.42, 3.05, 0.05], 0x66aa72);
box(group, [0.9, 0.75, 0.9], [0.42, 3.12, -0.08], 0x3f805d);
}
addTree(-8.6, -1.55, 0.9);
addTree(-0.3, -1.55, 0.82);
addTree(7.8, -1.55, 0.95);
// Street lamps.
[-11.2, 3.1, 11.6].forEach((x) => {
box(world, [0.58, 0.15, 0.58], [x, 0.07, 1.35], 0x40545a);
box(world, [0.16, 3.7, 0.16], [x, 1.95, 1.35], 0x40545a);
box(world, [0.95, 0.14, 0.35], [x + 0.28, 3.82, 1.35], 0x40545a);
box(world, [0.65, 0.2, 0.38], [x + 0.56, 3.68, 1.35], 0xffedaf);
});
// Voxel clouds.
const cloud = new THREE.Group();
cloud.position.set(-3, 9.5, -10);
world.add(cloud);
box(cloud, [2.2, 0.65, 0.7], [0, 0, 0], 0xf3f5e9);
box(cloud, [1.0, 1.05, 0.7], [-0.7, 0.25, 0], 0xf3f5e9);
box(cloud, [1.15, 1.3, 0.7], [0.25, 0.35, 0], 0xf3f5e9);
box(cloud, [1.0, 0.8, 0.7], [1.0, 0.05, 0], 0xf3f5e9);
// ---------------------------------------------------------------------
// Courier rig
// ---------------------------------------------------------------------
const courier = new THREE.Group();
courier.position.y = 0.025;
scene.add(courier);
const upper = new THREE.Group();
courier.add(upper);
const skin = material(0xb96f4d);
const jacket = material(0x087f83);
const jacketDark = material(0x075b63);
const pants = material(0x293a52);
const shoe = material(0xf0ead8);
const cap = material(0xf29a45);
const capDark = material(0xc86535);
const reflective = material(0xd9f4cf, {
emissive: 0x315c4d,
emissiveIntensity: 0.12
});
// Hips, torso, neck, and head.
box(upper, [0.44, 0.23, 0.58], [0, 0.78, 0], pants);
box(upper, [0.51, 0.73, 0.66], [0, 1.17, 0], jacket);
box(upper, [0.53, 0.09, 0.68], [0, 1.31, 0], reflective);
box(upper, [0.05, 0.55, 0.05], [0.266, 1.15, 0.05], jacketDark);
box(upper, [0.22, 0.16, 0.23], [0, 1.61, 0], skin);
const head = new THREE.Group();
head.position.set(0, 1.86, 0);
upper.add(head);
box(head, [0.46, 0.50, 0.48], [0, 0, 0], skin);
box(head, [0.12, 0.12, 0.13], [0.27, -0.02, 0], skin);
box(head, [0.025, 0.065, 0.065], [0.255, 0.09, 0.13], 0x18232a);
box(head, [0.025, 0.065, 0.065], [0.255, 0.09, -0.13], 0x18232a);
box(head, [0.46, 0.16, 0.50], [0, 0.25, 0], cap);
box(head, [0.48, 0.07, 0.54], [0.16, 0.20, 0], capDark);
function createArm(z) {
const shoulder = new THREE.Group();
shoulder.position.set(0, 1.45, z);
upper.add(shoulder);
box(shoulder, [0.17, 0.34, 0.18], [0, -0.17, 0], jacket);
const elbow = new THREE.Group();
elbow.position.set(0, -0.32, 0);
shoulder.add(elbow);
box(elbow, [0.16, 0.31, 0.17], [0, -0.155, 0], jacketDark);
box(elbow, [0.18, 0.18, 0.18], [0, -0.37, 0], skin);
return { shoulder, elbow };
}
const nearArm = createArm(0.36);
const farArm = createArm(-0.36);
function createLeg(z) {
const hip = new THREE.Group();
hip.position.set(0, 0.78, z);
courier.add(hip);
box(hip, [0.22, 0.37, 0.24], [0, -0.185, 0], pants);
const knee = new THREE.Group();
knee.position.set(0, -0.35, 0);
hip.add(knee);
box(knee, [0.20, 0.36, 0.22], [0, -0.18, 0], pants);
box(knee, [0.39, 0.15, 0.27], [0.055, -0.40, 0], shoe);
box(knee, [0.12, 0.08, 0.28], [0.055, -0.455, 0], 0x34444a);
return { hip, knee };
}
const nearLeg = createLeg(0.16);
const farLeg = createLeg(-0.16);
// ---------------------------------------------------------------------
// Satchel and rigid visual strap
// ---------------------------------------------------------------------
const satchel = new THREE.Group();
scene.add(satchel);
const bagColor = material(0xe85d78);
const bagDark = material(0xa83e5b);
const buckle = material(0xffc85c, {
metalness: 0.18,
roughness: 0.48
});
// The satchel group origin is its strap lug.
box(satchel, [0.49, 0.41, 0.35], [0, -0.245, 0], bagColor);
box(satchel, [0.51, 0.16, 0.37], [0, -0.12, 0], bagDark);
box(satchel, [0.45, 0.29, 0.025], [0, -0.29, 0.19], bagColor);
box(satchel, [0.12, 0.12, 0.075], [0, -0.13, 0.205], buckle);
box(satchel, [0.11, 0.11, 0.10], [0, 0, 0], buckle);
// A single rectangular strap is repositioned every frame.
// Its two endpoints exactly coincide with the shoulder anchor and bag lug.
const strap = new THREE.Mesh(
new THREE.BoxGeometry(0.085, 1, 0.055),
material(0x34313b)
);
strap.castShadow = true;
scene.add(strap);
const shoulderPad = box(
upper,
[0.17, 0.12, 0.10],
[-0.08, 1.50, 0.34],
0x30313a
);
const anchorLocal = new THREE.Vector3(-0.08, 1.50, 0.34);
const anchorWorld = new THREE.Vector3();
const bagPivot = new THREE.Vector3();
const strapDirection = new THREE.Vector3();
const strapMidpoint = new THREE.Vector3();
const localY = new THREE.Vector3(0, 1, 0);
const STRAP_LENGTH = 0.73;
// ---------------------------------------------------------------------
// Motion path: walk, decelerate, and stop
// ---------------------------------------------------------------------
const START_X = -2.4;
const WALK_SPEED = 1.18;
const WALK_END = 5.6;
const STOP_TIME = 7.2;
const DECEL_DURATION = STOP_TIME - WALK_END;
function pathAt(time) {
if (time <= 0.8) {
return {
x: START_X,
velocity: 0,
acceleration: 0
};
}
if (time < WALK_END) {
return {
x: START_X + WALK_SPEED * (time - 0.8),
velocity: WALK_SPEED,
acceleration: 0
};
}
if (time < STOP_TIME) {
const u = (time - WALK_END) / DECEL_DURATION;
const xAtBrake =
START_X + WALK_SPEED * (WALK_END - 0.8);
// Cosine-integrated easing:
// position is continuous and velocity reaches zero at the stop.
const x =
xAtBrake +
WALK_SPEED *
DECEL_DURATION *
(u - Math.sin(Math.PI * 2 * u) / (Math.PI * 2));
const velocity =
WALK_SPEED * (1 - Math.cos(Math.PI * 2 * u));
const acceleration =
(WALK_SPEED * Math.PI * 2 / DECEL_DURATION) *
Math.sin(Math.PI * 2 * u);
return { x, velocity, acceleration };
}
const xAtStop =
START_X +
WALK_SPEED * (WALK_END - 0.8) +
WALK_SPEED * DECEL_DURATION * 0.5;
return {
x: xAtStop,
velocity: 0,
acceleration: 0
};
}
// ---------------------------------------------------------------------
// Satchel spring dynamics
// ---------------------------------------------------------------------
let simTime = 0;
let playing = true;
let stopImpulseApplied = false;
let theta = 0;
let thetaVelocity = 0;
let phi = 1.10;
let phiVelocity = 0;
function resetSimulation() {
simTime = 0;
theta = 0;
thetaVelocity = 0;
phi = 1.10;
phiVelocity = 0;
stopImpulseApplied = false;
playing = true;
pauseButton.textContent = "PAUSE";
}
function updateSatchel(dt, path) {
const walkBlend = clamp(path.velocity / WALK_SPEED, 0, 1);
const phase = (path.x - START_X) * Math.PI * 2 / 0.82;
// Acceleration creates angular lag. When the target changes back to
// zero, the spring naturally produces the visible follow-through.
const targetTheta = clamp(
-path.acceleration * 0.10 +
Math.sin(phase) * 0.035 * walkBlend,
-0.34,
0.34
);
const targetPhi = 1.10 + Math.sin(phase * 0.5) * 0.025 * walkBlend;
// Under-damped angular springs: the bag rocks rather than snapping.
const thetaAcceleration =
38 * (targetTheta - theta) - 6.2 * thetaVelocity;
const phiAcceleration =
46 * (targetPhi - phi) - 9.0 * phiVelocity;
thetaVelocity += thetaAcceleration * dt;
phiVelocity += phiAcceleration * dt;
theta += thetaVelocity * dt;
phi += phiVelocity * dt;
// Keep the bag well outside the torso's collision volume.
// The minimum z separation is over 0.3 world units.
phi = clamp(phi, 1.03, 1.20);
if (!stopImpulseApplied && simTime >= STOP_TIME) {
// A small continuation impulse represents the satchel carrying
// momentum through the final instant of the body's stop.
thetaVelocity += 0.22;
phiVelocity += 0.025;
stopImpulseApplied = true;
}
// Get the moving shoulder attachment in world space.
upper.updateWorldMatrix(true, false);
anchorWorld.copy(anchorLocal);
upper.localToWorld(anchorWorld);
// Spherical constraint around the shoulder:
// |bagPivot - anchorWorld| is always exactly STRAP_LENGTH.
const cosPhi = Math.cos(phi);
const sinPhi = Math.sin(phi);
bagPivot.set(
anchorWorld.x + STRAP_LENGTH * Math.sin(theta) * cosPhi,
anchorWorld.y - STRAP_LENGTH * Math.cos(theta) * cosPhi,
anchorWorld.z + STRAP_LENGTH * sinPhi
);
satchel.position.copy(bagPivot);
satchel.rotation.z = theta * 0.9;
// Update the rigid strap between its exact attachment points.
strapDirection.subVectors(bagPivot, anchorWorld);
const actualLength = strapDirection.length();
strapDirection.normalize();
strapMidpoint.copy(anchorWorld).add(bagPivot).multiplyScalar(0.5);
strap.position.copy(strapMidpoint);
strap.quaternion.setFromUnitVectors(localY, strapDirection);
strap.scale.set(1, actualLength, 1);
}
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
const totalDuration = 12.5;
const phaseLabel = document.querySelector("#phase");
const timeLabel = document.querySelector("#time");
const progressBar = document.querySelector("#progress");
const pauseButton = document.querySelector("#pause");
const replayButton = document.querySelector("#replay");
const cameraResetButton = document.querySelector("#camera-reset");
function updateCourier(path) {
courier.position.x = path.x;
const walkBlend = clamp(path.velocity / WALK_SPEED, 0, 1);
const phase = (path.x - START_X) * Math.PI * 2 / 0.82;
// Anticipation: the center of mass lowers before the stop completes.
const anticipation =
smoothstep(5.35, 5.85, simTime) *
(1 - smoothstep(6.2, 7.35, simTime));
const bob =
Math.abs(Math.sin(phase)) *
0.035 *
walkBlend;
const breathing =
simTime > STOP_TIME
? Math.sin((simTime - STOP_TIME) * 2.1) * 0.006
: 0;
upper.position.y = bob - anticipation * 0.075 + breathing;
upper.rotation.z =
-anticipation * 0.052 -
walkBlend * Math.cos(phase) * 0.014;
head.rotation.z = -upper.rotation.z * 0.45;
// Walking gait blends into a stable, offset standing pose.
const nearLegTarget = 0.46 * Math.sin(phase);
const farLegTarget = -0.46 * Math.sin(phase);
nearLeg.hip.rotation.z = THREE.MathUtils.lerp(
0.13,
nearLegTarget,
walkBlend
);
farLeg.hip.rotation.z = THREE.MathUtils.lerp(
-0.18,
farLegTarget,
walkBlend
);
nearLeg.knee.rotation.z =
0.06 +
Math.max(0, -Math.sin(phase)) * 0.36 * walkBlend;
farLeg.knee.rotation.z =
0.06 +
Math.max(0, Math.sin(phase)) * 0.36 * walkBlend;
const nearArmTarget = -0.43 * Math.sin(phase);
const farArmTarget = 0.43 * Math.sin(phase);
nearArm.shoulder.rotation.z = THREE.MathUtils.lerp(
-0.07,
nearArmTarget,
walkBlend
);
farArm.shoulder.rotation.z = THREE.MathUtils.lerp(
0.07,
farArmTarget,
walkBlend
);
nearArm.elbow.rotation.z = -0.12 - walkBlend * 0.10;
farArm.elbow.rotation.z = -0.12 - walkBlend * 0.10;
// The shoulder pad follows the upper body exactly.
shoulderPad.position.copy(anchorLocal);
shoulderPad.position.x += 0.04;
}
function updateHUD() {
progressBar.style.width = `${(simTime / totalDuration) * 100}%`;
timeLabel.textContent = `${simTime.toFixed(1)} / ${totalDuration.toFixed(1)} SEC`;
let label = "Walking";
if (simTime < 5.35) {
label = "Walking · steady gait";
} else if (simTime < 6.15) {
label = "Anticipation · lowering center";
} else if (simTime < STOP_TIME) {
label = "Braking · weight transfer";
} else if (simTime < 10.2) {
label = "Follow-through · satchel settling";
} else {
label = "Settled · strap attached";
}
phaseLabel.textContent = label;
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.033);
if (playing) {
simTime = Math.min(totalDuration, simTime + dt);
const path = pathAt(simTime);
updateCourier(path);
updateSatchel(dt, path);
updateHUD();
}
updateCamera();
renderer.render(scene, camera);
}
// ---------------------------------------------------------------------
// Direct camera controls: orbit, pan, and zoom without add-ons
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(1.2, 1.0, 0),
radius: 15.6,
theta: 0.57,
phi: 1.16
};
const cameraDefault = {
target: new THREE.Vector3(1.2, 1.0, 0),
radius: 15.6,
theta: 0.57,
phi: 1.16
};
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
cameraState.theta -= dx * 0.005;
cameraState.phi = clamp(cameraState.phi - dy * 0.004, 0.32, 1.48);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
});
function endDrag(event) {
dragging = false;
if (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.radius = clamp(
cameraState.radius + event.deltaY * 0.012,
5.5,
27
);
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
function updateCamera() {
const offset = new THREE.Vector3().setFromSphericalCoords(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
}
cameraResetButton.addEventListener("click", () => {
cameraState.target.copy(cameraDefault.target);
cameraState.radius = cameraDefault.radius;
cameraState.theta = cameraDefault.theta;
cameraState.phi = cameraDefault.phi;
});
pauseButton.addEventListener("click", () => {
playing = !playing;
pauseButton.textContent = playing ? "PAUSE" : "RESUME";
});
replayButton.addEventListener("click", resetSimulation);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// Initialize the pose before the first frame.
const initialPath = pathAt(0);
updateCourier(initialPath);
updateSatchel(1 / 60, initialPath);
updateCamera();
animate();
</script>
</body>
</html>
```