Prompt specification
Build or customize the Three.js 3D scene "Burial sequence preservation box" 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: Burial sequence preservation box
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/burial-sequence-preservation-box-x1146
Scene Description Prompt:
Bury a stylized shell in sediment, then expose its impression through simplified fossil-preservation stages. One HTML scene with Three.js from cdnjs.
Working Three.js Starter (burial-sequence-preservation-box-x1146):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Burial to Trace — Fossil Preservation</title>
<style>
:root {
color-scheme: dark;
--ink: #e8f0ed;
--muted: #8da39e;
--accent: #74d4d2;
--sand: #d6ad75;
--panel: rgba(8, 18, 22, 0.78);
--line: rgba(160, 209, 202, 0.2);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071015;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.brand {
position: absolute;
top: 28px;
left: 32px;
max-width: 430px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
color: var(--accent);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 1px;
content: "";
background: currentColor;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 5vw, 66px);
font-weight: 400;
line-height: 0.94;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 390px;
margin: 16px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.transport {
position: absolute;
top: 27px;
right: 28px;
width: min(420px, calc(100vw - 56px));
padding: 16px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
backdrop-filter: blur(16px);
pointer-events: auto;
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.24);
}
.transport-row {
display: flex;
align-items: center;
gap: 10px;
}
button {
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(116, 212, 210, 0.08);
color: var(--ink);
font: inherit;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
button:hover {
border-color: rgba(116, 212, 210, 0.55);
background: rgba(116, 212, 210, 0.16);
}
button:active {
transform: scale(0.96);
}
#play {
width: 42px;
height: 42px;
flex: 0 0 auto;
color: var(--accent);
font-size: 16px;
}
#restart {
width: 42px;
height: 42px;
flex: 0 0 auto;
font-size: 18px;
}
.timeline {
min-width: 0;
flex: 1;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 999px;
outline: none;
background:
linear-gradient(
to right,
var(--accent) 0 var(--progress, 0%),
rgba(255, 255, 255, 0.12) var(--progress, 0%) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 2px solid #081216;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #081216;
border-radius: 50%;
background: var(--accent);
}
.time-row {
display: flex;
justify-content: space-between;
margin-top: 8px;
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
letter-spacing: 0.08em;
}
.stage-card {
position: absolute;
left: 32px;
bottom: 30px;
display: grid;
grid-template-columns: 48px 1fr;
width: min(430px, calc(100vw - 64px));
overflow: hidden;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
backdrop-filter: blur(16px);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
}
.stage-number {
display: grid;
place-items: center;
border-right: 1px solid var(--line);
color: var(--accent);
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
}
.stage-copy {
padding: 16px 18px 17px;
}
.stage-label {
margin-bottom: 5px;
color: var(--accent);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
#stage-title {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
font-weight: 400;
}
#stage-description {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.chapters {
position: absolute;
right: 30px;
bottom: 31px;
width: 208px;
margin: 0;
padding: 0;
list-style: none;
pointer-events: auto;
}
.chapters li {
position: relative;
display: grid;
grid-template-columns: 25px 1fr;
gap: 8px;
align-items: center;
min-height: 31px;
color: rgba(218, 232, 228, 0.38);
cursor: pointer;
font-size: 11px;
transition: color 200ms ease;
}
.chapters li:hover,
.chapters li.active {
color: var(--ink);
}
.chapters li::after {
position: absolute;
top: 23px;
bottom: -7px;
left: 7px;
width: 1px;
content: "";
background: rgba(160, 209, 202, 0.16);
}
.chapters li:last-child::after {
display: none;
}
.chapter-dot {
position: relative;
z-index: 1;
display: grid;
width: 15px;
height: 15px;
place-items: center;
border: 1px solid rgba(160, 209, 202, 0.3);
border-radius: 50%;
background: #0a1519;
color: transparent;
font-size: 8px;
}
.chapters li.active .chapter-dot {
border-color: var(--accent);
background: var(--accent);
color: #071015;
}
.hint {
position: absolute;
right: 30px;
top: 145px;
color: rgba(184, 205, 200, 0.46);
font-size: 10px;
line-height: 1.6;
text-align: right;
}
#reset-view {
margin-top: 8px;
padding: 6px 9px;
color: rgba(216, 235, 231, 0.72);
font-size: 10px;
}
#loader {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #071015;
color: var(--accent);
font-size: 11px;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loader.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 20px;
left: 20px;
}
h1 {
font-size: 39px;
}
.subtitle {
display: none;
}
.transport {
top: auto;
right: 16px;
bottom: 185px;
width: calc(100vw - 32px);
}
.stage-card {
left: 16px;
bottom: 16px;
width: calc(100vw - 32px);
}
.chapters,
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive fossil burial and preservation scene"></canvas>
<div class="hud">
<header class="brand">
<div class="eyebrow">Field model · simplified process</div>
<h1>Burial<br />to Trace</h1>
<p class="subtitle">
Follow a stylized shell through rapid burial, compaction, excavation,
and mineral replacement.
</p>
</header>
<section class="transport" aria-label="Animation controls">
<div class="transport-row">
<button id="play" title="Play or pause" aria-label="Pause">Ⅱ</button>
<button id="restart" title="Restart" aria-label="Restart">↺</button>
<div class="timeline">
<input
id="progress"
type="range"
min="0"
max="1000"
value="0"
aria-label="Fossil preservation timeline"
/>
<div class="time-row">
<span id="current-time">00:00</span>
<span>00:20</span>
</div>
</div>
</div>
</section>
<section class="stage-card" aria-live="polite">
<div id="stage-number" class="stage-number">01</div>
<div class="stage-copy">
<div class="stage-label">Preservation stage</div>
<h2 id="stage-title">A shell at rest</h2>
<p id="stage-description">
A ridged bivalve settles onto a fresh layer of sediment.
</p>
</div>
</section>
<ol id="chapters" class="chapters">
<li class="active" data-time="0"><span class="chapter-dot">1</span><span>Surface shell</span></li>
<li data-time="0.15"><span class="chapter-dot">2</span><span>Rapid burial</span></li>
<li data-time="0.43"><span class="chapter-dot">3</span><span>Compaction</span></li>
<li data-time="0.67"><span class="chapter-dot">4</span><span>Excavation</span></li>
<li data-time="0.86"><span class="chapter-dot">5</span><span>Mineralization</span></li>
</ol>
<div class="hint">
Drag to orbit · Wheel to zoom<br />Right-drag to pan
<br />
<button id="reset-view">Reset camera</button>
</div>
</div>
<div id="loader">Preparing sediment…</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.querySelector("#scene");
const progress = document.querySelector("#progress");
const playButton = document.querySelector("#play");
const restartButton = document.querySelector("#restart");
const resetViewButton = document.querySelector("#reset-view");
const chapterItems = [...document.querySelectorAll("#chapters li")];
const stageNumber = document.querySelector("#stage-number");
const stageTitle = document.querySelector("#stage-title");
const stageDescription = document.querySelector("#stage-description");
const currentTime = document.querySelector("#current-time");
const stages = [
{
at: 0,
title: "A shell at rest",
description:
"A ridged bivalve settles onto a fresh layer of sediment."
},
{
at: 0.15,
title: "Rapid burial",
description:
"Loose grains cover the shell, isolating it from oxygen and disturbance."
},
{
at: 0.43,
title: "Compaction",
description:
"Burial pressure compresses the layers and preserves the shell’s outline."
},
{
at: 0.67,
title: "Excavation",
description:
"Erosion removes the overlying sediment, exposing the buried form."
},
{
at: 0.86,
title: "Mineralization",
description:
"Dissolved minerals fill the cavity, leaving a durable cast and shell-shaped mold."
}
];
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071015);
scene.fog = new THREE.FogExp2(0x071015, 0.026);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, -0.15, 0);
const initialCameraPosition = new THREE.Vector3(7.1, 5.25, 8.0);
camera.position.copy(initialCameraPosition);
camera.lookAt(cameraTarget);
const hemisphere = new THREE.HemisphereLight(0xc9e8ef, 0x392519, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffd8aa, 3.8);
keyLight.position.set(5.5, 8.5, 4.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x70d4d2, 2.25);
rimLight.position.set(-6, 3.5, -5);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0xffbd7a, 18, 11, 2);
fillLight.position.set(-3, 2.5, 4);
scene.add(fillLight);
function randomGenerator(seed) {
return function () {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function makeSandTexture(r, g, b, seed) {
const size = 256;
const textureCanvas = document.createElement("canvas");
textureCanvas.width = textureCanvas.height = size;
const ctx = textureCanvas.getContext("2d");
const random = randomGenerator(seed);
ctx.fillStyle = `rgb(${r},${g},${b})`;
ctx.fillRect(0, 0, size, size);
for (let i = 0; i < 9500; i++) {
const shade = Math.floor((random() - 0.5) * 44);
ctx.fillStyle = `rgba(${r + shade},${g + shade},${b + shade},${0.18 + random() * 0.28})`;
const s = 0.4 + random() * 1.7;
ctx.fillRect(random() * size, random() * size, s, s);
}
for (let i = 0; i < 22; i++) {
ctx.strokeStyle = `rgba(255,235,195,${0.025 + random() * 0.04})`;
ctx.lineWidth = 0.5 + random();
ctx.beginPath();
const y = random() * size;
ctx.moveTo(0, y);
ctx.bezierCurveTo(
size * 0.3,
y + (random() - 0.5) * 8,
size * 0.7,
y + (random() - 0.5) * 8,
size,
y + (random() - 0.5) * 5
);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(textureCanvas);
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(3.2, 2.5);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeShellTexture() {
const size = 256;
const textureCanvas = document.createElement("canvas");
textureCanvas.width = textureCanvas.height = size;
const ctx = textureCanvas.getContext("2d");
const random = randomGenerator(51);
ctx.fillStyle = "#e7deca";
ctx.fillRect(0, 0, size, size);
for (let i = 0; i < 5000; i++) {
const alpha = random() * 0.16;
ctx.fillStyle = `rgba(85,67,42,${alpha})`;
ctx.fillRect(random() * size, random() * size, 1, 1);
}
for (let i = 0; i < 18; i++) {
ctx.strokeStyle = `rgba(105,83,52,${0.08 + random() * 0.09})`;
ctx.lineWidth = 1 + random() * 2;
ctx.beginPath();
const x = (i / 18) * size;
ctx.moveTo(x, 0);
ctx.quadraticCurveTo(
x + (random() - 0.5) * 12,
size * 0.5,
x + (random() - 0.5) * 20,
size
);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(35, 35),
new THREE.MeshStandardMaterial({
color: 0x081116,
roughness: 0.98,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.08;
floor.receiveShadow = true;
scene.add(floor);
const sedimentGroup = new THREE.Group();
scene.add(sedimentGroup);
const strata = [
{
size: [7.0, 0.55, 5.4],
position: [0, -0.78, 0],
color: [108, 73, 46],
seed: 4
},
{
size: [6.9, 0.31, 5.3],
position: [0, -0.35, 0],
color: [139, 99, 62],
seed: 8
},
{
size: [6.75, 0.24, 5.15],
position: [0, -0.08, 0],
color: [166, 126, 82],
seed: 12
}
];
for (const layer of strata) {
const geometry = new THREE.BoxGeometry(...layer.size);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
map: makeSandTexture(...layer.color, layer.seed),
roughness: 1,
metalness: 0
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...layer.position);
mesh.castShadow = true;
mesh.receiveShadow = true;
sedimentGroup.add(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
new THREE.LineBasicMaterial({
color: 0xf0cc94,
transparent: true,
opacity: 0.13
})
);
edges.position.copy(mesh.position);
sedimentGroup.add(edges);
}
const coverGeometry = new THREE.BoxGeometry(3.32, 0.82, 5.05);
coverGeometry.translate(0, 0.41, 0);
const coverMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
map: makeSandTexture(177, 138, 91, 21),
roughness: 1,
transparent: true,
opacity: 1
});
const coverHalves = [-1, 1].map((side) => {
const mesh = new THREE.Mesh(coverGeometry, coverMaterial);
mesh.position.set(side * 1.66, 0.04, 0);
mesh.scale.y = 0.001;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.visible = false;
sedimentGroup.add(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(coverGeometry),
new THREE.LineBasicMaterial({
color: 0xf2d29d,
transparent: true,
opacity: 0.14
})
);
edges.position.copy(mesh.position);
edges.scale.copy(mesh.scale);
edges.visible = false;
sedimentGroup.add(edges);
return { mesh, edges, side };
});
const pebbleRandom = randomGenerator(95);
const pebbleGeometry = new THREE.IcosahedronGeometry(1, 1);
for (let i = 0; i < 26; i++) {
const pebbleMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color().setHSL(
0.09,
0.2 + pebbleRandom() * 0.14,
0.24 + pebbleRandom() * 0.18
),
roughness: 1,
flatShading: true
});
const pebble = new THREE.Mesh(pebbleGeometry, pebbleMaterial);
const angle = pebbleRandom() * Math.PI * 2;
const radius = 3.55 + pebbleRandom() * 1.8;
const size = 0.05 + pebbleRandom() * 0.13;
pebble.position.set(
Math.cos(angle) * radius,
-0.01 + size * 0.3,
Math.sin(angle) * radius * 0.72
);
pebble.scale.set(size * (0.7 + pebbleRandom()), size, size);
pebble.rotation.set(
pebbleRandom() * Math.PI,
pebbleRandom() * Math.PI,
pebbleRandom() * Math.PI
);
pebble.castShadow = true;
pebble.receiveShadow = true;
scene.add(pebble);
}
function shellPoint(u, v, top = true) {
const across = v * 2 - 1;
const theta = -1.38 + across * 1.38;
const x =
across *
1.92 *
(0.43 + u * 0.57) *
(0.92 + 0.08 * Math.cos(theta * 2));
const z =
1.05 -
u * 2.2 +
0.1 * Math.cos(theta * 2) * u;
if (!top) {
return new THREE.Vector3(
x,
-0.014 - 0.036 * Math.sin(Math.PI * u),
z
);
}
const envelope =
Math.pow(Math.sin(Math.PI * u), 0.72) *
(1 - 0.35 * Math.pow(Math.abs(across), 2));
const ribs =
0.027 *
Math.cos(across * Math.PI * 14) *
u *
Math.pow(Math.sin(Math.PI * u), 0.18);
const y = 0.025 + 0.62 * envelope + ribs;
return new THREE.Vector3(x, y, z);
}
function createShellGeometry() {
const radialSegments = 34;
const angularSegments = 58;
const positions = [];
const uvs = [];
const indices = [];
for (let layer = 0; layer < 2; layer++) {
const base = layer * (radialSegments + 1) * (angularSegments + 1);
for (let i = 0; i <= radialSegments; i++) {
const u = i / radialSegments;
for (let j = 0; j <= angularSegments; j++) {
const v = j / angularSegments;
const point = shellPoint(u, v, layer === 0);
positions.push(point.x, point.y, point.z);
uvs.push(v, u);
}
}
for (let i = 0; i < radialSegments; i++) {
for (let j = 0; j < angularSegments; j++) {
const a = base + i * (angularSegments + 1) + j;
const b = a + 1;
const c = a + angularSegments + 1;
const d = c + 1;
if (layer === 0) {
indices.push(a, b, c, b, d, c);
} else {
indices.push(a, c, b, b, c, d);
}
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
const shellGeometry = createShellGeometry();
const shellTexture = makeShellTexture();
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0xd39a58,
map: shellTexture,
roughness: 0.66,
metalness: 0,
transparent: true,
opacity: 1,
side: THREE.DoubleSide
});
const shellGroup = new THREE.Group();
shellGroup.position.y = 0.06;
shellGroup.rotation.y = 0.045;
scene.add(shellGroup);
const shellMesh = new THREE.Mesh(shellGeometry, shellMaterial);
shellMesh.castShadow = true;
shellMesh.receiveShadow = true;
shellGroup.add(shellMesh);
const ribMaterial = new THREE.LineBasicMaterial({
color: 0x70452d,
transparent: true,
opacity: 0.34
});
for (let rib = 0; rib <= 14; rib++) {
const v = rib / 14;
const points = [];
for (let i = 1; i <= 36; i++) {
const u = i / 36;
const point = shellPoint(u, v, true);
point.y += 0.012;
points.push(point);
}
const ribLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
ribMaterial
);
shellGroup.add(ribLine);
}
const hingeMaterial = new THREE.MeshStandardMaterial({
color: 0x9d683b,
roughness: 0.75
});
const hinge = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 1.68, 12),
hingeMaterial
);
hinge.rotation.z = Math.PI / 2;
hinge.position.set(0, 0.055, 1.04);
hinge.castShadow = true;
shellGroup.add(hinge);
const impressionMaterial = new THREE.MeshStandardMaterial({
color: 0x3c281d,
roughness: 1,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -1
});
const impressionGroup = new THREE.Group();
impressionGroup.position.y = 0.054;
impressionGroup.rotation.y = 0.045;
impressionGroup.scale.y = 0.012;
impressionGroup.visible = false;
scene.add(impressionGroup);
const impressionMesh = new THREE.Mesh(
shellGeometry,
impressionMaterial
);
impressionGroup.add(impressionMesh);
function createShellContour(scaleXZ, opacity) {
const points = [];
for (let i = 0; i <= 28; i++) {
const point = shellPoint(i / 28, 0, true);
point.x *= scaleXZ;
point.z = (point.z + 0.05) * scaleXZ - 0.05;
point.y = 0.068;
points.push(point);
}
for (let i = 1; i <= 38; i++) {
const point = shellPoint(1, i / 38, true);
point.x *= scaleXZ;
point.z = (point.z + 0.05) * scaleXZ - 0.05;
point.y = 0.068;
points.push(point);
}
for (let i = 1; i <= 28; i++) {
const point = shellPoint(1 - i / 28, 1, true);
point.x *= scaleXZ;
point.z = (point.z + 0.05) * scaleXZ - 0.05;
point.y = 0.068;
points.push(point);
}
const material = new THREE.LineBasicMaterial({
color: 0x342019,
transparent: true,
opacity,
depthWrite: false
});
const contour = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
material
);
contour.visible = false;
scene.add(contour);
return contour;
}
const contours = [
createShellContour(1.0, 0),
createShellContour(0.86, 0),
createShellContour(0.7, 0)
];
const castMaterial = new THREE.MeshStandardMaterial({
color: 0xe5d9b9,
roughness: 0.72,
metalness: 0,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const castGroup = new THREE.Group();
castGroup.position.y = -0.2;
castGroup.rotation.y = 0.045;
castGroup.scale.set(1.015, 0.55, 1.015);
castGroup.visible = false;
scene.add(castGroup);
const castMesh = new THREE.Mesh(shellGeometry, castMaterial);
castMesh.castShadow = true;
castGroup.add(castMesh);
const grainCount = 300;
const grainPositions = new Float32Array(grainCount * 3);
const grainGeometry = new THREE.BufferGeometry();
grainGeometry.setAttribute(
"position",
new THREE.BufferAttribute(grainPositions, 3)
);
const grainMaterial = new THREE.PointsMaterial({
color: 0xd6ad75,
size: 0.043,
transparent: true,
opacity: 0,
depthWrite: false,
sizeAttenuation: true
});
const grains = new THREE.Points(grainGeometry, grainMaterial);
grains.frustumCulled = false;
scene.add(grains);
const grainRandom = randomGenerator(220);
const grainData = Array.from({ length: grainCount }, () => ({
x: (grainRandom() - 0.5) * 6.3,
z: (grainRandom() - 0.5) * 4.8,
phase: grainRandom(),
speed: 0.65 + grainRandom() * 0.8,
drift: (grainRandom() - 0.5) * 0.35
}));
const waveMaterial = new THREE.MeshBasicMaterial({
color: 0x78e0db,
transparent: true,
opacity: 0,
depthWrite: false
});
const compressionWave = new THREE.Mesh(
new THREE.BoxGeometry(6.45, 0.022, 0.055),
waveMaterial
);
compressionWave.position.y = 0.92;
compressionWave.visible = false;
scene.add(compressionWave);
const initialShellColor = new THREE.Color(0xd39a58);
const compactedShellColor = new THREE.Color(0x9b6846);
const mineralShellColor = new THREE.Color(0xe4d9bb);
let timeline = 0;
let playing = true;
let lastTime = performance.now();
let activeStage = -1;
const clamp01 = (value) => Math.min(1, Math.max(0, value));
function smoothstep(edge0, edge1, value) {
const x = clamp01((value - edge0) / (edge1 - edge0));
return x * x * (3 - 2 * x);
}
function updateScene(t) {
const burial = smoothstep(0.13, 0.43, t);
const compaction = smoothstep(0.42, 0.65, t);
const excavation = smoothstep(0.65, 0.87, t);
const mineralization = smoothstep(0.84, 0.99, t);
for (const half of coverHalves) {
half.mesh.visible = burial > 0.002;
half.edges.visible = burial > 0.002;
half.mesh.scale.y = Math.max(
0.001,
burial * (1 - 0.12 * compaction)
);
half.mesh.position.x =
half.side * (1.66 + excavation * 2.05);
half.mesh.position.y =
0.04 - compaction * 0.075 - excavation * 0.035;
half.edges.position.copy(half.mesh.position);
half.edges.scale.copy(half.mesh.scale);
}
const coverOpacity = 1 - smoothstep(0.91, 1, t) * 0.73;
coverMaterial.opacity = coverOpacity;
coverMaterial.depthWrite = coverOpacity > 0.97;
shellGroup.position.y = 0.06 - burial * 0.3 + excavation * 0.015;
shellGroup.rotation.y = 0.045 + burial * 0.025;
shellGroup.scale.y = 1 - compaction * 0.17;
const shellColor = initialShellColor
.clone()
.lerp(compactedShellColor, compaction * 0.82)
.lerp(mineralShellColor, mineralization);
shellMaterial.color.copy(shellColor);
shellMaterial.opacity = 1 - mineralization * 0.84;
shellMaterial.depthWrite = mineralization < 0.25;
ribMaterial.opacity = 0.34 * (1 - mineralization * 0.94);
impressionGroup.visible = mineralization > 0.001;
impressionMaterial.opacity =
smoothstep(0.82, 0.96, t) * 0.96;
contours.forEach((contour, index) => {
contour.visible = mineralization > 0.001;
contour.material.opacity =
smoothstep(0.84 + index * 0.025, 0.97 + index * 0.015, t) *
(0.44 - index * 0.1);
});
castGroup.visible = mineralization > 0.001;
castMaterial.opacity = smoothstep(0.86, 0.99, t) * 0.94;
castGroup.position.y = -0.2 + mineralization * 0.035;
const grainVisible = t > 0.12 && t < 0.47;
grains.visible = grainVisible;
if (grainVisible) {
const grainTime = Math.max(0, t - 0.12);
grainData.forEach((grain, index) => {
const fall = (grain.phase + grainTime * grain.speed) % 1;
const offset = index * 3;
grainPositions[offset] =
grain.x +
Math.sin(fall * 7 + grain.phase * 12) * 0.16 +
grain.drift * fall;
grainPositions[offset + 1] = 1.55 - fall * 1.85;
grainPositions[offset + 2] =
grain.z + Math.cos(fall * 6 + grain.phase * 9) * 0.12;
});
grainGeometry.attributes.position.needsUpdate = true;
grainMaterial.opacity =
smoothstep(0.12, 0.18, t) *
(1 - smoothstep(0.38, 0.47, t)) *
0.72;
}
const wavePhase = (t - 0.42) / 0.24;
compressionWave.visible = wavePhase > 0 && wavePhase < 1;
if (compressionWave.visible) {
compressionWave.position.z = 2.55 - wavePhase * 5.1;
compressionWave.position.y = 0.9 - wavePhase * 0.055;
waveMaterial.opacity = Math.sin(wavePhase * Math.PI) * 0.66;
}
let stageIndex = 0;
for (let i = 0; i < stages.length; i++) {
if (t >= stages[i].at) {
stageIndex = i;
}
}
if (stageIndex !== activeStage) {
activeStage = stageIndex;
const stage = stages[stageIndex];
stageNumber.textContent = String(stageIndex + 1).padStart(2, "0");
stageTitle.textContent = stage.title;
stageDescription.textContent = stage.description;
chapterItems.forEach((item, index) => {
item.classList.toggle("active", index === stageIndex);
});
}
progress.value = String(Math.round(t * 1000));
progress.style.setProperty("--progress", `${t * 100}%`);
const seconds = Math.floor(t * 20);
currentTime.textContent = `00:${String(seconds).padStart(2, "0")}`;
}
function setPlaying(value) {
playing = value;
playButton.textContent = playing ? "Ⅱ" : "▶";
playButton.setAttribute(
"aria-label",
playing ? "Pause" : "Play"
);
}
playButton.addEventListener("click", () => {
if (!playing && timeline >= 0.999) {
timeline = 0;
}
setPlaying(!playing);
});
restartButton.addEventListener("click", () => {
timeline = 0;
setPlaying(true);
});
progress.addEventListener("input", () => {
timeline = Number(progress.value) / 1000;
setPlaying(false);
updateScene(timeline);
});
chapterItems.forEach((item) => {
item.addEventListener("click", () => {
timeline = Number(item.dataset.time);
setPlaying(false);
updateScene(timeline);
});
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.code === "ArrowRight") {
timeline = Math.min(1, timeline + 0.025);
setPlaying(false);
}
if (event.code === "ArrowLeft") {
timeline = Math.max(0, timeline - 0.025);
setPlaying(false);
}
});
// Camera controls are implemented directly without Three.js addons.
const orbit = {
radius: camera.position.distanceTo(cameraTarget),
theta: Math.atan2(
camera.position.x - cameraTarget.x,
camera.position.z - cameraTarget.z
),
phi: Math.acos(
THREE.MathUtils.clamp(
(camera.position.y - cameraTarget.y) /
camera.position.distanceTo(cameraTarget),
-1,
1
)
)
};
const pointer = {
active: false,
id: null,
button: 0,
x: 0,
y: 0
};
const cameraOffset = new THREE.Vector3();
const cameraDirection = new THREE.Vector3();
const cameraRight = new THREE.Vector3();
function updateCamera() {
orbit.phi = THREE.MathUtils.clamp(orbit.phi, 0.24, 1.46);
orbit.radius = THREE.MathUtils.clamp(orbit.radius, 5.2, 16);
cameraOffset.setFromSpherical(
new THREE.Spherical(orbit.radius, orbit.phi, orbit.theta)
);
camera.position.copy(cameraTarget).add(cameraOffset);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraTarget.set(0, -0.15, 0);
orbit.radius = initialCameraPosition.distanceTo(cameraTarget);
orbit.theta = Math.atan2(
initialCameraPosition.x - cameraTarget.x,
initialCameraPosition.z - cameraTarget.z
);
orbit.phi = Math.acos(
THREE.MathUtils.clamp(
(initialCameraPosition.y - cameraTarget.y) / orbit.radius,
-1,
1
)
);
updateCamera();
}
resetViewButton.addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.button = event.button;
pointer.x = event.clientX;
pointer.y = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) {
return;
}
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.button === 0) {
orbit.theta -= dx * 0.005;
orbit.phi -= dy * 0.0045;
} else {
camera.getWorldDirection(cameraDirection);
cameraRight
.crossVectors(cameraDirection, camera.up)
.normalize();
const panScale = orbit.radius * 0.00125;
cameraTarget.addScaledVector(cameraRight, -dx * panScale);
cameraTarget.y += dy * panScale;
cameraTarget.x = THREE.MathUtils.clamp(
cameraTarget.x,
-2.4,
2.4
);
cameraTarget.y = THREE.MathUtils.clamp(
cameraTarget.y,
-1,
1.2
);
cameraTarget.z = THREE.MathUtils.clamp(
cameraTarget.z,
-2.4,
2.4
);
}
updateCamera();
});
function stopPointer(event) {
if (event.pointerId !== pointer.id) {
return;
}
pointer.active = false;
pointer.id = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", stopPointer);
canvas.addEventListener("pointercancel", stopPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
function animate(now) {
const delta = Math.min(0.05, (now - lastTime) / 1000);
lastTime = now;
if (playing) {
timeline += delta / 20;
if (timeline >= 1) {
timeline = 1;
setPlaying(false);
}
}
updateScene(timeline);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateScene(0);
updateCamera();
renderer.render(scene, camera);
document.querySelector("#loader").classList.add("hidden");
setTimeout(() => document.querySelector("#loader").remove(), 600);
requestAnimationFrame(animate);
</script>
</body>
</html>
```