Prompt specification
Build or customize the Three.js 3D scene "Cooking-pan handle teaching scene" 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: Cooking-pan handle teaching scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cooking-pan-handle-teaching-scene-x1475
Scene Description Prompt:
Please make a voxel Three.js scene in one standalone HTML file using cdnjs. Compose a pan, handle, heat source, and enlarged cross section; illustrate conduction pathways qualitatively and avoid claiming material temperatures without solving a defined model.
Working Three.js Starter (cooking-pan-handle-teaching-scene-x1475):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Pan — Qualitative Heat-Transfer Illustration</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(13, 21, 34, 0.88);
--border: rgba(170, 196, 224, 0.18);
--text: #e8f0f8;
--muted: #9eb0c3;
--yellow: #ffd166;
--orange: #ff8a3d;
--cyan: #62d5cf;
--silver: #b7c3d1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #09111d;
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;
}
.title-card,
.legend-card,
.view-controls {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
.title-card {
top: 22px;
left: 22px;
width: min(440px, calc(100vw - 44px));
padding: 18px 20px;
border-radius: 16px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--yellow);
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--text);
font-size: clamp(1.25rem, 2.2vw, 1.75rem);
line-height: 1.12;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 0.86rem;
line-height: 1.45;
}
.legend-card {
right: 22px;
bottom: 22px;
width: min(340px, calc(100vw - 44px));
padding: 16px 17px;
border-radius: 16px;
color: var(--muted);
font-size: 0.8rem;
line-height: 1.45;
}
.legend-title {
margin-bottom: 10px;
color: var(--text);
font-size: 0.76rem;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: flex-start;
gap: 10px;
margin: 7px 0;
}
.swatch {
flex: 0 0 auto;
width: 15px;
height: 15px;
margin-top: 1px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}
.swatch.source {
background: var(--orange);
}
.swatch.direction {
background: var(--yellow);
clip-path: polygon(0 38%, 66% 38%, 66% 0, 100% 50%, 66% 100%, 66% 62%, 0 62%);
}
.swatch.inner {
background: var(--cyan);
}
.swatch.bulk {
background: var(--silver);
}
.swatch.outer {
background: #3d4858;
}
.disclaimer {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--border);
color: #bac7d5;
}
.view-controls {
top: 22px;
right: 22px;
display: flex;
gap: 7px;
padding: 7px;
border-radius: 12px;
}
button {
border: 1px solid transparent;
border-radius: 8px;
padding: 8px 11px;
background: transparent;
color: var(--muted);
font: inherit;
font-size: 0.76rem;
font-weight: 700;
cursor: pointer;
}
button:hover,
button.active {
border-color: rgba(255, 209, 102, 0.3);
background: rgba(255, 209, 102, 0.11);
color: #ffe2a0;
}
.world-label {
position: fixed;
z-index: 5;
transform: translate(-50%, -50%);
padding: 5px 8px;
border: 1px solid rgba(183, 207, 229, 0.2);
border-radius: 7px;
background: rgba(8, 15, 26, 0.82);
color: #dce8f4;
font-size: 0.7rem;
font-weight: 700;
letter-spacing: 0.02em;
white-space: nowrap;
pointer-events: none;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
}
.world-label.accent {
border-color: rgba(255, 209, 102, 0.35);
color: #ffe1a0;
}
.help {
position: fixed;
z-index: 10;
left: 22px;
bottom: 22px;
padding: 8px 11px;
border: 1px solid var(--border);
border-radius: 9px;
background: rgba(13, 21, 34, 0.72);
color: var(--muted);
font-size: 0.72rem;
pointer-events: none;
}
@media (max-width: 760px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.view-controls {
top: auto;
right: 12px;
bottom: 12px;
}
.legend-card {
right: 12px;
bottom: 68px;
width: calc(100vw - 24px);
}
.help {
display: none;
}
.world-label {
font-size: 0.62rem;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel pan and qualitative heat-transfer diagram"></canvas>
<section class="title-card">
<div class="eyebrow">Schematic · Not a thermal solution</div>
<h1>Voxel Pan & Enlarged Cross Section</h1>
<p class="subtitle">
A qualitative illustration of a heat source, a voxel pan, and a magnified
base-and-wall section. Arrowheads indicate plausible heat-transfer
direction only.
</p>
</section>
<nav class="view-controls" aria-label="View controls">
<button id="overviewButton" class="active">Overview</button>
<button id="sectionButton">Cross section</button>
<button id="pathButton" class="active">Pathways</button>
</nav>
<aside class="legend-card">
<div class="legend-title">Diagram key</div>
<div class="legend-row">
<span class="swatch source"></span>
<span>Heat-source symbol; the color is not a temperature scale.</span>
</div>
<div class="legend-row">
<span class="swatch direction"></span>
<span>Expected direction of heat transfer for the illustrated setup.</span>
</div>
<div class="legend-row">
<span class="swatch inner"></span>
<span>Interior-facing layer, shown for geometry and orientation.</span>
</div>
<div class="legend-row">
<span class="swatch bulk"></span>
<span>Bulk section layer.</span>
</div>
<div class="legend-row">
<span class="swatch outer"></span>
<span>Outer section layer.</span>
</div>
<div class="disclaimer">
No material properties, boundary conditions, contact resistances, or
transient heat equation were defined or solved. Therefore, no material
temperatures are claimed or displayed.
</div>
</aside>
<div class="help">Drag to orbit · Shift/right-drag to pan · Wheel to zoom</div>
<div id="labels"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
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.background = new THREE.Color(0x09111d);
scene.fog = new THREE.Fog(0x09111d, 22, 45);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
target: new THREE.Vector3(-0.1, 1.25, -0.45),
radius: 19,
theta: 0.72,
phi: 0.97
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
// ------------------------------------------------------------
// Lighting and ground
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xbdd9ff, 0x182033, 1.55));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.5);
keyLight.position.set(5, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x7ea8ff, 1.25);
rimLight.position.set(-10, 7, -9);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0x0e1725,
roughness: 0.96,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(42, 42, 0x31445a, 0x1b2a3c);
grid.position.y = 0.008;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
// ------------------------------------------------------------
// Voxel construction helpers
// ------------------------------------------------------------
const sourceMaterials = [];
function deterministicNoise(index) {
const value = Math.sin(index * 91.731 + 17.173) * 43758.5453;
return value - Math.floor(value);
}
/**
* Creates a rectangular volume from separated cube-like voxels.
* Colors distinguish geometry/layers only; they are not a thermal scale.
*/
function voxelSlab({
center,
size,
color,
cell = 0.48,
gap = 0.045,
roughness = 0.72,
metalness = 0.18,
emissive = 0x000000,
isSource = false
}) {
const nx = Math.max(1, Math.round(size.x / cell));
const ny = Math.max(1, Math.round(size.y / cell));
const nz = Math.max(1, Math.round(size.z / cell));
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness,
metalness,
emissive,
emissiveIntensity: isSource ? 0.55 : 0
});
if (isSource) sourceMaterials.push(material);
const mesh = new THREE.InstancedMesh(
geometry,
material,
nx * ny * nz
);
mesh.castShadow = true;
mesh.receiveShadow = true;
const matrix = new THREE.Matrix4();
const position = new THREE.Vector3();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3();
const instanceColor = new THREE.Color(color);
const sx = size.x / nx;
const sy = size.y / ny;
const sz = size.z / nz;
const safeGap = Math.min(
gap,
Math.min(sx, sy, sz) * 0.18
);
let index = 0;
for (let ix = 0; ix < nx; ix++) {
for (let iy = 0; iy < ny; iy++) {
for (let iz = 0; iz < nz; iz++) {
position.set(
center.x - size.x / 2 + (ix + 0.5) * sx,
center.y - size.y / 2 + (iy + 0.5) * sy,
center.z - size.z / 2 + (iz + 0.5) * sz
);
scale.set(
sx - safeGap,
sy - safeGap,
sz - safeGap
);
matrix.compose(position, quaternion, scale);
mesh.setMatrixAt(index, matrix);
const variation =
(deterministicNoise(index + center.x * 3.1) - 0.5) * 0.075;
const c = instanceColor.clone().offsetHSL(0, 0, variation);
mesh.setColorAt(index, c);
index++;
}
}
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.computeBoundingSphere();
scene.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Pan
// ------------------------------------------------------------
const pan = new THREE.Group();
scene.add(pan);
// Lower pan body.
voxelSlab({
center: new THREE.Vector3(-3, 0.95, 0),
size: new THREE.Vector3(7.2, 0.7, 5.2),
color: 0x52606f,
cell: 0.43
});
// Interior cooking surface.
voxelSlab({
center: new THREE.Vector3(-3, 1.37, 0),
size: new THREE.Vector3(6.3, 0.14, 4.3),
color: 0x4ca8a4,
cell: 0.42,
roughness: 0.62,
metalness: 0.22
});
// Four pan walls.
voxelSlab({
center: new THREE.Vector3(-3, 1.95, 2.34),
size: new THREE.Vector3(7.2, 1.3, 0.46),
color: 0x52606f,
cell: 0.42
});
voxelSlab({
center: new THREE.Vector3(-3, 1.95, -2.34),
size: new THREE.Vector3(7.2, 1.3, 0.46),
color: 0x52606f,
cell: 0.42
});
voxelSlab({
center: new THREE.Vector3(-6.34, 1.95, 0),
size: new THREE.Vector3(0.46, 1.3, 4.24),
color: 0x52606f,
cell: 0.42
});
voxelSlab({
center: new THREE.Vector3(0.34, 1.95, 0),
size: new THREE.Vector3(0.46, 1.3, 4.24),
color: 0x52606f,
cell: 0.42
});
// Brighter rim pieces.
voxelSlab({
center: new THREE.Vector3(-3, 2.64, 2.34),
size: new THREE.Vector3(7.35, 0.14, 0.52),
color: 0x8492a1,
cell: 0.38
});
voxelSlab({
center: new THREE.Vector3(-3, 2.64, -2.34),
size: new THREE.Vector3(7.35, 0.14, 0.52),
color: 0x8492a1,
cell: 0.38
});
voxelSlab({
center: new THREE.Vector3(-6.34, 2.64, 0),
size: new THREE.Vector3(0.52, 0.14, 4.25),
color: 0x8492a1,
cell: 0.38
});
voxelSlab({
center: new THREE.Vector3(0.34, 2.64, 0),
size: new THREE.Vector3(0.52, 0.14, 4.25),
color: 0x8492a1,
cell: 0.38
});
// ------------------------------------------------------------
// Handle
// ------------------------------------------------------------
voxelSlab({
center: new THREE.Vector3(-3, 2.34, -2.68),
size: new THREE.Vector3(1.45, 0.5, 0.72),
color: 0x333d4a,
cell: 0.34,
roughness: 0.86,
metalness: 0.08
});
voxelSlab({
center: new THREE.Vector3(-3, 2.34, -3.55),
size: new THREE.Vector3(1.05, 0.42, 1.4),
color: 0x252d38,
cell: 0.34,
roughness: 0.88,
metalness: 0.05
});
voxelSlab({
center: new THREE.Vector3(-3, 2.34, -4.75),
size: new THREE.Vector3(1.45, 0.58, 1.55),
color: 0x171e28,
cell: 0.36,
roughness: 0.95,
metalness: 0.02
});
voxelSlab({
center: new THREE.Vector3(-3, 2.34, -5.58),
size: new THREE.Vector3(1.6, 0.68, 0.18),
color: 0x0e141d,
cell: 0.34,
roughness: 0.95,
metalness: 0.02
});
// ------------------------------------------------------------
// Heat source beneath the pan
// ------------------------------------------------------------
voxelSlab({
center: new THREE.Vector3(-3, 0.2, 0),
size: new THREE.Vector3(5.5, 0.3, 3.9),
color: 0x202a37,
cell: 0.43,
roughness: 0.9,
metalness: 0.12
});
const sourcePositions = [
[-4.4, -1.1],
[-4.4, 1.1],
[-3, -1.1],
[-3, 1.1],
[-1.6, -1.1],
[-1.6, 1.1]
];
for (const [x, z] of sourcePositions) {
voxelSlab({
center: new THREE.Vector3(x, 0.48, z),
size: new THREE.Vector3(0.56, 0.22, 0.56),
color: 0xff8438,
cell: 0.55,
roughness: 0.48,
metalness: 0.08,
emissive: 0xff4a14,
isSource: true
});
}
// ------------------------------------------------------------
// Enlarged base-and-wall cross section
// ------------------------------------------------------------
const section = new THREE.Group();
scene.add(section);
// Low display plinth.
voxelSlab({
center: new THREE.Vector3(6.4, 0.11, 0),
size: new THREE.Vector3(5.35, 0.18, 1.65),
color: 0x202b3a,
cell: 0.42,
roughness: 0.92,
metalness: 0.08
});
// Enlarged horizontal base layers.
voxelSlab({
center: new THREE.Vector3(6.35, 0.42, 0),
size: new THREE.Vector3(4.8, 0.32, 1.05),
color: 0x394655,
cell: 0.36
});
voxelSlab({
center: new THREE.Vector3(6.35, 0.86, 0),
size: new THREE.Vector3(4.8, 0.55, 1.05),
color: 0xaebbc9,
cell: 0.36,
roughness: 0.62,
metalness: 0.28
});
voxelSlab({
center: new THREE.Vector3(6.35, 1.21, 0),
size: new THREE.Vector3(4.8, 0.14, 1.05),
color: 0x55c3bd,
cell: 0.36,
roughness: 0.58,
metalness: 0.2
});
// Enlarged vertical wall layers.
voxelSlab({
center: new THREE.Vector3(8.03, 2.63, 0),
size: new THREE.Vector3(0.34, 2.92, 1.05),
color: 0x55c3bd,
cell: 0.35,
roughness: 0.58,
metalness: 0.2
});
voxelSlab({
center: new THREE.Vector3(8.43, 2.63, 0),
size: new THREE.Vector3(0.45, 2.92, 1.05),
color: 0xaebbc9,
cell: 0.35,
roughness: 0.62,
metalness: 0.28
});
voxelSlab({
center: new THREE.Vector3(8.8, 2.63, 0),
size: new THREE.Vector3(0.3, 2.92, 1.05),
color: 0x394655,
cell: 0.35
});
// A symbolic source under the enlarged base.
voxelSlab({
center: new THREE.Vector3(5.65, 0.18, 0),
size: new THREE.Vector3(0.7, 0.14, 0.75),
color: 0xff8438,
cell: 0.7,
roughness: 0.48,
emissive: 0xff4a14,
isSource: true
});
// Dashed visual callout connecting the pan to the enlarged section.
const calloutGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0.65, 2.2, 2.35),
new THREE.Vector3(3.15, 2.2, 2.35),
new THREE.Vector3(4.45, 2.2, 2.35),
new THREE.Vector3(4.45, 2.2, 0.55),
new THREE.Vector3(5.0, 2.2, 0.55)
]);
const callout = new THREE.Line(
calloutGeometry,
new THREE.LineDashedMaterial({
color: 0x7890aa,
dashSize: 0.17,
gapSize: 0.12,
transparent: true,
opacity: 0.62
})
);
callout.computeLineDistances();
scene.add(callout);
// ------------------------------------------------------------
// Qualitative pathway arrows
// ------------------------------------------------------------
const pathwayGroup = new THREE.Group();
scene.add(pathwayGroup);
function addArrow(start, end, color = 0xffd166, opacity = 0.96) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const arrow = new THREE.ArrowHelper(
direction.normalize(),
start,
length,
color,
Math.min(0.48, length * 0.24),
Math.min(0.3, length * 0.16)
);
// Keep the arrows readable through the voxel geometry.
arrow.line.material.depthTest = false;
arrow.cone.material.depthTest = false;
arrow.line.material.transparent = true;
arrow.cone.material.transparent = true;
arrow.line.material.opacity = opacity;
arrow.cone.material.opacity = opacity;
arrow.line.renderOrder = 20;
arrow.cone.renderOrder = 20;
pathwayGroup.add(arrow);
return arrow;
}
// In the pan: source -> base -> interior surface -> wall.
addArrow(
new THREE.Vector3(-3, 0.58, 0.4),
new THREE.Vector3(-3, 1.62, 0.4)
);
addArrow(
new THREE.Vector3(-3, 1.62, 0.55),
new THREE.Vector3(-3, 1.62, 2.15)
);
addArrow(
new THREE.Vector3(-3, 1.57, 2.22),
new THREE.Vector3(-3, 2.82, 2.22)
);
addArrow(
new THREE.Vector3(-4.35, 1.57, 0.25),
new THREE.Vector3(-1.65, 1.57, 0.25),
0xffd166,
0.72
);
// In the enlarged section: source -> base -> wall.
addArrow(
new THREE.Vector3(5.65, 0.26, 0.3),
new THREE.Vector3(5.65, 1.46, 0.3)
);
addArrow(
new THREE.Vector3(5.8, 0.98, 0.36),
new THREE.Vector3(7.62, 0.98, 0.36)
);
addArrow(
new THREE.Vector3(8.02, 1.43, 0.34),
new THREE.Vector3(8.02, 3.95, 0.34)
);
// ------------------------------------------------------------
// HTML labels projected from world positions
// ------------------------------------------------------------
const labelRoot = document.querySelector("#labels");
const worldLabels = [];
function addWorldLabel(text, position, accent = false) {
const element = document.createElement("div");
element.className = `world-label${accent ? " accent" : ""}`;
element.textContent = text;
labelRoot.appendChild(element);
worldLabels.push({ element, position });
}
addWorldLabel(
"Voxel pan",
new THREE.Vector3(-4.1, 3.05, 0.2)
);
addWorldLabel(
"Handle",
new THREE.Vector3(-3, 2.85, -4.75)
);
addWorldLabel(
"Heat source — symbolic",
new THREE.Vector3(-5.1, 0.55, 1.7),
true
);
addWorldLabel(
"Direction-only pathway",
new THREE.Vector3(-3.3, 1.95, 2.3),
true
);
addWorldLabel(
"Enlarged base-and-wall section · not to scale",
new THREE.Vector3(6.6, 4.45, 0)
);
addWorldLabel(
"Direction-only pathway",
new THREE.Vector3(6.35, 2.65, 0.55),
true
);
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of worldLabels) {
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.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
// ------------------------------------------------------------
// Direct camera controls: orbit, pan, and zoom
// ------------------------------------------------------------
const pointer = new THREE.Vector2();
let dragging = false;
let panMode = false;
let lastX = 0;
let lastY = 0;
const forward = new THREE.Vector3();
const right = new THREE.Vector3();
const cameraUp = new THREE.Vector3();
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panMode = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panMode) {
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
right.crossVectors(forward, camera.up).normalize();
cameraUp.crossVectors(right, forward).normalize();
const scale = orbit.radius * 0.00135;
orbit.target.addScaledVector(right, -dx * scale);
orbit.target.addScaledVector(cameraUp, dy * scale);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.28,
1.38
);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
7,
34
);
updateCamera();
},
{ passive: false }
);
// ------------------------------------------------------------
// Interface controls
// ------------------------------------------------------------
const overviewButton = document.querySelector("#overviewButton");
const sectionButton = document.querySelector("#sectionButton");
const pathButton = document.querySelector("#pathButton");
function setOverview() {
orbit.target.set(-0.1, 1.25, -0.45);
orbit.radius = window.innerWidth < 760 ? 23 : 19;
orbit.theta = 0.72;
orbit.phi = 0.97;
updateCamera();
overviewButton.classList.add("active");
sectionButton.classList.remove("active");
}
function focusSection() {
orbit.target.set(6.45, 1.85, 0);
orbit.radius = 10.2;
orbit.theta = 0.62;
orbit.phi = 0.98;
updateCamera();
sectionButton.classList.add("active");
overviewButton.classList.remove("active");
}
overviewButton.addEventListener("click", setOverview);
sectionButton.addEventListener("click", focusSection);
pathButton.addEventListener("click", () => {
pathwayGroup.visible = !pathwayGroup.visible;
pathButton.classList.toggle("active", pathwayGroup.visible);
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
// Subtle pulsing identifies the source as symbolic, not as a scale.
for (const material of sourceMaterials) {
material.emissiveIntensity = 0.5 + Math.sin(elapsed * 2.2) * 0.12;
}
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```