Prompt specification
Build or customize the Three.js 3D scene "Archaeology trench beside a geological outcrop" 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: Archaeology trench beside a geological outcrop
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/archaeology-trench-beside-a-geological-outcrop-x1171
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: archaeology trench beside a geological outcrop. Compose a trench with shallow human deposits beside much deeper rock layers; distinguish archaeological context from geological strata and avoid implying equal timescales.
Working Three.js Starter (archaeology-trench-beside-a-geological-outcrop-x1171):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A Trench Through Two Timescales</title>
<style>
:root {
--ink: #183038;
--muted: #607176;
--paper: rgba(248, 250, 246, 0.92);
--amber: #e69b42;
--amber-dark: #9b5b24;
--teal: #4b8e9b;
--teal-dark: #285d68;
--line: rgba(24, 48, 56, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe5e1;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
user-select: none;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
#leaders,
#callouts {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 3;
}
#leaders {
overflow: visible;
}
.leader {
fill: none;
stroke: rgba(24, 48, 56, 0.58);
stroke-width: 1.25;
stroke-linecap: round;
stroke-dasharray: 3 4;
}
.leader.amber {
stroke: rgba(155, 91, 36, 0.75);
}
.leader.teal {
stroke: rgba(40, 93, 104, 0.76);
}
.anchor {
stroke: #fff;
stroke-width: 1.5;
}
.anchor.amber {
fill: var(--amber);
}
.anchor.teal {
fill: var(--teal);
}
.callout {
position: absolute;
width: 230px;
transform: translate(-50%, -100%);
padding: 11px 13px 12px;
border: 1px solid rgba(24, 48, 56, 0.16);
border-top: 3px solid var(--amber);
border-radius: 8px;
background: rgba(249, 250, 246, 0.94);
box-shadow: 0 9px 28px rgba(24, 48, 56, 0.13);
backdrop-filter: blur(10px);
transition: opacity 120ms ease;
}
.callout.geology {
border-top-color: var(--teal);
}
.callout .eyebrow {
display: block;
margin-bottom: 4px;
color: var(--amber-dark);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.callout.geology .eyebrow {
color: var(--teal-dark);
}
.callout strong {
display: block;
font-size: 14px;
line-height: 1.15;
}
.callout small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.callout.mini {
width: 172px;
padding: 7px 9px;
border-top-width: 2px;
border-radius: 5px;
box-shadow: 0 5px 16px rgba(24, 48, 56, 0.11);
}
.callout.mini strong {
font-size: 10px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.title-card,
.view-tools,
.legend {
position: fixed;
z-index: 5;
}
.title-card {
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 17px 19px 18px;
border: 1px solid rgba(24, 48, 56, 0.13);
border-radius: 10px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(24, 48, 56, 0.12);
backdrop-filter: blur(12px);
pointer-events: none;
}
.kicker {
margin-bottom: 7px;
color: var(--amber-dark);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.3vw, 31px);
line-height: 1.06;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
max-width: 340px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.view-tools {
top: 20px;
right: 20px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: none;
}
.view-tools .hint,
#reset {
border: 1px solid rgba(24, 48, 56, 0.14);
border-radius: 7px;
background: rgba(249, 250, 246, 0.9);
color: var(--ink);
box-shadow: 0 7px 20px rgba(24, 48, 56, 0.09);
backdrop-filter: blur(10px);
}
.view-tools .hint {
padding: 9px 11px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.02em;
}
#reset {
padding: 9px 11px;
font: inherit;
font-size: 10px;
font-weight: 750;
cursor: pointer;
pointer-events: auto;
}
#reset:hover {
background: #fff;
}
.legend {
left: 50%;
bottom: 20px;
width: min(970px, calc(100vw - 40px));
transform: translateX(-50%);
display: grid;
grid-template-columns: 1fr 1fr 1.18fr;
overflow: hidden;
border: 1px solid rgba(24, 48, 56, 0.14);
border-radius: 10px;
background: rgba(249, 250, 246, 0.94);
box-shadow: 0 12px 35px rgba(24, 48, 56, 0.13);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-item {
min-height: 94px;
padding: 14px 16px 15px;
border-right: 1px solid var(--line);
}
.legend-item:last-child {
border-right: 0;
}
.legend-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.swatch {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.swatch.amber {
background: var(--amber);
}
.swatch.teal {
background: var(--teal);
}
.legend-item strong {
display: block;
margin-bottom: 3px;
font-size: 13px;
}
.legend-item p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.scale-note {
background: rgba(216, 232, 229, 0.56);
}
.scale-note .legend-title {
color: var(--teal-dark);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dbe5e1;
color: var(--ink);
font-size: 12px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
.title-card {
top: 12px;
left: 12px;
width: min(340px, calc(100vw - 24px));
padding: 13px 15px;
}
.view-tools {
top: 12px;
right: 12px;
}
.view-tools .hint {
display: none;
}
.legend {
bottom: 12px;
width: calc(100vw - 24px);
grid-template-columns: 1fr 1fr;
}
.scale-note {
grid-column: 1 / -1;
border-top: 1px solid var(--line);
}
.legend-item {
min-height: 82px;
}
.callout {
width: 190px;
}
.callout.mini {
width: 150px;
}
}
@media (max-width: 520px) {
.title-card {
width: calc(100vw - 24px);
}
.subtitle {
max-width: 270px;
}
.legend {
grid-template-columns: 1fr;
}
.legend-item {
min-height: 0;
padding: 10px 13px;
border-right: 0;
border-bottom: 1px solid var(--line);
}
.scale-note {
grid-column: auto;
border-top: 0;
}
.callout {
width: 165px;
padding: 8px 10px;
}
.callout strong {
font-size: 12px;
}
.callout small {
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel cutaway of an archaeological trench beside a much deeper geological outcrop"
></canvas>
<svg id="leaders" aria-hidden="true"></svg>
<div id="callouts" aria-hidden="true">
<div id="archTag" class="callout">
<span class="eyebrow">Archaeological context</span>
<strong>Recent human deposits</strong>
<small>Hearth, shallow burial and artefacts · years to millennia</small>
</div>
<div id="geoTag" class="callout geology">
<span class="eyebrow">Natural geology</span>
<strong>Deep geological time</strong>
<small>Rock sequence · millions to hundreds of millions of years</small>
</div>
<div id="burialTag" class="callout mini">
<strong>Sealed shallow burial</strong>
</div>
<div id="hearthTag" class="callout mini">
<strong>Hearth / occupation</strong>
</div>
<div id="occupationTag" class="callout mini">
<strong>Thin occupation layer</strong>
</div>
<div id="depthTag" class="callout mini">
<strong>≈ 1.5 m excavation</strong>
</div>
</div>
<header class="title-card">
<div class="kicker">Voxel cutaway · schematic study</div>
<h1>A trench through two timescales</h1>
<p class="subtitle">
A shallow archaeological context sits beside a much deeper natural
outcrop. Their scales and histories are deliberately distinguished.
</p>
</header>
<div class="view-tools">
<div class="hint">Drag to orbit · Scroll to zoom · R to reset</div>
<button id="reset" type="button">Reset view</button>
</div>
<section class="legend" aria-label="Scene legend">
<div class="legend-item">
<div class="legend-title">
<span class="swatch amber"></span>
Archaeology
</div>
<strong>Recent human activity</strong>
<p>
Shallow hearth, burial and artefact deposits.
Years to millennia, not geological time.
</p>
</div>
<div class="legend-item">
<div class="legend-title">
<span class="swatch teal"></span>
Geology
</div>
<strong>Natural rock sequence</strong>
<p>
A much deeper sedimentary and basement-rock section.
Millions to hundreds of millions of years.
</p>
</div>
<div class="legend-item scale-note">
<div class="legend-title">Different scales, deliberately</div>
<strong>Not a proportional time ruler</strong>
<p>
The geology is enlarged relative to the trench, and its immense
history is compressed into a schematic sequence. Band thickness does
not represent equal spans of time.
</p>
</div>
</section>
<div id="loading">Building the cutaway…</div>
<noscript>This scene requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const loading = document.getElementById("loading");
const legend = document.querySelector(".legend");
const resetButton = document.getElementById("reset");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
loading.textContent = "WebGL could not be initialized";
throw error;
}
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(0xdbe5e1);
scene.fog = new THREE.Fog(0xdbe5e1, 34, 72);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
120
);
const cameraState = {
target: new THREE.Vector3(0.5, -2.35, 0),
theta: 0.64,
phi: 0.86,
radius: 24
};
function baseRadius() {
if (window.innerWidth < 560) return 41;
if (window.innerWidth < 900) return 30;
return 24;
}
cameraState.radius = baseRadius();
const hemi = new THREE.HemisphereLight(0xf7fbf5, 0x60706f, 1.65);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff4df, 3.1);
keyLight.position.set(-9, 16, 11);
keyLight.target.position.set(0, -2, 0);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -15;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 48;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight, keyLight.target);
const fillLight = new THREE.DirectionalLight(0xb9d9e4, 1.35);
fillLight.position.set(12, 7, -9);
scene.add(fillLight);
const boxGeometry = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
const materialCache = new Map();
function hash(x, z, salt = 0) {
const value = Math.sin(
x * 127.1 + z * 311.7 + salt * 74.7
) * 43758.5453123;
return value - Math.floor(value);
}
function variedColor(hex, amount) {
const color = new THREE.Color(hex);
color.multiplyScalar(amount);
return color;
}
function standardMaterial(color, roughness = 0.92) {
const key = `${color}-${roughness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0
})
);
}
return materialCache.get(key);
}
function addBox(
width,
height,
depth,
x,
y,
z,
color,
options = {}
) {
const mesh = new THREE.Mesh(
boxGeometry,
options.material || standardMaterial(color, options.roughness ?? 0.92)
);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
scene.add(mesh);
return mesh;
}
function addInstances(items, name) {
if (!items.length) return null;
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.93,
metalness: 0
});
const mesh = new THREE.InstancedMesh(
boxGeometry,
material,
items.length
);
mesh.name = name;
mesh.castShadow = true;
mesh.receiveShadow = true;
for (let i = 0; i < items.length; i++) {
const item = items[i];
dummy.position.set(item.x, item.y, item.z);
dummy.scale.set(item.sx, item.sy, item.sz);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
const color = item.color instanceof THREE.Color
? item.color
: new THREE.Color(item.color);
mesh.setColorAt(i, color);
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) {
mesh.instanceColor.needsUpdate = true;
}
mesh.computeBoundingSphere();
scene.add(mesh);
return mesh;
}
// Common display ground and plinth.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
standardMaterial(0xcfdad6, 1)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -8.42;
ground.receiveShadow = true;
scene.add(ground);
addBox(
19.5,
0.42,
9.15,
0.45,
-8.18,
0.12,
0x33484d,
{ roughness: 0.96 }
);
// Neutral bedrock substrate below the archaeological site.
// It is intentionally not colored like the labeled geological sequence.
addBox(
7.25,
6.4,
8.0,
-4.45,
-4.8,
0,
0x6c7777,
{ roughness: 1 }
);
// ------------------------------------------------------------
// Archaeological site: a 0.5 m grid surrounding a shallow trench.
// ------------------------------------------------------------
const archaeologicalItems = [];
const grassItems = [];
const floorItems = [];
const artifactItems = [];
const pitMinX = -7;
const pitMaxX = -2.5;
const pitMinZ = -2.5;
const pitMaxZ = 2.5;
const cell = 0.5;
const siteMinX = -8;
const siteMaxX = -1;
const siteMinZ = -4;
const siteMaxZ = 4;
const columns = Math.round((siteMaxX - siteMinX) / cell);
const rows = Math.round((siteMaxZ - siteMinZ) / cell);
const layerColors = {
turf: 0x687653,
topsoil: 0x4b4032,
subsoil: 0x9a704a,
occupation: 0x403934,
natural: 0xb39a73
};
function pushLayer(items, x, z, y, height, color, salt) {
const variation = 0.91 + hash(x, z, salt) * 0.17;
items.push({
x,
y,
z,
sx: cell - 0.018,
sy: height,
sz: cell - 0.018,
color: variedColor(color, variation)
});
}
for (let ix = 0; ix < columns; ix++) {
for (let iz = 0; iz < rows; iz++) {
const x = siteMinX + (ix + 0.5) * cell;
const z = siteMinZ + (iz + 0.5) * cell;
const insidePit =
x > pitMinX &&
x < pitMaxX &&
z > pitMinZ &&
z < pitMaxZ;
if (insidePit) {
floorItems.push({
x,
y: -1.565,
z,
sx: cell - 0.02,
sy: 0.07,
sz: cell - 0.02,
color: variedColor(
0x80674e,
0.91 + hash(x, z, 6) * 0.18
)
});
continue;
}
pushLayer(
archaeologicalItems,
x,
z,
-0.04,
0.08,
layerColors.turf,
1
);
pushLayer(
archaeologicalItems,
x,
z,
-0.18,
0.20,
layerColors.topsoil,
2
);
pushLayer(
archaeologicalItems,
x,
z,
-0.58,
0.60,
layerColors.subsoil,
3
);
pushLayer(
archaeologicalItems,
x,
z,
-0.98,
0.20,
layerColors.occupation,
4
);
pushLayer(
archaeologicalItems,
x,
z,
-1.34,
0.52,
layerColors.natural,
5
);
// Sparse blocky turf caps, kept away from the closest cut face.
if (
hash(x, z, 12) > 0.72 &&
z < siteMaxZ - 0.8
) {
grassItems.push({
x: x + (hash(x, z, 13) - 0.5) * 0.12,
y: 0.025,
z: z + (hash(x, z, 14) - 0.5) * 0.12,
sx: 0.12 + hash(x, z, 15) * 0.13,
sy: 0.07,
sz: 0.10 + hash(x, z, 16) * 0.13,
color: variedColor(
0x738456,
0.86 + hash(x, z, 17) * 0.22
)
});
}
}
}
addInstances(archaeologicalItems, "Archaeological stratigraphy");
addInstances(grassItems, "Surface vegetation");
addInstances(floorItems, "Trench floor");
// Shallow grave cut and block-built bone arrangement.
addBox(
1.10,
0.045,
1.85,
-5.42,
-1.505,
0.20,
0x3b3029
);
function bone(x, z, sx, sz) {
artifactItems.push({
x,
y: -1.385,
z,
sx,
sy: 0.12,
sz,
color: 0xe8dfc7
});
}
bone(-5.42, 0.91, 0.30, 0.27);
bone(-5.42, 0.58, 0.13, 0.22);
bone(-5.42, 0.36, 0.13, 0.22);
bone(-5.42, 0.14, 0.13, 0.22);
bone(-5.42, -0.08, 0.13, 0.22);
bone(-5.42, -0.30, 0.13, 0.22);
bone(-5.69, 0.34, 0.13, 0.54);
bone(-5.15, 0.34, 0.13, 0.54);
bone(-5.66, -0.53, 0.13, 0.57);
bone(-5.18, -0.53, 0.13, 0.57);
// Compact hearth: a dark square with red-orange voxel coals.
addBox(
0.92,
0.07,
0.92,
-6.15,
-1.49,
-1.25,
0x302924
);
const hearthColors = [0x4a2921, 0x9d3f24, 0xd76d2d, 0xe5a044];
for (let hx = 0; hx < 3; hx++) {
for (let hz = 0; hz < 3; hz++) {
if (hx === 1 && hz === 1) continue;
artifactItems.push({
x: -6.15 + (hx - 1) * 0.22,
y: -1.39,
z: -1.25 + (hz - 1) * 0.22,
sx: 0.17,
sy: 0.14,
sz: 0.17,
color: hearthColors[
Math.floor(hash(hx, hz, 20) * hearthColors.length)
]
});
}
}
// A few ceramic and stone artefacts on the trench floor.
const artifactPositions = [
[-4.75, -1.48],
[-4.45, 0.82],
[-3.48, -0.55],
[-6.52, 1.38],
[-3.15, 1.72]
];
artifactPositions.forEach(([x, z], index) => {
artifactItems.push({
x,
y: -1.39,
z,
sx: 0.15 + hash(x, z, 25) * 0.10,
sy: 0.10,
sz: 0.12 + hash(x, z, 26) * 0.10,
color: index % 3 === 0 ? 0x746d61 : 0xc56f3c
});
});
// Small dark post-hole marks around the occupation area.
for (const [x, z] of [
[-6.73, -1.85],
[-5.55, -1.90],
[-6.73, -0.65],
[-5.55, -0.65]
]) {
artifactItems.push({
x,
y: -1.50,
z,
sx: 0.18,
sy: 0.05,
sz: 0.18,
color: 0x332b25
});
}
addInstances(artifactItems, "Archaeological features and artefacts");
// Survey/ranging pole inside the trench corner.
const poleX = -7.15;
const poleZ = 2.34;
for (let i = 0; i < 10; i++) {
addBox(
0.09,
0.20,
0.09,
poleX,
-1.50 + i * 0.20,
poleZ,
i % 2 === 0 ? 0xe38b36 : 0xf0ead7
);
}
// ------------------------------------------------------------
// Geological outcrop: a much deeper voxel sequence.
// ------------------------------------------------------------
const geologyItems = [];
const inclusionItems = [];
const geoStartX = 0.4;
const geoStartZ = -4.0;
const geoCell = 0.55;
const geoColumns = 16;
const geoRows = 15;
const geoBase = -8.0;
const geoRowHeight = 0.30;
// Unequal band thicknesses deliberately avoid reading like a
// proportional or equal-duration time ruler.
const boundaries = [0, 3, 5, 8, 10, 14, 16, 19, 21, 25, 27, 30, 33];
const geologyColors = [
0x465861,
0x68564c,
0xc18454,
0x708792,
0xd5c48f,
0xa86750,
0x788a82,
0xc4a071,
0x526970,
0x9b5f4d,
0x8ca1a2,
0xd7c8a5
];
const fissures = [
{ column: 4, start: 8, end: 14 },
{ column: 10, start: 17, end: 23 },
{ column: 13, start: 5, end: 10 }
];
function geologyBand(row) {
for (let band = 0; band < geologyColors.length; band++) {
if (row < boundaries[band + 1]) return band;
}
return geologyColors.length - 1;
}
for (let ix = 0; ix < geoColumns; ix++) {
for (let iz = 0; iz < geoRows; iz++) {
const x = geoStartX + (ix + 0.5) * geoCell;
const z = geoStartZ + (iz + 0.5) * geoCell;
const relief =
Math.floor(
hash(ix, iz, 30) * 4 +
hash(ix, iz, 31) * 3 +
Math.sin(ix * 0.8 + iz * 0.45) * 0.65
);
const height = THREE.MathUtils.clamp(27 + relief, 26, 33);
for (let row = 0; row < height; row++) {
const isFront = iz === geoRows - 1;
const inFissure = fissures.some(
(fissure) =>
fissure.column === ix &&
row >= fissure.start &&
row < fissure.end
);
if (isFront && inFissure) continue;
const band = geologyBand(row);
const variation =
0.89 + hash(ix + row, iz, 32) * 0.20;
geologyItems.push({
x,
y: geoBase + (row + 0.5) * geoRowHeight,
z,
sx: geoCell - 0.024,
sy: geoRowHeight - 0.018,
sz: geoCell - 0.024,
color: variedColor(geologyColors[band], variation)
});
}
// Small mineral or fossil-like inclusions exposed on the face.
if (
iz === geoRows - 1 &&
hash(ix, iz, 33) > 0.62
) {
const row = 3 + Math.floor(hash(ix, iz, 34) * 25);
inclusionItems.push({
x: x + (hash(ix, iz, 35) - 0.5) * 0.18,
y: geoBase + (row + 0.5) * geoRowHeight,
z: geoStartZ + geoRows * geoCell + 0.015,
sx: 0.08 + hash(ix, iz, 36) * 0.12,
sy: 0.07 + hash(ix, iz, 37) * 0.08,
sz: 0.045,
color: hash(ix, iz, 38) > 0.5
? 0xefd79b
: 0x45545a
});
}
}
}
addInstances(geologyItems, "Deep geological strata");
addInstances(inclusionItems, "Geological inclusions");
// ------------------------------------------------------------
// DOM callouts projected directly from Three.js world points.
// ------------------------------------------------------------
const svg = document.getElementById("leaders");
const svgNS = "http://www.w3.org/2000/svg";
const labelSpecs = [
{
id: "archTag",
point: new THREE.Vector3(-5.0, 1.15, -3.4),
dx: 0,
dy: -16,
color: "amber"
},
{
id: "geoTag",
point: new THREE.Vector3(4.9, 2.65, -3.5),
dx: 15,
dy: -20,
color: "teal"
},
{
id: "burialTag",
point: new THREE.Vector3(-5.42, -1.28, 0.20),
dx: 98,
dy: -18,
color: "amber",
minor: true
},
{
id: "hearthTag",
point: new THREE.Vector3(-6.15, -1.28, -1.25),
dx: -78,
dy: 8,
color: "amber",
minor: true
},
{
id: "occupationTag",
point: new THREE.Vector3(-2.52, -0.96, 1.45),
dx: 92,
dy: 37,
color: "amber",
minor: true
},
{
id: "depthTag",
point: new THREE.Vector3(poleX, -0.55, poleZ),
dx: -30,
dy: -6,
color: "amber",
minor: true
}
];
labelSpecs.forEach((spec) => {
spec.element = document.getElementById(spec.id);
spec.line = document.createElementNS(svgNS, "line");
spec.line.setAttribute("class", `leader ${spec.color}`);
svg.appendChild(spec.line);
spec.dot = document.createElementNS(svgNS, "circle");
spec.dot.setAttribute("r", "3.5");
spec.dot.setAttribute("class", `anchor ${spec.color}`);
svg.appendChild(spec.dot);
});
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
const bottomReserve = legend.offsetHeight + 38;
const narrow = width < 650;
labelSpecs.forEach((spec) => {
const projected = spec.point.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
!(narrow && spec.minor);
if (!visible) {
spec.element.style.opacity = "0";
spec.line.style.opacity = "0";
spec.dot.style.opacity = "0";
return;
}
const sx = (projected.x * 0.5 + 0.5) * width;
const sy = (-projected.y * 0.5 + 0.5) * height;
const lx = THREE.MathUtils.clamp(
sx + spec.dx,
95,
width - 95
);
const ly = THREE.MathUtils.clamp(
sy + spec.dy,
95,
height - bottomReserve
);
spec.element.style.left = `${lx}px`;
spec.element.style.top = `${ly}px`;
spec.element.style.opacity = "1";
spec.line.setAttribute("x1", sx);
spec.line.setAttribute("y1", sy);
spec.line.setAttribute("x2", lx);
spec.line.setAttribute("y2", ly);
spec.line.style.opacity = "1";
spec.dot.setAttribute("cx", sx);
spec.dot.setAttribute("cy", sy);
spec.dot.style.opacity = "1";
});
}
// ------------------------------------------------------------
// Camera controls implemented directly, without add-ons.
// ------------------------------------------------------------
const pointers = new Map();
let lastPinchDistance = 0;
function pinchDistance() {
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) {
lastPinchDistance = pinchDistance();
}
});
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;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size === 1) {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
1.28
);
} else if (pointers.size >= 2) {
const distance = pinchDistance();
if (distance > 0 && lastPinchDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (lastPinchDistance / distance),
14,
52
);
}
lastPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = pointers.size >= 2 ? pinchDistance() : 0;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
14,
52
);
},
{ passive: false }
);
function resetCamera() {
cameraState.theta = 0.64;
cameraState.phi = 0.86;
cameraState.radius = baseRadius();
}
resetButton.addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
if (event.key === "ArrowLeft") {
cameraState.theta -= 0.08;
}
if (event.key === "ArrowRight") {
cameraState.theta += 0.08;
}
if (event.key === "ArrowUp") {
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - 0.05,
0.48,
1.28
);
}
if (event.key === "ArrowDown") {
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + 0.05,
0.48,
1.28
);
}
});
function applyCamera() {
const { target, theta, phi, radius } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = width / height;
camera.fov = width < 600 ? 46 : 38;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
function animate() {
applyCamera();
renderer.render(scene, camera);
updateLabels();
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
});
</script>
</body>
</html>
```