Prompt specification
Build or customize the Three.js 3D scene "Cross-cutting rock layer 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: Cross-cutting rock layer specimen
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cross-cutting-rock-layer-specimen-x1169
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Build three horizontal strata crossed by a narrow vertical intrusion; expose the intersections clearly so relative sequence can be inferred without assigning absolute ages.
Working Three.js Starter (cross-cutting-rock-layer-specimen-x1169):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cross-Cutting Relationship — Low-Poly Strata</title>
<style>
:root {
color-scheme: dark;
--ink: #eef4f1;
--muted: #aab9b5;
--panel: rgba(15, 25, 30, 0.86);
--line: rgba(220, 237, 230, 0.14);
--accent: #f36b4d;
--marker: #ffe39a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 38%, #263b42 0, #16242b 38%, #0c151a 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene,
#scene canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene canvas {
display: block;
touch-action: none;
cursor: grab;
}
#scene canvas.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
background:
linear-gradient(180deg, rgba(4, 10, 13, 0.2), transparent 25%, transparent 72%, rgba(4, 9, 12, 0.5)),
radial-gradient(circle at center, transparent 48%, rgba(3, 8, 10, 0.35));
}
.masthead {
position: fixed;
z-index: 4;
top: 28px;
left: 30px;
width: min(470px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
margin: 0 0 9px;
color: #9ec1b9;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 450px;
font-size: clamp(30px, 4vw, 54px);
font-weight: 680;
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
margin: 15px 0 0;
max-width: 405px;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.panel {
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 16px 55px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.sequence-panel {
position: fixed;
z-index: 4;
left: 30px;
bottom: 28px;
width: 310px;
padding: 18px;
border-radius: 16px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.panel-heading h2 {
margin: 0;
font-size: 13px;
font-weight: 750;
letter-spacing: 0.04em;
}
.relative-badge {
padding: 4px 7px;
border: 1px solid rgba(158, 193, 185, 0.28);
border-radius: 999px;
color: #b9d2cb;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.sequence-list {
display: grid;
gap: 7px;
margin: 0;
padding: 0;
list-style: none;
}
.sequence-list li {
display: grid;
grid-template-columns: 30px 1fr;
align-items: center;
min-height: 31px;
color: #dce7e3;
font-size: 12px;
}
.sequence-list .number {
color: #80938e;
font-variant-numeric: tabular-nums;
font-size: 10px;
font-weight: 750;
}
.swatch {
display: inline-block;
width: 9px;
height: 9px;
margin-right: 9px;
border-radius: 2px;
vertical-align: 0;
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.swatch.lower { background: #5c8580; }
.swatch.middle { background: #bd8b59; }
.swatch.upper { background: #93647a; }
.swatch.intrusion { background: #f36b4d; }
.sequence-list .intrusion-row {
margin-top: 4px;
padding-top: 9px;
border-top: 1px solid var(--line);
color: #ffd0c5;
}
.inference {
margin: 14px 0 0;
padding-top: 13px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.inference strong {
color: #e8f0ed;
font-weight: 650;
}
.no-absolute {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
color: #8fa19c;
font-size: 10px;
}
.no-absolute::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--marker);
box-shadow: 0 0 12px rgba(255, 227, 154, 0.45);
}
.controls {
position: fixed;
z-index: 4;
top: 28px;
right: 30px;
width: 232px;
padding: 14px;
border-radius: 15px;
}
.control-label {
margin: 0 0 8px;
color: #8fa29d;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.button-row {
display: flex;
gap: 7px;
margin-bottom: 11px;
}
.control-button {
flex: 1;
min-height: 34px;
padding: 7px 9px;
border: 1px solid rgba(225, 239, 233, 0.14);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
color: #b9c8c4;
cursor: pointer;
font-size: 11px;
font-weight: 650;
transition: 160ms ease;
}
.control-button:hover {
border-color: rgba(225, 239, 233, 0.3);
background: rgba(255, 255, 255, 0.08);
color: white;
}
.control-button.active,
.control-button[aria-pressed="true"] {
border-color: rgba(243, 107, 77, 0.7);
background: rgba(243, 107, 77, 0.16);
color: #ffe2da;
}
.control-button:focus-visible {
outline: 2px solid #a8d3c8;
outline-offset: 2px;
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 7px 1px;
color: #aebdb9;
font-size: 11px;
}
.control-hint {
margin: 10px 1px 0;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #718681;
font-size: 9px;
line-height: 1.5;
}
#annotation-layer,
#leader-lines {
position: fixed;
inset: 0;
z-index: 2;
width: 100%;
height: 100%;
pointer-events: none;
}
#leader-lines {
overflow: visible;
}
#leader-lines line {
stroke: rgba(218, 236, 229, 0.55);
stroke-width: 1;
vector-effect: non-scaling-stroke;
}
#leader-lines circle {
fill: #eaf5ef;
stroke: rgba(10, 18, 22, 0.8);
stroke-width: 1.5;
vector-effect: non-scaling-stroke;
}
.scene-label {
position: absolute;
width: max-content;
max-width: 185px;
padding: 8px 10px;
border: 1px solid rgba(225, 239, 233, 0.18);
border-radius: 8px;
background: rgba(12, 21, 26, 0.82);
box-shadow: 0 7px 24px rgba(0, 0, 0, 0.2);
color: #e8f0ed;
font-size: 10px;
line-height: 1.25;
transform: translateY(-50%);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
.scene-label.left {
transform: translate(-100%, -50%);
}
.scene-label strong {
display: block;
font-size: 11px;
font-weight: 680;
}
.scene-label small {
display: block;
margin-top: 3px;
color: #91a49f;
font-size: 9px;
}
.scene-label.intrusion {
border-color: rgba(243, 107, 77, 0.4);
}
.scene-label.contact {
border-color: rgba(255, 227, 154, 0.35);
}
.scene-label .mini-swatch {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 5px;
border-radius: 50%;
background: var(--label-color);
box-shadow: 0 0 9px color-mix(in srgb, var(--label-color), transparent 45%);
}
.view-hint {
position: fixed;
z-index: 4;
right: 30px;
bottom: 28px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(11, 20, 24, 0.62);
color: #9cafaa;
font-size: 10px;
pointer-events: none;
}
@media (max-width: 760px) {
.masthead {
top: 17px;
left: 17px;
width: calc(100vw - 34px);
}
h1 {
max-width: 320px;
font-size: 33px;
}
.subtitle {
display: none;
}
.controls {
top: 103px;
right: 14px;
width: 185px;
padding: 11px;
}
.sequence-panel {
left: 14px;
bottom: 14px;
width: 235px;
padding: 13px;
}
.sequence-list li {
font-size: 10px;
}
.inference {
font-size: 9px;
}
.view-hint {
display: none;
}
.scene-label {
max-width: 125px;
padding: 6px 7px;
font-size: 8px;
}
.scene-label strong {
font-size: 9px;
}
.scene-label small {
display: none;
}
}
@media (max-width: 470px) {
.sequence-panel {
width: 205px;
}
.controls {
width: 165px;
}
.control-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<header class="masthead">
<p class="eyebrow">Geological relationships / interactive block</p>
<h1>A narrow intrusion cuts the stack.</h1>
<p class="subtitle">
Three horizontal strata are crossed by one vertical intrusion.
Use the exposed front face to read the cross-cutting relationship.
</p>
</header>
<section class="panel sequence-panel" aria-labelledby="sequence-title">
<div class="panel-heading">
<h2 id="sequence-title">Relative sequence</h2>
<span class="relative-badge">No absolute ages</span>
</div>
<ol class="sequence-list">
<li>
<span class="number">01</span>
<span><i class="swatch lower"></i>Lower stratum</span>
</li>
<li>
<span class="number">02</span>
<span><i class="swatch middle"></i>Middle stratum</span>
</li>
<li>
<span class="number">03</span>
<span><i class="swatch upper"></i>Upper stratum</span>
</li>
<li class="intrusion-row">
<span class="number">04</span>
<span><i class="swatch intrusion"></i>Vertical intrusion</span>
</li>
</ol>
<p class="inference">
<strong>Stacking order:</strong> lower → middle → upper.<br>
<strong>Cross-cutting order:</strong> the intrusion is later in the
relative sequence than all three strata.
</p>
<div class="no-absolute">Only relationships are shown; no dates are assigned.</div>
</section>
<aside class="panel controls" aria-label="Scene controls">
<p class="control-label">Camera</p>
<div class="button-row">
<button class="control-button active" type="button" data-view="perspective">
Perspective
</button>
<button class="control-button" type="button" data-view="section">
Front section
</button>
</div>
<p class="control-label">Annotations</p>
<div class="toggle-row">
<span>Scene labels</span>
<button
class="control-button"
type="button"
id="labels-toggle"
aria-pressed="true"
>On</button>
</div>
<div class="toggle-row">
<span>Contact markers</span>
<button
class="control-button"
type="button"
id="markers-toggle"
aria-pressed="true"
>On</button>
</div>
<div class="button-row" style="margin-top: 10px; margin-bottom: 0;">
<button class="control-button" type="button" id="reset-view">Reset view</button>
</div>
<p class="control-hint">
Drag to orbit. Scroll or pinch to zoom. The front-section view is best
for inspecting where the intrusion interrupts the horizontal contacts.
</p>
</aside>
<div id="annotation-layer">
<svg id="leader-lines" aria-hidden="true"></svg>
</div>
<div class="view-hint">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and lighting
// -------------------------------------------------------------------------
const host = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly geological block with three strata and a vertical intrusion"
);
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x101a20, 18, 34);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xcfe9ef, 0x34251f, 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe4c7, 3.2);
keyLight.position.set(7, 11, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x8bb8d0, 1.15);
fillLight.position.set(-9, 5, -7);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x142127,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.93;
ground.receiveShadow = true;
scene.add(ground);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(8.5, 9.1, 0.5, 10),
new THREE.MeshStandardMaterial({
color: 0x22343a,
roughness: 0.96,
flatShading: true
})
);
pedestal.position.y = -2.65;
pedestal.receiveShadow = true;
pedestal.castShadow = true;
scene.add(pedestal);
// -------------------------------------------------------------------------
// Low-poly faceted geometry helpers
// -------------------------------------------------------------------------
function stableRandom(value) {
const x = Math.sin(value * 12.9898 + 78.233) * 43758.5453;
return x - Math.floor(x);
}
function makeFacetedBox(width, height, depth, baseColor) {
const geometry = new THREE.BoxGeometry(
width,
height,
depth,
4,
1,
2
).toNonIndexed();
const positions = geometry.attributes.position;
const colors = [];
const base = new THREE.Color(baseColor);
for (let i = 0; i < positions.count; i += 3) {
const variation = (stableRandom(i + 1) - 0.5) * 0.16;
const color = base.clone().offsetHSL(
(stableRandom(i + 9) - 0.5) * 0.018,
0,
variation
);
for (let j = 0; j < 3; j++) {
colors.push(color.r, color.g, color.b);
}
}
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
return geometry;
}
// -------------------------------------------------------------------------
// Three horizontal strata
// -------------------------------------------------------------------------
const blockWidth = 10;
const blockDepth = 5.4;
const blockBottom = -2.4;
const layerHeight = 1.6;
const layers = [
{
name: "Lower stratum",
code: "Stratum 01",
color: 0x5c8580,
css: "#5c8580",
centerY: -1.6
},
{
name: "Middle stratum",
code: "Stratum 02",
color: 0xbd8b59,
css: "#bd8b59",
centerY: 0
},
{
name: "Upper stratum",
code: "Stratum 03",
color: 0x93647a,
css: "#93647a",
centerY: 1.6
}
];
const strataGroup = new THREE.Group();
scene.add(strataGroup);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x182126,
transparent: true,
opacity: 0.58
});
layers.forEach((layer, index) => {
const geometry = makeFacetedBox(
blockWidth,
layerHeight,
blockDepth,
layer.color
);
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.94,
metalness: 0,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = layer.centerY;
mesh.castShadow = true;
mesh.receiveShadow = true;
strataGroup.add(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 24),
edgeMaterial
);
edges.position.copy(mesh.position);
edges.renderOrder = 2;
strataGroup.add(edges);
// A subtle upper lip makes each slab read as a distinct lithologic unit.
if (index < layers.length - 1) {
const lip = new THREE.Mesh(
new THREE.BoxGeometry(blockWidth - 0.08, 0.055, blockDepth - 0.06),
new THREE.MeshStandardMaterial({
color: new THREE.Color(layer.color).offsetHSL(0, 0, 0.08),
roughness: 1,
flatShading: true
})
);
lip.position.set(
0,
layer.centerY + layerHeight / 2 + 0.027,
0
);
lip.castShadow = true;
lip.receiveShadow = true;
strataGroup.add(lip);
}
});
// -------------------------------------------------------------------------
// Narrow, faceted vertical intrusion
// -------------------------------------------------------------------------
const intrusionGroup = new THREE.Group();
scene.add(intrusionGroup);
const intrusionColor = 0xf36b4d;
const frontZ = 2.79;
const backZ = -2.79;
// The changing width and offsets give the intrusion a low-poly,
// slightly irregular geometry while preserving its vertical trend.
const dikeLevels = [
{ y: -2.55, left: 0.27, right: 0.92 },
{ y: -0.80, left: 0.21, right: 0.98 },
{ y: 0.80, left: 0.28, right: 0.91 },
{ y: 2.40, left: 0.22, right: 0.95 },
{ y: 3.05, left: 0.31, right: 0.80 }
];
const dikePositions = [];
const dikeColors = [];
const baseDikeColor = new THREE.Color(intrusionColor);
function addDikeTriangle(a, b, c, lightDelta = 0) {
const color = baseDikeColor.clone().offsetHSL(0, 0, lightDelta);
for (const point of [a, b, c]) {
dikePositions.push(point.x, point.y, point.z);
dikeColors.push(color.r, color.g, color.b);
}
}
for (let i = 0; i < dikeLevels.length - 1; i++) {
const lower = dikeLevels[i];
const upper = dikeLevels[i + 1];
const lf = new THREE.Vector3(lower.left, lower.y, frontZ);
const rf = new THREE.Vector3(lower.right, lower.y, frontZ);
const lfu = new THREE.Vector3(upper.left, upper.y, frontZ);
const rfu = new THREE.Vector3(upper.right, upper.y, frontZ);
const lb = new THREE.Vector3(lower.left, lower.y, backZ);
const rb = new THREE.Vector3(lower.right, lower.y, backZ);
const lbu = new THREE.Vector3(upper.left, upper.y, backZ);
const rbu = new THREE.Vector3(upper.right, upper.y, backZ);
// Front face: deliberately faceted.
addDikeTriangle(lf, rf, lfu, 0.015);
addDikeTriangle(rf, rfu, lfu, -0.035);
// Back face.
addDikeTriangle(lb, lbu, rb, -0.07);
addDikeTriangle(rb, lbu, rbu, -0.09);
// Left side.
addDikeTriangle(lf, lbu, lb, -0.08);
addDikeTriangle(lf, lfu, lbu, -0.055);
// Right side.
addDikeTriangle(rf, rb, rbu, -0.09);
addDikeTriangle(rf, rbu, rfu, -0.06);
}
const bottom = dikeLevels[0];
const top = dikeLevels[dikeLevels.length - 1];
// Bottom and top caps.
addDikeTriangle(
new THREE.Vector3(bottom.left, bottom.y, frontZ),
new THREE.Vector3(bottom.right, bottom.y, backZ),
new THREE.Vector3(bottom.left, bottom.y, backZ),
-0.05
);
addDikeTriangle(
new THREE.Vector3(bottom.left, bottom.y, frontZ),
new THREE.Vector3(bottom.right, bottom.y, frontZ),
new THREE.Vector3(bottom.right, bottom.y, backZ),
-0.05
);
addDikeTriangle(
new THREE.Vector3(top.left, top.y, frontZ),
new THREE.Vector3(top.left, top.y, backZ),
new THREE.Vector3(top.right, top.y, backZ),
0.04
);
addDikeTriangle(
new THREE.Vector3(top.left, top.y, frontZ),
new THREE.Vector3(top.right, top.y, backZ),
new THREE.Vector3(top.right, top.y, frontZ),
0.04
);
const dikeGeometry = new THREE.BufferGeometry();
dikeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(dikePositions, 3)
);
dikeGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(dikeColors, 3)
);
dikeGeometry.computeVertexNormals();
const dikeMesh = new THREE.Mesh(
dikeGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.78,
metalness: 0.02,
flatShading: true,
side: THREE.DoubleSide,
emissive: 0x3a0904,
emissiveIntensity: 0.18
})
);
dikeMesh.castShadow = true;
dikeMesh.receiveShadow = true;
intrusionGroup.add(dikeMesh);
// Crisp front outline makes the intrusion legible against all strata.
const outlinePoints = [];
for (let i = 0; i < dikeLevels.length - 1; i++) {
const a = dikeLevels[i];
const b = dikeLevels[i + 1];
outlinePoints.push(
new THREE.Vector3(a.left, a.y, frontZ + 0.012),
new THREE.Vector3(b.left, b.y, frontZ + 0.012),
new THREE.Vector3(a.right, a.y, frontZ + 0.012),
new THREE.Vector3(b.right, b.y, frontZ + 0.012)
);
}
outlinePoints.push(
new THREE.Vector3(top.left, top.y, frontZ + 0.012),
new THREE.Vector3(top.right, top.y, frontZ + 0.012),
new THREE.Vector3(top.left, top.y, frontZ + 0.012),
new THREE.Vector3(top.right, top.y, backZ),
new THREE.Vector3(top.right, top.y, frontZ + 0.012),
new THREE.Vector3(top.left, top.y, backZ)
);
const dikeOutline = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(outlinePoints),
new THREE.LineBasicMaterial({
color: 0x57251f,
transparent: true,
opacity: 0.9
})
);
intrusionGroup.add(dikeOutline);
// -------------------------------------------------------------------------
// Exposed horizontal contacts and intersection markers
// -------------------------------------------------------------------------
const contactGroup = new THREE.Group();
scene.add(contactGroup);
function dikeEdgesAt(y) {
for (let i = 0; i < dikeLevels.length - 1; i++) {
const a = dikeLevels[i];
const b = dikeLevels[i + 1];
if (y >= a.y && y <= b.y) {
const t = (y - a.y) / (b.y - a.y);
return {
left: THREE.MathUtils.lerp(a.left, b.left, t),
right: THREE.MathUtils.lerp(a.right, b.right, t)
};
}
}
return { left: dikeLevels[0].left, right: dikeLevels[0].right };
}
const contactMaterial = new THREE.LineBasicMaterial({
color: 0x211b1a,
transparent: true,
opacity: 0.86
});
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0xffe39a,
depthTest: true
});
const markerGeometry = new THREE.TorusGeometry(
0.115,
0.024,
4,
10
);
for (const y of [-0.8, 0.8]) {
const edges = dikeEdgesAt(y);
const leftContact = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-blockWidth / 2, y, 2.718),
new THREE.Vector3(edges.left, y, 2.718)
]),
contactMaterial
);
const rightContact = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(edges.right, y, 2.718),
new THREE.Vector3(blockWidth / 2, y, 2.718)
]),
contactMaterial
);
contactGroup.add(leftContact, rightContact);
for (const x of [edges.left, edges.right]) {
const marker = new THREE.Mesh(markerGeometry, markerMaterial);
marker.position.set(x, y, 2.825);
marker.renderOrder = 4;
contactGroup.add(marker);
}
}
// -------------------------------------------------------------------------
// A few low-poly peripheral rocks for scale and visual balance
// -------------------------------------------------------------------------
const rockGeometry = new THREE.IcosahedronGeometry(0.5, 0);
const rockColors = [0x385356, 0x4d5d59, 0x67564a, 0x32474c];
for (let i = 0; i < 13; i++) {
const angle = (i / 13) * Math.PI * 2 + stableRandom(i + 40) * 0.25;
const radius = 6.2 + stableRandom(i + 80) * 1.2;
const scale = 0.22 + stableRandom(i + 120) * 0.45;
const rock = new THREE.Mesh(
rockGeometry,
new THREE.MeshStandardMaterial({
color: rockColors[i % rockColors.length],
roughness: 1,
flatShading: true
})
);
rock.position.set(
Math.cos(angle) * radius,
-2.34 + scale * 0.28,
Math.sin(angle) * radius * 0.72
);
rock.scale.set(
scale * (0.8 + stableRandom(i + 160) * 0.5),
scale * (0.55 + stableRandom(i + 180) * 0.45),
scale * (0.75 + stableRandom(i + 200) * 0.55)
);
rock.rotation.set(
stableRandom(i + 210) * Math.PI,
stableRandom(i + 220) * Math.PI,
stableRandom(i + 230) * Math.PI
);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
// -------------------------------------------------------------------------
// Screen-space annotations
// -------------------------------------------------------------------------
const annotationLayer = document.querySelector("#annotation-layer");
const leaderSVG = document.querySelector("#leader-lines");
const annotations = [];
function addAnnotation({
html,
anchor,
dx,
dy,
side = "right",
color = "#eaf5ef"
}) {
const element = document.createElement("div");
element.className = `scene-label ${side}`;
element.style.setProperty("--label-color", color);
element.innerHTML = html;
annotationLayer.appendChild(element);
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
const circle = document.createElementNS(
"http://www.w3.org/2000/svg",
"circle"
);
circle.setAttribute("r", "3.2");
circle.setAttribute("fill", color);
leaderSVG.appendChild(line);
leaderSVG.appendChild(circle);
annotations.push({
element,
line,
circle,
anchor,
dx,
dy,
side
});
}
addAnnotation({
html: `
<span class="mini-swatch"></span>
<strong>Lower stratum</strong>
<small>Lowest unit in the exposed stack</small>
`,
anchor: new THREE.Vector3(-4.85, -1.6, 2.73),
dx: -132,
dy: 0,
side: "left",
color: layers[0].css
});
addAnnotation({
html: `
<span class="mini-swatch"></span>
<strong>Middle stratum</strong>
<small>Between the two internal contacts</small>
`,
anchor: new THREE.Vector3(-4.85, 0, 2.73),
dx: -132,
dy: 0,
side: "left",
color: layers[1].css
});
addAnnotation({
html: `
<span class="mini-swatch"></span>
<strong>Upper stratum</strong>
<small>Topmost horizontal unit</small>
`,
anchor: new THREE.Vector3(-4.85, 1.6, 2.73),
dx: -132,
dy: 0,
side: "left",
color: layers[2].css
});
addAnnotation({
html: `
<span class="mini-swatch"></span>
<strong>Vertical intrusion</strong>
<small>Crosscuts all three strata</small>
`,
anchor: new THREE.Vector3(0.58, 2.75, frontZ),
dx: 126,
dy: -18,
side: "right",
color: "#f36b4d"
});
addAnnotation({
html: `
<span class="mini-swatch"></span>
<strong>Interrupted contact</strong>
<small>The horizontal boundary stops at the intrusion</small>
`,
anchor: new THREE.Vector3(0.9, 0.8, frontZ + 0.02),
dx: 138,
dy: 43,
side: "right",
color: "#ffe39a"
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, and pinch
// -------------------------------------------------------------------------
const initialRadius = window.innerWidth < 760 ? 22 : 14.2;
const currentView = {
theta: 0.58,
phi: 1.03,
radius: initialRadius,
target: new THREE.Vector3(0, 0.15, 0)
};
const desiredView = {
theta: currentView.theta,
phi: currentView.phi,
radius: currentView.radius,
target: currentView.target.clone()
};
const viewButtons = [...document.querySelectorAll("[data-view]")];
function setView(name) {
if (name === "section") {
desiredView.theta = 0;
desiredView.phi = Math.PI / 2;
desiredView.radius = window.innerWidth < 760 ? 21 : 11.4;
desiredView.target.set(0, 0.2, 0);
} else {
desiredView.theta = 0.58;
desiredView.phi = 1.03;
desiredView.radius = window.innerWidth < 760 ? 22 : 14.2;
desiredView.target.set(0, 0.15, 0);
}
viewButtons.forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
viewButtons.forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
document.querySelector("#reset-view").addEventListener("click", () => {
setView("perspective");
});
const canvas = renderer.domElement;
const pointers = new Map();
let previousPinchDistance = 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 });
canvas.classList.add("dragging");
if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
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) {
desiredView.theta -= dx * 0.006;
desiredView.phi = THREE.MathUtils.clamp(
desiredView.phi - dy * 0.005,
0.34,
1.52
);
viewButtons.forEach((button) => button.classList.remove("active"));
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius * (previousPinchDistance / distance),
7.2,
28
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) previousPinchDistance = 0;
if (pointers.size === 0) canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius * Math.exp(event.deltaY * 0.001),
7.2,
28
);
},
{ passive: false }
);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
// -------------------------------------------------------------------------
// Toggles
// -------------------------------------------------------------------------
const labelsToggle = document.querySelector("#labels-toggle");
const markersToggle = document.querySelector("#markers-toggle");
labelsToggle.addEventListener("click", () => {
const enabled = labelsToggle.getAttribute("aria-pressed") !== "true";
labelsToggle.setAttribute("aria-pressed", String(enabled));
labelsToggle.textContent = enabled ? "On" : "Off";
annotationLayer.style.display = enabled ? "block" : "none";
});
markersToggle.addEventListener("click", () => {
const enabled = markersToggle.getAttribute("aria-pressed") !== "true";
markersToggle.setAttribute("aria-pressed", String(enabled));
markersToggle.textContent = enabled ? "On" : "Off";
contactGroup.visible = enabled;
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width < 760 ? 48 : 38;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
const compactScale = width < 760 ? 0.72 : 1;
for (const annotation of annotations) {
projected.copy(annotation.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
annotationLayer.style.display !== "none";
annotation.element.style.visibility = visible ? "visible" : "hidden";
annotation.line.style.visibility = visible ? "visible" : "hidden";
annotation.circle.style.visibility = visible ? "visible" : "hidden";
if (!visible) continue;
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const labelX = anchorX + annotation.dx * compactScale;
const labelY = anchorY + annotation.dy * compactScale;
annotation.element.style.left = `${labelX}px`;
annotation.element.style.top = `${labelY}px`;
annotation.line.setAttribute("x1", anchorX);
annotation.line.setAttribute("y1", anchorY);
annotation.line.setAttribute("x2", labelX);
annotation.line.setAttribute("y2", labelY);
annotation.circle.setAttribute("cx", anchorX);
annotation.circle.setAttribute("cy", anchorY);
}
}
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const easing = 1 - Math.exp(-dt * 8);
currentView.theta +=
(desiredView.theta - currentView.theta) * easing;
currentView.phi +=
(desiredView.phi - currentView.phi) * easing;
currentView.radius +=
(desiredView.radius - currentView.radius) * easing;
currentView.target.lerp(desiredView.target, easing);
const { theta, phi, radius, target } = currentView;
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);
const pulse = 1 + Math.sin(clock.elapsedTime * 3.2) * 0.09;
contactGroup.children.forEach((child) => {
if (child.geometry?.type === "TorusGeometry") {
child.scale.setScalar(pulse);
}
});
updateAnnotations();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```