Prompt specification
Build or customize the Three.js 3D scene "Sensory and motor pathway board" 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: Sensory and motor pathway board
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sensory-and-motor-pathway-board-x1017
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing reflex pathways. Build a schematic receptor, sensory neuron, spinal processing node, motor neuron, and muscle target; distinguish signal direction from anatomical scale using separate labels. A 3D cutaway view.
Working Three.js Starter (sensory-and-motor-pathway-board-x1017):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Reflex Pathway</title>
<style>
:root {
--bg: #07111f;
--panel: rgba(10, 22, 39, 0.86);
--panel-strong: rgba(13, 29, 49, 0.95);
--line: rgba(157, 190, 219, 0.2);
--text: #eaf4ff;
--muted: #9db1c8;
--afferent: #49baff;
--efferent: #58e69b;
--node: #ffb44b;
--receptor: #ff7188;
--muscle: #ef6074;
--bone: #dbe7f1;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
header {
position: fixed;
top: 22px;
left: 24px;
z-index: 10;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--node);
box-shadow: 0 0 15px rgba(255, 180, 75, 0.8);
content: "";
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 38px);
font-weight: 660;
letter-spacing: -0.035em;
line-height: 1.05;
}
.subtitle {
max-width: 540px;
margin-top: 9px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.panel {
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#info-panel {
position: fixed;
top: 24px;
right: 24px;
z-index: 10;
width: 286px;
padding: 17px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.panel-title span:last-child {
color: var(--muted);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.12em;
}
.steps {
display: grid;
gap: 5px;
}
.step {
display: grid;
grid-template-columns: 25px 1fr;
align-items: center;
min-height: 38px;
padding: 6px 8px;
border: 1px solid transparent;
border-radius: 10px;
color: var(--muted);
transition:
background 180ms ease,
border-color 180ms ease,
color 180ms ease;
}
.step.active {
border-color: rgba(255, 180, 75, 0.27);
background: rgba(255, 180, 75, 0.09);
color: var(--text);
}
.step-number {
display: grid;
width: 20px;
height: 20px;
place-items: center;
border: 1px solid rgba(157, 190, 219, 0.27);
border-radius: 50%;
color: var(--muted);
font-size: 9px;
font-weight: 800;
}
.step.active .step-number {
border-color: var(--node);
background: var(--node);
color: #18202a;
}
.step strong {
display: block;
font-size: 11px;
font-weight: 700;
}
.step small {
display: block;
margin-top: 2px;
font-size: 9px;
line-height: 1.35;
}
.accuracy-note {
margin: 13px 2px 0;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9.5px;
line-height: 1.5;
}
#legend {
position: fixed;
bottom: 22px;
left: 24px;
z-index: 10;
display: flex;
align-items: stretch;
gap: 10px;
pointer-events: none;
}
.legend-card {
min-width: 210px;
padding: 12px 14px;
border-radius: 13px;
background: var(--panel-strong);
}
.legend-card.direction {
border: 1px solid rgba(73, 186, 255, 0.3);
}
.legend-card.scale {
border: 1px solid rgba(219, 231, 241, 0.27);
}
.legend-heading {
margin-bottom: 8px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.direction .legend-heading {
color: var(--afferent);
}
.scale .legend-heading {
color: var(--bone);
}
.signal-key {
display: flex;
align-items: center;
gap: 12px;
font-size: 10px;
font-weight: 700;
}
.signal-key span {
display: flex;
align-items: center;
gap: 5px;
}
.signal-key i {
display: inline-block;
width: 17px;
height: 3px;
border-radius: 3px;
background: currentColor;
box-shadow: 0 0 9px currentColor;
}
.signal-key i::after {
display: block;
width: 0;
height: 0;
margin-left: 12px;
margin-top: -4px;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 7px solid currentColor;
content: "";
}
.signal-key .afferent {
color: var(--afferent);
}
.signal-key .efferent {
color: var(--efferent);
}
.legend-note {
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.ruler {
position: relative;
width: 100%;
height: 10px;
margin-bottom: 7px;
border-bottom: 2px solid var(--bone);
}
.ruler::before,
.ruler::after {
position: absolute;
bottom: -6px;
width: 2px;
height: 8px;
background: var(--bone);
content: "";
}
.ruler::before {
left: 0;
}
.ruler::after {
right: 0;
}
#toolbar {
position: fixed;
right: 24px;
bottom: 22px;
z-index: 12;
display: flex;
gap: 8px;
}
button {
border: 1px solid rgba(157, 190, 219, 0.25);
border-radius: 11px;
padding: 10px 13px;
background: rgba(13, 29, 49, 0.92);
color: var(--text);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.22);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.03em;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(255, 180, 75, 0.5);
background: rgba(24, 44, 69, 0.97);
transform: translateY(-1px);
}
button.active {
border-color: rgba(73, 186, 255, 0.5);
color: var(--afferent);
}
#leaders,
#labels {
position: fixed;
inset: 0;
z-index: 7;
width: 100%;
height: 100%;
overflow: hidden;
pointer-events: none;
}
#leaders {
z-index: 6;
}
.structure-label {
position: absolute;
min-width: 112px;
max-width: 190px;
padding: 8px 10px;
transform: translate(-50%, -50%);
border: 1px solid rgba(157, 190, 219, 0.24);
border-left: 3px solid var(--label-color, var(--bone));
border-radius: 9px;
background: rgba(7, 17, 31, 0.88);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
white-space: nowrap;
}
.structure-label strong {
display: block;
color: var(--label-color, var(--text));
font-size: 10px;
font-weight: 800;
letter-spacing: 0.02em;
}
.structure-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8.5px;
font-weight: 500;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: var(--bg);
color: var(--muted);
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
#info-panel {
top: auto;
right: 12px;
bottom: 76px;
width: 245px;
}
#legend {
bottom: 12px;
left: 12px;
}
#toolbar {
right: 12px;
bottom: 12px;
}
.legend-card {
min-width: 180px;
}
}
@media (max-width: 650px) {
header {
top: 14px;
left: 14px;
}
.subtitle {
max-width: 330px;
font-size: 10px;
}
#info-panel {
display: none;
}
#legend {
bottom: 66px;
gap: 6px;
}
.legend-card {
min-width: 0;
width: 172px;
padding: 9px;
}
.signal-key {
gap: 7px;
font-size: 8px;
}
.legend-note {
font-size: 8px;
}
#toolbar {
right: 10px;
bottom: 10px;
left: 10px;
justify-content: center;
}
button {
flex: 1;
padding: 9px 7px;
font-size: 9px;
}
.structure-label {
min-width: 88px;
padding: 6px 7px;
}
.structure-label strong {
font-size: 8px;
}
.structure-label small {
font-size: 7px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive 3D cutaway of a spinal reflex pathway. Drag to orbit and scroll to zoom."
></canvas>
<header>
<div class="eyebrow">Interactive anatomy · 3D cutaway</div>
<h1>Spinal Reflex Pathway</h1>
<div class="subtitle">
Follow a stimulus from a skin receptor through the sensory neuron,
spinal processing node, motor neuron, and responding muscle.
Drag to orbit · scroll to zoom.
</div>
</header>
<aside id="info-panel" class="panel">
<div class="panel-title">
<span>Signal sequence</span>
<span>Polysynaptic</span>
</div>
<div class="steps">
<div class="step" data-step="0">
<div class="step-number">1</div>
<div>
<strong>Stimulus detected</strong>
<small>A skin receptor responds to the stimulus.</small>
</div>
</div>
<div class="step" data-step="1">
<div class="step-number">2</div>
<div>
<strong>Afferent impulse</strong>
<small>The sensory neuron carries the signal to the spinal cord.</small>
</div>
</div>
<div class="step" data-step="2">
<div class="step-number">3</div>
<div>
<strong>Spinal integration</strong>
<small>A processing node relays the signal locally.</small>
</div>
</div>
<div class="step" data-step="3">
<div class="step-number">4</div>
<div>
<strong>Efferent impulse</strong>
<small>The motor neuron carries an output toward muscle.</small>
</div>
</div>
<div class="step" data-step="4">
<div class="step-number">5</div>
<div>
<strong>Muscle response</strong>
<small>The target muscle contracts.</small>
</div>
</div>
</div>
<p class="accuracy-note">
This illustrative reflex integrates in the spinal cord. Parallel ascending
signals to the brain are not shown, and the pathway is not drawn to scale.
</p>
</aside>
<div id="legend">
<section class="legend-card direction">
<div class="legend-heading">Signal direction · schematic</div>
<div class="signal-key">
<span class="afferent"><i></i>Afferent</span>
<span class="efferent"><i></i>Efferent</span>
</div>
<div class="legend-note" style="margin-top: 7px;">
Arrowheads and moving pulses show information flow, not path length.
</div>
</section>
<section class="legend-card scale">
<div class="legend-heading">Anatomical scale · relative</div>
<div class="ruler"></div>
<div class="legend-note">
Structures retain relative size; neurons and the spinal segment are enlarged for clarity.
</div>
</section>
</div>
<div id="toolbar">
<button id="play-button" type="button">Pause signal</button>
<button id="replay-button" type="button">Replay</button>
<button id="cutaway-button" class="active" type="button">Cutaway: on</button>
<button id="reset-button" type="button">Reset view</button>
</div>
<svg id="leaders" aria-hidden="true"></svg>
<div id="labels" aria-hidden="true"></div>
<div id="loading">Loading 3D 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 scene
// -------------------------------------------------------------------------
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.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x07111f, 1);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x07111f, 13, 27);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0.65, 2.25, 0);
// Direct camera controls: no addons are used.
const spherical = new THREE.Spherical(12.9, 1.28, 0.62);
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - dy * 0.006,
0.48,
2.12
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
7.5,
20
);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
cameraTarget.set(0.65, 2.25, 0);
spherical.set(12.9, 1.28, 0.62);
updateCamera();
}
// -------------------------------------------------------------------------
// Lighting and floor
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xa9d8ff, 0x111521, 2.0));
const keyLight = new THREE.DirectionalLight(0xd9efff, 3.0);
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 = 9;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 24;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x318cff, 18, 16, 2);
rimLight.position.set(-4, 4, -4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff8b65, 9, 10, 2);
warmLight.position.set(4.5, 4.2, 3);
scene.add(warmLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x091522,
roughness: 0.94,
metalness: 0.03
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.035;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 48, 0x31506b, 0x183148);
grid.position.y = -0.015;
grid.material.transparent = true;
grid.material.opacity = 0.26;
scene.add(grid);
const model = new THREE.Group();
model.position.y = 0.02;
scene.add(model);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
const up = new THREE.Vector3(0, 1, 0);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.52,
metalness: 0.05,
...options
});
}
function cylinderBetween(a, b, radius, material, radialSegments = 24) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(up, direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
model.add(mesh);
return mesh;
}
function makeCurve(points) {
return new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point)),
false,
"catmullrom",
0.35
);
}
function makeTube(points, radius, material, segments = 100) {
const curve = makeCurve(points);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, segments, radius, 10, false),
material
);
mesh.castShadow = true;
model.add(mesh);
return { curve, mesh };
}
function makeGlowTube(points, radius, color) {
const curve = makeCurve(points);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.13,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 100, radius, 10, false),
material
);
mesh.renderOrder = 1;
model.add(mesh);
return mesh;
}
function addDirectionalArrows(curve, color) {
const material = standardMaterial(color, {
emissive: color,
emissiveIntensity: 1.6,
roughness: 0.35
});
[0.12, 0.37, 0.63, 0.84].forEach((t) => {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.075, 0.21, 12),
material
);
arrow.position.copy(curve.getPointAt(t));
arrow.quaternion.setFromUnitVectors(
up,
curve.getTangentAt(t).normalize()
);
model.add(arrow);
});
}
function sphereAt(position, radius, material, scale = [1, 1, 1]) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 30, 20),
material
);
mesh.position.set(...position);
mesh.scale.set(...scale);
mesh.castShadow = true;
model.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const boneMaterial = standardMaterial(0xdbe7f1, {
roughness: 0.42,
metalness: 0.02
});
const discMaterial = standardMaterial(0x7892a9, {
roughness: 0.72,
metalness: 0.02
});
const skinMaterial = new THREE.MeshPhysicalMaterial({
color: 0x83bff2,
transparent: true,
opacity: 0.18,
roughness: 0.35,
metalness: 0,
clearcoat: 0.35,
depthWrite: false,
side: THREE.DoubleSide
});
const afferentMaterial = standardMaterial(0x49baff, {
emissive: 0x197db8,
emissiveIntensity: 1.35,
roughness: 0.3
});
const efferentMaterial = standardMaterial(0x58e69b, {
emissive: 0x1b9d61,
emissiveIntensity: 1.35,
roughness: 0.3
});
const nodeMaterial = standardMaterial(0xffb44b, {
emissive: 0xb96808,
emissiveIntensity: 1.3,
roughness: 0.28
});
const receptorMaterial = standardMaterial(0xff7188, {
emissive: 0xb6253f,
emissiveIntensity: 1.2,
roughness: 0.32
});
const muscleMaterial = standardMaterial(0xef6074, {
emissive: 0x6d1529,
emissiveIntensity: 0.45,
roughness: 0.56
});
// -------------------------------------------------------------------------
// Cutaway spinal column
// -------------------------------------------------------------------------
const cordX = -0.72;
const cordCenterY = 2.55;
const cordMaterial = new THREE.MeshPhysicalMaterial({
color: 0xc8e7ff,
transparent: true,
opacity: 0.23,
roughness: 0.25,
metalness: 0,
clearcoat: 0.6,
depthWrite: false,
side: THREE.DoubleSide
});
const cord = new THREE.Mesh(
new THREE.CylinderGeometry(0.44, 0.44, 4.5, 48, 1, true),
cordMaterial
);
cord.position.set(cordX, cordCenterY, 0);
model.add(cord);
const innerCord = new THREE.Mesh(
new THREE.CylinderGeometry(0.345, 0.345, 4.42, 40, 1, true),
new THREE.MeshPhysicalMaterial({
color: 0x89b9dc,
transparent: true,
opacity: 0.16,
roughness: 0.4,
depthWrite: false,
side: THREE.DoubleSide
})
);
innerCord.position.copy(cord.position);
model.add(innerCord);
// Vertebral bodies sit anterior/left of the cord in this lateral cutaway.
[0.65, 1.45, 2.25, 3.05, 3.85, 4.65].forEach((y, index) => {
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.46, 0.46, 0.34, 32),
boneMaterial
);
body.position.set(-1.63, y, 0);
body.castShadow = true;
body.receiveShadow = true;
model.add(body);
const disc = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.43, 0.09, 32),
discMaterial
);
disc.position.set(-1.63, y + 0.42, 0);
model.add(disc);
// Open vertebral arch: the front wedge is removed to expose the cord.
const archPoints = [];
for (let i = 0; i <= 28; i++) {
const angle = THREE.MathUtils.degToRad(135 + (270 * i) / 28);
archPoints.push([
cordX + Math.cos(angle) * 0.64,
y,
Math.sin(angle) * 0.64
]);
}
makeTube(archPoints, 0.085, boneMaterial, 56);
cylinderBetween(
[cordX - 0.58, y, 0],
[-1.48, y, 0],
0.075,
boneMaterial,
16
);
});
// Stylized gray-matter horns at the active spinal level.
const grayMaterial = standardMaterial(0xf1c98a, {
emissive: 0x7a4815,
emissiveIntensity: 0.35,
roughness: 0.6
});
[
[-0.86, 2.54, -0.15, 0.14, 0.34, 0.17],
[-0.58, 2.54, -0.15, 0.14, 0.34, 0.17],
[-0.83, 2.54, 0.16, 0.13, 0.31, 0.16],
[-0.61, 2.54, 0.16, 0.13, 0.31, 0.16]
].forEach(([x, y, z, sx, sy, sz], index) => {
const horn = sphereAt([x, y, z], 1, grayMaterial, [sx, sy, sz]);
horn.rotation.z = index < 2 ? -0.3 : 0.3;
});
// -------------------------------------------------------------------------
// Stylized transparent upper limb
// -------------------------------------------------------------------------
const shoulder = sphereAt([0.12, 2.62, 0], 0.56, skinMaterial, [1, 0.9, 0.95]);
const upperArm = cylinderBetween(
[0.25, 2.58, 0],
[2.02, 2.33, 0],
0.37,
skinMaterial,
36
);
const elbow = sphereAt([2.02, 2.33, 0], 0.36, skinMaterial);
const forearm = cylinderBetween(
[2.02, 2.33, 0],
[3.57, 1.90, 0],
0.27,
skinMaterial,
36
);
const hand = sphereAt([3.78, 1.78, 0], 0.52, skinMaterial, [0.9, 0.72, 0.55]);
// Fingers.
cylinderBetween(
[3.91, 1.76, 0.08],
[4.43, 1.64, 0.08],
0.105,
skinMaterial,
20
);
cylinderBetween(
[3.89, 1.68, -0.09],
[4.30, 1.56, -0.09],
0.085,
skinMaterial,
20
);
cylinderBetween(
[3.82, 1.61, -0.17],
[4.13, 1.53, -0.17],
0.075,
skinMaterial,
20
);
// Humerus and forearm bones.
cylinderBetween(
[0.28, 2.58, 0],
[2.02, 2.33, 0],
0.115,
boneMaterial
);
sphereAt([2.02, 2.33, 0], 0.15, boneMaterial);
cylinderBetween(
[2.02, 2.33, 0.11],
[3.57, 1.90, 0.10],
0.072,
boneMaterial,
18
);
cylinderBetween(
[2.02, 2.33, -0.11],
[3.57, 1.90, -0.10],
0.065,
boneMaterial,
18
);
// Muscle target, centered in the upper arm.
const muscleGroup = new THREE.Group();
muscleGroup.position.set(1.02, 2.45, 0.15);
model.add(muscleGroup);
const muscleBody = new THREE.Mesh(
new THREE.SphereGeometry(1, 36, 24),
muscleMaterial
);
muscleBody.scale.set(0.54, 0.19, 0.18);
muscleBody.rotation.z = -0.08;
muscleBody.castShadow = true;
muscleGroup.add(muscleBody);
const fiberMaterial = standardMaterial(0xff8797, {
emissive: 0x641126,
emissiveIntensity: 0.25,
roughness: 0.62
});
[-0.075, -0.025, 0.025, 0.075].forEach((offset, index) => {
const fiber = new THREE.Mesh(
new THREE.TubeGeometry(
makeCurve([
[-0.48, offset, offset * 0.25],
[-0.15, offset + 0.015, 0.14 + index * 0.003],
[0.16, offset - 0.01, 0.14 + index * 0.003],
[0.48, offset, offset * 0.25]
]),
42,
0.012,
7,
false
),
fiberMaterial
);
muscleGroup.add(fiber);
});
// -------------------------------------------------------------------------
// Receptor, ganglion, and spinal processing node
// -------------------------------------------------------------------------
const receptorPosition = new THREE.Vector3(4.37, 1.65, 0.1);
const receptor = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.105, 2),
receptorMaterial
);
receptor.position.copy(receptorPosition);
model.add(receptor);
const receptorHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.16, 0.012, 10, 36),
new THREE.MeshBasicMaterial({
color: 0xff7188,
transparent: true,
opacity: 0.7,
blending: THREE.AdditiveBlending
})
);
receptorHalo.position.copy(receptorPosition);
receptorHalo.rotation.x = 0.3;
model.add(receptorHalo);
const ganglion = sphereAt(
[-0.25, 3.10, 0.08],
0.145,
standardMaterial(0xc88cff, {
emissive: 0x66389c,
emissiveIntensity: 0.85
})
);
const processingNode = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.145, 2),
nodeMaterial
);
processingNode.position.set(cordX, 2.52, 0);
model.add(processingNode);
const nodeHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.016, 10, 36),
new THREE.MeshBasicMaterial({
color: 0xffb44b,
transparent: true,
opacity: 0.65,
blending: THREE.AdditiveBlending
})
);
nodeHalo.position.copy(processingNode.position);
nodeHalo.rotation.x = 0.25;
model.add(nodeHalo);
const nodeLight = new THREE.PointLight(0xffa332, 0, 1.5, 2);
nodeLight.position.copy(processingNode.position);
model.add(nodeLight);
// Motor neuron soma in the ventral portion of the processing region.
const motorSoma = sphereAt(
[-0.59, 2.30, 0.06],
0.085,
standardMaterial(0x77efa9, {
emissive: 0x1b9d61,
emissiveIntensity: 1.0
})
);
// -------------------------------------------------------------------------
// Sensory and motor pathways
// -------------------------------------------------------------------------
const sensoryPoints = [
[4.37, 1.65, 0.10],
[4.05, 1.83, 0.15],
[3.56, 1.98, 0.18],
[2.75, 2.15, 0.20],
[2.05, 2.34, 0.23],
[1.25, 2.50, 0.25],
[0.50, 2.70, 0.23],
[-0.24, 3.10, 0.08],
[-0.56, 2.91, -0.02],
[-0.72, 2.68, -0.08],
[-0.72, 2.52, 0.00]
];
const motorPoints = [
[-0.72, 2.52, 0.00],
[-0.62, 2.34, 0.06],
[-0.28, 2.28, 0.10],
[0.20, 2.33, 0.13],
[0.72, 2.40, 0.15],
[1.22, 2.44, 0.15],
[1.48, 2.43, 0.15]
];
const sensory = makeTube(sensoryPoints, 0.034, afferentMaterial, 150);
const motor = makeTube(motorPoints, 0.038, efferentMaterial, 100);
makeGlowTube(sensoryPoints, 0.075, 0x49baff);
makeGlowTube(motorPoints, 0.08, 0x58e69b);
addDirectionalArrows(sensory.curve, 0x49baff);
addDirectionalArrows(motor.curve, 0x58e69b);
// Traveling signal pulses.
const sensoryPulse = new THREE.Mesh(
new THREE.SphereGeometry(0.078, 20, 14),
new THREE.MeshBasicMaterial({ color: 0xd7f4ff })
);
sensoryPulse.add(
new THREE.PointLight(0x49baff, 2.5, 1.1, 2)
);
model.add(sensoryPulse);
const motorPulse = new THREE.Mesh(
new THREE.SphereGeometry(0.078, 20, 14),
new THREE.MeshBasicMaterial({ color: 0xd8ffea })
);
motorPulse.add(
new THREE.PointLight(0x58e69b, 2.5, 1.1, 2)
);
model.add(motorPulse);
// -------------------------------------------------------------------------
// Relative-size ruler, intentionally separate from the signal arrows
// -------------------------------------------------------------------------
const rulerGroup = new THREE.Group();
rulerGroup.position.set(0.65, 0.05, 1.38);
model.add(rulerGroup);
const rulerMaterial = new THREE.MeshBasicMaterial({
color: 0xdbe7f1,
transparent: true,
opacity: 0.65
});
cylinderBetween(
[0, 0, 0],
[1.35, 0, 0],
0.012,
rulerMaterial,
8
);
[0, 0.675, 1.35].forEach((x) => {
cylinderBetween(
[x, -0.08, 0],
[x, 0.08, 0],
0.012,
rulerMaterial,
8
);
});
// -------------------------------------------------------------------------
// HTML labels and projected leader lines
// -------------------------------------------------------------------------
const labelLayer = document.querySelector("#labels");
const leaderLayer = document.querySelector("#leaders");
const svgNS = "http://www.w3.org/2000/svg";
const labelDefinitions = [
{
id: "receptor",
title: "Skin receptor",
detail: "Detects the stimulus",
anchor: receptorPosition,
offset: [66, -45],
color: "#ff7188"
},
{
id: "sensory",
title: "Sensory neuron",
detail: "Afferent · toward spinal cord",
anchor: new THREE.Vector3(3.0, 2.16, 0.2),
offset: [-20, -60],
color: "#49baff"
},
{
id: "ganglion",
title: "Dorsal root ganglion",
detail: "Sensory cell body",
anchor: ganglion.position,
offset: [-85, -30],
color: "#c88cff"
},
{
id: "node",
title: "Spinal processing node",
detail: "Interneuron / local synapse",
anchor: processingNode.position,
offset: [-118, 0],
color: "#ffb44b"
},
{
id: "motor",
title: "Motor neuron",
detail: "Efferent · toward muscle",
anchor: new THREE.Vector3(-0.08, 2.30, 0.12),
offset: [3, 65],
color: "#58e69b"
},
{
id: "muscle",
title: "Muscle target",
detail: "Produces contraction",
anchor: new THREE.Vector3(1.2, 2.45, 0.16),
offset: [48, 68],
color: "#ef6074"
},
{
id: "cord",
title: "Cutaway spinal cord",
detail: "Gray matter exposed",
anchor: new THREE.Vector3(cordX, 4.45, 0),
offset: [-108, -42],
color: "#dbe7f1"
},
{
id: "scale",
title: "Anatomical scale",
detail: "Relative structure sizes",
anchor: new THREE.Vector3(1.32, 0.13, 1.38),
offset: [45, 34],
color: "#dbe7f1"
}
];
const projectedLabels = labelDefinitions.map((definition) => {
const element = document.createElement("div");
element.className = "structure-label";
element.style.setProperty("--label-color", definition.color);
element.innerHTML = `
<strong>${definition.title}</strong>
<small>${definition.detail}</small>
`;
labelLayer.appendChild(element);
const line = document.createElementNS(svgNS, "line");
line.setAttribute("stroke", definition.color);
line.setAttribute("stroke-width", "1.1");
line.setAttribute("stroke-opacity", "0.62");
leaderLayer.appendChild(line);
const dot = document.createElementNS(svgNS, "circle");
dot.setAttribute("r", "3");
dot.setAttribute("fill", definition.color);
dot.setAttribute("stroke", "#07111f");
dot.setAttribute("stroke-width", "1.5");
leaderLayer.appendChild(dot);
return { definition, element, line, dot };
});
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
const compactScale = width < 700 ? 0.56 : 1;
leaderLayer.setAttribute("viewBox", `0 0 ${width} ${height}`);
projectedLabels.forEach(({ definition, element, line, dot }) => {
const projected = definition.anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
element.style.display = "none";
line.style.display = "none";
dot.style.display = "none";
return;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const labelX = THREE.MathUtils.clamp(
x + definition.offset[0] * compactScale,
70,
width - 70
);
const labelY = THREE.MathUtils.clamp(
y + definition.offset[1] * compactScale,
86,
height - 86
);
element.style.display = "block";
element.style.left = `${labelX}px`;
element.style.top = `${labelY}px`;
line.style.display = "block";
dot.style.display = "block";
line.setAttribute("x1", x);
line.setAttribute("y1", y);
line.setAttribute("x2", labelX);
line.setAttribute("y2", labelY);
dot.setAttribute("cx", x);
dot.setAttribute("cy", y);
});
}
// -------------------------------------------------------------------------
// Animation and controls
// -------------------------------------------------------------------------
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const state = {
running: !reducedMotion,
simulationTime: 0,
cutaway: true
};
const cycleDuration = 6.0;
const playButton = document.querySelector("#play-button");
const replayButton = document.querySelector("#replay-button");
const cutawayButton = document.querySelector("#cutaway-button");
const resetButton = document.querySelector("#reset-button");
const stepElements = [...document.querySelectorAll(".step")];
function updatePlayButton() {
playButton.textContent = state.running ? "Pause signal" : "Play signal";
}
playButton.addEventListener("click", () => {
state.running = !state.running;
updatePlayButton();
});
replayButton.addEventListener("click", () => {
state.simulationTime = 0;
state.running = true;
updatePlayButton();
});
cutawayButton.addEventListener("click", () => {
state.cutaway = !state.cutaway;
skinMaterial.opacity = state.cutaway ? 0.18 : 0.82;
skinMaterial.depthWrite = !state.cutaway;
skinMaterial.needsUpdate = true;
cutawayButton.classList.toggle("active", state.cutaway);
cutawayButton.textContent = `Cutaway: ${state.cutaway ? "on" : "off"}`;
});
resetButton.addEventListener("click", resetCamera);
updatePlayButton();
const clock = new THREE.Clock();
function smoothstep(edge0, edge1, value) {
const t = THREE.MathUtils.clamp(
(value - edge0) / (edge1 - edge0),
0,
1
);
return t * t * (3 - 2 * t);
}
function setActiveStep(index) {
stepElements.forEach((element, i) => {
element.classList.toggle("active", i === index);
});
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (state.running) {
state.simulationTime += delta;
}
const phase = (state.simulationTime % cycleDuration) / cycleDuration;
// Afferent signal travels from receptor to spinal processing node.
const sensoryProgress = THREE.MathUtils.clamp(
(phase - 0.08) / 0.38,
0,
1
);
const sensoryVisible =
phase >= 0.08 && phase < 0.48;
sensoryPulse.visible = sensoryVisible;
if (sensoryVisible) {
sensoryPulse.position.copy(
sensory.curve.getPointAt(sensoryProgress)
);
const pulseScale = 0.9 + Math.sin(phase * 90) * 0.12;
sensoryPulse.scale.setScalar(pulseScale);
}
// Efferent signal travels from spinal node to the muscle.
const motorProgress = THREE.MathUtils.clamp(
(phase - 0.50) / 0.36,
0,
1
);
const motorVisible =
phase >= 0.50 && phase < 0.89;
motorPulse.visible = motorVisible;
if (motorVisible) {
motorPulse.position.copy(
motor.curve.getPointAt(motorProgress)
);
const pulseScale = 0.9 + Math.sin(phase * 95) * 0.12;
motorPulse.scale.setScalar(pulseScale);
}
// Receptor activation.
const receptorFlash =
smoothstep(0.0, 0.045, phase) *
(1 - smoothstep(0.12, 0.23, phase));
receptorMaterial.emissiveIntensity = 1.2 + receptorFlash * 3.0;
receptorHalo.scale.setScalar(1 + receptorFlash * 0.8);
receptorHalo.material.opacity = 0.22 + receptorFlash * 0.75;
// Spinal node activation.
const nodeFlash =
smoothstep(0.41, 0.48, phase) *
(1 - smoothstep(0.53, 0.64, phase));
nodeMaterial.emissiveIntensity = 1.3 + nodeFlash * 3.0;
nodeHalo.scale.setScalar(1 + nodeFlash * 0.55);
nodeHalo.material.opacity = 0.25 + nodeFlash * 0.7;
nodeLight.intensity = nodeFlash * 5.0;
// Muscle contraction.
const contractionPhase = THREE.MathUtils.clamp(
(phase - 0.83) / 0.17,
0,
1
);
const contraction =
contractionPhase < 1
? Math.sin(contractionPhase * Math.PI)
: 0;
muscleGroup.scale.set(
1 - contraction * 0.09,
1 + contraction * 0.16,
1 + contraction * 0.12
);
muscleMaterial.emissiveIntensity = 0.45 + contraction * 1.8;
fiberMaterial.emissiveIntensity = 0.25 + contraction * 1.3;
// Active timeline step.
let activeStep = 0;
if (phase >= 0.5 && phase < 0.86) {
activeStep = 3;
} else if (phase >= 0.86) {
activeStep = 4;
} else if (phase >= 0.41) {
activeStep = 2;
} else if (phase >= 0.1) {
activeStep = 1;
}
setActiveStep(activeStep);
updateLabels();
renderer.render(scene, camera);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
document.querySelector("#loading").classList.add("hidden");
animate();
</script>
</body>
</html>
```