Prompt specification
Build or customize the Three.js 3D scene "Basalt column cluster specimen" 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: Basalt column cluster specimen
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/basalt-column-cluster-specimen-x1125
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: basalt column cluster specimen. Model a tightly fitted cluster of irregular polygonal stone columns with varied heights; show shared boundaries and a cut base rather than identical detached hexagonal prisms.
Working Three.js Starter (basalt-column-cluster-specimen-x1125):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Basalt Column Cluster</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d3c8;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-block {
position: absolute;
top: clamp(24px, 5vw, 58px);
left: clamp(24px, 5vw, 66px);
max-width: 390px;
}
.eyebrow {
margin-bottom: 12px;
color: #62635f;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.25em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #292c2c;
font-size: clamp(25px, 3.2vw, 43px);
font-weight: 520;
letter-spacing: -0.035em;
line-height: 1.04;
}
.description {
margin: 14px 0 0;
color: #666762;
font-size: 12px;
line-height: 1.65;
letter-spacing: 0.025em;
}
.specimen-tag {
display: inline-flex;
align-items: center;
gap: 9px;
margin-top: 18px;
color: #5b5e5c;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.specimen-tag::before {
width: 23px;
height: 1px;
background: #777a75;
content: "";
}
.controls {
position: absolute;
right: clamp(20px, 4vw, 54px);
bottom: clamp(20px, 4vw, 42px);
display: flex;
align-items: center;
gap: 16px;
pointer-events: auto;
}
.hint {
color: #666762;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.12em;
text-transform: uppercase;
}
button {
border: 1px solid rgba(50, 53, 51, 0.26);
border-radius: 999px;
padding: 10px 15px;
color: #3d403e;
background: rgba(244, 241, 234, 0.66);
backdrop-filter: blur(8px);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
transition: background 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(255, 253, 248, 0.94);
transform: translateY(-1px);
}
.base-note {
position: absolute;
left: clamp(24px, 5vw, 66px);
bottom: clamp(22px, 4vw, 43px);
display: flex;
gap: 12px;
align-items: center;
color: #666762;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.base-note::before {
width: 8px;
height: 8px;
border: 1px solid #71746f;
border-radius: 50%;
content: "";
}
@media (max-width: 620px) {
.description {
max-width: 280px;
}
.hint,
.base-note {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly basalt column specimen"></canvas>
<div class="overlay">
<section class="title-block">
<div class="eyebrow">Geological Study · 01</div>
<h1>Basalt Column<br>Cluster</h1>
<p class="description">
Fourteen irregular polygonal columns assembled from shared boundaries,
with stepped fracture faces and a continuous level sawn base.
</p>
<div class="specimen-tag">Jointed volcanic specimen</div>
</section>
<div class="base-note">Shared walls · flat basal section</div>
<div class="controls">
<span class="hint">Drag to orbit · scroll to zoom</span>
<button id="reset" type="button">Reset view</button>
</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 resetButton = document.querySelector("#reset");
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(0xd8d3c8);
scene.fog = new THREE.Fog(0xd8d3c8, 13, 29);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const controls = {
target: new THREE.Vector3(0, 1.4, 0),
radius: 8.9,
theta: 0.72,
phi: 1.02
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * cosPhi,
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
// Museum-style lighting.
scene.add(new THREE.HemisphereLight(0xf3eee3, 0x383a3b, 1.75));
const keyLight = new THREE.DirectionalLight(0xffefd7, 3.5);
keyLight.position.set(-4.5, 8.0, 5.2);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5.5;
keyLight.shadow.camera.right = 5.5;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -3.5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbdd2e3, 1.25);
fillLight.position.set(5, 4, -5);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xe7eef0, 0.85);
rimLight.position.set(-5, 3.5, -4);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0xc9c4b9,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.105;
ground.receiveShadow = true;
scene.add(ground);
// Deterministic pseudo-random values.
function random(a, b = 0) {
const value = Math.sin(a * 127.1 + b * 311.7) * 43758.5453123;
return value - Math.floor(value);
}
function distance2D(a, b) {
return Math.hypot(a.x - b.x, a.z - b.z);
}
function signedArea(poly) {
let area = 0;
for (let i = 0; i < poly.length; i++) {
const a = poly[i];
const b = poly[(i + 1) % poly.length];
area += a.x * b.z - b.x * a.z;
}
return area * 0.5;
}
// Convex outline of the entire specimen.
const footprint = [
{ x: -2.45, z: -0.85 },
{ x: -1.95, z: -1.75 },
{ x: -0.80, z: -2.25 },
{ x: 0.65, z: -2.30 },
{ x: 1.85, z: -1.75 },
{ x: 2.45, z: -0.75 },
{ x: 2.30, z: 0.45 },
{ x: 1.70, z: 1.45 },
{ x: 0.45, z: 2.05 },
{ x: -0.95, z: 1.90 },
{ x: -2.00, z: 1.10 },
{ x: -2.55, z: 0.20 }
];
if (signedArea(footprint) < 0) footprint.reverse();
// Seed points and deliberately varied column heights.
const seeds = [
{ x: -1.55, z: -1.35, height: 2.18 },
{ x: -0.18, z: -1.68, height: 2.72 },
{ x: 1.12, z: -1.32, height: 2.05 },
{ x: -2.00, z: -0.55, height: 1.62 },
{ x: -0.76, z: -0.58, height: 2.96 },
{ x: 0.60, z: -0.55, height: 3.22 },
{ x: 1.78, z: -0.18, height: 1.88 },
{ x: -1.78, z: 0.38, height: 1.82 },
{ x: -0.48, z: 0.38, height: 3.05 },
{ x: 0.78, z: 0.42, height: 2.62 },
{ x: 1.72, z: 0.90, height: 1.55 },
{ x: -1.22, z: 1.32, height: 2.12 },
{ x: -0.22, z: 1.40, height: 2.70 },
{ x: 1.02, z: 1.28, height: 1.75 }
];
// Clip the footprint by each Voronoi half-plane.
function clipHalfPlane(poly, nx, nz, limit) {
if (!poly.length) return [];
const output = [];
let previous = poly[poly.length - 1];
let previousDistance = nx * previous.x + nz * previous.z - limit;
for (const current of poly) {
const currentDistance = nx * current.x + nz * current.z - limit;
const previousInside = previousDistance <= 1e-8;
const currentInside = currentDistance <= 1e-8;
if (previousInside !== currentInside) {
const t = previousDistance / (previousDistance - currentDistance);
output.push({
x: previous.x + (current.x - previous.x) * t,
z: previous.z + (current.z - previous.z) * t
});
}
if (currentInside) output.push({ ...current });
previous = current;
previousDistance = currentDistance;
}
return output;
}
function cleanPolygon(poly) {
const clean = [];
for (const point of poly) {
if (
!clean.length ||
distance2D(point, clean[clean.length - 1]) > 1e-5
) {
clean.push(point);
}
}
if (
clean.length > 1 &&
distance2D(clean[0], clean[clean.length - 1]) < 1e-5
) {
clean.pop();
}
return clean;
}
const cells = seeds.map((seed, cellIndex) => {
let polygon = footprint.map(point => ({ ...point }));
for (let otherIndex = 0; otherIndex < seeds.length; otherIndex++) {
if (otherIndex === cellIndex) continue;
const other = seeds[otherIndex];
const nx = other.x - seed.x;
const nz = other.z - seed.z;
const limit =
(other.x * other.x + other.z * other.z -
seed.x * seed.x - seed.z * seed.z) * 0.5;
polygon = cleanPolygon(
clipHalfPlane(polygon, nx, nz, limit)
);
}
const topHeights = polygon.map((_, vertexIndex) =>
seed.height + (random(cellIndex + 4, vertexIndex + 9) - 0.5) * 0.07
);
return {
index: cellIndex,
seed,
polygon,
topHeights,
height: seed.height
};
});
const specimen = new THREE.Group();
scene.add(specimen);
const sidePalette = [
0x3d4244, 0x34393c, 0x484b49,
0x303538, 0x414542, 0x51534f
];
const topPalette = [
0x4b5051, 0x555854, 0x414648,
0x595a55, 0x474b4c, 0x3d4244
];
function paletteColor(palette, a, b, variation = 0.16) {
const color = new THREE.Color(
palette[Math.abs(a * 3 + b) % palette.length]
);
color.multiplyScalar(0.9 + random(a + 2, b + 7) * variation);
return color;
}
function pushTriangle(
positions,
colors,
a,
b,
c,
color
) {
positions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
// Build a shared edge graph from the Voronoi cells.
const edges = [];
cells.forEach(cell => {
cell.polygon.forEach((a, vertexIndex) => {
const nextIndex = (vertexIndex + 1) % cell.polygon.length;
const b = cell.polygon[nextIndex];
edges.push({
cell,
cellIndex: cell.index,
vertexIndex,
nextIndex,
a,
b,
paired: false
});
});
});
function edgesMatch(first, second) {
const firstMid = {
x: (first.a.x + first.b.x) * 0.5,
z: (first.a.z + first.b.z) * 0.5
};
const secondMid = {
x: (second.a.x + second.b.x) * 0.5,
z: (second.a.z + second.b.z) * 0.5
};
const midpointDistance = distance2D(firstMid, secondMid);
const lengthDifference = Math.abs(
distance2D(first.a, first.b) - distance2D(second.a, second.b)
);
const directDistance =
distance2D(first.a, second.a) + distance2D(first.b, second.b);
const reversedDistance =
distance2D(first.a, second.b) + distance2D(first.b, second.a);
return (
midpointDistance < 0.014 &&
lengthDifference < 0.035 &&
Math.min(directDistance, reversedDistance) < 0.035
);
}
for (let i = 0; i < edges.length; i++) {
if (edges[i].paired) continue;
let bestIndex = -1;
let bestDistance = Infinity;
for (let j = i + 1; j < edges.length; j++) {
if (edges[j].paired || !edgesMatch(edges[i], edges[j])) continue;
const midpoint = {
x: (edges[i].a.x + edges[i].b.x) * 0.5,
z: (edges[i].a.z + edges[i].b.z) * 0.5
};
const otherMidpoint = {
x: (edges[j].a.x + edges[j].b.x) * 0.5,
z: (edges[j].a.z + edges[j].b.z) * 0.5
};
const candidateDistance = distance2D(midpoint, otherMidpoint);
if (candidateDistance < bestDistance) {
bestDistance = candidateDistance;
bestIndex = j;
}
}
if (bestIndex !== -1) {
edges[i].paired = true;
edges[bestIndex].paired = true;
edges[i].pair = edges[bestIndex];
edges[bestIndex].pair = edges[i];
}
}
function topHeightAtPoint(cell, point) {
let bestIndex = 0;
let bestDistance = Infinity;
cell.polygon.forEach((vertex, index) => {
const candidateDistance = distance2D(vertex, point);
if (candidateDistance < bestDistance) {
bestDistance = candidateDistance;
bestIndex = index;
}
});
return cell.topHeights[bestIndex];
}
const sidePositions = [];
const sideColors = [];
const wallRecords = [];
function addWall(
cellIndex,
edge,
lowA,
lowB,
highA,
highB,
color
) {
const a0 = { x: edge.a.x, y: lowA, z: edge.a.z };
const a1 = { x: edge.a.x, y: highA, z: edge.a.z };
const b0 = { x: edge.b.x, y: lowB, z: edge.b.z };
const b1 = { x: edge.b.x, y: highB, z: edge.b.z };
const secondColor = color.clone().multiplyScalar(
0.91 + random(cellIndex, 17) * 0.13
);
pushTriangle(
sidePositions, sideColors,
a0, a1, b0,
color
);
pushTriangle(
sidePositions, sideColors,
b0, a1, b1,
secondColor
);
wallRecords.push({
cellIndex,
edge,
lowA,
lowB,
highA,
highB
});
}
// Internal boundaries are rendered only once: from the lower column's top
// to the taller column's top. This prevents duplicated, z-fighting walls.
edges.forEach(edge => {
if (!edge.pair) return;
const owner =
edge.cell.height >= edge.pair.cell.height ? edge : edge.pair;
const lower =
edge.cell.height >= edge.pair.cell.height ? edge.pair : edge;
const sameOrientation =
distance2D(owner.a, lower.a) <= distance2D(owner.a, lower.b);
const lowerA = sameOrientation ? lower.a : lower.b;
const lowerB = sameOrientation ? lower.b : lower.a;
const lowA = topHeightAtPoint(lower.cell, lowerA);
const lowB = topHeightAtPoint(lower.cell, lowerB);
const highA = owner.cell.topHeights[owner.vertexIndex];
const highB = owner.cell.topHeights[owner.nextIndex];
if (Math.min(highA - lowA, highB - lowB) <= 0.015) return;
addWall(
owner.cellIndex,
owner,
lowA,
lowB,
highA,
highB,
paletteColor(sidePalette, owner.cellIndex, owner.vertexIndex)
);
});
const BASE_BOTTOM = -0.10;
const BASE_TOP = 0.09;
// Outer walls form one continuous sawn-base silhouette.
edges.forEach(edge => {
if (edge.pair) return;
addWall(
edge.cellIndex,
edge,
BASE_TOP,
BASE_TOP,
edge.cell.topHeights[edge.vertexIndex],
edge.cell.topHeights[edge.nextIndex],
paletteColor(sidePalette, edge.cellIndex, edge.vertexIndex, 0.12)
);
});
const sideGeometry = new THREE.BufferGeometry();
sideGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(sidePositions, 3)
);
sideGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(sideColors, 3)
);
sideGeometry.computeVertexNormals();
const sideMesh = new THREE.Mesh(
sideGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.86,
metalness: 0.015,
flatShading: true,
side: THREE.DoubleSide
})
);
sideMesh.castShadow = true;
sideMesh.receiveShadow = true;
specimen.add(sideMesh);
// Faceted top surfaces. A slightly raised center creates restrained
// low-poly relief without turning the columns into noisy cylinders.
const topPositions = [];
const topColors = [];
cells.forEach(cell => {
const center = cell.polygon.reduce(
(sum, point) => ({
x: sum.x + point.x / cell.polygon.length,
z: sum.z + point.z / cell.polygon.length
}),
{ x: 0, z: 0 }
);
center.y =
cell.topHeights.reduce((sum, height) => sum + height, 0) /
cell.topHeights.length;
for (let i = 0; i < cell.polygon.length; i++) {
const next = (i + 1) % cell.polygon.length;
const currentPoint = {
x: cell.polygon[i].x,
y: cell.topHeights[i],
z: cell.polygon[i].z
};
const nextPoint = {
x: cell.polygon[next].x,
y: cell.topHeights[next],
z: cell.polygon[next].z
};
pushTriangle(
topPositions,
topColors,
center,
nextPoint,
currentPoint,
paletteColor(topPalette, cell.index, i, 0.19)
);
}
});
const topGeometry = new THREE.BufferGeometry();
topGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(topPositions, 3)
);
topGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(topColors, 3)
);
topGeometry.computeVertexNormals();
const topMesh = new THREE.Mesh(
topGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.94,
metalness: 0.005,
flatShading: true,
side: THREE.DoubleSide
})
);
topMesh.castShadow = true;
topMesh.receiveShadow = true;
specimen.add(topMesh);
// Fine outlines emphasize the shared polygon boundaries.
const outlinePositions = [];
cells.forEach(cell => {
cell.polygon.forEach((point, index) => {
const next = (index + 1) % cell.polygon.length;
outlinePositions.push(
point.x,
cell.topHeights[index] + 0.012,
point.z,
cell.polygon[next].x,
cell.topHeights[next] + 0.012,
cell.polygon[next].z
);
});
});
const outlineGeometry = new THREE.BufferGeometry();
outlineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(outlinePositions, 3)
);
const outlines = new THREE.LineSegments(
outlineGeometry,
new THREE.LineBasicMaterial({
color: 0x202426,
transparent: true,
opacity: 0.58,
depthWrite: false
})
);
outlines.renderOrder = 2;
specimen.add(outlines);
// Sparse vertical mineral fractures on exposed side faces.
const fracturePositions = [];
wallRecords.forEach((wall, wallIndex) => {
const dx = wall.edge.b.x - wall.edge.a.x;
const dz = wall.edge.b.z - wall.edge.a.z;
const length = Math.hypot(dx, dz);
if (length < 0.2) return;
// Outward normal for the CCW cell polygons.
const normalX = dz / length;
const normalZ = -dx / length;
const t = 0.30 + random(wallIndex + 31, wall.cellIndex + 3) * 0.32;
const t2 = t + 0.035;
const lowY =
wall.lowA * (1 - t) + wall.lowB * t;
const highY =
wall.highA * (1 - t) + wall.highB * t;
if (highY - lowY < 0.16) return;
const start = {
x:
wall.edge.a.x +
(wall.edge.b.x - wall.edge.a.x) * t +
normalX * 0.012,
y: lowY + 0.045,
z:
wall.edge.a.z +
(wall.edge.b.z - wall.edge.a.z) * t +
normalZ * 0.012
};
const end = {
x:
wall.edge.a.x +
(wall.edge.b.x - wall.edge.a.x) * t2 +
normalX * 0.012,
y: highY - 0.035,
z:
wall.edge.a.z +
(wall.edge.b.z - wall.edge.a.z) * t2 +
normalZ * 0.012
};
fracturePositions.push(
start.x, start.y, start.z,
end.x, end.y, end.z
);
});
const fractureGeometry = new THREE.BufferGeometry();
fractureGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(fracturePositions, 3)
);
const fractures = new THREE.LineSegments(
fractureGeometry,
new THREE.LineBasicMaterial({
color: 0x171b1d,
transparent: true,
opacity: 0.38,
depthWrite: false
})
);
fractures.renderOrder = 1;
specimen.add(fractures);
// A single continuous basal section, rather than individual footings.
const basePositions = [];
const baseColors = [];
footprint.forEach((point, index) => {
const next = footprint[(index + 1) % footprint.length];
const bottomA = { x: point.x, y: BASE_BOTTOM, z: point.z };
const topA = { x: point.x, y: BASE_TOP, z: point.z };
const bottomB = { x: next.x, y: BASE_BOTTOM, z: next.z };
const topB = { x: next.x, y: BASE_TOP, z: next.z };
const color = new THREE.Color(0x3c4548);
color.multiplyScalar(0.92 + random(index, 71) * 0.12);
pushTriangle(
basePositions, baseColors,
bottomA, topA, bottomB,
color
);
pushTriangle(
basePositions, baseColors,
bottomB, topA, topB,
color.clone().multiplyScalar(0.96)
);
});
const baseCenter = footprint.reduce(
(sum, point) => ({
x: sum.x + point.x / footprint.length,
z: sum.z + point.z / footprint.length
}),
{ x: 0, z: 0 }
);
baseCenter.y = BASE_TOP + 0.002;
for (let i = 0; i < footprint.length; i++) {
const next = (i + 1) % footprint.length;
pushTriangle(
basePositions,
baseColors,
baseCenter,
{ x: footprint[next].x, y: baseCenter.y, z: footprint[next].z },
{ x: footprint[i].x, y: baseCenter.y, z: footprint[i].z },
new THREE.Color(0x30383b)
);
}
const baseGeometry = new THREE.BufferGeometry();
baseGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(basePositions, 3)
);
baseGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(baseColors, 3)
);
baseGeometry.computeVertexNormals();
const baseMesh = new THREE.Mesh(
baseGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.7,
metalness: 0.01,
flatShading: true,
side: THREE.DoubleSide
})
);
baseMesh.castShadow = true;
baseMesh.receiveShadow = true;
specimen.add(baseMesh);
// A crisp, slightly cooler edge identifies the sawn basal plane.
const cutLinePositions = [];
footprint.forEach((point, index) => {
const next = footprint[(index + 1) % footprint.length];
cutLinePositions.push(
point.x, BASE_TOP + 0.005, point.z,
next.x, BASE_TOP + 0.005, next.z
);
});
const cutLineGeometry = new THREE.BufferGeometry();
cutLineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(cutLinePositions, 3)
);
const cutLine = new THREE.LineSegments(
cutLineGeometry,
new THREE.LineBasicMaterial({
color: 0x859093,
transparent: true,
opacity: 0.38,
depthWrite: false
})
);
cutLine.renderOrder = 3;
specimen.add(cutLine);
// Camera controls implemented directly without addons.
const pointers = new Map();
let pinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) pinchDistance = pointerDistance();
});
canvas.addEventListener("pointermove", event => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const current = {
x: event.clientX,
y: event.clientY
};
pointers.set(event.pointerId, current);
if (pointers.size === 1) {
const deltaX = current.x - previous.x;
const deltaY = current.y - previous.y;
controls.theta -= deltaX * 0.006;
controls.phi -= deltaY * 0.005;
controls.phi = THREE.MathUtils.clamp(controls.phi, 0.38, 1.42);
} else if (pointers.size >= 2) {
const nextDistance = pointerDistance();
if (pinchDistance > 0 && nextDistance > 0) {
controls.radius *= pinchDistance / nextDistance;
controls.radius = THREE.MathUtils.clamp(
controls.radius,
5.2,
14
);
}
pinchDistance = nextDistance;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.radius *= Math.exp(event.deltaY * 0.001);
controls.radius = THREE.MathUtils.clamp(
controls.radius,
5.2,
14
);
updateCamera();
},
{ passive: false }
);
function resetView() {
controls.radius = 8.9;
controls.theta = 0.72;
controls.phi = 1.02;
updateCamera();
}
resetButton.addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```