Prompt specification
Build or customize the Three.js 3D scene "Strap path around a head form" 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: Strap path around a head form
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/strap-path-around-a-head-form-x0606
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows protective helmet structure. Animate straps aligning around a simplified head form and joining beneath it; show their attachment routes clearly while avoiding medical or safety-fit prescriptions. Voxel style.
Working Three.js Starter (strap-path-around-a-head-form-x0606):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="color-scheme" content="dark">
<title>Voxel Helmet Structure</title>
<style>
:root {
--bg: #071117;
--panel: rgba(9, 24, 31, 0.86);
--line: rgba(143, 193, 205, 0.22);
--text: #e9f3f3;
--muted: #8fa8ae;
--cyan: #36e0c5;
--amber: #ffb45b;
--shell: #7795a3;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app {
position: fixed;
inset: 0;
isolation: isolate;
background:
radial-gradient(circle at 50% 42%, rgba(39, 79, 88, 0.18), transparent 42%),
var(--bg);
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.brand {
position: absolute;
z-index: 10;
top: 26px;
left: 28px;
max-width: 370px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 2px;
content: "";
background: var(--cyan);
box-shadow: 0 0 12px rgba(54, 224, 197, 0.6);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 50px);
font-weight: 800;
line-height: 0.93;
letter-spacing: -0.055em;
text-transform: uppercase;
}
.subtitle {
margin-top: 13px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
letter-spacing: 0.03em;
}
.notice {
position: absolute;
z-index: 10;
top: 26px;
right: 26px;
width: 245px;
padding: 14px 15px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--panel);
backdrop-filter: blur(12px);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
letter-spacing: 0.04em;
}
.notice strong {
display: block;
margin-bottom: 5px;
color: var(--amber);
font-size: 9px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend {
position: absolute;
z-index: 10;
left: 28px;
bottom: 116px;
display: grid;
gap: 8px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-item i {
display: block;
width: 12px;
height: 12px;
border-radius: 2px;
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.legend-item .shell-swatch {
background: var(--shell);
}
.legend-item .strap-swatch {
background: var(--cyan);
box-shadow: 0 0 12px rgba(54, 224, 197, 0.35);
}
.legend-item .junction-swatch {
background: var(--amber);
box-shadow: 0 0 12px rgba(255, 180, 91, 0.3);
}
.transport {
position: absolute;
z-index: 20;
left: 50%;
bottom: 24px;
width: min(620px, calc(100vw - 40px));
transform: translateX(-50%);
padding: 13px 15px 12px;
border: 1px solid var(--line);
border-radius: 6px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(16px);
}
.transport-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 8px;
}
.phase {
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.clock {
flex: 0 0 auto;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
#timeline {
width: 100%;
height: 3px;
margin: 0 0 11px;
appearance: none;
border-radius: 99px;
outline: none;
background:
linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) var(--progress, 0%),
rgba(116, 153, 162, 0.22) var(--progress, 0%),
rgba(116, 153, 162, 0.22) 100%
);
cursor: pointer;
}
#timeline::-webkit-slider-thumb {
width: 12px;
height: 12px;
appearance: none;
border: 2px solid var(--bg);
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 12px rgba(54, 224, 197, 0.55);
}
#timeline::-moz-range-thumb {
width: 9px;
height: 9px;
border: 2px solid var(--bg);
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 12px rgba(54, 224, 197, 0.55);
}
.transport-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.buttons {
display: flex;
gap: 7px;
}
.button {
min-width: 74px;
padding: 8px 11px;
border: 1px solid rgba(133, 176, 186, 0.25);
border-radius: 3px;
background: rgba(255, 255, 255, 0.035);
color: var(--text);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.button:hover {
border-color: rgba(54, 224, 197, 0.65);
background: rgba(54, 224, 197, 0.08);
}
.button:active {
transform: translateY(1px);
}
.button.primary {
border-color: rgba(54, 224, 197, 0.48);
color: var(--cyan);
}
.disclaimer {
max-width: 270px;
color: #789198;
font-size: 9px;
line-height: 1.45;
text-align: right;
}
.camera-hint {
position: absolute;
z-index: 10;
right: 27px;
bottom: 116px;
color: #6f8990;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
pointer-events: none;
}
#leaders {
position: absolute;
z-index: 5;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leaders line {
stroke: rgba(148, 190, 198, 0.42);
stroke-width: 1;
stroke-dasharray: 3 4;
}
#leaders circle {
fill: var(--cyan);
stroke: rgba(255, 255, 255, 0.65);
stroke-width: 1;
}
.callout {
position: absolute;
z-index: 6;
display: flex;
align-items: center;
gap: 8px;
min-width: 118px;
padding: 7px 9px;
transform: translate(-50%, -50%);
border: 1px solid rgba(143, 193, 205, 0.2);
border-radius: 3px;
background: rgba(7, 17, 23, 0.83);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(8px);
pointer-events: none;
white-space: nowrap;
}
.callout span {
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.callout b {
color: #c4d7da;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.callout.amber span {
color: var(--amber);
}
@media (max-width: 760px) {
.brand {
top: 19px;
left: 18px;
max-width: 260px;
}
h1 {
font-size: 31px;
}
.subtitle {
display: none;
}
.notice {
top: auto;
right: 15px;
bottom: 116px;
width: 205px;
padding: 10px 11px;
font-size: 8px;
}
.legend,
.camera-hint,
.callout.secondary {
display: none;
}
.transport {
bottom: 15px;
width: calc(100vw - 28px);
padding: 11px 12px;
}
.disclaimer {
max-width: 165px;
font-size: 8px;
}
.button {
min-width: 62px;
padding: 8px 9px;
}
}
@media (max-width: 470px) {
.disclaimer {
display: none;
}
.notice {
display: none;
}
}
</style>
</head>
<body>
<main id="app">
<canvas id="scene" aria-label="Interactive voxel helmet structure visualization"></canvas>
<header class="brand">
<div class="eyebrow">Structural animation</div>
<h1>Voxel<br>Helmet</h1>
<div class="subtitle">
Shell panels, lower anchors, and schematic webbing routes
assembling around a simplified head form.
</div>
</header>
<aside class="notice">
<strong>Non-prescriptive concept</strong>
Geometry is schematic and not to scale. It does not prescribe
placement, tension, fit, use, or safety assessment.
</aside>
<svg id="leaders" aria-hidden="true">
<line id="leader-shell"></line>
<circle id="dot-shell" r="3"></circle>
<line id="leader-anchor"></line>
<circle id="dot-anchor" r="3"></circle>
<line id="leader-route"></line>
<circle id="dot-route" r="3"></circle>
<line id="leader-junction"></line>
<circle id="dot-junction" r="3"></circle>
</svg>
<div id="label-shell" class="callout">
<span>01</span><b>Voxel shell</b>
</div>
<div id="label-anchor" class="callout secondary">
<span>02</span><b>Lower anchor</b>
</div>
<div id="label-route" class="callout secondary">
<span>03</span><b>Strap route</b>
</div>
<div id="label-junction" class="callout amber">
<span>04</span><b>Below-junction</b>
</div>
<aside class="legend" aria-label="Color legend">
<div class="legend-item">
<i class="shell-swatch"></i>
<span>Cutaway shell</span>
</div>
<div class="legend-item">
<i class="strap-swatch"></i>
<span>Illustrative webbing</span>
</div>
<div class="legend-item">
<i class="junction-swatch"></i>
<span>Attachment / junction</span>
</div>
</aside>
<div class="camera-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<section class="transport" aria-label="Animation controls">
<div class="transport-top">
<span id="phase" class="phase">01 / Preparing routes</span>
<span id="clock" class="clock">0.0 / 5.8s</span>
</div>
<input
id="timeline"
type="range"
min="0"
max="1000"
value="0"
aria-label="Animation timeline"
>
<div class="transport-bottom">
<div class="buttons">
<button id="replay" class="button primary" type="button">Replay</button>
<button id="pause" class="button" type="button">Pause</button>
</div>
<div class="disclaimer">
Concept visualization only. Routes illustrate assembly logic,
not a recommended or certified helmet configuration.
</div>
</div>
</section>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071117);
scene.fog = new THREE.FogExp2(0x071117, 0.047);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.22, 0);
const cameraState = {
yaw: 0.53,
pitch: 0.16,
radius: 7.35
};
function updateCamera() {
const { yaw, pitch, radius } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(yaw) * Math.cos(pitch),
cameraTarget.y + radius * Math.sin(pitch),
cameraTarget.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
updateCamera();
const ambient = new THREE.HemisphereLight(0xc8e8f0, 0x17232a, 1.65);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.7);
keyLight.position.set(4.5, 7, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x47d9df, 1.3);
rimLight.position.set(-5, 3, -4);
scene.add(rimLight);
const frontLight = new THREE.PointLight(0xffbd7a, 14, 12, 2);
frontLight.position.set(2.5, 0.2, 5);
scene.add(frontLight);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.06,
...options
});
}
const materials = {
shell: [
standardMaterial(0x63818f, { roughness: 0.62, metalness: 0.16 }),
standardMaterial(0x7895a1, { roughness: 0.58, metalness: 0.18 }),
standardMaterial(0x4f7080, { roughness: 0.68, metalness: 0.13 })
],
shellDark: standardMaterial(0x294550, { roughness: 0.7 }),
head: [
standardMaterial(0xa88d76),
standardMaterial(0xb89a82),
standardMaterial(0x957a67),
standardMaterial(0xc1a58e)
],
dark: standardMaterial(0x17282e, { roughness: 0.8 }),
face: standardMaterial(0x172328, { roughness: 0.86 }),
strap: standardMaterial(0x24cbb5, {
roughness: 0.48,
metalness: 0.05,
emissive: 0x075e55,
emissiveIntensity: 0.58
}),
strapEdge: new THREE.MeshBasicMaterial({
color: 0x8fffe9,
toneMapped: false
}),
amber: standardMaterial(0xffad50, {
roughness: 0.42,
metalness: 0.22,
emissive: 0x6e2d00,
emissiveIntensity: 0.45
}),
amberBright: new THREE.MeshBasicMaterial({
color: 0xffc57c,
toneMapped: false
}),
platform: standardMaterial(0x10232b, { roughness: 0.82, metalness: 0.12 }),
platformEdge: standardMaterial(0x1c3943, { roughness: 0.66, metalness: 0.2 })
};
function makeBox(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Voxel display platform.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
standardMaterial(0x071117, { roughness: 1, metalness: 0 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.765;
ground.receiveShadow = true;
scene.add(ground);
makeBox(5.1, 0.16, 4.5, materials.platform, 0, -1.9, 0);
makeBox(4.25, 0.08, 3.65, materials.platformEdge, 0, -1.79, 0);
const grid = new THREE.GridHelper(12, 24, 0x35515b, 0x1a3038);
grid.position.y = -1.755;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
// Small voxel corner markers.
[
[-2.05, -1.71, -1.72],
[2.05, -1.71, -1.72],
[-2.05, -1.71, 1.72],
[2.05, -1.71, 1.72]
].forEach(([x, y, z]) => {
makeBox(0.1, 0.1, 0.1, materials.strap, x, y, z);
});
// Simplified voxel head form.
const headGroup = new THREE.Group();
scene.add(headGroup);
const headStep = 0.34;
for (let ix = -3; ix <= 3; ix++) {
for (let iy = -3; iy <= 3; iy++) {
for (let iz = -3; iz <= 3; iz++) {
const x = ix * headStep;
const y = iy * headStep;
const z = iz * headStep;
const ellipsoid =
Math.pow(x / 1.24, 2) +
Math.pow(y / 1.52, 2) +
Math.pow(z / 1.12, 2);
if (ellipsoid > 1) continue;
const hash = Math.abs(ix * 17 + iy * 31 + iz * 13);
const materialIndex = hash % materials.head.length;
makeBox(
0.315,
0.315,
0.315,
materials.head[materialIndex],
x,
y,
z,
headGroup
);
}
}
}
// Neck and abstract facial orientation marks.
makeBox(0.66, 0.46, 0.58, materials.head[2], 0, -1.57, -0.08, headGroup);
makeBox(0.16, 0.12, 0.08, materials.face, -0.42, 0.34, 1.085, headGroup);
makeBox(0.16, 0.12, 0.08, materials.face, 0.42, 0.34, 1.085, headGroup);
makeBox(0.18, 0.28, 0.17, materials.head[3], 0, 0.02, 1.12, headGroup);
makeBox(0.14, 0.34, 0.26, materials.head[1], -1.2, -0.06, -0.02, headGroup);
makeBox(0.14, 0.34, 0.26, materials.head[1], 1.2, -0.06, -0.02, headGroup);
// Voxel helmet shell with a front cutaway.
const helmetGroup = new THREE.Group();
scene.add(helmetGroup);
const shellStep = 0.34;
for (let ix = -5; ix <= 5; ix++) {
for (let iy = 0; iy <= 5; iy++) {
for (let iz = -4; iz <= 4; iz++) {
const x = ix * shellStep;
const y = 0.58 + iy * shellStep;
const z = iz * shellStep;
const ellipsoid =
Math.pow(x / 1.58, 2) +
Math.pow((y - 0.58) / 1.56, 2) +
Math.pow(z / 1.47, 2);
if (ellipsoid > 1) continue;
// Remove the central front sector to expose the simplified form.
if (z > 0.48 && Math.abs(x) < 0.82 && y < 1.58) continue;
const hash = Math.abs(ix * 23 + iy * 17 + iz * 11);
const material = materials.shell[hash % materials.shell.length];
makeBox(
0.305,
0.305,
0.305,
material,
x,
y,
z,
helmetGroup
);
}
}
}
// Lower structural rim and inset liner blocks.
for (let i = 0; i < 36; i++) {
const angle = (i / 36) * Math.PI * 2;
const x = Math.cos(angle) * 1.5;
const z = Math.sin(angle) * 1.39;
makeBox(
0.22,
0.15,
0.22,
materials.shell[2],
x,
0.57,
z,
helmetGroup
);
makeBox(
0.15,
0.11,
0.15,
materials.shellDark,
Math.cos(angle) * 1.35,
0.52,
Math.sin(angle) * 1.24,
helmetGroup
);
}
// Lower attachment anchors.
const anchorGroups = [];
for (const side of [-1, 1]) {
const anchor = new THREE.Group();
anchor.position.set(side * 1.48, 0.58, 0.05);
scene.add(anchor);
makeBox(
0.23,
0.28,
0.34,
materials.shellDark,
0,
0,
0,
anchor
);
makeBox(
0.11,
0.18,
0.18,
materials.amber,
side * 0.08,
-0.02,
0,
anchor
);
makeBox(
0.035,
0.065,
0.065,
materials.amberBright,
side * 0.145,
-0.02,
0,
anchor
);
anchorGroups.push(anchor);
}
const routeSegments = [];
const routeLines = [];
const xAxis = new THREE.Vector3(1, 0, 0);
function buildRoute(side) {
const points = [
new THREE.Vector3(side * 1.47, 0.58, 0.05),
new THREE.Vector3(side * 1.55, 0.22, 0.1),
new THREE.Vector3(side * 1.48, -0.26, 0.12),
new THREE.Vector3(side * 1.28, -0.72, 0.26),
new THREE.Vector3(side * 0.92, -1.08, 0.54),
new THREE.Vector3(side * 0.48, -1.31, 0.76),
new THREE.Vector3(side * 0.16, -1.4, 0.82)
];
const curve = new THREE.CatmullRomCurve3(
points,
false,
"centripetal",
0.5
);
const lineGeometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(80)
);
const lineMaterial = new THREE.LineBasicMaterial({
color: 0x42e7cf,
transparent: true,
opacity: 0,
depthTest: false
});
const line = new THREE.Line(lineGeometry, lineMaterial);
line.renderOrder = 4;
scene.add(line);
routeLines.push(line);
const segmentCount = 15;
for (let i = 0; i < segmentCount; i++) {
const t = i / (segmentCount - 1);
const a = curve.getPoint(t);
const b = curve.getPoint(Math.min(1, t + 1 / (segmentCount - 1)));
const tangent = curve.getTangent(t).normalize();
const length = a.distanceTo(b);
const finalPosition = a.clone().lerp(b, 0.5);
const finalQuaternion = new THREE.Quaternion().setFromUnitVectors(
xAxis,
tangent
);
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(Math.max(0.045, length * 0.87), 0.085, 0.17),
materials.strap
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(Math.max(0.035, length * 0.58), 0.035, 0.015),
materials.strapEdge
);
stripe.position.z = 0.092;
mesh.add(stripe);
const exploded = finalPosition.clone().add(
new THREE.Vector3(
side * (1.05 + 0.25 * (1 - t)),
0.46 + 0.3 * (1 - t),
0.8 + 0.35 * t
)
);
const initialQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(
0.38 + t * 0.45,
side * (0.7 + t * 0.5),
-0.65 + t * 0.3
)
);
mesh.position.copy(exploded);
mesh.quaternion.copy(initialQuaternion);
routeSegments.push({
mesh,
exploded,
finalPosition,
initialQuaternion,
finalQuaternion,
delay: 0.55 + t * 2.65
});
}
}
buildRoute(-1);
buildRoute(1);
// Central illustrative below-junction.
const junction = new THREE.Group();
const junctionPosition = new THREE.Vector3(0, -1.43, 0.82);
junction.position.copy(junctionPosition);
scene.add(junction);
makeBox(
0.38,
0.17,
0.28,
materials.amber,
0,
0,
0,
junction
);
makeBox(
0.16,
0.085,
0.025,
materials.dark,
0,
0.012,
0.151,
junction
);
makeBox(
0.065,
0.035,
0.03,
materials.amberBright,
0,
0.012,
0.171,
junction
);
const junctionGlowMaterial = new THREE.MeshBasicMaterial({
color: 0xffbd70,
transparent: true,
opacity: 0.42,
depthWrite: false
});
const junctionGlow = new THREE.Group();
junction.add(junctionGlow);
[
[-0.25, 0, 0],
[0.25, 0, 0],
[0, 0.17, 0],
[0, -0.17, 0]
].forEach(([x, y, z]) => {
makeBox(
0.055,
0.055,
0.055,
junctionGlowMaterial,
x,
y,
z,
junctionGlow
);
});
const junctionLight = new THREE.PointLight(0xffad50, 0, 3.2, 2);
junction.add(junctionLight);
// Screen-space callout anchors.
const calloutData = [
{
id: "shell",
world: new THREE.Vector3(-0.42, 1.98, -0.16),
offset: new THREE.Vector2(-125, -58)
},
{
id: "anchor",
world: new THREE.Vector3(1.5, 0.58, 0.05),
offset: new THREE.Vector2(110, -30)
},
{
id: "route",
world: new THREE.Vector3(1.48, -0.38, 0.16),
offset: new THREE.Vector2(110, 38)
},
{
id: "junction",
world: junctionPosition.clone(),
offset: new THREE.Vector2(78, 58)
}
];
const leaders = document.querySelector("#leaders");
const labelElements = new Map();
const lineElements = new Map();
const dotElements = new Map();
calloutData.forEach((item) => {
labelElements.set(item.id, document.querySelector(`#label-${item.id}`));
lineElements.set(item.id, document.querySelector(`#leader-${item.id}`));
dotElements.set(item.id, document.querySelector(`#dot-${item.id}`));
});
function updateCallouts() {
const width = window.innerWidth;
const height = window.innerHeight;
leaders.setAttribute("viewBox", `0 0 ${width} ${height}`);
for (const item of calloutData) {
const label = labelElements.get(item.id);
const line = lineElements.get(item.id);
const dot = dotElements.get(item.id);
const isHidden =
window.innerWidth <= 760 &&
label.classList.contains("secondary");
if (isHidden) {
label.style.display = "none";
line.style.display = "none";
dot.style.display = "none";
continue;
}
label.style.display = "flex";
line.style.display = "";
dot.style.display = "";
const projected = item.world.clone().project(camera);
const sx = (projected.x * 0.5 + 0.5) * width;
const sy = (-projected.y * 0.5 + 0.5) * height;
const mobileScale = width < 760 ? 0.72 : 1;
let lx = sx + item.offset.x * mobileScale;
let ly = sy + item.offset.y * mobileScale;
const halfWidth = 74;
const halfHeight = 22;
lx = THREE.MathUtils.clamp(lx, halfWidth, width - halfWidth);
ly = THREE.MathUtils.clamp(ly, 76, height - 100);
label.style.left = `${lx}px`;
label.style.top = `${ly}px`;
line.setAttribute("x1", sx);
line.setAttribute("y1", sy);
line.setAttribute("x2", lx);
line.setAttribute("y2", ly);
dot.setAttribute("cx", sx);
dot.setAttribute("cy", sy);
}
}
// Animation state.
const duration = 5.8;
const state = {
elapsed: 0,
playing: true
};
const phaseElement = document.querySelector("#phase");
const clockElement = document.querySelector("#clock");
const timelineElement = document.querySelector("#timeline");
const pauseButton = document.querySelector("#pause");
const replayButton = document.querySelector("#replay");
function smooth01(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function updateAnimation(time) {
for (const segment of routeSegments) {
const progress = smooth01((time - segment.delay) / 0.9);
segment.mesh.position.lerpVectors(
segment.exploded,
segment.finalPosition,
progress
);
segment.mesh.quaternion.slerpQuaternions(
segment.initialQuaternion,
segment.finalQuaternion,
progress
);
segment.mesh.scale.set(
0.16 + progress * 0.84,
0.2 + progress * 0.8,
0.2 + progress * 0.8
);
}
for (const line of routeLines) {
const routeProgress = smooth01((time - 0.65) / 3.5);
line.material.opacity = 0.16 * routeProgress;
}
const junctionProgress = smooth01((time - 3.95) / 0.72);
junction.visible = junctionProgress > 0.001;
junction.position.set(
junctionPosition.x,
junctionPosition.y + (1 - junctionProgress) * 0.28,
junctionPosition.z + (1 - junctionProgress) * 0.38
);
junction.scale.setScalar(
0.2 + junctionProgress * 0.8
);
junctionLight.intensity = junctionProgress * 4.5;
const pulse = 1 + Math.sin(time * 4.2) * 0.1 * junctionProgress;
junctionGlow.scale.setScalar(pulse);
junctionGlowMaterial.opacity = 0.42 * junctionProgress;
anchorGroups.forEach((anchor, index) => {
const localPulse = smooth01((time - index * 0.12) / 0.7);
const scale = 1 + Math.sin(time * 5 + index) * 0.035 * localPulse;
anchor.scale.setScalar(scale);
});
}
function getPhase(time) {
if (time < 0.7) return "01 / Preparing routes";
if (time < 2.35) return "02 / Aligning upper anchors";
if (time < 3.95) return "03 / Tracing around head form";
if (time < 4.78) return "04 / Joining beneath form";
if (time < duration) return "05 / Route assembly";
return "06 / Assembly complete";
}
function updateTransport() {
const progress = state.elapsed / duration;
const percentage = `${(progress * 100).toFixed(2)}%`;
timelineElement.value = String(Math.round(progress * 1000));
timelineElement.style.setProperty("--progress", percentage);
clockElement.textContent = `${state.elapsed.toFixed(1)} / ${duration.toFixed(1)}s`;
phaseElement.textContent = getPhase(state.elapsed);
pauseButton.textContent = state.playing ? "Pause" : "Resume";
}
replayButton.addEventListener("click", () => {
state.elapsed = 0;
state.playing = true;
updateAnimation(state.elapsed);
updateTransport();
});
pauseButton.addEventListener("click", () => {
if (state.elapsed >= duration) {
state.elapsed = 0;
state.playing = true;
} else {
state.playing = !state.playing;
}
updateTransport();
});
timelineElement.addEventListener("input", () => {
state.elapsed = Number(timelineElement.value) / 1000 * duration;
state.playing = false;
updateAnimation(state.elapsed);
updateTransport();
});
// Direct camera controls implemented without addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.0045,
-0.12,
0.76
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
5.3,
10.8
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.yaw = 0.53;
cameraState.pitch = 0.16;
cameraState.radius = 7.35;
updateCamera();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
updateCamera();
updateCallouts();
}
window.addEventListener("resize", resize);
resize();
let previousFrameTime = performance.now();
function animate(now) {
const delta = Math.min((now - previousFrameTime) / 1000, 0.05);
previousFrameTime = now;
if (state.playing) {
state.elapsed = Math.min(duration, state.elapsed + delta);
if (state.elapsed >= duration) {
state.playing = false;
}
}
updateAnimation(state.elapsed);
updateTransport();
updateCallouts();
renderer.render(scene, camera);
}
updateAnimation(0);
updateTransport();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```