Prompt specification
Build or customize the Three.js 3D scene "Passing the Same Parcel" 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: Passing the Same Parcel
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/passing-the-same-parcel-x3410
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts references to objects in context. Animate two characters exchanging one distinctive parcel, then moving apart. Track object identity across possession changes and distinguish the parcel from its current owner. Voxel style.
Working Three.js Starter (passing-the-same-parcel-x3410):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>P-07 — Object Identity Through Possession</title>
<style>
:root {
color-scheme: light;
--ink: #172b3a;
--muted: #617582;
--panel: rgba(248, 252, 253, 0.92);
--line: rgba(23, 43, 58, 0.13);
--mara: #13aa9b;
--ivo: #ee654c;
--parcel: #ffc84a;
--navy: #243b53;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9ed;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
#world-labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 7px;
background: rgba(25, 42, 55, 0.86);
color: white;
box-shadow: 0 5px 16px rgba(20, 38, 52, 0.18);
transform: translate(-50%, -100%);
transition: border-color 180ms ease, box-shadow 180ms ease;
white-space: nowrap;
font-size: 10px;
letter-spacing: 0.08em;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 9px;
background: rgba(255, 255, 255, 0.75);
}
.world-label b {
font-size: 11px;
letter-spacing: 0.09em;
}
.world-label span {
opacity: 0.7;
font-size: 9px;
}
.parcel-label {
background: rgba(54, 42, 19, 0.9);
border-color: var(--parcel);
}
.parcel-label b { color: #ffe28a; }
.person-label.holder {
border-color: white;
box-shadow:
0 0 0 2px rgba(255, 255, 255, 0.25),
0 6px 18px rgba(20, 38, 52, 0.22);
}
.person-label.holder span {
color: #fff4a8;
opacity: 1;
}
.panel {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(31, 57, 73, 0.16);
backdrop-filter: blur(14px);
}
.eyebrow {
color: #607887;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 8px;
font-size: clamp(23px, 3vw, 31px);
line-height: 1.04;
letter-spacing: -0.04em;
}
.intro {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.resolve {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 7px;
margin: 15px 0;
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.68);
font-size: 12px;
}
.resolve .term {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
}
.resolve em {
font-weight: 700;
}
.resolve .arrow {
color: #8da0aa;
}
.resolve b {
padding: 3px 7px;
border-radius: 5px;
background: #ffe08a;
color: #59420b;
letter-spacing: 0.05em;
}
.readout {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.readout > div {
min-width: 0;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.55);
}
.readout span,
.status-row span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
}
.readout strong {
display: block;
overflow: hidden;
font-size: 15px;
letter-spacing: 0.06em;
text-overflow: ellipsis;
white-space: nowrap;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 9px;
padding: 9px 11px;
border-radius: 9px;
background: #eaf1f4;
font-size: 12px;
}
.status-row span {
display: inline;
margin: 0;
}
#statusValue { font-weight: 750; }
.context {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 11px;
}
.context span {
padding: 5px 7px;
border: 1px solid var(--line);
border-radius: 6px;
background: rgba(255, 255, 255, 0.56);
color: #526a78;
font-size: 10px;
}
.context .p07 {
border-color: rgba(198, 146, 0, 0.34);
background: #fff2bf;
color: #70530c;
}
.history {
margin-top: 10px;
color: var(--muted);
font-size: 11px;
}
#caption {
position: fixed;
z-index: 10;
left: 50%;
bottom: 24px;
display: flex;
align-items: center;
gap: 12px;
width: min(680px, calc(100vw - 40px));
padding: 13px 16px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 12px;
background: rgba(248, 252, 253, 0.92);
box-shadow: 0 10px 30px rgba(27, 51, 65, 0.16);
transform: translateX(-50%);
backdrop-filter: blur(12px);
}
#captionSpeaker {
flex: 0 0 auto;
min-width: 64px;
padding: 6px 8px;
border-radius: 6px;
background: var(--navy);
color: white;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-align: center;
}
#captionText {
font-size: 13px;
line-height: 1.45;
}
.controls {
position: fixed;
z-index: 11;
top: 20px;
right: 20px;
width: 230px;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 12px;
background: rgba(248, 252, 253, 0.88);
box-shadow: 0 10px 28px rgba(31, 57, 73, 0.12);
backdrop-filter: blur(12px);
}
.buttons {
display: flex;
gap: 7px;
}
button {
flex: 1;
padding: 8px 9px;
border: 0;
border-radius: 7px;
background: var(--navy);
color: white;
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 750;
}
button:hover { filter: brightness(1.12); }
#scrub {
width: 100%;
margin: 12px 0 5px;
accent-color: #16a99a;
cursor: pointer;
}
.timeline-info {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.06em;
}
.camera-help {
margin-top: 9px;
color: var(--muted);
font-size: 9px;
line-height: 1.4;
text-align: center;
}
@media (max-width: 760px) {
.panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px;
}
.intro, .context, .history { display: none; }
.resolve { margin: 10px 0; }
.readout > div { padding: 7px 9px; }
.controls {
top: auto;
right: 10px;
bottom: 88px;
width: 190px;
}
#caption {
bottom: 10px;
width: calc(100vw - 20px);
padding: 10px;
}
#captionSpeaker { min-width: 54px; }
#captionText { font-size: 11px; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="world-labels" aria-hidden="true">
<div id="parcelLabel" class="world-label parcel-label">
<b>P-07</b><span>OBJECT · STRIPED PARCEL</span>
</div>
<div id="maraLabel" class="world-label person-label">
<b>MARA</b><span>CHARACTER</span>
</div>
<div id="ivoLabel" class="world-label person-label">
<b>IVO</b><span>CHARACTER</span>
</div>
<div id="crateLabel" class="world-label">
<b>C-12</b><span>CRATE</span>
</div>
<div id="mailboxLabel" class="world-label">
<b>M-03</b><span>MAILBOX</span>
</div>
</div>
<section class="panel" aria-label="Object identity and possession tracking">
<div class="eyebrow">Referential tracking / one scene</div>
<h1>One parcel.<br />Two possible holders.</h1>
<p class="intro">
The referring expression <em>“the striped parcel”</em> resolves to one
persistent object. Its appearance and identity do not change when
possession does.
</p>
<div class="resolve">
<span class="term">REFERENCE</span>
<em>“the striped parcel”</em>
<span class="arrow">→</span>
<b>P-07</b>
</div>
<div class="readout">
<div>
<span>OBJECT ID</span>
<strong style="color:#9b6a00">P-07</strong>
</div>
<div>
<span>CURRENT HOLDER</span>
<strong id="ownerValue">MARA</strong>
</div>
</div>
<div class="status-row">
<span>STATE</span>
<span id="statusValue">holding</span>
</div>
<div class="context" aria-label="Objects in context">
<span>C-12 · crate</span>
<span>M-03 · mailbox</span>
<span class="p07">P-07 · parcel</span>
</div>
<div id="historyText" class="history">Possession: Mara</div>
</section>
<aside class="controls" aria-label="Animation and camera controls">
<div class="buttons">
<button id="replayButton" type="button">Replay</button>
<button id="pauseButton" type="button">Pause</button>
</div>
<input
id="scrub"
type="range"
min="0"
max="12.2"
step="0.01"
value="0"
aria-label="Animation timeline"
/>
<div class="timeline-info">
<span>TIMELINE</span>
<span id="timelineValue">0.0 / 12.2 s</span>
</div>
<div class="camera-help">
Drag to orbit · Scroll to zoom<br />
Space: pause · R: replay
</div>
</aside>
<div id="caption" aria-live="polite">
<span id="captionSpeaker">MARA</span>
<span id="captionText">“I’m holding the striped parcel.”</span>
</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, camera, and lighting
// ------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Voxel scene showing two characters exchanging a parcel"
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9ed);
scene.fog = new THREE.Fog(0xdce9ed, 19, 37);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xf4fbff, 0x80929b, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.1);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0006;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0xa9d9ff, 1.0);
rimLight.position.set(9, 7, -8);
scene.add(rimLight);
// ------------------------------------------------------------------
// Voxel construction helpers
// ------------------------------------------------------------------
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(
parent,
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
customMaterial = null
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
customMaterial || getMaterial(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createPerson(id, name, shirtColor, hairColor, accentColor) {
const root = new THREE.Group();
root.name = name;
root.userData.personId = id;
scene.add(root);
const skin = 0xeeb18e;
// Legs and shoes.
const legs = [-1, 1].map((side) => {
const pivot = new THREE.Group();
pivot.position.set(side * 0.25, 0.92, 0);
root.add(pivot);
box(pivot, 0.32, 0.72, 0.38, 0x24364c, 0, -0.34, 0);
box(pivot, 0.39, 0.24, 0.53, 0x172634, 0, -0.73, 0.07);
return pivot;
});
// Torso and identifying chest patch.
box(root, 0.96, 1.05, 0.58, shirtColor, 0, 1.28, 0);
box(root, 0.26, 0.25, 0.035, accentColor, -0.22, 1.47, 0.315);
box(root, 0.98, 0.12, 0.61, 0x24364c, 0, 0.83, 0);
// Head, hair, eyes, and mouth. Characters face local +Z.
box(root, 0.72, 0.72, 0.68, skin, 0, 2.14, 0);
box(root, 0.79, 0.18, 0.75, hairColor, 0, 2.52, -0.015);
box(root, 0.76, 0.23, 0.16, hairColor, 0, 2.36, -0.32);
box(root, 0.10, 0.11, 0.035, 0x14212b, -0.17, 2.19, 0.355);
box(root, 0.10, 0.11, 0.035, 0x14212b, 0.17, 2.19, 0.355);
box(root, 0.25, 0.055, 0.035, 0x8a4d43, 0, 1.99, 0.355);
// Small square hair clips make the two speakers easy to distinguish.
box(root, 0.12, 0.12, 0.12, accentColor, -0.27, 2.54, 0.26);
function createArm(side) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.62, 1.68, 0);
root.add(pivot);
box(pivot, 0.30, 0.70, 0.34, shirtColor, 0, -0.31, 0);
box(pivot, 0.29, 0.27, 0.31, skin, 0, -0.70, 0.02);
const anchor = new THREE.Object3D();
anchor.position.set(0, -0.78, 0.05);
pivot.add(anchor);
return { pivot, anchor };
}
const leftArm = createArm(-1);
const rightArm = createArm(1);
return {
id,
name,
root,
legs,
leftArm,
rightArm,
shirtColor
};
}
// ------------------------------------------------------------------
// Ground, exchange zone, context objects, and backdrop
// ------------------------------------------------------------------
box(scene, 18.4, 0.48, 12.4, 0x637b87, 0, -0.30, 0);
const tileColors = [0xd7e1e4, 0xd1dcdf, 0xdce5e7, 0xcdd9dd];
for (let ix = 0; ix < 9; ix++) {
for (let iz = 0; iz < 6; iz++) {
const x = -8 + ix * 2;
const z = -5 + iz * 2;
const color = tileColors[(ix + iz * 2) % tileColors.length];
box(scene, 1.91, 0.14, 1.91, color, x, -0.01, z);
}
}
// Corner brackets around the exchange area.
const zoneMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.72,
roughness: 0.9
});
const zone = new THREE.Group();
zone.position.z = -0.62;
scene.add(zone);
const bracketX = [-1.05, 1.05];
const bracketZ = [-1.05, 1.05];
bracketX.forEach((x) => {
bracketZ.forEach((z) => {
box(zone, 0.55, 0.055, 0.09, 0xffffff, x, 0.09, z, zoneMaterial);
box(zone, 0.09, 0.055, 0.55, 0xffffff, x, 0.09, z, zoneMaterial);
});
});
// Context crate C-12.
const crate = new THREE.Group();
crate.position.set(-5.8, 0, -3.35);
scene.add(crate);
box(crate, 1.35, 1.12, 1.16, 0x42aeb3, 0, 0.62, 0);
box(crate, 1.43, 0.13, 1.23, 0x267b84, 0, 0.27, 0);
box(crate, 1.43, 0.13, 1.23, 0x267b84, 0, 0.99, 0);
box(crate, 0.12, 0.75, 1.19, 0x267b84, -0.43, 0.62, 0);
box(crate, 0.12, 0.75, 1.19, 0x267b84, 0.43, 0.62, 0);
box(crate, 0.34, 0.28, 0.04, 0xf5e6b4, 0, 0.66, 0.61);
// Context mailbox M-03.
const mailbox = new THREE.Group();
mailbox.position.set(5.75, 0, -3.35);
scene.add(mailbox);
box(mailbox, 0.22, 1.35, 0.22, 0x354b5b, 0, 0.68, 0);
box(mailbox, 0.90, 0.76, 0.68, 0xd9564f, 0, 1.48, 0);
box(mailbox, 0.99, 0.13, 0.76, 0x9c3f3c, 0, 1.91, 0);
box(mailbox, 0.58, 0.07, 0.04, 0xf7d9a7, 0, 1.48, 0.36);
// Quiet voxel skyline for context.
const buildingColors = [0xa7bbc2, 0xb9c9cd, 0x91aab3, 0xc3cfd1];
const buildingData = [
[-7.4, 1.9, -5.15],
[-5.7, 2.6, -5.15],
[-3.6, 1.35, -5.15],
[-0.6, 2.25, -5.15],
[2.0, 1.55, -5.15],
[4.2, 2.8, -5.15],
[7.0, 1.7, -5.15]
];
buildingData.forEach(([x, h, z], index) => {
box(
scene,
1.35,
h,
1.25,
buildingColors[index % buildingColors.length],
x,
h / 2,
z
);
box(scene, 1.47, 0.16, 1.37, 0x8099a4, x, h + 0.08, z);
});
// ------------------------------------------------------------------
// Characters
// ------------------------------------------------------------------
const mara = createPerson("mara", "Mara", 0x13aa9b, 0x40345f, 0xf5d55b);
const ivo = createPerson("ivo", "Ivo", 0xee654c, 0x26384b, 0x8ed8e4);
// Mara faces right; Ivo faces left.
mara.root.rotation.y = Math.PI / 2;
ivo.root.rotation.y = -Math.PI / 2;
// ------------------------------------------------------------------
// The single persistent parcel
//
// This Group is created exactly once. Possession changes update a
// separate currentHolderId relation; the parcel's geometry, color,
// ID, and scene membership never change.
// ------------------------------------------------------------------
const parcel = new THREE.Group();
parcel.name = "P-07";
parcel.userData.objectId = "P-07";
parcel.userData.objectType = "distinctive-striped-parcel";
parcel.userData.currentHolderId = "mara";
scene.add(parcel);
box(parcel, 0.90, 0.82, 0.78, 0xffc84a, 0, 0, 0);
// Dark cross straps make the parcel unmistakable.
box(parcel, 0.16, 0.84, 0.80, 0x243b53, -0.20, 0, 0);
box(parcel, 0.92, 0.14, 0.80, 0x243b53, 0, 0.06, 0.008);
// Red seal and a voxel-built number 7.
box(parcel, 0.42, 0.50, 0.045, 0xe75245, 0, 0.06, 0.425);
box(parcel, 0.09, 0.09, 0.025, 0xfff7db, -0.10, 0.19, 0.455);
box(parcel, 0.09, 0.09, 0.025, 0xfff7db, 0.01, 0.19, 0.455);
box(parcel, 0.09, 0.09, 0.025, 0xfff7db, 0.12, 0.19, 0.455);
box(parcel, 0.09, 0.09, 0.025, 0xfff7db, 0.12, 0.08, 0.455);
box(parcel, 0.09, 0.09, 0.025, 0xfff7db, 0.12, -0.03, 0.455);
box(parcel, 0.09, 0.09, 0.025, 0xfff7db, 0.12, -0.14, 0.455);
// The holder marker surrounds the current owner, not the parcel.
const holderRing = new THREE.Group();
scene.add(holderRing);
const holderRingMaterial = new THREE.MeshStandardMaterial({
color: mara.shirtColor,
transparent: true,
opacity: 0.92,
roughness: 0.75
});
box(holderRing, 1.58, 0.075, 0.10, 0xffffff, 0, 0, -0.79, holderRingMaterial);
box(holderRing, 1.58, 0.075, 0.10, 0xffffff, 0, 0, 0.79, holderRingMaterial);
box(holderRing, 0.10, 0.075, 1.48, 0xffffff, -0.74, 0, 0, holderRingMaterial);
box(holderRing, 0.10, 0.075, 1.48, 0xffffff, 0.74, 0, 0, holderRingMaterial);
// ------------------------------------------------------------------
// Animation state
// ------------------------------------------------------------------
const DURATION = 12.2;
const APPROACH_START = 1.2;
const APPROACH_END = 3.2;
const OFFER_START = 3.1;
const HANDOFF_START = 4.8;
const HANDOFF_END = 6.8;
const HANDOFF_MID = (HANDOFF_START + HANDOFF_END) / 2;
const DEPART_START = 8.0;
const DEPART_END = 12.0;
let timeline = 0;
let paused = false;
let currentHolderId = null;
const ownerValue = document.getElementById("ownerValue");
const statusValue = document.getElementById("statusValue");
const historyText = document.getElementById("historyText");
const captionSpeaker = document.getElementById("captionSpeaker");
const captionText = document.getElementById("captionText");
const caption = document.getElementById("caption");
const maraLabel = document.getElementById("maraLabel");
const ivoLabel = document.getElementById("ivoLabel");
const parcelLabel = document.getElementById("parcelLabel");
const crateLabel = document.getElementById("crateLabel");
const mailboxLabel = document.getElementById("mailboxLabel");
const scrub = document.getElementById("scrub");
const timelineValue = document.getElementById("timelineValue");
const replayButton = document.getElementById("replayButton");
const pauseButton = document.getElementById("pauseButton");
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
function smoothstep(edge0, edge1, value) {
const t = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return t * t * (3 - 2 * t);
}
function setHolder(holderId) {
if (holderId === currentHolderId) return;
currentHolderId = holderId;
parcel.userData.currentHolderId = holderId;
const holder = holderId === "mara" ? mara : ivo;
ownerValue.textContent = holder.name.toUpperCase();
ownerValue.style.color = holderId === "mara" ? "#13aa9b" : "#ee654c";
holderRingMaterial.color.set(holder.shirtColor);
maraLabel.classList.toggle("holder", holderId === "mara");
ivoLabel.classList.toggle("holder", holderId === "ivo");
maraLabel.querySelector("span").textContent =
holderId === "mara" ? "CURRENT HOLDER" : "CHARACTER";
ivoLabel.querySelector("span").textContent =
holderId === "ivo" ? "CURRENT HOLDER" : "CHARACTER";
historyText.textContent =
holderId === "ivo"
? "Possession: Mara → Ivo · Object ID remains P-07"
: "Possession: Mara · Object ID remains P-07";
}
function setCaption(speaker, text) {
if (
captionSpeaker.textContent !== speaker ||
captionText.textContent !== text
) {
captionSpeaker.textContent = speaker;
captionText.textContent = text;
}
}
function updateCaptionAndStatus(t) {
if (t < APPROACH_START) {
setCaption("MARA", "“I’m holding the striped parcel.”");
statusValue.textContent = "holding";
} else if (t < APPROACH_END) {
setCaption("SCENE", "Mara and Ivo enter the handoff area.");
statusValue.textContent = "approaching";
} else if (t < HANDOFF_START) {
setCaption("IVO", "“Please pass me the striped parcel.”");
statusValue.textContent = "offering";
} else if (t < HANDOFF_END) {
setCaption("IDENTITY", "One parcel changes hands; its identity remains P-07.");
statusValue.textContent = "handoff";
} else if (t < DEPART_START) {
setCaption("IVO", "“I have it now — still P-07.”");
statusValue.textContent = "received";
} else {
setCaption("SCENE", "They move apart. P-07 travels with Ivo.");
statusValue.textContent = "separated";
}
}
const parcelTarget = new THREE.Vector3();
const maraHand = new THREE.Vector3();
const ivoHand = new THREE.Vector3();
const handoffMidpoint = new THREE.Vector3(0, 1.59, -0.62);
function updateScene(t) {
const approach = smoothstep(APPROACH_START, APPROACH_END, t);
const departure = smoothstep(DEPART_START, DEPART_END, t);
// Mara: -3.25 → -1.15 → -5.30
// Ivo: 3.25 → 1.15 → 5.30
const maraX = -3.25 + 2.10 * approach - 4.15 * departure;
const ivoX = 3.25 - 2.10 * approach + 4.15 * departure;
const approachWalk =
t >= APPROACH_START && t <= APPROACH_END
? Math.sin(
Math.PI * ((t - APPROACH_START) / (APPROACH_END - APPROACH_START))
)
: 0;
const departureWalk =
t >= DEPART_START && t <= DEPART_END
? Math.sin(
Math.PI * ((t - DEPART_START) / (DEPART_END - DEPART_START))
)
: 0;
const walk = Math.min(1, approachWalk + departureWalk);
const cycle = Math.sin(t * 9.2);
mara.root.position.set(
maraX,
0.045 * walk * Math.abs(cycle),
0
);
ivo.root.position.set(
ivoX,
0.045 * walk * Math.abs(cycle),
0
);
const legSwing = cycle * 0.46 * walk;
const oppositeSwing = -cycle * 0.46 * walk;
mara.legs[0].rotation.x = legSwing;
mara.legs[1].rotation.x = oppositeSwing;
ivo.legs[0].rotation.x = oppositeSwing;
ivo.legs[1].rotation.x = legSwing;
// Mara's right arm presents the parcel.
const offer = smoothstep(OFFER_START, HANDOFF_START, t);
const maraRetract = smoothstep(6.15, 7.45, t);
let maraRightAngle = lerp(-0.06, -1.48, offer);
maraRightAngle = lerp(maraRightAngle, -0.06, maraRetract);
mara.leftArm.pivot.rotation.x = -oppositeSwing * 0.42;
mara.rightArm.pivot.rotation.x = maraRightAngle;
// Ivo's left arm reaches for and then carries the same parcel.
const reach = smoothstep(3.1, HANDOFF_START, t);
const settle = smoothstep(HANDOFF_END, 7.8, t);
let ivoLeftAngle = lerp(-0.06, -1.48, reach);
ivoLeftAngle = lerp(ivoLeftAngle, -1.18, settle);
ivo.leftArm.pivot.rotation.x = ivoLeftAngle;
ivo.rightArm.pivot.rotation.x = legSwing * 0.42;
mara.root.updateMatrixWorld(true);
ivo.root.updateMatrixWorld(true);
mara.rightArm.anchor.getWorldPosition(maraHand);
ivo.leftArm.anchor.getWorldPosition(ivoHand);
// Parcel movement is continuous. It is never recreated or recolored.
if (t < HANDOFF_START) {
parcelTarget.copy(maraHand);
} else if (t < HANDOFF_END) {
const handoff = (t - HANDOFF_START) / (HANDOFF_END - HANDOFF_START);
if (handoff < 0.5) {
parcelTarget.lerpVectors(
maraHand,
handoffMidpoint,
handoff * 2
);
} else {
parcelTarget.lerpVectors(
handoffMidpoint,
ivoHand,
(handoff - 0.5) * 2
);
}
} else {
parcelTarget.copy(ivoHand);
}
parcel.position.copy(parcelTarget);
// The relation changes at the midpoint; the object identity does not.
setHolder(t >= HANDOFF_MID ? "ivo" : "mara");
const holder = currentHolderId === "mara" ? mara : ivo;
holderRing.position.set(holder.root.position.x, 0.085, holder.root.position.z);
updateCaptionAndStatus(t);
}
// ------------------------------------------------------------------
// Projected DOM labels
// ------------------------------------------------------------------
function projectLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
if (!visible) {
element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = "1";
}
function updateLabels() {
projectLabel(
parcelLabel,
parcel.position.clone().add(new THREE.Vector3(0, 1.15, 0))
);
projectLabel(
maraLabel,
mara.root.position.clone().add(new THREE.Vector3(0, 3.0, 0))
);
projectLabel(
ivoLabel,
ivo.root.position.clone().add(new THREE.Vector3(0, 3.0, 0))
);
projectLabel(crateLabel, new THREE.Vector3(-5.8, 1.55, -3.35));
projectLabel(mailboxLabel, new THREE.Vector3(5.75, 2.25, -3.35));
}
// ------------------------------------------------------------------
// Camera controls implemented directly, without addons
// ------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.1, 0);
let cameraYaw = 0.38;
let cameraPitch = 0.48;
let cameraRadius = 17.5;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
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);
}
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;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraYaw -= dx * 0.006;
cameraPitch = clamp(cameraPitch + dy * 0.005, 0.18, 1.12);
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = clamp(cameraRadius + event.deltaY * 0.012, 10, 27);
},
{ passive: false }
);
// ------------------------------------------------------------------
// Playback controls
// ------------------------------------------------------------------
function replay() {
timeline = 0;
paused = false;
pauseButton.textContent = "Pause";
setHolder("mara");
}
replayButton.addEventListener("click", replay);
pauseButton.addEventListener("click", () => {
if (timeline >= DURATION) {
replay();
return;
}
paused = !paused;
pauseButton.textContent = paused ? "Play" : "Pause";
});
scrub.addEventListener("input", () => {
timeline = Number(scrub.value);
paused = true;
pauseButton.textContent = "Play";
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
replay();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ------------------------------------------------------------------
// Main loop
// ------------------------------------------------------------------
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) {
timeline = Math.min(DURATION, timeline + delta);
}
updateCamera();
updateScene(timeline);
renderer.render(scene, camera);
updateLabels();
scrub.value = timeline.toFixed(2);
timelineValue.textContent = `${timeline.toFixed(1)} / ${DURATION.toFixed(1)} s`;
requestAnimationFrame(animate);
}
setHolder("mara");
updateCamera();
requestAnimationFrame(animate);
</script>
</body>
</html>
```