Prompt specification
Build or customize the Three.js 3D scene "Plate-motion sandbox with landmarks" 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: Plate-motion sandbox with landmarks
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/plate-motion-sandbox-with-landmarks-x1168
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows tectonic plate boundaries. Allow users to choose divergent, convergent, or transform motion beneath fixed reference markers; show resulting schematic landform changes without claiming a numerical geodynamics simulation. Low-poly.
Working Three.js Starter (plate-motion-sandbox-with-landmarks-x1168):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tectonic Boundary Lab</title>
<style>
:root {
color-scheme: dark;
--ink: #edf7f6;
--muted: #91a8ad;
--panel: rgba(10, 23, 30, 0.78);
--panel-strong: rgba(10, 23, 30, 0.92);
--line: rgba(166, 211, 215, 0.17);
--cyan: #67d9e5;
--amber: #ffc96b;
--coral: #ff8f70;
--shadow: 0 18px 55px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07131b;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
.vignette {
position: absolute;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 48% 46%, transparent 35%, rgba(2, 9, 14, 0.34) 100%),
linear-gradient(180deg, rgba(3, 11, 16, 0.3), transparent 25%, transparent 72%, rgba(3, 10, 15, 0.45));
z-index: 1;
}
.hud {
position: absolute;
inset: 0;
pointer-events: none;
z-index: 2;
}
.topbar {
position: absolute;
top: 24px;
left: 28px;
right: 28px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
}
.brand {
max-width: 430px;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.55);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
h1 {
margin: 10px 0 7px;
font-size: clamp(27px, 3.5vw, 50px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 760;
}
.brand p {
margin: 0;
max-width: 390px;
color: #aac0c4;
font-size: 13px;
line-height: 1.55;
}
.mode-panel {
pointer-events: auto;
width: min(470px, 45vw);
padding: 7px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(125%);
}
.mode-label {
padding: 7px 10px 5px;
color: #789198;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.modes {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
.mode-button {
min-height: 64px;
padding: 9px 8px;
border: 1px solid transparent;
border-radius: 12px;
color: #8ea8ad;
background: transparent;
cursor: pointer;
transition: 160ms ease;
text-align: left;
}
.mode-button:hover {
color: var(--ink);
background: rgba(255, 255, 255, 0.045);
}
.mode-button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.mode-button.active {
color: #07131b;
background: linear-gradient(135deg, #d9fbf5, #76dce4);
box-shadow: 0 8px 24px rgba(80, 205, 215, 0.16);
}
.mode-button .arrows {
display: block;
margin-bottom: 5px;
font-size: 17px;
font-weight: 900;
letter-spacing: -0.12em;
white-space: nowrap;
}
.mode-button .name {
display: block;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.025em;
}
.info-card {
position: absolute;
top: 126px;
right: 28px;
width: min(330px, calc(100vw - 56px));
padding: 19px;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(125%);
}
.info-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.mode-index {
color: var(--cyan);
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
}
.boundary-chip {
padding: 5px 8px;
border: 1px solid rgba(103, 217, 229, 0.25);
border-radius: 999px;
color: var(--cyan);
background: rgba(103, 217, 229, 0.07);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.info-card h2 {
margin: 0 0 8px;
font-size: 24px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.info-card p {
margin: 0;
color: #9db3b7;
font-size: 12px;
line-height: 1.6;
}
.forms-title {
margin-top: 15px;
color: #70898f;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.forms {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 8px;
}
.form-tag {
padding: 6px 8px;
border-radius: 7px;
color: #c9dcde;
background: rgba(255, 255, 255, 0.055);
font-size: 9px;
font-weight: 650;
}
.marker-note {
position: absolute;
left: 28px;
bottom: 112px;
width: 240px;
padding: 14px 15px;
border-left: 2px solid var(--amber);
border-radius: 0 12px 12px 0;
background: linear-gradient(90deg, rgba(10, 23, 30, 0.88), rgba(10, 23, 30, 0.32));
box-shadow: var(--shadow);
}
.marker-note strong {
display: block;
margin-bottom: 4px;
color: var(--amber);
font-size: 10px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.marker-note span {
display: block;
color: #9eb2b6;
font-size: 10px;
line-height: 1.5;
}
.controls {
position: absolute;
left: 50%;
bottom: 30px;
transform: translateX(-50%);
width: min(650px, calc(100vw - 40px));
display: grid;
grid-template-columns: 116px 1fr 72px;
align-items: center;
gap: 14px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--panel-strong);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(125%);
pointer-events: auto;
}
.control-button {
height: 42px;
border: 1px solid rgba(160, 211, 214, 0.16);
border-radius: 10px;
color: #d8e8e9;
background: rgba(255, 255, 255, 0.05);
cursor: pointer;
transition: 150ms ease;
}
.control-button:hover {
border-color: rgba(103, 217, 229, 0.42);
background: rgba(103, 217, 229, 0.09);
}
.control-button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
#playButton {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
color: #07131b;
border-color: transparent;
background: var(--cyan);
font-size: 11px;
font-weight: 850;
}
#playIcon {
font-size: 10px;
}
.slider-block {
min-width: 0;
}
.slider-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
color: #8fa6ab;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#motionValue {
color: var(--ink);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 999px;
background: linear-gradient(90deg, var(--cyan) var(--fill, 35%), rgba(255,255,255,.12) var(--fill, 35%));
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 3px solid #09212a;
border-radius: 50%;
background: #d9ffff;
box-shadow: 0 0 0 1px rgba(103,217,229,.65), 0 0 16px rgba(103,217,229,.35);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #09212a;
border-radius: 50%;
background: #d9ffff;
box-shadow: 0 0 0 1px rgba(103,217,229,.65);
}
input[type="range"]:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 6px;
}
#resetButton {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.interaction-hint {
position: absolute;
left: 50%;
bottom: 8px;
transform: translateX(-50%);
color: rgba(172, 198, 201, 0.55);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.disclaimer {
position: absolute;
right: 28px;
bottom: 29px;
width: min(350px, calc(100vw - 56px));
color: rgba(177, 201, 204, 0.62);
font-size: 9px;
line-height: 1.5;
text-align: right;
}
@media (max-width: 900px) {
.topbar {
top: 16px;
left: 16px;
right: 16px;
flex-direction: column;
}
.brand p { display: none; }
.mode-panel { width: 100%; }
.info-card { top: auto; right: 16px; bottom: 122px; width: 285px; }
.marker-note { display: none; }
.disclaimer { display: none; }
.controls {
bottom: 30px;
width: calc(100vw - 24px);
grid-template-columns: 92px 1fr 62px;
gap: 9px;
}
.interaction-hint { bottom: 9px; }
}
@media (max-width: 560px) {
h1 { font-size: 29px; }
.brand { max-width: 290px; }
.mode-button { min-height: 58px; padding: 8px 6px; }
.mode-button .arrows { font-size: 14px; }
.mode-button .name { font-size: 9px; }
.info-card {
right: 12px;
bottom: 117px;
width: 240px;
padding: 13px;
}
.info-card h2 { font-size: 19px; }
.info-card p { font-size: 10px; }
.forms-title, .forms { display: none; }
.controls {
grid-template-columns: 78px 1fr 54px;
padding: 9px;
}
#playButton { font-size: 0; gap: 0; }
#playIcon { font-size: 12px; }
#resetButton { font-size: 8px; }
.slider-label { font-size: 8px; }
.interaction-hint { display: none; }
}
</style>
</head>
<body>
<main id="app">
<canvas id="scene" aria-label="Interactive low-poly tectonic plate boundary diagram"></canvas>
<div class="vignette"></div>
<div class="hud">
<header class="topbar">
<div class="brand">
<div class="eyebrow">Earth systems · interactive study</div>
<h1>Tectonic Boundary Lab</h1>
<p>
Compare schematic plate motion and the landforms associated with
divergent, convergent, and transform boundaries.
</p>
</div>
<nav class="mode-panel" aria-label="Boundary type">
<div class="mode-label">Select a relative motion</div>
<div class="modes">
<button class="mode-button active" data-mode="divergent" aria-pressed="true">
<span class="arrows">← →</span>
<span class="name">Divergent</span>
</button>
<button class="mode-button" data-mode="convergent" aria-pressed="false">
<span class="arrows">→ ←</span>
<span class="name">Convergent</span>
</button>
<button class="mode-button" data-mode="transform" aria-pressed="false">
<span class="arrows">⇄</span>
<span class="name">Transform</span>
</button>
</div>
</nav>
</header>
<aside class="info-card" aria-live="polite">
<div class="info-head">
<span id="modeIndex" class="mode-index">01 / 03</span>
<span id="boundaryChip" class="boundary-chip">Extension</span>
</div>
<h2 id="infoTitle">A boundary tears open</h2>
<p id="infoBody">
Separation stretches the crust apart. A central rift, a warm fissure,
and a narrow strip of new crust schematically replace the former join.
</p>
<div class="forms-title">Schematic landforms</div>
<div id="forms" class="forms">
<span class="form-tag">Rift valley</span>
<span class="form-tag">Fissure</span>
<span class="form-tag">New central crust</span>
</div>
</aside>
<div class="marker-note">
<strong>Fixed reference frame</strong>
<span>
Markers R1–R3 remain locked in place while the plates shift beneath them.
</span>
</div>
<section class="controls" aria-label="Motion controls">
<button id="playButton" class="control-button" aria-pressed="false">
<span id="playIcon">▶</span>
<span id="playLabel">Play</span>
</button>
<div class="slider-block">
<label class="slider-label" for="motionSlider">
<span>Schematic motion amount</span>
<output id="motionValue" for="motionSlider">35%</output>
</label>
<input
id="motionSlider"
type="range"
min="0"
max="100"
value="35"
aria-label="Schematic motion amount"
/>
</div>
<button id="resetButton" class="control-button">Reset</button>
</section>
<div class="interaction-hint">
Drag a plate to adjust motion · drag empty space to orbit · scroll to zoom
</div>
<div class="disclaimer">
Illustrative geometry only—not a numerical geodynamics simulation.
No physical rates, stress values, crustal ages, or material calculations are modeled.
</div>
</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and application state
// -------------------------------------------------------------------------
const canvas = document.getElementById("scene");
const modeButtons = [...document.querySelectorAll(".mode-button")];
const motionSlider = document.getElementById("motionSlider");
const motionValue = document.getElementById("motionValue");
const playButton = document.getElementById("playButton");
const playIcon = document.getElementById("playIcon");
const playLabel = document.getElementById("playLabel");
const resetButton = document.getElementById("resetButton");
const modeInfo = {
divergent: {
index: "01 / 03",
chip: "Extension",
title: "A boundary tears open",
body:
"Separation stretches the crust apart. A central rift, a warm fissure, and a narrow strip of new crust schematically replace the former join.",
forms: ["Rift valley", "Fissure", "New central crust"]
},
convergent: {
index: "02 / 03",
chip: "Compression",
title: "A boundary buckles upward",
body:
"Compression shortens the gap between plates. A folded mountain belt rises, while a simplified subduction-style wedge suggests one possible convergent outcome.",
forms: ["Mountain belt", "Crustal shortening", "Subduction wedge"]
},
transform: {
index: "03 / 03",
chip: "Shear",
title: "A boundary slides sideways",
body:
"The plates move past one another along the fault. A raised scarp and offset drainage illustrate lateral displacement without implying that new crust is created.",
forms: ["Fault scarp", "Offset stream", "Lateral shear"]
}
};
const state = {
mode: "divergent",
motion: 0.35,
targetMotion: 0.35,
phase: Math.acos(1 - 2 * 0.35),
playing: false,
weights: {
divergent: 1,
convergent: 0,
transform: 0
}
};
function clamp01(v) {
return Math.max(0, Math.min(1, v));
}
function damp(current, target, speed, dt) {
return THREE.MathUtils.lerp(current, target, 1 - Math.exp(-speed * dt));
}
// -------------------------------------------------------------------------
// Renderer, scene, and fixed orthographic-style camera
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131b);
scene.fog = new THREE.Fog(0x07131b, 18, 36);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.15, -0.15);
const cameraOrbit = {
radius: 15,
theta: 0.72,
phi: 1.03,
zoom: 1
};
function updateCamera() {
const sinPhi = Math.sin(cameraOrbit.phi);
camera.position.set(
cameraTarget.x + cameraOrbit.radius * sinPhi * Math.sin(cameraOrbit.theta),
cameraTarget.y + cameraOrbit.radius * Math.cos(cameraOrbit.phi),
cameraTarget.z + cameraOrbit.radius * sinPhi * Math.cos(cameraOrbit.theta)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraOrbit.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const aspect = window.innerWidth / Math.max(1, window.innerHeight);
const viewHeight = Math.max(9.8, 13.5 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const hemi = new THREE.HemisphereLight(0xb8e8f2, 0x26342f, 2.0);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffe6c4, 3.2);
keyLight.position.set(-5, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x58cddd, 1.4);
rimLight.position.set(7, 5, -8);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Materials and helper geometry
// -------------------------------------------------------------------------
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x17272e,
roughness: 0.94,
metalness: 0.04
});
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x091820,
roughness: 1
});
function featureMaterial(color, baseOpacity = 1, extra = {}) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.02,
transparent: true,
opacity: baseOpacity,
...extra
});
material.userData.baseOpacity = baseOpacity;
return material;
}
function setFeatureOpacity(materials, factor) {
for (const material of materials) {
material.opacity = (material.userData.baseOpacity ?? 1) * factor;
}
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function makeTextSprite(text, accent = "#dfffff", width = 1.8, height = 0.45) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
roundedRect(ctx, 7, 12, 498, 104, 22);
ctx.fillStyle = "rgba(5, 17, 24, 0.84)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.globalAlpha = 0.65;
ctx.lineWidth = 4;
ctx.stroke();
ctx.globalAlpha = 1;
ctx.fillStyle = accent;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "800 50px system-ui, sans-serif";
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 20;
return sprite;
}
function hash2(x, z, seed) {
const value = Math.sin(x * 127.1 + z * 311.7 + seed * 74.7) * 43758.5453123;
return value - Math.floor(value);
}
// -------------------------------------------------------------------------
// Ground, platform, and fixed reference frame
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(new THREE.PlaneGeometry(42, 42), groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.02;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(28, 28, 0x31515a, 0x193039);
grid.position.y = -1.0;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
const platform = new THREE.Mesh(
new THREE.BoxGeometry(13.2, 0.28, 7.0),
platformMaterial
);
platform.position.set(0, -0.85, -0.15);
platform.receiveShadow = true;
scene.add(platform);
const referenceGroup = new THREE.Group();
scene.add(referenceGroup);
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xffca68,
emissive: 0x3a2100,
emissiveIntensity: 0.28,
roughness: 0.68,
metalness: 0.12
});
const markerDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x493c25,
roughness: 0.8,
metalness: 0.25
});
const rail = new THREE.Mesh(
new THREE.BoxGeometry(7.4, 0.12, 0.15),
markerDarkMaterial
);
rail.position.set(0, 2.52, -3.08);
referenceGroup.add(rail);
[-2.65, 0, 2.65].forEach((x, index) => {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.065, 3.35, 6),
markerMaterial
);
post.position.set(x, 0.82, -3.08);
post.castShadow = true;
referenceGroup.add(post);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.19, 0.14, 8),
markerDarkMaterial
);
base.position.set(x, -0.64, -3.08);
referenceGroup.add(base);
const cap = new THREE.Mesh(
new THREE.OctahedronGeometry(0.12, 0),
markerMaterial
);
cap.position.set(x, 2.57, -3.08);
referenceGroup.add(cap);
const label = makeTextSprite(`R${index + 1}`, "#ffd783", 0.72, 0.28);
label.position.set(x, 2.92, -3.08);
referenceGroup.add(label);
});
// -------------------------------------------------------------------------
// Low-poly terrain plates
// -------------------------------------------------------------------------
const PLATE_WIDTH = 5.3;
const PLATE_DEPTH = 5.2;
const BASE_X = 3.05;
function terrainHeight(side, x, z) {
const outer = side === "left"
? (PLATE_WIDTH / 2 - x) / PLATE_WIDTH
: (PLATE_WIDTH / 2 + x) / PLATE_WIDTH;
const n = hash2(Math.round((x + 3) * 7), Math.round((z + 3) * 7), side === "left" ? 1 : 2);
const ridge = Math.pow(Math.max(0, outer), 1.75);
const ripple = 0.035 * Math.sin(x * 2.1 + z * 1.3 + (side === "left" ? 0 : 2));
return 0.055 + n * 0.11 + ridge * (0.22 + n * 0.30) + ripple;
}
function terrainColor(side, height, variation) {
const low = new THREE.Color(side === "left" ? 0x486d58 : 0x416b70);
const mid = new THREE.Color(side === "left" ? 0x78956a : 0x6c9290);
const high = new THREE.Color(side === "left" ? 0xa39a70 : 0x9a9b7a);
const color = new THREE.Color();
if (height < 0.24) {
color.copy(low).lerp(mid, clamp01((height - 0.05) / 0.19));
} else {
color.copy(mid).lerp(high, clamp01((height - 0.24) / 0.42));
}
color.offsetHSL(0, 0, (variation - 0.5) * 0.055);
return color;
}
function createTerrainGeometry(side) {
const nx = 8;
const nz = 7;
const positions = [];
const colors = [];
const seed = side === "left" ? 1 : 2;
const point = (ix, iz) => {
const x = -PLATE_WIDTH / 2 + (ix / nx) * PLATE_WIDTH;
const z = -PLATE_DEPTH / 2 + (iz / nz) * PLATE_DEPTH;
return { x, z, y: terrainHeight(side, x, z) };
};
const pushTriangle = (a, b, c, cellSeed) => {
positions.push(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z);
const average = (a.y + b.y + c.y) / 3;
const variation = hash2(cellSeed, seed * 13, 4);
const color = terrainColor(side, average, variation);
for (let i = 0; i < 3; i++) colors.push(color.r, color.g, color.b);
};
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const a = point(ix, iz);
const b = point(ix + 1, iz);
const c = point(ix + 1, iz + 1);
const d = point(ix, iz + 1);
const cellSeed = ix * 11 + iz * 19;
if ((ix + iz) % 2 === 0) {
pushTriangle(a, b, c, cellSeed);
pushTriangle(a, c, d, cellSeed + 1);
} else {
pushTriangle(a, b, d, cellSeed);
pushTriangle(b, c, d, cellSeed + 1);
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
const pickableMeshes = [];
function createPlate(side) {
const group = new THREE.Group();
const crustMaterial = new THREE.MeshStandardMaterial({
color: side === "left" ? 0x3e5048 : 0x354e55,
roughness: 0.95,
metalness: 0.02
});
const crust = new THREE.Mesh(
new THREE.BoxGeometry(PLATE_WIDTH, 0.62, PLATE_DEPTH),
crustMaterial
);
crust.position.y = -0.38;
crust.castShadow = true;
crust.receiveShadow = true;
crust.userData.side = side;
group.add(crust);
const terrainMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.96,
metalness: 0
});
const terrain = new THREE.Mesh(createTerrainGeometry(side), terrainMaterial);
terrain.castShadow = true;
terrain.receiveShadow = true;
terrain.userData.side = side;
group.add(terrain);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(crust.geometry),
new THREE.LineBasicMaterial({
color: side === "left" ? 0x8ea59b : 0x7fa9b1,
transparent: true,
opacity: 0.22
})
);
edges.position.copy(crust.position);
group.add(edges);
const label = makeTextSprite(
side === "left" ? "PLATE A" : "PLATE B",
side === "left" ? "#ffd28a" : "#7ce9ef",
1.65,
0.41
);
label.position.set(0, 0.92, 2.24);
group.add(label);
group.position.x = side === "left" ? -BASE_X : BASE_X;
scene.add(group);
pickableMeshes.push(crust, terrain);
return { group, crust, terrain };
}
const leftPlate = createPlate("left");
const rightPlate = createPlate("right");
// -------------------------------------------------------------------------
// Direction arrows
// -------------------------------------------------------------------------
const leftArrow = new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(),
1.4,
0xffc96b,
0.34,
0.18
);
const rightArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(),
1.4,
0x67d9e5,
0.34,
0.18
);
for (const arrow of [leftArrow, rightArrow]) {
arrow.line.material.transparent = true;
arrow.cone.material.transparent = true;
arrow.line.material.depthTest = false;
arrow.cone.material.depthTest = false;
arrow.renderOrder = 15;
}
leftPlate.group.add(leftArrow);
rightPlate.group.add(rightArrow);
// -------------------------------------------------------------------------
// Divergent-boundary features
// -------------------------------------------------------------------------
const divergentGroup = new THREE.Group();
scene.add(divergentGroup);
const divergentMaterials = [];
const riftFloorMaterial = featureMaterial(0x55251d, 0.9);
const magmaMaterial = featureMaterial(0xff7a31, 1, {
emissive: 0xff3a08,
emissiveIntensity: 1.35,
roughness: 0.55
});
const riftRockMaterial = featureMaterial(0x704332, 1);
divergentMaterials.push(riftFloorMaterial, magmaMaterial, riftRockMaterial);
const riftFloor = new THREE.Mesh(
new THREE.BoxGeometry(1.55, 0.12, 5.15),
riftFloorMaterial
);
riftFloor.position.y = -0.53;
divergentGroup.add(riftFloor);
const magmaFissure = new THREE.Mesh(
new THREE.BoxGeometry(0.32, 0.08, 5.02),
magmaMaterial
);
magmaFissure.position.y = -0.45;
divergentGroup.add(magmaFissure);
const newbornRidge = new THREE.Group();
divergentGroup.add(newbornRidge);
for (let i = 0; i < 8; i++) {
const ridge = new THREE.Mesh(
new THREE.ConeGeometry(0.22 + hash2(i, 1, 8) * 0.14, 0.46, 5),
riftRockMaterial
);
ridge.position.set(
(hash2(i, 2, 3) - 0.5) * 0.55,
-0.08,
-2.25 + i * 0.63
);
ridge.rotation.y = hash2(i, 4, 7) * Math.PI;
ridge.castShadow = true;
newbornRidge.add(ridge);
}
const shoulderMaterials = [];
function addRiftShoulders(plate, side) {
const group = new THREE.Group();
const material = featureMaterial(0x694633, 1);
shoulderMaterials.push(material);
for (let i = 0; i < 5; i++) {
const shoulder = new THREE.Mesh(
new THREE.ConeGeometry(0.27, 0.48, 4),
material
);
shoulder.position.set(
side === "left" ? 2.52 : -2.52,
0.12,
-2.05 + i * 1.02
);
shoulder.rotation.y = Math.PI / 4;
shoulder.castShadow = true;
group.add(shoulder);
}
plate.group.add(group);
return group;
}
const leftShoulders = addRiftShoulders(leftPlate, "left");
const rightShoulders = addRiftShoulders(rightPlate, "right");
// -------------------------------------------------------------------------
// Convergent-boundary features
// -------------------------------------------------------------------------
const convergentGroup = new THREE.Group();
scene.add(convergentGroup);
const convergentMaterials = [];
const mountainMaterial = featureMaterial(0x777c70, 1);
const snowMaterial = featureMaterial(0xd8e2d8, 1);
const slabMaterial = featureMaterial(0x274d5d, 0.92);
const trenchMaterial = featureMaterial(0x122b37, 0.96);
convergentMaterials.push(mountainMaterial, snowMaterial, slabMaterial, trenchMaterial);
const mountainGroup = new THREE.Group();
convergentGroup.add(mountainGroup);
for (let i = 0; i < 9; i++) {
const height = 0.72 + hash2(i, 1, 17) * 1.18;
const radius = 0.48 + hash2(i, 2, 23) * 0.42;
const mountain = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, 5),
mountainMaterial
);
mountain.position.set(
(hash2(i, 3, 31) - 0.5) * 1.35,
height / 2 - 0.03,
-2.35 + i * 0.58
);
mountain.rotation.y = hash2(i, 4, 41) * Math.PI;
mountain.castShadow = true;
mountainGroup.add(mountain);
if (height > 1.25) {
const cap = new THREE.Mesh(
new THREE.ConeGeometry(radius * 0.28, height * 0.24, 5),
snowMaterial
);
cap.position.y = height * 0.38;
mountain.add(cap);
}
}
const subductionWedge = new THREE.Mesh(
new THREE.BoxGeometry(3.05, 0.18, 5.05),
slabMaterial
);
subductionWedge.position.set(0.62, -0.52, 0);
subductionWedge.rotation.z = -0.39;
convergentGroup.add(subductionWedge);
const trench = new THREE.Mesh(
new THREE.BoxGeometry(0.19, 0.09, 5.08),
trenchMaterial
);
trench.position.set(0.24, -0.05, 0);
convergentGroup.add(trench);
// -------------------------------------------------------------------------
// Transform-boundary features
// -------------------------------------------------------------------------
const transformGroup = new THREE.Group();
scene.add(transformGroup);
const transformMaterials = [];
const faultMaterial = featureMaterial(0xffc96b, 1, {
emissive: 0x5f3900,
emissiveIntensity: 0.42
});
const scarpMaterial = featureMaterial(0x806a4b, 1);
transformMaterials.push(faultMaterial, scarpMaterial);
const faultTrace = new THREE.Mesh(
new THREE.BoxGeometry(0.075, 0.07, 5.16),
faultMaterial
);
faultTrace.position.set(0, -0.04, 0);
transformGroup.add(faultTrace);
[-1, 1].forEach((side) => {
const scarp = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.36, 5.05),
scarpMaterial
);
scarp.position.set(side * 0.25, 0.08, 0);
scarp.rotation.z = side * -0.08;
scarp.castShadow = true;
transformGroup.add(scarp);
});
const riverMaterial = featureMaterial(0x55c9d5, 0.95, {
emissive: 0x073c46,
emissiveIntensity: 0.38,
roughness: 0.4
});
const leftRiver = new THREE.Mesh(
new THREE.BoxGeometry(2.72, 0.045, 0.22),
riverMaterial
);
leftRiver.position.set(-1.35, 0.66, 0);
leftPlate.group.add(leftRiver);
const rightRiver = new THREE.Mesh(
new THREE.BoxGeometry(2.72, 0.045, 0.22),
riverMaterial
);
rightRiver.position.set(1.35, 0.66, 0);
rightPlate.group.add(rightRiver);
// -------------------------------------------------------------------------
// Mode and control UI
// -------------------------------------------------------------------------
function updateInfo(mode) {
const info = modeInfo[mode];
document.getElementById("modeIndex").textContent = info.index;
document.getElementById("boundaryChip").textContent = info.chip;
document.getElementById("infoTitle").textContent = info.title;
document.getElementById("infoBody").textContent = info.body;
document.getElementById("forms").innerHTML = info.forms
.map((form) => `<span class="form-tag">${form}</span>`)
.join("");
}
function setMode(mode) {
state.mode = mode;
for (const button of modeButtons) {
const active = button.dataset.mode === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
}
updateInfo(mode);
}
function updateMotionUI() {
const percent = Math.round(state.targetMotion * 100);
motionSlider.value = String(percent);
motionSlider.style.setProperty("--fill", `${percent}%`);
motionValue.textContent = `${percent}%`;
}
function updatePlayUI() {
playButton.setAttribute("aria-pressed", String(state.playing));
playIcon.textContent = state.playing ? "Ⅱ" : "▶";
playLabel.textContent = state.playing ? "Pause" : "Play";
}
modeButtons.forEach((button) => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
motionSlider.addEventListener("input", () => {
state.targetMotion = Number(motionSlider.value) / 100;
state.phase = Math.acos(1 - 2 * state.targetMotion);
state.playing = false;
updateMotionUI();
updatePlayUI();
});
playButton.addEventListener("click", () => {
if (!state.playing && state.targetMotion > 0.985) state.phase = 0;
state.playing = !state.playing;
updatePlayUI();
});
resetButton.addEventListener("click", () => {
state.targetMotion = 0.35;
state.phase = Math.acos(1 - 2 * 0.35);
state.playing = false;
setMode("divergent");
updateMotionUI();
updatePlayUI();
});
// -------------------------------------------------------------------------
// Custom direct camera and plate interaction — no external controls addon
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.36);
const planeHit = new THREE.Vector3();
let plateDrag = null;
let orbitDrag = null;
function pointerToPlane(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
return raycaster.ray.intersectPlane(dragPlane, new THREE.Vector3());
}
function pickPlate(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
scene.updateMatrixWorld(true);
const hits = raycaster.intersectObjects(pickableMeshes, false);
return hits.length ? hits[0] : null;
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.focus();
const hit = event.button === 0 ? pickPlate(event) : null;
if (hit) {
const point = pointerToPlane(event);
if (!point) return;
plateDrag = {
pointerId: event.pointerId,
side: hit.object.userData.side,
startPoint: point.clone(),
startMotion: state.targetMotion
};
state.playing = false;
updatePlayUI();
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
} else {
orbitDrag = {
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY,
theta: cameraOrbit.theta,
phi: cameraOrbit.phi
};
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
}
});
canvas.addEventListener("pointermove", (event) => {
if (plateDrag && event.pointerId === plateDrag.pointerId) {
const point = pointerToPlane(event);
if (!point) return;
const dx = point.x - plateDrag.startPoint.x;
const dz = point.z - plateDrag.startPoint.z;
let nextMotion = plateDrag.startMotion;
if (state.mode === "divergent") {
nextMotion += (plateDrag.side === "left" ? -dx : dx) / 1.2;
} else if (state.mode === "convergent") {
nextMotion += (plateDrag.side === "left" ? dx : -dx) / 0.3;
} else {
nextMotion += (plateDrag.side === "left" ? -dz : dz) / 1.35;
}
state.targetMotion = clamp01(nextMotion);
state.phase = Math.acos(1 - 2 * state.targetMotion);
updateMotionUI();
return;
}
if (orbitDrag && event.pointerId === orbitDrag.pointerId) {
const dx = event.clientX - orbitDrag.x;
const dy = event.clientY - orbitDrag.y;
cameraOrbit.theta = orbitDrag.theta - dx * 0.005;
cameraOrbit.phi = THREE.MathUtils.clamp(orbitDrag.phi + dy * 0.004, 0.66, 1.34);
updateCamera();
return;
}
if (event.pointerType === "mouse") {
const hit = pickPlate(event);
canvas.style.cursor = hit
? (state.mode === "transform" ? "ns-resize" : "ew-resize")
: "grab";
}
});
function endPointer(event) {
if (plateDrag && event.pointerId === plateDrag.pointerId) plateDrag = null;
if (orbitDrag && event.pointerId === orbitDrag.pointerId) orbitDrag = null;
if (canvas.hasPointerCapture(event.pointerId)) canvas.releasePointerCapture(event.pointerId);
canvas.style.cursor = "grab";
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = event.deltaY > 0 ? 0.92 : 1.08;
cameraOrbit.zoom = THREE.MathUtils.clamp(cameraOrbit.zoom * factor, 0.72, 1.7);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Animation and schematic state updates
// -------------------------------------------------------------------------
const arrowDirection = new THREE.Vector3();
function updateScene(dt) {
if (state.playing) {
state.phase = (state.phase + dt * 0.72) % (Math.PI * 2);
state.targetMotion = (1 - Math.cos(state.phase)) / 2;
updateMotionUI();
}
state.motion = damp(state.motion, state.targetMotion, 8, dt);
state.weights.divergent = damp(
state.weights.divergent,
state.mode === "divergent" ? 1 : 0,
5.5,
dt
);
state.weights.convergent = damp(
state.weights.convergent,
state.mode === "convergent" ? 1 : 0,
5.5,
dt
);
state.weights.transform = damp(
state.weights.transform,
state.mode === "transform" ? 1 : 0,
5.5,
dt
);
const d = state.weights.divergent;
const c = state.weights.convergent;
const t = state.weights.transform;
const m = state.motion;
// Relative displacement. Values are visual controls only, not physical units.
leftPlate.group.position.x =
-BASE_X + (-1.2 * d + 0.3 * c) * m;
rightPlate.group.position.x =
BASE_X + (1.2 * d - 0.3 * c) * m;
leftPlate.group.position.z = -1.35 * t * m;
rightPlate.group.position.z = 1.35 * t * m;
// Motion arrows.
arrowDirection.set(-d + c, 0, -t);
if (arrowDirection.lengthSq() < 0.0001) arrowDirection.set(-1, 0, 0);
arrowDirection.normalize();
leftArrow.setDirection(arrowDirection);
rightArrow.setDirection(arrowDirection.clone().negate());
const arrowStrength = Math.max(d, c, t);
const arrowLength = 0.05 + arrowStrength * 1.42;
leftArrow.setLength(arrowLength, 0.34, 0.18);
rightArrow.setLength(arrowLength, 0.34, 0.18);
leftArrow.position.set(0.7 * d - 0.7 * c, 1.52, 0.8 * t);
rightArrow.position.set(-0.7 * d + 0.7 * c, 1.52, -0.8 * t);
for (const arrow of [leftArrow, rightArrow]) {
arrow.line.material.opacity = arrowStrength;
arrow.cone.material.opacity = arrowStrength;
arrow.visible = arrowStrength > 0.015;
}
// Divergent features.
divergentGroup.visible = d > 0.01;
setFeatureOpacity(divergentMaterials, d * (0.12 + 0.88 * m));
magmaFissure.scale.x = 0.45 + m * 1.55;
newbornRidge.scale.set(
0.65 + m * 0.45,
0.12 + m * 0.88,
0.65 + m * 0.45
);
setFeatureOpacity(shoulderMaterials, d * (0.16 + 0.84 * m));
leftShoulders.visible = d > 0.01;
rightShoulders.visible = d > 0.01;
// Convergent features.
convergentGroup.visible = c > 0.01;
setFeatureOpacity(convergentMaterials, c * (0.12 + 0.88 * m));
mountainGroup.scale.set(
0.72 + m * 0.28,
0.12 + m * 0.88,
0.72 + m * 0.28
);
subductionWedge.scale.set(
0.72 + m * 0.28,
0.5 + m * 0.5,
0.72 + m * 0.28
);
// Transform features.
transformGroup.visible = t > 0.01;
setFeatureOpacity(transformMaterials, t * (0.2 + 0.8 * m));
riverMaterial.opacity = 0.95 * t * (0.25 + 0.75 * m);
leftRiver.visible = rightRiver.visible = t > 0.01;
}
updateInfo(state.mode);
updateMotionUI();
updatePlayUI();
renderer.setAnimationLoop((time) => {
const dt = Math.min(0.05, renderer.info.render.frame === 0 ? 0.016 : 0.016);
updateScene(dt);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```