Prompt specification
Build or customize the Three.js 3D scene "Salt-crust polygon and shallow brine tile" 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: Salt-crust polygon and shallow brine tile
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/salt-crust-polygon-and-shallow-brine-tile-x3045
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring closed saline basins of the Andean Altiplano. Build a referenced high-plateau salt-flat fragment with polygonal crust and a shallow water patch. Distinguish surface pattern from the deeper basin geometry through a cutaway edge. Stylized solid forms.
Working Three.js Starter (salt-crust-polygon-and-shallow-brine-tile-x3045):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Altiplano — Closed Saline Basin</title>
<style>
:root {
--ink: #263536;
--muted: #61706e;
--paper: #f3eadb;
--salt: #f3f0df;
--brine: #5ba4a2;
--sediment: #bd806c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfcfbb;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.title-block {
position: absolute;
top: 30px;
left: 34px;
max-width: 390px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 11px;
color: #6e7771;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 30px;
height: 1px;
content: "";
background: currentColor;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4.1vw, 58px);
font-weight: 400;
line-height: 0.93;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 330px;
margin: 15px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.6;
}
.classification {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 15px;
padding: 7px 10px;
border: 1px solid rgba(38, 53, 54, 0.2);
border-radius: 999px;
background: rgba(247, 239, 225, 0.44);
color: #53625f;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
backdrop-filter: blur(7px);
}
.classification i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--brine);
box-shadow: 0 0 0 3px rgba(91, 164, 162, 0.18);
}
.controls {
position: absolute;
top: 30px;
right: 30px;
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.control-hint {
padding: 9px 12px;
border: 1px solid rgba(38, 53, 54, 0.14);
border-radius: 8px;
background: rgba(247, 239, 225, 0.48);
color: #61706e;
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
button {
min-height: 36px;
padding: 0 13px;
border: 1px solid rgba(38, 53, 54, 0.2);
border-radius: 8px;
background: rgba(247, 239, 225, 0.78);
color: var(--ink);
font: inherit;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(8px);
transition:
background 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(255, 250, 239, 0.96);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--brine);
outline-offset: 3px;
}
.legend {
position: absolute;
left: 34px;
bottom: 30px;
display: grid;
grid-template-columns: repeat(3, auto);
gap: 19px;
padding: 13px 16px;
border: 1px solid rgba(38, 53, 54, 0.13);
border-radius: 9px;
background: rgba(247, 239, 225, 0.58);
backdrop-filter: blur(10px);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #586664;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.swatch {
width: 15px;
height: 8px;
border: 1px solid rgba(38, 53, 54, 0.13);
border-radius: 2px;
}
.swatch.crust {
background: var(--salt);
}
.swatch.brine {
background: var(--brine);
}
.swatch.basin {
background: var(--sediment);
}
.pin {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
pointer-events: none;
will-change: transform;
}
.pin i {
position: relative;
display: block;
width: 7px;
height: 7px;
border: 1px solid rgba(38, 53, 54, 0.55);
border-radius: 50%;
background: #f7f0df;
box-shadow: 0 0 0 4px rgba(247, 240, 223, 0.28);
}
.pin span {
margin-left: 12px;
padding: 6px 8px;
border-left: 1px solid rgba(38, 53, 54, 0.36);
background: rgba(245, 236, 219, 0.67);
color: #425452;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.13em;
line-height: 1.35;
text-transform: uppercase;
white-space: nowrap;
backdrop-filter: blur(6px);
}
.pin.reverse {
flex-direction: row-reverse;
}
.pin.reverse span {
margin-right: 12px;
margin-left: 0;
border-right: 1px solid rgba(38, 53, 54, 0.36);
border-left: 0;
text-align: right;
}
.section-tag {
position: absolute;
right: 34px;
bottom: 30px;
color: rgba(38, 53, 54, 0.55);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.title-block {
top: 20px;
left: 20px;
max-width: 280px;
}
.subtitle {
max-width: 250px;
font-size: 11px;
}
.classification {
margin-top: 10px;
}
.controls {
top: 20px;
right: 18px;
}
.control-hint {
display: none;
}
.legend {
left: 18px;
right: 18px;
bottom: 18px;
justify-content: space-between;
gap: 8px;
padding: 11px 12px;
}
.legend-item {
gap: 5px;
font-size: 7px;
letter-spacing: 0.04em;
}
.section-tag,
.pin {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<header class="title-block">
<div class="eyebrow">Andean Altiplano · Basin Study 01</div>
<h1>Saline<br />Interior</h1>
<p class="subtitle">
A stylized fragment of a closed, endorheic salt flat: polygonal
evaporite crust surrounding a shallow residual brine patch.
</p>
<div class="classification"><i></i> Endorheic · no surface outflow</div>
</header>
<div class="controls">
<div class="control-hint">Drag to orbit · scroll to zoom</div>
<button id="reset" type="button">Reset view</button>
</div>
<div class="legend" aria-label="Scene legend">
<div class="legend-item">
<span class="swatch crust"></span>
Salt crust
</div>
<div class="legend-item">
<span class="swatch brine"></span>
Shallow brine
</div>
<div class="legend-item">
<span class="swatch basin"></span>
Basin sediment
</div>
</div>
<div class="pin" id="pin-crust"><i></i><span>Polygonal salt crust</span></div>
<div class="pin" id="pin-brine"><i></i><span>Residual brine</span></div>
<div class="pin reverse" id="pin-section"><i></i><span>Cutaway · closed basin</span></div>
<div class="section-tag">Section A—A / Altiplano saline basin</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 mount = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfcfbb);
scene.fog = new THREE.FogExp2(0xdfcfbb, 0.018);
const renderer = new THREE.WebGLRenderer({
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;
mount.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, -0.08, 0);
let azimuth = 0.57;
let polar = 1.04;
let radius = 13.2;
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
updateCamera();
// Lighting
const hemisphere = new THREE.HemisphereLight(0xfff3dc, 0x667574, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.4);
sun.position.set(-5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8cb8c1, 1.05);
fill.position.set(7, 4, -5);
scene.add(fill);
// Geometric helpers
function seededRandom(seed) {
return function () {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(48271);
function shapeFromXZ(points) {
const shape = new THREE.Shape();
points.forEach((point, index) => {
if (index === 0) {
shape.moveTo(point.x, -point.y);
} else {
shape.lineTo(point.x, -point.y);
}
});
shape.closePath();
return shape;
}
function polygonCentroid(points) {
const center = new THREE.Vector2();
points.forEach((point) => center.add(point));
return center.multiplyScalar(1 / points.length);
}
function scalePolygon(points, factor, center = polygonCentroid(points)) {
return points.map((point) =>
center.clone().add(point.clone().sub(center).multiplyScalar(factor))
);
}
function pointInPolygon(point, polygon) {
let inside = false;
for (
let i = 0, j = polygon.length - 1;
i < polygon.length;
j = i++
) {
const a = polygon[i];
const b = polygon[j];
const intersects =
a.y > point.y !== b.y > point.y &&
point.x <
((b.x - a.x) * (point.y - a.y)) / (b.y - a.y) + a.x;
if (intersects) inside = !inside;
}
return inside;
}
function clipToBisector(polygon, site, otherSite) {
const midpoint = site.clone().add(otherSite).multiplyScalar(0.5);
const direction = otherSite.clone().sub(site);
const signedValue = (point) =>
point.clone().sub(midpoint).dot(direction);
const result = [];
let previous = polygon[polygon.length - 1];
let previousValue = signedValue(previous);
let previousInside = previousValue <= 0;
for (const current of polygon) {
const currentValue = signedValue(current);
const currentInside = currentValue <= 0;
if (currentInside !== previousInside) {
const t = previousValue / (previousValue - currentValue);
result.push(previous.clone().lerp(current, t));
}
if (currentInside) result.push(current.clone());
previous = current;
previousValue = currentValue;
previousInside = currentInside;
}
return result;
}
function angularTube(points, y, radius, material, closed = true) {
const path = new THREE.CurvePath();
for (let i = 0; i < points.length - 1; i++) {
path.add(
new THREE.LineCurve3(
new THREE.Vector3(points[i].x, y, points[i].y),
new THREE.Vector3(points[i + 1].x, y, points[i + 1].y)
)
);
}
if (closed) {
const last = points[points.length - 1];
const first = points[0];
path.add(
new THREE.LineCurve3(
new THREE.Vector3(last.x, y, last.y),
new THREE.Vector3(first.x, y, first.y)
)
);
}
const geometry = new THREE.TubeGeometry(
path,
Math.max(48, points.length * 8),
radius,
5,
closed
);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
return mesh;
}
// Main irregular salt-flat fragment
const outline = [
new THREE.Vector2(-4.8, -1.2),
new THREE.Vector2(-4.2, -2.2),
new THREE.Vector2(-2.8, -2.95),
new THREE.Vector2(-1.0, -3.25),
new THREE.Vector2(1.1, -3.2),
new THREE.Vector2(3.1, -2.65),
new THREE.Vector2(4.35, -1.6),
new THREE.Vector2(4.75, -0.2),
new THREE.Vector2(4.45, 1.2),
new THREE.Vector2(3.35, 2.15),
new THREE.Vector2(1.6, 2.42),
new THREE.Vector2(-0.4, 2.5),
new THREE.Vector2(-2.2, 2.38),
new THREE.Vector2(-3.7, 1.85),
new THREE.Vector2(-4.55, 0.75)
];
const topY = 0.45;
const bottomY = -1.45;
const baseShape = shapeFromXZ(outline);
const baseGeometry = new THREE.ExtrudeGeometry(baseShape, {
depth: topY - bottomY,
bevelEnabled: false,
steps: 1,
curveSegments: 1
});
baseGeometry.rotateX(-Math.PI / 2);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0xae806c,
roughness: 0.94,
metalness: 0
});
const capMaterial = new THREE.MeshStandardMaterial({
color: 0x8f9187,
roughness: 1
});
const base = new THREE.Mesh(baseGeometry, [capMaterial, baseMaterial]);
base.position.y = bottomY;
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
// Gray underlayer visible through the polygonal seams
const underlayerGeometry = new THREE.ShapeGeometry(
shapeFromXZ(outline)
);
underlayerGeometry.rotateX(-Math.PI / 2);
const underlayer = new THREE.Mesh(
underlayerGeometry,
new THREE.MeshStandardMaterial({
color: 0x8d9189,
roughness: 1,
side: THREE.DoubleSide
})
);
underlayer.position.y = topY + 0.002;
underlayer.receiveShadow = true;
scene.add(underlayer);
// Generate a Voronoi-like salt-crust pattern by clipping half-planes.
const sites = [];
let attempts = 0;
while (sites.length < 58 && attempts < 8000) {
attempts++;
const candidate = new THREE.Vector2(
-4.55 + random() * 9.1,
-3.05 + random() * 5.35
);
if (!pointInPolygon(candidate, outline)) continue;
const sufficientlySeparated = sites.every(
(site) => site.distanceTo(candidate) > 0.39
);
if (sufficientlySeparated) sites.push(candidate);
}
const crustPalette = [
0xf3efdf,
0xe9e4d2,
0xeee8d5,
0xe3deca,
0xf7f1df,
0xded9c8
];
const crustMaterials = crustPalette.map(
(color) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
side: THREE.DoubleSide
})
);
sites.forEach((site, siteIndex) => {
let cell = outline.map((point) => point.clone());
for (let j = 0; j < sites.length && cell.length; j++) {
if (j === siteIndex) continue;
cell = clipToBisector(cell, site, sites[j]);
}
if (cell.length < 3) return;
// Small inset creates narrow saline seams between crust plates.
const insetCell = cell.map((point) =>
site.clone().add(point.clone().sub(site).multiplyScalar(0.972))
);
const geometry = new THREE.ShapeGeometry(
shapeFromXZ(insetCell)
);
geometry.rotateX(-Math.PI / 2);
const material =
crustMaterials[Math.floor(random() * crustMaterials.length)];
const plate = new THREE.Mesh(geometry, material);
plate.position.y = topY + 0.009 + random() * 0.01;
plate.receiveShadow = true;
scene.add(plate);
});
// Raised angular salt perimeter
const saltEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0xf5f0df,
roughness: 0.8
});
const perimeter = angularTube(
outline,
topY + 0.026,
0.025,
saltEdgeMaterial
);
scene.add(perimeter);
// Residual shallow brine and its damp shoreline
const waterOutline = [
new THREE.Vector2(-3.15, -0.65),
new THREE.Vector2(-2.8, -1.25),
new THREE.Vector2(-1.95, -1.58),
new THREE.Vector2(-1.0, -1.42),
new THREE.Vector2(-0.45, -0.95),
new THREE.Vector2(-0.48, -0.28),
new THREE.Vector2(-0.95, 0.2),
new THREE.Vector2(-1.85, 0.53),
new THREE.Vector2(-2.75, 0.3),
new THREE.Vector2(-3.25, -0.1)
];
const waterCenter = polygonCentroid(waterOutline);
const shoreline = scalePolygon(waterOutline, 1.17, waterCenter);
const shorelineGeometry = new THREE.ShapeGeometry(
shapeFromXZ(shoreline)
);
shorelineGeometry.rotateX(-Math.PI / 2);
const shorelineMesh = new THREE.Mesh(
shorelineGeometry,
new THREE.MeshStandardMaterial({
color: 0xc3b393,
roughness: 0.92,
side: THREE.DoubleSide
})
);
shorelineMesh.position.y = topY + 0.019;
shorelineMesh.receiveShadow = true;
scene.add(shorelineMesh);
const waterGeometry = new THREE.ShapeGeometry(
shapeFromXZ(waterOutline)
);
waterGeometry.rotateX(-Math.PI / 2);
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x3f9698,
roughness: 0.22,
metalness: 0.03,
transparent: true,
opacity: 0.84,
clearcoat: 0.72,
clearcoatRoughness: 0.22,
depthWrite: false,
side: THREE.DoubleSide
});
const water = new THREE.Mesh(waterGeometry, waterMaterial);
water.position.y = topY + 0.025;
water.renderOrder = 2;
scene.add(water);
const wetEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0xb9ded6,
roughness: 0.38,
transparent: true,
opacity: 0.72
});
scene.add(
angularTube(
waterOutline,
topY + 0.031,
0.012,
wetEdgeMaterial
)
);
// Small residual salt islands
const islandDefinitions = [
[
[-1.75, -0.45],
[-1.48, -0.58],
[-1.25, -0.38],
[-1.52, -0.2]
],
[
[-2.58, -0.05],
[-2.32, -0.16],
[-2.12, 0.02],
[-2.4, 0.17]
],
[
[-0.95, -0.83],
[-0.68, -0.91],
[-0.53, -0.74],
[-0.77, -0.62]
]
];
islandDefinitions.forEach((definition) => {
const points = definition.map(
(point) => new THREE.Vector2(point[0], point[1])
);
const geometry = new THREE.ShapeGeometry(shapeFromXZ(points));
geometry.rotateX(-Math.PI / 2);
const island = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0xeee9d7,
roughness: 0.9,
side: THREE.DoubleSide
})
);
island.position.y = topY + 0.034;
island.castShadow = true;
scene.add(island);
});
// Stylized ripple highlights on the brine
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0xb8e5df,
transparent: true,
opacity: 0.42
});
function addRipple(x1, z1, x2, z2, bend, phase = 0) {
const points = [];
for (let i = 0; i <= 8; i++) {
const t = i / 8;
const x = THREE.MathUtils.lerp(x1, x2, t);
const z =
THREE.MathUtils.lerp(z1, z2, t) +
Math.sin(t * Math.PI + phase) * bend;
points.push(new THREE.Vector3(x, topY + 0.039, z));
}
const curve = new THREE.CatmullRomCurve3(points);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 28, 0.007, 4, false),
rippleMaterial
);
scene.add(mesh);
}
addRipple(-2.65, -0.8, -1.65, -0.65, 0.08);
addRipple(-2.4, 0.02, -1.25, 0.15, -0.08);
addRipple(-1.55, -1.16, -0.75, -1.03, 0.05);
// Exposed front cutaway: surface cap and deeper concave basin geometry.
const cutEdge = [
new THREE.Vector2(-4.55, 0.75),
new THREE.Vector2(-3.7, 1.85),
new THREE.Vector2(-2.2, 2.38),
new THREE.Vector2(-0.4, 2.5),
new THREE.Vector2(1.6, 2.42),
new THREE.Vector2(3.35, 2.15),
new THREE.Vector2(4.45, 1.2)
];
function makeCutBand(topValues, bottomValues, color) {
const positions = [];
for (let i = 0; i < cutEdge.length - 1; i++) {
const a = cutEdge[i];
const b = cutEdge[i + 1];
positions.push(
a.x, topValues[i], a.y,
b.x, topValues[i + 1], b.y,
b.x, bottomValues[i + 1], b.y,
a.x, topValues[i], a.y,
b.x, bottomValues[i + 1], b.y,
a.x, bottomValues[i], a.y
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.95,
side: THREE.DoubleSide,
polygonOffset: true,
polygonOffsetFactor: -1,
polygonOffsetUnits: -1
});
const band = new THREE.Mesh(geometry, material);
band.castShadow = true;
band.receiveShadow = true;
scene.add(band);
}
const crustBottom = cutEdge.map(() => topY - 0.13);
const basinBottom = [
-0.19,
-0.43,
-0.7,
-0.78,
-0.64,
-0.35,
-0.18
];
const sedimentBottom = basinBottom.map((value) => value - 0.46);
const baseBottom = cutEdge.map(() => bottomY);
makeCutBand(
cutEdge.map(() => topY),
crustBottom,
0xf0ecdc
);
makeCutBand(
crustBottom,
basinBottom,
0x8faeaa
);
makeCutBand(
basinBottom,
sedimentBottom,
0xc1816b
);
makeCutBand(
sedimentBottom,
baseBottom,
0x596968
);
const interfaceMaterial = new THREE.MeshStandardMaterial({
color: 0x547a78,
roughness: 0.72
});
scene.add(
angularTube(
cutEdge,
0,
0.015,
interfaceMaterial,
false
).translateY(0)
);
// The interface tube was created at y = 0, so replace it with the
// curved basin boundary at the appropriate elevations.
const boundaryPoints = cutEdge.map(
(point, index) => new THREE.Vector2(point.x, basinBottom[index])
);
const curvedBoundary = angularTube(
boundaryPoints,
0,
0.014,
interfaceMaterial,
false
);
scene.add(curvedBoundary);
// Distant solid Andean ridges
function addRidge(points, z, depth, color) {
const shape = new THREE.Shape();
points.forEach((point, index) => {
if (index === 0) shape.moveTo(point[0], point[1]);
else shape.lineTo(point[0], point[1]);
});
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
steps: 1
});
const ridge = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color,
roughness: 1,
flatShading: true
})
);
ridge.position.z = z;
ridge.receiveShadow = true;
scene.add(ridge);
}
addRidge(
[
[-15, -1.46],
[-12, 0.15],
[-9.5, 1.05],
[-7.5, 0.22],
[-5.5, 1.7],
[-3.7, 0.38],
[-1.8, 1.08],
[0.2, 0.28],
[2.3, 1.5],
[4.4, 0.45],
[6.6, 1.9],
[9.3, 0.18],
[12.5, 1.2],
[15, -1.46]
],
-11,
0.75,
0xc2b19e
);
addRidge(
[
[-15, -1.46],
[-11.8, 0.7],
[-9.1, 0.08],
[-6.8, 1.35],
[-4.5, 0.42],
[-2.2, 1.05],
[0.1, 0.18],
[2.5, 1.2],
[4.8, 0.25],
[7.2, 1.55],
[10, 0.3],
[15, -1.46]
],
-8.5,
0.8,
0xae978a
);
// Studio ground
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xd7c3aa,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = bottomY - 0.025;
ground.receiveShadow = true;
scene.add(ground);
// Direct camera controls: no examples/addons modules.
const pointers = new Map();
let pinchDistance = null;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(
polar - dy * 0.005,
0.42,
1.43
);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance) {
radius = THREE.MathUtils.clamp(
radius * (pinchDistance / distance),
7.8,
19
);
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = null;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
7.8,
19
);
},
{ passive: false }
);
function resetView() {
azimuth = 0.57;
polar = 1.04;
radius = 13.2;
}
document.getElementById("reset").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
const step = 0.09;
if (event.key === "ArrowLeft") azimuth += step;
if (event.key === "ArrowRight") azimuth -= step;
if (event.key === "ArrowUp") polar = Math.max(0.42, polar - step);
if (event.key === "ArrowDown") polar = Math.min(1.43, polar + step);
if (event.key === "+" || event.key === "=") radius = Math.max(7.8, radius - 0.6);
if (event.key === "-" || event.key === "_") radius = Math.min(19, radius + 0.6);
});
// Lightweight projected HTML annotations
const pinDefinitions = [
{
element: document.getElementById("pin-crust"),
position: new THREE.Vector3(2.25, 0.58, -0.85)
},
{
element: document.getElementById("pin-brine"),
position: new THREE.Vector3(-1.7, 0.59, -0.4)
},
{
element: document.getElementById("pin-section"),
position: new THREE.Vector3(0.75, -0.18, 2.56)
}
];
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
pinDefinitions.forEach(({ element, position }) => {
projected.copy(position).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.transform = `translate3d(${x}px, ${y}px, 0)`;
element.style.opacity =
projected.z > -1 && projected.z < 1 ? "1" : "0";
});
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
function animate() {
requestAnimationFrame(animate);
updateCamera();
renderer.render(scene, camera);
updateAnnotations();
}
animate();
</script>
</body>
</html>
```