Prompt specification
Build or customize the Three.js 3D scene "Diverging crust model on sliders" 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: Diverging crust model on sliders
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/diverging-crust-model-on-sliders-x1165
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing tectonic plate boundaries. Build two crust slabs separating above a rising central strip; show new surface formation schematically and keep the motion perpendicular to the boundary. Low-poly.
Working Three.js Starter (diverging-crust-model-on-sliders-x1165):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Divergent Plate Boundary — Three.js</title>
<style>
:root {
color-scheme: dark;
--text: #eef8f7;
--muted: #9db2b6;
--cyan: #69d5d0;
--orange: #ff7642;
--gold: #ffd166;
--panel: rgba(7, 19, 27, 0.76);
--border: rgba(153, 211, 213, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 38%, #173442 0%, #0b202c 38%, #061119 78%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
outline: none;
touch-action: none;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
box-shadow:
inset 0 0 130px rgba(0, 0, 0, 0.55),
inset 0 -100px 120px rgba(0, 0, 0, 0.25);
}
.heading {
position: fixed;
top: 26px;
left: 28px;
z-index: 5;
width: min(430px, calc(100vw - 56px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: var(--cyan);
box-shadow: 0 0 14px rgba(105, 213, 208, 0.7);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 48px);
font-weight: 670;
letter-spacing: -0.045em;
line-height: 1;
}
.heading p {
max-width: 390px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
position: fixed;
top: 27px;
right: 28px;
z-index: 5;
display: grid;
gap: 9px;
min-width: 194px;
padding: 14px 16px;
border: 1px solid var(--border);
border-radius: 13px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 15px 50px rgba(0, 0, 0, 0.22);
pointer-events: none;
}
.legend-title {
margin-bottom: 2px;
color: #d9e8e8;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 11px;
}
.swatch {
width: 17px;
height: 9px;
flex: 0 0 auto;
border-radius: 2px;
box-shadow: 0 0 10px rgba(255, 118, 66, 0.16);
}
.swatch.crust {
background: #917252;
}
.swatch.new {
background: #343b3e;
border: 1px solid #ff7642;
}
.swatch.mantle {
background: linear-gradient(90deg, #f04a25, #8f241c);
}
.orientation {
position: fixed;
bottom: 27px;
left: 28px;
z-index: 5;
display: flex;
align-items: center;
gap: 15px;
padding: 12px 15px;
border: 1px solid var(--border);
border-radius: 13px;
background: var(--panel);
backdrop-filter: blur(14px);
pointer-events: none;
}
.orientation-diagram {
position: relative;
width: 76px;
height: 48px;
flex: 0 0 auto;
}
.boundary-line {
position: absolute;
top: 2px;
bottom: 2px;
left: 37px;
border-left: 2px dashed rgba(255, 209, 102, 0.85);
}
.motion-line {
position: absolute;
top: 23px;
left: 8px;
width: 60px;
height: 2px;
background: var(--cyan);
}
.motion-line::before,
.motion-line::after {
position: absolute;
top: -4px;
width: 0;
height: 0;
content: "";
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
}
.motion-line::before {
left: -1px;
border-right: 8px solid var(--cyan);
}
.motion-line::after {
right: -1px;
border-left: 8px solid var(--cyan);
}
.orientation-copy strong {
display: block;
margin-bottom: 3px;
color: #e4eeee;
font-size: 11px;
font-weight: 700;
}
.orientation-copy span {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.controls {
position: fixed;
right: 28px;
bottom: 27px;
z-index: 6;
display: flex;
align-items: center;
gap: 8px;
}
button {
min-height: 38px;
padding: 0 13px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(9, 28, 38, 0.86);
color: #dbe9e9;
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(105, 213, 208, 0.5);
background: rgba(20, 49, 59, 0.94);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
button[aria-pressed="true"] {
border-color: rgba(105, 213, 208, 0.42);
color: var(--cyan);
}
.hint {
position: fixed;
bottom: 8px;
left: 50%;
z-index: 4;
color: rgba(191, 211, 214, 0.55);
font-size: 9px;
letter-spacing: 0.08em;
transform: translateX(-50%);
pointer-events: none;
white-space: nowrap;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
padding: 6px 9px;
border: 1px solid rgba(166, 211, 214, 0.25);
border-radius: 7px;
background: rgba(5, 17, 24, 0.77);
color: #eef9f8;
font-size: 9px;
font-weight: 760;
letter-spacing: 0.12em;
white-space: nowrap;
transform: translate(-50%, -50%);
backdrop-filter: blur(7px);
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}
.world-label::before {
display: inline-block;
width: 5px;
height: 5px;
margin-right: 7px;
border-radius: 50%;
content: "";
vertical-align: 1px;
background: var(--cyan);
}
.world-label.new-crust::before {
background: var(--orange);
box-shadow: 0 0 9px var(--orange);
}
.world-label.mantle::before {
background: #ff9d54;
box-shadow: 0 0 9px #ff9d54;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #07131c;
color: #a8c5c8;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 450ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.heading {
top: 18px;
left: 18px;
}
.heading p {
max-width: 290px;
font-size: 11px;
}
.legend {
top: auto;
right: 18px;
bottom: 67px;
min-width: 156px;
padding: 10px 12px;
}
.orientation {
bottom: 18px;
left: 18px;
padding: 9px 11px;
}
.orientation-diagram {
display: none;
}
.controls {
right: 18px;
bottom: 18px;
}
button {
min-height: 35px;
padding: 0 10px;
font-size: 10px;
}
.hint {
display: none;
}
.world-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div id="vignette"></div>
<div id="labels"></div>
<header class="heading">
<div class="eyebrow">Divergent plate boundary</div>
<h1>Rifting Lithosphere</h1>
<p>
Two crustal slabs pull apart perpendicular to the boundary.
Mantle material rises through the opening and cools into new crust.
</p>
</header>
<aside class="legend" aria-label="Scene legend">
<div class="legend-title">Material key</div>
<div class="legend-row">
<span class="swatch crust"></span>
Existing crust
</div>
<div class="legend-row">
<span class="swatch new"></span>
Newly formed crust
</div>
<div class="legend-row">
<span class="swatch mantle"></span>
Rising mantle
</div>
</aside>
<aside class="orientation" aria-label="Motion orientation">
<div class="orientation-diagram">
<span class="boundary-line"></span>
<span class="motion-line"></span>
</div>
<div class="orientation-copy">
<strong>Motion is perpendicular to the boundary</strong>
<span>Dashed line: boundary trend<br />Arrows: plate separation</span>
</div>
</aside>
<nav class="controls" aria-label="Scene controls">
<button id="pause" type="button" aria-pressed="false">Pause motion</button>
<button id="labels-toggle" type="button" aria-pressed="true">Labels</button>
<button id="reset" type="button">Reset view</button>
</nav>
<div class="hint">DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET</div>
<div id="loading">Loading tectonic model…</div>
<script type="module">
const loadingElement = document.getElementById("loading");
async function boot() {
// Only the Three.js core ES module is loaded.
const THREE = await import(
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"
);
const app = document.getElementById("app");
const labelContainer = document.getElementById("labels");
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07141d, 0.0175);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x07141d, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional divergent tectonic plate boundary"
);
app.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xb9e8ff, 0x3a1712, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe5c2, 3.0);
sun.position.set(7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x68c8ff, 1.35);
rim.position.set(-9, 6, -8);
scene.add(rim);
const magmaLight = new THREE.PointLight(0xff5427, 46, 15, 2);
magmaLight.position.set(0, 2.6, 1.2);
scene.add(magmaLight);
// ------------------------------------------------------------
// Utilities
// ------------------------------------------------------------
function seededRandom(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;
};
}
const random = seededRandom(72431);
function pushTriangle(positionArray, colorArray, a, b, c, color) {
positionArray.push(...a, ...b, ...c);
const converted = new THREE.Color(color);
for (let i = 0; i < 3; i++) {
colorArray.push(converted.r, converted.g, converted.b);
}
}
function createFacetedMesh(
positions,
colors,
options = {}
) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.94,
metalness: 0,
side: THREE.DoubleSide,
...options
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function addEdges(mesh, color = 0x8db1b7, opacity = 0.16) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 24),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(edges);
}
// ------------------------------------------------------------
// Deep mantle platform and floor
// ------------------------------------------------------------
const mantleBase = new THREE.Mesh(
new THREE.BoxGeometry(12.5, 0.8, 14.6),
new THREE.MeshStandardMaterial({
color: 0x271719,
roughness: 1,
flatShading: true
})
);
mantleBase.position.y = -4.55;
mantleBase.castShadow = true;
mantleBase.receiveShadow = true;
addEdges(mantleBase, 0x71382e, 0.28);
scene.add(mantleBase);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x07141b,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -4.98;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(
42,
42,
0x28515b,
0x142b34
);
grid.position.y = -4.965;
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
// ------------------------------------------------------------
// Existing crust slabs
// ------------------------------------------------------------
const plateWidth = 4.65;
const plateDepth = 13.0;
const plateCenter = 3.08;
const plateTop = 1.44;
function makeTopTiles(x0, x1, z0, z1, nx, nz, palette) {
const points = [];
const positions = [];
const colors = [];
const cellX = (x1 - x0) / nx;
const cellZ = (z1 - z0) / nz;
for (let j = 0; j <= nz; j++) {
const row = [];
for (let i = 0; i <= nx; i++) {
const interiorX = i > 0 && i < nx;
const interiorZ = j > 0 && j < nz;
const x =
x0 + i * cellX + (interiorX ? (random() - 0.5) * cellX * 0.38 : 0);
const z =
z0 + j * cellZ + (interiorZ ? (random() - 0.5) * cellZ * 0.38 : 0);
const y = plateTop + 0.022 + (random() - 0.5) * 0.045;
row.push([x, y, z]);
}
points.push(row);
}
for (let j = 0; j < nz; j++) {
for (let i = 0; i < nx; i++) {
const p00 = points[j][i];
const p10 = points[j][i + 1];
const p01 = points[j + 1][i];
const p11 = points[j + 1][i + 1];
const colorA = palette[Math.floor(random() * palette.length)];
const colorB = palette[Math.floor(random() * palette.length)];
if (random() > 0.5) {
pushTriangle(positions, colors, p00, p10, p11, colorA);
pushTriangle(positions, colors, p00, p11, p01, colorB);
} else {
pushTriangle(positions, colors, p00, p10, p01, colorA);
pushTriangle(positions, colors, p10, p11, p01, colorB);
}
}
}
return createFacetedMesh(positions, colors);
}
function styleArrow(arrow) {
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.92;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.96;
}
function makePlate(side) {
const group = new THREE.Group();
const x0 = side < 0 ? -plateCenter - plateWidth / 2 : plateCenter - plateWidth / 2;
const x1 = side < 0 ? -plateCenter + plateWidth / 2 : plateCenter + plateWidth / 2;
const lower = new THREE.Mesh(
new THREE.BoxGeometry(plateWidth, 1.8, plateDepth),
new THREE.MeshStandardMaterial({
color: 0x30373a,
roughness: 0.98,
flatShading: true
})
);
lower.position.y = 0.08;
lower.castShadow = true;
lower.receiveShadow = true;
addEdges(lower, 0xa08468, 0.13);
group.add(lower);
const upper = new THREE.Mesh(
new THREE.BoxGeometry(plateWidth, 0.46, plateDepth),
new THREE.MeshStandardMaterial({
color: 0x65513e,
roughness: 1,
flatShading: true
})
);
upper.position.y = 1.21;
upper.castShadow = true;
upper.receiveShadow = true;
addEdges(upper, 0xb5946f, 0.17);
group.add(upper);
const tileMesh = makeTopTiles(
x0,
x1,
-plateDepth / 2,
plateDepth / 2,
6,
12,
[0x927456, 0x765c44, 0xa1815c, 0x84694d, 0x695340]
);
group.add(tileMesh);
// Visible stratification on the front cut face.
const strataColors = [0x6d3d30, 0x8a4b33, 0x4d3530];
for (let i = 0; i < 3; i++) {
const stratum = new THREE.Mesh(
new THREE.BoxGeometry(plateWidth - 0.05, 0.11, 0.035),
new THREE.MeshStandardMaterial({
color: strataColors[i],
roughness: 1,
flatShading: true
})
);
stratum.position.set(0, -0.47 + i * 0.53, plateDepth / 2 + 0.02);
group.add(stratum);
}
// Outward arrows are children of each moving slab.
for (const z of [-3.8, 3.8]) {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(side, 0, 0),
new THREE.Vector3(side < 0 ? 1.25 : -1.25, 1.70, z),
2.05,
0xffd166,
0.36,
0.23
);
styleArrow(arrow);
group.add(arrow);
}
group.position.x = side * plateCenter;
scene.add(group);
return group;
}
const plateA = makePlate(-1);
const plateB = makePlate(1);
// ------------------------------------------------------------
// Rising central mantle wedge
// ------------------------------------------------------------
const plumePositions = [];
const plumeColors = [];
const profile = [
[-0.70, 1.42],
[0.00, 1.94],
[0.70, 1.42],
[0.30, -4.15],
[-0.30, -4.15]
];
const front = profile.map(([x, y]) => [x, y, 6.58]);
const back = profile.map(([x, y]) => [x, y, -6.58]);
const frontColors = [0xf15a2a, 0xc72e21, 0xff8a38];
const sideColors = [0x9f261f, 0xb93224, 0xe14a27];
// Front and back cross-sections.
pushTriangle(plumePositions, plumeColors, front[0], front[4], front[3], frontColors[0]);
pushTriangle(plumePositions, plumeColors, front[0], front[3], front[2], frontColors[1]);
pushTriangle(plumePositions, plumeColors, front[0], front[2], front[1], frontColors[2]);
pushTriangle(plumePositions, plumeColors, back[0], back[3], back[4], frontColors[0]);
pushTriangle(plumePositions, plumeColors, back[0], back[2], back[3], frontColors[1]);
pushTriangle(plumePositions, plumeColors, back[0], back[1], back[2], frontColors[2]);
// Faceted side walls.
for (let i = 0; i < profile.length; i++) {
const next = (i + 1) % profile.length;
const color = sideColors[i % sideColors.length];
pushTriangle(
plumePositions,
plumeColors,
front[i],
back[i],
back[next],
color
);
pushTriangle(
plumePositions,
plumeColors,
front[i],
back[next],
front[next],
color
);
}
const plume = createFacetedMesh(plumePositions, plumeColors, {
emissive: 0x4a0800,
emissiveIntensity: 0.5
});
scene.add(plume);
// ------------------------------------------------------------
// Newly formed ridge and molten fissure
// ------------------------------------------------------------
const ridgeRows = [];
const ridgePositions = [];
const ridgeColors = [];
const ridgeSegments = 13;
const ridgePalette = [
0x293238,
0x343a3c,
0x443b38,
0x202b30,
0x5d3027,
0x71402e
];
for (let j = 0; j <= ridgeSegments; j++) {
const z = -6.48 + (12.96 * j) / ridgeSegments;
const edgeY = 1.47 + (random() - 0.5) * 0.08;
const centerY = 1.91 + (random() - 0.5) * 0.12;
ridgeRows.push({
left: [-0.72, edgeY, z],
center: [0, centerY, z],
right: [0.72, edgeY, z]
});
}
for (let j = 0; j < ridgeSegments; j++) {
const a = ridgeRows[j];
const b = ridgeRows[j + 1];
pushTriangle(
ridgePositions,
ridgeColors,
a.left,
b.left,
a.center,
ridgePalette[Math.floor(random() * ridgePalette.length)]
);
pushTriangle(
ridgePositions,
ridgeColors,
b.left,
b.center,
a.center,
ridgePalette[Math.floor(random() * ridgePalette.length)]
);
pushTriangle(
ridgePositions,
ridgeColors,
a.center,
b.center,
b.right,
ridgePalette[Math.floor(random() * ridgePalette.length)]
);
pushTriangle(
ridgePositions,
ridgeColors,
a.center,
b.right,
a.right,
ridgePalette[Math.floor(random() * ridgePalette.length)]
);
}
const ridge = createFacetedMesh(ridgePositions, ridgeColors, {
emissive: 0x321008,
emissiveIntensity: 0.34
});
scene.add(ridge);
// A narrow, zig-zagging molten seam.
const seamPositions = [];
const seamColors = [];
for (let j = 0; j < ridgeSegments; j++) {
const p0 = ridgeRows[j].center;
const p1 = ridgeRows[j + 1].center;
const w0 = 0.075 + random() * 0.04;
const w1 = 0.075 + random() * 0.04;
const p0L = [p0[0] - w0, p0[1] + 0.035, p0[2]];
const p0R = [p0[0] + w0, p0[1] + 0.035, p0[2]];
const p1L = [p1[0] - w1, p1[1] + 0.035, p1[2]];
const p1R = [p1[0] + w1, p1[1] + 0.035, p1[2]];
pushTriangle(seamPositions, seamColors, p0L, p1L, p0R, 0xff5b24);
pushTriangle(seamPositions, seamColors, p0R, p1L, p1R, 0xffb13b);
}
const seamGeometry = new THREE.BufferGeometry();
seamGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(seamPositions, 3)
);
seamGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(seamColors, 3)
);
seamGeometry.computeVertexNormals();
const seamMaterial = new THREE.MeshBasicMaterial({
vertexColors: true,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.94
});
const seam = new THREE.Mesh(seamGeometry, seamMaterial);
scene.add(seam);
// Small faceted basalt fragments along the new ridge.
const chipGeometry = new THREE.TetrahedronGeometry(0.2, 0);
for (let i = 0; i < 9; i++) {
const chip = new THREE.Mesh(
chipGeometry,
new THREE.MeshStandardMaterial({
color: i % 4 === 0 ? 0x783b2a : 0x30373a,
roughness: 1,
flatShading: true
})
);
chip.position.set(
(i % 2 === 0 ? -1 : 1) * (0.18 + random() * 0.28),
1.62 + random() * 0.13,
-5.4 + i * 1.35 + random() * 0.45
);
chip.rotation.set(random(), random() * Math.PI, random());
chip.scale.set(1.2, 0.62, 1.35);
chip.castShadow = true;
scene.add(chip);
}
// ------------------------------------------------------------
// Boundary guides and upward mantle-flow arrow
// ------------------------------------------------------------
for (const x of [-0.72, 0.72]) {
const boundaryGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, 1.56, -6.4),
new THREE.Vector3(x, 1.56, 6.4)
]);
const boundary = new THREE.Line(
boundaryGeometry,
new THREE.LineDashedMaterial({
color: 0xffd98a,
dashSize: 0.27,
gapSize: 0.17,
transparent: true,
opacity: 0.9
})
);
boundary.computeLineDistances();
scene.add(boundary);
}
const upwellingArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0, -3.75, 6.72),
2.35,
0xff8c42,
0.4,
0.26
);
styleArrow(upwellingArrow);
scene.add(upwellingArrow);
// ------------------------------------------------------------
// Animated magma embers
// ------------------------------------------------------------
const emberCount = 15;
const emberGeometry = new THREE.IcosahedronGeometry(0.058, 0);
const emberMaterial = new THREE.MeshBasicMaterial({
color: 0xff8d3b
});
const embers = new THREE.InstancedMesh(
emberGeometry,
emberMaterial,
emberCount
);
embers.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
scene.add(embers);
const emberData = [];
for (let i = 0; i < emberCount; i++) {
emberData.push({
phase: random(),
speed: 0.12 + random() * 0.14,
x: (random() - 0.5) * 0.32,
z: -5.7 + random() * 11.4,
size: 0.55 + random() * 1.0
});
}
const dummy = new THREE.Object3D();
// ------------------------------------------------------------
// World-space labels
// ------------------------------------------------------------
const labelDefinitions = [
{
id: "plate-a",
text: "PLATE A",
className: "plate-a",
offset: [-45, -8],
anchor: () =>
new THREE.Vector3(plateA.position.x - 0.45, 1.72, 2.3)
},
{
id: "plate-b",
text: "PLATE B",
className: "plate-b",
offset: [45, -8],
anchor: () =>
new THREE.Vector3(plateB.position.x + 0.45, 1.72, 2.3)
},
{
id: "new-crust",
text: "NEW CRUST",
className: "new-crust",
offset: [0, -32],
anchor: () => new THREE.Vector3(0, 2.15, -1.15)
},
{
id: "mantle",
text: "RISING MANTLE",
className: "mantle",
offset: [78, 0],
anchor: () => new THREE.Vector3(0, -2.25, 6.72)
}
];
for (const definition of labelDefinitions) {
const element = document.createElement("div");
element.className = `world-label ${definition.className}`;
element.textContent = definition.text;
labelContainer.appendChild(element);
definition.element = element;
}
const projected = new THREE.Vector3();
function updateLabels() {
for (const definition of labelDefinitions) {
projected.copy(definition.anchor()).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
definition.element.style.opacity = visible ? "1" : "0";
const x =
(projected.x * 0.5 + 0.5) * window.innerWidth +
definition.offset[0];
const y =
(-projected.y * 0.5 + 0.5) * window.innerHeight +
definition.offset[1];
definition.element.style.left = `${x}px`;
definition.element.style.top = `${y}px`;
}
}
// ------------------------------------------------------------
// Direct camera controls: orbit and zoom, no external addons
// ------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, -0.45, 0),
radius: 19.2,
theta: 0.73,
phi: 1.02
};
function applyCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.target.set(0, -0.45, 0);
orbit.radius = 19.2;
orbit.theta = 0.73;
orbit.phi = 1.02;
applyCamera();
}
applyCamera();
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.005,
0.3,
1.48
);
applyCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"pointerleave",
() => {
if (dragging) stopDragging();
}
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
10,
29
);
applyCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.style.cursor = "grab";
// ------------------------------------------------------------
// UI buttons and keyboard controls
// ------------------------------------------------------------
let paused = false;
let labelsVisible = true;
const pauseButton = document.getElementById("pause");
const labelsButton = document.getElementById("labels-toggle");
const resetButton = document.getElementById("reset");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume motion" : "Pause motion";
pauseButton.setAttribute("aria-pressed", String(paused));
});
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelContainer.style.display = labelsVisible ? "block" : "none";
labelsButton.setAttribute("aria-pressed", String(labelsVisible));
});
resetButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
let simulationTime = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
simulationTime += delta;
}
// A periodic separation cycle keeps the model centered.
const cycle = (simulationTime % 10) / 10;
const easedCycle = 0.5 - 0.5 * Math.cos(cycle * Math.PI * 2);
const separation = 0.025 + easedCycle * 0.25;
plateA.position.x = -plateCenter - separation;
plateB.position.x = plateCenter + separation;
// Magma pulse.
const pulse = 0.5 + 0.5 * Math.sin(simulationTime * 3.1);
magmaLight.intensity = 37 + pulse * 14;
seamMaterial.opacity = 0.78 + pulse * 0.2;
ridge.material.emissiveIntensity = 0.28 + pulse * 0.13;
// Rising faceted embers.
for (let i = 0; i < emberCount; i++) {
const data = emberData[i];
const progress = (data.phase + simulationTime * data.speed) % 1;
dummy.position.set(
data.x + Math.sin(simulationTime * 2.1 + i) * 0.12,
1.85 + progress * 1.65,
data.z + Math.sin(progress * Math.PI * 2) * 0.12
);
const scale = data.size * (0.65 + (1 - progress) * 0.55);
dummy.scale.setScalar(scale);
dummy.rotation.set(
simulationTime * 0.7 + i,
simulationTime + i * 0.4,
0
);
dummy.updateMatrix();
embers.setMatrixAt(i, dummy.matrix);
}
embers.instanceMatrix.needsUpdate = true;
upwellingArrow.setLength(
2.25 + pulse * 0.25,
0.4,
0.26
);
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
loadingElement.classList.add("hidden");
});
}
boot().catch((error) => {
console.error(error);
loadingElement.textContent =
"Unable to load the Three.js scene. Check your connection and WebGL support.";
loadingElement.style.padding = "0 24px";
loadingElement.style.textAlign = "center";
});
</script>
</body>
</html>
```