Prompt specification
Build or customize the Three.js 3D scene "Shell impression and cast pair" 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: Shell impression and cast pair
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shell-impression-and-cast-pair-x1145
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts fossil preservation. Model a shell-shaped depression in a rock slab beside its matching raised cast; align their contours so the complementary geometric relationship is unmistakable. Low-poly.
Working Three.js Starter (shell-impression-and-cast-pair-x1145):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fossil Preservation — Mold and Cast</title>
<style>
:root {
color-scheme: dark;
--ink: #eee4cf;
--muted: #aaa38f;
--gold: #d8b96d;
--line: rgba(216, 185, 109, 0.3);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #151713;
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;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 46%, transparent 38%, rgba(5, 7, 5, 0.42) 100%),
linear-gradient(180deg, rgba(0, 0, 0, 0.15), transparent 30%);
z-index: 2;
}
.hud {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.title-card {
position: absolute;
top: clamp(18px, 3vw, 34px);
left: clamp(18px, 3vw, 38px);
max-width: 360px;
padding-left: 18px;
border-left: 1px solid var(--gold);
color: var(--ink);
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.75);
}
.eyebrow {
margin: 0 0 7px;
color: var(--gold);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(24px, 3.2vw, 42px);
font-weight: 400;
line-height: 1.05;
letter-spacing: -0.025em;
}
.subtitle {
margin: 10px 0 0;
max-width: 300px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.controls {
position: absolute;
top: clamp(18px, 3vw, 32px);
right: clamp(18px, 3vw, 34px);
display: flex;
gap: 7px;
pointer-events: auto;
}
button {
min-width: 38px;
height: 38px;
padding: 0 12px;
border: 1px solid rgba(235, 224, 195, 0.2);
border-radius: 3px;
background: rgba(19, 21, 17, 0.74);
color: var(--ink);
font: 600 11px/1 ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.05em;
backdrop-filter: blur(8px);
cursor: pointer;
transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}
button:hover,
button.active {
border-color: rgba(216, 185, 109, 0.72);
background: rgba(75, 62, 35, 0.68);
color: #f4dfae;
}
.legend {
position: absolute;
bottom: clamp(18px, 3vw, 32px);
left: clamp(18px, 3vw, 38px);
display: flex;
flex-wrap: wrap;
gap: 10px 24px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 17px;
height: 5px;
border-radius: 1px;
background: #3a2b22;
box-shadow: inset 0 1px rgba(255, 255, 255, 0.08);
}
.swatch.cast {
height: 8px;
background: #c7a266;
}
.hint {
position: absolute;
right: clamp(18px, 3vw, 34px);
bottom: clamp(18px, 3vw, 32px);
color: rgba(218, 212, 193, 0.55);
font-size: 10px;
letter-spacing: 0.07em;
text-align: right;
line-height: 1.6;
text-transform: uppercase;
}
@media (max-width: 700px) {
.subtitle,
.hint {
display: none;
}
.title-card {
max-width: 225px;
}
.legend {
right: 18px;
gap: 8px 14px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly fossil mold and cast"></canvas>
<div class="vignette"></div>
<div class="hud">
<section class="title-card">
<p class="eyebrow">Specimen 07 · Shell Preservation</p>
<h1>One form.<br />Two impressions.</h1>
<p class="subtitle">
A negative impression in stone and its matching positive cast share the
same radial geometry, reversed across the split.
</p>
</section>
<nav class="controls" aria-label="Scene controls">
<button id="guides" class="active" title="Toggle alignment guides">Guides</button>
<button id="zoomIn" title="Zoom in">+</button>
<button id="zoomOut" title="Zoom out">−</button>
<button id="reset" title="Reset camera">Reset</button>
</nav>
<div class="legend">
<div class="legend-item">
<span class="swatch"></span>
Negative impression / mold
</div>
<div class="legend-item">
<span class="swatch cast"></span>
Positive relief / cast
</div>
</div>
<div class="hint">
Drag to orbit · Scroll to zoom<br />
Shift-drag to pan · Arrow keys to rotate
</div>
</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.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.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(0x151713);
scene.fog = new THREE.Fog(0x151713, 15, 34);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
80
);
// ---------------------------------------------------------------------
// Shared shell geometry
//
// Both fossil surfaces use this exact height function. The left slab
// negates it to make the mold; the right slab adds it to make the cast.
// ---------------------------------------------------------------------
const TOP = 0.30;
const BOTTOM = -0.28;
const AMPLITUDE = 0.285;
const SHELL_WIDTH = 1.18;
const SHELL_LENGTH = 1.72;
const HINGE_Z = 0.85;
const MAX_ANGLE = 1.15;
const RIB_COUNT = 11;
const SLAB_WIDTH = 3.35;
const SLAB_DEPTH = 4.30;
const LEFT_CENTER = -1.77;
const RIGHT_CENTER = 1.77;
const clamp = THREE.MathUtils.clamp;
function smoothstep(min, max, value) {
const t = clamp((value - min) / (max - min), 0, 1);
return t * t * (3 - 2 * t);
}
function hash2(x, z, seed = 0) {
const value = Math.sin(
x * 127.1 + z * 311.7 + seed * 74.73
) * 43758.5453123;
return value - Math.floor(value);
}
function shellRelief(x, z) {
const qx = x / SHELL_WIDTH;
const qz = (HINGE_Z - z) / SHELL_LENGTH;
const radius = Math.hypot(qx, qz);
if (radius > 1 || radius < 0.0001) return 0;
const angle = Math.atan2(qx, qz);
if (Math.abs(angle) > MAX_ANGLE) return 0;
const angularPosition = clamp(
(angle + MAX_ANGLE) / (MAX_ANGLE * 2),
0,
1
);
const rib = Math.pow(
0.5 + 0.5 * Math.cos(angularPosition * Math.PI * 2 * RIB_COUNT),
1.55
);
const edgeFade = smoothstep(0, 0.075, 1 - radius);
const sideFade = smoothstep(0, 0.16, MAX_ANGLE - Math.abs(angle));
const hingeFade = smoothstep(0, 0.055, radius);
const growthBands = 0.075 * Math.cos(radius * 29.0);
const profile = 0.61 + rib * 0.32 + growthBands;
return (
AMPLITUDE *
edgeFade *
sideFade *
hingeFade *
profile
);
}
function shellPoint(angle, radius) {
return new THREE.Vector3(
SHELL_WIDTH * radius * Math.sin(angle),
0,
HINGE_Z - SHELL_LENGTH * radius * Math.cos(angle)
);
}
function surfaceHeight(x, z, sign, seed = 0) {
const microRelief =
(hash2(x * 1.7, z * 1.3, seed) - 0.5) * 0.014;
return TOP + sign * shellRelief(x, z) + microRelief;
}
// ---------------------------------------------------------------------
// Rock slabs
// ---------------------------------------------------------------------
const stoneColor = new THREE.Color("#786956");
const moldColor = new THREE.Color("#33261f");
const castColor = new THREE.Color("#c7a266");
function createSlab(sign, centerX, seed) {
const group = new THREE.Group();
group.position.x = centerX;
const segmentsX = 52;
const segmentsZ = 68;
const stride = segmentsX + 1;
const positions = [];
const colors = [];
const indices = [];
for (let j = 0; j <= segmentsZ; j++) {
const z = -SLAB_DEPTH / 2 + (j / segmentsZ) * SLAB_DEPTH;
for (let i = 0; i <= segmentsX; i++) {
const x = -SLAB_WIDTH / 2 + (i / segmentsX) * SLAB_WIDTH;
const relief = shellRelief(x, z);
const y = surfaceHeight(x, z, sign, seed);
positions.push(x, y, z);
const color = stoneColor.clone();
const variation = 0.87 + hash2(x * 2.2, z * 1.9, seed) * 0.23;
color.multiplyScalar(variation);
const fossilAmount =
sign < 0
? clamp(-relief / AMPLITUDE, 0, 1)
: clamp(relief / AMPLITUDE, 0, 1);
color.lerp(
sign < 0 ? moldColor : castColor,
fossilAmount * 0.72
);
colors.push(color.r, color.g, color.b);
}
}
for (let j = 0; j < segmentsZ; j++) {
for (let i = 0; i < segmentsX; i++) {
const a = j * stride + i;
const b = a + 1;
const c = a + stride;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const topGeometry = new THREE.BufferGeometry();
topGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
topGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
topGeometry.setIndex(indices);
const facetedGeometry = topGeometry.toNonIndexed();
facetedGeometry.computeVertexNormals();
topGeometry.dispose();
const topMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
metalness: 0,
flatShading: true
});
const top = new THREE.Mesh(facetedGeometry, topMaterial);
top.castShadow = true;
top.receiveShadow = true;
group.add(top);
// Side walls, constructed separately so the recessed mold is not
// covered by the top of a conventional box geometry.
const sidePositions = [];
const sideColors = [];
const topSideColor = new THREE.Color("#695d4c");
const lowerSideColor = new THREE.Color("#302c25");
function addTriangle(a, b, c, colorA, colorB, colorC) {
sidePositions.push(...a, ...b, ...c);
sideColors.push(
colorA.r, colorA.g, colorA.b,
colorB.r, colorB.g, colorB.b,
colorC.r, colorC.g, colorC.b
);
}
function addWall(x1, z1, x2, z2) {
const y1 = surfaceHeight(x1, z1, sign, seed);
const y2 = surfaceHeight(x2, z2, sign, seed);
const a = [x1, y1, z1];
const b = [x2, y2, z2];
const c = [x1, BOTTOM, z1];
const d = [x2, BOTTOM, z2];
addTriangle(a, c, b, topSideColor, lowerSideColor, topSideColor);
addTriangle(b, c, d, topSideColor, lowerSideColor, lowerSideColor);
}
const xL = -SLAB_WIDTH / 2;
const xR = SLAB_WIDTH / 2;
const zL = -SLAB_DEPTH / 2;
const zR = SLAB_DEPTH / 2;
addWall(xL, zL, xR, zL);
addWall(xR, zL, xR, zR);
addWall(xR, zR, xL, zR);
addWall(xL, zR, xL, zL);
const sideGeometry = new THREE.BufferGeometry();
sideGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(sidePositions, 3)
);
sideGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(sideColors, 3)
);
sideGeometry.computeVertexNormals();
const sideMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
metalness: 0,
flatShading: true,
side: THREE.DoubleSide
});
const sides = new THREE.Mesh(sideGeometry, sideMaterial);
sides.castShadow = true;
sides.receiveShadow = true;
group.add(sides);
const bottom = new THREE.Mesh(
new THREE.BoxGeometry(SLAB_WIDTH * 0.995, 0.10, SLAB_DEPTH * 0.995),
new THREE.MeshStandardMaterial({
color: 0x292822,
roughness: 1,
flatShading: true
})
);
bottom.position.y = BOTTOM - 0.045;
bottom.castShadow = true;
bottom.receiveShadow = true;
group.add(bottom);
// Fine highlighted contour and shell sutures make the inverse
// geometry easy to read while retaining the low-poly treatment.
const contourMaterial = new THREE.LineBasicMaterial({
color: 0xe0bd70,
transparent: true,
opacity: 0.88
});
const ribMaterial = new THREE.LineBasicMaterial({
color: 0xd5b16a,
transparent: true,
opacity: 0.46
});
const growthMaterial = new THREE.LineBasicMaterial({
color: 0xd9c18c,
transparent: true,
opacity: 0.25
});
const outline = [];
for (let i = 0; i <= 18; i++) {
const radius = i / 18;
const p = shellPoint(-MAX_ANGLE, radius);
outline.push(
new THREE.Vector3(
p.x,
surfaceHeight(p.x, p.z, sign, seed) + 0.012,
p.z
)
);
}
for (let i = 1; i <= 56; i++) {
const angle = -MAX_ANGLE + (i / 56) * MAX_ANGLE * 2;
const p = shellPoint(angle, 1);
outline.push(
new THREE.Vector3(
p.x,
surfaceHeight(p.x, p.z, sign, seed) + 0.012,
p.z
)
);
}
for (let i = 17; i >= 0; i--) {
const radius = i / 18;
const p = shellPoint(MAX_ANGLE, radius);
outline.push(
new THREE.Vector3(
p.x,
surfaceHeight(p.x, p.z, sign, seed) + 0.012,
p.z
)
);
}
outline.push(outline[0].clone());
const contour = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(outline),
contourMaterial
);
group.add(contour);
for (let rib = 1; rib < RIB_COUNT; rib++) {
const q = rib / RIB_COUNT;
const angle = -MAX_ANGLE + q * MAX_ANGLE * 2;
const points = [];
for (let i = 0; i <= 24; i++) {
const radius = 0.055 + (i / 24) * 0.90;
const p = shellPoint(angle, radius);
points.push(
new THREE.Vector3(
p.x,
surfaceHeight(p.x, p.z, sign, seed) + 0.014,
p.z
)
);
}
group.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
ribMaterial
)
);
}
for (const radius of [0.27, 0.47, 0.67, 0.84]) {
const points = [];
for (let i = 0; i <= 40; i++) {
const angle =
-MAX_ANGLE + 0.04 +
(i / 40) * (MAX_ANGLE * 2 - 0.08);
const p = shellPoint(angle, radius);
points.push(
new THREE.Vector3(
p.x,
surfaceHeight(p.x, p.z, sign, seed) + 0.011,
p.z
)
);
}
group.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
growthMaterial
)
);
}
return group;
}
scene.add(createSlab(-1, LEFT_CENTER, 11));
scene.add(createSlab(1, RIGHT_CENTER, 11));
// ---------------------------------------------------------------------
// Registration guides: subtle floating lines connect identical contour
// features on the mold and cast.
// ---------------------------------------------------------------------
const guideGroup = new THREE.Group();
scene.add(guideGroup);
const guideMaterial = new THREE.LineDashedMaterial({
color: 0xe1c47e,
dashSize: 0.13,
gapSize: 0.09,
transparent: true,
opacity: 0.31,
depthWrite: false
});
const guideNodeMaterial = new THREE.MeshBasicMaterial({
color: 0xe4c982,
transparent: true,
opacity: 0.72
});
const guideNodeGeometry = new THREE.OctahedronGeometry(0.035, 0);
function dashedLine(points) {
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
guideMaterial
);
line.computeLineDistances();
guideGroup.add(line);
return line;
}
for (const angle of [-0.82, 0, 0.82]) {
const local = shellPoint(angle, 1);
const guideY = 1.17;
dashedLine([
new THREE.Vector3(LEFT_CENTER + local.x, guideY, local.z),
new THREE.Vector3(RIGHT_CENTER + local.x, guideY, local.z)
]);
for (const center of [LEFT_CENTER, RIGHT_CENTER]) {
const x = center + local.x;
const contourY = TOP + 0.015;
dashedLine([
new THREE.Vector3(x, contourY, local.z),
new THREE.Vector3(x, guideY, local.z)
]);
const node = new THREE.Mesh(
guideNodeGeometry,
guideNodeMaterial
);
node.position.set(x, guideY, local.z);
guideGroup.add(node);
}
}
// ---------------------------------------------------------------------
// Ground, chips, and atmosphere
// ---------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x191c17,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = BOTTOM - 0.10;
ground.receiveShadow = true;
scene.add(ground);
let randomState = 7391;
function random() {
randomState |= 0;
randomState = (randomState + 0x6d2b79f5) | 0;
let t = Math.imul(randomState ^ (randomState >>> 15), 1 | randomState);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
const pebbleGeometry = new THREE.DodecahedronGeometry(1, 0);
const pebbleMaterials = [
new THREE.MeshStandardMaterial({
color: 0x655b4c,
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x4b493e,
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x75664e,
roughness: 1,
flatShading: true
})
];
for (let i = 0; i < 30; i++) {
const pebble = new THREE.Mesh(
pebbleGeometry,
pebbleMaterials[i % pebbleMaterials.length]
);
const side = random() > 0.5 ? 1 : -1;
let x;
let z;
if (i % 3 === 0) {
x = (random() - 0.5) * 10;
z = side * (2.55 + random() * 2.4);
} else {
x = side * (3.65 + random() * 2.1);
z = (random() - 0.5) * 7.2;
}
const scale = 0.06 + random() * 0.18;
pebble.scale.set(
scale * (0.8 + random() * 0.8),
scale * (0.45 + random() * 0.55),
scale * (0.8 + random() * 0.9)
);
pebble.position.set(x, BOTTOM - 0.07 + pebble.scale.y, z);
pebble.rotation.set(random() * 3, random() * 3, random() * 3);
pebble.castShadow = true;
pebble.receiveShadow = true;
scene.add(pebble);
}
const dustCount = 110;
const dustPositions = new Float32Array(dustCount * 3);
const dustSpeeds = new Float32Array(dustCount);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (random() - 0.5) * 14;
dustPositions[i * 3 + 1] = random() * 5.5;
dustPositions[i * 3 + 2] = (random() - 0.5) * 12;
dustSpeeds[i] = 0.025 + random() * 0.04;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xd6c69c,
size: 0.026,
transparent: true,
opacity: 0.36,
sizeAttenuation: true,
depthWrite: false
})
);
scene.add(dust);
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
scene.add(
new THREE.HemisphereLight(0xb8c9c5, 0x3b2a1c, 1.45)
);
const keyLight = new THREE.DirectionalLight(0xffdfb0, 4.2);
keyLight.position.set(-4.5, 9, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0004;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x9fc9d1, 1.45);
fillLight.position.set(7, 4.5, -5);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xe3b96e, 16, 14, 2);
rimLight.position.set(0, 3.8, -4.5);
scene.add(rimLight);
// ---------------------------------------------------------------------
// Direct camera controls — no addons are used.
// ---------------------------------------------------------------------
const target = new THREE.Vector3(0, 0.03, 0);
let theta = 0.46;
let phi = 0.82;
let radius = 12.4;
const defaultView = {
theta,
phi,
radius,
target: target.clone()
};
function updateCamera() {
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.shiftKey || event.button === 2;
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 (panning) {
const right = new THREE.Vector3(
Math.cos(theta),
0,
-Math.sin(theta)
);
const forward = new THREE.Vector3(
-Math.sin(theta),
0,
-Math.cos(theta)
);
const panScale = radius * 0.0011;
target.addScaledVector(right, -dx * panScale);
target.addScaledVector(forward, dy * panScale);
} else {
theta -= dx * 0.0058;
phi = clamp(phi + dy * 0.0048, 0.34, 1.36);
}
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();
radius = clamp(
radius * Math.exp(event.deltaY * 0.001),
6.5,
21
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
theta += 0.09;
break;
case "ArrowRight":
theta -= 0.09;
break;
case "ArrowUp":
phi = clamp(phi - 0.07, 0.34, 1.36);
break;
case "ArrowDown":
phi = clamp(phi + 0.07, 0.34, 1.36);
break;
case "+":
case "=":
radius = clamp(radius - 0.7, 6.5, 21);
break;
case "-":
case "_":
radius = clamp(radius + 0.7, 6.5, 21);
break;
case "r":
case "R":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
function resetView() {
theta = defaultView.theta;
phi = defaultView.phi;
radius = defaultView.radius;
target.copy(defaultView.target);
updateCamera();
}
document.querySelector("#reset").addEventListener("click", resetView);
document.querySelector("#zoomIn").addEventListener("click", () => {
radius = clamp(radius - 0.8, 6.5, 21);
updateCamera();
});
document.querySelector("#zoomOut").addEventListener("click", () => {
radius = clamp(radius + 0.8, 6.5, 21);
updateCamera();
});
const guideButton = document.querySelector("#guides");
guideButton.addEventListener("click", () => {
guideGroup.visible = !guideGroup.visible;
guideButton.classList.toggle("active", guideGroup.visible);
});
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function resize() {
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);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = clock.getDelta();
const positions = dustGeometry.attributes.position.array;
for (let i = 0; i < dustCount; i++) {
positions[i * 3 + 1] += dustSpeeds[i] * delta;
positions[i * 3] += Math.sin(clock.elapsedTime * 0.18 + i) * 0.0008;
if (positions[i * 3 + 1] > 5.8) {
positions[i * 3 + 1] = 0.1;
}
}
dustGeometry.attributes.position.needsUpdate = true;
renderer.render(scene, camera);
});
</script>
</body>
</html>
```