Prompt specification
Build or customize the Three.js 3D scene "Protective response classroom diorama" 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: Protective response classroom diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/protective-response-classroom-diorama-x1019
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring reflex pathways. Compose a stylized hand near a harmless spring button with an enlarged neural-pathway inset; show input, relay, and response without harmful stimuli or diagnosis. Voxel style.
Working Three.js Starter (protective-response-classroom-diorama-x1019):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#080c1c" />
<title>Reflex Arc — Voxel Pathway Study</title>
<style>
:root {
--bg: #080c1c;
--ink: #f6f7ff;
--muted: #9da8c8;
--panel: rgba(16, 23, 47, 0.78);
--line: rgba(158, 177, 229, 0.18);
--input: #ffd45c;
--relay: #ff6fae;
--response: #50e3e1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
circle at 52% 48%,
transparent 35%,
rgba(3, 6, 17, 0.2) 72%,
rgba(3, 6, 17, 0.76) 100%
);
z-index: 2;
}
.ui {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.copy {
position: absolute;
top: 28px;
left: 30px;
width: min(370px, calc(100vw - 60px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: #b8c4e7;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 3px;
background: var(--input);
box-shadow: 0 0 18px rgba(255, 212, 92, 0.65);
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 52px);
line-height: 0.98;
letter-spacing: -0.055em;
}
.copy p {
max-width: 340px;
margin: 15px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.safe-badge {
position: absolute;
top: 28px;
right: 30px;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid rgba(80, 227, 225, 0.25);
border-radius: 999px;
background: rgba(9, 20, 31, 0.72);
color: #baf9f4;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.safe-badge::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--response);
box-shadow: 0 0 14px rgba(80, 227, 225, 0.9);
}
.controls {
position: absolute;
right: 30px;
bottom: 28px;
display: flex;
gap: 9px;
pointer-events: auto;
}
.control {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 0 15px;
border: 1px solid var(--line);
border-radius: 11px;
background: var(--panel);
color: #dfe5ff;
cursor: pointer;
font-size: 12px;
font-weight: 750;
backdrop-filter: blur(14px);
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
.control.primary {
border-color: rgba(255, 212, 92, 0.35);
background: rgba(255, 212, 92, 0.14);
color: #fff1b6;
}
.control:hover {
transform: translateY(-2px);
border-color: rgba(255, 255, 255, 0.38);
background: rgba(30, 39, 68, 0.9);
}
.control:focus-visible {
outline: 2px solid var(--input);
outline-offset: 3px;
}
.control-icon {
display: inline-block;
font-size: 15px;
line-height: 1;
}
.timeline {
position: absolute;
left: 50%;
bottom: 27px;
width: min(530px, calc(100vw - 440px));
min-width: 380px;
transform: translateX(-50%);
padding: 13px 15px 12px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(10, 16, 36, 0.78);
box-shadow: 0 18px 70px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(18px);
}
.timeline-top {
display: flex;
justify-content: space-between;
gap: 16px;
margin-bottom: 10px;
color: #aeb9d8;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
#status {
overflow: hidden;
max-width: 330px;
text-overflow: ellipsis;
white-space: nowrap;
}
.stages {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.stage {
position: relative;
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
padding: 9px 10px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.06);
border-radius: 9px;
background: rgba(255, 255, 255, 0.025);
color: #737f9f;
transition:
color 180ms ease,
border-color 180ms ease,
background 180ms ease;
}
.stage::after {
content: "";
position: absolute;
inset: auto 0 0;
height: 2px;
transform: scaleX(0);
transform-origin: left;
background: currentColor;
transition: transform 200ms ease;
}
.stage.active::after {
transform: scaleX(1);
}
.stage.active {
color: #fff;
background: rgba(255, 255, 255, 0.06);
}
.stage.done {
color: #b9c3df;
}
.stage-dot {
flex: 0 0 auto;
width: 8px;
height: 8px;
border-radius: 2px;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.stage[data-stage="input"] {
--stage-color: var(--input);
}
.stage[data-stage="relay"] {
--stage-color: var(--relay);
}
.stage[data-stage="response"] {
--stage-color: var(--response);
}
.stage.active[data-stage="input"] {
color: var(--input);
border-color: rgba(255, 212, 92, 0.3);
}
.stage.active[data-stage="relay"] {
color: var(--relay);
border-color: rgba(255, 111, 174, 0.3);
}
.stage.active[data-stage="response"] {
color: var(--response);
border-color: rgba(80, 227, 225, 0.3);
}
.stage-number {
margin-left: auto;
color: currentColor;
opacity: 0.55;
font-size: 9px;
font-weight: 900;
}
.hint {
position: absolute;
left: 30px;
bottom: 30px;
display: flex;
align-items: center;
gap: 9px;
color: #7f8bad;
font-size: 11px;
}
.hint::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--input);
box-shadow: 0 0 12px rgba(255, 212, 92, 0.8);
}
.loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: var(--bg);
color: #aeb9d8;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.copy {
top: 22px;
left: 22px;
}
.copy p {
max-width: 300px;
font-size: 12px;
}
.safe-badge {
top: 22px;
right: 22px;
}
.timeline {
bottom: 20px;
width: calc(100vw - 44px);
min-width: 0;
}
.controls {
right: 22px;
bottom: 132px;
}
.hint {
display: none;
}
}
@media (max-width: 600px) {
.copy {
width: calc(100vw - 44px);
}
h1 {
max-width: 220px;
font-size: 32px;
}
.copy p {
display: none;
}
.safe-badge {
padding: 8px 10px;
font-size: 8px;
}
.timeline {
bottom: 12px;
width: calc(100vw - 24px);
padding: 10px;
}
.stage {
padding: 8px;
}
.stage-number {
display: none;
}
.controls {
right: 12px;
bottom: 117px;
}
.control {
min-height: 38px;
padding: 0 12px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive 3D voxel reflex pathway scene"></div>
<div class="vignette"></div>
<div class="ui">
<header class="copy">
<div class="eyebrow">Voxel pathway study · 03</div>
<h1>Reflex<br />Arc</h1>
<p>
A harmless button press becomes a quick signal: input, relay, then a
gentle response. Drag the scene to explore the enlarged pathway.
</p>
</header>
<div class="safe-badge">Safe · non-painful demo</div>
<section class="timeline" aria-label="Reflex pathway progress">
<div class="timeline-top">
<span>Signal sequence</span>
<span id="status" role="status" aria-live="polite">Ready · tap the yellow cap</span>
</div>
<div class="stages">
<div class="stage" data-stage="input">
<span class="stage-dot"></span>
<span>Input</span>
<span class="stage-number">01</span>
</div>
<div class="stage" data-stage="relay">
<span class="stage-dot"></span>
<span>Relay</span>
<span class="stage-number">02</span>
</div>
<div class="stage" data-stage="response">
<span class="stage-dot"></span>
<span>Response</span>
<span class="stage-number">03</span>
</div>
</div>
</section>
<div class="controls">
<button class="control" id="resetView" type="button" aria-label="Reset camera view">
<span class="control-icon">⌖</span>
Reset view
</button>
<button class="control primary" id="replay" type="button">
<span class="control-icon">↻</span>
Run reflex
</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Tap yellow cap</div>
</div>
<div class="loading" id="loading">Building voxel pathway…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and direct orbit/zoom controls
// -------------------------------------------------------------------------
const mount = document.getElementById("scene");
const loading = document.getElementById("loading");
const statusElement = document.getElementById("status");
const replayButton = document.getElementById("replay");
const resetViewButton = document.getElementById("resetView");
const stageElements = [...document.querySelectorAll(".stage")];
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.16;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080c1c);
scene.fog = new THREE.Fog(0x080c1c, 16, 31);
const camera = new THREE.OrthographicCamera(-7, 7, 4, -4, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0, 0);
let orbitTheta = 0.02;
let orbitPhi = 0.20;
let orbitRadius = 14;
let pointerDown = false;
let pointerMoved = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousPointerX = 0;
let previousPointerY = 0;
let hoveredButton = false;
function updateCamera() {
const sinPhi = Math.sin(orbitPhi);
camera.position.set(
cameraTarget.x + orbitRadius * sinPhi * Math.sin(orbitTheta),
cameraTarget.y + orbitRadius * Math.cos(orbitPhi),
cameraTarget.z + orbitRadius * sinPhi * Math.cos(orbitTheta)
);
camera.lookAt(cameraTarget);
camera.zoom = 14 / orbitRadius;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(7.4, 11.8 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// -------------------------------------------------------------------------
// Lighting and scene utilities
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0x9fb5ff, 0x171326, 2.25));
const keyLight = new THREE.DirectionalLight(0xfff2dc, 3.2);
keyLight.position.set(-5, 9, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x49e9e0, 16, 12, 2);
cyanLight.position.set(3.2, 0.3, 4.2);
scene.add(cyanLight);
const pinkLight = new THREE.PointLight(0xff5da8, 11, 8, 2);
pinkLight.position.set(0.4, -0.1, 3.2);
scene.add(pinkLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 30),
new THREE.MeshStandardMaterial({
color: 0x0a1024,
roughness: 0.92,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.12;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x273454, 0x17213a);
grid.position.y = -2.105;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.68,
metalness: options.metalness ?? 0.08,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
flatShading: true
});
}
function addBox(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
makeMaterial(color, options)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0xffffff, opacity = 0.2) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
edges.renderOrder = 3;
mesh.add(edges);
return edges;
}
function addLabel(parent, text, color, width = 1.4, position = [0, 0, 0]) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
const radius = 22;
const x = 8;
const y = 8;
const w = canvas.width - 16;
const h = canvas.height - 16;
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + w - radius, y);
context.quadraticCurveTo(x + w, y, x + w, y + radius);
context.lineTo(x + w, y + h - radius);
context.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);
context.lineTo(x + radius, y + h);
context.quadraticCurveTo(x, y + h, x, y + h - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
context.fillStyle = "rgba(8, 13, 31, 0.88)";
context.fill();
context.lineWidth = 3;
context.strokeStyle = color;
context.stroke();
context.fillStyle = color;
context.font = "800 34px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text.toUpperCase(), canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, (width * 112) / 512, 1);
sprite.position.set(position[0], position[1], position[2]);
sprite.renderOrder = 20;
parent.add(sprite);
return sprite;
}
function addVoxelTrail(parent, curve, count, color, size = 0.055) {
const geometry = new THREE.BoxGeometry(size, size, size);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.72
});
const mesh = new THREE.InstancedMesh(geometry, material, count);
const dummy = new THREE.Object3D();
for (let i = 0; i < count; i++) {
const point = curve.getPointAt(i / (count - 1));
dummy.position.copy(point);
dummy.rotation.set(0, 0, (i % 3) * 0.08);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
}
mesh.instanceMatrix.needsUpdate = true;
parent.add(mesh);
return mesh;
}
function makePulse(color, size = 0.15) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size, size, size),
new THREE.MeshBasicMaterial({ color })
);
mesh.visible = false;
mesh.renderOrder = 8;
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Stylized voxel hand
// -------------------------------------------------------------------------
const hand = new THREE.Group();
hand.position.z = 0.18;
scene.add(hand);
const skin = 0xf1a17f;
const skinLight = 0xffc3a3;
const skinShade = 0xd9786c;
const cuff = 0x253352;
addBox(hand, [2.15, 0.82, 0.67], [-4.15, -0.08, 0.18], skin, {
roughness: 0.76
});
const sleeve = addBox(
hand,
[0.58, 0.9, 0.74],
[-5.02, -0.08, 0.18],
cuff,
{ roughness: 0.8, metalness: 0.18 }
);
addEdges(sleeve, 0x61e7df, 0.35);
const palm = addBox(
hand,
[1.55, 1.55, 0.72],
[-2.88, -0.03, 0.28],
skin,
{ roughness: 0.72 }
);
addEdges(palm, 0xffddc7, 0.12);
addBox(
hand,
[1.13, 1.13, 0.10],
[-2.91, -0.03, 0.69],
skinShade,
{ roughness: 0.84 }
);
addBox(
hand,
[0.95, 0.12, 0.12],
[-2.83, 0.23, 0.78],
skinLight,
{ roughness: 0.72 }
);
addBox(
hand,
[0.95, 0.12, 0.12],
[-2.83, -0.32, 0.78],
skinLight,
{ roughness: 0.72 }
);
const fingerPivots = [];
function makeFinger(y, length, tint = skin) {
const pivot = new THREE.Group();
pivot.position.set(-2.16, y, 0.42);
hand.add(pivot);
addBox(
pivot,
[1.05, 0.27, 0.57],
[0.54, 0, 0],
tint,
{ roughness: 0.75 }
);
addBox(
pivot,
[0.54, 0.25, 0.51],
[1.29, 0, 0.015],
skinLight,
{ roughness: 0.72 }
);
addBox(
pivot,
[0.12, 0.29, 0.59],
[1.015, 0, 0],
skinShade,
{ roughness: 0.78 }
);
addBox(
pivot,
[0.26, 0.13, 0.08],
[1.29, 0, 0.28],
0xffe0c7,
{ roughness: 0.65 }
);
fingerPivots.push(pivot);
return pivot;
}
makeFinger(0.51, 1.0, skinLight);
makeFinger(0.16, 1.12);
makeFinger(-0.19, 1.02);
makeFinger(-0.53, 0.86, skinShade);
// A simple angled thumb identifies the hand silhouette.
const thumbA = addBox(
hand,
[0.95, 0.34, 0.58],
[-2.03, 0.89, 0.43],
skin,
{ roughness: 0.76 }
);
thumbA.rotation.z = 0.28;
const thumbB = addBox(
hand,
[0.65, 0.31, 0.52],
[-1.34, 1.08, 0.43],
skinLight,
{ roughness: 0.74 }
);
thumbB.rotation.z = 0.42;
// Small cyan muscle blocks represent the response effector.
const responseMuscle = new THREE.Group();
responseMuscle.position.set(-3.75, -0.49, 0.78);
hand.add(responseMuscle);
const muscleMaterial = makeMaterial(0x50e3e1, {
emissive: 0x50e3e1,
emissiveIntensity: 0.08,
roughness: 0.5,
metalness: 0.15
});
for (let i = 0; i < 3; i++) {
const muscle = new THREE.Mesh(
new THREE.BoxGeometry(0.45, 0.16, 0.22),
muscleMaterial
);
muscle.position.set((i - 1) * 0.43, Math.abs(i - 1) * 0.08, 0);
muscle.rotation.z = (i - 1) * -0.13;
muscle.castShadow = true;
responseMuscle.add(muscle);
}
// -------------------------------------------------------------------------
// Harmless spring button
// -------------------------------------------------------------------------
const buttonGroup = new THREE.Group();
buttonGroup.position.set(-0.13, 0, 0.69);
scene.add(buttonGroup);
addBox(
buttonGroup,
[1.55, 1.28, 1.12],
[0, -1.4, -0.02],
0x202c4b,
{ roughness: 0.78, metalness: 0.25 }
);
addBox(
buttonGroup,
[1.16, 0.20, 0.88],
[0, -0.70, 0],
0x7c8aab,
{ roughness: 0.38, metalness: 0.72 }
);
// Stepped gold blocks form a clearly voxel-like spring.
for (let i = 0; i < 10; i++) {
addBox(
buttonGroup,
[0.35, 0.055, 0.35],
[i % 2 === 0 ? -0.13 : 0.13, -0.57 + i * 0.052, 0],
0xd8b35d,
{ roughness: 0.35, metalness: 0.65 }
);
}
addBox(
buttonGroup,
[0.13, 0.54, 0.13],
[0, -0.26, 0],
0xa7b4cb,
{ roughness: 0.3, metalness: 0.8 }
);
const capPivot = new THREE.Group();
capPivot.position.y = 0.15;
buttonGroup.add(capPivot);
const buttonCapMaterial = makeMaterial(0xffd45c, {
emissive: 0xffb92f,
emissiveIntensity: 0.12,
roughness: 0.38,
metalness: 0.18
});
const buttonCap = new THREE.Mesh(
new THREE.BoxGeometry(0.86, 0.27, 0.82),
buttonCapMaterial
);
buttonCap.castShadow = true;
capPivot.add(buttonCap);
addEdges(buttonCap, 0xfff0a1, 0.48);
addLabel(buttonGroup, "Safe cap", "#ffd45c", 0.92, [0, 0.83, 0.18]);
// -------------------------------------------------------------------------
// Main pathway
// -------------------------------------------------------------------------
const mainInputPoint = new THREE.Vector3(-0.53, 0.51, 0.97);
const mainRelayPoint = new THREE.Vector3(0.55, -0.19, 0.58);
const mainSensoryCurve = new THREE.CatmullRomCurve3([
mainInputPoint,
new THREE.Vector3(-0.08, 0.72, 0.92),
new THREE.Vector3(0.39, 0.38, 0.74),
mainRelayPoint
]);
const mainMotorCurve = new THREE.CatmullRomCurve3([
mainRelayPoint,
new THREE.Vector3(0.46, -0.86, 0.76),
new THREE.Vector3(-0.55, -1.18, 0.88),
new THREE.Vector3(-2.55, -0.91, 0.92),
new THREE.Vector3(-3.73, -0.50, 0.86)
]);
addVoxelTrail(scene, mainSensoryCurve, 32, 0xffd45c, 0.055);
addVoxelTrail(scene, mainMotorCurve, 46, 0x50e3e1, 0.055);
const relayMaterial = makeMaterial(0xff6fae, {
emissive: 0xff2d8d,
emissiveIntensity: 0.22,
roughness: 0.52,
metalness: 0.16
});
const mainRelay = new THREE.Mesh(
new THREE.BoxGeometry(0.43, 0.43, 0.43),
relayMaterial
);
mainRelay.position.copy(mainRelayPoint);
mainRelay.castShadow = true;
scene.add(mainRelay);
addEdges(mainRelay, 0xffd4e7, 0.5);
for (let i = 0; i < 4; i++) {
const satellite = addBox(
scene,
[0.12, 0.12, 0.12],
[
mainRelayPoint.x + Math.cos(i * Math.PI / 2) * 0.37,
mainRelayPoint.y + Math.sin(i * Math.PI / 2) * 0.37,
mainRelayPoint.z + 0.01
],
0xff91c2,
{ emissive: 0xff4b9c, emissiveIntensity: 0.18 }
);
satellite.castShadow = false;
}
addLabel(scene, "Relay", "#ff6fae", 0.77, [0.56, -0.74, 0.72]);
const mainInputPulse = makePulse(0xffe37a, 0.17);
const mainMotorPulse = makePulse(0x8effff, 0.17);
// -------------------------------------------------------------------------
// Enlarged neural-pathway inset
// -------------------------------------------------------------------------
const inset = new THREE.Group();
inset.position.set(3.14, 0.12, -0.67);
scene.add(inset);
const panelBack = addBox(
inset,
[4.78, 4.88, 0.22],
[0, 0, -0.1],
0x111a34,
{ roughness: 0.86, metalness: 0.12, castShadow: true }
);
addEdges(panelBack, 0x8192c2, 0.26);
// Pixel-like frame bars.
addBox(inset, [4.95, 0.09, 0.17], [0, 2.48, 0.02], 0x59698f, {
metalness: 0.45
});
addBox(inset, [4.95, 0.09, 0.17], [0, -2.48, 0.02], 0x59698f, {
metalness: 0.45
});
addBox(inset, [0.09, 4.95, 0.17], [-2.48, 0, 0.02], 0x59698f, {
metalness: 0.45
});
addBox(inset, [0.09, 4.95, 0.17], [2.48, 0, 0.02], 0x59698f, {
metalness: 0.45
});
// Small corner brackets suggest a magnified technical view.
const bracketMaterial = new THREE.MeshBasicMaterial({ color: 0x91a4d6 });
const bracketGeometry = new THREE.BoxGeometry(0.26, 0.07, 0.07);
for (const sx of [-1, 1]) {
for (const sy of [-1, 1]) {
const h = new THREE.Mesh(bracketGeometry, bracketMaterial);
h.position.set(sx * 2.24, sy * 2.24, 0.08);
inset.add(h);
const v = new THREE.Mesh(bracketGeometry, bracketMaterial);
v.rotation.z = Math.PI / 2;
v.position.set(sx * 2.36, sy * 2.24, 0.08);
inset.add(v);
}
}
addLabel(inset, "Magnified pathway · 4×", "#d8e1ff", 2.45, [0, 2.13, 0.18]);
const insetInputPoint = new THREE.Vector3(-1.35, -1.27, 0.30);
const insetRelayPoint = new THREE.Vector3(0, -0.18, 0.38);
const insetResponsePoint = new THREE.Vector3(1.25, 1.05, 0.30);
const insetSensoryCurve = new THREE.CatmullRomCurve3([
insetInputPoint,
new THREE.Vector3(-0.90, -0.68, 0.34),
new THREE.Vector3(-0.45, -0.37, 0.38),
insetRelayPoint
]);
const insetResponseCurve = new THREE.CatmullRomCurve3([
insetRelayPoint,
new THREE.Vector3(0.47, 0.23, 0.37),
new THREE.Vector3(0.92, 0.68, 0.34),
insetResponsePoint
]);
addVoxelTrail(inset, insetSensoryCurve, 27, 0xffd45c, 0.075);
addVoxelTrail(inset, insetResponseCurve, 30, 0x50e3e1, 0.075);
// Input receptor: yellow voxel ending.
addBox(
inset,
[0.47, 0.18, 0.32],
[-1.35, -1.27, 0.30],
0xffd45c,
{ emissive: 0xffb82f, emissiveIntensity: 0.12 }
);
addBox(
inset,
[0.13, 0.47, 0.13],
[-1.56, -1.05, 0.32],
0xffdc72,
{ emissive: 0xffb82f, emissiveIntensity: 0.09 }
);
addBox(
inset,
[0.13, 0.47, 0.13],
[-1.14, -1.05, 0.32],
0xffdc72,
{ emissive: 0xffb82f, emissiveIntensity: 0.09 }
);
// Relay: enlarged magenta relay block with a small voxel cluster.
const insetRelayMaterial = makeMaterial(0xff6fae, {
emissive: 0xff2d8d,
emissiveIntensity: 0.25,
roughness: 0.5,
metalness: 0.18
});
const insetRelay = new THREE.Mesh(
new THREE.BoxGeometry(0.66, 0.66, 0.66),
insetRelayMaterial
);
insetRelay.position.copy(insetRelayPoint);
insetRelay.castShadow = true;
inset.add(insetRelay);
addEdges(insetRelay, 0xffd4e7, 0.55);
for (let i = 0; i < 4; i++) {
const angle = (i / 4) * Math.PI * 2;
addBox(
inset,
[0.16, 0.16, 0.16],
[
insetRelayPoint.x + Math.cos(angle) * 0.53,
insetRelayPoint.y + Math.sin(angle) * 0.53,
insetRelayPoint.z
],
0xff9ac5,
{ emissive: 0xff4b9c, emissiveIntensity: 0.16 }
);
}
// Response: stacked cyan effector blocks.
const insetResponseMaterial = makeMaterial(0x50e3e1, {
emissive: 0x50e3e1,
emissiveIntensity: 0.12,
roughness: 0.5,
metalness: 0.17
});
for (let i = 0; i < 3; i++) {
const block = new THREE.Mesh(
new THREE.BoxGeometry(0.83, 0.25, 0.45),
insetResponseMaterial
);
block.position.set(
insetResponsePoint.x + (i - 1) * 0.08,
insetResponsePoint.y + (i - 1) * 0.30,
insetResponsePoint.z
);
block.rotation.z = (i - 1) * -0.16;
block.castShadow = true;
inset.add(block);
}
addLabel(
inset,
"01 Input",
"#ffd45c",
1.27,
[-1.35, -1.82, 0.36]
);
addLabel(
inset,
"02 Relay",
"#ff6fae",
1.30,
[0, -0.88, 0.45]
);
addLabel(
inset,
"03 Response",
"#50e3e1",
1.64,
[1.18, 1.83, 0.37]
);
const insetInputPulse = new THREE.Mesh(
new THREE.BoxGeometry(0.20, 0.20, 0.20),
new THREE.MeshBasicMaterial({ color: 0xffef91 })
);
insetInputPulse.visible = false;
insetInputPulse.renderOrder = 9;
inset.add(insetInputPulse);
const insetResponsePulse = new THREE.Mesh(
new THREE.BoxGeometry(0.20, 0.20, 0.20),
new THREE.MeshBasicMaterial({ color: 0x9cffff })
);
insetResponsePulse.visible = false;
insetResponsePulse.renderOrder = 9;
inset.add(insetResponsePulse);
// Decorative voxel motes in the background.
let seed = 731;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const moteGeometry = new THREE.BoxGeometry(0.08, 0.08, 0.08);
const moteMaterial = new THREE.MeshBasicMaterial({
color: 0x53658e,
transparent: true,
opacity: 0.3
});
const motes = new THREE.InstancedMesh(moteGeometry, moteMaterial, 65);
const moteDummy = new THREE.Object3D();
for (let i = 0; i < 65; i++) {
moteDummy.position.set(
-6 + random() * 12,
-2 + random() * 5.4,
-2.5 - random() * 5
);
const s = 0.45 + random() * 1.2;
moteDummy.scale.setScalar(s);
moteDummy.updateMatrix();
motes.setMatrixAt(i, moteDummy.matrix);
}
motes.instanceMatrix.needsUpdate = true;
scene.add(motes);
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const cycleDuration = 4.25;
let cycleStart = -100;
let cycleActive = false;
function clamp01(value) {
return Math.min(1, Math.max(0, value));
}
function smoothstep(edge0, edge1, value) {
const t = clamp01((value - edge0) / (edge1 - edge0));
return t * t * (3 - 2 * t);
}
function setStage(stageName) {
const order = ["input", "relay", "response"];
const activeIndex = order.indexOf(stageName);
stageElements.forEach((element) => {
const index = order.indexOf(element.dataset.stage);
element.classList.toggle("active", index === activeIndex);
element.classList.toggle("done", activeIndex >= 0 && index < activeIndex);
});
}
function triggerCycle() {
cycleStart = clock.getElapsedTime();
cycleActive = true;
statusElement.textContent = "Input · sensing the safe press";
setStage("input");
}
function resetCycleVisuals() {
mainInputPulse.visible = false;
mainMotorPulse.visible = false;
insetInputPulse.visible = false;
insetResponsePulse.visible = false;
relayMaterial.emissiveIntensity = 0.22;
insetRelayMaterial.emissiveIntensity = 0.25;
muscleMaterial.emissiveIntensity = 0.08;
insetResponseMaterial.emissiveIntensity = 0.12;
fingerPivots.forEach((pivot) => {
pivot.rotation.z = 0;
});
}
replayButton.addEventListener("click", triggerCycle);
resetViewButton.addEventListener("click", () => {
orbitTheta = 0.02;
orbitPhi = 0.20;
orbitRadius = 14;
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
triggerCycle();
}
});
// -------------------------------------------------------------------------
// Direct pointer controls and button picking
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function isButtonHit(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObject(buttonCap, false).length > 0;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerDown) {
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
if (
Math.abs(event.clientX - pointerStartX) +
Math.abs(event.clientY - pointerStartY) >
5
) {
pointerMoved = true;
}
orbitTheta -= dx * 0.006;
orbitPhi = Math.min(0.78, Math.max(0.07, orbitPhi - dy * 0.004));
previousPointerX = event.clientX;
previousPointerY = event.clientY;
updateCamera();
} else {
const nextHover = isButtonHit(event);
if (nextHover !== hoveredButton) {
hoveredButton = nextHover;
renderer.domElement.style.cursor = nextHover ? "pointer" : "grab";
}
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
const shouldTrigger = !pointerMoved && isButtonHit(event);
pointerDown = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (shouldTrigger) {
triggerCycle();
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
pointerMoved = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbitRadius = Math.min(20, Math.max(10, orbitRadius + event.deltaY * 0.008));
updateCamera();
},
{ passive: false }
);
renderer.domElement.style.cursor = "grab";
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const localTime = elapsed - cycleStart;
let pressAmount = 0;
let responseAmount = 0;
if (cycleActive && localTime >= 0 && localTime <= cycleDuration) {
// The cap compresses briefly and safely.
if (localTime < 0.28) {
pressAmount = smoothstep(0, 0.28, localTime);
} else if (localTime < 0.44) {
pressAmount = 1 - smoothstep(0.28, 0.44, localTime);
}
capPivot.position.y = 0.15 - pressAmount * 0.13;
// Input travels from the fingertip toward the relay.
const inputProgress = clamp01((localTime - 0.16) / 0.96);
mainInputPulse.visible = inputProgress < 1;
if (mainInputPulse.visible) {
mainInputPulse.position.copy(mainSensoryCurve.getPointAt(inputProgress));
mainInputPulse.rotation.y += 0.08;
mainInputPulse.rotation.x += 0.05;
}
// The enlarged view follows the same input.
const insetInputProgress = clamp01((localTime - 0.62) / 0.68);
insetInputPulse.visible = insetInputProgress < 1;
if (insetInputPulse.visible) {
insetInputPulse.position.copy(
insetSensoryCurve.getPointAt(insetInputProgress)
);
insetInputPulse.rotation.y += 0.08;
}
// Relay flash.
const relayPulse = 1 - Math.abs(localTime - 1.43) / 0.55;
const relayGlow = clamp01(relayPulse);
relayMaterial.emissiveIntensity = 0.22 + relayGlow * 1.9;
insetRelayMaterial.emissiveIntensity = 0.25 + relayGlow * 2.2;
mainRelay.scale.setScalar(1 + relayGlow * 0.2);
insetRelay.scale.setScalar(1 + relayGlow * 0.18);
if (localTime >= 1.15 && localTime < 1.72) {
statusElement.textContent = "Relay · passing the signal";
setStage("relay");
} else if (localTime < 1.15) {
statusElement.textContent = "Input · sensing the safe press";
setStage("input");
} else {
statusElement.textContent = "Response · activating the effector";
setStage("response");
}
// Response signal travels back to the muscle.
const motorProgress = clamp01((localTime - 1.43) / 1.12);
mainMotorPulse.visible = motorProgress < 1;
if (mainMotorPulse.visible) {
mainMotorPulse.position.copy(mainMotorCurve.getPointAt(motorProgress));
mainMotorPulse.rotation.x += 0.07;
mainMotorPulse.rotation.z += 0.05;
}
const insetResponseProgress = clamp01((localTime - 1.58) / 0.86);
insetResponsePulse.visible = insetResponseProgress < 1;
if (insetResponsePulse.visible) {
insetResponsePulse.position.copy(
insetResponseCurve.getPointAt(insetResponseProgress)
);
insetResponsePulse.rotation.y += 0.07;
}
// The hand makes a small, harmless withdrawal.
responseAmount = smoothstep(2.14, 3.02, localTime);
fingerPivots.forEach((pivot, index) => {
pivot.rotation.z = -responseAmount * (0.08 + index * 0.012);
});
const responseGlow = smoothstep(2.05, 2.55, localTime);
muscleMaterial.emissiveIntensity = 0.08 + responseGlow * 1.55;
insetResponseMaterial.emissiveIntensity = 0.12 + responseGlow * 1.35;
} else {
capPivot.position.y = 0.15;
mainRelay.scale.setScalar(1);
insetRelay.scale.setScalar(1);
if (cycleActive && localTime > cycleDuration) {
cycleActive = false;
statusElement.textContent = "Cycle complete · tap again or run reflex";
setStage("");
resetCycleVisuals();
}
}
buttonCapMaterial.emissiveIntensity =
0.12 + (hoveredButton ? 0.32 : 0) + pressAmount * 0.45;
motes.rotation.y = Math.sin(elapsed * 0.07) * 0.035;
cyanLight.position.x = 3.2 + Math.sin(elapsed * 0.55) * 0.18;
renderer.render(scene, camera);
}
resetCycleVisuals();
updateCamera();
renderer.render(scene, camera);
loading.classList.add("hidden");
// One gentle automatic demonstration makes the full sequence discoverable.
if (!reducedMotion) {
window.setTimeout(triggerCycle, 950);
} else {
statusElement.textContent = "Ready · activate the reflex pathway";
}
animate();
</script>
</body>
</html>
```