Prompt specification
Build or customize the Three.js 3D scene "Ant antenna and trail markers" 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: Ant antenna and trail markers
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ant-antenna-and-trail-markers-x0641
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts ant foraging trails. Model one ant with six legs and paired antennae beside a dotted trail; use separate symbolic markers to distinguish the animal from environmental chemical cues. Voxel style.
Working Three.js Starter (ant-antenna-and-trail-markers-x0641):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Ant Foraging Trails</title>
<style>
:root {
--ink: #edf3e5;
--muted: #9eaaa2;
--panel: rgba(17, 25, 28, 0.82);
--border: rgba(225, 238, 220, 0.16);
--gold: #ffc857;
--pink: #f43fbf;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #10191d;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
z-index: 10;
pointer-events: none;
}
.panel {
background: var(--panel);
border: 1px solid var(--border);
border-radius: 14px;
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(12px);
}
.title-panel {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px;
}
.eyebrow,
.micro {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
text-transform: uppercase;
letter-spacing: 0.16em;
font-size: 10px;
}
.eyebrow {
color: var(--gold);
margin-bottom: 10px;
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 37px);
line-height: 1.02;
letter-spacing: -0.045em;
font-weight: 760;
}
.subtitle {
color: var(--muted);
margin: 11px 0 18px;
font-size: 13px;
line-height: 1.5;
}
.facts {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.fact {
border: 1px solid var(--border);
border-radius: 999px;
padding: 6px 9px;
color: #c8d1ca;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
}
.legend {
left: 24px;
bottom: 24px;
padding: 15px 17px;
min-width: 245px;
}
.legend-title {
color: var(--muted);
margin-bottom: 12px;
}
.legend-row {
display: flex;
align-items: center;
gap: 11px;
margin-top: 10px;
font-size: 12px;
color: #dce5dc;
}
.legend-row small {
display: block;
color: var(--muted);
font-size: 10px;
margin-top: 2px;
}
.actor-symbol {
position: relative;
width: 21px;
height: 21px;
flex: 0 0 21px;
border: 2px solid var(--gold);
border-radius: 2px;
box-shadow: 0 0 14px rgba(255, 200, 87, 0.22);
}
.actor-symbol::before,
.actor-symbol::after {
content: "";
position: absolute;
background: #10191d;
}
.actor-symbol::before {
width: 6px;
height: 21px;
left: 5px;
top: -2px;
}
.actor-symbol::after {
width: 21px;
height: 6px;
left: -2px;
top: 5px;
}
.cue-symbol {
width: 21px;
height: 21px;
flex: 0 0 21px;
position: relative;
color: var(--pink);
font: 25px/19px ui-monospace, monospace;
text-align: center;
text-shadow: 0 0 13px rgba(244, 63, 191, 0.55);
}
.hint {
right: 24px;
bottom: 24px;
padding: 12px 15px;
color: var(--muted);
font: 10px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
text-align: right;
}
.world-label {
position: fixed;
z-index: 5;
transform: translate(-50%, -100%);
pointer-events: none;
white-space: nowrap;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
padding: 7px 9px;
border-radius: 6px;
border: 1px solid;
background: rgba(12, 18, 21, 0.82);
backdrop-filter: blur(6px);
}
.world-label.actor {
color: var(--gold);
border-color: rgba(255, 200, 87, 0.38);
}
.world-label.cue {
color: #ff79d2;
border-color: rgba(244, 63, 191, 0.38);
}
.world-label.trail {
color: #d8e1d8;
border-color: rgba(216, 225, 216, 0.2);
}
@media (max-width: 700px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px;
}
.subtitle { margin-bottom: 12px; }
.legend { left: 12px; bottom: 12px; min-width: 0; }
.hint { display: none; }
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="hud panel title-panel">
<div class="eyebrow">Ecology field note / 07</div>
<h1>Ant foraging<br />trails</h1>
<p class="subtitle">
A voxel study of one animal navigating a shared chemical landscape.
</p>
<div class="facts">
<span class="fact">1 ACTOR</span>
<span class="fact">6 LEGS</span>
<span class="fact">2 ANTENNAE</span>
<span class="fact">2 TRAIL BRANCHES</span>
</div>
</header>
<aside class="hud panel legend">
<div class="legend-title micro">Symbol key</div>
<div class="legend-row">
<span class="actor-symbol"></span>
<span>Ant actor<small>Gold corner bracket</small></span>
</div>
<div class="legend-row">
<span class="cue-symbol">+</span>
<span>Environmental cue<small>Magenta pheromone marker</small></span>
</div>
</aside>
<div class="hud panel hint">
DRAG · ORBIT<br />
SHIFT-DRAG · PAN<br />
WHEEL · ZOOM
</div>
<div id="actorLabel" class="world-label actor">Ant / actor</div>
<div id="cueLabel" class="world-label cue">Pheromone cue</div>
<div id="trailLabel" class="world-label trail">Dotted trail</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const actorLabel = document.querySelector("#actorLabel");
const cueLabel = document.querySelector("#cueLabel");
const trailLabel = document.querySelector("#trailLabel");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x10191d);
scene.fog = new THREE.Fog(0x10191d, 17, 34);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
// ------------------------------------------------------------------
// Lighting
// ------------------------------------------------------------------
const hemi = new THREE.HemisphereLight(0xffe8bd, 0x28342f, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffedcf, 3.1);
sun.position.set(6, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.0005;
scene.add(sun);
const magentaFill = new THREE.PointLight(0xf03db7, 7, 13, 2);
magentaFill.position.set(-1, 2.5, 2.5);
scene.add(magentaFill);
// ------------------------------------------------------------------
// Shared voxel geometry and materials
// ------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const xAxis = new THREE.Vector3(1, 0, 0);
const materials = {
base: new THREE.MeshStandardMaterial({
color: 0x272a25,
roughness: 1
}),
shell: new THREE.MeshStandardMaterial({
color: 0x321914,
roughness: 0.76,
flatShading: true
}),
shellLight: new THREE.MeshStandardMaterial({
color: 0x5a281b,
roughness: 0.72,
flatShading: true
}),
leg: new THREE.MeshStandardMaterial({
color: 0x180d0b,
roughness: 0.9
}),
joint: new THREE.MeshStandardMaterial({
color: 0x482119,
roughness: 0.8
}),
eye: new THREE.MeshStandardMaterial({
color: 0xffc35a,
emissive: 0xd66a00,
emissiveIntensity: 1.7,
roughness: 0.35
}),
actor: new THREE.MeshStandardMaterial({
color: 0xffc857,
emissive: 0xa45a00,
emissiveIntensity: 1.0,
roughness: 0.45
}),
cue: new THREE.MeshStandardMaterial({
color: 0xf43fbf,
emissive: 0x9c0b72,
emissiveIntensity: 1.1,
roughness: 0.42
}),
cueDot: new THREE.MeshStandardMaterial({
color: 0xe13aad,
emissive: 0x6e084f,
emissiveIntensity: 0.65,
roughness: 0.65
}),
cueFaint: new THREE.MeshStandardMaterial({
color: 0xb73191,
emissive: 0x4e073a,
emissiveIntensity: 0.4,
transparent: true,
opacity: 0.58,
roughness: 0.8
}),
rock: new THREE.MeshStandardMaterial({
color: 0x6f6854,
roughness: 1
}),
grass: new THREE.MeshStandardMaterial({
color: 0x526343,
roughness: 1
})
};
function makeBox(parent, size, position, material) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeSegment(parent, a, b, width, material, height = width) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.scale.set(length, height, width);
mesh.quaternion.setFromUnitVectors(xAxis, direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function hash2(x, z) {
const value = Math.sin(x * 127.1 + z * 311.7) * 43758.5453123;
return value - Math.floor(value);
}
function floorTop(x, z) {
const ix = Math.round(x / 0.8);
const iz = Math.round(z / 0.8);
return 0.07 + hash2(ix, iz) * 0.08;
}
function randomGenerator(seed) {
return function () {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
const random = randomGenerator(1947);
// ------------------------------------------------------------------
// Voxel terrain
// ------------------------------------------------------------------
const groundBase = makeBox(
scene,
[20, 0.7, 13.2],
[0, -0.35, 0],
materials.base
);
groundBase.castShadow = false;
const tileGeometry = new THREE.BoxGeometry(0.78, 1, 0.78);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.98
});
const tileCount = 25 * 17;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, tileCount);
tiles.receiveShadow = true;
const matrixDummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let ix = -12; ix <= 12; ix++) {
for (let iz = -8; iz <= 8; iz++) {
const height = 0.07 + hash2(ix, iz) * 0.08;
matrixDummy.position.set(ix * 0.8, height * 0.5, iz * 0.8);
matrixDummy.scale.set(1, height, 1);
matrixDummy.updateMatrix();
tiles.setMatrixAt(tileIndex, matrixDummy.matrix);
const shade = 0.37 + hash2(ix + 19, iz - 7) * 0.075;
tileColor.setHSL(
0.105 + hash2(ix - 4, iz + 11) * 0.018,
0.27,
shade
);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// Sparse voxel rocks and grass around the edges of the field.
for (let i = 0; i < 34; i++) {
const side = i % 2 === 0 ? -1 : 1;
const x = side * (6.7 + random() * 2.7);
const z = -5.5 + random() * 11;
const size = 0.13 + random() * 0.28;
makeBox(
scene,
[size, size * (0.65 + random()), size],
[x, floorTop(x, z) + size * 0.45, z],
materials.rock
);
}
for (let i = 0; i < 20; i++) {
const x = -9 + random() * 18;
const z = random() < 0.5 ? -4.4 - random() * 1.6 : 4.4 + random() * 1.6;
const baseY = floorTop(x, z);
for (let blade = 0; blade < 3; blade++) {
const bladeMesh = makeBox(
scene,
[0.065, 0.25 + random() * 0.28, 0.065],
[
x + (blade - 1) * 0.11,
baseY + 0.16,
z + (random() - 0.5) * 0.18
],
materials.grass
);
bladeMesh.rotation.z = (random() - 0.5) * 0.28;
}
}
// ------------------------------------------------------------------
// Foraging trails: a main dotted path and a secondary branch
// ------------------------------------------------------------------
const mainCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-8.5, 0, 0.4),
new THREE.Vector3(-6.4, 0, 1.5),
new THREE.Vector3(-4.5, 0, 0.45),
new THREE.Vector3(-2.5, 0, 1.65),
new THREE.Vector3(-0.4, 0, 0.85),
new THREE.Vector3(1.5, 0, 1.35),
new THREE.Vector3(3.5, 0, 0.45),
new THREE.Vector3(5.6, 0, 1.45),
new THREE.Vector3(8.5, 0, 0.75)
]);
const branchCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-2.5, 0, 1.65),
new THREE.Vector3(-2.7, 0, 3.1),
new THREE.Vector3(-1.3, 0, 4.2),
new THREE.Vector3(0.5, 0, 4.8)
]);
function createDottedTrail(curve, count, material, size) {
for (let i = 0; i < count; i++) {
const t = count === 1 ? 0 : i / (count - 1);
const point = curve.getPointAt(t);
makeBox(
scene,
[size, size, size],
[point.x, floorTop(point.x, point.z) + size * 0.55, point.z],
material
);
}
}
createDottedTrail(mainCurve, 58, materials.cueDot, 0.105);
createDottedTrail(branchCurve, 24, materials.cueFaint, 0.085);
// Environmental markers use a plus shape, unlike the animal's
// four-corner bracket and unlike the plain square trail deposits.
const cueMarkers = [];
function createCueMarker(curve, t, phase) {
const point = curve.getPointAt(t);
const group = new THREE.Group();
group.position.set(
point.x,
floorTop(point.x, point.z) + 0.045,
point.z
);
makeBox(group, [0.15, 0.075, 0.15], [0, 0, 0], materials.cue);
makeBox(group, [0.34, 0.075, 0.09], [0, 0, 0], materials.cue);
makeBox(group, [0.09, 0.075, 0.34], [0, 0, 0], materials.cue);
scene.add(group);
cueMarkers.push({ group, phase });
return group;
}
createCueMarker(mainCurve, 0.16, 0.0);
createCueMarker(mainCurve, 0.40, 1.1);
const featuredCue = createCueMarker(mainCurve, 0.66, 2.2);
createCueMarker(mainCurve, 0.84, 3.0);
createCueMarker(branchCurve, 0.55, 4.1);
// ------------------------------------------------------------------
// The ant: body, six articulated legs, and two segmented antennae
// ------------------------------------------------------------------
const ant = new THREE.Group();
const antTrailPoint = mainCurve.getPointAt(0.66);
const antTrailTangent = mainCurve.getTangentAt(0.66);
ant.position.set(
antTrailPoint.x,
floorTop(antTrailPoint.x, antTrailPoint.z - 1.05),
antTrailPoint.z - 1.05
);
ant.rotation.y = -Math.atan2(antTrailTangent.z, antTrailTangent.x);
scene.add(ant);
// Abdomen, thorax, neck, and head.
makeBox(ant, [1.30, 0.82, 0.86], [-1.03, 0.70, 0], materials.shell);
makeBox(ant, [1.08, 0.16, 0.74], [-1.07, 1.10, 0], materials.shellLight);
makeBox(ant, [0.25, 0.29, 0.30], [-0.26, 0.72, 0], materials.joint);
makeBox(ant, [0.80, 0.56, 0.62], [0.05, 0.64, 0], materials.shellLight);
makeBox(ant, [0.74, 0.68, 0.70], [0.76, 0.72, 0], materials.shell);
// Blocky abdominal plates.
for (let i = 0; i < 3; i++) {
makeBox(
ant,
[0.12, 0.12, 0.92],
[-1.46 + i * 0.36, 1.16, 0],
materials.joint
);
}
// Eyes and mandibles.
makeBox(ant, [0.09, 0.12, 0.12], [1.14, 0.83, -0.235], materials.eye);
makeBox(ant, [0.09, 0.12, 0.12], [1.14, 0.83, 0.235], materials.eye);
makeBox(ant, [0.28, 0.10, 0.10], [1.28, 0.53, -0.12], materials.leg);
makeBox(ant, [0.28, 0.10, 0.10], [1.28, 0.53, 0.12], materials.leg);
// Exactly six legs, arranged as three articulated pairs.
const legDefinitions = [
{ root: [0.43, 0.59], knee: [0.98, 0.25], foot: [1.62, 0.06] },
{ root: [0.02, 0.58], knee: [0.17, 0.24], foot: [-0.30, 0.06] },
{ root: [-0.44, 0.58], knee: [-0.95, 0.25], foot: [-1.55, 0.06] }
];
for (const side of [-1, 1]) {
for (const definition of legDefinitions) {
const root = [definition.root[0], definition.root[1], side * 0.27];
const knee = [definition.knee[0], definition.knee[1], side * 1.08];
const foot = [definition.foot[0], definition.foot[1], side * 1.38];
makeSegment(ant, root, knee, 0.105, materials.leg);
makeSegment(ant, knee, foot, 0.09, materials.leg);
makeBox(ant, [0.17, 0.15, 0.15], root, materials.joint);
makeBox(ant, [0.16, 0.14, 0.14], knee, materials.joint);
makeBox(ant, [0.18, 0.09, 0.12], foot, materials.leg);
}
}
// Two independently animated, segmented antennae.
const antennae = [];
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(1.05, 0.93, side * 0.17);
ant.add(pivot);
const innerEnd = new THREE.Vector3(0.48, 0.28, side * 0.20);
const outerEnd = innerEnd.clone().add(
new THREE.Vector3(0.43, 0.18, side * 0.25)
);
makeSegment(pivot, [0, 0, 0], innerEnd.toArray(), 0.065, materials.leg);
makeSegment(
pivot,
innerEnd.toArray(),
outerEnd.toArray(),
0.055,
materials.leg
);
makeBox(
pivot,
[0.09, 0.09, 0.09],
innerEnd.toArray(),
materials.joint
);
makeBox(
pivot,
[0.10, 0.10, 0.10],
outerEnd.toArray(),
materials.shellLight
);
antennae.push({ pivot, side, phase: side < 0 ? 0 : Math.PI });
}
// Gold four-corner bracket: the actor-specific symbolic marker.
const actorMarker = new THREE.Group();
actorMarker.position.y = 1.86;
ant.add(actorMarker);
const cornerX = 1.66;
const cornerZ = 1.12;
const barLength = 0.32;
for (const xSign of [-1, 1]) {
for (const zSign of [-1, 1]) {
makeBox(
actorMarker,
[barLength, 0.075, 0.075],
[xSign * (cornerX - barLength * 0.5), 0, zSign * cornerZ],
materials.actor
);
makeBox(
actorMarker,
[0.075, 0.075, barLength],
[xSign * cornerX, 0, zSign * (cornerZ - barLength * 0.5)],
materials.actor
);
}
}
// ------------------------------------------------------------------
// Custom orbit, pan, and zoom controls — no external controls addon
// ------------------------------------------------------------------
const orbit = {
radius: 13.4,
targetRadius: 13.4,
theta: 0.72,
targetTheta: 0.72,
phi: 0.78,
targetPhi: 0.78,
target: new THREE.Vector3(0, 0.25, 0),
targetGoal: new THREE.Vector3(0, 0.25, 0)
};
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
dragging = true;
panning = event.shiftKey || event.button === 2;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const scale = orbit.targetRadius * 0.00125;
orbit.targetGoal.addScaledVector(right, -dx * scale);
orbit.targetGoal.addScaledVector(forward, dy * scale);
} else {
orbit.targetTheta -= dx * 0.006;
orbit.targetPhi = THREE.MathUtils.clamp(
orbit.targetPhi - dy * 0.005,
0.28,
1.43
);
}
});
function endDrag(event) {
dragging = false;
panning = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius * Math.exp(event.deltaY * 0.001),
6.8,
24
);
}, { passive: false });
function updateCamera(dt) {
const smoothing = 1 - Math.exp(-dt * 10);
orbit.theta = THREE.MathUtils.lerp(
orbit.theta,
orbit.targetTheta,
smoothing
);
orbit.phi = THREE.MathUtils.lerp(
orbit.phi,
orbit.targetPhi,
smoothing
);
orbit.radius = THREE.MathUtils.lerp(
orbit.radius,
orbit.targetRadius,
smoothing
);
orbit.target.lerp(orbit.targetGoal, smoothing);
const offset = new THREE.Vector3().setFromSphericalCoords(
orbit.radius,
orbit.phi,
orbit.theta
);
camera.position.copy(orbit.target).add(offset);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
// ------------------------------------------------------------------
// Projected labels
// ------------------------------------------------------------------
function placeLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
element.style.display = visible ? "block" : "none";
if (!visible) return;
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
const actorAnchor = new THREE.Vector3();
const cueAnchor = new THREE.Vector3();
const trailAnchor = new THREE.Vector3();
const trailPoint = mainCurve.getPointAt(0.28);
// ------------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
updateCamera(dt);
// Gentle symbolic-marker pulses.
actorMarker.scale.setScalar(1 + Math.sin(time * 2.4) * 0.035);
for (const marker of cueMarkers) {
const pulse = 1 + Math.sin(time * 3.1 + marker.phase) * 0.11;
marker.group.scale.setScalar(pulse);
}
// Antennae feel/search independently.
for (const antenna of antennae) {
antenna.pivot.rotation.y =
Math.sin(time * 2.2 + antenna.phase) * 0.09;
antenna.pivot.rotation.z =
Math.sin(time * 1.7 + antenna.phase) * 0.035;
}
materials.cueDot.emissiveIntensity =
0.58 + Math.sin(time * 1.8) * 0.12;
actorMarker.getWorldPosition(actorAnchor);
actorAnchor.y += 0.28;
featuredCue.getWorldPosition(cueAnchor);
cueAnchor.y += 0.34;
trailAnchor.set(trailPoint.x, floorTop(trailPoint.x, trailPoint.z) + 0.35, trailPoint.z);
placeLabel(actorLabel, actorAnchor);
placeLabel(cueLabel, cueAnchor);
placeLabel(trailLabel, trailAnchor);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```