Prompt specification
Build or customize the Three.js 3D scene "Layered seismic propagation block" 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: Layered seismic propagation block
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/layered-seismic-propagation-block-x1181
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: layered seismic propagation block. Build a transparent ground block containing a marked source and concentric wavefront shells; distinguish source location from surface observation points using readable geometric markers.
Working Three.js Starter (layered-seismic-propagation-block-x1181):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#07131d">
<title>Layered Seismic Propagation Block</title>
<style>
:root {
--bg: #07131d;
--panel: rgba(10, 25, 36, 0.78);
--panel-border: rgba(157, 204, 224, 0.18);
--text: #e8f3f7;
--muted: #91a9b7;
--source: #ff7048;
--wave: #ffae78;
--receiver: #69ddff;
--line: rgba(154, 211, 235, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--text);
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
background:
radial-gradient(circle at 52% 45%, transparent 38%, rgba(1, 7, 12, 0.44) 100%),
linear-gradient(180deg, rgba(4, 11, 17, 0.16), rgba(4, 11, 17, 0.3));
}
.intro {
position: fixed;
top: 28px;
left: 30px;
z-index: 10;
width: min(440px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: #a9c5d3;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--source);
box-shadow: 0 0 0 5px rgba(255, 112, 72, 0.12);
animation: livePulse 1.8s ease-in-out infinite;
}
@keyframes livePulse {
50% {
opacity: 0.55;
transform: scale(0.75);
}
}
h1 {
max-width: 420px;
margin: 0;
font-size: clamp(30px, 4vw, 53px);
font-weight: 520;
line-height: 0.98;
letter-spacing: -0.045em;
text-wrap: balance;
text-shadow: 0 3px 24px rgba(0, 0, 0, 0.35);
}
.intro p {
max-width: 390px;
margin: 16px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.legend {
position: fixed;
z-index: 10;
top: 28px;
right: 30px;
width: 230px;
padding: 16px;
border: 1px solid var(--panel-border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(14px);
}
.legend-title,
.readout-title {
margin-bottom: 12px;
color: #b6cad4;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 11px;
min-height: 31px;
color: #c8d8df;
font-size: 12px;
}
.legend-symbol {
position: relative;
display: grid;
width: 22px;
height: 22px;
flex: 0 0 22px;
place-items: center;
}
.legend-symbol.source::before {
width: 9px;
height: 9px;
content: "";
background: var(--source);
transform: rotate(45deg);
box-shadow: 0 0 12px rgba(255, 112, 72, 0.55);
}
.legend-symbol.receiver::before {
width: 0;
height: 0;
content: "";
border-right: 7px solid transparent;
border-bottom: 12px solid var(--receiver);
border-left: 7px solid transparent;
filter: drop-shadow(0 0 7px rgba(105, 221, 255, 0.5));
}
.legend-symbol.wave::before {
width: 17px;
height: 17px;
content: "";
border: 1px solid var(--wave);
border-radius: 50%;
box-shadow:
0 0 0 3px rgba(255, 174, 120, 0.12),
inset 0 0 8px rgba(255, 174, 120, 0.14);
}
.readout {
position: fixed;
z-index: 10;
right: 30px;
bottom: 104px;
width: 230px;
padding: 16px;
border: 1px solid var(--panel-border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(14px);
}
.readout-grid {
display: grid;
grid-template-columns: 1fr auto;
gap: 10px 12px;
font-size: 12px;
}
.readout-grid span:nth-child(odd) {
color: var(--muted);
}
.readout-grid span:nth-child(even) {
color: #e7f3f7;
font-variant-numeric: tabular-nums;
}
.controls {
position: fixed;
z-index: 20;
bottom: 26px;
left: 50%;
display: flex;
align-items: center;
gap: 10px;
width: max-content;
max-width: calc(100vw - 32px);
padding: 10px;
border: 1px solid var(--panel-border);
border-radius: 15px;
background: rgba(9, 22, 32, 0.88);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.32);
transform: translateX(-50%);
backdrop-filter: blur(16px);
}
.control-button {
min-height: 36px;
padding: 0 14px;
border: 1px solid rgba(163, 207, 224, 0.18);
border-radius: 9px;
color: #d9e8ee;
background: rgba(129, 169, 188, 0.08);
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.control-button:hover {
border-color: rgba(105, 221, 255, 0.42);
background: rgba(105, 221, 255, 0.1);
}
.control-button:active {
transform: translateY(1px);
}
.control-button.primary {
min-width: 78px;
border-color: rgba(255, 112, 72, 0.38);
color: #fff0e9;
background: rgba(255, 112, 72, 0.13);
}
.speed-control {
display: flex;
align-items: center;
gap: 9px;
padding: 0 8px;
color: var(--muted);
font-size: 11px;
}
.speed-control input {
width: 92px;
accent-color: var(--receiver);
cursor: pointer;
}
#speed-value {
width: 28px;
color: #d7e6ec;
font-variant-numeric: tabular-nums;
}
.hint {
position: fixed;
z-index: 8;
bottom: 32px;
left: 30px;
color: rgba(185, 207, 217, 0.62);
font-size: 11px;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 6;
overflow: hidden;
pointer-events: none;
}
.marker-label {
position: absolute;
padding: 5px 8px;
border: 1px solid rgba(149, 206, 229, 0.24);
border-radius: 6px;
color: #dcecf1;
background: rgba(6, 18, 27, 0.84);
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.24);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
white-space: nowrap;
opacity: 0;
transform: translate(-50%, -125%);
transition: opacity 120ms linear;
}
.marker-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 9px;
content: "";
background: rgba(163, 211, 229, 0.4);
}
.marker-label.source {
border-color: rgba(255, 112, 72, 0.52);
color: #ffd5c6;
background: rgba(56, 20, 13, 0.88);
}
.marker-label.source::after {
background: rgba(255, 112, 72, 0.7);
}
.marker-label.receiver {
border-color: rgba(105, 221, 255, 0.45);
color: #cdf4ff;
}
.marker-label.receiver::after {
background: rgba(105, 221, 255, 0.65);
}
@media (max-width: 800px) {
.intro {
top: 18px;
left: 18px;
}
.intro p {
display: none;
}
.legend {
top: 18px;
right: 18px;
width: auto;
padding: 11px;
}
.legend-title,
.legend-row span:last-child {
display: none;
}
.legend-row {
min-height: 27px;
}
.readout {
right: 18px;
bottom: 98px;
width: 190px;
}
.hint {
display: none;
}
.controls {
bottom: 14px;
gap: 6px;
padding: 8px;
}
.control-button {
padding: 0 10px;
font-size: 12px;
}
.speed-control {
display: none;
}
}
@media (max-width: 480px) {
h1 {
max-width: 245px;
font-size: 29px;
}
.readout {
display: none;
}
.legend {
top: 16px;
right: 14px;
}
.intro {
left: 14px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive three-dimensional seismic propagation model"></main>
<div class="vignette" aria-hidden="true"></div>
<header class="intro">
<div class="eyebrow">
<span class="live-dot"></span>
Seismic visualization / live model
</div>
<h1>Layered seismic propagation block</h1>
<p>
A translucent geological section with a subsurface source,
expanding wavefront shells, and five surface observation stations.
</p>
</header>
<section class="legend" aria-label="Scene legend">
<div class="legend-title">Marker key</div>
<div class="legend-row">
<span class="legend-symbol source"></span>
<span>Subsurface source</span>
</div>
<div class="legend-row">
<span class="legend-symbol wave"></span>
<span>Wavefront shell</span>
</div>
<div class="legend-row">
<span class="legend-symbol receiver"></span>
<span>Surface observation point</span>
</div>
</section>
<aside class="readout" aria-label="Model information">
<div class="readout-title">Model readout</div>
<div class="readout-grid">
<span>Source depth</span><span>2.8 m</span>
<span>Observers</span><span>5</span>
<span>Geological layers</span><span>3</span>
<span>Current front</span><span id="front-distance">0.0 m</span>
<span>Block volume</span><span>15 × 9 × 4.2</span>
</div>
</aside>
<nav class="controls" aria-label="Animation and camera controls">
<button class="control-button primary" id="play-button" type="button">Pause</button>
<button class="control-button" id="reset-button" type="button">Reset view</button>
<label class="speed-control" for="speed">
Speed
<input id="speed" type="range" min="0.25" max="2" step="0.05" value="1">
<span id="speed-value">1.0×</span>
</label>
</nav>
<div class="hint">Drag to orbit · Scroll or pinch to zoom · Arrow keys to rotate</div>
<div id="labels" aria-hidden="true"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const mount = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.localClippingEnabled = true;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131d);
scene.fog = new THREE.Fog(0x07131d, 19, 39);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Direct camera controls; no examples or addons are used.
const cameraState = {
target: new THREE.Vector3(0, -0.35, 0),
yaw: 0.68,
pitch: 0.57,
radius: 18.5
};
function applyCamera() {
const { target, yaw, pitch, radius } = cameraState;
const sinPitch = Math.sin(pitch);
camera.position.set(
target.x + radius * sinPitch * Math.sin(yaw),
target.y + radius * Math.cos(pitch),
target.z + radius * sinPitch * Math.cos(yaw)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
applyCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb8dded, 0x071018, 2.1));
const keyLight = new THREE.DirectionalLight(0xffd8b7, 3.1);
keyLight.position.set(-5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
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 = 32;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x66d8ff, 1.8);
rimLight.position.set(8, 3, -7);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Geological block dimensions
// -------------------------------------------------------------------------
const BLOCK_W = 15;
const BLOCK_D = 9;
const BLOCK_BOTTOM = -2.6;
const BLOCK_TOP = 1.6;
const BLOCK_H = BLOCK_TOP - BLOCK_BOTTOM;
const block = new THREE.Group();
scene.add(block);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 25),
new THREE.MeshStandardMaterial({
color: 0x081722,
roughness: 0.94,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = BLOCK_BOTTOM - 0.32;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x315767, 0x17303c);
grid.position.y = BLOCK_BOTTOM - 0.30;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
// Transparent enclosing volume.
const enclosure = new THREE.Mesh(
new THREE.BoxGeometry(BLOCK_W, BLOCK_H, BLOCK_D),
new THREE.MeshPhysicalMaterial({
color: 0x76bed6,
transparent: true,
opacity: 0.055,
roughness: 0.25,
metalness: 0.02,
side: THREE.DoubleSide,
depthWrite: false
})
);
enclosure.position.y = (BLOCK_TOP + BLOCK_BOTTOM) / 2;
enclosure.renderOrder = 7;
block.add(enclosure);
const enclosureEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(enclosure.geometry),
new THREE.LineBasicMaterial({
color: 0x89b8cb,
transparent: true,
opacity: 0.47
})
);
enclosureEdges.position.copy(enclosure.position);
enclosureEdges.renderOrder = 10;
block.add(enclosureEdges);
// Three translucent, color-coded geological layers.
const strata = [
{ bottom: -2.6, top: -1.6, color: 0x17374c, opacity: 0.26 },
{ bottom: -1.6, top: -0.3, color: 0x24665f, opacity: 0.23 },
{ bottom: -0.3, top: 1.58, color: 0x77715c, opacity: 0.18 }
];
for (const stratum of strata) {
const height = stratum.top - stratum.bottom;
const geometry = new THREE.BoxGeometry(BLOCK_W, height, BLOCK_D);
const material = new THREE.MeshStandardMaterial({
color: stratum.color,
transparent: true,
opacity: stratum.opacity,
roughness: 0.92,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false,
flatShading: true
});
const layer = new THREE.Mesh(geometry, material);
layer.position.y = (stratum.bottom + stratum.top) / 2;
layer.renderOrder = 1;
block.add(layer);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
new THREE.LineBasicMaterial({
color: stratum.color,
transparent: true,
opacity: 0.48
})
);
edges.position.copy(layer.position);
edges.renderOrder = 5;
block.add(edges);
}
// -------------------------------------------------------------------------
// Low-poly faceted terrain surface
// -------------------------------------------------------------------------
function terrainHeight(x, z) {
const edgeDistance = Math.min(
BLOCK_W / 2 - Math.abs(x),
BLOCK_D / 2 - Math.abs(z)
);
const edgeFactor = THREE.MathUtils.clamp(edgeDistance / 1.15, 0, 1);
return (
BLOCK_TOP +
edgeFactor *
0.075 *
(Math.sin(x * 0.73 + z * 0.31) * Math.cos(z * 0.57) +
0.35 * Math.sin(x * 1.31 - z * 0.83))
);
}
const terrainSegmentsX = 14;
const terrainSegmentsZ = 8;
const terrainPositions = [];
const terrainColors = [];
const terrainIndices = [];
const terrainBase = new THREE.Color(0x3c7468);
for (let iz = 0; iz <= terrainSegmentsZ; iz++) {
const z = -BLOCK_D / 2 + (BLOCK_D * iz) / terrainSegmentsZ;
for (let ix = 0; ix <= terrainSegmentsX; ix++) {
const x = -BLOCK_W / 2 + (BLOCK_W * ix) / terrainSegmentsX;
const y = terrainHeight(x, z);
terrainPositions.push(x, y, z);
const color = terrainBase.clone();
color.offsetHSL(
0.015 * Math.sin(x * 0.6 + z),
-0.03,
0.035 * Math.cos(x * 0.8 - z * 0.5)
);
terrainColors.push(color.r, color.g, color.b);
}
}
for (let iz = 0; iz < terrainSegmentsZ; iz++) {
for (let ix = 0; ix < terrainSegmentsX; ix++) {
const a = iz * (terrainSegmentsX + 1) + ix;
const b = a + 1;
const c = a + terrainSegmentsX + 1;
const d = c + 1;
if ((ix + iz) % 2 === 0) {
terrainIndices.push(a, c, b, b, c, d);
} else {
terrainIndices.push(a, c, d, a, d, b);
}
}
}
const terrainGeometry = new THREE.BufferGeometry();
terrainGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(terrainPositions, 3)
);
terrainGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.setIndex(terrainIndices);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
transparent: true,
opacity: 0.67,
roughness: 0.96,
metalness: 0,
side: THREE.DoubleSide,
flatShading: true
})
);
terrain.receiveShadow = true;
terrain.renderOrder = 4;
block.add(terrain);
const terrainWire = new THREE.LineSegments(
new THREE.WireframeGeometry(terrainGeometry),
new THREE.LineBasicMaterial({
color: 0xb5e3d7,
transparent: true,
opacity: 0.09,
depthWrite: false
})
);
terrainWire.renderOrder = 6;
block.add(terrainWire);
// Angular inclusions in the lowest stratum.
const inclusionGeometry = new THREE.IcosahedronGeometry(1, 0);
const inclusionMaterials = [
new THREE.MeshStandardMaterial({
color: 0x294b5b,
transparent: true,
opacity: 0.32,
roughness: 1,
depthWrite: false,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x3d5d62,
transparent: true,
opacity: 0.22,
roughness: 1,
depthWrite: false,
flatShading: true
})
];
for (let i = 0; i < 18; i++) {
const inclusion = new THREE.Mesh(
inclusionGeometry,
inclusionMaterials[i % inclusionMaterials.length]
);
const x = -BLOCK_W / 2 + 0.8 + ((i * 1.917) % (BLOCK_W - 1.6));
const z = -BLOCK_D / 2 + 0.7 + ((i * 1.371) % (BLOCK_D - 1.4));
const scale = 0.12 + ((i * 0.071) % 0.23);
inclusion.position.set(x, -2.08 + (i % 3) * 0.13, z);
inclusion.scale.set(scale * 1.7, scale, scale * 1.15);
inclusion.rotation.set(i * 0.4, i * 0.7, i * 0.25);
inclusion.renderOrder = 2;
block.add(inclusion);
}
// -------------------------------------------------------------------------
// Source marker: orange octahedron, distinct from triangular receivers
// -------------------------------------------------------------------------
const sourcePosition = new THREE.Vector3(-2.6, -1.25, 0.35);
const sourceGroup = new THREE.Group();
sourceGroup.position.copy(sourcePosition);
block.add(sourceGroup);
const sourceMaterial = new THREE.MeshStandardMaterial({
color: 0xff7048,
emissive: 0xff351b,
emissiveIntensity: 0.8,
roughness: 0.3,
metalness: 0.08,
depthTest: false,
flatShading: true
});
const sourceDiamond = new THREE.Mesh(
new THREE.OctahedronGeometry(0.28, 0),
sourceMaterial
);
sourceDiamond.renderOrder = 30;
sourceGroup.add(sourceDiamond);
const sourceHalo = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.IcosahedronGeometry(0.43, 0)),
new THREE.LineBasicMaterial({
color: 0xffa27d,
transparent: true,
opacity: 0.8,
depthTest: false
})
);
sourceHalo.renderOrder = 31;
sourceGroup.add(sourceHalo);
const sourceRing = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.018, 5, 32),
new THREE.MeshBasicMaterial({
color: 0xff8b64,
transparent: true,
opacity: 0.75,
depthTest: false
})
);
sourceRing.rotation.x = Math.PI / 2;
sourceRing.renderOrder = 31;
sourceGroup.add(sourceRing);
// Dashed line connects the source to its surface epicenter.
const epicenter = new THREE.Vector3(
sourcePosition.x,
terrainHeight(sourcePosition.x, sourcePosition.z) + 0.025,
sourcePosition.z
);
const sourceTrace = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
sourcePosition,
epicenter
]),
new THREE.LineDashedMaterial({
color: 0xff8b64,
dashSize: 0.12,
gapSize: 0.09,
transparent: true,
opacity: 0.72,
depthTest: false
})
);
sourceTrace.computeLineDistances();
sourceTrace.renderOrder = 25;
block.add(sourceTrace);
const epicenterRing = new THREE.Mesh(
new THREE.RingGeometry(0.12, 0.22, 4),
new THREE.MeshBasicMaterial({
color: 0xff8b64,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide,
depthTest: false
})
);
epicenterRing.rotation.x = -Math.PI / 2;
epicenterRing.position.copy(epicenter);
epicenterRing.renderOrder = 26;
block.add(epicenterRing);
const sourceLight = new THREE.PointLight(0xff633d, 1.25, 5.5, 2);
sourceLight.position.copy(sourcePosition);
block.add(sourceLight);
// -------------------------------------------------------------------------
// Surface observation stations
// -------------------------------------------------------------------------
const receiverPositions = [
{ x: -5.45, z: 2.65 },
{ x: -1.15, z: 3.10 },
{ x: 2.05, z: 2.45 },
{ x: 4.90, z: -1.35 },
{ x: 0.15, z: -3.15 }
];
const receivers = [];
for (let i = 0; i < receiverPositions.length; i++) {
const station = receiverPositions[i];
const y = terrainHeight(station.x, station.z);
const receiverGroup = new THREE.Group();
receiverGroup.position.set(station.x, y, station.z);
block.add(receiverGroup);
const receiverMaterial = new THREE.MeshStandardMaterial({
color: 0x69ddff,
emissive: 0x167c9e,
emissiveIntensity: 0.8,
roughness: 0.4,
metalness: 0.05,
depthTest: false,
flatShading: true
});
const foot = new THREE.Mesh(
new THREE.RingGeometry(0.11, 0.2, 18),
new THREE.MeshBasicMaterial({
color: 0x69ddff,
transparent: true,
opacity: 0.82,
side: THREE.DoubleSide,
depthTest: false
})
);
foot.rotation.x = -Math.PI / 2;
foot.position.y = 0.025;
foot.renderOrder = 25;
receiverGroup.add(foot);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.36, 6),
receiverMaterial
);
stem.position.y = 0.19;
stem.renderOrder = 26;
receiverGroup.add(stem);
// A three-sided cone reads clearly as a triangular station marker.
const pyramid = new THREE.Mesh(
new THREE.ConeGeometry(0.17, 0.34, 3),
receiverMaterial
);
pyramid.position.y = 0.53;
pyramid.rotation.y = Math.PI / 6;
pyramid.renderOrder = 27;
receiverGroup.add(pyramid);
const arrivalHalo = new THREE.Mesh(
new THREE.RingGeometry(0.24, 0.29, 32),
new THREE.MeshBasicMaterial({
color: 0x8cecff,
transparent: true,
opacity: 0.18,
side: THREE.DoubleSide,
depthTest: false
})
);
arrivalHalo.rotation.x = -Math.PI / 2;
arrivalHalo.position.y = 0.04;
arrivalHalo.renderOrder = 24;
receiverGroup.add(arrivalHalo);
// A faint ray makes the source-to-observer relationship explicit.
const ray = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
sourcePosition,
new THREE.Vector3(station.x, y, station.z)
]),
new THREE.LineBasicMaterial({
color: 0xffba86,
transparent: true,
opacity: 0.16,
depthWrite: false,
depthTest: false
})
);
ray.renderOrder = 3;
block.add(ray);
receivers.push({
group: receiverGroup,
halo: arrivalHalo,
distance: sourcePosition.distanceTo(
new THREE.Vector3(station.x, y, station.z)
)
});
}
// -------------------------------------------------------------------------
// Concentric wavefront shells, clipped to the transparent geological block
// -------------------------------------------------------------------------
const clipPlanes = [
new THREE.Plane(new THREE.Vector3(1, 0, 0), BLOCK_W / 2),
new THREE.Plane(new THREE.Vector3(-1, 0, 0), BLOCK_W / 2),
new THREE.Plane(new THREE.Vector3(0, 1, 0), -BLOCK_BOTTOM),
new THREE.Plane(new THREE.Vector3(0, -1, 0), BLOCK_TOP),
new THREE.Plane(new THREE.Vector3(0, 0, 1), BLOCK_D / 2),
new THREE.Plane(new THREE.Vector3(0, 0, -1), BLOCK_D / 2)
];
const shellGeometry = new THREE.IcosahedronGeometry(1, 1);
const shellEdgeGeometry = new THREE.EdgesGeometry(shellGeometry, 8);
const shells = [];
for (let i = 0; i < 4; i++) {
const shellGroup = new THREE.Group();
shellGroup.position.copy(sourcePosition);
block.add(shellGroup);
const shellMaterial = new THREE.MeshBasicMaterial({
color: 0xff8356,
transparent: true,
opacity: 0.05,
side: THREE.DoubleSide,
depthWrite: false,
clippingPlanes: clipPlanes
});
const shellMesh = new THREE.Mesh(shellGeometry, shellMaterial);
shellMesh.renderOrder = 8;
shellGroup.add(shellMesh);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xffb27f,
transparent: true,
opacity: 0.3,
depthWrite: false,
clippingPlanes: clipPlanes
});
const shellEdges = new THREE.LineSegments(
shellEdgeGeometry,
edgeMaterial
);
shellEdges.renderOrder = 9;
shellGroup.add(shellEdges);
shells.push({
group: shellGroup,
material: shellMaterial,
edgeMaterial
});
}
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelLayer = document.querySelector("#labels");
const projectedLabels = [];
function createLabel(text, className, position) {
const element = document.createElement("div");
element.className = `marker-label ${className}`;
element.textContent = text;
labelLayer.appendChild(element);
projectedLabels.push({ element, position });
}
createLabel(
"SOURCE · S-01",
"source",
sourcePosition.clone().add(new THREE.Vector3(0, 0.52, 0))
);
receiverPositions.forEach((station, index) => {
const y = terrainHeight(station.x, station.z);
createLabel(
`OBS · P${index + 1}`,
"receiver",
new THREE.Vector3(station.x, y + 0.8, station.z)
);
});
const labelProjection = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const item of projectedLabels) {
labelProjection.copy(item.position).project(camera);
const visible =
labelProjection.z > -1 &&
labelProjection.z < 1 &&
labelProjection.x > -1.15 &&
labelProjection.x < 1.15 &&
labelProjection.y > -1.15 &&
labelProjection.y < 1.15;
item.element.style.opacity = visible ? "1" : "0";
if (visible) {
const x = (labelProjection.x * 0.5 + 0.5) * width;
const y = (-labelProjection.y * 0.5 + 0.5) * height;
item.element.style.left = `${x}px`;
item.element.style.top = `${y}px`;
}
}
}
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
let elapsed = 0;
let speed = 1;
let running = true;
const cycleDuration = 7.6;
const minimumRadius = 0.28;
const maximumDistance = Math.max(
...receivers.map((receiver) => receiver.distance)
);
const maximumRadius = maximumDistance + 1.15;
const radiusRange = maximumRadius - minimumRadius;
const frontDistanceElement = document.querySelector("#front-distance");
function updateScene() {
const cyclePhase = (elapsed / cycleDuration) % 1;
shells.forEach((shell, index) => {
const phase = (cyclePhase + index * 0.19) % 1;
const radius = minimumRadius + phase * radiusRange;
const envelope = Math.sin(phase * Math.PI);
shell.group.scale.setScalar(radius);
shell.material.opacity = 0.018 + envelope * 0.075;
shell.edgeMaterial.opacity = 0.08 + envelope * 0.38;
});
const sourcePulse = 1 + Math.sin(elapsed * 5.2) * 0.065;
sourceDiamond.scale.setScalar(sourcePulse);
sourceHalo.rotation.y = elapsed * 0.42;
sourceHalo.rotation.x = elapsed * 0.18;
sourceRing.rotation.z = elapsed * 0.32;
sourceLight.intensity = 1.1 + Math.sin(elapsed * 5.2) * 0.18;
// Highlight each observer as the primary wave reaches its distance.
receivers.forEach((receiver) => {
const arrivalPhase = THREE.MathUtils.clamp(
(receiver.distance - minimumRadius) / radiusRange,
0,
1
);
const difference = Math.abs(cyclePhase - arrivalPhase);
const arrivalPulse = Math.exp(-Math.pow(difference / 0.055, 2));
receiver.halo.material.opacity = 0.12 + arrivalPulse * 0.86;
const haloScale = 1 + arrivalPulse * 0.55;
receiver.halo.scale.setScalar(haloScale);
});
const primaryRadius = minimumRadius + cyclePhase * radiusRange;
frontDistanceElement.textContent = `${primaryRadius.toFixed(1)} m`;
}
// -------------------------------------------------------------------------
// Pointer, touch, wheel, and keyboard camera controls
// -------------------------------------------------------------------------
const pointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const current = { x: event.clientX, y: event.clientY };
pointers.set(event.pointerId, current);
if (pointers.size === 1) {
const dx = current.x - previous.x;
const dy = current.y - previous.y;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.2,
1.42
);
} else if (pointers.size >= 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / distance),
9,
31
);
}
pinchDistance = distance;
}
});
function removePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
renderer.domElement.addEventListener("lostpointercapture", removePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9,
31
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
switch (event.key) {
case "ArrowLeft":
cameraState.yaw += 0.08;
break;
case "ArrowRight":
cameraState.yaw -= 0.08;
break;
case "ArrowUp":
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch - 0.06,
0.2,
1.42
);
break;
case "ArrowDown":
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + 0.06,
0.2,
1.42
);
break;
case "+":
case "=":
cameraState.radius = Math.max(9, cameraState.radius - 0.7);
break;
case "-":
cameraState.radius = Math.min(31, cameraState.radius + 0.7);
break;
case "r":
case "R":
resetView();
break;
case " ":
event.preventDefault();
togglePlayback();
break;
}
});
function resetView() {
cameraState.yaw = 0.68;
cameraState.pitch = 0.57;
cameraState.radius = 18.5;
cameraState.target.set(0, -0.35, 0);
}
function togglePlayback() {
running = !running;
document.querySelector("#play-button").textContent = running
? "Pause"
: "Play";
}
document
.querySelector("#play-button")
.addEventListener("click", togglePlayback);
document
.querySelector("#reset-button")
.addEventListener("click", resetView);
document.querySelector("#speed").addEventListener("input", (event) => {
speed = Number(event.target.value);
document.querySelector("#speed-value").textContent = `${speed.toFixed(1)}×`;
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (running) {
elapsed += delta * speed;
}
updateScene();
applyCamera();
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```