Prompt specification
Build or customize the Three.js 3D scene "Intestinal and root exchange comparison exhibit" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Intestinal and root exchange comparison exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/intestinal-and-root-exchange-comparison-exhibit-x0871
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a scene with schematic folded tissue and root-hair sections beside smooth alternatives; connect added surface geometry to exchange opportunities without claiming that surface area alone determines absorption. Voxel style.
Working Three.js Starter (intestinal-and-root-exchange-comparison-exhibit-x0871):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Surface Geometry and Exchange Opportunities</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 24, 41, 0.86);
--line: rgba(149, 190, 218, 0.2);
--text: #eaf4fb;
--muted: #a9bdcc;
--green: #a9df72;
--cyan: #58e7df;
--gold: #f1bd72;
--blue: #409fc4;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.top-title {
position: fixed;
z-index: 5;
top: 22px;
left: 24px;
max-width: min(650px, calc(100vw - 48px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
padding: 6px 9px;
border: 1px solid rgba(88, 231, 223, 0.35);
border-radius: 4px;
background: rgba(8, 25, 40, 0.72);
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 6px;
height: 6px;
background: var(--cyan);
box-shadow: 0 0 12px rgba(88, 231, 223, 0.8);
}
h1 {
margin: 0;
max-width: 620px;
font-size: clamp(24px, 3.3vw, 47px);
line-height: 0.98;
letter-spacing: -0.045em;
text-wrap: balance;
text-shadow: 0 3px 24px rgba(0, 0, 0, 0.5);
}
.subtitle {
margin: 10px 0 0;
max-width: 590px;
color: var(--muted);
font-size: clamp(12px, 1.25vw, 15px);
line-height: 1.45;
}
.legend {
position: fixed;
z-index: 5;
top: 22px;
right: 22px;
width: 225px;
padding: 13px 14px;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--panel);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(10px);
pointer-events: none;
}
.legend-title {
margin-bottom: 9px;
color: #d9e8f1;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 7px;
color: var(--muted);
font-size: 11px;
line-height: 1.25;
}
.swatch {
flex: 0 0 auto;
width: 12px;
height: 12px;
border-radius: 2px;
}
.swatch.geometry {
background: var(--green);
box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}
.swatch.opportunity {
border: 1px solid var(--cyan);
background: rgba(88, 231, 223, 0.18);
box-shadow: 0 0 8px rgba(88, 231, 223, 0.35);
}
.swatch.reference {
background: var(--gold);
box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}
.interpretation {
position: fixed;
z-index: 5;
left: 22px;
bottom: 22px;
width: min(680px, calc(100vw - 44px));
padding: 15px 17px;
border: 1px solid rgba(88, 231, 223, 0.22);
border-left: 3px solid var(--cyan);
border-radius: 7px;
background: var(--panel);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
pointer-events: none;
}
.interpretation strong {
display: block;
margin-bottom: 5px;
color: var(--cyan);
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.interpretation p {
margin: 0;
color: #c9d9e4;
font-size: 12px;
line-height: 1.5;
}
.interpretation em {
color: #f1f7fa;
font-style: normal;
font-weight: 700;
}
.controls {
position: fixed;
z-index: 6;
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 9px;
}
.controls button {
border: 1px solid rgba(169, 223, 114, 0.35);
border-radius: 5px;
padding: 9px 12px;
background: rgba(13, 31, 47, 0.9);
color: var(--green);
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.06em;
cursor: pointer;
}
.controls button:hover {
background: rgba(28, 58, 75, 0.95);
}
.controls span {
color: rgba(190, 211, 225, 0.62);
font-size: 10px;
letter-spacing: 0.05em;
}
.scene-label {
position: fixed;
z-index: 4;
min-width: 120px;
max-width: 210px;
padding: 7px 9px;
border: 1px solid rgba(169, 223, 114, 0.36);
border-radius: 5px;
background: rgba(7, 19, 31, 0.84);
box-shadow: 0 7px 22px rgba(0, 0, 0, 0.28);
transform: translate(-50%, -100%);
pointer-events: none;
opacity: 0;
transition: opacity 120ms linear;
backdrop-filter: blur(6px);
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 15px;
background: rgba(169, 223, 114, 0.55);
}
.scene-label b {
display: block;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.09em;
line-height: 1.25;
text-transform: uppercase;
}
.scene-label span {
display: block;
margin-top: 3px;
color: #aebfca;
font-size: 9px;
line-height: 1.25;
}
.scene-label.reference {
border-color: rgba(241, 189, 114, 0.34);
}
.scene-label.reference b {
color: var(--gold);
}
.scene-label.reference::after {
background: rgba(241, 189, 114, 0.5);
}
.scene-label.opportunity {
border-color: rgba(88, 231, 223, 0.5);
background: rgba(6, 29, 39, 0.9);
}
.scene-label.opportunity b {
color: var(--cyan);
}
.scene-label.opportunity::after {
background: rgba(88, 231, 223, 0.7);
}
@media (max-width: 800px) {
.legend {
display: none;
}
.top-title {
top: 15px;
left: 15px;
}
.subtitle {
max-width: 480px;
}
.interpretation {
left: 12px;
bottom: 58px;
width: calc(100vw - 24px);
padding: 12px 13px;
}
.interpretation p {
font-size: 11px;
}
.controls {
right: 12px;
bottom: 12px;
}
.controls span {
display: none;
}
.scene-label {
min-width: 92px;
padding: 5px 7px;
}
.scene-label span {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel comparison of folded tissue and root hairs"></canvas>
<header class="top-title">
<div class="eyebrow">Voxel study · schematic, not to scale</div>
<h1>Surface geometry creates exchange opportunities.</h1>
<p class="subtitle">
Folded tissue and root-hair sections are shown beside smooth references.
Added geometry can provide more interfaces where contact may be possible.
</p>
</header>
<aside class="legend" aria-label="Scene legend">
<div class="legend-title">Visual key</div>
<div class="legend-row">
<span class="swatch geometry"></span>
<span>Added surface geometry</span>
</div>
<div class="legend-row">
<span class="swatch opportunity"></span>
<span>Potential exchange interface</span>
</div>
<div class="legend-row">
<span class="swatch reference"></span>
<span>Structure / reference</span>
</div>
</aside>
<section class="interpretation" aria-label="Scientific interpretation">
<strong>Opportunity is not the same as uptake</strong>
<p>
Added folds and root hairs can create additional interfaces where exchange
<em>may be possible</em>. Surface area alone does not determine absorption;
membrane permeability, internal transport, moisture, and tissue physiology
also matter.
</p>
</section>
<div class="controls">
<span>drag to orbit · wheel to zoom</span>
<button id="resetView" type="button">RESET VIEW</button>
</div>
<div id="foldedLabel" class="scene-label">
<b>Folded tissue</b>
<span>ridges and grooves add exposed interfaces</span>
</div>
<div id="smoothTissueLabel" class="scene-label reference">
<b>Smooth tissue</b>
<span>flat reference surface</span>
</div>
<div id="rootHairLabel" class="scene-label">
<b>Root-hair section</b>
<span>projecting hairs add geometry</span>
</div>
<div id="smoothRootLabel" class="scene-label reference">
<b>Smooth root</b>
<span>hair-free reference</span>
</div>
<div id="foldOpportunityLabel" class="scene-label opportunity">
<b>Potential exchange interface</b>
<span>an opportunity, not a guaranteed uptake rate</span>
</div>
<div id="rootOpportunityLabel" class="scene-label opportunity">
<b>Potential exchange interface</b>
<span>additional contact may be possible here</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
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.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 20, 38);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xbfe4ff, 0x17202b, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d5, 3.3);
keyLight.position.set(-5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x62d9ee, 1.5);
rimLight.position.set(7, 5, -7);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffb86b, 18, 13, 2);
warmFill.position.set(-1, 4, 5);
scene.add(warmFill);
// ------------------------------------------------------------
// Voxel batching: all static blocks use instanced cube geometry.
// ------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
const materialCache = new Map();
const voxelBatches = new Map();
function getVoxelMaterial(color, emissive = 0x000000, emissiveIntensity = 0) {
const key = `${color}_${emissive}_${emissiveIntensity}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
flatShading: true,
emissive,
emissiveIntensity
})
);
}
return materialCache.get(key);
}
function addVoxel(
x,
y,
z,
sx,
sy,
sz,
color,
emissive = 0x000000,
emissiveIntensity = 0
) {
const material = getVoxelMaterial(color, emissive, emissiveIntensity);
const key = material.uuid;
if (!voxelBatches.has(key)) {
voxelBatches.set(key, {
material,
matrices: []
});
}
dummy.position.set(x, y, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(sx, sy, sz);
dummy.updateMatrix();
voxelBatches.get(key).matrices.push(dummy.matrix.clone());
}
function flushVoxels() {
for (const { material, matrices } of voxelBatches.values()) {
const mesh = new THREE.InstancedMesh(
cubeGeometry,
material,
matrices.length
);
matrices.forEach((matrix, index) => {
mesh.setMatrixAt(index, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
}
// Ground and exhibition plinths.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0x0a1828,
roughness: 0.95,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.36;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(40, 40, 0x294258, 0x152b3d);
grid.position.y = -0.345;
grid.material.transparent = true;
grid.material.opacity = 0.36;
scene.add(grid);
function addPlinth(x, width, depth) {
addVoxel(x, -0.08, 0, width, 0.34, depth, 0x142a40);
addVoxel(x, 0.105, 0, width - 0.12, 0.055, depth - 0.12, 0x213d55);
// Small reference tabs along the front edge.
const tabCount = Math.max(3, Math.floor(width / 0.65));
const tabWidth = 0.13;
for (let i = 0; i < tabCount; i++) {
const tx = x - width * 0.42 + (i / (tabCount - 1)) * width * 0.84;
addVoxel(tx, 0.05, depth * 0.5 + 0.012, tabWidth, 0.07, 0.03, 0x67839a);
}
}
addPlinth(-5.6, 4.02, 2.75);
addPlinth(-1.6, 4.02, 2.75);
addPlinth(2.2, 3.55, 2.85);
addPlinth(6.0, 3.55, 2.85);
// ------------------------------------------------------------
// Folded and smooth tissue sections.
// ------------------------------------------------------------
function createTissueSection(centerX, folded) {
const unit = 0.34;
const nx = 11;
const nz = 7;
const bottom = 0.13;
const x0 = centerX - ((nx - 1) * unit) / 2;
const z0 = -((nz - 1) * unit) / 2;
const surfaceMap = new Map();
for (let ix = 0; ix < nx; ix++) {
for (let iz = 0; iz < nz; iz++) {
let stack;
if (folded) {
const ridgeA = Math.exp(-Math.pow((ix - 2.4) / 1.45, 2));
const ridgeB = Math.exp(-Math.pow((ix - 8.3) / 1.6, 2));
const groove = Math.exp(-Math.pow((ix - 5.45) / 0.95, 2));
const crossWave = 0.3 * Math.sin(iz * 1.25 + ix * 0.22);
stack = THREE.MathUtils.clamp(
Math.round(3 + ridgeA * 2.7 + ridgeB * 2.5 - groove * 1.6 + crossWave),
2,
6
);
} else {
stack = 2;
}
for (let iy = 0; iy < stack; iy++) {
const x = x0 + ix * unit;
const y = bottom + (iy + 0.5) * unit;
const z = z0 + iz * unit;
let color;
if (iy === stack - 1) {
if (!folded) {
color = 0x59ae71;
} else {
color = stack >= 5 ? 0xa9dc72 : 0x65b86a;
}
} else if (iy === stack - 2) {
color = folded ? 0xdb867c : 0xc46d70;
} else if (iy % 2 === 0) {
color = 0x7b4055;
} else {
color = 0xa95762;
}
// Blue blocks suggest an internal transport route rather than
// implying that surface area determines uptake.
const transportCue =
iz === nz - 1 &&
iy === 1 &&
ix % 4 === 0;
if (transportCue) {
addVoxel(
x,
y,
z,
unit,
unit,
unit,
0x368caf,
0x153e51,
0.55
);
} else {
addVoxel(x, y, z, unit, unit, unit, color);
}
}
surfaceMap.set(
`${ix},${iz}`,
new THREE.Vector3(
x0 + ix * unit,
bottom + stack * unit,
z0 + iz * unit
)
);
}
}
return surfaceMap;
}
const foldedSurface = createTissueSection(-5.6, true);
createTissueSection(-1.6, false);
// ------------------------------------------------------------
// Root sections built from voxel cross-sections.
// ------------------------------------------------------------
function createRootSection(centerX, withHairs) {
const unit = 0.34;
const nx = 9;
const centerY = 0.95;
const x0 = centerX - ((nx - 1) * unit) / 2;
const hairTips = [];
for (let ix = 0; ix < nx; ix++) {
const x = x0 + ix * unit;
for (let iy = -2; iy <= 2; iy++) {
for (let iz = -2; iz <= 2; iz++) {
// Voxelized circular cross-section.
if (iy * iy + iz * iz > 5) continue;
const y = centerY + iy * unit;
const z = iz * unit;
const distance = Math.abs(iy) + Math.abs(iz);
let color;
if (iy === 0 && iz === 0) {
color = 0x287fa2;
} else if (distance <= 2) {
color = 0xd7804d;
} else {
color = 0xaa6040;
}
addVoxel(x, y, z, unit, unit, unit, color);
}
}
}
function addStairHair(start, direction, bend, count = 5) {
const dir = direction.clone().normalize();
let tip = start.clone();
for (let k = 0; k < count; k++) {
const p = start
.clone()
.addScaledVector(dir, (k + 1) * 0.18)
.addScaledVector(bend, k * k * 0.022);
const size = 0.16 - k * 0.007;
addVoxel(
p.x,
p.y,
p.z,
size,
size,
size,
k % 2 === 0 ? 0xf3c783 : 0xe7aa69
);
tip = p;
}
hairTips.push(tip.clone());
}
if (withHairs) {
const topSurfaceY = centerY + 2 * unit + unit / 2;
// Projecting hairs from the upper surface.
addStairHair(
new THREE.Vector3(x0 + unit, topSurfaceY, -0.34),
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0.08, 0, 0.05),
5
);
addStairHair(
new THREE.Vector3(x0 + 3 * unit, topSurfaceY, 0),
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(-0.06, 0, 0.07),
5
);
addStairHair(
new THREE.Vector3(x0 + 6 * unit, topSurfaceY, 0.34),
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0.04, 0, -0.05),
5
);
// Projecting hairs from the camera-facing surface.
addStairHair(
new THREE.Vector3(x0 + 2 * unit, centerY + 0.2, 0.85),
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(0.05, 0.05, 0),
5
);
addStairHair(
new THREE.Vector3(x0 + 6 * unit, centerY - 0.15, 0.85),
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(-0.04, 0.06, 0),
4
);
}
return { hairTips, x0 };
}
const rootWithHairs = createRootSection(2.2, true);
createRootSection(6.0, false);
// Small yellow focus blocks on representative added geometry.
const foldAnchor = foldedSurface.get("8,2").clone();
foldAnchor.y += 0.02;
addVoxel(foldAnchor.x, foldAnchor.y, foldAnchor.z, 0.23, 0.16, 0.23, 0xd7eb85);
if (rootWithHairs.hairTips.length) {
const rootTip = rootWithHairs.hairTips[1];
addVoxel(rootTip.x, rootTip.y, rootTip.z, 0.19, 0.19, 0.19, 0xffe0a1);
}
flushVoxels();
// ------------------------------------------------------------
// Opportunity indicators connect added geometry to cyan markers.
// ------------------------------------------------------------
const opportunityVisuals = [];
const connectorDotGeometry = new THREE.BoxGeometry(0.055, 0.055, 0.055);
const connectorDotMaterial = new THREE.MeshBasicMaterial({
color: 0x58e7df,
transparent: true,
opacity: 0.9,
depthWrite: false
});
function addOpportunity(anchor, offset) {
const end = anchor.clone().add(offset);
const lineGeometry = new THREE.BufferGeometry().setFromPoints([
anchor,
end
]);
const lineMaterial = new THREE.LineDashedMaterial({
color: 0x58e7df,
dashSize: 0.11,
gapSize: 0.08,
transparent: true,
opacity: 0.78,
depthTest: false,
depthWrite: false
});
const line = new THREE.Line(lineGeometry, lineMaterial);
line.computeLineDistances();
line.renderOrder = 4;
scene.add(line);
for (let i = 1; i <= 5; i++) {
const p = anchor.clone().lerp(end, i / 6);
const dot = new THREE.Mesh(
connectorDotGeometry,
connectorDotMaterial
);
dot.position.copy(p);
dot.renderOrder = 4;
scene.add(dot);
}
const marker = new THREE.Group();
marker.position.copy(end);
const core = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.13, 0.13),
new THREE.MeshBasicMaterial({
color: 0x7ffff4,
depthTest: false
})
);
const frame = new THREE.Mesh(
new THREE.BoxGeometry(0.31, 0.31, 0.31),
new THREE.MeshBasicMaterial({
color: 0x58e7df,
wireframe: true,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
core.renderOrder = 5;
frame.renderOrder = 5;
marker.add(core, frame);
scene.add(marker);
opportunityVisuals.push({
marker,
phase: opportunityVisuals.length * 1.7
});
return end;
}
const foldOpportunityEnd = addOpportunity(
foldAnchor,
new THREE.Vector3(0.48, 0.72, 0.32)
);
const rootOpportunityEnd = addOpportunity(
rootWithHairs.hairTips[1],
new THREE.Vector3(0.42, 0.66, 0.2)
);
// ------------------------------------------------------------
// World-anchored HTML labels.
// ------------------------------------------------------------
const labels = [];
function registerLabel(id, position) {
labels.push({
element: document.getElementById(id),
position: position.clone()
});
}
registerLabel(
"foldedLabel",
new THREE.Vector3(-5.85, 2.72, 0)
);
registerLabel(
"smoothTissueLabel",
new THREE.Vector3(-1.6, 1.42, 0)
);
registerLabel(
"rootHairLabel",
new THREE.Vector3(2.45, 2.86, 0)
);
registerLabel(
"smoothRootLabel",
new THREE.Vector3(6.0, 1.92, 0)
);
registerLabel(
"foldOpportunityLabel",
foldOpportunityEnd.clone().add(new THREE.Vector3(0.66, 0.15, 0))
);
registerLabel(
"rootOpportunityLabel",
rootOpportunityEnd.clone().add(new THREE.Vector3(-0.62, 0.18, 0))
);
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
label.element.style.opacity = visible ? "1" : "0";
label.element.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
label.element.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
// ------------------------------------------------------------
// Direct camera controls: no addons or example modules.
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.72, 0),
radius: 15.5,
phi: 1.04,
theta: 0.12
};
let dragging = false;
let previousX = 0;
let previousY = 0;
let userMoved = false;
function updateCamera() {
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position
.setFromSpherical(spherical)
.add(cameraState.target);
camera.lookAt(cameraState.target);
}
function resetCamera() {
const aspect = window.innerWidth / window.innerHeight;
cameraState.radius = Math.max(15.5, 20.8 / aspect);
cameraState.phi = 1.04;
cameraState.theta = 0.12;
cameraState.target.set(0, 0.72, 0);
userMoved = false;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
1.38
);
userMoved = true;
updateCamera();
});
function endDrag(event) {
dragging = false;
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();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9.5,
29
);
userMoved = true;
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.theta += 0.08;
break;
case "ArrowRight":
cameraState.theta -= 0.08;
break;
case "ArrowUp":
cameraState.phi = Math.max(0.48, cameraState.phi - 0.06);
break;
case "ArrowDown":
cameraState.phi = Math.min(1.38, cameraState.phi + 0.06);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
userMoved = true;
updateCamera();
}
});
document.getElementById("resetView").addEventListener("click", resetCamera);
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
if (!userMoved) resetCamera();
else updateCamera();
}
window.addEventListener("resize", onResize);
resetCamera();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const time = clock.getElapsedTime();
if (!reducedMotion) {
opportunityVisuals.forEach(({ marker, phase }, index) => {
const pulse = 1 + Math.sin(time * 2.1 + phase) * 0.1;
marker.scale.setScalar(pulse);
marker.rotation.y = time * 0.38 + phase;
marker.rotation.x = Math.sin(time * 0.75 + phase) * 0.12;
marker.position.y +=
(Math.sin(time * 1.4 + phase) * 0.025 -
(marker.userData.lastBob || 0));
marker.userData.lastBob =
Math.sin(time * 1.4 + phase) * 0.025;
});
}
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```