Prompt specification
Build or customize the Three.js 3D scene "Two-person collection handoff" 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-person collection handoff
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-person-collection-handoff-x3886
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts cooperative neighborhood cleanup. Animate one volunteer gathering paper while another holds its collection bag; each item remains visible until deposited and the bag count updates once per transfer. Voxel style.
Working Three.js Starter (two-person-collection-handoff-x3886):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Neighborhood Cleanup</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9fd5e5;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 20px 22px;
color: #173b42;
background: rgba(255, 250, 232, 0.9);
border: 3px solid rgba(23, 59, 66, 0.12);
border-radius: 20px;
box-shadow: 0 14px 40px rgba(29, 70, 75, 0.16);
backdrop-filter: blur(10px);
}
.eyebrow {
margin-bottom: 6px;
color: #d06439;
font-size: 11px;
font-weight: 900;
letter-spacing: 0.18em;
}
h1 {
margin: 0;
font-size: clamp(24px, 4vw, 34px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin: 10px 0 0;
color: #557077;
font-size: 13px;
line-height: 1.45;
}
.status {
display: flex;
align-items: center;
gap: 9px;
margin-top: 15px;
padding-top: 13px;
border-top: 2px solid rgba(23, 59, 66, 0.1);
color: #294d53;
font-size: 12px;
font-weight: 700;
line-height: 1.35;
}
.status-dot {
flex: 0 0 auto;
width: 9px;
height: 9px;
border-radius: 2px;
background: #ed8b45;
box-shadow: 0 0 0 4px rgba(237, 139, 69, 0.16);
}
.counter {
position: absolute;
top: 24px;
right: 24px;
min-width: 160px;
padding: 15px 18px;
color: #173b42;
background: rgba(255, 250, 232, 0.92);
border: 3px solid rgba(23, 59, 66, 0.12);
border-radius: 18px;
box-shadow: 0 14px 40px rgba(29, 70, 75, 0.16);
backdrop-filter: blur(10px);
text-align: right;
}
.counter small {
display: block;
margin-bottom: 2px;
color: #6a7f83;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
}
.counter strong {
display: flex;
align-items: baseline;
justify-content: flex-end;
gap: 6px;
font-size: 14px;
}
.counter #count {
color: #d06439;
font-size: 36px;
line-height: 1;
}
.pips {
display: flex;
justify-content: flex-end;
gap: 5px;
margin-top: 9px;
}
.pip {
width: 18px;
height: 6px;
border-radius: 2px;
background: #d8ddd2;
transition: background 180ms ease, transform 180ms ease;
}
.pip.current {
background: #ed8b45;
transform: scaleY(1.35);
}
.pip.done {
background: #438b62;
}
.counter.pulse {
animation: counterPulse 450ms ease;
}
@keyframes counterPulse {
0% { transform: scale(1); }
45% { transform: scale(1.08) rotate(1deg); }
100% { transform: scale(1); }
}
.controls {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
padding: 9px 14px;
color: rgba(23, 59, 66, 0.82);
background: rgba(255, 250, 232, 0.78);
border: 2px solid rgba(23, 59, 66, 0.08);
border-radius: 999px;
font-size: 11px;
font-weight: 750;
white-space: nowrap;
backdrop-filter: blur(8px);
}
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.subtitle {
display: none;
}
.status {
margin-top: 11px;
padding-top: 10px;
}
.counter {
top: auto;
right: 12px;
bottom: 58px;
min-width: 130px;
padding: 11px 14px;
}
.counter #count {
font-size: 29px;
}
.controls {
bottom: 12px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div class="hud">
<section class="title-card">
<div class="eyebrow">BLOCK BY BLOCK</div>
<h1>Neighborhood cleanup</h1>
<p class="subtitle">
One volunteer gathers each sheet while a teammate keeps the collection bag open.
</p>
<div class="status">
<span class="status-dot"></span>
<span id="status">A volunteer is reaching for a sheet of paper.</span>
</div>
</section>
<section class="counter" id="counter">
<small>COLLECTION BAG</small>
<strong>
<span id="count">0</span>
<span>/ 4 papers</span>
</strong>
<div class="pips" id="pips" aria-label="Transfer progress"></div>
</section>
<div class="controls">Drag to orbit · Scroll to zoom · Arrow keys to rotate</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 and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9fd5e5);
scene.fog = new THREE.Fog(0x9fd5e5, 16, 31);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 4.5, -4.5, 0.1, 80);
const hemisphere = new THREE.HemisphereLight(0xdff5ff, 0x78924e, 2.35);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xfff0ce, 3.4);
sunlight.position.set(-7, 12, 7);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -12;
sunlight.shadow.camera.right = 12;
sunlight.shadow.camera.top = 12;
sunlight.shadow.camera.bottom = -12;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 35;
sunlight.shadow.bias = -0.0005;
scene.add(sunlight);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0
})
);
}
return materialCache.get(color);
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
color instanceof THREE.Material ? color : material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(parent, x = 0, y = 0, z = 0) {
const result = new THREE.Group();
result.position.set(x, y, z);
parent.add(result);
return result;
}
// -------------------------------------------------------------------------
// Voxel neighborhood
// -------------------------------------------------------------------------
const world = group(scene);
box(world, 18, 0.4, 14, 0x78ad59, 0, -0.22, 0);
box(world, 11.5, 0.08, 4.4, 0xd8c9a6, 0, 0.02, 1.35);
box(world, 18, 0.08, 2.25, 0x566168, 0, 0.015, -3.35);
box(world, 18, 0.14, 0.22, 0xe1ddd2, 0, 0.06, -2.12);
// Sidewalk seams.
for (let x = -5; x <= 5; x += 1) {
box(world, 0.025, 0.012, 4.35, 0xb9aa8b, x, 0.068, 1.35);
}
for (const z of [-0.25, 1.35, 3]) {
box(world, 11.4, 0.012, 0.025, 0xb9aa8b, 0, 0.068, z);
}
// Road markings.
for (let x = -7.5; x <= 7.5; x += 2.4) {
box(world, 1.1, 0.025, 0.12, 0xf0dfa1, x, 0.075, -3.35);
}
function makeHouse(x, z, w, h, d, wallColor, roofColor) {
const house = group(world, x, 0, z);
box(house, w, h, d, wallColor, 0, h / 2 + 0.06, 0);
box(house, w + 0.18, 0.18, d + 0.18, roofColor, 0, h + 0.14, 0);
box(house, w * 0.72, 0.18, d * 0.75, roofColor, 0, h + 0.3, 0);
box(house, 0.45, 0.9, 0.08, 0x557779, 0, 0.52, d / 2 + 0.045);
box(house, 0.06, 0.08, 0.05, 0xf1d47b, 0.14, 0.52, d / 2 + 0.1);
for (const side of [-1, 1]) {
box(
house,
0.52,
0.58,
0.06,
0x95d3dc,
side * w * 0.29,
h * 0.63,
d / 2 + 0.04
);
box(
house,
0.55,
0.06,
0.08,
0xf6f1dc,
side * w * 0.29,
h * 0.63,
d / 2 + 0.07
);
box(
house,
0.06,
0.61,
0.08,
0xf6f1dc,
side * w * 0.29,
h * 0.63,
d / 2 + 0.07
);
}
box(house, 0.65, 0.8, 0.65, 0x9e7564, w * 0.22, h + 0.65, -d * 0.1);
}
makeHouse(-5.3, -5.3, 2.5, 2.5, 2.2, 0xe9b985, 0xb85f4b);
makeHouse(-2.3, -5.45, 2.65, 3.1, 2.35, 0xf0d79b, 0x668b83);
makeHouse(1.15, -5.35, 2.45, 2.65, 2.2, 0xc7d3b2, 0xb85f4b);
makeHouse(4.65, -5.4, 2.85, 3.25, 2.4, 0xe9b0a0, 0x536e7b);
function makeTree(x, z, scale = 1) {
const tree = group(world, x, 0.04, z);
box(tree, 0.38 * scale, 1.7 * scale, 0.38 * scale, 0x79553c, 0, 0.85 * scale, 0);
box(tree, 1.65 * scale, 1.2 * scale, 1.55 * scale, 0x438957, 0, 2.05 * scale, 0);
box(tree, 1.2 * scale, 0.85 * scale, 1.2 * scale, 0x5ba867, -0.35 * scale, 2.8 * scale, 0.05);
box(tree, 1.1 * scale, 0.8 * scale, 1.05 * scale, 0x70b66f, 0.5 * scale, 2.7 * scale, -0.1);
}
makeTree(-6.2, 1.5, 1.08);
makeTree(6.1, 1.0, 1.12);
makeTree(-6.5, -1.4, 0.72);
makeTree(5.8, -1.5, 0.74);
function makeBench(x, z, rotation = 0) {
const bench = group(world, x, 0.06, z);
bench.rotation.y = rotation;
box(bench, 1.65, 0.16, 0.48, 0xa96f43, 0, 0.55, 0);
box(bench, 1.65, 0.48, 0.13, 0xb77a49, 0, 0.92, -0.22);
box(bench, 0.14, 0.55, 0.42, 0x4d6663, -0.62, 0.26, 0);
box(bench, 0.14, 0.55, 0.42, 0x4d6663, 0.62, 0.26, 0);
}
makeBench(-4.5, 2.85, -0.08);
makeBench(4.5, 2.85, 0.08);
// Voxel flower patches.
for (const [x, z, color] of [
[-5.7, 3.6, 0xf29c72],
[-5.15, 3.9, 0xf5d05f],
[5.2, 3.5, 0xe77d89],
[5.7, 3.75, 0xf5d05f],
[-3.8, -0.9, 0xf4cf60],
[4.0, -1.0, 0xf08b68]
]) {
box(world, 0.05, 0.35, 0.05, 0x4f8d52, x, 0.24, z);
box(world, 0.2, 0.14, 0.2, color, x, 0.44, z);
}
// Blocky clouds.
const clouds = [];
function makeCloud(x, y, z, scale) {
const cloud = group(world, x, y, z);
box(cloud, 1.5 * scale, 0.45 * scale, 0.6 * scale, 0xf4fbff, 0, 0, 0);
box(cloud, 0.75 * scale, 0.75 * scale, 0.6 * scale, 0xf4fbff, -0.55 * scale, 0.2 * scale, 0);
box(cloud, 0.95 * scale, 0.85 * scale, 0.6 * scale, 0xf4fbff, 0.35 * scale, 0.18 * scale, 0);
clouds.push({ mesh: cloud, speed: 0.08 + Math.random() * 0.05 });
}
makeCloud(-6.5, 6.3, -5.8, 1.15);
makeCloud(0.1, 7.1, -7.0, 0.95);
makeCloud(6.4, 5.9, -6.2, 1.25);
box(world, 1.15, 1.15, 0.38, 0xffd96b, 5.9, 6.5, -7.2);
// -------------------------------------------------------------------------
// Voxel volunteers
// -------------------------------------------------------------------------
function createCharacter(x, z, shirtColor, pantsColor, skinColor, capColor) {
const root = group(world, x, 0.08, z);
const legs = [];
for (const side of [-1, 1]) {
const leg = group(root, side * 0.18, 0.82, 0);
box(leg, 0.23, 0.58, 0.27, pantsColor, 0, -0.28, 0);
box(leg, 0.29, 0.16, 0.4, 0x354547, 0, -0.64, 0.08);
legs.push(leg);
}
box(root, 0.66, 0.73, 0.44, shirtColor, 0, 1.18, 0);
box(root, 0.54, 0.56, 0.53, skinColor, 0, 1.9, 0.015);
box(root, 0.58, 0.14, 0.57, capColor, 0, 2.2, 0.005);
box(root, 0.5, 0.08, 0.2, capColor, 0, 2.13, 0.32);
// Face.
box(root, 0.065, 0.075, 0.035, 0x26363a, -0.12, 1.96, 0.284);
box(root, 0.065, 0.075, 0.035, 0x26363a, 0.12, 1.96, 0.284);
box(root, 0.18, 0.04, 0.035, 0x8f5147, 0, 1.8, 0.286);
box(root, 0.16, 0.16, 0.13, skinColor, 0, 1.9, 0.315);
// Volunteer badge.
box(root, 0.16, 0.16, 0.035, 0xffe49b, -0.17, 1.34, 0.237);
return { root, legs };
}
function staticArm(root, x, color) {
box(root, 0.2, 0.63, 0.22, color, x, 1.16, 0);
box(root, 0.22, 0.22, 0.24, color, x, 0.82, 0.02);
}
const Y_AXIS = new THREE.Vector3(0, 1, 0);
function orientBone(mesh, a, b) {
const direction = b.clone().sub(a);
const length = direction.length();
direction.normalize();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction);
mesh.scale.set(1, length, 1);
}
function createArm(root, shoulder, side, color) {
const upperLength = 0.76;
const lowerLength = 0.76;
const upper = box(root, 0.19, 1, 0.2, color);
const lower = box(root, 0.17, 1, 0.18, color);
const joint = box(root, 0.22, 0.22, 0.22, color);
const hand = box(root, 0.23, 0.23, 0.24, color);
function update(target) {
const delta = target.clone().sub(shoulder);
const actualDistance = Math.max(delta.length(), 0.001);
const direction = delta.clone().normalize();
const distance = Math.min(actualDistance, upperLength + lowerLength - 0.001);
const along =
(upperLength * upperLength - lowerLength * lowerLength + distance * distance) /
(2 * distance);
const height = Math.sqrt(Math.max(0, upperLength * upperLength - along * along));
const bend = new THREE.Vector3(side, 0, 0);
bend.addScaledVector(direction, -bend.dot(direction));
if (bend.lengthSq() < 0.0001) {
bend.set(0, 0, side);
bend.addScaledVector(direction, -bend.dot(direction));
}
bend.normalize();
const elbow = shoulder
.clone()
.addScaledVector(direction, along)
.addScaledVector(bend, height);
const reachableTarget = shoulder.clone().addScaledVector(direction, distance);
orientBone(upper, shoulder, elbow);
orientBone(lower, elbow, reachableTarget);
joint.position.copy(elbow);
hand.position.copy(reachableTarget);
}
return { update };
}
const picker = createCharacter(
-1.9,
1.18,
0x317f78,
0x334e68,
0xc9825c,
0xf0a448
);
staticArm(picker.root, -0.44, 0xc9825c);
const pickerArm = createArm(
picker.root,
new THREE.Vector3(0.48, 1.48, 0),
1,
0xc9825c
);
const holder = createCharacter(
2.45,
1.05,
0xd86442,
0x59655e,
0xf0bd8e,
0x385d77
);
staticArm(holder.root, 0.44, 0xf0bd8e);
const holderArm = createArm(
holder.root,
new THREE.Vector3(-0.48, 1.48, 0),
-1,
0xf0bd8e
);
// -------------------------------------------------------------------------
// Open collection bag and its live count label
// -------------------------------------------------------------------------
const bag = group(holder.root, -0.9, 0.42, 0.2);
const bagMaterial = material(0xe88742);
// Bottom and four walls leave the top visibly open.
box(bag, 0.72, 0.1, 0.52, 0xb95c2f, 0, 0.05, 0);
box(bag, 0.72, 0.72, 0.08, bagMaterial, 0, 0.42, 0.22);
box(bag, 0.72, 0.72, 0.08, bagMaterial, 0, 0.42, -0.22);
box(bag, 0.08, 0.72, 0.44, bagMaterial, -0.32, 0.42, 0);
box(bag, 0.08, 0.72, 0.44, bagMaterial, 0.32, 0.42, 0);
box(bag, 0.6, 0.06, 0.39, 0x5c3928, 0, 0.12, 0);
// Handle.
box(bag, 0.08, 0.3, 0.09, 0x9f512c, -0.25, 0.92, 0);
box(bag, 0.08, 0.3, 0.09, 0x9f512c, 0.25, 0.92, 0);
box(bag, 0.58, 0.08, 0.09, 0x9f512c, 0, 1.07, 0);
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 256;
labelCanvas.height = 160;
const labelContext = labelCanvas.getContext("2d");
const labelTexture = new THREE.CanvasTexture(labelCanvas);
labelTexture.colorSpace = THREE.SRGBColorSpace;
const label = new THREE.Mesh(
new THREE.PlaneGeometry(0.5, 0.32),
new THREE.MeshBasicMaterial({ map: labelTexture })
);
label.position.set(0, 0.45, 0.266);
bag.add(label);
function drawBagCount(count) {
labelContext.clearRect(0, 0, 256, 160);
labelContext.fillStyle = "#fff5d8";
labelContext.fillRect(0, 0, 256, 160);
labelContext.fillStyle = "#315358";
labelContext.textAlign = "center";
labelContext.font = "900 27px sans-serif";
labelContext.fillText("PAPERS", 128, 42);
labelContext.fillStyle = "#d06439";
labelContext.font = "900 84px sans-serif";
labelContext.fillText(String(count), 128, 128);
labelTexture.needsUpdate = true;
}
drawBagCount(0);
// -------------------------------------------------------------------------
// Four paper items. Each remains visible until its actual deposit.
// -------------------------------------------------------------------------
const paperColors = [0xf4d85f, 0x72b7c8, 0xef8b73, 0x9fc37a];
const itemSpecs = [
[-1.42, 1.18],
[-1.55, 0.82],
[-1.18, 1.42],
[-1.57, 1.42]
];
const items = itemSpecs.map(([x, z], index) => {
const mesh = group(scene, x, 0.085, z);
const rotation = (index - 1.5) * 0.21;
mesh.rotation.y = rotation;
box(mesh, 0.34, 0.035, 0.25, 0xfffdf0);
box(mesh, 0.21, 0.016, 0.065, paperColors[index], 0, 0.027, 0.01);
box(mesh, 0.07, 0.018, 0.055, 0x8fa4a2, -0.1, 0.028, -0.07);
return {
mesh,
home: new THREE.Vector3(x, 0.085, z),
homeRotation: rotation
};
});
// -------------------------------------------------------------------------
// Cleanup transfer state machine
// -------------------------------------------------------------------------
const statusElement = document.getElementById("status");
const countElement = document.getElementById("count");
const counterElement = document.getElementById("counter");
const pipsElement = document.getElementById("pips");
const pips = items.map(() => {
const pip = document.createElement("span");
pip.className = "pip";
pipsElement.appendChild(pip);
return pip;
});
let collectedCount = 0;
let transferPhase = "reach";
let transferTime = 0;
let activeIndex = 0;
let nextIndex = 0;
const restHand = new THREE.Vector3(0.45, 0.73, 0.04);
let handTarget = restHand.clone();
let carryStartRoot = picker.root.position.clone();
let liftStart = new THREE.Vector3();
let carryStart = new THREE.Vector3();
let carryEnd = new THREE.Vector3();
let carryControl = new THREE.Vector3();
let depositRoot = new THREE.Vector3();
const ease = (t) => {
const x = THREE.MathUtils.clamp(t, 0, 1);
return x * x * (3 - 2 * x);
};
const lerp = THREE.MathUtils.lerp;
function setStatus(message) {
statusElement.textContent = message;
}
function updatePips() {
pips.forEach((pip, index) => {
pip.classList.toggle("done", index < collectedCount);
pip.classList.toggle(
"current",
index === activeIndex && transferPhase !== "done"
);
});
}
function itemLocalPosition(item) {
return item.home.clone().sub(picker.root.position);
}
function beginReach(index) {
activeIndex = index;
transferPhase = "reach";
transferTime = 0;
handTarget.copy(restHand);
setStatus("A volunteer is reaching for a sheet of paper.");
updatePips();
}
function completeTransfer() {
// This is the only function that changes the collection count.
items[activeIndex].mesh.visible = false;
collectedCount += 1;
countElement.textContent = String(collectedCount);
drawBagCount(collectedCount);
counterElement.classList.remove("pulse");
void counterElement.offsetWidth;
counterElement.classList.add("pulse");
setStatus(
`Transfer complete. The bag now holds ${collectedCount} ${
collectedCount === 1 ? "paper" : "papers"
}.`
);
updatePips();
if (activeIndex < items.length - 1) {
nextIndex = activeIndex + 1;
transferPhase = "return";
transferTime = 0;
setStatus("The volunteer is moving to the next piece of litter.");
} else {
transferPhase = "done";
handTarget.copy(restHand);
setStatus("Cleanup complete. Every sheet is safely in the collection bag.");
updatePips();
}
}
function quadraticBezier(a, b, c, t) {
const inverse = 1 - t;
return new THREE.Vector3()
.addScaledVector(a, inverse * inverse)
.addScaledVector(b, 2 * inverse * t)
.addScaledVector(c, t * t);
}
function updateTransfer(dt, bagMouth) {
transferTime += dt;
if (transferPhase === "return") {
const t = ease(transferTime / 1.15);
const target = items[nextIndex].home
.clone()
.sub(new THREE.Vector3(0.48, 0, 0));
picker.root.position.lerpVectors(
picker.root.position,
target,
0.055
);
// The explicit interpolation above is replaced with a stable start/end
// interpolation when the return starts.
const start = picker.root.userData.returnStart;
if (start) {
picker.root.position.lerpVectors(start, target, t);
}
picker.legs[0].rotation.z = Math.sin(transferTime * 12) * 0.22;
picker.legs[1].rotation.z = -Math.sin(transferTime * 12) * 0.22;
handTarget.copy(restHand);
if (transferTime >= 1.15) {
picker.root.position.copy(target);
beginReach(nextIndex);
}
return;
}
const item = items[activeIndex];
if (transferPhase === "reach") {
const t = ease(transferTime / 0.75);
const target = itemLocalPosition(item);
target.y += 0.08;
handTarget.lerpVectors(restHand, target, t);
if (transferTime >= 0.75) {
transferPhase = "lift";
transferTime = 0;
liftStart.copy(item.mesh.position);
setStatus("Paper gathered — carrying it to the open bag.");
}
} else if (transferPhase === "lift") {
const t = ease(transferTime / 0.65);
item.mesh.position.lerpVectors(
liftStart,
liftStart.clone().add(new THREE.Vector3(0, 0.78, 0)),
t
);
item.mesh.rotation.z = Math.sin(t * Math.PI) * 0.08;
handTarget.copy(item.mesh.position).sub(picker.root.position);
handTarget.y += 0.04;
if (transferTime >= 0.65) {
transferPhase = "carry";
transferTime = 0;
carryStartRoot.copy(picker.root.position);
carryStart.copy(item.mesh.position);
carryEnd.copy(bagMouth).add(new THREE.Vector3(0, 0.85, 0));
carryControl.copy(carryStart).add(carryEnd).multiplyScalar(0.5);
carryControl.y += 1.0;
depositRoot.set(bagMouth.x - 1.28, 0.08, bagMouth.z);
}
} else if (transferPhase === "carry") {
const t = ease(transferTime / 1.35);
item.mesh.position.copy(
quadraticBezier(carryStart, carryControl, carryEnd, t)
);
item.mesh.rotation.z = Math.sin(t * Math.PI * 2) * 0.1;
item.mesh.rotation.y =
item.homeRotation + Math.sin(t * Math.PI * 2) * 0.13;
picker.root.position.lerpVectors(carryStartRoot, depositRoot, t);
picker.legs[0].rotation.z = Math.sin(transferTime * 13) * 0.32;
picker.legs[1].rotation.z = -Math.sin(transferTime * 13) * 0.32;
handTarget.copy(item.mesh.position).sub(picker.root.position);
handTarget.y += 0.04;
if (transferTime >= 1.35) {
transferPhase = "lower";
transferTime = 0;
carryEnd.copy(item.mesh.position);
setStatus("Careful — lowering the paper into the open bag.");
}
} else if (transferPhase === "lower") {
const t = ease(transferTime / 0.55);
const inside = bag.localToWorld(new THREE.Vector3(0, 0.67, 0));
item.mesh.position.lerpVectors(carryEnd, inside, t);
item.mesh.scale.setScalar(lerp(1, 0.72, t));
item.mesh.rotation.z = lerp(item.mesh.rotation.z, 0, t * 0.4);
handTarget.copy(item.mesh.position).sub(picker.root.position);
handTarget.y += 0.04;
picker.legs[0].rotation.z *= 0.8;
picker.legs[1].rotation.z *= 0.8;
if (transferTime >= 0.55) {
completeTransfer();
}
} else if (transferPhase === "done") {
handTarget.copy(restHand);
}
}
// Position the picker for the first item and remember a return origin.
picker.root.position.copy(
items[0].home.clone().sub(new THREE.Vector3(0.48, 0, 0))
);
picker.root.position.y = 0.08;
picker.root.userData.returnStart = picker.root.position.clone();
beginReach(0);
// -------------------------------------------------------------------------
// Direct camera controls: no addons or examples modules are used.
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.9, 0);
let cameraTheta = 0.65;
let cameraPhi = 0.96;
let cameraZoom = 1;
let cameraRadius = 15;
function updateCamera() {
camera.position.set(
cameraTarget.x +
cameraRadius * Math.sin(cameraPhi) * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z +
cameraRadius * Math.sin(cameraPhi) * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const verticalView = aspect < 1 ? 10.5 : 8.6;
camera.left = (-verticalView * aspect) / 2;
camera.right = (verticalView * aspect) / 2;
camera.top = verticalView / 2;
camera.bottom = -verticalView / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
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 deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + deltaY * 0.005,
0.42,
1.38
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.7
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") cameraTheta += 0.12;
else if (event.key === "ArrowRight") cameraTheta -= 0.12;
else if (event.key === "ArrowUp")
cameraPhi = Math.max(0.42, cameraPhi - 0.08);
else if (event.key === "ArrowDown")
cameraPhi = Math.min(1.38, cameraPhi + 0.08);
else return;
updateCamera();
});
window.addEventListener("resize", resize);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const bagHandleLocal = new THREE.Vector3(-0.9, 1.49, 0.2);
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
// Gentle environmental movement.
for (const cloud of clouds) {
cloud.mesh.position.x += cloud.speed * dt;
if (cloud.mesh.position.x > 9) cloud.mesh.position.x = -9;
}
// The bag is held by the second volunteer and moves subtly with their hand.
bag.position.y = 0.42 + Math.sin(elapsed * 2.1) * 0.018;
holderArm.update(bagHandleLocal);
scene.updateMatrixWorld(true);
const bagMouth = bag.localToWorld(new THREE.Vector3(0, 0.82, 0));
// Capture the return start position before the first return update.
if (transferPhase === "return" && transferTime <= dt) {
picker.root.userData.returnStart = picker.root.position.clone();
}
updateTransfer(dt, bagMouth);
pickerArm.update(handTarget);
// Gentle idle breathing.
picker.root.position.y =
0.08 + Math.sin(elapsed * 2.4) * 0.006;
holder.root.position.y =
0.08 + Math.sin(elapsed * 2.1 + 1) * 0.006;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```