Prompt specification
Build or customize the Three.js 3D scene "Two Actors Exchange a Prop" 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: Two Actors Exchange a Prop
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-actors-exchange-a-prop-x3354
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring theater staging, props, and audience sightlines. Animate two original stylized characters passing a box during a short scene. Maintain hand contact, readable anticipation, and a clear transfer of possession. Stylized solid forms.
Working Three.js Starter (two-actors-exchange-a-prop-x3354):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Handoff — Three.js Theatre</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #080d17;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
#hud {
position: fixed;
inset: 0;
pointer-events: none;
color: #f5f0e8;
}
#title {
position: absolute;
top: 24px;
left: 28px;
padding-left: 14px;
border-left: 3px solid #f0b45e;
text-shadow: 0 2px 12px #000;
}
#title h1 {
margin: 0;
font-size: clamp(24px, 3vw, 42px);
font-weight: 750;
letter-spacing: .12em;
}
#title p {
margin: 6px 0 0;
color: #c6d2df;
font-size: 12px;
letter-spacing: .18em;
text-transform: uppercase;
}
#phase {
position: absolute;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
width: min(560px, calc(100vw - 48px));
padding: 12px 16px 14px;
border: 1px solid rgba(255,255,255,.16);
border-radius: 10px;
background: rgba(8,13,23,.66);
backdrop-filter: blur(10px);
text-align: center;
box-shadow: 0 10px 35px rgba(0,0,0,.25);
}
#phase-text {
display: block;
margin-bottom: 9px;
font-size: 11px;
letter-spacing: .14em;
text-transform: uppercase;
color: #e9edf3;
}
#track {
height: 3px;
overflow: hidden;
border-radius: 99px;
background: rgba(255,255,255,.14);
}
#progress {
display: block;
width: 0;
height: 100%;
background: linear-gradient(90deg, #61c7c0, #f0b45e);
}
#help {
position: absolute;
right: 24px;
bottom: 24px;
color: #b8c4d1;
font-size: 11px;
line-height: 1.6;
text-align: right;
text-shadow: 0 2px 8px #000;
}
#reset {
pointer-events: auto;
margin-top: 8px;
padding: 7px 11px;
border: 1px solid rgba(255,255,255,.22);
border-radius: 7px;
background: rgba(10,16,28,.72);
color: white;
font: inherit;
cursor: pointer;
}
#reset:hover { background: rgba(35,48,68,.85); }
#fade {
position: fixed;
inset: 0;
background: #070b13;
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
#title { top: 16px; left: 16px; }
#help { display: none; }
#phase { bottom: 16px; }
}
</style>
</head>
<body>
<div id="hud">
<div id="title">
<h1>THE HANDOFF</h1>
<p>A miniature theatre study</p>
</div>
<div id="phase" aria-live="polite">
<span id="phase-text">Mara holds the parcel</span>
<div id="track"><i id="progress"></i></div>
</div>
<div id="help">
Drag to orbit · Wheel or pinch to zoom<br>
Arrow keys: orbit · + / −: zoom
<br><button id="reset" type="button">Reset camera</button>
</div>
</div>
<div id="fade"></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 renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"A miniature theater scene in which two stylized characters pass a box."
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0a1020);
scene.fog = new THREE.Fog(0x0a1020, 18, 38);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 2.05, 0);
const cameraState = {
yaw: 0.285,
pitch: 0.245,
radius: 15.6
};
function updateCamera() {
const { yaw, pitch, radius } = cameraState;
camera.position.set(
Math.sin(yaw) * Math.cos(pitch) * radius,
cameraTarget.y + Math.sin(pitch) * radius,
Math.cos(yaw) * Math.cos(pitch) * radius
);
camera.lookAt(cameraTarget);
}
updateCamera();
// ------------------------------------------------------------
// Materials and small geometry helpers
// ------------------------------------------------------------
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
woodA: standard(0x8f5635),
woodB: standard(0xa66840),
woodC: standard(0x77452e),
stageEdge: standard(0x382a25),
gold: standard(0xd59a49, { metalness: 0.25, roughness: 0.45 }),
burgundy: standard(0x651f37, { roughness: 0.96 }),
burgundyDark: standard(0x3c1529),
backdrop: standard(0x243b59),
backdropPanel: standard(0x304d6d),
moon: standard(0x9ec6d6, { emissive: 0x19303d, emissiveIntensity: 0.4 }),
black: standard(0x101419),
audience: standard(0x111a29),
audienceAlt: standard(0x1b2638),
audienceSkin: standard(0x536071),
box: standard(0xc99b56),
boxLid: standard(0xe1b872),
boxBand: standard(0x725037),
metal: standard(0x27313e, { metalness: 0.55, roughness: 0.48 }),
bulb: standard(0xffd59a, {
emissive: 0xffb24d,
emissiveIntensity: 2.2,
roughness: 0.3
})
};
function mesh(geometry, material, parent = scene) {
const object = new THREE.Mesh(geometry, material);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(w, h, d, material, x = 0, y = 0, z = 0, parent = scene) {
const object = mesh(new THREE.BoxGeometry(w, h, d), material, parent);
object.position.set(x, y, z);
return object;
}
function cylinder(rt, rb, h, material, x = 0, y = 0, z = 0, parent = scene, sides = 10) {
const object = mesh(
new THREE.CylinderGeometry(rt, rb, h, sides),
material,
parent
);
object.position.set(x, y, z);
return object;
}
function sphere(r, material, x = 0, y = 0, z = 0, parent = scene, width = 12) {
const object = mesh(new THREE.SphereGeometry(r, width, 8), material, parent);
object.position.set(x, y, z);
return object;
}
function orientSegment(object, from, to) {
const direction = new THREE.Vector3().subVectors(to, from);
const length = direction.length();
object.position.copy(from).add(to).multiplyScalar(0.5);
object.scale.set(1, length, 1);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
}
// ------------------------------------------------------------
// Theatre architecture
// ------------------------------------------------------------
box(40, 0.3, 40, standard(0x090e17), 0, -0.82, 0);
// Stage platform and individual floorboards.
box(18, 0.66, 10, M.stageEdge, 0, -0.36, -0.5);
const boardMaterials = [M.woodA, M.woodB, M.woodC];
for (let i = 0; i < 18; i++) {
box(
0.985, 0.045, 9.94,
boardMaterials[i % boardMaterials.length],
-8.5 + i, -0.022, -0.5
);
}
box(18.1, 0.13, 0.18, M.gold, 0, -0.08, 4.48);
// Backdrop and set flats.
box(15.8, 7.1, 0.25, M.backdrop, 0, 3.45, -5.35);
box(4.5, 5.8, 0.18, M.backdropPanel, -4.7, 3, -5.12);
box(4.2, 5.2, 0.18, M.backdropPanel, 4.75, 2.75, -5.12);
const moon = mesh(new THREE.CircleGeometry(2.05, 40), M.moon);
moon.position.set(-3.25, 4.25, -5.0);
moon.castShadow = false;
// Proscenium.
box(0.52, 7.1, 0.7, M.gold, -7.8, 3.45, 2.25);
box(0.52, 7.1, 0.7, M.gold, 7.8, 3.45, 2.25);
box(16.15, 0.52, 0.72, M.gold, 0, 6.82, 2.25);
box(16.35, 0.18, 0.88, standard(0x2c2020), 0, 7.14, 2.25);
// Folded curtain geometry.
function makeCurtain(side) {
const width = 2.55;
const height = 6.45;
const geometry = new THREE.PlaneGeometry(width, height, 36, 12);
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const fold = 0.13 * Math.sin(x * 15) + 0.035 * Math.sin(x * 31);
positions.setZ(i, fold);
if (y < -height * 0.42) {
positions.setY(i, y + 0.07 * Math.sin(x * 12));
}
}
geometry.computeVertexNormals();
const curtain = mesh(
geometry,
standard(side < 0 ? 0x6c203b : 0x5b1b33, {
side: THREE.DoubleSide,
roughness: 0.96
})
);
curtain.position.set(side * 6.25, 3.38, 2.12);
curtain.rotation.y = side * -0.06;
return curtain;
}
makeCurtain(-1);
makeCurtain(1);
// Scalloped valance.
box(15.8, 0.45, 0.65, M.burgundyDark, 0, 6.42, 2.12);
for (let i = 0; i < 13; i++) {
const scallop = sphere(0.53, M.burgundyDark, -7.2 + i * 1.2, 6.2, 2.12);
scallop.scale.set(1, 0.58, 0.42);
}
// Footlights.
for (let i = 0; i < 11; i++) {
const x = -7.5 + i * 1.5;
box(0.36, 0.2, 0.28, M.metal, x, 0.12, 4.05);
sphere(0.1, M.bulb, x, 0.25, 4.19, scene, 10);
}
// ------------------------------------------------------------
// Props
// ------------------------------------------------------------
// Stool in the left wing.
const stool = new THREE.Group();
stool.position.set(-4.9, 0, -1.25);
stool.rotation.y = 0.2;
scene.add(stool);
cylinder(0.52, 0.48, 0.16, M.woodB, 0, 1.02, 0, stool, 12);
for (const x of [-0.32, 0.32]) {
for (const z of [-0.25, 0.25]) {
const leg = cylinder(0.055, 0.075, 1, M.woodC, x, 0.5, z, stool, 8);
leg.rotation.z = x * 0.12;
}
}
// Ladder in the right wing.
const ladder = new THREE.Group();
ladder.position.set(4.9, 0, -2.7);
ladder.rotation.y = -0.22;
ladder.rotation.z = -0.055;
scene.add(ladder);
for (const x of [-0.38, 0.38]) {
box(0.09, 3.3, 0.11, M.woodB, x, 1.65, 0, ladder);
}
for (let i = 0; i < 6; i++) {
box(0.85, 0.075, 0.12, M.woodC, 0, 0.35 + i * 0.5, 0, ladder);
}
// Small rolled rug.
const rug = cylinder(0.28, 0.28, 1.8, standard(0x7b3e4b), -5.6, 0.3, 0.9);
rug.rotation.z = Math.PI / 2;
rug.rotation.y = 0.18;
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xadc8e6, 0x34221d, 1.75));
const key = new THREE.DirectionalLight(0xffe3bd, 2.7);
key.position.set(-5, 9, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -11;
key.shadow.camera.right = 11;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -5;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 30;
key.shadow.bias = -0.0004;
scene.add(key);
const rim = new THREE.DirectionalLight(0x7fc9ff, 1.45);
rim.position.set(7, 5, -3);
scene.add(rim);
function addSpot(position, target, color, intensity, radius) {
const light = new THREE.SpotLight(color, intensity, 25, 0.34, 0.68, 1.4);
light.position.copy(position);
light.target.position.copy(target);
light.castShadow = true;
light.shadow.mapSize.set(1024, 1024);
light.shadow.bias = -0.0005;
scene.add(light, light.target);
const length = position.distanceTo(target);
const cone = new THREE.Mesh(
new THREE.ConeGeometry(radius, length, 24, 1, true),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.032,
depthWrite: false,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending
})
);
cone.position.copy(position).add(target).multiplyScalar(0.5);
cone.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
position.clone().sub(target).normalize()
);
scene.add(cone);
return light;
}
addSpot(
new THREE.Vector3(-4.5, 7.8, 4.3),
new THREE.Vector3(-0.65, 1.3, 0),
0xffd59a,
48,
2.15
);
addSpot(
new THREE.Vector3(4.8, 7.5, 3.7),
new THREE.Vector3(0.9, 1.5, 0),
0x8bcfff,
42,
2.0
);
// Soft floor pools reinforce the two audience sightlines.
function floorPool(x, z, color, radius) {
const pool = new THREE.Mesh(
new THREE.CircleGeometry(radius, 48),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.075,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
pool.rotation.x = -Math.PI / 2;
pool.position.set(x, 0.014, z);
scene.add(pool);
}
floorPool(-0.7, 0.1, 0xffca78, 2.2);
floorPool(0.8, 0.1, 0x83cfff, 2.0);
// ------------------------------------------------------------
// Audience silhouettes
// ------------------------------------------------------------
function addAudienceMember(x, z, index) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
const seatMaterial = index % 3 === 0 ? M.audienceAlt : M.audience;
box(0.72, 0.73, 0.18, seatMaterial, 0, -0.02, 0.26, g);
box(0.68, 0.13, 0.5, seatMaterial, 0, -0.42, 0.05, g);
const body = sphere(0.37, seatMaterial, 0, 0.13, -0.02, g, 10);
body.scale.set(1.05, 1.15, 0.72);
const head = sphere(
0.23,
index % 4 === 0 ? standard(0x687080) : M.audienceSkin,
0,
0.7,
-0.02,
g,
10
);
head.scale.set(0.93, 1.08, 0.92);
}
const audienceRows = [
{ z: 6.35, y: 0 },
{ z: 7.75, y: -0.08 },
{ z: 9.2, y: -0.16 }
];
const audienceX = [-6, -4.5, -3, -1.5, 1.5, 3, 4.5, 6];
audienceRows.forEach((row, rowIndex) => {
audienceX.forEach((x, colIndex) => {
const offset = (colIndex % 2) * 0.12;
addAudienceMember(
x + (rowIndex % 2 ? 0.18 : -0.12),
row.z + offset,
rowIndex * 8 + colIndex
);
});
});
// ------------------------------------------------------------
// Characters
// ------------------------------------------------------------
const UP = new THREE.Vector3(0, 1, 0);
function createCharacter(config) {
const root = new THREE.Group();
root.position.x = config.x;
scene.add(root);
const pants = standard(config.pants);
const shirt = standard(config.shirt);
const skin = standard(config.skin);
const hair = standard(config.hair);
const shoe = standard(config.shoe);
const detail = standard(config.detail);
// Legs and shoes.
for (const side of [-1, 1]) {
const leg = cylinder(
0.17, 0.21, 0.98, pants,
side * 0.235, 0.56, 0, root, 8
);
leg.rotation.z = side * 0.025;
const shoeMesh = box(
0.39, 0.19, 0.62, shoe,
side * 0.235, 0.115, 0.12, root
);
shoeMesh.rotation.y = side * 0.05;
}
box(0.77, 0.25, 0.48, pants, 0, 1.05, 0, root);
const upper = new THREE.Group();
upper.position.y = 1.08;
root.add(upper);
const torso = cylinder(
0.48, 0.61, 1.18, shirt,
0, 0.61, 0, upper, 8
);
// Distinct clothing silhouettes.
if (config.id === "mara") {
box(0.58, 0.72, 0.075, detail, 0, 0.52, 0.475, upper);
for (const x of [-0.21, 0.21]) {
box(0.11, 0.57, 0.075, detail, x, 0.79, 0.48, upper);
}
box(0.69, 0.1, 0.59, detail, 0, 0.27, 0, upper);
} else {
box(0.76, 0.12, 0.58, detail, 0, 0.25, 0, upper);
const hood = sphere(0.47, detail, 0, 1.13, -0.18, upper, 12);
hood.scale.set(1.08, 0.95, 0.72);
box(0.13, 0.48, 0.08, detail, 0, 0.82, 0.49, upper);
}
cylinder(0.16, 0.16, 0.24, skin, 0, 1.28, 0, upper, 10);
const head = new THREE.Group();
head.position.set(0, 1.79, 0.015);
upper.add(head);
const headMesh = sphere(0.48, skin, 0, 0, 0, head, 16);
headMesh.scale.set(0.95, 1.04, 0.94);
const hairCap = sphere(0.515, hair, 0, 0.31, -0.035, head, 14);
hairCap.scale.set(1.02, 0.43, 0.98);
if (config.id === "mara") {
const bun = sphere(0.23, hair, 0.43, 0.26, -0.03, head, 12);
bun.scale.set(1, 0.92, 1);
sphere(0.16, detail, -0.35, 0.3, 0.11, head, 10);
} else {
const curlA = sphere(0.2, hair, -0.39, 0.25, 0.0, head, 10);
const curlB = sphere(0.18, hair, 0.37, 0.31, -0.03, head, 10);
curlA.scale.set(0.9, 1.1, 0.9);
curlB.scale.set(0.85, 1.15, 0.85);
}
// Ears, eyes, brows, nose, and mouth.
sphere(0.105, skin, -0.47, 0.0, 0, head, 10);
sphere(0.105, skin, 0.47, 0.0, 0, head, 10);
const eyeWhite = standard(0xf5f0e7);
const pupils = [];
const brows = [];
for (const side of [-1, 1]) {
const eye = sphere(0.083, eyeWhite, side * 0.145, 0.035, 0.425, head, 12);
eye.scale.set(1, 1.08, 0.55);
const pupil = sphere(
0.039, M.black,
side * 0.145, 0.03, 0.469, head, 10
);
pupil.scale.set(0.9, 1.05, 0.55);
pupil.userData.baseX = pupil.position.x;
pupils.push(pupil);
const brow = box(
0.16, 0.032, 0.038, hair,
side * 0.145, 0.165, 0.455, head
);
brows.push(brow);
}
sphere(0.072, skin, 0, -0.045, 0.48, head, 10);
const mouth = box(0.18, 0.034, 0.035, M.black, 0, -0.17, 0.452, head);
// Shoulder anchors and fixed shoulder caps.
const shoulders = {};
for (const side of [-1, 1]) {
const shoulder = new THREE.Object3D();
shoulder.position.set(side * 0.52, 1.1, 0);
upper.add(shoulder);
shoulders[side] = shoulder;
sphere(0.18, shirt, side * 0.52, 1.1, 0, upper, 10);
}
// Dynamic arms are world-space so hand targets remain exact.
function makeArm(side) {
const upperArm = mesh(
new THREE.CylinderGeometry(0.13, 0.145, 1, 9),
shirt
);
const forearm = mesh(
new THREE.CylinderGeometry(0.095, 0.12, 1, 9),
skin
);
const elbow = sphere(0.12, skin, 0, 0, 0, scene, 10);
const hand = new THREE.Group();
scene.add(hand);
const palm = sphere(0.145, skin, 0, 0, 0, hand, 10);
palm.scale.set(0.9, 1.12, 0.76);
const thumb = sphere(0.065, skin, side * -0.11, 0.025, 0.055, hand, 8);
thumb.scale.set(0.8, 1.25, 0.8);
return { side, shoulder: shoulders[side], upperArm, forearm, elbow, hand };
}
const arms = {
left: makeArm(-1),
right: makeArm(1)
};
return {
id: config.id,
root,
upper,
head,
pupils,
brows,
mouth,
arms,
innerSide: config.innerSide,
baseX: config.x,
skin
};
}
const mara = createCharacter({
id: "mara",
x: -1.48,
innerSide: 1,
shirt: 0xe46f55,
pants: 0x267b79,
skin: 0xd99a72,
hair: 0x3d2525,
shoe: 0x222d39,
detail: 0x2e8581
});
const jules = createCharacter({
id: "jules",
x: 1.48,
innerSide: -1,
shirt: 0xe1a84c,
pants: 0x51466f,
skin: 0x81513f,
hair: 0x171c26,
shoe: 0x20232d,
detail: 0x30364c
});
// ------------------------------------------------------------
// The prop box
// ------------------------------------------------------------
const parcel = new THREE.Group();
scene.add(parcel);
box(0.9, 0.56, 0.62, M.box, 0, 0, 0, parcel);
box(0.96, 0.1, 0.66, M.boxLid, 0, 0.31, 0, parcel);
box(0.09, 0.56, 0.64, M.boxBand, -0.27, 0, 0, parcel);
box(0.09, 0.56, 0.64, M.boxBand, 0.27, 0, 0, parcel);
box(0.18, 0.15, 0.03, M.boxBand, 0, 0.02, 0.327, parcel);
const handle = mesh(
new THREE.TorusGeometry(0.2, 0.045, 8, 24, Math.PI),
M.boxBand,
parcel
);
handle.position.set(0, 0.39, 0);
// ------------------------------------------------------------
// Articulated arm solver
// ------------------------------------------------------------
const shoulderWorld = new THREE.Vector3();
const targetWorld = new THREE.Vector3();
const direction = new THREE.Vector3();
const bend = new THREE.Vector3();
const elbowPosition = new THREE.Vector3();
function updateArm(arm, target) {
arm.shoulder.getWorldPosition(shoulderWorld);
targetWorld.copy(target);
direction.subVectors(targetWorld, shoulderWorld);
const distance = direction.length();
if (distance < 0.0001) direction.set(0, -1, 0);
else direction.divideScalar(distance);
const upperLength = 0.78;
const lowerLength = 0.78;
const maxReach = upperLength + lowerLength - 0.015;
if (distance > maxReach) {
targetWorld.copy(shoulderWorld).addScaledVector(direction, maxReach);
direction.copy(targetWorld).sub(shoulderWorld).normalize();
}
const d = Math.min(
targetWorld.distanceTo(shoulderWorld),
upperLength + lowerLength - 0.001
);
const along =
(upperLength * upperLength - lowerLength * lowerLength + d * d) /
(2 * d);
const height = Math.sqrt(Math.max(0, upperLength * upperLength - along * along));
// Elbows point downward and slightly toward the audience.
bend.set(-direction.y, direction.x, 0);
if (bend.lengthSq() < 0.001) bend.set(0, -1, 0);
bend.normalize();
if (bend.y > 0) bend.negate();
bend.z = 0.34;
bend.normalize();
elbowPosition.copy(shoulderWorld)
.addScaledVector(direction, along)
.addScaledVector(bend, height);
orientSegment(arm.upperArm, shoulderWorld, elbowPosition);
orientSegment(arm.forearm, elbowPosition, targetWorld);
arm.elbow.position.copy(elbowPosition);
arm.hand.position.copy(targetWorld);
}
// ------------------------------------------------------------
// Timeline helpers
// ------------------------------------------------------------
const DURATION = 12;
const smooth = x => {
x = THREE.MathUtils.clamp(x, 0, 1);
return x * x * (3 - 2 * x);
};
const mix = THREE.MathUtils.lerp;
function sampleScalar(keys, time) {
if (time <= keys[0][0]) return keys[0][1];
for (let i = 0; i < keys.length - 1; i++) {
const [t0, v0] = keys[i];
const [t1, v1] = keys[i + 1];
if (time <= t1) {
return mix(v0, v1, smooth((time - t0) / (t1 - t0)));
}
}
return keys[keys.length - 1][1];
}
function sampleVector(keys, time, output = new THREE.Vector3()) {
if (time <= keys[0][0]) {
return output.fromArray(keys[0][1]);
}
for (let i = 0; i < keys.length - 1; i++) {
const [t0, v0] = keys[i];
const [t1, v1] = keys[i + 1];
if (time <= t1) {
const u = smooth((time - t0) / (t1 - t0));
return output.set(
mix(v0[0], v1[0], u),
mix(v0[1], v1[1], u),
mix(v0[2], v1[2], u)
);
}
}
return output.fromArray(keys[keys.length - 1][1]);
}
const boxXKeys = [
[0, -0.55],
[3.4, -0.55],
[4.15, -0.50],
[4.55, -0.32],
[5.65, 0.42],
[6.25, 0.55],
[7.15, 0.78],
[11.3, 0.78]
];
const boxYKeys = [
[0, 2.42],
[0.8, 2.49],
[3.4, 2.49],
[4.15, 2.58],
[5.65, 2.58],
[6.25, 2.48],
[7.15, 2.45],
[11.3, 2.45]
];
const bInnerReachKeys = [
[0, [0.38, 1.93, 0.29]],
[0.8, [0.38, 1.93, 0.29]],
[3.4, [-0.35, 2.88, 0.15]]
];
const aOuterKeys = [
[0, [-2.00, 1.91, 0.20]],
[2.6, [-2.00, 1.91, 0.20]],
[4.2, [-1.52, 2.12, 0.52]],
[5.45, [-1.18, 2.34, 0.68]],
[6.25, [-1.55, 2.12, 0.56]],
[7.3, [-2.00, 1.91, 0.20]],
[11.3, [-2.00, 1.91, 0.20]]
];
const bOuterRest = new THREE.Vector3(2.0, 1.91, 0.2);
const aInnerTarget = new THREE.Vector3();
const bInnerTarget = new THREE.Vector3();
const aOuterTarget = new THREE.Vector3();
const bOuterTarget = new THREE.Vector3();
const releaseStart = new THREE.Vector3();
const releaseEnd = new THREE.Vector3();
const aRestAfterRelease = new THREE.Vector3(-0.92, 2.05, 0.42);
const parcelZ = 0.15;
function updateCharacter(character, time, isA) {
const anticipation =
smooth((time - 2.8) / 0.8) *
(1 - smooth((time - 5.5) / 1.0));
const transfer =
smooth((time - 3.8) / 0.9) *
(1 - smooth((time - 5.5) / 1.15));
const bob = Math.sin(time * 2.1 + (isA ? 0 : 1.3)) * 0.018;
character.root.position.y = bob;
character.upper.position.y = 1.08 + bob * 0.4;
if (isA) {
character.root.position.x = character.baseX + 0.035 * transfer;
character.upper.rotation.z = -0.025 - 0.042 * transfer - 0.012 * anticipation;
character.upper.rotation.y = 0.10 + 0.045 * transfer;
character.head.rotation.y = 0.07 + 0.06 * anticipation;
character.head.rotation.z = -0.025 - 0.03 * transfer;
character.brows[0].rotation.z = -0.08 * anticipation;
character.brows[1].rotation.z = 0.08 * anticipation;
character.mouth.scale.x = 1 + 0.12 * anticipation;
} else {
character.root.position.x = character.baseX - 0.035 * transfer;
character.upper.rotation.z = 0.025 + 0.04 * transfer + 0.018 * anticipation;
character.upper.rotation.y = -0.10 - 0.04 * transfer;
character.head.rotation.y = -0.08 - 0.04 * anticipation;
character.head.rotation.z = 0.025 + 0.03 * transfer;
character.brows[0].rotation.z = 0.08 * anticipation;
character.brows[1].rotation.z = -0.08 * anticipation;
character.mouth.scale.x = 1 + 0.08 * anticipation;
}
}
function updateScene(time) {
const boxX = sampleScalar(boxXKeys, time);
const boxY = sampleScalar(boxYKeys, time);
parcel.position.set(boxX, boxY, parcelZ);
parcel.rotation.z = Math.sin(time * 1.35) * 0.008;
updateCharacter(mara, time, true);
updateCharacter(jules, time, false);
mara.root.updateMatrixWorld(true);
jules.root.updateMatrixWorld(true);
// Handle endpoints are the exact hand-contact targets.
const aGrip = aInnerTarget.set(
boxX - 0.20,
boxY + 0.39,
parcelZ
);
const bGrip = bInnerTarget.set(
boxX + 0.20,
boxY + 0.39,
parcelZ
);
// Mara keeps the left end of the handle until Jules has it.
if (time <= 5.65) {
aInnerTarget.copy(aGrip);
} else {
const releaseTime = 5.65;
const releaseBoxX = sampleScalar(boxXKeys, releaseTime);
const releaseBoxY = sampleScalar(boxYKeys, releaseTime);
releaseStart.set(
releaseBoxX - 0.2,
releaseBoxY + 0.39,
parcelZ
);
releaseEnd.copy(releaseStart).add(new THREE.Vector3(-0.43, 0.13, 0.38));
if (time <= 6.35) {
const u = smooth((time - releaseTime) / 0.7);
aInnerTarget.lerpVectors(releaseStart, releaseEnd, u);
} else {
const u = smooth((time - 6.35) / 0.95);
aInnerTarget.lerpVectors(releaseEnd, aRestAfterRelease, u);
}
}
// Jules reaches the right end, then keeps continuous contact.
if (time < 3.4) {
sampleVector(bInnerReachKeys, time, bInnerTarget);
} else {
bInnerTarget.copy(bGrip);
}
sampleVector(aOuterKeys, time, aOuterTarget);
// Jules' second hand comes underneath only after Mara releases.
const bSupport = bOuterTarget.set(
boxX,
boxY - 0.32,
parcelZ + 0.39
);
if (time < 6.1) {
bOuterTarget.copy(bOuterRest);
} else if (time < 7.2) {
const u = smooth((time - 6.1) / 1.1);
bOuterTarget.lerpVectors(bOuterRest, bSupport, u);
} else {
bOuterTarget.copy(bSupport);
}
updateArm(mara.arms.right, aInnerTarget);
updateArm(mara.arms.left, aOuterTarget);
updateArm(jules.arms.left, bInnerTarget);
updateArm(jules.arms.right, bOuterTarget);
// Pupils subtly track the parcel.
const maraGaze = THREE.MathUtils.clamp((boxX - mara.baseX) * 0.025, -0.055, 0.055);
const julesGaze = THREE.MathUtils.clamp((boxX - jules.baseX) * 0.025, -0.055, 0.055);
mara.pupils.forEach(p => {
p.position.x = p.userData.baseX + maraGaze;
});
jules.pupils.forEach(p => {
p.position.x = p.userData.baseX + julesGaze;
});
return { boxX, boxY };
}
// ------------------------------------------------------------
// Custom camera interaction — no external controls addon
// ------------------------------------------------------------
const canvas = renderer.domElement;
const pointers = new Map();
let pinchStart = 0;
let radiusStart = 0;
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchStart = Math.hypot(a.x - b.x, a.y - b.y);
radiusStart = cameraState.radius;
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.06,
0.68
);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
cameraState.radius = THREE.MathUtils.clamp(
radiusStart * pinchStart / Math.max(distance, 1),
10,
22
);
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchStart = 0;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
10,
22
);
updateCamera();
}, { passive: false });
window.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.yaw += 0.08;
break;
case "ArrowRight":
cameraState.yaw -= 0.08;
break;
case "ArrowUp":
cameraState.pitch = Math.min(0.68, cameraState.pitch + 0.05);
break;
case "ArrowDown":
cameraState.pitch = Math.max(0.06, cameraState.pitch - 0.05);
break;
case "+":
case "=":
cameraState.radius = Math.max(10, cameraState.radius - 0.7);
break;
case "-":
case "_":
cameraState.radius = Math.min(22, cameraState.radius + 0.7);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
document.getElementById("reset").addEventListener("click", () => {
cameraState.yaw = 0.285;
cameraState.pitch = 0.245;
cameraState.radius = 15.6;
updateCamera();
});
// ------------------------------------------------------------
// Resize and animation loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const progressElement = document.getElementById("progress");
const phaseElement = document.getElementById("phase-text");
const fadeElement = document.getElementById("fade");
const clock = new THREE.Clock();
function phaseLabel(time) {
if (time < 0.8) return "Mara holds the parcel";
if (time < 3.4) return "Jules reaches for the handle";
if (time < 4.15) return "A shared moment of anticipation";
if (time < 5.65) return "The parcel changes hands";
if (time < 7.2) return "Mara releases — Jules takes possession";
return "Jules secures the parcel";
}
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const cycle = Math.floor(elapsed / DURATION);
const time = elapsed % DURATION;
updateScene(time);
updateCamera();
progressElement.style.width = `${(time / DURATION) * 100}%`;
phaseElement.textContent = phaseLabel(time);
// Fade only around a loop reset, leaving the first frame visible.
let opacity = 0;
if (time > 11.2) {
opacity = smooth((time - 11.2) / 0.65);
} else if (cycle > 0 && time < 0.45) {
opacity = 1 - smooth(time / 0.45);
}
fadeElement.style.opacity = opacity.toFixed(3);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```