Prompt specification
Build or customize the Three.js 3D scene "Singing posture anatomical exhibit" 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: Singing posture anatomical exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/singing-posture-anatomical-exhibit-x0971
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts the diaphragm and rib cage. Compose a stylized singer beside transparent thoracic motion insets; relate controlled airflow and chest-volume change conceptually without providing clinical or vocal-training prescriptions. Voxel style.
Working Three.js Starter (singing-posture-anatomical-exhibit-x0971):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Flow — Thoracic Motion Study</title>
<style>
:root {
--bg: #080b18;
--panel: rgba(16, 23, 46, 0.72);
--line: rgba(162, 178, 255, 0.24);
--text: #edf1ff;
--muted: #99a5c8;
--cyan: #4de3ff;
--lilac: #b8a5ff;
--coral: #ff7468;
}
* {
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 {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.intro {
position: absolute;
top: 28px;
left: 30px;
width: min(390px, 42vw);
}
.eyebrow {
margin-bottom: 10px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 3.2vw, 48px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.intro p {
max-width: 360px;
margin: 14px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.disclaimer {
display: inline-block;
margin-top: 14px;
padding: 8px 10px;
border: 1px solid rgba(255, 116, 104, 0.28);
border-radius: 8px;
background: rgba(255, 116, 104, 0.07);
color: #c7b9c4;
font-size: 10px;
line-height: 1.4;
letter-spacing: 0.02em;
}
.phase-box {
position: absolute;
top: 28px;
right: 30px;
width: 238px;
padding: 14px 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(12px);
}
.phase-kicker {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.phase-dot {
width: 6px;
height: 6px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
#phaseTitle {
margin-top: 9px;
font-size: 14px;
font-weight: 800;
letter-spacing: 0.04em;
}
#phaseDetail {
margin-top: 5px;
color: var(--muted);
font-size: 10px;
}
.progress {
height: 3px;
margin-top: 13px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.08);
}
#progressFill {
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--cyan), var(--lilac));
box-shadow: 0 0 12px rgba(77, 227, 255, 0.6);
}
.world-label {
position: absolute;
z-index: 2;
min-width: 112px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(11, 16, 35, 0.78);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
transform: translate(-50%, -100%);
text-align: center;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.world-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 16px;
background: linear-gradient(var(--line), transparent);
}
.world-label .number {
color: var(--cyan);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.16em;
}
.world-label .title {
margin-top: 3px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.world-label .sub {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
}
.world-label.coral {
border-color: rgba(255, 116, 104, 0.38);
}
.world-label.coral .number {
color: var(--coral);
}
.legend {
position: absolute;
bottom: 27px;
left: 30px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: 520px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(12, 17, 36, 0.68);
color: #b9c3df;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.swatch {
width: 8px;
height: 8px;
border-radius: 2px;
}
.swatch.rib {
background: var(--lilac);
box-shadow: 0 0 9px rgba(184, 165, 255, 0.5);
}
.swatch.diaphragm {
background: var(--coral);
box-shadow: 0 0 9px rgba(255, 116, 104, 0.5);
}
.swatch.air {
background: var(--cyan);
box-shadow: 0 0 9px rgba(77, 227, 255, 0.5);
}
.controls {
position: absolute;
right: 30px;
bottom: 27px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.control-button {
min-height: 34px;
padding: 0 11px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(13, 19, 40, 0.82);
color: #d8def2;
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.control-button:hover {
border-color: rgba(77, 227, 255, 0.5);
color: white;
}
.control-hint {
margin-right: 4px;
color: #7f8aa8;
font-size: 9px;
}
@media (max-width: 760px) {
.intro {
top: 16px;
left: 16px;
width: 48vw;
}
.eyebrow {
font-size: 8px;
}
h1 {
font-size: 24px;
}
.intro p,
.disclaimer {
display: none;
}
.phase-box {
top: 14px;
right: 14px;
width: 176px;
padding: 11px;
}
#phaseDetail,
.world-label .sub,
.control-hint {
display: none;
}
.world-label {
min-width: 84px;
padding: 6px 7px;
}
.world-label .title {
font-size: 8px;
}
.legend {
bottom: 15px;
left: 14px;
max-width: 58vw;
gap: 5px;
}
.legend-item {
padding: 6px;
font-size: 7px;
}
.controls {
right: 14px;
bottom: 15px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel anatomy visualization"></canvas>
<div class="overlay">
<header class="intro">
<div class="eyebrow">Voxel Motion Study / 01</div>
<h1>Flow &<br />Thoracic Volume</h1>
<p>
A stylized anatomical scene relating a continuous airflow path,
rib-cage expansion, and diaphragm displacement.
</p>
<div class="disclaimer">
Abstract visualization only — not breathing, health, or vocal-training guidance.
</div>
</header>
<section class="phase-box" aria-live="polite">
<div class="phase-kicker">
<span class="phase-dot"></span>
Conceptual cycle
</div>
<div id="phaseTitle">CONTROLLED FLOW</div>
<div id="phaseDetail">Smooth particle path</div>
<div class="progress"><div id="progressFill"></div></div>
</section>
<div class="legend">
<div class="legend-item">
<span class="swatch rib"></span>
Rib cage
</div>
<div class="legend-item">
<span class="swatch diaphragm"></span>
Diaphragm
</div>
<div class="legend-item">
<span class="swatch air"></span>
Airflow
</div>
</div>
<div class="controls">
<span class="control-hint">Drag to orbit · Wheel to zoom</span>
<button class="control-button" id="resetCamera">Reset view</button>
<button class="control-button" id="motionToggle">Pause motion</button>
</div>
</div>
<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 phaseTitle = document.querySelector("#phaseTitle");
const phaseDetail = document.querySelector("#phaseDetail");
const progressFill = document.querySelector("#progressFill");
const motionToggle = document.querySelector("#motionToggle");
const resetCamera = document.querySelector("#resetCamera");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080b18);
scene.fog = new THREE.FogExp2(0x080b18, 0.025);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0.45, 1.28, 0);
const controls = {
yaw: 0.25,
pitch: 0.23,
radius: 16.5,
desiredYaw: 0.25,
desiredPitch: 0.23,
desiredRadius: 16.5,
dragging: false,
pointerX: 0,
pointerY: 0
};
function defaultRadius() {
const aspect = window.innerWidth / window.innerHeight;
if (aspect < 0.8) return 22;
if (aspect < 1.25) return 19;
return 16.5;
}
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 8);
controls.yaw = THREE.MathUtils.lerp(
controls.yaw,
controls.desiredYaw,
smoothing
);
controls.pitch = THREE.MathUtils.lerp(
controls.pitch,
controls.desiredPitch,
smoothing
);
controls.radius = THREE.MathUtils.lerp(
controls.radius,
controls.desiredRadius,
smoothing
);
const horizontal = controls.radius * Math.cos(controls.pitch);
camera.position.set(
target.x + Math.sin(controls.yaw) * horizontal,
target.y + Math.sin(controls.pitch) * controls.radius,
target.z + Math.cos(controls.yaw) * horizontal
);
camera.lookAt(target);
}
function resetView() {
controls.desiredYaw = 0.25;
controls.desiredPitch = 0.23;
controls.desiredRadius = defaultRadius();
}
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
controls.desiredYaw -= dx * 0.0055;
controls.desiredPitch = THREE.MathUtils.clamp(
controls.desiredPitch + dy * 0.004,
-0.08,
0.72
);
});
function stopDragging(event) {
controls.dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("dblclick", resetView);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius + event.deltaY * 0.008,
11,
27
);
},
{ passive: false }
);
resetCamera.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
toggleMotion();
}
if (event.key === "ArrowLeft") controls.desiredYaw += 0.12;
if (event.key === "ArrowRight") controls.desiredYaw -= 0.12;
if (event.key === "ArrowUp") controls.desiredPitch += 0.06;
if (event.key === "ArrowDown") controls.desiredPitch -= 0.06;
if (event.key.toLowerCase() === "r") resetView();
});
const ambient = new THREE.HemisphereLight(0x9bb8ff, 0x161126, 1.55);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xe8edff, 3.1);
keyLight.position.set(-4, 8, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x38dcff, 18, 15, 2);
cyanLight.position.set(5, 2.8, 4);
scene.add(cyanLight);
const coralLight = new THREE.PointLight(0xff5f58, 9, 9, 2);
coralLight.position.set(-3, 1, 3);
scene.add(coralLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const yAxis = new THREE.Vector3(0, 1, 0);
const tempVector = new THREE.Vector3();
const tempVector2 = new THREE.Vector3();
const dummy = new THREE.Object3D();
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.04,
...options
});
}
function addBox(
parent,
size,
position,
material,
rotation = [0, 0, 0]
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(...size);
mesh.position.set(...position);
mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBone(parent, from, to, width, depth, material) {
const start = new THREE.Vector3(...from);
const end = new THREE.Vector3(...to);
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(width, length, depth);
mesh.quaternion.setFromUnitVectors(
yAxis,
direction.clone().normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const materials = {
rib: standardMaterial(0xb7a3ff, {
transparent: true,
opacity: 0.73,
depthWrite: false
}),
cartilage: standardMaterial(0xded5ff, {
transparent: true,
opacity: 0.78,
depthWrite: false
}),
diaphragm: standardMaterial(0xff6f61, {
emissive: 0x4a0e10,
emissiveIntensity: 0.45,
transparent: true,
opacity: 0.88,
depthWrite: false
}),
panelRib: standardMaterial(0xb7a3ff, {
transparent: true,
opacity: 0.62,
depthWrite: false
}),
panelDiaphragm: standardMaterial(0xff7468, {
emissive: 0x430b0c,
emissiveIntensity: 0.4,
transparent: true,
opacity: 0.88,
depthWrite: false
}),
brightDiaphragm: standardMaterial(0xff7468, {
emissive: 0x5a1010,
emissiveIntensity: 0.75,
transparent: true,
opacity: 1,
depthWrite: false
}),
panelGlass: new THREE.MeshBasicMaterial({
color: 0x7789ff,
transparent: true,
opacity: 0.035,
depthWrite: false,
side: THREE.DoubleSide
}),
panelFrame: standardMaterial(0x7184c7, {
transparent: true,
opacity: 0.72,
depthWrite: false
}),
frameBright: standardMaterial(0x58def6, {
emissive: 0x154658,
emissiveIntensity: 0.65
}),
skin: standardMaterial(0xe7b08d),
skinLight: standardMaterial(0xf2c2a3),
hair: standardMaterial(0x181426),
jacket: standardMaterial(0x6253cf),
jacketDark: standardMaterial(0x3e347f),
shirt: standardMaterial(0x181d34),
pants: standardMaterial(0x20263e),
shoe: standardMaterial(0x111525),
mic: standardMaterial(0x171b2c),
micMetal: standardMaterial(0x71809d, {
metalness: 0.55,
roughness: 0.38
}),
mouth: standardMaterial(0x311526),
teeth: standardMaterial(0xf2e9dd),
eyes: standardMaterial(0x111322),
cyan: new THREE.MeshBasicMaterial({
color: 0x4de3ff,
transparent: true,
opacity: 0.92,
depthWrite: false
})
};
// Seeded visual variation for the tiled floor.
let seed = 9137;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const floor = new THREE.InstancedMesh(
unitBox,
standardMaterial(0xffffff, {
roughness: 0.9,
metalness: 0
}),
192
);
floor.receiveShadow = true;
let floorIndex = 0;
for (let x = -8; x < 8; x += 1) {
for (let z = -6; z < 6; z += 1) {
dummy.position.set(x * 0.8, -0.14, z * 0.8);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.76, 0.12, 0.76);
dummy.updateMatrix();
floor.setMatrixAt(floorIndex, dummy.matrix);
const shade = 0.035 + random() * 0.018;
floor.setColorAt(
floorIndex,
new THREE.Color(shade * 0.7, shade * 0.9, shade * 1.8)
);
floorIndex += 1;
}
}
floor.instanceMatrix.needsUpdate = true;
floor.instanceColor.needsUpdate = true;
scene.add(floor);
// Sparse voxel particles in the background.
const backgroundPixels = new THREE.InstancedMesh(
unitBox,
new THREE.MeshBasicMaterial({
color: 0x5f75ad,
transparent: true,
opacity: 0.16
}),
70
);
for (let i = 0; i < 70; i += 1) {
dummy.position.set(
-9 + random() * 18,
0.3 + random() * 6,
-5 - random() * 5
);
dummy.rotation.set(0, random() * Math.PI, 0);
const s = 0.025 + random() * 0.055;
dummy.scale.set(s, s, s);
dummy.updateMatrix();
backgroundPixels.setMatrixAt(i, dummy.matrix);
}
backgroundPixels.instanceMatrix.needsUpdate = true;
scene.add(backgroundPixels);
/*
A cage is built entirely from voxel-like boxes:
- instanced rib segments,
- lighter cartilage segments,
- a block sternum and spine,
- an instanced diaphragm surface.
*/
function createCage(parent, options = {}) {
const group = new THREE.Group();
parent.add(group);
const ribMaterial = options.ribMaterial || materials.rib;
const diaphragmMaterial =
options.diaphragmMaterial || materials.diaphragm;
const baseScale = options.baseScale ?? 1;
group.position.set(...(options.position || [0, 0, 0]));
group.scale.setScalar(baseScale);
const ribCount = 8 * 28;
const ribs = new THREE.InstancedMesh(
unitBox,
ribMaterial,
ribCount
);
ribs.castShadow = true;
ribs.frustumCulled = false;
let ribIndex = 0;
for (let row = 0; row < 8; row += 1) {
const y = 0.18 + row * 0.155;
const taper =
1 - 0.075 * Math.pow((row - 3.5) / 3.5, 2);
const radiusX = 0.72 * taper;
const radiusZ = 0.405 * (0.94 + row * 0.012);
for (let segment = 0; segment < 28; segment += 1) {
const theta = (segment / 28) * Math.PI * 2;
const x = Math.cos(theta) * radiusX;
const z = Math.sin(theta) * radiusZ;
const tangentX = -Math.sin(theta) * radiusX;
const tangentZ = Math.cos(theta) * radiusZ;
const rotationY = Math.atan2(-tangentZ, tangentX);
dummy.position.set(x, y, z);
dummy.rotation.set(0, rotationY, 0);
dummy.scale.set(0.145, 0.068, 0.082);
dummy.updateMatrix();
ribs.setMatrixAt(ribIndex++, dummy.matrix);
}
}
ribs.instanceMatrix.needsUpdate = true;
group.add(ribs);
const cartilage = new THREE.InstancedMesh(
unitBox,
materials.cartilage,
8 * 5
);
cartilage.frustumCulled = false;
let cartilageIndex = 0;
for (let row = 0; row < 8; row += 1) {
const y = 0.18 + row * 0.155;
const taper =
1 - 0.075 * Math.pow((row - 3.5) / 3.5, 2);
const radiusX = 0.72 * taper;
const radiusZ = 0.405 * (0.94 + row * 0.012);
for (let segment = 0; segment < 5; segment += 1) {
const theta =
Math.PI / 2 - 0.3 + segment * 0.15;
const x = Math.cos(theta) * radiusX;
const z = Math.sin(theta) * radiusZ;
const tangentX = -Math.sin(theta) * radiusX;
const tangentZ = Math.cos(theta) * radiusZ;
const rotationY = Math.atan2(-tangentZ, tangentX);
dummy.position.set(x, y, z);
dummy.rotation.set(0, rotationY, 0);
dummy.scale.set(0.16, 0.073, 0.088);
dummy.updateMatrix();
cartilage.setMatrixAt(cartilageIndex++, dummy.matrix);
}
}
cartilage.instanceMatrix.needsUpdate = true;
group.add(cartilage);
// Front sternum.
for (let i = 0; i < 8; i += 1) {
addBox(
group,
[0.13, 0.16, 0.095],
[0, 0.2 + i * 0.16, 0.405],
materials.cartilage
);
}
// Rear vertebral blocks.
for (let i = 0; i < 9; i += 1) {
addBox(
group,
[0.19, 0.13, 0.12],
[0, 0.12 + i * 0.15, -0.405],
materials.panelRib
);
}
const diaphragmCells = [];
for (let ix = 0; ix < 13; ix += 1) {
for (let iz = 0; iz < 8; iz += 1) {
const x = -0.69 + ix * 0.115;
const z = -0.4 + iz * 0.115;
const normalized =
Math.pow(x / 0.75, 2) + Math.pow(z / 0.46, 2);
if (normalized <= 1.08) {
diaphragmCells.push({ x, z, normalized });
}
}
}
const diaphragm = new THREE.InstancedMesh(
unitBox,
diaphragmMaterial,
diaphragmCells.length
);
diaphragm.frustumCulled = false;
diaphragm.renderOrder = 2;
group.add(diaphragm);
const cage = {
group,
diaphragm,
diaphragmCells,
baseScale
};
setCageMotion(cage, 0);
return cage;
}
function setCageMotion(cage, expansion) {
cage.group.scale.set(
cage.baseScale * (1 + expansion * 0.12),
cage.baseScale,
cage.baseScale * (1 + expansion * 0.085)
);
for (let i = 0; i < cage.diaphragmCells.length; i += 1) {
const cell = cage.diaphragmCells[i];
const dome =
0.22 * (1 - Math.min(cell.normalized, 1));
const y =
0.045 -
expansion * 0.12 +
dome * (1 - expansion * 0.25);
dummy.position.set(cell.x, y, cell.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.108, 0.082, 0.108);
dummy.updateMatrix();
cage.diaphragm.setMatrixAt(i, dummy.matrix);
}
cage.diaphragm.instanceMatrix.needsUpdate = true;
}
function createFlow(parent, count, points, color, speed, size) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point)),
false,
"catmullrom",
0.25
);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92,
depthWrite: false
});
const mesh = new THREE.InstancedMesh(unitBox, material, count);
mesh.frustumCulled = false;
mesh.renderOrder = 4;
parent.add(mesh);
return { mesh, curve, count, speed, size };
}
function updateFlow(flow, time) {
for (let i = 0; i < flow.count; i += 1) {
const progress = (time * flow.speed + i / flow.count) % 1;
flow.curve.getPointAt(progress, tempVector);
const envelope = Math.pow(
Math.sin(Math.PI * progress),
0.45
);
const scale = flow.size * (0.28 + envelope * 0.72);
dummy.position.copy(tempVector);
dummy.rotation.set(0, progress * Math.PI, 0);
dummy.scale.setScalar(scale);
dummy.updateMatrix();
flow.mesh.setMatrixAt(i, dummy.matrix);
}
flow.mesh.instanceMatrix.needsUpdate = true;
}
// Stylized singer.
const singer = new THREE.Group();
singer.position.set(-3, 0, 0);
scene.add(singer);
// Shoes and legs.
addBox(singer, [0.36, 0.2, 0.55], [-0.23, 0.1, 0.12], materials.shoe);
addBox(singer, [0.36, 0.2, 0.55], [0.23, 0.1, 0.12], materials.shoe);
addBox(singer, [0.28, 0.78, 0.3], [-0.23, 0.56, 0], materials.pants);
addBox(singer, [0.28, 0.78, 0.3], [0.23, 0.56, 0], materials.pants);
// Torso and clothing.
addBox(singer, [0.82, 0.92, 0.52], [0, 1.27, 0], materials.jacket);
addBox(singer, [0.3, 0.76, 0.56], [0, 1.28, 0.015], materials.shirt);
addBox(singer, [0.9, 0.18, 0.57], [0, 0.84, 0], materials.jacketDark);
addBox(singer, [0.26, 0.25, 0.3], [0, 1.83, 0.015], materials.skin);
// Collar.
addBox(singer, [0.17, 0.13, 0.08], [-0.19, 1.69, 0.29], materials.jacketDark);
addBox(singer, [0.17, 0.13, 0.08], [0.19, 1.69, 0.29], materials.jacketDark);
// Head and hair.
addBox(singer, [0.61, 0.61, 0.5], [0, 2.19, 0.08], materials.skin);
addBox(singer, [0.65, 0.18, 0.56], [0, 2.5, 0.06], materials.hair);
addBox(singer, [0.65, 0.54, 0.18], [0, 2.2, -0.18], materials.hair);
addBox(singer, [0.13, 0.49, 0.52], [-0.3, 2.21, 0.04], materials.hair);
addBox(singer, [0.13, 0.49, 0.52], [0.3, 2.21, 0.04], materials.hair);
// Face.
addBox(singer, [0.065, 0.065, 0.035], [-0.14, 2.27, 0.345], materials.eyes);
addBox(singer, [0.065, 0.065, 0.035], [0.14, 2.27, 0.345], materials.eyes);
addBox(singer, [0.08, 0.11, 0.09], [0, 2.2, 0.37], materials.skinLight);
addBox(singer, [0.14, 0.07, 0.035], [0, 2.08, 0.35], materials.mouth);
addBox(singer, [0.085, 0.025, 0.025], [0, 2.095, 0.373], materials.teeth);
addBox(singer, [0.11, 0.17, 0.09], [-0.34, 2.18, 0.06], materials.skinLight);
addBox(singer, [0.11, 0.17, 0.09], [0.34, 2.18, 0.06], materials.skinLight);
// Bent arms.
addBone(
singer,
[-0.42, 1.62, 0],
[-0.65, 1.2, 0.05],
0.22,
0.26,
materials.jacket
);
addBone(
singer,
[-0.65, 1.2, 0.05],
[-0.76, 1.01, 0.25],
0.2,
0.23,
materials.jacketDark
);
addBox(singer, [0.22, 0.2, 0.2], [-0.77, 0.96, 0.28], materials.skin);
addBone(
singer,
[0.42, 1.62, 0],
[0.64, 1.3, 0.34],
0.22,
0.25,
materials.jacket
);
addBone(
singer,
[0.64, 1.3, 0.34],
[0.22, 1.78, 0.75],
0.2,
0.22,
materials.jacketDark
);
addBox(singer, [0.21, 0.19, 0.2], [0.2, 1.83, 0.78], materials.skin);
// Voxel microphone and stand.
addBox(singer, [0.06, 1.98, 0.06], [0.28, 1.03, 1], materials.micMetal);
addBox(singer, [0.52, 0.08, 0.42], [0.28, 0.07, 1], materials.mic);
addBone(
singer,
[0.28, 1.98, 1],
[0.05, 2.1, 1.02],
0.07,
0.07,
materials.micMetal
);
addBox(singer, [0.34, 0.25, 0.26], [0.04, 2.11, 1.02], materials.micMetal);
addBox(singer, [0.37, 0.075, 0.29], [0.04, 2.12, 1.02], materials.mic);
// Main transparent anatomical overlay.
const mainCage = createCage(scene, {
position: [-3, 0.72, 0.47],
baseScale: 1,
ribMaterial: materials.rib,
diaphragmMaterial: materials.diaphragm
});
// A few translucent interior voxels suggest changing air volume.
const innerVolumeMaterial = new THREE.MeshBasicMaterial({
color: 0x4de3ff,
transparent: true,
opacity: 0.13,
depthWrite: false
});
for (let i = 0; i < 12; i += 1) {
const side = i % 2 === 0 ? -1 : 1;
const row = Math.floor(i / 2);
addBox(
mainCage.group,
[0.16, 0.16, 0.13],
[
side * (0.14 + row * 0.035),
0.55 + (row % 3) * 0.19,
-0.04 + (row % 2) * 0.08
],
innerVolumeMaterial
);
}
// Air path from the lower chest, through the head, and toward the mic.
const mainFlow = createFlow(
singer,
25,
[
[-0.12, 1.11, 0.82],
[-0.18, 1.5, 0.72],
[-0.04, 1.87, 0.51],
[0, 2.07, 0.39],
[0.025, 2.12, 0.72],
[0.04, 2.11, 1.01]
],
0x4de3ff,
0.12,
0.065
);
// Transparent thoracic inset panels.
const panelXs = [1.65, 3.65, 5.65];
const panelGroups = [];
function createPanel(x, index) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
panelGroups.push(group);
const back = new THREE.Mesh(
new THREE.BoxGeometry(1.76, 2.62, 0.035),
materials.panelGlass
);
back.position.set(0, 1.55, -0.25);
back.renderOrder = 0;
group.add(back);
const framePieces = [
[[1.8, 0.035, 0.05], [0, 0.25, -0.21]],
[[1.8, 0.035, 0.05], [0, 2.85, -0.21]],
[[0.035, 2.62, 0.05], [-0.9, 1.55, -0.21]],
[[0.035, 2.62, 0.05], [0.9, 1.55, -0.21]],
[[0.18, 0.07, 0.08], [-0.75, 2.78, -0.16]],
[[0.18, 0.07, 0.08], [0.75, 2.78, -0.16]],
[[0.48, 0.06, 0.08], [0, 0.31, -0.16]]
];
framePieces.forEach(([size, position], i) => {
addBox(
group,
size,
position,
i === 5 ? materials.frameBright : materials.panelFrame
);
});
// Small panel number marker.
for (let i = 0; i <= index; i += 1) {
addBox(
group,
[0.075, 0.075, 0.075],
[-0.18 + i * 0.12, 2.68, -0.12],
materials.frameBright
);
}
const cage = createCage(group, {
position: [0, 0.73, 0.22],
baseScale: 0.72,
ribMaterial: materials.panelRib,
diaphragmMaterial:
index === 2
? materials.brightDiaphragm
: materials.panelDiaphragm
});
return { group, cage };
}
const panelOne = createPanel(panelXs[0], 0);
const panelTwo = createPanel(panelXs[1], 1);
const panelThree = createPanel(panelXs[2], 2);
// Panel 1: flowing voxel particles.
const panelFlow = createFlow(
panelOne.group,
18,
[
[-0.48, 0.75, 0.5],
[-0.28, 1.14, 0.58],
[-0.05, 1.43, 0.56],
[0.18, 1.55, 0.5],
[0.48, 1.43, 0.4]
],
0x4de3ff,
0.16,
0.045
);
// Panel 2: markers around a changing volume envelope.
const volumeMarkers = [];
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0x9fb3ff,
transparent: true,
opacity: 0.38,
depthWrite: false
});
for (let i = 0; i < 24; i += 1) {
const angle = (i / 24) * Math.PI * 2;
const marker = addBox(
panelTwo.group,
[0.075, 0.075, 0.075],
[0, 0.9, 0.35],
markerMaterial
);
volumeMarkers.push({ marker, angle });
}
// Panel 3: a compact position indicator beside the diaphragm.
const indicatorMaterial = standardMaterial(0xff7468, {
emissive: 0x4d1110,
emissiveIntensity: 0.65
});
addBox(
panelThree.group,
[0.035, 0.52, 0.035],
[0.61, 0.9, 0.31],
materials.panelFrame
);
addBox(
panelThree.group,
[0.18, 0.035, 0.04],
[0.61, 0.69, 0.31],
indicatorMaterial
);
addBox(
panelThree.group,
[0.18, 0.035, 0.04],
[0.61, 1.13, 0.31],
indicatorMaterial
);
const diaphragmIndicator = addBox(
panelThree.group,
[0.12, 0.12, 0.12],
[0.61, 0.93, 0.34],
indicatorMaterial
);
// DOM labels anchored to scene positions.
const labels = [
{
element: createLabel("Vocal figure", "Stylized singer", "Controlled flow"),
position: new THREE.Vector3(-3, 2.95, 0)
},
{
element: createLabel("Anatomy", "Diaphragm", "Voxel surface"),
position: new THREE.Vector3(-3, 0.62, 1.02),
className: "coral"
},
{
element: createLabel("01", "Controlled flow", "Particle path"),
position: new THREE.Vector3(panelXs[0], 3.08, 0)
},
{
element: createLabel("02", "Chest volume", "Spreading envelope"),
position: new THREE.Vector3(panelXs[1], 3.08, 0)
},
{
element: createLabel("03", "Diaphragm", "Position shift"),
position: new THREE.Vector3(panelXs[2], 3.08, 0),
className: "coral"
}
];
function createLabel(number, title, sub, className = "") {
const element = document.createElement("div");
element.className = `world-label ${className}`.trim();
element.innerHTML = `
<div class="number">${number}</div>
<div class="title">${title}</div>
<div class="sub">${sub}</div>
`;
document.querySelector(".overlay").appendChild(element);
return element;
}
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
tempVector.copy(label.position).project(camera);
const x = (tempVector.x * 0.5 + 0.5) * width;
const y = (-tempVector.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity =
tempVector.z > -1 && tempVector.z < 1 ? "1" : "0";
}
}
function smoothstep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function cycleExpansion(time) {
const cycle = (time % 9) / 9;
if (cycle < 0.44) {
return smoothstep(cycle / 0.44);
}
if (cycle < 0.63) {
return 1;
}
return 1 - smoothstep((cycle - 0.63) / 0.37);
}
let paused = false;
let elapsed = 0;
function toggleMotion() {
paused = !paused;
motionToggle.textContent = paused ? "Resume motion" : "Pause motion";
}
motionToggle.addEventListener("click", toggleMotion);
function updatePhase(time) {
const cycle = (time % 9) / 9;
progressFill.style.width = `${cycle * 100}%`;
if (cycle < 0.44) {
phaseTitle.textContent = "CONTROLLED FLOW";
phaseDetail.textContent = "Smooth particle path";
} else if (cycle < 0.63) {
phaseTitle.textContent = "EXPANDED ENVELOPE";
phaseDetail.textContent = "Largest illustrated thoracic volume";
} else {
phaseTitle.textContent = "RETURN PHASE";
phaseDetail.textContent = "The volume envelope recedes";
}
}
function updateVolumeMarkers(expansion) {
for (const item of volumeMarkers) {
const radiusX = 0.84 * (1 + expansion * 0.14);
const radiusZ = 0.56 * (1 + expansion * 0.1);
item.marker.position.x = Math.cos(item.angle) * radiusX;
item.marker.position.z =
0.31 + Math.sin(item.angle) * radiusZ;
item.marker.position.y =
0.86 + Math.sin(item.angle * 2) * 0.06;
const size = 0.068 + expansion * 0.026;
item.marker.scale.set(size, size, size);
}
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
camera.aspect = aspect;
camera.fov = aspect < 0.8 ? 56 : aspect < 1.25 ? 46 : 38;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
controls.radius = defaultRadius();
controls.desiredRadius = controls.radius;
let previousTime = performance.now();
renderer.setAnimationLoop((now) => {
const delta = THREE.MathUtils.clamp((now - previousTime) / 1000, 0, 0.05);
previousTime = now;
if (!paused) elapsed += delta;
updateCamera(delta);
const expansion = cycleExpansion(elapsed);
setCageMotion(mainCage, expansion);
setCageMotion(panelOne.cage, expansion);
setCageMotion(panelTwo.cage, expansion);
setCageMotion(panelThree.cage, expansion);
updateFlow(mainFlow, elapsed);
updateFlow(panelFlow, elapsed);
updateVolumeMarkers(expansion);
const indicatorY =
0.73 + 0.72 * (0.265 - expansion * 0.12);
diaphragmIndicator.position.y = indicatorY;
updatePhase(elapsed);
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```