Prompt specification
Build or customize the Three.js 3D scene "Convergent and transform comparison devices" 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: Convergent and transform comparison devices
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/convergent-and-transform-comparison-devices-x1166
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows tectonic plate boundaries. Place a subduction-style sectional model beside two laterally sliding plates; animate their contrasting motion with clear arrows and explicitly simplified crust geometry. Stylized solid forms.
Working Three.js Starter (convergent-and-transform-comparison-devices-x1166):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Tectonic Plate Boundaries — Subduction & Transform (Schematic)</title>
<style>
:root{
--ink:#dfe9f5; --dim:#93a7bd; --panel:rgba(12,18,28,.84); --line:rgba(120,165,215,.20);
--accent:#63e0ff;
}
*{box-sizing:border-box}
html,body{height:100%;margin:0;background:#0a0f17;overflow:hidden;
font-family:system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;color:var(--ink)}
#app{position:fixed;inset:0}
canvas{display:block}
#hud{position:fixed;top:16px;left:16px;width:296px;padding:14px 16px 13px;
background:var(--panel);border:1px solid var(--line);border-radius:14px;
backdrop-filter:blur(9px);-webkit-backdrop-filter:blur(9px);
box-shadow:0 18px 40px rgba(0,0,0,.45);font-size:12.5px;line-height:1.45}
#hud h1{margin:0 0 2px;font-size:16px;letter-spacing:.3px}
#hud .sub{margin:0 0 10px;color:var(--dim);font-size:11.5px}
.note{margin:9px 0 10px;padding:8px 9px;border-left:3px solid #ffb347;border-radius:0 7px 7px 0;
background:rgba(255,179,71,.10);color:#f3d9b4;font-size:11px}
.legend{display:grid;grid-template-columns:1fr 1fr;gap:4px 8px;margin:8px 0 11px}
.legend div{display:flex;align-items:center;gap:6px;color:#c9d7e6;font-size:11px}
.sw{width:11px;height:11px;border-radius:3px;flex:0 0 auto;box-shadow:0 0 0 1px rgba(255,255,255,.14)}
.row{display:flex;flex-wrap:wrap;gap:6px}
button{font:inherit;font-size:11.5px;color:var(--ink);background:rgba(70,110,160,.20);
border:1px solid var(--line);border-radius:8px;padding:5px 9px;cursor:pointer;transition:.15s}
button:hover{background:rgba(90,140,200,.32)}
button.on{background:rgba(99,224,255,.22);border-color:rgba(99,224,255,.55);color:#dff7ff}
#hint{position:fixed;left:50%;bottom:14px;transform:translateX(-50%);
padding:7px 14px;border-radius:20px;background:rgba(12,18,28,.72);border:1px solid var(--line);
color:var(--dim);font-size:11.5px;white-space:nowrap}
#hint b{color:#cfe0f2;font-weight:600}
</style>
</head>
<body>
<div id="app"></div>
<div id="hud">
<h1>Tectonic Plate Boundaries</h1>
<p class="sub">Convergent (subduction) model & transform (lateral-slip) model, side by side.</p>
<div class="note"><b>Explicitly simplified geometry.</b> Crust is drawn as stylized solid blocks with exaggerated
thickness, a straight ~30° slab dip, and a schematic wedge — it is <i>not</i> to scale or a true geological section.</div>
<div class="legend">
<div><i class="sw" style="background:#2b5f8f"></i>Oceanic crust</div>
<div><i class="sw" style="background:#c98a52"></i>Continental crust</div>
<div><i class="sw" style="background:#f4813c"></i>Mantle wedge</div>
<div><i class="sw" style="background:#c0392b"></i>Asthenosphere</div>
<div><i class="sw" style="background:#3f8f63"></i>Offset dike / trace</div>
<div><i class="sw" style="background:#0d1117"></i>Transform fault</div>
</div>
<div class="row">
<button id="bLabels" class="on">Labels</button>
<button id="bArrows" class="on">Arrows</button>
<button id="bPause">Pause</button>
<button id="bReset">Reset view</button>
</div>
</div>
<div id="hint"><b>Drag</b> orbit · <b>Wheel</b> zoom · <b>Right-drag / Shift-drag</b> pan · <b>Touch</b> drag + pinch</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ------------------------------------------------------------------ setup */
const renderer = new THREE.WebGLRenderer({ antialias:true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.getElementById('app').appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0a0f17);
scene.fog = new THREE.Fog(0x0a0f17, 46, 95);
const camera = new THREE.PerspectiveCamera(35, innerWidth/innerHeight, 0.1, 250);
scene.add(new THREE.HemisphereLight(0x9dc4ff, 0x33200f, 0.62));
const key = new THREE.DirectionalLight(0xfff2e0, 1.25);
key.position.set(10, 17, 13);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -18; key.shadow.camera.right = 18;
key.shadow.camera.top = 14; key.shadow.camera.bottom = -12;
key.shadow.camera.near = 1; key.shadow.camera.far = 60;
key.shadow.bias = -0.0009; key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0x8fbcff, 0.42); fill.position.set(-13, 8, -9); scene.add(fill);
const rim = new THREE.DirectionalLight(0xffd2a1, 0.30); rim.position.set(0, 3, -16); scene.add(rim);
/* ------------------------------------------------------------- materials */
const M = (color, o = {}) => new THREE.MeshStandardMaterial(
Object.assign({ color, roughness:0.86, metalness:0.0, flatShading:true }, o));
const MAT = {
astheno : M(0xc0392b, { emissive:0x4a0f06, emissiveIntensity:0.55 }),
wedge : M(0xf4813c, { emissive:0x7a2c05, emissiveIntensity:0.85 }),
oceanic : M(0x2b5f8f),
sedim : M(0xa9bdcb),
cont : M(0xc98a52),
land : M(0x86a75c),
water : M(0x2f8fd0, { transparent:true, opacity:0.40, roughness:0.18, emissive:0x0b3350, emissiveIntensity:0.5 }),
volcano : M(0x57453c),
lava : M(0xff5a1f, { emissive:0xff3b00, emissiveIntensity:1.6 }),
plinth : M(0x1b2431),
ground : M(0x121a25, { roughness:0.95 }),
plateL : M(0x9a8a68),
plateR : M(0x87795c),
dike : M(0x3f8f63),
trace : M(0x6d5b3d),
fault : M(0x0c1017, { roughness:0.6 })
};
const EDGE = new THREE.LineBasicMaterial({ color:0x080c12, transparent:true, opacity:0.55 });
/* -------------------------------------------------------------- helpers */
function shapeFrom(pts){ // pts: [[x,y],...] -> THREE.Shape (CCW)
let area = 0;
for (let i = 0; i < pts.length; i++){
const a = pts[i], b = pts[(i+1)%pts.length];
area += a[0]*b[1] - b[0]*a[1];
}
if (area < 0) pts = pts.slice().reverse();
const s = new THREE.Shape();
s.moveTo(pts[0][0], pts[0][1]);
for (let i = 1; i < pts.length; i++) s.lineTo(pts[i][0], pts[i][1]);
s.closePath();
return s;
}
function slab(pts, depth, material, edges = true){
const geo = new THREE.ExtrudeGeometry(shapeFrom(pts), { depth, bevelEnabled:false, curveSegments:3 });
geo.translate(0, 0, -depth/2);
const m = new THREE.Mesh(geo, material);
m.castShadow = true; m.receiveShadow = true;
if (edges){ m.add(new THREE.LineSegments(new THREE.EdgesGeometry(geo, 24), EDGE)); }
return m;
}
function box(w, h, d, material, x, y, z, edges = true){
const geo = new THREE.BoxGeometry(w, h, d);
const m = new THREE.Mesh(geo, material);
m.position.set(x, y, z); m.castShadow = true; m.receiveShadow = true;
if (edges) m.add(new THREE.LineSegments(new THREE.EdgesGeometry(geo, 24), EDGE));
return m;
}
function arrow(len, color, thickness = 0.075){
const g = new THREE.Group();
const mat = M(color, { emissive:color, emissiveIntensity:0.32, roughness:0.5 });
const shaftLen = Math.max(0.2, len - 0.42);
const sh = new THREE.Mesh(new THREE.CylinderGeometry(thickness, thickness, shaftLen, 10), mat);
sh.rotation.z = -Math.PI/2; sh.position.x = shaftLen/2; sh.castShadow = true;
const hd = new THREE.Mesh(new THREE.ConeGeometry(thickness*2.5, 0.42, 12), mat);
hd.rotation.z = -Math.PI/2; hd.position.x = shaftLen + 0.21; hd.castShadow = true;
g.add(sh, hd);
g.userData.mat = mat;
return g;
}
function placeArrow(parent, g, tail, dir){
g.position.copy(tail);
g.quaternion.setFromUnitVectors(new THREE.Vector3(1,0,0), dir.clone().normalize());
parent.add(g);
return g;
}
/* --------------------------------------------------------------- labels */
function label(text, sub = '', accent = '#63e0ff', scale = 1){
const c = document.createElement('canvas');
const ctx = c.getContext('2d');
const font = '600 42px system-ui,-apple-system,Segoe UI,Roboto,sans-serif';
ctx.font = font;
const w = Math.ceil(ctx.measureText(text).width) + 58;
const h = sub ? 132 : 86;
c.width = w; c.height = h;
const g = c.getContext('2d');
const rr = (x,y,ww,hh,r)=>{ g.beginPath(); g.moveTo(x+r,y); g.arcTo(x+ww,y,x+ww,y+hh,r); g.arcTo(x+ww,y+hh,x,y+hh,r);
g.arcTo(x,y+hh,x,y,r); g.arcTo(x,y,x+ww,y,r); g.closePath(); };
rr(2,2,w-4,h-4,16); g.fillStyle = 'rgba(10,16,26,0.86)'; g.fill();
g.strokeStyle = accent; g.lineWidth = 3; g.stroke();
g.fillStyle = accent; rr(13,20,6,h-40,3); g.fill();
g.fillStyle = '#eaf3ff'; g.font = font; g.textBaseline = 'middle'; g.fillText(text, 31, sub ? 42 : h/2);
if (sub){ g.font = '400 27px system-ui,-apple-system,Segoe UI,Roboto,sans-serif'; g.fillStyle = '#9fb3c8'; g.fillText(sub, 31, 96); }
const tex = new THREE.CanvasTexture(c); tex.colorSpace = THREE.SRGBColorSpace; tex.minFilter = THREE.LinearFilter;
const s = new THREE.Sprite(new THREE.SpriteMaterial({ map:tex, transparent:true, depthWrite:false }));
const hh = 0.30 * scale; s.scale.set(hh * (w/h), hh, 1);
return s;
}
const labelsGroup = new THREE.Group(); scene.add(labelsGroup);
const leaderMat = new THREE.LineBasicMaterial({ color:0x7f9ab5, transparent:true, opacity:0.45 });
function addLabel(text, sub, accent, pos, anchor, scale = 1){
const s = label(text, sub, accent, scale);
s.position.set(pos[0], pos[1], pos[2]);
labelsGroup.add(s);
if (anchor){
const g = new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(...anchor), s.position.clone()]);
labelsGroup.add(new THREE.Line(g, leaderMat));
}
return s;
}
/* ==========================================================================
STATION A — CONVERGENT BOUNDARY: SUBDUCTION (schematic cross-section)
========================================================================== */
const A = new THREE.Group(); A.position.set(-6.4, 0, 0); scene.add(A);
const DEPTH = 2.2;
/* --- geometry (all values schematic) --- */
const slabTop = [[-4.3,-0.20],[0.50,-0.20],[1.00,-0.45],[1.80,-0.95],[2.60,-1.45],[3.40,-1.95]];
const slabBot = [[3.40,-2.29],[2.60,-1.79],[1.80,-1.29],[1.00,-0.79],[0.50,-0.54],[-4.30,-0.54]];
// asthenosphere (everything below the slab / behind the arc)
A.add(slab([[-4.30,-0.54],[0.50,-0.54],[1.00,-0.79],[1.80,-1.29],[2.60,-1.79],[3.40,-2.29],
[3.40,-1.60],[4.30,0.55],[4.30,-3.40],[-4.30,-3.40]], DEPTH, MAT.astheno));
// mantle wedge (between slab top and overriding-plate base)
A.add(slab([[1.00,-0.10],[1.80,-0.60],[2.60,-1.10],[3.40,-1.60],
[3.40,-1.95],[2.60,-1.45],[1.80,-0.95],[1.00,-0.45]], DEPTH, MAT.wedge));
// subducting oceanic plate + slab
A.add(slab(slabTop.concat(slabBot), DEPTH, MAT.oceanic));
// thin oceanic sediment cover
A.add(slab([[-4.30,-0.20],[0.50,-0.20],[0.50,-0.10],[-4.30,-0.10]], DEPTH, MAT.sedim));
// overriding continental plate
A.add(slab([[0.65,-0.18],[1.20,0.75],[2.00,1.05],[3.00,1.20],[4.30,1.25],[4.30,0.55],
[3.40,-1.60],[2.60,-1.10],[1.80,-0.60],[1.00,-0.10]], DEPTH, MAT.cont));
// land / soil cap
A.add(slab([[1.05,0.55],[1.20,0.75],[2.00,1.05],[3.00,1.20],[4.30,1.25],
[4.30,1.12],[3.00,1.07],[2.00,0.92],[1.20,0.62],[1.05,0.42]], DEPTH, MAT.land));
// ocean water (transparent)
A.add(slab([[-4.30,-0.20],[0.62,-0.20],[0.62,0.26],[-4.30,0.26]], DEPTH, MAT.water, false));
// plinth
A.add(box(9.1, 0.45, 2.7, MAT.plinth, 0, -3.62, 0));
// volcano (arc)
const volcano = new THREE.Group(); volcano.position.set(3.00, 1.20, 0); A.add(volcano);
const cone = new THREE.Mesh(new THREE.CylinderGeometry(0.20, 0.86, 1.05, 9, 1), MAT.volcano);
cone.position.y = 0.525; cone.castShadow = true; volcano.add(cone);
volcano.add(new THREE.LineSegments(new THREE.EdgesGeometry(cone.geometry, 24), EDGE));
const crater = new THREE.Mesh(new THREE.CylinderGeometry(0.21, 0.16, 0.09, 9), MAT.lava);
crater.position.y = 1.06; volcano.add(crater);
/* --- smoke puffs --- */
const puffs = [];
for (let i = 0; i < 6; i++){
const m = new THREE.Mesh(new THREE.IcosahedronGeometry(0.16 + i*0.012, 0),
new THREE.MeshStandardMaterial({ color:0x9aa7b4, transparent:true, opacity:0, roughness:1, flatShading:true }));
A.add(m); puffs.push({ m, ph:i/6 });
}
/* --- subduction flow markers (plate material diving under the arc) --- */
const pathPts = [[-3.60,-0.37],[0.45,-0.37],[1.00,-0.62],[1.80,-1.12],[2.60,-1.62],[3.30,-2.10]]
.map(p => new THREE.Vector3(p[0], p[1], 1.34));
const lens = [0]; let total = 0;
for (let i = 1; i < pathPts.length; i++){ total += pathPts[i].distanceTo(pathPts[i-1]); lens.push(total); }
function samplePath(u, pos, dir){
const d = ((u % 1) + 1) % 1 * total;
let i = 1; while (i < lens.length - 1 && lens[i] < d) i++;
const f = (d - lens[i-1]) / (lens[i] - lens[i-1]);
pos.copy(pathPts[i-1]).lerp(pathPts[i], f);
dir.copy(pathPts[i]).sub(pathPts[i-1]).normalize();
return u;
}
const tracers = [];
for (let i = 0; i < 5; i++){
const m = new THREE.Mesh(new THREE.ConeGeometry(0.11, 0.36, 10),
new THREE.MeshStandardMaterial({ color:0xffe08a, emissive:0xffb020, emissiveIntensity:1.1,
transparent:true, opacity:0.95, roughness:0.4, flatShading:true }));
A.add(m); tracers.push(m);
}
const tmpP = new THREE.Vector3(), tmpD = new THREE.Vector3();
const UP = new THREE.Vector3(0,1,0);
/* --- arrows (station A) --- */
const arrows = [];
arrows.push(placeArrow(A, arrow(1.95, 0xffd24a), new THREE.Vector3(-3.55, 0.72, 1.36), new THREE.Vector3(1,0,0)));
arrows.push(placeArrow(A, arrow(1.95, 0xff8a3d), new THREE.Vector3( 1.45, 1.85, 1.36), new THREE.Vector3(-1,0,0)));
arrows.push(placeArrow(A, arrow(1.65, 0xffd24a), new THREE.Vector3(1.62,-1.85, 1.36), new THREE.Vector3(0.848,-0.530,0)));
arrows.push(placeArrow(A, arrow(1.10, 0xff7a45, 0.06), new THREE.Vector3(2.88,-1.30, 1.36), new THREE.Vector3(0,1,0)));
/* --- station A labels --- */
addLabel('① CONVERGENT · SUBDUCTION', 'oceanic plate sinks beneath the arc', '#ffb347', [-6.4, 3.55, 0], null, 1.35);
addLabel('Oceanic plate', 'basaltic crust + sediment', '#63e0ff', [-9.9, 1.15, 1.5], [-8.6, -0.30, 1.1]);
addLabel('Subducting slab', 'cold, dense plate descends', '#63e0ff', [-2.1, -2.45, 1.5], [-3.6, -2.05, 1.1]);
addLabel('Mantle wedge', 'hot, buoyant mantle', '#ff8a3d', [-2.1, -1.35, 1.5], [-3.6, -1.25, 1.1]);
addLabel('Asthenosphere', 'ductile mantle', '#ff6a4d', [-1.1, -3.05, 1.5], [-2.4, -2.60, 1.1]);
addLabel('Overriding plate', 'continental crust + arc', '#ffb347', [-6.4, 2.75, 1.5], [-4.5, 1.25, 1.1]);
addLabel('Trench', 'where the slab bends down', '#63e0ff', [-6.4, 0.95, 1.5], [-5.85, -0.20, 1.1], 0.9);
addLabel('Volcano / arc', 'magma rises in the wedge', '#ff7a45', [-3.4, 3.05, 1.5], [-3.4, 2.30, 0.9], 0.9);
/* ==========================================================================
STATION B — TRANSFORM BOUNDARY: two plates sliding laterally (map view)
========================================================================== */
const B = new THREE.Group();
B.position.set(5.7, -1.15, 0);
B.rotation.y = -0.62;
B.scale.setScalar(0.82);
scene.add(B);
const WX = 2.80, WZ = 2.60; // map window (x half-width, z half-depth)
const PT = 0.14; // recess depth of the map
const BELT_HL = 3.80, BELT_END = 4.50; // flat top half-length / buried ramp end
const PERIOD = 1.80; // feature period (lets the belt loop seamlessly)
/* platform frame around the recessed map */
B.add(box(0.60, 0.60, 9.60, MAT.plinth, -(WX+0.30), -0.30, 0));
B.add(box(0.60, 0.60, 9.60, MAT.plinth, (WX+0.30), -0.30, 0));
B.add(box(2*WX, 0.60, 2*(BELT_END+0.30)-2*WZ, MAT.plinth, 0, -0.30, 0));
/* pedestal down to the table */
B.add(box(6.9, 2.05, 9.9, MAT.plinth, 0, -1.62, 0));
/* the two plates: long belts whose ends dive under the platform frame */
function belt(x0, width, material){
const prof = [[-BELT_END,-0.55],[-BELT_HL,-PT],[BELT_HL,-PT],[BELT_END,-0.55]];
const geo = new THREE.ExtrudeGeometry(shapeFrom(prof), { depth:width, bevelEnabled:false });
geo.rotateY(Math.PI/2);
const m = new THREE.Mesh(geo, material);
m.position.x = x0; m.castShadow = true; m.receiveShadow = true;
m.add(new THREE.LineSegments(new THREE.EdgesGeometry(geo, 24), EDGE));
return m;
}
const GAP = 0.09;
const leftBelt = new THREE.Group(); B.add(leftBelt);
const rightBelt = new THREE.Group(); B.add(rightBelt);
leftBelt.add(belt(-WX, WX - GAP, MAT.plateL));
rightBelt.add(belt(GAP, WX - GAP, MAT.plateR));
/* dark fault zone in the gap */
B.add(box(2*GAP, 0.52, 2*WZ, MAT.fault, 0, -0.38, 0));
/* periodic surface features (dike + thin layer trace) -> they show the offset */
function addFeatures(group, width){
for (let k = -3; k <= 3; k++){
const d = new THREE.Mesh(new THREE.BoxGeometry(width, 0.05, 0.26), MAT.dike);
d.position.set(-GX + width/2, -PT + 0.025, k*PERIOD);
d.castShadow = true; group.add(d);
const t = new THREE.Mesh(new THREE.BoxGeometry(width, 0.03, 0.09), MAT.trace);
t.position.set(-GX + width/2, -PT + 0.015, k*PERIOD + PERIOD/2);
group.add(t);
}
}
const GX = WX; // belts are built from local x = -WX (left) and +GAP (right)
addFeatures(leftBelt, WX - GAP);
addFeatures(rightBelt, WX - GAP);
/* arrows showing opposite lateral motion */
arrows.push(placeArrow(B, arrow(1.85, 0x63e0ff), new THREE.Vector3(-1.55, 0.62, -0.85), new THREE.Vector3(0,0,1)));
arrows.push(placeArrow(B, arrow(1.85, 0xffc857), new THREE.Vector3( 1.55, 0.62, 0.85), new THREE.Vector3(0,0,-1)));
/* station B labels */
addLabel('② TRANSFORM · LATERAL SLIP', 'plates slide past one another in opposite senses', '#63e0ff', [5.7, 1.15, 0], null, 1.35);
addLabel('Transform fault', 'vertical, strike-slip plane', '#63e0ff', [5.7, 0.05, 1.9], [5.7, -0.95, 0.2], 0.9);
addLabel('Offset dike', 'matching layer cut by the fault', '#3f8f63', [8.6, -0.35, -1.6], [7.0, -1.05, 0.4], 0.9);
addLabel('Plate A', 'left plate', '#63e0ff', [1.6, -0.45, 2.3], [3.4, -1.05, 1.6], 0.85);
addLabel('Plate B', 'right plate', '#ffc857', [9.9, -0.45, -2.3], [8.1, -1.05, -1.6], 0.85);
/* ==========================================================================
ground, grid
========================================================================== */
const ground = new THREE.Mesh(new THREE.PlaneGeometry(160,160), MAT.ground);
ground.rotation.x = -Math.PI/2; ground.position.y = -3.90; ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(120, 60, 0x2b3d54, 0x1b2635);
grid.position.y = -3.885;
grid.material.transparent = true; grid.material.opacity = 0.35; grid.material.depthWrite = false;
scene.add(grid);
/* ==========================================================================
camera controls (implemented here — no addon imports)
========================================================================== */
const cam = { r: 27.0, theta: 0.0, phi: 1.09, target: new THREE.Vector3(0.0, -0.55, 0.0) };
const CAM_HOME = { r: 27.0, theta: 0.0, phi: 1.09, target: new THREE.Vector3(0.0, -0.55, 0.0) };
function updateCamera(){
const s = new THREE.Spherical(cam.r, cam.phi, cam.theta);
camera.position.setFromSpherical(s).add(cam.target);
camera.lookAt(cam.target);
}
updateCamera();
const pointers = new Map();
let dragging = false, panning = false, lastX = 0, lastY = 0, pinchDist = 0;
const dom = renderer.domElement;
dom.style.touchAction = 'none';
dom.addEventListener('pointerdown', e => {
dom.setPointerCapture(e.pointerId);
pointers.set(e.pointerId, { x:e.clientX, y:e.clientY });
if (pointers.size === 1){
dragging = true; panning = (e.button === 2 || e.shiftKey);
lastX = e.clientX; lastY = e.clientY;
} else if (pointers.size === 2){
const [a,b] = [...pointers.values()];
pinchDist = Math.hypot(a.x-b.x, a.y-b.y);
}
});
dom.addEventListener('pointermove', e => {
if (!pointers.has(e.pointerId)) return;
pointers.set(e.pointerId, { x:e.clientX, y:e.clientY });
if (pointers.size === 2){
const [a,b] = [...pointers.values()];
const d = Math.hypot(a.x-b.x, a.y-b.y);
if (pinchDist > 0) cam.r = THREE.MathUtils.clamp(cam.r * (pinchDist / d), 9, 60);
pinchDist = d; return;
}
if (!dragging) return;
const dx = e.clientX - lastX, dy = e.clientY - lastY;
lastX = e.clientX; lastY = e.clientY;
if (panning){
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const k = cam.r * 0.0016;
cam.target.addScaledVector(right, -dx*k).addScaledVector(up, dy*k);
} else {
cam.theta -= dx * 0.0055;
cam.phi = THREE.MathUtils.clamp(cam.phi - dy * 0.0050, 0.28, 1.46);
}
});
const endPointer = e => { pointers.delete(e.pointerId); if (pointers.size < 2) pinchDist = 0;
if (pointers.size === 0) dragging = false; };
dom.addEventListener('pointerup', endPointer);
dom.addEventListener('pointercancel', endPointer);
dom.addEventListener('contextmenu', e => e.preventDefault());
dom.addEventListener('wheel', e => {
e.preventDefault();
cam.r = THREE.MathUtils.clamp(cam.r * (1 + Math.sign(e.deltaY) * 0.10), 9, 60);
}, { passive:false });
/* ------------------------------------------------------------------ HUD */
let paused = false, showLabels = true, showArrows = true;
document.getElementById('bLabels').onclick = e => { showLabels = !showLabels; labelsGroup.visible = showLabels; e.target.classList.toggle('on', showLabels); };
document.getElementById('bArrows').onclick = e => { showArrows = !showArrows; arrows.forEach(a => a.visible = showArrows); e.target.classList.toggle('on', showArrows); };
document.getElementById('bPause').onclick = e => { paused = !paused; e.target.classList.toggle('on', paused); e.target.textContent = paused ? 'Resume' : 'Pause'; };
document.getElementById('bReset').onclick = () => { cam.r = CAM_HOME.r; cam.theta = CAM_HOME.theta; cam.phi = CAM_HOME.phi; cam.target.copy(CAM_HOME.target); };
/* ------------------------------------------------------------- animation */
let beltPhase = 0, t = 0;
const clock = new THREE.Clock();
function update(dt){
// transform belts: continuous one-way slide, looping seamlessly (period = feature spacing)
beltPhase = (beltPhase + dt * 0.30) % PERIOD;
const d = beltPhase - PERIOD/2;
leftBelt.position.z = d; // left plate slides one way ...
rightBelt.position.z = -d; // ... right plate slides the other way
// subduction markers: plate material diving under the arc
for (let i = 0; i < tracers.length; i++){
const u = (t * 0.105 + i / tracers.length) % 1;
samplePath(u, tmpP, tmpD);
tracers[i].position.copy(tmpP);
tracers[i].quaternion.setFromUnitVectors(UP, tmpD);
const fade = THREE.MathUtils.clamp(Math.min(u, 1-u) * 7.0, 0, 1);
tracers[i].material.opacity = 0.95 * fade;
tracers[i].visible = fade > 0.02;
}
// volcano smoke
for (const p of puffs){
const u = (t * 0.28 + p.ph) % 1;
p.m.position.set(3.00 + Math.sin(u*6.0)*0.10*u, 2.35 + u*1.55, 0.05 + Math.cos(u*5.0)*0.08*u);
p.m.scale.setScalar(0.7 + u*1.9);
p.m.material.opacity = 0.42 * Math.sin(Math.PI * u);
p.m.material.transparent = true;
}
// arrow pulse
for (let i = 0; i < arrows.length; i++){
const s = 1 + 0.055 * Math.sin(t * 2.6 + i * 1.7);
arrows[i].scale.setScalar(s);
arrows[i].userData.mat.emissiveIntensity = 0.30 + 0.30 * (0.5 + 0.5*Math.sin(t*2.6 + i*1.7));
}
}
function animate(){
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused){ t += dt; update(dt); }
updateCamera();
renderer.render(scene, camera);
}
animate();
addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
```