Prompt specification
Build or customize the Three.js 3D scene "Getting-ready entryway scene" 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: Getting-ready entryway scene
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/getting-ready-entryway-scene-x0623
Scene Description Prompt:
A stylized character sits on an entryway bench, tightens shoelaces, stands, then picks up a bag. Create standalone HTML using Three.js from cdnjs.
Working Three.js Starter (getting-ready-entryway-scene-x0623):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ready to Go — Three.js Character</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee7dc;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 22px;
left: 22px;
z-index: 10;
max-width: min(340px, calc(100vw - 44px));
padding: 15px 18px 14px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 18px;
background: rgba(255, 250, 242, 0.78);
box-shadow: 0 14px 36px rgba(69, 51, 35, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 4px;
color: #a36b45;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #41352d;
font-size: clamp(22px, 3vw, 30px);
line-height: 1.05;
letter-spacing: -0.04em;
}
#status {
margin: 8px 0 0;
color: #77685e;
font-size: 13px;
}
.progress-track {
height: 4px;
margin-top: 13px;
overflow: hidden;
border-radius: 999px;
background: rgba(95, 73, 54, 0.12);
}
#progress {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #dc9062, #e6b66f);
transition: width 80ms linear;
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 10;
display: flex;
align-items: center;
gap: 12px;
}
.hint {
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 999px;
background: rgba(255, 250, 242, 0.72);
color: #75665c;
box-shadow: 0 10px 24px rgba(69, 51, 35, 0.09);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
font-size: 11px;
pointer-events: none;
}
#replay {
border: 0;
border-radius: 999px;
padding: 12px 17px;
background: #493b32;
box-shadow: 0 10px 22px rgba(69, 51, 35, 0.2);
color: #fffaf3;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
#replay:hover {
transform: translateY(-2px);
background: #5a493d;
}
#replay:active {
transform: translateY(0);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #eee7dc;
color: #69584c;
font-size: 14px;
transition: opacity 300ms ease;
pointer-events: none;
}
#loading.hidden {
opacity: 0;
}
@media (max-width: 620px) {
.title-card {
top: 14px;
left: 14px;
}
.controls {
right: 14px;
bottom: 14px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<section class="title-card">
<div class="eyebrow">An entryway moment</div>
<h1>Ready to Go</h1>
<p id="status">Getting settled...</p>
<div class="progress-track"><div id="progress"></div></div>
</section>
<div class="controls">
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<button id="replay" type="button">Replay</button>
</div>
<div id="loading">Building the scene…</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 stage = document.querySelector("#stage");
const statusEl = document.querySelector("#status");
const progressEl = document.querySelector("#progress");
const replayButton = document.querySelector("#replay");
const loadingEl = document.querySelector("#loading");
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.12;
renderer.domElement.setAttribute("aria-label", "Interactive 3D entryway scene");
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee7dc);
scene.fog = new THREE.Fog(0xeee7dc, 9, 16);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
50
);
const cameraTarget = new THREE.Vector3(0, 1.25, 0.1);
let cameraYaw = 0.19;
let cameraPitch = 0.23;
let cameraRadius = 6.65;
function updateCamera() {
const horizontal = Math.cos(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting and materials
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff5e8, 0x8b9b9c, 2.25));
const sun = new THREE.DirectionalLight(0xffe1b9, 3.7);
sun.position.set(4.5, 7.5, 5.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -5;
sun.shadow.camera.right = 5;
sun.shadow.camera.top = 6;
sun.shadow.camera.bottom = -3;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 18;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbad8ee, 1.15);
fill.position.set(-4, 3.5, 2);
scene.add(fill);
const materials = {
wall: new THREE.MeshStandardMaterial({ color: 0xf0e7da, roughness: 0.94 }),
wallSide: new THREE.MeshStandardMaterial({ color: 0xe8ddcf, roughness: 0.96 }),
floor: new THREE.MeshStandardMaterial({ color: 0xd7c3a7, roughness: 0.88 }),
rug: new THREE.MeshStandardMaterial({ color: 0x9eb4aa, roughness: 1 }),
rugBorder: new THREE.MeshStandardMaterial({ color: 0x78978d, roughness: 1 }),
wood: new THREE.MeshStandardMaterial({ color: 0xa86f45, roughness: 0.72 }),
woodDark: new THREE.MeshStandardMaterial({ color: 0x76503a, roughness: 0.8 }),
door: new THREE.MeshStandardMaterial({ color: 0x68898a, roughness: 0.8 }),
doorFrame: new THREE.MeshStandardMaterial({ color: 0xf6eee3, roughness: 0.88 }),
brass: new THREE.MeshStandardMaterial({
color: 0xd7a84d,
metalness: 0.7,
roughness: 0.3
}),
shirt: new THREE.MeshStandardMaterial({ color: 0xdd7658, roughness: 0.86 }),
shirtDark: new THREE.MeshStandardMaterial({ color: 0xb95741, roughness: 0.9 }),
pants: new THREE.MeshStandardMaterial({ color: 0x384f67, roughness: 0.9 }),
shoe: new THREE.MeshStandardMaterial({ color: 0xf1c36d, roughness: 0.76 }),
sole: new THREE.MeshStandardMaterial({ color: 0x4d413b, roughness: 0.92 }),
lace: new THREE.MeshStandardMaterial({ color: 0xfff9e9, roughness: 0.95 }),
skin: new THREE.MeshStandardMaterial({ color: 0xe6a57e, roughness: 0.83 }),
hair: new THREE.MeshStandardMaterial({ color: 0x3c2c29, roughness: 0.95 }),
eye: new THREE.MeshStandardMaterial({ color: 0x241c1b, roughness: 0.6 }),
bag: new THREE.MeshStandardMaterial({ color: 0xd99b4e, roughness: 0.9 }),
bagDark: new THREE.MeshStandardMaterial({ color: 0x9a6538, roughness: 0.95 }),
pot: new THREE.MeshStandardMaterial({ color: 0xc9795f, roughness: 0.88 }),
leaf: new THREE.MeshStandardMaterial({ color: 0x4f8063, roughness: 0.92 }),
leafLight: new THREE.MeshStandardMaterial({ color: 0x72a67a, roughness: 0.92 }),
black: new THREE.MeshStandardMaterial({ color: 0x252525, roughness: 0.72 })
};
function addMesh(geometry, material, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(w, h, d, material, parent = scene, x = 0, y = 0, z = 0) {
const mesh = addMesh(new THREE.BoxGeometry(w, h, d), material, parent);
mesh.position.set(x, y, z);
return mesh;
}
function sphere(radius, material, parent = scene, x = 0, y = 0, z = 0) {
const mesh = addMesh(new THREE.SphereGeometry(radius, 24, 16), material, parent);
mesh.position.set(x, y, z);
return mesh;
}
// -------------------------------------------------------------------------
// Entryway room
// -------------------------------------------------------------------------
const floor = addMesh(new THREE.PlaneGeometry(14, 11), materials.floor);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
floor.castShadow = false;
box(7.5, 4.6, 0.14, materials.wall, scene, 0, 2.3, -2.35);
box(0.14, 4.6, 7.2, materials.wallSide, scene, -3.65, 2.3, 0.9);
box(7.5, 0.13, 0.08, materials.doorFrame, scene, 0, 0.065, -2.25);
box(0.08, 0.13, 7, materials.doorFrame, scene, -3.53, 0.065, 0.8);
// Door and frame.
box(1.52, 2.88, 0.13, materials.doorFrame, scene, -1.25, 1.44, -2.23);
box(1.32, 2.72, 0.11, materials.door, scene, -1.25, 1.36, -2.13);
box(0.84, 0.94, 0.035, materials.doorDark, scene, -1.25, 1.8, -2.055);
box(0.84, 0.84, 0.036, materials.door, scene, -1.25, 1.78, -2.03);
sphere(0.055, materials.brass, scene, -0.76, 1.23, -2.0);
// Small wall hooks and a hanging tote.
box(1.18, 0.12, 0.08, materials.woodDark, scene, 1.48, 2.08, -2.23);
for (const x of [1.18, 1.48, 1.78]) {
const hook = addMesh(
new THREE.TorusGeometry(0.065, 0.017, 8, 18, Math.PI * 1.45),
materials.brass
);
hook.position.set(x, 2.0, -2.16);
hook.rotation.z = Math.PI * 0.5;
}
box(0.42, 0.54, 0.12, materials.bagDark, scene, 1.78, 1.67, -2.11);
box(0.28, 0.12, 0.13, materials.bag, scene, 1.78, 1.97, -2.11);
// Rug.
const rug = box(4.25, 0.025, 2.22, materials.rug, scene, 0.18, 0.014, 0.38);
rug.castShadow = false;
box(3.94, 0.029, 1.93, materials.rugBorder, scene, 0.18, 0.017, 0.38);
// Bench.
const bench = new THREE.Group();
scene.add(bench);
for (const z of [-0.69, -0.49, -0.29]) {
box(2.85, 0.14, 0.17, materials.wood, bench, 0, 0.65, z);
}
box(2.75, 0.12, 0.12, materials.woodDark, bench, 0, 0.48, -0.42);
box(2.78, 0.16, 0.12, materials.wood, bench, 0, 1.25, -0.82);
box(2.78, 0.13, 0.12, materials.wood, bench, 0, 1.60, -0.82);
for (const x of [-1.08, 1.08]) {
box(0.13, 0.62, 0.13, materials.woodDark, bench, x, 0.31, -0.49);
box(0.11, 1.72, 0.12, materials.woodDark, bench, x, 0.86, -0.82);
}
// Plant.
const plant = new THREE.Group();
plant.position.set(-2.45, 0, -1.52);
scene.add(plant);
addMesh(new THREE.CylinderGeometry(0.34, 0.26, 0.48, 24), materials.pot, plant)
.position.y = 0.24;
const stem = addMesh(new THREE.CylinderGeometry(0.025, 0.035, 1.25, 10), materials.leaf, plant);
stem.position.y = 1.0;
const leafData = [
[-0.22, 0.75, 0.02, -0.7, 0.2],
[0.22, 0.92, 0.03, 0.7, -0.15],
[-0.25, 1.17, 0.02, -0.5, -0.1],
[0.24, 1.35, 0.0, 0.45, 0.2],
[0.02, 1.57, 0.0, 0.0, 0.05]
];
for (const [x, y, z, rz, ry] of leafData) {
const leaf = sphere(0.28, materials.leafLight, plant, x, y, z);
leaf.scale.set(0.48, 1.45, 0.22);
leaf.rotation.set(0.15, ry, rz);
}
// -------------------------------------------------------------------------
// Character rig
// -------------------------------------------------------------------------
const character = new THREE.Group();
character.position.z = 0.03;
scene.add(character);
const pelvis = new THREE.Group();
pelvis.position.y = 0.90;
character.add(pelvis);
const hips = sphere(0.25, materials.pants, pelvis, 0, -0.04, 0);
hips.scale.set(1.18, 0.62, 0.86);
const torso = new THREE.Group();
torso.position.set(0, 0.04, 0);
pelvis.add(torso);
const shirt = addMesh(
new THREE.CylinderGeometry(0.31, 0.25, 0.70, 28),
materials.shirt,
torso
);
shirt.position.y = 0.41;
shirt.scale.z = 0.78;
const collar = addMesh(
new THREE.TorusGeometry(0.14, 0.045, 10, 28),
materials.shirtDark,
torso
);
collar.position.y = 0.78;
collar.rotation.x = Math.PI / 2;
box(0.025, 0.53, 0.018, materials.shirtDark, torso, 0, 0.39, 0.247);
const neck = addMesh(
new THREE.CylinderGeometry(0.09, 0.105, 0.17, 18),
materials.skin,
torso
);
neck.position.y = 0.82;
// Head and face.
const head = new THREE.Group();
head.position.y = 1.08;
torso.add(head);
const face = sphere(0.27, materials.skin, head);
face.scale.set(0.95, 1.05, 0.96);
const hair = addMesh(
new THREE.SphereGeometry(0.285, 28, 16, 0, Math.PI * 2, 0, Math.PI * 0.54),
materials.hair,
head
);
hair.position.set(0, 0.045, -0.008);
hair.scale.z = 0.98;
const fringe = sphere(0.245, materials.hair, head, 0, 0.12, 0.09);
fringe.scale.set(1.0, 0.35, 0.52);
fringe.rotation.x = -0.18;
const leftEye = sphere(0.024, materials.eye, head, -0.087, 0.025, 0.252);
const rightEye = sphere(0.024, materials.eye, head, 0.087, 0.025, 0.252);
sphere(0.034, materials.skin, head, 0, -0.018, 0.272).scale.set(0.7, 0.8, 1.1);
const smile = addMesh(
new THREE.TorusGeometry(0.059, 0.008, 8, 24, Math.PI),
materials.hair,
head
);
smile.position.set(0, -0.073, 0.258);
smile.rotation.z = Math.PI;
sphere(0.062, materials.skin, head, -0.263, 0.005, 0).scale.set(0.55, 1, 0.8);
sphere(0.062, materials.skin, head, 0.263, 0.005, 0).scale.set(0.55, 1, 0.8);
// Arms are solved with a small two-bone IK system.
const upperArmGeometry = new THREE.CylinderGeometry(0.105, 0.09, 1, 16);
const lowerArmGeometry = new THREE.CylinderGeometry(0.082, 0.07, 1, 16);
const down = new THREE.Vector3(0, -1, 0);
function createArm(side) {
const shoulder = new THREE.Vector3(side * 0.34, 0.74, 0);
const upper = addMesh(upperArmGeometry, materials.shirt, torso);
const lower = addMesh(lowerArmGeometry, materials.skin, torso);
const elbow = sphere(0.094, materials.shirtDark, torso);
const hand = sphere(0.095, materials.skin, torso);
const shoulderCap = sphere(0.13, materials.shirt, torso);
shoulderCap.position.copy(shoulder);
return {
side,
shoulder,
upper,
lower,
elbow,
hand,
upperLength: 0.64,
lowerLength: 0.63
};
}
const leftArm = createArm(-1);
const rightArm = createArm(1);
function setSegment(mesh, start, end) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = Math.max(direction.length(), 0.0001);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(down, direction.normalize());
mesh.scale.set(1, length, 1);
}
function solveArm(arm, target, bendDirection) {
const start = arm.shoulder;
const delta = new THREE.Vector3().subVectors(target, start);
const maximum = arm.upperLength + arm.lowerLength;
let distance = delta.length();
if (distance < 0.0001) {
delta.set(0, -1, 0);
distance = 1;
}
const direction = delta.clone().normalize();
if (distance > maximum) {
target.copy(start).addScaledVector(direction, maximum);
distance = maximum;
}
const along = (
arm.upperLength * arm.upperLength -
arm.lowerLength * arm.lowerLength +
distance * distance
) / (2 * distance);
const height = Math.sqrt(
Math.max(0, arm.upperLength * arm.upperLength - along * along)
);
const bend = bendDirection.clone();
bend.addScaledVector(direction, -bend.dot(direction));
if (bend.lengthSq() < 0.0001) {
bend.set(arm.side, 0, 0);
bend.addScaledVector(direction, -bend.dot(direction));
}
bend.normalize();
const elbow = start.clone()
.addScaledVector(direction, along)
.addScaledVector(bend, height);
setSegment(arm.upper, start, elbow);
setSegment(arm.lower, elbow, target);
arm.elbow.position.copy(elbow);
arm.hand.position.copy(target);
}
// Legs.
const thighLength = 0.56;
const shinLength = 0.68;
function createLeg(side) {
const upperPivot = new THREE.Group();
upperPivot.position.set(side * 0.16, -0.04, 0);
pelvis.add(upperPivot);
const thigh = addMesh(
new THREE.CylinderGeometry(0.145, 0.12, thighLength, 18),
materials.pants,
upperPivot
);
thigh.position.y = -thighLength / 2;
const lowerPivot = new THREE.Group();
lowerPivot.position.y = -thighLength;
upperPivot.add(lowerPivot);
const shin = addMesh(
new THREE.CylinderGeometry(0.12, 0.09, shinLength, 18),
materials.pants,
lowerPivot
);
shin.position.y = -shinLength / 2;
const shoe = new THREE.Group();
shoe.position.y = -shinLength;
lowerPivot.add(shoe);
box(0.29, 0.06, 0.47, materials.sole, shoe, 0, -0.085, 0.09);
const shoeUpper = sphere(0.17, materials.shoe, shoe, 0, -0.025, 0.075);
shoeUpper.scale.set(0.86, 0.61, 1.4);
const heel = sphere(0.12, materials.shoe, shoe, 0, -0.015, -0.105);
heel.scale.set(0.95, 0.9, 0.8);
for (const z of [0.04, 0.115, 0.19]) {
const lace = addMesh(
new THREE.CylinderGeometry(0.009, 0.009, 0.18, 8),
materials.lace,
shoe
);
lace.rotation.z = Math.PI / 2;
lace.position.set(0, 0.072, z);
}
const laceAnchor = new THREE.Object3D();
laceAnchor.position.set(0, 0.095, 0.115);
shoe.add(laceAnchor);
return { upperPivot, lowerPivot, shoe, laceAnchor };
}
const leftLeg = createLeg(-1);
const rightLeg = createLeg(1);
// -------------------------------------------------------------------------
// Bag
// -------------------------------------------------------------------------
const bag = new THREE.Group();
scene.add(bag);
const bagBody = box(0.57, 0.44, 0.28, materials.bag, bag, 0, -0.29, 0);
bagBody.geometry = new THREE.BoxGeometry(0.57, 0.44, 0.28);
const bagPocket = box(0.32, 0.20, 0.025, materials.bagDark, bag, 0, -0.30, 0.154);
const handle = addMesh(
new THREE.TorusGeometry(0.13, 0.022, 10, 32, Math.PI),
materials.bagDark,
bag
);
handle.position.y = -0.13;
const handleBack = handle.clone();
handleBack.position.z = -0.065;
bag.add(handleBack);
for (const x of [-0.21, 0.21]) {
box(0.045, 0.36, 0.30, materials.bagDark, bag, x, -0.28, 0);
}
box(0.13, 0.065, 0.02, materials.lace, bag, 0, -0.23, 0.175);
const bagStart = new THREE.Vector3(0.82, 0.58, 0.42);
bag.position.copy(bagStart);
// -------------------------------------------------------------------------
// Animation helpers
// -------------------------------------------------------------------------
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smooth(a, b, value) {
const x = clamp((value - a) / (b - a), 0, 1);
return x * x * (3 - 2 * x);
}
const tempA = new THREE.Vector3();
const tempB = new THREE.Vector3();
const tempC = new THREE.Vector3();
let startTime = performance.now();
const duration = 9.4;
function getStatus(t) {
if (t < 0.75) return "Settling onto the bench";
if (t < 3.55) return "Tightening the shoelaces";
if (t < 5.15) return "Pushing up and standing";
if (t < 6.55) return "Reaching for the bag";
if (t < 8.15) return "Picking the bag up";
return "Ready for the day";
}
function animate(now) {
requestAnimationFrame(animate);
const t = (now - startTime) / 1000;
const breathing = Math.sin(t * 2.2) * 0.006;
// Main body poses.
const stand = smooth(4.0, 5.15, t);
const lift = smooth(6.55, 8.15, t);
const crouch = smooth(5.15, 6.05, t) * (1 - lift);
const laceLean =
smooth(0.65, 1.55, t) *
(1 - smooth(3.4, 4.0, t));
pelvis.position.set(
0.12 * crouch,
lerp(0.90, 1.43, stand) - 0.52 * crouch,
0.06 * crouch
);
torso.position.set(
0,
0.04 + breathing,
0.08 * laceLean
);
torso.rotation.x =
0.93 * laceLean +
0.22 * crouch * (1 - lift) +
0.04 * lift;
torso.rotation.z =
-0.04 * laceLean +
-0.18 * crouch * (1 - lift) +
-0.05 * lift;
// Arms and legs unfold when standing.
leftLeg.upperPivot.rotation.x =
-Math.PI * 0.5 * (1 - stand) -
1.0 * crouch;
rightLeg.upperPivot.rotation.x =
-Math.PI * 0.5 * (1 - stand) -
1.0 * crouch;
leftLeg.lowerPivot.rotation.x =
Math.PI * 0.5 * (1 - stand) +
1.7 * crouch;
rightLeg.lowerPivot.rotation.x =
Math.PI * 0.5 * (1 - stand) +
1.7 * crouch;
// Tiny head motion adds life without distracting from the action.
head.rotation.x = 0.04 * Math.sin(t * 1.6) + 0.04 * laceLean;
head.rotation.y = 0.025 * Math.sin(t * 0.75);
// Blink every few seconds.
const blinkCycle = (t + 1.6) % 4.3;
const blink = blinkCycle < 0.12
? Math.max(0.08, Math.abs(blinkCycle - 0.06) / 0.06)
: 1;
leftEye.scale.y = blink;
rightEye.scale.y = blink;
scene.updateMatrixWorld(true);
// Natural arm positions are defined relative to the torso.
const leftSideWorld = torso.localToWorld(
new THREE.Vector3(-0.42, 0.22, 0.035)
);
const rightSideWorld = torso.localToWorld(
new THREE.Vector3(0.42, 0.22, 0.035)
);
// Lacing targets.
leftLeg.laceAnchor.getWorldPosition(tempA);
rightLeg.laceAnchor.getWorldPosition(tempB);
const pullCycle = t * 3.0;
const leftPull = Math.max(0, Math.sin(pullCycle));
const rightPull = Math.max(0, Math.sin(pullCycle + Math.PI));
tempA.y += leftPull * 0.10;
tempA.z -= leftPull * 0.035;
tempA.x += (1 - leftPull) * 0.025;
tempB.y += rightPull * 0.10;
tempB.z -= rightPull * 0.035;
tempB.x -= (1 - rightPull) * 0.025;
const prep = smooth(0.65, 1.55, t);
const release = smooth(3.4, 4.05, t);
const leftTargetWorld = tempC.copy(leftSideWorld).lerp(tempA, prep);
leftTargetWorld.lerp(leftSideWorld, release);
const reach = smooth(5.15, 6.05, t);
const rightTargetWorld = rightSideWorld.clone().lerp(bagStart, reach);
// After grabbing, lift the hand and carry the bag close to the body.
const finalHandLocal = new THREE.Vector3(0.53, 0.14, 0.32);
const finalHandWorld = torso.localToWorld(finalHandLocal.clone());
rightTargetWorld.lerp(finalHandWorld, lift);
const leftTargetLocal = torso.worldToLocal(leftTargetWorld.clone());
const rightTargetLocal = torso.worldToLocal(rightTargetWorld.clone());
solveArm(
leftArm,
leftTargetLocal,
new THREE.Vector3(-1, -0.1, -0.55)
);
solveArm(
rightArm,
rightTargetLocal,
new THREE.Vector3(1, -0.1, -0.55)
);
scene.updateMatrixWorld(true);
// Once grasped, the bag follows the right hand.
if (t >= 6.55) {
rightArm.hand.getWorldPosition(bag.position);
bag.rotation.z = -0.07 * lift;
bag.rotation.x = 0.04 * lift;
} else {
bag.position.copy(bagStart);
bag.rotation.set(0, 0, 0);
}
progressEl.style.width = `${Math.min(100, (t / duration) * 100)}%`;
statusEl.textContent = getStatus(t);
renderer.render(scene, camera);
}
// -------------------------------------------------------------------------
// Custom camera controls: drag/orbit, wheel/zoom, double-click reset
// -------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
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;
cameraYaw -= dx * 0.006;
cameraPitch = clamp(cameraPitch + dy * 0.0045, 0.05, 0.78);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
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();
cameraRadius = clamp(
cameraRadius + event.deltaY * 0.005,
4.25,
10
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraYaw = 0.19;
cameraPitch = 0.23;
cameraRadius = 6.65;
updateCamera();
});
replayButton.addEventListener("click", () => {
startTime = performance.now();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
startTime = performance.now();
}
});
requestAnimationFrame(animate);
requestAnimationFrame(() => {
loadingEl.classList.add("hidden");
setTimeout(() => loadingEl.remove(), 350);
});
</script>
</body>
</html>
```