Prompt specification
Build or customize the Three.js 3D scene "Fossil evidence sampling explorer" 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: Fossil evidence sampling explorer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/fossil-evidence-sampling-explorer-x1148
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring fossil preservation. Let viewers uncover a limited number of cells in a layered block; compare observed fossils with hidden positions to illustrate incomplete sampling without inventing a real species history. Voxel style.
Working Three.js Starter (fossil-evidence-sampling-explorer-x1148):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#081410">
<title>STRATA — Partial Fossil Record</title>
<style>
:root {
color-scheme: dark;
--bg: #081410;
--panel: #0d1c17;
--panel-2: #10231c;
--line: rgba(174, 229, 207, 0.14);
--text: #e5f2ec;
--muted: #88a79a;
--mint: #9af0d0;
--mint-strong: #baffdf;
--amber: #efb65c;
--danger: #ef8876;
--radius: 16px;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
}
body {
overflow: hidden;
}
button {
font: inherit;
}
button:focus-visible {
outline: 2px solid var(--mint);
outline-offset: 3px;
}
.app {
min-height: 100vh;
display: flex;
flex-direction: column;
}
header {
height: 72px;
flex: 0 0 72px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 26px;
border-bottom: 1px solid var(--line);
background: rgba(8, 20, 16, 0.94);
position: relative;
z-index: 5;
}
.brand {
display: flex;
align-items: center;
gap: 14px;
min-width: 0;
}
.brand-mark {
width: 36px;
height: 36px;
border: 1px solid rgba(154, 240, 208, 0.45);
display: grid;
place-items: center;
transform: rotate(45deg);
background: rgba(154, 240, 208, 0.05);
flex: 0 0 auto;
}
.brand-mark::before {
content: "";
width: 12px;
height: 12px;
background: var(--mint);
box-shadow: 0 0 18px rgba(154, 240, 208, 0.55);
}
.brand-copy {
min-width: 0;
}
.eyebrow {
margin: 0 0 5px;
color: var(--mint);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(16px, 2vw, 21px);
line-height: 1.1;
font-weight: 650;
letter-spacing: -0.02em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.header-meta {
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 11px;
white-space: nowrap;
}
.badge {
border: 1px solid var(--line);
border-radius: 999px;
padding: 7px 10px;
background: rgba(255, 255, 255, 0.025);
}
.badge strong {
color: var(--text);
font-weight: 650;
}
main {
flex: 1;
min-height: 0;
display: grid;
grid-template-columns: minmax(0, 1fr) 380px;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 40%, rgba(54, 112, 89, 0.12), transparent 44%),
#081410;
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.stage-top,
.stage-bottom {
position: absolute;
left: 22px;
right: 22px;
z-index: 2;
pointer-events: none;
}
.stage-top {
top: 22px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
}
.stage-title {
max-width: 330px;
}
.stage-title strong {
display: block;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stage-title span {
display: block;
margin-top: 7px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.view-actions {
display: flex;
gap: 8px;
pointer-events: auto;
}
.icon-button {
width: 38px;
height: 38px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(9, 25, 19, 0.78);
color: var(--muted);
cursor: pointer;
backdrop-filter: blur(10px);
transition: 160ms ease;
}
.icon-button:hover {
color: var(--mint);
border-color: rgba(154, 240, 208, 0.42);
background: rgba(154, 240, 208, 0.07);
}
.budget-hud {
min-width: 190px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(8, 22, 17, 0.78);
backdrop-filter: blur(14px);
}
.budget-label {
display: flex;
justify-content: space-between;
gap: 16px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.budget-label strong {
color: var(--mint);
font-size: 11px;
}
#budgetDots {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 4px;
margin-top: 10px;
}
#budgetDots span {
height: 5px;
border-radius: 2px;
background: rgba(255, 255, 255, 0.11);
transition: 180ms ease;
}
#budgetDots span.used {
background: var(--mint);
box-shadow: 0 0 8px rgba(154, 240, 208, 0.4);
}
.stage-bottom {
bottom: 20px;
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 20px;
}
.help-card {
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(8, 22, 17, 0.75);
backdrop-filter: blur(12px);
color: var(--muted);
font-size: 11px;
line-height: 1.6;
}
.help-card strong {
color: var(--text);
font-weight: 600;
}
kbd {
display: inline-block;
min-width: 19px;
padding: 1px 5px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-bottom-color: rgba(255, 255, 255, 0.28);
border-radius: 4px;
background: rgba(255, 255, 255, 0.05);
color: var(--text);
font: 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
.layer-switcher {
pointer-events: auto;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(8, 22, 17, 0.82);
backdrop-filter: blur(12px);
}
.layer-switcher > span {
padding: 0 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.layer-button {
min-width: 48px;
padding: 9px 10px;
border: 1px solid transparent;
border-radius: 8px;
background: transparent;
color: var(--muted);
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: 160ms ease;
}
.layer-button:hover {
color: var(--text);
background: rgba(255, 255, 255, 0.04);
}
.layer-button.active {
border-color: rgba(154, 240, 208, 0.34);
background: rgba(154, 240, 208, 0.11);
color: var(--mint-strong);
}
#tooltip {
position: absolute;
z-index: 4;
pointer-events: none;
opacity: 0;
transform: translate(12px, 12px);
transition: opacity 100ms ease;
padding: 8px 10px;
border: 1px solid rgba(154, 240, 208, 0.28);
border-radius: 8px;
background: rgba(5, 16, 12, 0.92);
color: var(--text);
font: 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
white-space: nowrap;
}
#tooltip.visible {
opacity: 1;
}
#toast {
position: absolute;
z-index: 6;
left: 50%;
top: 18%;
transform: translate(-50%, -8px);
opacity: 0;
pointer-events: none;
padding: 10px 14px;
border: 1px solid rgba(154, 240, 208, 0.26);
border-radius: 10px;
background: rgba(6, 20, 15, 0.9);
color: var(--text);
font-size: 12px;
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
transition: 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
aside {
min-height: 0;
overflow-y: auto;
border-left: 1px solid var(--line);
background:
linear-gradient(rgba(255, 255, 255, 0.012), rgba(255, 255, 255, 0)),
var(--panel);
scrollbar-width: thin;
scrollbar-color: #29473c transparent;
}
.panel {
padding: 24px;
border-bottom: 1px solid var(--line);
}
.panel h2 {
margin: 0 0 9px;
font-size: 19px;
line-height: 1.25;
letter-spacing: -0.02em;
}
.panel p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
}
.control-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 18px;
}
.button {
min-height: 42px;
border: 1px solid var(--line);
border-radius: 10px;
padding: 10px 12px;
background: rgba(255, 255, 255, 0.035);
color: var(--text);
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: 160ms ease;
}
.button:hover {
border-color: rgba(154, 240, 208, 0.4);
background: rgba(154, 240, 208, 0.07);
}
.button.primary {
border-color: rgba(154, 240, 208, 0.38);
background: var(--mint);
color: #082018;
}
.button.primary:hover {
background: var(--mint-strong);
}
.button.active {
border-color: var(--amber);
background: rgba(239, 182, 92, 0.11);
color: #ffd58e;
}
.button:disabled {
opacity: 0.42;
cursor: not-allowed;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 18px;
}
.stat {
min-width: 0;
padding: 12px 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.stat span {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stat strong {
display: block;
font-size: 21px;
font-weight: 650;
letter-spacing: -0.04em;
}
.stat em {
color: var(--muted);
font-size: 10px;
font-style: normal;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.section-title h3 {
margin: 0;
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-title span {
color: var(--muted);
font-size: 10px;
}
.observed-list {
display: grid;
gap: 7px;
}
.observed-row {
display: grid;
grid-template-columns: 9px 1fr auto;
align-items: center;
gap: 10px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.observed-row .dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--mint);
box-shadow: 0 0 9px rgba(154, 240, 208, 0.45);
}
.observed-row strong {
display: block;
font: 600 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.observed-row small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.observed-row > span:last-child {
color: var(--mint);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.empty-state {
padding: 18px;
border: 1px dashed rgba(174, 229, 207, 0.17);
border-radius: 11px;
color: var(--muted);
font-size: 11px;
line-height: 1.6;
text-align: center;
}
.comparison-card {
margin-top: 14px;
padding: 13px;
border: 1px solid rgba(239, 182, 92, 0.18);
border-radius: 11px;
background: rgba(239, 182, 92, 0.045);
}
.comparison-card strong {
display: block;
margin-bottom: 5px;
color: #ffd58e;
font-size: 11px;
}
.comparison-card p {
color: #b8a98f;
font-size: 10px;
}
.map-stack {
display: grid;
gap: 15px;
}
.map-layer-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.map-grid {
display: grid;
grid-template-columns: repeat(9, 1fr);
gap: 3px;
padding: 5px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(0, 0, 0, 0.13);
}
.map-cell {
position: relative;
aspect-ratio: 1;
border-radius: 2px;
background: rgba(255, 255, 255, 0.035);
}
.map-cell.sampled-empty::after {
content: "";
position: absolute;
inset: 42%;
border-radius: 1px;
background: rgba(136, 167, 154, 0.6);
}
.map-cell.hidden::after {
content: "";
position: absolute;
inset: 27%;
border-radius: 2px;
background: var(--amber);
box-shadow: 0 0 7px rgba(239, 182, 92, 0.4);
}
.map-cell.observed {
background: rgba(154, 240, 208, 0.17);
}
.map-cell.observed::after {
content: "";
position: absolute;
inset: 22%;
border: 2px solid var(--mint);
border-radius: 2px;
background: rgba(154, 240, 208, 0.32);
box-shadow: 0 0 8px rgba(154, 240, 208, 0.38);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 14px;
color: var(--muted);
font-size: 9px;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--mint);
}
.legend i.hidden {
background: var(--amber);
}
.legend i.empty {
background: var(--muted);
}
.disclaimer {
padding: 18px 24px 24px;
color: #678579;
font-size: 10px;
line-height: 1.65;
}
.disclaimer strong {
color: #91aa9f;
}
@media (max-width: 880px) {
body {
overflow: auto;
}
header {
height: 64px;
flex-basis: 64px;
padding: 0 16px;
}
.header-meta .badge:first-child {
display: none;
}
main {
display: block;
}
#stage {
height: 62vh;
min-height: 460px;
}
aside {
overflow: visible;
border-left: 0;
border-top: 1px solid var(--line);
}
.stage-top,
.stage-bottom {
left: 14px;
right: 14px;
}
.stage-title {
max-width: 220px;
}
.stage-title span {
display: none;
}
.budget-hud {
min-width: 168px;
}
.help-card {
display: none;
}
}
@media (max-width: 560px) {
.header-meta {
display: none;
}
.stage-top {
top: 14px;
}
.budget-hud {
min-width: 146px;
padding: 10px;
}
.stage-bottom {
bottom: 14px;
justify-content: center;
}
.layer-switcher {
width: 100%;
justify-content: center;
}
.panel {
padding: 21px 18px;
}
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<p class="eyebrow">STRATA / Sampling Study 04</p>
<h1>Partial fossil record</h1>
</div>
</div>
<div class="header-meta">
<span class="badge"><strong>162</strong> voxel cells</span>
<span class="badge"><strong>12</strong> cell limit</span>
<span class="badge">Synthetic teaching model</span>
</div>
</header>
<main>
<section id="stage" aria-label="Interactive three-dimensional fossil block">
<div id="viewport"></div>
<div class="stage-top">
<div class="stage-title">
<strong>Stratigraphic volume</strong>
<span>
Isolate a layer, then uncover individual cells.
The sample is deliberately smaller than the block.
</span>
</div>
<div class="view-actions">
<button id="resetView" class="icon-button" title="Reset camera" aria-label="Reset camera">
↺
</button>
</div>
</div>
<div class="budget-hud">
<div class="budget-label">
<span>Excavation budget</span>
<strong id="budgetText">0 / 12</strong>
</div>
<div id="budgetDots" aria-hidden="true"></div>
</div>
<div class="stage-bottom">
<div class="help-card">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom · <strong>Click</strong> a voxel to uncover<br />
<kbd>1</kbd> <kbd>2</kbd> <kbd>3</kbd> switch strata
</div>
<div class="layer-switcher" role="group" aria-label="Select active stratum">
<span>Layer</span>
<button class="layer-button" data-layer="0">01</button>
<button class="layer-button active" data-layer="1">02</button>
<button class="layer-button" data-layer="2">03</button>
</div>
</div>
<div id="tooltip"></div>
<div id="toast" role="status" aria-live="polite"></div>
</section>
<aside aria-label="Sampling report">
<section class="panel">
<p class="eyebrow">Recovery control</p>
<h2>Uncover a bounded sample</h2>
<p>
Only a small number of cells can be opened. Fossil-bearing positions are
distributed through all three strata and remain unknown until uncovered.
</p>
<div class="control-row">
<button id="compareButton" class="button primary">
Compare with hidden positions
</button>
<button id="newButton" class="button">New synthetic block</button>
</div>
<div class="control-row">
<button id="resetSample" class="button">Reset this sample</button>
</div>
<div class="stats">
<div class="stat">
<span>Observed</span>
<strong id="observedCount">0</strong>
<em id="fossilTotal">of 0 fossil cells</em>
</div>
<div class="stat">
<span>Still hidden</span>
<strong id="hiddenCount">—</strong>
<em id="hiddenCaption">comparison off</em>
</div>
<div class="stat">
<span>Coverage</span>
<strong id="coverage">0%</strong>
<em id="coverageCaption">0 of 162 cells</em>
</div>
</div>
</section>
<section class="panel">
<div class="section-title">
<h3>Observed material</h3>
<span id="observedCaption">0 records</span>
</div>
<div id="observedList" class="observed-list">
<div class="empty-state">
No cells have been uncovered yet. Choose a layer and begin sampling.
</div>
</div>
</section>
<section class="panel">
<div class="section-title">
<h3>Position comparison</h3>
<span>Top-down layer maps</span>
</div>
<p>
Enable the comparison to mark all fossil-bearing cells. Observed positions
remain mint; unobserved positions appear amber.
</p>
<div id="mapStack" class="map-stack" style="margin-top: 16px"></div>
<div class="legend">
<span><i></i> observed fossil</span>
<span><i class="hidden"></i> hidden fossil</span>
<span><i class="empty"></i> sampled, no fossil</span>
</div>
<div id="comparisonCard" class="comparison-card">
<strong>Comparison hidden</strong>
<p>
Reveal the complete set of fossil-bearing positions to compare the observed
subset with the unsampled remainder.
</p>
</div>
</section>
<div class="disclaimer">
<strong>Interpretation note:</strong> the voxel forms and positions are synthetic.
They illustrate preservation and incomplete sampling only. The abstract morphologies
do not represent a real species, lineage, evolutionary sequence, or species history.
</div>
</aside>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Constants and state
// -------------------------------------------------------------------------
const WIDTH = 9;
const HEIGHT = 6;
const DEPTH = 3;
const STEP = 0.84;
const MAX_SAMPLES = 12;
const viewport = document.getElementById("viewport");
const tooltip = document.getElementById("tooltip");
const toast = document.getElementById("toast");
let activeLayer = 1;
let usedSamples = 0;
let compareMode = false;
let specimenSeed = 40317;
let hoverCell = null;
let toastTimer = null;
const cells = [];
const fossils = [];
const layerGroups = [];
const cavities = [];
const layerNames = ["Basal stratum", "Middle stratum", "Cap stratum"];
// -------------------------------------------------------------------------
// Renderer, camera, lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x081410);
scene.fog = new THREE.FogExp2(0x081410, 0.035);
const camera = new THREE.PerspectiveCamera(
42,
viewport.clientWidth / viewport.clientHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Rotatable voxel block containing synthetic fossil-bearing cells"
);
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xc5ffe8, 0x182019, 1.9);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe5bc, 3.2);
keyLight.position.set(5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x62e4ba, 38, 22, 2);
rimLight.position.set(-6, 2, -4);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb95f, 20, 16, 2);
warmLight.position.set(5, -1, 5);
scene.add(warmLight);
// Display platform and floor.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(36, 36),
new THREE.MeshStandardMaterial({
color: 0x07110d,
roughness: 0.96,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -3.13;
floor.receiveShadow = true;
scene.add(floor);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(5.15, 5.45, 0.28, 64),
new THREE.MeshStandardMaterial({
color: 0x11251e,
roughness: 0.72,
metalness: 0.18
})
);
platform.position.y = -2.93;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const platformTop = new THREE.Mesh(
new THREE.CylinderGeometry(4.82, 4.82, 0.025, 64),
new THREE.MeshStandardMaterial({
color: 0x0c1d17,
roughness: 0.8,
metalness: 0.12
})
);
platformTop.position.y = -2.775;
platformTop.receiveShadow = true;
scene.add(platformTop);
const grid = new THREE.GridHelper(18, 18, 0x3d806b, 0x1a3b30);
grid.position.y = -3.105;
grid.material.transparent = true;
grid.material.opacity = 0.26;
scene.add(grid);
for (const radius of [3.9, 4.45, 5.0]) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(radius, radius + 0.018, 96),
new THREE.MeshBasicMaterial({
color: 0x4c9b82,
transparent: true,
opacity: 0.16,
side: THREE.DoubleSide
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = -2.755;
scene.add(ring);
}
// A faint outer volume frame.
const volumeGeometry = new THREE.BoxGeometry(
WIDTH * STEP - 0.08,
HEIGHT * STEP - 0.08,
DEPTH * STEP - 0.06
);
const volumeFrame = new THREE.LineSegments(
new THREE.EdgesGeometry(volumeGeometry),
new THREE.LineBasicMaterial({
color: 0x8bd6ba,
transparent: true,
opacity: 0.14
})
);
scene.add(volumeFrame);
// -------------------------------------------------------------------------
// Shared geometries and materials
// -------------------------------------------------------------------------
const cellGeometry = new THREE.BoxGeometry(0.77, 0.77, 0.77);
const fossilGeometry = new THREE.BoxGeometry(1, 1, 1);
const markerGeometry = new THREE.BoxGeometry(0.3, 0.3, 0.3);
const cavityGeometry = new THREE.BoxGeometry(0.59, 0.59, 0.16);
const fossilMaterials = [
new THREE.MeshStandardMaterial({
color: 0xb8f2db,
emissive: 0x153c2e,
emissiveIntensity: 0.65,
roughness: 0.52,
metalness: 0.05
}),
new THREE.MeshStandardMaterial({
color: 0xc9edcf,
emissive: 0x173a26,
emissiveIntensity: 0.62,
roughness: 0.58,
metalness: 0.04
}),
new THREE.MeshStandardMaterial({
color: 0xafe2d1,
emissive: 0x103c3a,
emissiveIntensity: 0.68,
roughness: 0.48,
metalness: 0.06
}),
new THREE.MeshStandardMaterial({
color: 0xd1e8ba,
emissive: 0x293b22,
emissiveIntensity: 0.55,
roughness: 0.6,
metalness: 0.03
})
];
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0xefb65c,
wireframe: true,
transparent: true,
opacity: 0.3,
depthTest: false,
depthWrite: false
});
const cavityMaterial = new THREE.MeshStandardMaterial({
color: 0x17231c,
roughness: 1,
metalness: 0
});
const hoverMaterial = new THREE.LineBasicMaterial({
color: 0xbaffdf,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
});
const hoverOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(0.81, 0.81, 0.81)),
hoverMaterial
);
hoverOutline.visible = false;
hoverOutline.renderOrder = 50;
scene.add(hoverOutline);
// -------------------------------------------------------------------------
// Build the voxel strata
// -------------------------------------------------------------------------
const layerColors = [0x785b3d, 0x99764d, 0xb08b5d];
const dimColor = new THREE.Color(0x29443a);
for (let layer = 0; layer < DEPTH; layer++) {
const group = new THREE.Group();
group.userData.baseZ = (layer - 1) * STEP;
group.position.z = group.userData.baseZ;
layerGroups.push(group);
scene.add(group);
const frame = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(WIDTH * STEP - 0.06, HEIGHT * STEP - 0.06, 0.79)
),
new THREE.LineBasicMaterial({
color: 0xd1b88c,
transparent: true,
opacity: 0.12
})
);
group.add(frame);
for (let row = 0; row < HEIGHT; row++) {
for (let col = 0; col < WIDTH; col++) {
const color = new THREE.Color(layerColors[layer]);
color.offsetHSL(
((row * 7 + col * 11 + layer * 3) % 7 - 3) * 0.004,
((row + col) % 3 - 1) * 0.025,
((row * 5 + col * 3) % 5 - 2) * 0.012
);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.025,
transparent: true,
opacity: 1
});
const mesh = new THREE.Mesh(cellGeometry, material);
mesh.position.set(
(col - (WIDTH - 1) / 2) * STEP,
((HEIGHT - 1) / 2 - row) * STEP,
0
);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData = {
layer,
row,
col,
sampled: false,
revealStart: null,
baseColor: color.clone(),
targetColor: color.clone(),
record: null
};
group.add(mesh);
cells.push(mesh);
}
}
}
// -------------------------------------------------------------------------
// Synthetic fossil morphology
// -------------------------------------------------------------------------
function addVoxel(group, material, x, y, z, sx, sy, sz) {
const mesh = new THREE.Mesh(fossilGeometry, material);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function createFossil(morph, material) {
const group = new THREE.Group();
if (morph === 0) {
// Abstract segmented axis.
for (let i = -2; i <= 2; i++) {
addVoxel(group, material, i * 0.115, Math.sin(i * 1.2) * 0.035, 0, 0.13, 0.12, 0.13);
}
addVoxel(group, material, -0.12, 0.12, 0, 0.09, 0.16, 0.09);
addVoxel(group, material, 0.11, -0.12, 0, 0.09, 0.15, 0.09);
addVoxel(group, material, 0.01, 0.15, 0, 0.1, 0.08, 0.09);
} else if (morph === 1) {
// Abstract branching form.
addVoxel(group, material, 0, -0.13, 0, 0.12, 0.27, 0.12);
addVoxel(group, material, 0, 0.08, 0, 0.12, 0.25, 0.12);
addVoxel(group, material, -0.12, 0.14, 0, 0.18, 0.09, 0.1);
addVoxel(group, material, 0.13, 0.2, 0, 0.18, 0.09, 0.1);
addVoxel(group, material, -0.16, -0.03, 0, 0.18, 0.09, 0.1);
addVoxel(group, material, 0.17, 0.03, 0, 0.18, 0.09, 0.1);
} else if (morph === 2) {
// Abstract curved form built from square elements.
const points = [
[-0.16, -0.08],
[-0.16, 0.07],
[-0.07, 0.17],
[0.06, 0.18],
[0.16, 0.09],
[0.17, -0.04],
[0.08, -0.13],
[-0.04, -0.14]
];
points.forEach(([x, y]) => {
addVoxel(group, material, x, y, 0, 0.105, 0.105, 0.12);
});
} else {
// Abstract radial form.
addVoxel(group, material, 0, 0, 0, 0.13, 0.13, 0.13);
addVoxel(group, material, 0, 0.15, 0, 0.09, 0.2, 0.1);
addVoxel(group, material, -0.15, 0.08, 0, 0.2, 0.09, 0.1);
addVoxel(group, material, 0.15, 0.08, 0, 0.2, 0.09, 0.1);
addVoxel(group, material, -0.1, -0.14, 0, 0.09, 0.18, 0.1);
addVoxel(group, material, 0.1, -0.14, 0, 0.09, 0.18, 0.1);
}
group.scale.setScalar(0.001);
group.visible = false;
return group;
}
function mulberry32(seed) {
return function random() {
let t = seed += 0x6d2b79f5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function clearCavities() {
while (cavities.length) {
const cavity = cavities.pop();
cavity.parent?.remove(cavity);
}
}
function clearFossils() {
fossils.forEach((record) => {
record.group.parent?.remove(record.group);
record.marker.parent?.remove(record.marker);
});
fossils.length = 0;
cells.forEach((cell) => {
cell.userData.record = null;
});
}
function generateSpecimen(seed) {
clearFossils();
clearCavities();
const random = mulberry32(seed);
const perLayer = [9, 9, 8];
const typeNames = [
"Segmented morph",
"Branching morph",
"Curved morph",
"Radial morph"
];
for (let layer = 0; layer < DEPTH; layer++) {
const usedPositions = new Set();
while (usedPositions.size < perLayer[layer]) {
const row = Math.floor(random() * HEIGHT);
const col = Math.floor(random() * WIDTH);
const key = `${row}:${col}`;
if (!usedPositions.has(key)) {
usedPositions.add(key);
}
}
for (const key of usedPositions) {
const [row, col] = key.split(":").map(Number);
const cell = cells.find(
(candidate) =>
candidate.userData.layer === layer &&
candidate.userData.row === row &&
candidate.userData.col === col
);
const morph = Math.floor(random() * 4);
const group = createFossil(morph, fossilMaterials[morph]);
group.position.set(cell.position.x, cell.position.y, 0.055);
layerGroups[layer].add(group);
const marker = new THREE.Mesh(markerGeometry, markerMaterial);
marker.position.set(cell.position.x, cell.position.y, 0.08);
marker.visible = false;
marker.renderOrder = 40;
layerGroups[layer].add(marker);
const record = {
id: `F-${String(fossils.length + 1).padStart(2, "0")}`,
layer,
row,
col,
morph,
typeName: typeNames[morph],
group,
marker,
cell,
observed: false,
observedAt: 0,
coordinate: `${String.fromCharCode(65 + col)}${HEIGHT - row}`
};
cell.userData.record = record;
fossils.push(record);
}
}
}
// -------------------------------------------------------------------------
// UI and appearance
// -------------------------------------------------------------------------
const budgetDots = document.getElementById("budgetDots");
for (let i = 0; i < MAX_SAMPLES; i++) {
budgetDots.appendChild(document.createElement("span"));
}
const observedCount = document.getElementById("observedCount");
const fossilTotal = document.getElementById("fossilTotal");
const hiddenCount = document.getElementById("hiddenCount");
const hiddenCaption = document.getElementById("hiddenCaption");
const coverage = document.getElementById("coverage");
const coverageCaption = document.getElementById("coverageCaption");
const observedList = document.getElementById("observedList");
const observedCaption = document.getElementById("observedCaption");
const mapStack = document.getElementById("mapStack");
const compareButton = document.getElementById("compareButton");
const comparisonCard = document.getElementById("comparisonCard");
function updateLayerAppearance() {
cells.forEach((cell) => {
const active = cell.userData.layer === activeLayer;
const sampled = cell.userData.sampled;
cell.userData.targetColor.copy(cell.userData.baseColor);
if (!active) {
cell.userData.targetColor.lerp(dimColor, 0.62);
}
if (sampled) {
cell.userData.targetColor.lerp(dimColor, 0.4);
}
cell.material.depthWrite = active && !sampled;
});
}
function updateMap() {
mapStack.innerHTML = "";
for (let layer = 0; layer < DEPTH; layer++) {
const wrapper = document.createElement("div");
const title = document.createElement("div");
title.className = "map-layer-title";
const observedInLayer = fossils.filter(
(record) => record.layer === layer && record.observed
).length;
title.innerHTML = `
<span>Layer ${String(layer + 1).padStart(2, "0")} · ${layerNames[layer]}</span>
<span>${observedInLayer} observed</span>
`;
const gridElement = document.createElement("div");
gridElement.className = "map-grid";
for (let row = 0; row < HEIGHT; row++) {
for (let col = 0; col < WIDTH; col++) {
const cell = cells.find(
(candidate) =>
candidate.userData.layer === layer &&
candidate.userData.row === row &&
candidate.userData.col === col
);
const marker = document.createElement("div");
marker.className = "map-cell";
if (cell.userData.record?.observed) {
marker.classList.add("observed");
} else if (compareMode && cell.userData.record) {
marker.classList.add("hidden");
} else if (cell.userData.sampled) {
marker.classList.add("sampled-empty");
}
marker.title = `${String.fromCharCode(65 + col)}${HEIGHT - row} — Layer ${layer + 1}`;
gridElement.appendChild(marker);
}
}
wrapper.appendChild(title);
wrapper.appendChild(gridElement);
mapStack.appendChild(wrapper);
}
}
function updateUI() {
const observed = fossils.filter((record) => record.observed);
const hidden = fossils.length - observed.length;
const totalCells = WIDTH * HEIGHT * DEPTH;
const coveragePercent = (usedSamples / totalCells) * 100;
document.getElementById("budgetText").textContent = `${usedSamples} / ${MAX_SAMPLES}`;
[...budgetDots.children].forEach((dot, index) => {
dot.classList.toggle("used", index < usedSamples);
});
observedCount.textContent = observed.length;
fossilTotal.textContent = `of ${fossils.length} fossil cells`;
hiddenCount.textContent = compareMode ? hidden : "—";
hiddenCaption.textContent = compareMode ? "unsampled fossils" : "comparison off";
coverage.textContent = `${coveragePercent.toFixed(1)}%`;
coverageCaption.textContent = `${usedSamples} of ${totalCells} cells`;
observedCaption.textContent = `${observed.length} record${observed.length === 1 ? "" : "s"}`;
compareButton.textContent = compareMode
? "Hide hidden positions"
: "Compare with hidden positions";
compareButton.classList.toggle("active", compareMode);
comparisonCard.innerHTML = compareMode
? `
<strong>${observed.length} observed, ${hidden} still hidden</strong>
<p>
The recovery sample contains ${usedSamples} cells but does not provide a complete
inventory. Hidden positions are shown only for comparison, not as recovered evidence.
</p>
`
: `
<strong>Comparison hidden</strong>
<p>
Reveal the complete set of fossil-bearing positions to compare the observed
subset with the unsampled remainder.
</p>
`;
if (observed.length === 0) {
observedList.innerHTML = `
<div class="empty-state">
No cells have been uncovered yet. Choose a layer and begin sampling.
</div>
`;
} else {
observedList.innerHTML = observed
.map(
(record) => `
<div class="observed-row">
<span class="dot"></span>
<div>
<strong>${record.id} · ${record.coordinate}</strong>
<small>Layer ${record.layer + 1} · ${record.typeName}</small>
</div>
<span>Recovered</span>
</div>
`
)
.join("");
}
fossils.forEach((record) => {
record.marker.visible = compareMode && !record.observed;
});
updateMap();
}
function showToast(message) {
clearTimeout(toastTimer);
toast.textContent = message;
toast.classList.add("show");
toastTimer = setTimeout(() => toast.classList.remove("show"), 2300);
}
function setActiveLayer(layer) {
activeLayer = layer;
hoverCell = null;
hoverOutline.visible = false;
tooltip.classList.remove("visible");
renderer.domElement.style.cursor = "grab";
document.querySelectorAll("[data-layer]").forEach((button) => {
const selected = Number(button.dataset.layer) === activeLayer;
button.classList.toggle("active", selected);
button.setAttribute("aria-pressed", String(selected));
});
updateLayerAppearance();
}
function excavate(cell) {
if (!cell || cell.userData.sampled) return;
if (usedSamples >= MAX_SAMPLES) {
showToast("The 12-cell recovery limit has been reached.");
return;
}
cell.userData.sampled = true;
cell.userData.revealStart = performance.now();
usedSamples++;
const record = cell.userData.record;
if (record) {
record.observed = true;
record.observedAt = performance.now();
record.group.visible = true;
record.group.scale.setScalar(0.001);
} else {
const cavity = new THREE.Mesh(cavityGeometry, cavityMaterial);
cavity.position.set(cell.position.x, cell.position.y, 0);
layerGroups[cell.userData.layer].add(cavity);
cavities.push(cavity);
}
updateLayerAppearance();
updateUI();
if (record) {
showToast(`${record.id} recovered: abstract ${record.typeName.toLowerCase()}.`);
} else {
showToast("Cell uncovered — no fossil-bearing material.");
}
if (usedSamples === MAX_SAMPLES) {
setTimeout(
() => showToast("Sampling complete. Compare the observed subset with hidden positions."),
900
);
}
}
function resetExcavation() {
usedSamples = 0;
compareMode = false;
clearCavities();
cells.forEach((cell) => {
cell.userData.sampled = false;
cell.userData.revealStart = null;
cell.scale.setScalar(1);
});
fossils.forEach((record) => {
record.observed = false;
record.observedAt = 0;
record.group.visible = false;
record.group.scale.setScalar(0.001);
record.marker.visible = false;
});
updateLayerAppearance();
updateUI();
}
// -------------------------------------------------------------------------
// Camera controls implemented directly
// -------------------------------------------------------------------------
const target = new THREE.Vector3(0, -0.05, 0);
let cameraTheta = 0.63;
let cameraPhi = 1.02;
let cameraRadius = 12.1;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
target.x + cameraRadius * sinPhi * Math.cos(cameraTheta),
target.y + cameraRadius * Math.cos(cameraPhi),
target.z + cameraRadius * sinPhi * Math.sin(cameraTheta)
);
camera.lookAt(target);
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousX = 0;
let previousY = 0;
let dragDistance = 0;
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickCell(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const pickables = cells.filter(
(cell) =>
cell.userData.layer === activeLayer &&
!cell.userData.sampled
);
const hit = raycaster.intersectObjects(pickables, false)[0];
return hit ? hit.object : null;
}
function updateHover(event) {
const cell = pickCell(event);
hoverCell = cell;
if (!cell) {
hoverOutline.visible = false;
tooltip.classList.remove("visible");
renderer.domElement.style.cursor = "grab";
return;
}
hoverOutline.visible = true;
cell.getWorldPosition(hoverOutline.position);
renderer.domElement.style.cursor = "pointer";
const rect = viewport.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
tooltip.textContent =
`${String.fromCharCode(65 + cell.userData.col)}${HEIGHT - cell.userData.row}` +
` · L${cell.userData.layer + 1} · click to uncover`;
tooltip.style.left = `${x}px`;
tooltip.style.top = `${y}px`;
tooltip.classList.add("visible");
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerDown = true;
dragDistance = 0;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerDown) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi - dy * 0.006, 0.52, 1.46);
previousX = event.clientX;
previousY = event.clientY;
dragDistance = Math.hypot(
event.clientX - pointerStartX,
event.clientY - pointerStartY
);
updateCamera();
hoverOutline.visible = false;
tooltip.classList.remove("visible");
} else {
updateHover(event);
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointerDown) return;
pointerDown = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (dragDistance < 6) {
const cell = pickCell(event);
excavate(cell);
}
renderer.domElement.style.cursor = hoverCell ? "pointer" : "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!pointerDown) {
hoverCell = null;
hoverOutline.visible = false;
tooltip.classList.remove("visible");
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.008,
8.3,
18
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
document.getElementById("resetView").addEventListener("click", () => {
cameraTheta = 0.63;
cameraPhi = 1.02;
cameraRadius = 12.1;
updateCamera();
showToast("Camera reset.");
});
// -------------------------------------------------------------------------
// Panel controls
// -------------------------------------------------------------------------
document.querySelectorAll("[data-layer]").forEach((button) => {
button.addEventListener("click", () => {
setActiveLayer(Number(button.dataset.layer));
});
});
compareButton.addEventListener("click", () => {
compareMode = !compareMode;
updateUI();
showToast(
compareMode
? "Hidden fossil positions are now shown in amber."
: "Hidden positions concealed."
);
});
document.getElementById("resetSample").addEventListener("click", () => {
resetExcavation();
showToast("Excavation reset; the same synthetic block remains.");
});
document.getElementById("newButton").addEventListener("click", () => {
specimenSeed = (specimenSeed * 1664525 + 1013904223) >>> 0;
generateSpecimen(specimenSeed);
resetExcavation();
showToast("A new synthetic fossil arrangement has been generated.");
});
window.addEventListener("keydown", (event) => {
if (event.key === "1") setActiveLayer(0);
if (event.key === "2") setActiveLayer(1);
if (event.key === "3") setActiveLayer(2);
if (event.key.toLowerCase() === "c") {
compareMode = !compareMode;
updateUI();
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
function easeOutCubic(value) {
return 1 - Math.pow(1 - value, 3);
}
function animate(now) {
requestAnimationFrame(animate);
layerGroups.forEach((group, index) => {
const targetZ =
group.userData.baseZ + (index === activeLayer ? 0.34 : 0);
group.position.z = THREE.MathUtils.lerp(
group.position.z,
targetZ,
0.09
);
});
cells.forEach((cell) => {
const active = cell.userData.layer === activeLayer;
const sampled = cell.userData.sampled;
const targetOpacity = sampled
? 0.08
: active
? 0.96
: 0.13;
cell.material.opacity = THREE.MathUtils.lerp(
cell.material.opacity,
targetOpacity,
0.1
);
cell.material.color.lerp(cell.userData.targetColor, 0.09);
if (cell.userData.revealStart !== null) {
const progress = Math.min(
1,
(now - cell.userData.revealStart) / 420
);
const eased = easeOutCubic(progress);
cell.scale.setScalar(THREE.MathUtils.lerp(1, 0.18, eased));
if (progress >= 1) {
cell.userData.revealStart = null;
}
} else {
const targetScale = sampled ? 0.18 : 1;
const nextScale = THREE.MathUtils.lerp(
cell.scale.x,
targetScale,
0.12
);
cell.scale.setScalar(nextScale);
}
});
fossils.forEach((record) => {
if (!record.observed) return;
const progress = Math.min(
1,
(now - record.observedAt) / 520
);
const scale = Math.max(0.001, easeOutCubic(progress));
record.group.scale.setScalar(scale);
});
markerMaterial.opacity =
compareMode ? 0.24 + Math.sin(now * 0.004) * 0.08 : 0.24;
if (hoverCell) {
hoverCell.getWorldPosition(hoverOutline.position);
}
renderer.render(scene, camera);
}
// -------------------------------------------------------------------------
// Start
// -------------------------------------------------------------------------
generateSpecimen(specimenSeed);
resetExcavation();
requestAnimationFrame(animate);
</script>
</body>
</html>
```