Prompt specification
Build or customize the Three.js 3D scene "Pyloric junction lumen and wall study" 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: Pyloric junction lumen and wall study
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/pyloric-junction-lumen-and-wall-study-x0973
Scene Description Prompt:
A stomach-to-duodenum cutaway with a tracer traveling through the continuous lumen, clearly separated from surrounding tissue. Create one HTML file using Three.js from cdnjs.
Working Three.js Starter (pyloric-junction-lumen-and-wall-study-x0973):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stomach–Duodenum Cutaway</title>
<style>
:root {
color-scheme: dark;
--ink: #eaf8f8;
--muted: #8ca9af;
--accent: #55f2ce;
--line: rgba(160, 226, 225, 0.18);
--panel: rgba(7, 20, 27, 0.68);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 58% 42%, #142a33 0%, #09151d 48%, #050c12 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-block {
position: absolute;
top: clamp(22px, 4vw, 52px);
left: clamp(22px, 4vw, 58px);
width: min(390px, calc(100vw - 44px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
color: var(--accent);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 1px;
background: var(--accent);
box-shadow: 0 0 10px rgba(85, 242, 206, 0.65);
}
h1 {
margin: 0;
max-width: 360px;
font-size: clamp(31px, 4.2vw, 60px);
font-weight: 620;
line-height: 0.98;
letter-spacing: -0.045em;
text-wrap: balance;
}
.subtitle {
max-width: 330px;
margin: 17px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
}
.live-chip {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 17px;
padding: 8px 11px;
border: 1px solid rgba(85, 242, 206, 0.24);
border-radius: 999px;
background: rgba(30, 90, 80, 0.14);
color: #a9fff0;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live-chip i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 10px var(--accent);
animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
50% { opacity: 0.38; transform: scale(0.75); }
}
.legend {
position: absolute;
left: clamp(22px, 4vw, 58px);
bottom: clamp(24px, 4vw, 50px);
display: grid;
gap: 9px;
min-width: 205px;
padding: 15px 17px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--panel);
backdrop-filter: blur(13px);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.22);
}
.legend-title {
margin-bottom: 2px;
color: #d5edef;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #9eb6bb;
font-size: 10px;
}
.swatch {
width: 17px;
height: 7px;
border-radius: 4px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.swatch.tissue { background: #ca7478; }
.swatch.lumen { background: #f0aa94; }
.swatch.tracer {
background: var(--accent);
box-shadow: 0 0 8px rgba(85, 242, 206, 0.65);
}
.controls {
position: absolute;
right: clamp(22px, 4vw, 52px);
bottom: clamp(24px, 4vw, 50px);
color: #77939a;
font-size: 9px;
line-height: 1.8;
letter-spacing: 0.12em;
text-align: right;
text-transform: uppercase;
}
.controls b {
color: #b9d2d5;
font-weight: 650;
}
.annotation {
position: absolute;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 8px;
padding: 6px 9px;
border: 1px solid rgba(227, 165, 158, 0.22);
border-radius: 7px;
background: rgba(7, 19, 25, 0.76);
color: #f1c3b9;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
transition: opacity 160ms ease;
}
.annotation::before {
content: "";
width: 5px;
height: 5px;
border: 1px solid currentColor;
border-radius: 50%;
box-shadow: 0 0 8px currentColor;
}
.annotation.tracer {
border-color: rgba(85, 242, 206, 0.38);
color: var(--accent);
}
.annotation.cut {
border-color: rgba(255, 204, 194, 0.3);
color: #ffd0c4;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #07131b;
color: #7b999f;
font-size: 10px;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader-ring {
width: 34px;
height: 34px;
margin: 0 auto 14px;
border: 1px solid rgba(85, 242, 206, 0.18);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 700px) {
.title-block { top: 20px; }
.subtitle { max-width: 275px; font-size: 11px; }
.legend {
bottom: 20px;
min-width: 0;
padding: 12px 13px;
}
.controls { display: none; }
.annotation { font-size: 8px; }
}
</style>
</head>
<body>
<div id="loading">
<div>
<div class="loader-ring"></div>
Constructing anatomical model
</div>
</div>
<div class="hud">
<section class="title-block">
<div class="eyebrow">Gastrointestinal cutaway</div>
<h1>Continuous<br>Lumen Study</h1>
<p class="subtitle">
The anterior wall is removed to reveal a tracer moving from the stomach
through the pylorus and into the duodenum.
</p>
<div class="live-chip"><i></i>Live tracer flow</div>
</section>
<section class="legend">
<div class="legend-title">Tissue key</div>
<div class="legend-row"><span class="swatch tissue"></span>Outer tissue wall</div>
<div class="legend-row"><span class="swatch lumen"></span>Exposed mucosa</div>
<div class="legend-row"><span class="swatch tracer"></span>Radiotracer particles</div>
</section>
<div class="controls">
<b>Drag</b> to orbit · <b>Scroll</b> to zoom<br>
<b>Double click</b> to reset view
</div>
<div id="label-esophagus" class="annotation">Esophagus</div>
<div id="label-stomach" class="annotation">Stomach</div>
<div id="label-duodenum" class="annotation">Duodenum</div>
<div id="label-tracer" class="annotation tracer">Tracer</div>
<div id="label-cut" class="annotation cut">Anterior wall removed</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131b);
scene.fog = new THREE.FogExp2(0x07131b, 0.034);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 80);
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
} catch (error) {
document.querySelector("#loading").innerHTML =
"<div>WebGL is required to display this model.</div>";
throw error;
}
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xc8f3ff, 0x29151c, 1.8));
const keyLight = new THREE.DirectionalLight(0xfff0e8, 3.3);
keyLight.position.set(4.5, 8, 7.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x91dff3, 1.45);
fillLight.position.set(-5, 2, 5);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xff8f96, 2.25);
rimLight.position.set(2, 4, -6);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Camera controls, implemented directly without external helper modules
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0.05, 1.18, 0),
radius: 10.7,
theta: 0.18,
phi: 1.22,
dragging: false,
pointerX: 0,
pointerY: 0,
moved: false
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.target.set(0.05, 1.18, 0);
controls.radius = innerWidth < 700 ? 12.4 : 10.7;
controls.theta = 0.18;
controls.phi = 1.22;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.moved = false;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.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.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(controls.phi - dy * 0.005, 0.48, 2.52);
controls.moved = true;
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
6.4,
16
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
resetCamera();
// -------------------------------------------------------------------------
// Continuous centerline: esophagus → stomach → pylorus → duodenum
// -------------------------------------------------------------------------
const points = [
new THREE.Vector3( 0.00, 5.20, -0.18),
new THREE.Vector3( 0.00, 4.55, -0.18),
new THREE.Vector3( 0.00, 3.90, -0.16),
new THREE.Vector3(-0.05, 3.15, -0.10),
new THREE.Vector3(-0.22, 2.55, -0.03),
new THREE.Vector3(-0.70, 2.10, 0.00),
new THREE.Vector3(-1.28, 1.52, 0.03),
new THREE.Vector3(-1.52, 0.84, 0.05),
new THREE.Vector3(-1.38, 0.22, 0.07),
new THREE.Vector3(-0.92, -0.18, 0.10),
new THREE.Vector3(-0.25, -0.24, 0.13),
new THREE.Vector3( 0.43, 0.02, 0.17),
new THREE.Vector3( 1.00, 0.36, 0.21),
new THREE.Vector3( 1.39, 0.62, 0.24),
new THREE.Vector3( 1.73, 0.75, 0.27),
new THREE.Vector3( 1.98, 0.16, 0.30),
new THREE.Vector3( 2.00, -0.56, 0.29),
new THREE.Vector3( 1.65, -1.25, 0.20),
new THREE.Vector3( 0.96, -1.72, 0.05),
new THREE.Vector3( 0.15, -1.85, -0.12),
new THREE.Vector3(-0.55, -1.50, -0.24),
new THREE.Vector3(-0.84, -0.88, -0.32),
new THREE.Vector3(-0.69, -0.22, -0.34)
];
const curve = new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.48);
// Outer radii follow the broad gastric body and narrower duodenal tube.
const radiusKeys = [
0.39, 0.39, 0.41, 0.47, 0.58,
0.94, 1.10, 1.17, 1.13, 0.98,
0.79, 0.60, 0.49, 0.45, 0.44,
0.44, 0.45, 0.47, 0.48, 0.47,
0.46, 0.45, 0.44
];
const wallThickness = 0.15;
const depthScale = 0.86;
function radiusAt(t) {
const scaled = THREE.MathUtils.clamp(t, 0, 1) * (radiusKeys.length - 1);
const index = Math.min(Math.floor(scaled), radiusKeys.length - 2);
const mix = scaled - index;
const smooth = mix * mix * (3 - 2 * mix);
return THREE.MathUtils.lerp(radiusKeys[index], radiusKeys[index + 1], smooth);
}
const zAxis = new THREE.Vector3(0, 0, 1);
const xAxis = new THREE.Vector3(1, 0, 0);
function frameAt(t) {
const center = curve.getPoint(t);
const tangent = curve.getTangent(t).normalize();
let side = new THREE.Vector3().crossVectors(tangent, zAxis);
if (side.lengthSq() < 0.00001) {
side = new THREE.Vector3().crossVectors(tangent, xAxis);
}
side.normalize();
const up = new THREE.Vector3().crossVectors(side, tangent).normalize();
return { center, tangent, side, up };
}
function frameAtArc(u) {
const center = curve.getPointAt(u);
const tangent = curve.getTangentAt(u).normalize();
let side = new THREE.Vector3().crossVectors(tangent, zAxis);
if (side.lengthSq() < 0.00001) {
side = new THREE.Vector3().crossVectors(tangent, xAxis);
}
side.normalize();
const up = new THREE.Vector3().crossVectors(side, tangent).normalize();
return { center, tangent, side, up };
}
// The front 100-degree wedge is removed, exposing the continuous lumen.
const cutStart = THREE.MathUtils.degToRad(40);
const cutEnd = THREE.MathUtils.degToRad(140);
const keptStart = cutEnd;
const keptLength = Math.PI * 2 - (cutEnd - cutStart);
function radialPosition(frame, angle, radius, inset = 0) {
const r = Math.max(0.08, radius - inset);
return frame.center.clone()
.addScaledVector(frame.side, Math.cos(angle) * r)
.addScaledVector(frame.up, Math.sin(angle) * r * depthScale);
}
// -------------------------------------------------------------------------
// Outer tissue and inner mucosal surfaces
// -------------------------------------------------------------------------
const tissueMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.66,
metalness: 0.0,
side: THREE.DoubleSide
});
const mucosaMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.48,
metalness: 0.0,
emissive: 0x38110e,
emissiveIntensity: 0.09,
side: THREE.DoubleSide
});
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0xffc0b3,
roughness: 0.62,
metalness: 0,
side: THREE.DoubleSide
});
function createSurface(isInner, rings = 180, columns = 88) {
const positions = [];
const colors = [];
const indices = [];
const base = new THREE.Color(isInner ? 0xe49a83 : 0xc66d73);
const light = new THREE.Color(isInner ? 0xffc5a8 : 0xe79a91);
const dark = new THREE.Color(isInner ? 0xb96d62 : 0x8e4654);
for (let i = 0; i <= rings; i++) {
const t = i / rings;
const frame = frameAt(t);
const outerRadius = radiusAt(t);
const radius = isInner ? outerRadius - wallThickness : outerRadius;
for (let j = 0; j <= columns; j++) {
const v = j / columns;
const angle = keptStart + keptLength * v;
const position = radialPosition(frame, angle, radius);
// Subtle deterministic variation gives the tissue an organic surface.
const variation =
0.08 +
0.08 * Math.sin(i * 0.71 + j * 0.29) +
0.04 * Math.sin(i * 1.91 - j * 0.11);
const color = base.clone();
color.lerp(light, THREE.MathUtils.clamp(variation, 0, 0.24));
color.lerp(dark, 0.06 + 0.06 * Math.sin(i * 0.24 + j * 0.13));
positions.push(position.x, position.y, position.z);
colors.push(color.r, color.g, color.b);
}
}
const stride = columns + 1;
for (let i = 0; i < rings; i++) {
for (let j = 0; j < columns; j++) {
const a = i * stride + j;
const b = (i + 1) * stride + j;
const c = (i + 1) * stride + j + 1;
const d = i * stride + j + 1;
if (isInner) {
indices.push(a, d, b, d, c, b);
} else {
indices.push(a, b, d, b, c, d);
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
const mesh = new THREE.Mesh(geometry, isInner ? mucosaMaterial : tissueMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const tissueMesh = createSurface(false);
const mucosaMesh = createSurface(true);
// -------------------------------------------------------------------------
// Cut faces connecting the tissue and mucosal layers
// -------------------------------------------------------------------------
function createCutStrip(angle) {
const rings = 180;
const positions = [];
const indices = [];
for (let i = 0; i <= rings; i++) {
const t = i / rings;
const frame = frameAt(t);
const radius = radiusAt(t);
positions.push(...radialPosition(frame, angle, radius).toArray());
positions.push(...radialPosition(frame, angle, radius, wallThickness).toArray());
}
for (let i = 0; i < rings; i++) {
const a = i * 2;
const b = (i + 1) * 2;
const c = (i + 1) * 2 + 1;
const d = i * 2 + 1;
indices.push(a, b, d, b, c, d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, cutMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
createCutStrip(cutStart);
createCutStrip(cutEnd);
function createBoundaryContour(angle) {
const positions = [];
for (let i = 0; i <= 180; i++) {
const t = i / 180;
const frame = frameAt(t);
positions.push(...radialPosition(frame, angle, radiusAt(t) + 0.006).toArray());
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0xffd0c4,
transparent: true,
opacity: 0.64
})
);
scene.add(line);
}
createBoundaryContour(cutStart);
createBoundaryContour(cutEnd);
// Open end rings show the wall thickness at the esophageal and duodenal ends.
function createEndRing(t, reverse = false) {
const frame = frameAt(t);
const outer = radiusAt(t);
const inner = outer - wallThickness;
const geometry = new THREE.RingGeometry(inner, outer, 64);
const mesh = new THREE.Mesh(geometry, cutMaterial);
mesh.position.copy(frame.center);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
frame.tangent.clone().multiplyScalar(reverse ? -1 : 1)
);
mesh.castShadow = true;
scene.add(mesh);
}
createEndRing(0, true);
createEndRing(1, false);
// -------------------------------------------------------------------------
// Subtle mucosal folds in the stomach and duodenum
// -------------------------------------------------------------------------
function createFold(t, opacity) {
const frame = frameAt(t);
const radius = radiusAt(t) - wallThickness + 0.008;
const positions = [];
const segments = 70;
for (let j = 0; j <= segments; j++) {
const angle = keptStart + keptLength * (j / segments);
positions.push(...radialPosition(frame, angle, radius).toArray());
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0x8d4b48,
transparent: true,
opacity,
depthWrite: false
})
);
scene.add(line);
}
for (const t of [0.30, 0.37, 0.44, 0.51]) createFold(t, 0.13);
for (let i = 0; i < 11; i++) createFold(0.69 + i * 0.027, 0.22);
// -------------------------------------------------------------------------
// Lumen volume, guide line, tracer, and tracer light
// -------------------------------------------------------------------------
const lumenMaterial = new THREE.MeshBasicMaterial({
color: 0x74e8df,
transparent: true,
opacity: 0.065,
depthWrite: false,
side: THREE.BackSide
});
function createLumenVolume() {
const rings = 160;
const columns = 48;
const positions = [];
const indices = [];
for (let i = 0; i <= rings; i++) {
const t = i / rings;
const frame = frameAt(t);
const radius = radiusAt(t) - wallThickness - 0.01;
for (let j = 0; j <= columns; j++) {
const angle = j / columns * Math.PI * 2;
positions.push(...radialPosition(frame, angle, radius).toArray());
}
}
const stride = columns + 1;
for (let i = 0; i < rings; i++) {
for (let j = 0; j < columns; j++) {
const a = i * stride + j;
const b = (i + 1) * stride + j;
const c = (i + 1) * stride + j + 1;
const d = i * stride + j + 1;
indices.push(a, b, d, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, lumenMaterial);
mesh.renderOrder = 1;
scene.add(mesh);
}
createLumenVolume();
const guide = new THREE.Mesh(
new THREE.TubeGeometry(curve, 260, 0.012, 6, false),
new THREE.MeshBasicMaterial({
color: 0x61f7dc,
transparent: true,
opacity: 0.38,
depthWrite: false
})
);
guide.renderOrder = 2;
scene.add(guide);
const tracerGroup = new THREE.Group();
scene.add(tracerGroup);
const tracerParticles = [];
const particleSizes = [0.125, 0.103, 0.084, 0.068, 0.052];
for (let i = 0; i < particleSizes.length; i++) {
const material = new THREE.MeshStandardMaterial({
color: i === 0 ? 0xa1ffe9 : 0x55f2ce,
emissive: 0x24ffc5,
emissiveIntensity: 2.4 - i * 0.22,
roughness: 0.2,
metalness: 0.05
});
const particle = new THREE.Mesh(
new THREE.SphereGeometry(particleSizes[i], 20, 14),
material
);
particle.castShadow = true;
particle.renderOrder = 4;
tracerGroup.add(particle);
tracerParticles.push(particle);
}
const tracerLight = new THREE.PointLight(0x4affcf, 1.7, 2.5, 2);
tracerLight.renderOrder = 5;
scene.add(tracerLight);
const pulseMaterial = new THREE.MeshBasicMaterial({
color: 0x7affdf,
transparent: true,
opacity: 0.48,
depthWrite: false
});
const tracerPulse = new THREE.Mesh(
new THREE.TorusGeometry(0.16, 0.017, 8, 42),
pulseMaterial
);
tracerPulse.renderOrder = 4;
scene.add(tracerPulse);
// -------------------------------------------------------------------------
// Ground and subtle scientific grid
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x08151d,
roughness: 0.94,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.66;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(24, 48, 0x28535f, 0x173640);
grid.position.y = -2.645;
grid.material.transparent = true;
grid.material.opacity = 0.18;
scene.add(grid);
// -------------------------------------------------------------------------
// Screen-space annotations
// -------------------------------------------------------------------------
const labels = {
esophagus: document.querySelector("#label-esophagus"),
stomach: document.querySelector("#label-stomach"),
duodenum: document.querySelector("#label-duodenum"),
tracer: document.querySelector("#label-tracer"),
cut: document.querySelector("#label-cut")
};
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, offsetX = 0, offsetY = 0) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth + offsetX}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight + offsetY}px`;
}
const annotationAnchors = {
esophagus: new THREE.Vector3(0.02, 4.18, -0.12),
stomach: new THREE.Vector3(-1.18, 1.02, 0.12),
duodenum: new THREE.Vector3(1.82, -0.52, 0.28),
cut: new THREE.Vector3(-0.42, -0.75, 0.35)
};
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const tracerPosition = new THREE.Vector3();
const zDirection = new THREE.Vector3(0, 0, 1);
function animateTracer(elapsed) {
const flow = (elapsed * 0.052) % 1;
for (let i = 0; i < tracerParticles.length; i++) {
const u = (flow - i * 0.022 + 1) % 1;
const frame = frameAtArc(u);
const lateral = Math.sin(elapsed * 3.1 - u * 21) * 0.035;
const vertical = Math.cos(elapsed * 2.7 - u * 17) * 0.022;
tracerPosition.copy(frame.center)
.addScaledVector(frame.side, lateral)
.addScaledVector(frame.up, vertical);
tracerParticles[i].position.copy(tracerPosition);
}
const leadFrame = frameAtArc(flow);
tracerPosition.copy(tracerParticles[0].position);
tracerLight.position.copy(tracerPosition);
tracerPulse.position.copy(tracerPosition);
tracerPulse.quaternion.setFromUnitVectors(zDirection, leadFrame.tangent);
const pulse = 1 + 0.18 * Math.sin(elapsed * 5.0);
tracerPulse.scale.setScalar(pulse);
pulseMaterial.opacity = 0.25 + 0.18 * (0.5 + 0.5 * Math.sin(elapsed * 5.0));
return tracerPosition;
}
function render() {
const elapsed = clock.getElapsedTime();
const currentTracerPosition = animateTracer(elapsed);
placeLabel(labels.esophagus, annotationAnchors.esophagus, 66, -5);
placeLabel(labels.stomach, annotationAnchors.stomach, -58, 3);
placeLabel(labels.duodenum, annotationAnchors.duodenum, 76, -8);
placeLabel(labels.cut, annotationAnchors.cut, 66, 24);
placeLabel(labels.tracer, currentTracerPosition, 72, -26);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(render);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
if (!controls.moved) {
controls.radius = innerWidth < 700 ? 12.4 : 10.7;
updateCamera();
}
});
setTimeout(() => document.querySelector("#loading").classList.add("hidden"), 450);
</script>
</body>
</html>
```