Prompt specification
Build or customize the Three.js 3D scene "Relative-age reasoning puzzle" 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: Relative-age reasoning puzzle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/relative-age-reasoning-puzzle-x1172
Scene Description Prompt:
Order deposition, tilting, erosion, and intrusion beside a voxel geological cutaway using visible evidence. Build one HTML file with Three.js from cdnjs.
Working Three.js Starter (relative-age-reasoning-puzzle-x1172):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Strata — Geological Relative Dating</title>
<style>
:root {
--bg: #071015;
--panel: #0d171d;
--panel-2: #111e25;
--line: rgba(202, 225, 218, 0.13);
--text: #edf4f0;
--muted: #91a6a4;
--stage: #e2c47c;
--accent: #e2c47c;
--magma: #ff6b2c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button {
color: inherit;
font: inherit;
}
.app {
width: 100vw;
height: 100vh;
display: grid;
grid-template-rows: 68px minmax(0, 1fr);
background:
radial-gradient(circle at 72% 36%, rgba(57, 91, 91, 0.18), transparent 34%),
var(--bg);
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(8, 16, 21, 0.88);
backdrop-filter: blur(18px);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
position: relative;
flex: 0 0 auto;
border: 1px solid rgba(226, 196, 124, 0.45);
border-radius: 7px;
overflow: hidden;
background: #111d22;
}
.brand-mark span {
position: absolute;
left: -4px;
width: 44px;
height: 6px;
transform: rotate(-9deg);
border-radius: 2px;
}
.brand-mark span:nth-child(1) { top: 4px; background: #d0a85e; }
.brand-mark span:nth-child(2) { top: 11px; background: #72928c; }
.brand-mark span:nth-child(3) { top: 18px; background: #bd6755; }
.brand-mark span:nth-child(4) { top: 25px; background: #ddd0a5; }
.brand-text {
display: flex;
align-items: baseline;
gap: 10px;
min-width: 0;
}
.brand-text strong {
font-size: 15px;
letter-spacing: 0.19em;
font-weight: 750;
white-space: nowrap;
}
.brand-text span {
color: var(--muted);
font-size: 12px;
letter-spacing: 0.04em;
white-space: nowrap;
}
.top-meta {
display: flex;
align-items: center;
gap: 9px;
}
.meta-chip {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
color: #b9cbc7;
background: rgba(255, 255, 255, 0.025);
font-size: 11px;
letter-spacing: 0.07em;
text-transform: uppercase;
white-space: nowrap;
}
.meta-chip::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: #79b69d;
box-shadow: 0 0 10px rgba(121, 182, 157, 0.65);
}
.workspace {
min-height: 0;
display: grid;
grid-template-columns: 342px minmax(0, 1fr);
}
.evidence-panel {
min-height: 0;
padding: 29px 24px 22px;
overflow-y: auto;
border-right: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(255, 255, 255, 0.018), transparent 30%),
var(--panel);
scrollbar-width: thin;
scrollbar-color: #304348 transparent;
}
.eyebrow {
margin: 0 0 10px;
color: var(--stage);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 280px;
font-size: clamp(27px, 2.5vw, 38px);
line-height: 1.03;
letter-spacing: -0.045em;
font-weight: 690;
}
.intro {
margin: 15px 0 25px;
color: var(--muted);
font-size: 13px;
line-height: 1.62;
}
.timeline-label {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 11px;
color: #718886;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.timeline-label span:last-child {
color: #a8b9b6;
letter-spacing: 0.08em;
}
.timeline {
position: relative;
display: grid;
gap: 9px;
margin: 0;
padding: 0;
list-style: none;
}
.timeline::before {
content: "";
position: absolute;
top: 24px;
bottom: 24px;
left: 18px;
width: 1px;
background: linear-gradient(var(--stage), rgba(145, 166, 164, 0.16));
opacity: 0.65;
}
.stage-card {
position: relative;
width: 100%;
display: grid;
grid-template-columns: 38px minmax(0, 1fr);
gap: 12px;
padding: 13px 13px 13px 0;
border: 1px solid transparent;
border-radius: 12px;
background: transparent;
text-align: left;
cursor: pointer;
transition:
border-color 180ms ease,
background 180ms ease,
transform 180ms ease;
}
.stage-card:hover {
background: rgba(255, 255, 255, 0.025);
transform: translateX(2px);
}
.stage-card.active {
border-color: color-mix(in srgb, var(--card-color) 45%, transparent);
background:
linear-gradient(
90deg,
color-mix(in srgb, var(--card-color) 10%, transparent),
rgba(255, 255, 255, 0.015)
);
}
.stage-number {
z-index: 1;
width: 37px;
height: 37px;
display: grid;
place-items: center;
border: 1px solid #33464a;
border-radius: 50%;
color: #a4b7b4;
background: #101b20;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.06em;
transition: 180ms ease;
}
.stage-card.active .stage-number {
color: #0b1316;
border-color: var(--card-color);
background: var(--card-color);
box-shadow: 0 0 20px color-mix(in srgb, var(--card-color) 22%, transparent);
}
.stage-card h2 {
display: flex;
align-items: center;
gap: 9px;
margin: 1px 0 6px;
font-size: 15px;
letter-spacing: -0.015em;
font-weight: 690;
}
.age-tag {
padding: 3px 6px;
border-radius: 4px;
color: var(--card-color);
background: color-mix(in srgb, var(--card-color) 10%, transparent);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.stage-card p {
margin: 0;
color: #829895;
font-size: 11.5px;
line-height: 1.48;
}
.stage-card.active p {
color: #b4c4c1;
}
.principle {
margin-top: 20px;
padding: 15px 16px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.022);
}
.principle-label {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--stage);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.principle-label::before {
content: "";
width: 13px;
height: 2px;
background: currentColor;
}
.principle p {
margin: 0;
color: #a7b8b5;
font-size: 11.5px;
line-height: 1.58;
}
.model-note {
margin: 16px 3px 0;
color: #647976;
font-size: 9.5px;
line-height: 1.5;
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
isolation: isolate;
background:
radial-gradient(circle at 50% 45%, rgba(59, 89, 88, 0.17), transparent 42%),
#081116;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
outline: none;
}
#scene.dragging {
cursor: grabbing;
}
.stage-readout {
position: absolute;
z-index: 4;
top: 24px;
left: 25px;
width: min(330px, calc(100% - 125px));
padding: 15px 17px 16px;
border: 1px solid rgba(205, 228, 220, 0.13);
border-left: 2px solid var(--stage);
border-radius: 4px 12px 12px 4px;
background: rgba(8, 17, 22, 0.72);
backdrop-filter: blur(15px);
box-shadow: 0 14px 42px rgba(0, 0, 0, 0.18);
pointer-events: none;
transition: border-color 200ms ease;
}
.readout-kicker {
margin-bottom: 7px;
color: var(--stage);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.stage-readout h3 {
margin: 0 0 7px;
font-size: 20px;
letter-spacing: -0.025em;
font-weight: 690;
}
.stage-readout p {
margin: 0;
color: #9cafac;
font-size: 11.5px;
line-height: 1.52;
}
.compass {
position: absolute;
z-index: 4;
top: 24px;
right: 25px;
width: 67px;
height: 67px;
display: grid;
place-items: center;
border: 1px solid rgba(205, 228, 220, 0.14);
border-radius: 50%;
background: rgba(8, 17, 22, 0.58);
backdrop-filter: blur(12px);
pointer-events: none;
}
.compass::before,
.compass::after {
content: "";
position: absolute;
background: rgba(205, 228, 220, 0.13);
}
.compass::before { width: 1px; height: 47px; }
.compass::after { width: 47px; height: 1px; }
.compass-needle {
position: absolute;
z-index: 1;
width: 2px;
height: 27px;
transform-origin: 50% 100%;
transition: transform 80ms linear;
}
.compass-needle::before {
content: "";
position: absolute;
left: -3px;
top: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 8px solid #d8e2dc;
}
.compass-needle::after {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 2px;
height: 18px;
background: #607572;
}
.compass b {
position: absolute;
z-index: 2;
top: 5px;
color: #dfe9e4;
font-size: 8px;
}
.legend {
position: absolute;
z-index: 4;
left: 25px;
bottom: 25px;
display: flex;
align-items: center;
gap: 16px;
padding: 9px 12px;
border: 1px solid rgba(205, 228, 220, 0.12);
border-radius: 9px;
color: #8ea19e;
background: rgba(8, 17, 22, 0.6);
backdrop-filter: blur(12px);
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.13);
}
.swatch.beds {
background: linear-gradient(135deg, #d8c183 0 34%, #72928c 34% 67%, #bd6755 67%);
}
.swatch.dike {
background: #ff6b2c;
box-shadow: 0 0 8px rgba(255, 107, 44, 0.55);
}
.view-controls {
position: absolute;
z-index: 5;
right: 25px;
bottom: 25px;
display: flex;
align-items: center;
gap: 8px;
}
.control-button {
min-height: 37px;
padding: 0 13px;
border: 1px solid rgba(205, 228, 220, 0.15);
border-radius: 9px;
color: #c2d0cc;
background: rgba(11, 22, 27, 0.78);
backdrop-filter: blur(12px);
cursor: pointer;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
transition: 150ms ease;
}
.control-button:hover {
border-color: rgba(205, 228, 220, 0.32);
color: #fff;
background: rgba(21, 37, 42, 0.9);
}
.control-button.primary {
color: #101719;
border-color: var(--stage);
background: var(--stage);
}
.control-button.primary:hover {
filter: brightness(1.08);
}
.orbit-hint {
position: absolute;
z-index: 3;
right: 25px;
bottom: 73px;
color: rgba(164, 184, 180, 0.62);
font-size: 9px;
letter-spacing: 0.06em;
pointer-events: none;
}
#leaders {
position: absolute;
z-index: 2;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
.leader-line {
stroke: rgba(190, 213, 205, 0.38);
stroke-width: 1;
stroke-dasharray: 3 4;
transition: stroke 180ms ease, opacity 180ms ease;
}
.leader-dot {
fill: #8fa5a1;
stroke: rgba(255, 255, 255, 0.36);
stroke-width: 1;
transition: fill 180ms ease, opacity 180ms ease;
}
.leader-line.active {
stroke-width: 1.3;
stroke-dasharray: none;
}
.leader-dot.active {
fill: var(--stage);
stroke: #fff;
stroke-width: 1.3;
}
.callout {
position: absolute;
z-index: 3;
display: flex;
align-items: center;
gap: 8px;
min-width: 112px;
padding: 7px 10px 7px 7px;
border: 1px solid rgba(205, 228, 220, 0.14);
border-radius: 8px;
color: #b8c8c4;
background: rgba(10, 20, 25, 0.78);
backdrop-filter: blur(10px);
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.16);
transform: translate(-50%, -50%);
cursor: pointer;
user-select: none;
transition:
border-color 180ms ease,
color 180ms ease,
background 180ms ease,
scale 180ms ease;
}
.callout:hover {
border-color: rgba(205, 228, 220, 0.32);
color: #fff;
}
.callout.active {
color: #fff;
border-color: var(--callout-color);
background: rgba(14, 27, 32, 0.92);
scale: 1.04;
}
.callout-number {
width: 23px;
height: 23px;
display: grid;
place-items: center;
border-radius: 6px;
color: #101719;
background: var(--callout-color);
font-size: 9px;
font-weight: 900;
}
.callout-text {
display: grid;
gap: 2px;
}
.callout-text strong {
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.callout-text small {
color: #758b87;
font-size: 8.5px;
}
@media (max-width: 1080px) {
.workspace {
grid-template-columns: 305px minmax(0, 1fr);
}
.evidence-panel {
padding-left: 18px;
padding-right: 18px;
}
.callout-text small {
display: none;
}
}
@media (max-width: 760px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100vh;
grid-template-rows: 62px auto;
}
.topbar {
padding: 0 14px;
}
.brand-text span,
.meta-chip:first-child {
display: none;
}
.workspace {
display: flex;
flex-direction: column;
}
.viewport {
order: 1;
height: 68vh;
min-height: 520px;
}
.evidence-panel {
order: 2;
overflow: visible;
border-right: 0;
border-top: 1px solid var(--line);
}
.stage-readout {
top: 15px;
left: 15px;
width: min(270px, calc(100% - 100px));
}
.compass {
top: 15px;
right: 15px;
width: 58px;
height: 58px;
}
.legend {
display: none;
}
.view-controls {
right: 15px;
bottom: 15px;
}
.orbit-hint {
display: none;
}
.callout {
min-width: 0;
padding-right: 8px;
}
.callout-text {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span><span></span>
</div>
<div class="brand-text">
<strong>STRATA</strong>
<span>Relative age reader</span>
</div>
</div>
<div class="top-meta">
<div class="meta-chip">Interactive voxel cutaway</div>
<div class="meta-chip">4 events</div>
</div>
</header>
<div class="workspace">
<aside class="evidence-panel">
<p class="eyebrow">Geologic log · oldest to youngest</p>
<h1>Read the rock record.</h1>
<p class="intro">
Follow the visible relationships in the cutaway. Each event leaves a
geometric clue that establishes its position in the sequence.
</p>
<div class="timeline-label">
<span>Relative chronology</span>
<span>Old → Young</span>
</div>
<ol class="timeline">
<li>
<button class="stage-card active" data-stage="0"
style="--card-color:#e2c47c" aria-pressed="true">
<span class="stage-number">01</span>
<span>
<h2>Deposition <span class="age-tag">Oldest</span></h2>
<p>Repeated parallel beds show sediment accumulated in layers before later deformation.</p>
</span>
</button>
</li>
<li>
<button class="stage-card" data-stage="1"
style="--card-color:#8fc8b1" aria-pressed="false">
<span class="stage-number">02</span>
<span>
<h2>Tilting <span class="age-tag">Younger</span></h2>
<p>Every sedimentary bed shares the same dip, so the entire stack rotated together.</p>
</span>
</button>
</li>
<li>
<button class="stage-card" data-stage="2"
style="--card-color:#f0a56e" aria-pressed="false">
<span class="stage-number">03</span>
<span>
<h2>Erosion <span class="age-tag">Younger</span></h2>
<p>An irregular upper surface truncates the tilted beds and removes their continuations.</p>
</span>
</button>
</li>
<li>
<button class="stage-card" data-stage="3"
style="--card-color:#ff6b2c" aria-pressed="false">
<span class="stage-number">04</span>
<span>
<h2>Intrusion <span class="age-tag">Youngest</span></h2>
<p>The orange dike cuts across the layered rock and reaches the eroded surface.</p>
</span>
</button>
</li>
</ol>
<section class="principle" aria-live="polite">
<div class="principle-label">Evidence rule</div>
<p id="principle-text">
Superposition comes first: the bottom bed was deposited before the bed above it.
</p>
</section>
<p class="model-note">
Conceptual section, not to scale. The sequence is inferred specifically
from the relationships visible in this model.
</p>
</aside>
<main class="viewport" id="viewport">
<canvas id="scene" tabindex="0"
aria-label="Interactive three-dimensional voxel geological cutaway"></canvas>
<svg id="leaders" aria-hidden="true"></svg>
<section class="stage-readout" aria-live="polite">
<div class="readout-kicker" id="readout-kicker">Event 01 / 04</div>
<h3 id="readout-title">Deposition</h3>
<p id="readout-text">
The colored beds began as horizontal sediment layers. Dashed guides mark their original flat orientation.
</p>
</section>
<div class="compass" aria-hidden="true">
<div class="compass-needle" id="compass-needle"></div>
<b>N</b>
</div>
<div class="legend">
<div class="legend-item">
<span class="swatch beds"></span>
<span>Sedimentary beds</span>
</div>
<div class="legend-item">
<span class="swatch dike"></span>
<span>Magma dike</span>
</div>
</div>
<div class="orbit-hint">Drag to orbit · Scroll to zoom · Arrow keys to inspect</div>
<div class="view-controls">
<button class="control-button" id="reset-view">Reset view</button>
<button class="control-button primary" id="play-sequence">▶ Replay sequence</button>
</div>
<div class="callout" data-stage="0" role="button" tabindex="0"
style="--callout-color:#e2c47c">
<span class="callout-number">01</span>
<span class="callout-text">
<strong>Deposition</strong>
<small>Original stacked beds</small>
</span>
</div>
<div class="callout" data-stage="1" role="button" tabindex="0"
style="--callout-color:#8fc8b1">
<span class="callout-number">02</span>
<span class="callout-text">
<strong>Tilting</strong>
<small>Shared 12° dip</small>
</span>
</div>
<div class="callout" data-stage="2" role="button" tabindex="0"
style="--callout-color:#f0a56e">
<span class="callout-number">03</span>
<span class="callout-text">
<strong>Erosion</strong>
<small>Truncated upper surface</small>
</span>
</div>
<div class="callout" data-stage="3" role="button" tabindex="0"
style="--callout-color:#ff6b2c">
<span class="callout-number">04</span>
<span class="callout-text">
<strong>Intrusion</strong>
<small>Cross-cutting dike</small>
</span>
</div>
</main>
</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.getElementById("scene");
const viewport = document.getElementById("viewport");
const readoutKicker = document.getElementById("readout-kicker");
const readoutTitle = document.getElementById("readout-title");
const readoutText = document.getElementById("readout-text");
const principleText = document.getElementById("principle-text");
const compassNeedle = document.getElementById("compass-needle");
const leaderSvg = document.getElementById("leaders");
const stages = [
{
name: "Deposition",
color: "#e2c47c",
text: "The colored beds began as horizontal sediment layers. Dashed guides mark their original flat orientation.",
principle: "Superposition comes first: the bottom bed was deposited before the bed above it.",
target: new THREE.Vector3(-0.7, 2.25, 1.1),
radius: 21.5
},
{
name: "Tilting",
color: "#8fc8b1",
text: "All beds now incline in the same direction. The highlighted contact follows the shared 12° dip.",
principle: "Tilt after deposition: all layers rotated together, so tilting must postdate deposition.",
target: new THREE.Vector3(-0.2, 2.9, 1.2),
radius: 20.5
},
{
name: "Erosion",
color: "#f0a56e",
text: "The uneven top edge cuts across the tilted contacts, preserving only truncated portions of the beds.",
principle: "Erosion after tilting: the erosional surface cuts the tilted beds, so erosion is later.",
target: new THREE.Vector3(0.1, 4.15, 0.45),
radius: 21.5
},
{
name: "Intrusion",
color: "#ff6b2c",
text: "The glowing orange dike crosses the sedimentary contacts and cuts the present erosional surface.",
principle: "Cross-cutting after erosion: the dike cuts the truncated rock and surface, making it youngest.",
target: new THREE.Vector3(1.3, 3.05, 1.55),
radius: 19.3
}
];
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#081116");
scene.fog = new THREE.Fog("#081116", 28, 52);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const hemisphere = new THREE.HemisphereLight("#c8e2dc", "#172025", 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight("#fff1d6", 3.6);
keyLight.position.set(7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight("#7bb8c8", 1.35);
fillLight.position.set(-9, 7, -6);
scene.add(fillLight);
const magmaLight = new THREE.PointLight("#ff5a1f", 7, 7, 2);
magmaLight.position.set(1.5, 3.1, 2.1);
scene.add(magmaLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(34, 34),
new THREE.MeshStandardMaterial({
color: "#091217",
roughness: 0.94,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.075;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, "#36515a", "#21343b");
grid.position.y = -0.065;
grid.material.transparent = true;
grid.material.opacity = 0.24;
grid.material.depthWrite = false;
scene.add(grid);
const rock = new THREE.Group();
scene.add(rock);
const CELL = 0.54;
const SIZE = 0.50;
const X_COUNT = 15;
const Z_COUNT = 9;
const MAX_Y = 11;
const X_MIN = -7;
const X_MAX = 7;
const Z_MIN = -4;
const Z_MAX = 4;
const palette = [
"#35494d", // Basement
"#b87559", // Lower sandstone
"#ddc27c", // Pale sandstone
"#6e8e89", // Green shale
"#b95f50", // Red mudstone
"#dfd0a6", // Limestone
"#708997", // Blue shale
"#d1a054", // Ochre sandstone
"#765955", // Brown shale
"#aebcb2", // Upper limestone
"#cf8156" // Upper sandstone
];
const layerBuckets = Array.from({ length: palette.length }, () => []);
const magmaCore = [];
const magmaEdge = [];
function surfaceAt(ix, iz) {
const surface =
9.15 -
0.20 * Math.abs(ix + 1) +
0.22 * Math.sin(ix * 0.72) +
0.13 * Math.cos(iz * 0.95) +
0.08 * Math.sin((ix - iz) * 1.10);
return THREE.MathUtils.clamp(surface, 7.3, 10.2);
}
function hashNoise(ix, iy, iz) {
const raw = Math.sin(
(ix + 13) * 12.9898 +
(iy + 7) * 78.233 +
(iz + 3) * 37.719
) * 43758.5453;
return raw - Math.floor(raw);
}
for (let ix = X_MIN; ix <= X_MAX; ix++) {
for (let iz = Z_MIN; iz <= Z_MAX; iz++) {
const topIndex = Math.floor(surfaceAt(ix, iz));
for (let iy = 0; iy <= topIndex; iy++) {
const x = ix * CELL;
const y = iy * CELL + SIZE * 0.5;
const z = iz * CELL;
// Dike is a steep, slightly irregular sheet crossing the block.
const dikeCenter = 3.8 - 0.32 * iy + 0.11 * iz;
const dikeDistance = Math.abs(ix - dikeCenter);
if (dikeDistance < 0.39) {
magmaCore.push({ x, y, z, ix, iy, iz });
} else if (dikeDistance < 0.76) {
magmaEdge.push({ x, y, z, ix, iy, iz });
} else {
// Tilted stratigraphic coordinate.
const strat = iy - 0.22 * ix - 0.10 * iz;
const layerIndex = strat < 0
? 0
: Math.min(palette.length - 1, 1 + Math.floor(strat + 0.15));
layerBuckets[layerIndex].push({ x, y, z, ix, iy, iz });
}
}
}
}
const voxelGeometry = new THREE.BoxGeometry(SIZE, SIZE, SIZE);
const dummy = new THREE.Object3D();
function createInstancedMesh(items, material, colorFn = null) {
if (!items.length) return null;
const mesh = new THREE.InstancedMesh(voxelGeometry, material, items.length);
mesh.castShadow = true;
mesh.receiveShadow = true;
items.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (colorFn) {
mesh.setColorAt(index, colorFn(item));
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.computeBoundingSphere();
rock.add(mesh);
return mesh;
}
const sedimentMaterials = [];
layerBuckets.forEach((items, layerIndex) => {
const base = new THREE.Color(palette[layerIndex]);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: layerIndex === 0 ? 0.92 : 0.76,
metalness: 0.02,
emissive: base.clone().multiplyScalar(0.045),
emissiveIntensity: 0.14
});
sedimentMaterials.push(material);
createInstancedMesh(items, material, item => {
const color = base.clone();
const variation = 0.92 + hashNoise(item.ix, item.iy, item.iz) * 0.14;
color.multiplyScalar(variation);
return color;
});
});
const magmaCoreMaterial = new THREE.MeshStandardMaterial({
color: "#ff792d",
emissive: "#ff3c08",
emissiveIntensity: 0.62,
roughness: 0.34,
metalness: 0.04
});
const magmaEdgeMaterial = new THREE.MeshStandardMaterial({
color: "#8e2d20",
emissive: "#b72d0d",
emissiveIntensity: 0.38,
roughness: 0.58,
metalness: 0.02
});
createInstancedMesh(
magmaCore,
magmaCoreMaterial,
item => new THREE.Color("#ff8a3c").multiplyScalar(
0.90 + hashNoise(item.ix, item.iy, item.iz) * 0.18
)
);
createInstancedMesh(
magmaEdge,
magmaEdgeMaterial,
item => new THREE.Color("#9f3523").multiplyScalar(
0.88 + hashNoise(item.ix, item.iy, item.iz) * 0.18
)
);
// Stage-specific 3D evidence overlays.
const depositionGuides = new THREE.Group();
const tiltEvidence = new THREE.Group();
const erosionEvidence = new THREE.Group();
const intrusionEvidence = new THREE.Group();
scene.add(depositionGuides, tiltEvidence, erosionEvidence, intrusionEvidence);
const guideMaterial = new THREE.LineDashedMaterial({
color: "#d9e9df",
transparent: true,
opacity: 0.42,
dashSize: 0.11,
gapSize: 0.10,
depthTest: false
});
for (let boundary = 1; boundary <= 8; boundary++) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-4.03, boundary * CELL, 2.43),
new THREE.Vector3(4.03, boundary * CELL, 2.43)
]);
const line = new THREE.Line(geometry, guideMaterial);
line.computeLineDistances();
line.renderOrder = 4;
depositionGuides.add(line);
}
const tiltPoints = [];
for (let ix = -7; ix <= 7; ix++) {
const iy = 4.40 + 0.22 * ix;
if (iy >= 0 && iy <= 10) {
tiltPoints.push(new THREE.Vector3(ix * CELL, iy * CELL, 2.44));
}
}
const tiltLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(tiltPoints),
new THREE.LineBasicMaterial({
color: "#a8efd0",
transparent: true,
opacity: 0.95,
depthTest: false
})
);
tiltLine.renderOrder = 5;
tiltEvidence.add(tiltLine);
const arrowStart = new THREE.Vector3(-3.10, 1.10, 2.46);
const arrowEnd = new THREE.Vector3(-2.00, 1.73, 2.46);
const arrowDirection = arrowEnd.clone().sub(arrowStart).normalize();
const tiltArrow = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([arrowStart, arrowEnd]),
new THREE.LineBasicMaterial({
color: "#a8efd0",
depthTest: false
})
);
tiltArrow.renderOrder = 5;
tiltEvidence.add(tiltArrow);
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.11, 0.28, 16),
new THREE.MeshBasicMaterial({ color: "#a8efd0" })
);
arrowHead.position.copy(arrowEnd);
arrowHead.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
arrowDirection
);
tiltEvidence.add(arrowHead);
const erosionMaterial = new THREE.LineBasicMaterial({
color: "#ffc080",
transparent: true,
opacity: 0.95,
depthTest: false
});
const frontSurfacePoints = [];
for (let ix = X_MIN; ix <= X_MAX; ix++) {
const topIndex = Math.floor(surfaceAt(ix, Z_MAX));
const topY = topIndex * CELL + SIZE;
frontSurfacePoints.push(
new THREE.Vector3(ix * CELL, topY, 2.43)
);
}
const sideSurfacePoints = [];
for (let iz = Z_MIN; iz <= Z_MAX; iz++) {
const topIndex = Math.floor(surfaceAt(X_MAX, iz));
const topY = topIndex * CELL + SIZE;
sideSurfacePoints.push(
new THREE.Vector3(4.03, topY, iz * CELL)
);
}
const erosionFront = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(frontSurfacePoints),
erosionMaterial
);
const erosionSide = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(sideSurfacePoints),
erosionMaterial
);
erosionFront.renderOrder = 5;
erosionSide.renderOrder = 5;
erosionEvidence.add(erosionFront, erosionSide);
const intrusionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.62, 0.035, 10, 72),
new THREE.MeshBasicMaterial({
color: "#ff7a35",
transparent: true,
opacity: 0.95,
depthTest: false
})
);
const ringIndex = 5;
const ringX = (3.8 - 0.32 * ringIndex + 0.11 * Z_MAX) * CELL;
intrusionRing.position.set(ringX, ringIndex * CELL + SIZE * 0.5, 2.46);
intrusionRing.renderOrder = 6;
intrusionEvidence.add(intrusionRing);
depositionGuides.visible = true;
tiltEvidence.visible = false;
erosionEvidence.visible = false;
intrusionEvidence.visible = false;
// Custom camera controls implemented without addons.
const desired = {
theta: 0.72,
phi: 1.15,
radius: 21.5,
target: new THREE.Vector3(0, 2.6, 0)
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius,
target: desired.target.clone()
};
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.62,
1.43
);
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("lostpointercapture", () => {
dragging = false;
canvas.classList.remove("dragging");
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
14,
34
);
}, { passive: false });
canvas.addEventListener("keydown", event => {
const step = 0.10;
if (event.key === "ArrowLeft") desired.theta += step;
else if (event.key === "ArrowRight") desired.theta -= step;
else if (event.key === "ArrowUp") {
desired.phi = THREE.MathUtils.clamp(desired.phi - step, 0.62, 1.43);
} else if (event.key === "ArrowDown") {
desired.phi = THREE.MathUtils.clamp(desired.phi + step, 0.62, 1.43);
} else if (event.key === "+" || event.key === "=") {
desired.radius = THREE.MathUtils.clamp(desired.radius - 1.2, 14, 34);
} else if (event.key === "-") {
desired.radius = THREE.MathUtils.clamp(desired.radius + 1.2, 14, 34);
} else {
return;
}
event.preventDefault();
});
// Screen-space labels and leader lines.
const callouts = [...document.querySelectorAll(".callout")];
const stageCards = [...document.querySelectorAll(".stage-card")];
const anchors = [
new THREE.Vector3(-2.65, 1.15, 2.44),
new THREE.Vector3(1.15, 3.12, 2.44),
new THREE.Vector3(-1.50, 5.05, 2.44),
new THREE.Vector3(1.45, 3.15, 2.44)
];
const offsets = [
[-118, 52],
[-105, -32],
[-66, -70],
[105, 58]
];
const leaderLines = [];
const leaderDots = [];
callouts.forEach(() => {
const line = document.createElementNS("http://www.w3.org/2000/svg", "line");
line.setAttribute("class", "leader-line");
leaderSvg.appendChild(line);
leaderLines.push(line);
const dot = document.createElementNS("http://www.w3.org/2000/svg", "circle");
dot.setAttribute("class", "leader-dot");
dot.setAttribute("r", "3.4");
leaderSvg.appendChild(dot);
leaderDots.push(dot);
});
let activeStage = 0;
let playing = false;
let playTimer = null;
function setStage(index) {
activeStage = index;
const stage = stages[index];
document.documentElement.style.setProperty("--stage", stage.color);
readoutKicker.textContent = `Event ${String(index + 1).padStart(2, "0")} / 04`;
readoutTitle.textContent = stage.name;
readoutText.textContent = stage.text;
principleText.textContent = stage.principle;
stageCards.forEach((card, cardIndex) => {
const active = cardIndex === index;
card.classList.toggle("active", active);
card.setAttribute("aria-pressed", String(active));
});
callouts.forEach((callout, calloutIndex) => {
callout.classList.toggle("active", calloutIndex === index);
});
depositionGuides.visible = index === 0;
tiltEvidence.visible = index === 1;
erosionEvidence.visible = index === 2;
intrusionEvidence.visible = index === 3;
desired.target.copy(stage.target);
desired.radius = stage.radius;
}
function stopPlayback() {
playing = false;
clearTimeout(playTimer);
document.getElementById("play-sequence").textContent = "▶ Replay sequence";
}
function playNext() {
if (!playing) return;
const next = activeStage >= stages.length - 1 ? 0 : activeStage + 1;
setStage(next);
playTimer = setTimeout(playNext, 3600);
}
stageCards.forEach(card => {
card.addEventListener("click", () => {
stopPlayback();
setStage(Number(card.dataset.stage));
});
});
callouts.forEach(callout => {
const activate = () => {
stopPlayback();
setStage(Number(callout.dataset.stage));
};
callout.addEventListener("click", activate);
callout.addEventListener("keydown", event => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
activate();
}
});
});
document.getElementById("reset-view").addEventListener("click", () => {
desired.theta = 0.72;
desired.phi = 1.15;
desired.radius = 22.5;
desired.target.set(0, 2.7, 0);
});
document.getElementById("play-sequence").addEventListener("click", () => {
if (playing) {
stopPlayback();
return;
}
playing = true;
document.getElementById("play-sequence").textContent = "Ⅱ Pause sequence";
setStage(0);
playTimer = setTimeout(playNext, 3600);
});
function resizeRenderer() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resizeRenderer).observe(viewport);
resizeRenderer();
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
anchors.forEach((anchor, index) => {
const projected = anchor.clone().project(camera);
const px = (projected.x * 0.5 + 0.5) * width;
const py = (-projected.y * 0.5 + 0.5) * height;
const [offsetX, offsetY] = offsets[index];
const lx = THREE.MathUtils.clamp(px + offsetX, 62, width - 62);
const ly = THREE.MathUtils.clamp(py + offsetY, 40, height - 40);
const label = callouts[index];
label.style.left = `${lx}px`;
label.style.top = `${ly}px`;
const halfWidth = label.offsetWidth * 0.5;
const endX = offsetX >= 0 ? lx - halfWidth : lx + halfWidth;
const line = leaderLines[index];
line.setAttribute("x1", px.toFixed(1));
line.setAttribute("y1", py.toFixed(1));
line.setAttribute("x2", endX.toFixed(1));
line.setAttribute("y2", ly.toFixed(1));
line.setAttribute("stroke", stages[index].color);
line.classList.toggle("active", index === activeStage);
line.style.opacity = index === activeStage ? "0.95" : "0.48";
const dot = leaderDots[index];
dot.setAttribute("cx", px.toFixed(1));
dot.setAttribute("cy", py.toFixed(1));
dot.setAttribute("fill", stages[index].color);
dot.classList.toggle("active", index === activeStage);
dot.style.opacity = index === activeStage ? "1" : "0.65";
});
}
const clock = new THREE.Clock();
function animate() {
const time = clock.getElapsedTime();
const smoothing = 0.075;
current.theta += (desired.theta - current.theta) * smoothing;
current.phi += (desired.phi - current.phi) * smoothing;
current.radius += (desired.radius - current.radius) * smoothing;
current.target.lerp(desired.target, smoothing);
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x + current.radius * sinPhi * Math.cos(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z + current.radius * sinPhi * Math.sin(current.theta)
);
camera.lookAt(current.target);
camera.updateMatrixWorld();
const pulse = 0.5 + 0.5 * Math.sin(time * 3.2);
magmaCoreMaterial.emissiveIntensity =
activeStage === 3 ? 0.72 + pulse * 0.42 : 0.46 + pulse * 0.16;
magmaEdgeMaterial.emissiveIntensity =
activeStage === 3 ? 0.40 + pulse * 0.18 : 0.28;
magmaLight.intensity = activeStage === 3
? 6 + pulse * 5
: 3.5 + pulse * 2;
const ringScale = 1 + pulse * 0.09;
intrusionRing.scale.setScalar(ringScale);
intrusionRing.material.opacity = 0.72 + pulse * 0.28;
compassNeedle.style.transform = `rotate(${-current.theta * 180 / Math.PI}deg)`;
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(animate);
}
setStage(0);
animate();
</script>
</body>
</html>
```