Prompt specification
Build or customize the Three.js 3D scene "Baton Between Two Hand Proxies" 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: Baton Between Two Hand Proxies
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/baton-between-two-hand-proxies-x3633
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: baton between two hand proxies. Model two hand proxies and one baton with distinct ownership markers. Show a valid overlapping grip interval without duplicating the baton during transfer.
Working Three.js Starter (baton-between-two-hand-proxies-x3633):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Single Baton Transfer</title>
<style>
:root {
--cyan: #28d9e8;
--amber: #ff9f43;
--ink: #eaf5fa;
--muted: #91a8b4;
--panel: rgba(9, 18, 26, 0.84);
--line: rgba(159, 202, 218, 0.2);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0b141c;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
.info-panel {
top: 20px;
left: 20px;
width: min(410px, calc(100vw - 40px));
padding: 18px;
border-radius: 14px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 4vw, 36px);
line-height: 1.02;
letter-spacing: -0.04em;
}
.intro {
margin: 10px 0 15px;
color: #b6c8d0;
font-size: 13px;
line-height: 1.5;
}
.status-row {
display: grid;
grid-template-columns: auto 1fr;
gap: 12px;
align-items: center;
padding: 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
#phase-code {
display: grid;
width: 48px;
height: 48px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 10px;
color: #d8e9ef;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.06em;
}
#status-title {
margin-bottom: 3px;
font-size: 13px;
font-weight: 850;
letter-spacing: 0.035em;
}
#status-detail {
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.owner-row {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 12px;
}
.owner {
display: flex;
gap: 7px;
align-items: center;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 999px;
color: #728995;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
transition: 180ms ease;
}
.owner .dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 0 transparent;
}
.owner.left {
color: var(--cyan);
}
.owner.right {
color: var(--amber);
}
.owner.grip-active {
border-color: currentColor;
color: #dce8ed;
}
.owner.grip-active .dot {
background: currentColor;
box-shadow: 0 0 13px currentColor;
}
.owner.owner-active {
background: rgba(255, 255, 255, 0.07);
color: currentColor;
}
.instance-chip {
margin-left: auto;
color: #9eb4bf;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
}
.timeline-panel {
left: 50%;
bottom: 20px;
width: min(790px, calc(100vw - 40px));
padding: 15px 17px 13px;
border-radius: 14px;
transform: translateX(-50%);
pointer-events: auto;
}
.timeline-head {
display: flex;
justify-content: space-between;
gap: 16px;
align-items: center;
margin-bottom: 11px;
}
.timeline-title {
font-size: 11px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.overlap-readout {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
}
.track {
position: relative;
height: 13px;
overflow: visible;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 999px;
background: #182731;
}
.zone {
position: absolute;
top: 0;
bottom: 0;
}
.zone.left {
left: 0;
border-radius: 999px 0 0 999px;
background: linear-gradient(90deg, rgba(40, 217, 232, 0.52), rgba(40, 217, 232, 0.12));
}
.zone.overlap {
background: linear-gradient(
90deg,
rgba(40, 217, 232, 0.75),
rgba(255, 159, 67, 0.78)
);
}
.zone.right {
right: 0;
border-radius: 0 999px 999px 0;
background: linear-gradient(90deg, rgba(255, 159, 67, 0.12), rgba(255, 159, 67, 0.52));
}
.transfer-line {
position: absolute;
z-index: 3;
top: -5px;
bottom: -5px;
width: 1px;
background: #ffffff;
box-shadow: 0 0 9px rgba(255, 255, 255, 0.75);
}
#playhead {
position: absolute;
z-index: 4;
top: 50%;
left: 0;
width: 16px;
height: 16px;
border: 3px solid #f7fcff;
border-radius: 50%;
background: #162630;
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
transform: translate(-50%, -50%);
}
.time-labels {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #718995;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.05em;
}
.controls {
display: flex;
gap: 9px;
align-items: center;
margin-top: 12px;
}
button {
min-width: 78px;
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.17);
border-radius: 8px;
background: rgba(255, 255, 255, 0.06);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: 160ms ease;
}
button:hover {
border-color: rgba(255, 255, 255, 0.35);
background: rgba(255, 255, 255, 0.11);
}
#scrub {
width: 100%;
accent-color: #dcecf1;
cursor: pointer;
}
#time-readout {
min-width: 76px;
color: #b9cbd3;
font-size: 10px;
font-variant-numeric: tabular-nums;
text-align: right;
}
.camera-hint {
position: fixed;
z-index: 10;
right: 20px;
top: 20px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(9, 18, 26, 0.68);
color: #849ca8;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.07em;
pointer-events: none;
}
@media (max-width: 680px) {
.info-panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px;
}
.intro {
display: none;
}
.status-row {
padding: 9px;
}
#phase-code {
width: 42px;
height: 42px;
}
.timeline-panel {
bottom: 10px;
width: calc(100vw - 20px);
padding: 12px;
}
.camera-hint {
display: none;
}
.overlap-readout {
font-size: 9px;
}
.instance-chip {
width: 100%;
margin-left: 0;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section class="panel info-panel">
<div class="eyebrow">Transfer protocol / single entity</div>
<h1>One baton.<br />Two grips.</h1>
<p class="intro">
The baton mesh is never cloned. Ownership changes only during a valid
overlapping-grip interval, while both proxies hold the same object.
</p>
<div class="status-row" aria-live="polite">
<div id="phase-code">01</div>
<div>
<div id="status-title">LEFT SOLE OWNER</div>
<div id="status-detail">The right proxy is approaching the single baton.</div>
</div>
</div>
<div class="owner-row">
<div id="left-owner" class="owner left owner-active">
<span class="dot"></span>LEFT / CYAN
</div>
<div id="right-owner" class="owner right">
<span class="dot"></span>RIGHT / AMBER
</div>
<div class="instance-chip">BATON INSTANCES: 1</div>
</div>
</section>
<div class="camera-hint">DRAG TO ORBIT · WHEEL / PINCH TO ZOOM</div>
<section class="panel timeline-panel">
<div class="timeline-head">
<div class="timeline-title">Transfer timeline</div>
<div class="overlap-readout">VALID SHARED GRIP: 1.50–4.50 s</div>
</div>
<div class="track" id="track">
<div class="zone left" id="left-zone"></div>
<div class="zone overlap" id="overlap-zone"></div>
<div class="zone right" id="right-zone"></div>
<div class="transfer-line" id="transfer-line"></div>
<div id="playhead"></div>
</div>
<div class="time-labels">
<span>0.0 s</span>
<span>OWNER FLIP AT 3.0 s</span>
<span>8.5 s</span>
</div>
<div class="controls">
<button id="toggle" type="button">Pause</button>
<button id="restart" type="button">Restart</button>
<input
id="scrub"
type="range"
min="0"
max="8.5"
step="0.01"
value="0"
aria-label="Transfer timeline"
/>
<div id="time-readout">0.00 / 8.50</div>
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------
const host = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b141c);
scene.fog = new THREE.Fog(0x0b141c, 8, 18);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
50
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
host.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xb9e8ff, 0x182028, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.8);
keyLight.position.set(3.5, 7, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x72b8ff, 1.4);
rimLight.position.set(-5, 3, -4);
scene.add(rimLight);
const leftColor = new THREE.Color(0x28d9e8);
const rightColor = new THREE.Color(0xff9f43);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(4.6, 4.8, 0.16, 24),
new THREE.MeshStandardMaterial({
color: 0x14232d,
roughness: 0.9,
metalness: 0.05,
flatShading: true
})
);
platform.position.y = -1.58;
platform.receiveShadow = true;
scene.add(platform);
const grid = new THREE.GridHelper(9, 18, 0x355363, 0x233844);
grid.position.y = -1.485;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
// ------------------------------------------------------------
// One physical baton. This group is never cloned.
// ------------------------------------------------------------
const baton = new THREE.Group();
baton.position.y = 0.48;
const batonMaterial = new THREE.MeshStandardMaterial({
color: 0xe6edf0,
roughness: 0.38,
metalness: 0.18,
flatShading: true
});
const batonShaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.115, 0.115, 2.75, 8, 1, false),
batonMaterial
);
batonShaft.rotation.z = Math.PI / 2;
batonShaft.castShadow = true;
batonShaft.receiveShadow = true;
baton.add(batonShaft);
const capGeometry = new THREE.CylinderGeometry(0.145, 0.145, 0.13, 8);
const capMaterial = new THREE.MeshStandardMaterial({
color: 0x8ba2ad,
roughness: 0.42,
metalness: 0.3,
flatShading: true
});
for (const x of [-1.38, 1.38]) {
const cap = new THREE.Mesh(capGeometry, capMaterial);
cap.rotation.z = Math.PI / 2;
cap.position.x = x;
cap.castShadow = true;
baton.add(cap);
}
scene.add(baton);
// This collar is only an ownership marker, not another baton.
const ownerMarker = new THREE.Group();
ownerMarker.position.x = -1.02;
const ownerMaterial = new THREE.MeshStandardMaterial({
color: leftColor,
emissive: leftColor,
emissiveIntensity: 1.8,
roughness: 0.32,
metalness: 0.1,
flatShading: true
});
const ownerCollar = new THREE.Mesh(
new THREE.TorusGeometry(0.185, 0.036, 6, 18),
ownerMaterial
);
ownerCollar.rotation.y = Math.PI / 2;
ownerMarker.add(ownerCollar);
const ownerLight = new THREE.PointLight(leftColor, 0.65, 2.4);
ownerLight.position.set(0, 0.32, 0);
ownerMarker.add(ownerLight);
baton.add(ownerMarker);
// ------------------------------------------------------------
// Low-poly hand proxy construction
// ------------------------------------------------------------
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0xe4e0d6,
roughness: 0.78,
metalness: 0.02,
flatShading: true
});
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0x91a0a5,
roughness: 0.72,
metalness: 0.05,
flatShading: true
});
function makeLabelSprite(colorHex) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.3, 0.325, 1);
sprite.renderOrder = 20;
let lastKey = "";
function set(text, active = true) {
const key = `${text}|${active}`;
if (key === lastKey) return;
lastKey = key;
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = active
? "rgba(8, 17, 24, 0.94)"
: "rgba(8, 17, 24, 0.68)";
ctx.fillRect(4, 8, 504, 112);
ctx.strokeStyle = active ? colorHex : "rgba(135, 160, 171, 0.35)";
ctx.lineWidth = active ? 5 : 2;
ctx.strokeRect(4, 8, 504, 112);
ctx.font = "800 39px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = active ? colorHex : "rgba(151, 174, 184, 0.55)";
ctx.fillText(text, 256, 66);
texture.needsUpdate = true;
}
return { sprite, set };
}
function createHand(color, side) {
const group = new THREE.Group();
const accentMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.35,
roughness: 0.5,
metalness: 0.08,
flatShading: true
});
const palm = new THREE.Mesh(
new THREE.BoxGeometry(0.62, 0.45, 0.3),
skinMaterial
);
palm.position.set(0, -0.24, -0.07);
palm.castShadow = true;
palm.receiveShadow = true;
group.add(palm);
const wrist = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 0.38, 0.29),
jointMaterial
);
wrist.position.set(0, -0.55, -0.045);
wrist.castShadow = true;
group.add(wrist);
const forearm = new THREE.Mesh(
new THREE.BoxGeometry(0.36, 0.95, 0.31),
skinMaterial
);
forearm.position.set(0, -0.93, -0.045);
forearm.rotation.z = side * 0.16;
forearm.castShadow = true;
group.add(forearm);
const cuff = new THREE.Mesh(
new THREE.BoxGeometry(0.41, 0.18, 0.35),
accentMaterial
);
cuff.position.set(side * 0.025, -0.57, -0.045);
cuff.rotation.z = side * 0.16;
cuff.castShadow = true;
group.add(cuff);
const fingers = [];
for (const x of [-0.21, -0.07, 0.07, 0.21]) {
const pivot = new THREE.Group();
pivot.position.set(x, 0.015, 0);
const upper = new THREE.Mesh(
new THREE.BoxGeometry(0.115, 0.145, 0.31),
skinMaterial
);
upper.position.z = 0.145;
upper.castShadow = true;
pivot.add(upper);
const tip = new THREE.Mesh(
new THREE.BoxGeometry(0.105, 0.22, 0.115),
jointMaterial
);
tip.position.set(0, -0.035, 0.315);
tip.rotation.x = 0.24;
tip.castShadow = true;
pivot.add(tip);
group.add(pivot);
fingers.push(pivot);
}
// Distinct ground halo and floating ownership diamond.
const markerMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 1.2,
transparent: true,
opacity: 0.8,
roughness: 0.35,
flatShading: true
});
const groundHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.37, 0.042, 6, 18),
markerMaterial
);
groundHalo.rotation.x = Math.PI / 2;
groundHalo.position.y = -1.96;
group.add(groundHalo);
const diamond = new THREE.Mesh(
new THREE.OctahedronGeometry(0.14, 0),
markerMaterial
);
diamond.position.y = 0.91;
group.add(diamond);
const label = makeLabelSprite(`#${color.getHexString()}`);
label.sprite.position.y = 1.24;
group.add(label.sprite);
scene.add(group);
return {
group,
palm,
fingers,
markerMaterial,
groundHalo,
diamond,
label,
color
};
}
const leftHand = createHand(leftColor, -1);
const rightHand = createHand(rightColor, 1);
// ------------------------------------------------------------
// Direct camera controls: no addons or OrbitControls.
// ------------------------------------------------------------
const orbit = {
yaw: 0.52,
pitch: 0.34,
radius: 7.4,
target: new THREE.Vector3(0, 0.12, 0)
};
const pointers = new Map();
function updateCamera() {
const horizontal = orbit.radius * Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + Math.sin(orbit.yaw) * horizontal,
orbit.target.y + Math.sin(orbit.pitch) * orbit.radius,
orbit.target.z + Math.cos(orbit.yaw) * horizontal
);
camera.lookAt(orbit.target);
}
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const oldDistance = pointerDistance();
if (pointers.size === 1) {
orbit.yaw -= (event.clientX - previous.x) * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + (event.clientY - previous.y) * 0.0045,
0.05,
1.12
);
} else if (pointers.size === 2) {
previous.x = event.clientX;
previous.y = event.clientY;
const newDistance = pointerDistance();
if (oldDistance > 0 && newDistance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (oldDistance / newDistance),
4.2,
12.5
);
}
} else {
previous.x = event.clientX;
previous.y = event.clientY;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
4.2,
12.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.yaw = 0.52;
orbit.pitch = 0.34;
orbit.radius = 7.4;
});
window.addEventListener("keydown", (event) => {
const tag = document.activeElement?.tagName;
if (tag === "INPUT" || tag === "BUTTON") return;
if (event.key === "ArrowLeft") orbit.yaw -= 0.08;
if (event.key === "ArrowRight") orbit.yaw += 0.08;
if (event.key === "ArrowUp") orbit.pitch += 0.05;
if (event.key === "ArrowDown") orbit.pitch -= 0.05;
if (event.key === "+" || event.key === "=") orbit.radius -= 0.25;
if (event.key === "-") orbit.radius += 0.25;
if (event.key === " ") {
event.preventDefault();
togglePlayback();
}
});
// ------------------------------------------------------------
// Transfer protocol
//
// 0.00–1.50: left sole owner
// 1.50–4.50: both grips are valid on the same baton
// 3.00: nominal owner flips while the shared grip continues
// 4.50–5.15: left releases
// ------------------------------------------------------------
const TOTAL = 8.5;
const OVERLAP_START = 1.5;
const OVERLAP_END = 4.5;
const TRANSFER_AT = 3.0;
let time = 0;
let playing = true;
const phaseCode = document.getElementById("phase-code");
const statusTitle = document.getElementById("status-title");
const statusDetail = document.getElementById("status-detail");
const leftOwner = document.getElementById("left-owner");
const rightOwner = document.getElementById("right-owner");
const playhead = document.getElementById("playhead");
const timeReadout = document.getElementById("time-readout");
const toggleButton = document.getElementById("toggle");
const restartButton = document.getElementById("restart");
const scrubber = document.getElementById("scrub");
const leftZone = document.getElementById("left-zone");
const overlapZone = document.getElementById("overlap-zone");
const rightZone = document.getElementById("right-zone");
const transferLine = document.getElementById("transfer-line");
leftZone.style.width = `${(OVERLAP_START / TOTAL) * 100}%`;
overlapZone.style.left = `${(OVERLAP_START / TOTAL) * 100}%`;
overlapZone.style.width = `${((OVERLAP_END - OVERLAP_START) / TOTAL) * 100}%`;
rightZone.style.left = `${(OVERLAP_END / TOTAL) * 100}%`;
transferLine.style.left = `${(TRANSFER_AT / TOTAL) * 100}%`;
scrubber.max = TOTAL;
function setText(element, text) {
if (element.textContent !== text) element.textContent = text;
}
function smoothstep(a, b, value) {
const x = THREE.MathUtils.clamp((value - a) / (b - a), 0, 1);
return x * x * (3 - 2 * x);
}
function togglePlayback() {
if (time >= TOTAL) {
time = 0;
playing = true;
} else {
playing = !playing;
}
}
toggleButton.addEventListener("click", togglePlayback);
restartButton.addEventListener("click", () => {
time = 0;
playing = true;
});
scrubber.addEventListener("input", () => {
time = Number(scrubber.value);
playing = false;
});
function updateHand(hand, grip, active, labelText) {
hand.fingers.forEach((finger, index) => {
finger.rotation.x =
THREE.MathUtils.lerp(-0.58, 0.30, grip) +
Math.sin(index * 1.7) * 0.018 * (1 - grip);
});
hand.palm.position.z = THREE.MathUtils.lerp(-0.11, -0.025, grip);
const pulse = active
? 1 + Math.sin(time * 6.5 + hand.group.position.x) * 0.055
: 1;
hand.groundHalo.scale.setScalar(pulse);
hand.groundHalo.material.opacity = active ? 0.86 : 0.22;
hand.markerMaterial.emissiveIntensity = active ? 1.45 : 0.16;
hand.diamond.rotation.y = time * 1.4;
hand.diamond.rotation.x = Math.sin(time * 1.1) * 0.16;
hand.label.set(labelText, active);
}
function updateScene() {
// The right proxy approaches and closes its grip before the
// declared overlap interval begins.
const approach = smoothstep(0.15, 1.25, time);
const rightX = THREE.MathUtils.lerp(1.58, 1.02, approach);
const rightGrip = smoothstep(1.20, 1.50, time);
// The left proxy releases only after the overlap interval ends.
const leftGrip = 1 - smoothstep(4.50, 5.15, time);
const leftX = THREE.MathUtils.lerp(
-1.02,
-1.52,
smoothstep(4.50, 6.00, time)
);
leftHand.group.position.set(leftX, 0.48, 0);
rightHand.group.position.set(rightX, 0.48, 0);
const nominalOwner = time < TRANSFER_AT ? "left" : "right";
const ownerColor = nominalOwner === "left" ? leftColor : rightColor;
const leftActive = leftGrip > 0.45;
const rightActive = rightGrip > 0.45;
let leftLabel = "LEFT • OWNER";
let rightLabel = "RIGHT • SHARED";
if (time >= OVERLAP_START && time < TRANSFER_AT) {
leftLabel = "LEFT • OWNER";
rightLabel = "RIGHT • SHARED";
} else if (time >= TRANSFER_AT && time < OVERLAP_END) {
leftLabel = "LEFT • SHARED";
rightLabel = "RIGHT • OWNER";
} else if (time >= OVERLAP_END && time < 5.15) {
leftLabel = "LEFT • RELEASING";
rightLabel = "RIGHT • OWNER";
} else if (time >= 5.15) {
leftLabel = "LEFT • RELEASED";
rightLabel = "RIGHT • OWNER";
}
updateHand(leftHand, leftGrip, leftActive, leftLabel);
updateHand(rightHand, rightGrip, rightActive, rightLabel);
// The owner collar travels over the existing baton only.
// It never creates or duplicates the baton object.
const ownerProgress = smoothstep(
OVERLAP_START,
OVERLAP_END,
time
);
ownerMarker.position.x = THREE.MathUtils.lerp(
-1.02,
1.02,
ownerProgress
);
ownerMaterial.color.copy(ownerColor);
ownerMaterial.emissive.copy(ownerColor);
ownerLight.color.copy(ownerColor);
const transferPulse =
1 - Math.min(1, Math.abs(time - TRANSFER_AT) / 0.32);
ownerMarker.scale.setScalar(1 + transferPulse * 0.18);
// A subtle roll/settle communicates weight transfer without
// changing the baton count or spawning a second baton.
const overlapProgress = THREE.MathUtils.clamp(
(time - OVERLAP_START) / (OVERLAP_END - OVERLAP_START),
0,
1
);
const overlapBell = Math.sin(overlapProgress * Math.PI);
baton.position.y = 0.48 - overlapBell * 0.045;
baton.rotation.x =
Math.sin(overlapProgress * Math.PI * 2) *
overlapBell *
0.08;
// HUD state.
let code;
let title;
let detail;
if (time < OVERLAP_START) {
code = "01";
title = "LEFT SOLE OWNER";
detail = "The right proxy approaches the same baton.";
} else if (time < TRANSFER_AT) {
code = "02A";
title = "SHARED GRIP • LEFT OWNER";
detail = "Both grips are valid; ownership flips at the midpoint.";
} else if (time < OVERLAP_END) {
code = "02B";
title = "SHARED GRIP • RIGHT OWNER";
detail = "Ownership has flipped while the second grip remains valid.";
} else if (time < 5.15) {
code = "03";
title = "LEFT RELEASING";
detail = "Left fingers open; the single baton remains with right.";
} else {
code = "04";
title = "RIGHT SOLE OWNER";
detail = "Transfer complete. Baton instance count remains one.";
}
setText(phaseCode, code);
setText(statusTitle, title);
setText(statusDetail, detail);
leftOwner.classList.toggle("grip-active", leftActive);
rightOwner.classList.toggle("grip-active", rightActive);
leftOwner.classList.toggle("owner-active", nominalOwner === "left");
rightOwner.classList.toggle("owner-active", nominalOwner === "right");
const timelinePercent = (time / TOTAL) * 100;
playhead.style.left = `${timelinePercent}%`;
scrubber.value = String(time);
setText(timeReadout, `${time.toFixed(2)} / ${TOTAL.toFixed(2)}`);
setText(toggleButton, playing ? "Pause" : time >= TOTAL ? "Replay" : "Play");
}
// ------------------------------------------------------------
// Resize and animation loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
let previousTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
time = Math.min(TOTAL, time + delta);
if (time >= TOTAL) playing = false;
}
updateScene();
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
updateScene();
requestAnimationFrame(animate);
</script>
</body>
</html>
```