Prompt specification
Build or customize the Three.js 3D scene "Glacially smoothed rock and moraine clasts" 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: Glacially smoothed rock and moraine clasts
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/glacially-smoothed-rock-and-moraine-clasts-x3109
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a stylized solid geomorphology display. On the left, place a smoothed bedrock fragment with a rounded exposed face and a few aligned surface grooves; on the right, arrange angular stones of varied sizes in a loose deposit. Use one consistent scale and a pale base that separates the two surfaces clearly. Provide small observation tags for shape, texture, and arrangement, followed by a source-based example interpretation. Do not let the labels claim that shape alone proves glacial origin.
Working Three.js Starter (glacially-smoothed-rock-and-moraine-clasts-x3109):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Two Surfaces — Geomorphology Display</title>
<style>
:root {
--paper: #f3f0e8;
--panel: #faf8f2;
--ink: #252923;
--muted: #70746a;
--line: #d7d4ca;
--moss: #59634e;
--moss-dark: #394333;
--stone: #8a8071;
--warm: #a58f76;
--white: #fffdf7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
sans-serif;
-webkit-font-smoothing: antialiased;
}
button,
a {
-webkit-tap-highlight-color: transparent;
}
.app {
display: grid;
grid-template-columns: minmax(0, 1fr) 370px;
width: 100%;
height: 100dvh;
}
.stage {
position: relative;
min-width: 0;
overflow: hidden;
isolation: isolate;
background:
radial-gradient(
circle at 45% 38%,
rgba(255, 254, 249, 0.95) 0,
rgba(241, 238, 229, 0.94) 48%,
rgba(226, 222, 211, 0.98) 100%
);
}
.stage::before {
position: absolute;
inset: 0;
z-index: -1;
content: "";
pointer-events: none;
opacity: 0.22;
background:
repeating-radial-gradient(
ellipse at 48% 52%,
transparent 0 52px,
rgba(81, 86, 73, 0.12) 53px 54px
);
mask-image: linear-gradient(
to bottom,
transparent 0,
black 20%,
black 70%,
transparent 100%
);
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#viewport canvas:active {
cursor: grabbing;
}
#viewport canvas:focus-visible {
outline: 2px solid var(--moss);
outline-offset: -4px;
}
.scene-header {
position: absolute;
top: 34px;
left: 38px;
z-index: 3;
width: min(430px, calc(100% - 190px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 15px;
color: var(--moss);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 27px;
height: 1px;
content: "";
background: currentColor;
}
.scene-header h1 {
margin: 0;
max-width: 410px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(35px, 4.25vw, 66px);
font-weight: 400;
line-height: 0.96;
letter-spacing: -0.045em;
}
.scene-header h1 em {
color: var(--moss);
font-weight: 400;
}
.scene-header p {
max-width: 320px;
margin: 17px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
letter-spacing: 0.02em;
}
.toolbar {
position: absolute;
top: 32px;
right: 30px;
z-index: 5;
display: flex;
align-items: center;
gap: 6px;
padding: 5px;
border: 1px solid rgba(73, 77, 65, 0.16);
border-radius: 999px;
background: rgba(255, 253, 247, 0.76);
box-shadow: 0 8px 30px rgba(44, 45, 39, 0.08);
backdrop-filter: blur(12px);
}
.toolbar button {
display: grid;
width: 34px;
height: 34px;
padding: 0;
place-items: center;
border: 0;
border-radius: 50%;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 18px;
cursor: pointer;
transition:
color 150ms ease,
background 150ms ease;
}
.toolbar button:hover,
.toolbar button:focus-visible {
outline: none;
background: var(--moss);
color: var(--white);
}
.toolbar .reset {
width: auto;
padding: 0 14px;
border-radius: 999px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.toolbar-divider {
width: 1px;
height: 18px;
background: var(--line);
}
.scene-label {
position: absolute;
z-index: 3;
display: flex;
align-items: center;
gap: 8px;
min-width: max-content;
padding: 8px 10px;
border: 1px solid rgba(62, 66, 56, 0.17);
border-radius: 4px;
background: rgba(255, 253, 247, 0.84);
box-shadow: 0 5px 20px rgba(44, 45, 39, 0.08);
color: var(--ink);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
transform: translate(-50%, calc(-100% - 18px));
backdrop-filter: blur(8px);
transition: opacity 120ms ease;
}
.scene-label::after {
position: absolute;
bottom: -18px;
left: 50%;
width: 1px;
height: 18px;
content: "";
background: rgba(61, 66, 56, 0.48);
}
.scene-label__dot {
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--moss);
box-shadow: 0 0 0 4px rgba(89, 99, 78, 0.12);
}
.scene-label small {
display: block;
margin-bottom: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.16em;
}
.scene-label.scale-label {
padding: 5px 8px;
font-size: 8px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.is-hidden {
opacity: 0 !important;
}
.stage-footer {
position: absolute;
right: 30px;
bottom: 24px;
z-index: 3;
display: flex;
align-items: center;
gap: 10px;
color: rgba(50, 55, 47, 0.66);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.stage-footer span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.stage-footer span::before {
width: 5px;
height: 5px;
border-radius: 50%;
content: "";
background: currentColor;
}
.panel {
position: relative;
z-index: 6;
overflow-y: auto;
padding: 34px 30px 32px;
border-left: 1px solid var(--line);
background:
linear-gradient(rgba(250, 248, 242, 0.96), rgba(250, 248, 242, 0.96)),
repeating-linear-gradient(
0deg,
transparent 0 31px,
rgba(68, 73, 62, 0.06) 32px
);
scrollbar-width: thin;
scrollbar-color: #c7c5bc transparent;
}
.panel-kicker {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
color: var(--moss);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.panel-kicker span:last-child {
color: #98998f;
font-variant-numeric: tabular-nums;
}
.panel h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 31px;
font-weight: 400;
line-height: 1.06;
letter-spacing: -0.035em;
}
.panel-intro {
margin: 13px 0 24px;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
}
.specimens {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 27px;
}
.specimen {
padding: 13px;
border: 1px solid var(--line);
border-radius: 5px;
background: rgba(255, 255, 255, 0.35);
}
.specimen i {
display: block;
width: 23px;
height: 7px;
margin-bottom: 18px;
border-radius: 20px;
background: var(--stone);
}
.specimen.angular i {
width: 17px;
height: 17px;
border-radius: 3px;
background: #9c8e7c;
transform: rotate(12deg);
}
.specimen small {
display: block;
margin-bottom: 4px;
color: #93958b;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.specimen strong {
font-family: Georgia, "Times New Roman", serif;
font-size: 16px;
font-weight: 400;
}
.section-heading {
display: flex;
align-items: center;
gap: 10px;
margin: 0 0 13px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.section-heading::after {
flex: 1;
height: 1px;
content: "";
background: var(--line);
}
.observations {
margin-bottom: 25px;
border-top: 1px solid var(--line);
}
.observation {
display: grid;
grid-template-columns: 76px 1fr;
gap: 12px;
padding: 13px 0;
border-bottom: 1px solid var(--line);
}
.observation-tag {
align-self: start;
padding: 5px 6px;
border: 1px solid #c8cabe;
border-radius: 3px;
color: var(--moss-dark);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.09em;
text-align: center;
text-transform: uppercase;
}
.observation p {
margin: 0;
color: #666a61;
font-size: 11px;
line-height: 1.6;
}
.observation strong {
color: #33382f;
font-weight: 700;
}
.interpretation {
position: relative;
overflow: hidden;
padding: 20px 19px 18px;
border-radius: 6px;
background: var(--moss-dark);
color: #f2f0e8;
box-shadow: 0 12px 35px rgba(45, 51, 40, 0.12);
}
.interpretation::after {
position: absolute;
right: -35px;
bottom: -50px;
width: 130px;
height: 130px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 50%;
content: "";
box-shadow:
0 0 0 18px rgba(255, 255, 255, 0.025),
0 0 0 37px rgba(255, 255, 255, 0.018);
}
.interpretation-label {
display: inline-block;
margin-bottom: 12px;
padding: 5px 7px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 3px;
color: #cfd7c5;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.interpretation h3 {
position: relative;
z-index: 1;
margin: 0 0 10px;
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
font-weight: 400;
line-height: 1.12;
}
.interpretation p {
position: relative;
z-index: 1;
margin: 0;
color: #d6d9cf;
font-size: 11px;
line-height: 1.72;
}
.caution {
position: relative;
z-index: 1;
display: grid;
grid-template-columns: 22px 1fr;
gap: 9px;
margin-top: 16px;
padding-top: 14px;
border-top: 1px solid rgba(255, 255, 255, 0.14);
}
.caution-mark {
display: grid;
width: 21px;
height: 21px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 50%;
color: #f3d59f;
font-family: Georgia, serif;
font-size: 12px;
}
.caution p {
font-size: 10px;
line-height: 1.55;
}
.sources {
margin-top: 22px;
}
.source-list {
margin: 0;
padding: 0;
list-style: none;
}
.source-list li {
padding: 10px 0;
border-top: 1px solid var(--line);
}
.source-list a {
color: #42483d;
font-size: 10px;
font-weight: 700;
line-height: 1.45;
text-decoration-color: #a8ad9d;
text-underline-offset: 3px;
}
.source-list a:hover,
.source-list a:focus-visible {
color: var(--moss);
}
.source-list span {
display: block;
margin-top: 3px;
color: #92958c;
font-size: 9px;
line-height: 1.45;
}
.panel-note {
margin: 18px 0 0;
color: #92958c;
font-size: 9px;
line-height: 1.55;
}
.mobile-instruction {
display: none;
}
@media (max-width: 980px) {
body {
overflow: auto;
}
.app {
grid-template-columns: 1fr;
grid-template-rows: minmax(540px, 67dvh) auto;
height: auto;
min-height: 100dvh;
}
.panel {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
.scene-header {
top: 25px;
left: 25px;
}
.toolbar {
top: 23px;
right: 20px;
}
}
@media (max-width: 620px) {
.app {
grid-template-rows: minmax(470px, 62dvh) auto;
}
.scene-header {
top: 22px;
left: 20px;
width: calc(100% - 40px);
}
.scene-header h1 {
font-size: 38px;
}
.scene-header p {
display: none;
}
.toolbar {
top: auto;
right: 16px;
bottom: 17px;
}
.stage-footer {
right: auto;
bottom: 27px;
left: 18px;
}
.stage-footer .drag-hint {
display: none;
}
.panel {
padding: 29px 21px;
}
.mobile-instruction {
display: inline;
}
}
</style>
</head>
<body>
<main class="app">
<section class="stage" id="stage" aria-label="Interactive three-dimensional geomorphology comparison">
<div id="viewport"></div>
<header class="scene-header">
<div class="eyebrow">Geomorphology study / 04</div>
<h1>Two surfaces.<br><em>One shared scale.</em></h1>
<p>
A comparative study of an exposed bedrock fragment and a loose deposit
of angular stones.
</p>
</header>
<nav class="toolbar" aria-label="Camera controls">
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<span class="toolbar-divider" aria-hidden="true"></span>
<button id="resetView" class="reset" type="button">Reset</button>
</nav>
<div
id="bedrockLabel"
class="scene-label"
aria-hidden="true"
>
<span class="scene-label__dot"></span>
<span><small>Left surface</small>Smoothed bedrock</span>
</div>
<div
id="stoneLabel"
class="scene-label"
aria-hidden="true"
>
<span class="scene-label__dot"></span>
<span><small>Right surface</small>Angular stone deposit</span>
</div>
<div
id="scaleLabel"
class="scene-label scale-label"
aria-hidden="true"
>
1 m · shared scale
</div>
<div class="stage-footer" aria-hidden="true">
<span class="drag-hint">Drag to orbit</span>
<span class="mobile-instruction">Drag · pinch</span>
<span>Scroll to zoom</span>
</div>
</section>
<aside class="panel" aria-label="Field observations and interpretation">
<div class="panel-kicker">
<span>Comparative field notes</span>
<span>FIG. 04</span>
</div>
<h2>Read the form first.</h2>
<p class="panel-intro">
Both specimens are rendered on the same scale. The notes below describe
visible shape, texture, and arrangement without assigning an origin.
</p>
<div class="specimens" aria-label="Specimen key">
<div class="specimen">
<i aria-hidden="true"></i>
<small>Left</small>
<strong>Bedrock</strong>
</div>
<div class="specimen angular">
<i aria-hidden="true"></i>
<small>Right</small>
<strong>Stone deposit</strong>
</div>
</div>
<h3 class="section-heading">Observation tags</h3>
<section class="observations" aria-label="Observations">
<div class="observation">
<span class="observation-tag">Shape</span>
<p>
<strong>Left:</strong> broad, rounded exposed face.<br />
<strong>Right:</strong> angular outlines with sharp edges.
</p>
</div>
<div class="observation">
<span class="observation-tag">Texture</span>
<p>
<strong>Left:</strong> smooth surface with a few subparallel grooves.<br />
<strong>Right:</strong> rough, flat facets and varied faces.
</p>
</div>
<div class="observation">
<span class="observation-tag">Arrangement</span>
<p>
<strong>Left:</strong> one continuous rock mass.<br />
<strong>Right:</strong> dispersed clasts of mixed sizes with open gaps.
</p>
</div>
</section>
<section class="interpretation">
<span class="interpretation-label">Example · not a diagnosis</span>
<h3>What these forms could suggest</h3>
<p>
Glacial ice can abrade bedrock, and debris carried at the ice base can
leave linear marks on a smoothed surface. The left-hand form is
therefore <strong>compatible with glacial abrasion</strong>, as described
in the USGS and University of Minnesota Extension references below.
The right-hand deposit is recorded here by its visible form and spacing.
</p>
<div class="caution">
<span class="caution-mark" aria-hidden="true">!</span>
<p>
<strong>Shape alone does not prove glacial origin.</strong>
Rounded forms and grooves can have other causes. A genetic
interpretation requires local context, geological relationships,
fabric analysis, and other independent evidence.
</p>
</div>
</section>
<section class="sources" aria-label="Sources">
<h3 class="section-heading">Source guide</h3>
<ul class="source-list">
<li>
<a
href="https://pubs.usgs.gov/gip/ms017/"
target="_blank"
rel="noopener noreferrer"
>
U.S. Geological Survey — Glaciers and Icecaps
</a>
<span>
General reference for glacial erosion, polished bedrock, and
glacial markings.
</span>
</li>
<li>
<a
href="https://extension.umn.edu/environment-and-gis/glaciers-and-glaciation"
target="_blank"
rel="noopener noreferrer"
>
University of Minnesota Extension — Glaciers and Glaciation
</a>
<span>
Educational overview of glacial processes and landform development.
</span>
</li>
</ul>
</section>
<p class="panel-note">
The 3D specimen is a schematic illustration, not a field measurement.
Its relative proportions and the 1 m scale bar are shared across both
surfaces.
</p>
</aside>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const stage = document.getElementById("stage");
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xebe8df, 17, 32);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const canvas = renderer.domElement;
canvas.tabIndex = 0;
canvas.setAttribute(
"aria-label",
"Interactive 3D comparison of smoothed bedrock and angular stones. Drag to orbit, scroll or pinch to zoom."
);
const camera = new THREE.PerspectiveCamera(
35,
1,
0.1,
100
);
const controls = {
theta: 0.18,
phi: 1.13,
radius: 13.7,
target: new THREE.Vector3(0, 0.65, 0)
};
const initialControls = {
theta: 0.18,
phi: 1.13,
radius: 13.7
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
// Lighting
const hemisphere = new THREE.HemisphereLight(0xfffdf5, 0x777064, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4df, 3.2);
keyLight.position.set(-4.5, 9.5, 7.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00025;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xdce6e1, 1.15);
fillLight.position.set(7, 4, -6);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xe8d8bd, 14, 18, 2);
rimLight.position.set(-4, 4, -3);
scene.add(rimLight);
// Ground
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe9e5db,
roughness: 1,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.09;
ground.receiveShadow = true;
scene.add(ground);
// Shared pale plinth
function makeRoundedRectShape(width, depth, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -depth / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + depth - radius);
shape.quadraticCurveTo(
x + width,
y + depth,
x + width - radius,
y + depth
);
shape.lineTo(x + radius, y + depth);
shape.quadraticCurveTo(x, y + depth, x, y + depth - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
shape.closePath();
return shape;
}
const baseShape = makeRoundedRectShape(11.2, 5.4, 0.32);
const baseGeometry = new THREE.ExtrudeGeometry(baseShape, {
depth: 0.2,
bevelEnabled: true,
bevelSegments: 4,
bevelSize: 0.055,
bevelThickness: 0.045,
curveSegments: 10
});
baseGeometry.rotateX(-Math.PI / 2);
baseGeometry.computeVertexNormals();
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0xd8d5ca,
roughness: 0.93,
metalness: 0
});
const base = new THREE.Mesh(baseGeometry, baseMaterial);
base.receiveShadow = true;
base.castShadow = true;
scene.add(base);
base.geometry.computeBoundingBox();
const baseTop = base.geometry.boundingBox.max.y;
// A restrained divider makes the two observational surfaces explicit.
const seam = new THREE.Mesh(
new THREE.BoxGeometry(0.027, 0.012, 4.88),
new THREE.MeshStandardMaterial({
color: 0xb8b5ab,
roughness: 1
})
);
seam.position.set(0, baseTop + 0.003, 0);
seam.receiveShadow = true;
scene.add(seam);
// Smooth bedrock fragment
const bedrockMaterial = new THREE.MeshStandardMaterial({
color: 0x82796b,
roughness: 0.91,
metalness: 0
});
const grooveTargets = [0.42, 0.76, 1.08];
function deformBedrock(nx, ny, nz) {
let x = nx * 2.32 + 0.07 * Math.sin(ny * 2.5 + nz * 1.6);
let y = ny * 1.04;
let z = nz * 1.52 + 0.05 * Math.sin(nx * 2.1 - nz * 1.3);
y +=
0.055 * Math.sin(nx * 3.1 + ny * 1.8) +
0.035 * Math.sin(nz * 4.2 - ny * 2.0);
const xEnvelope = Math.exp(-Math.pow(x / 2.05, 4));
const surfaceMask =
THREE.MathUtils.clamp((y + 0.2) / 0.75, 0, 1) *
THREE.MathUtils.clamp((z - 0.05) / 0.35, 0, 1);
let grooveDepth = 0;
for (const target of grooveTargets) {
grooveDepth +=
0.085 *
Math.exp(-Math.pow((z - target) / 0.075, 2)) *
xEnvelope *
surfaceMask;
}
y -= grooveDepth;
// A flattened underside gives the fragment a stable seated profile.
if (y < -0.72) {
y = -0.72 + (y + 0.72) * 0.08;
}
return new THREE.Vector3(x, y, z);
}
const bedrockGeometry = new THREE.SphereGeometry(1, 96, 64);
const bedrockPositions = bedrockGeometry.attributes.position;
for (let i = 0; i < bedrockPositions.count; i++) {
const nx = bedrockPositions.getX(i);
const ny = bedrockPositions.getY(i);
const nz = bedrockPositions.getZ(i);
const p = deformBedrock(nx, ny, nz);
bedrockPositions.setXYZ(i, p.x, p.y, p.z);
}
bedrockGeometry.computeVertexNormals();
bedrockGeometry.computeBoundingBox();
const bedrock = new THREE.Mesh(bedrockGeometry, bedrockMaterial);
bedrock.position.set(-2.65, baseTop + 0.745, 0.05);
bedrock.castShadow = true;
bedrock.receiveShadow = true;
scene.add(bedrock);
// Fine dark lines seated within the geometrically recessed grooves.
const grooveMaterial = new THREE.MeshStandardMaterial({
color: 0x4b463e,
roughness: 1,
metalness: 0
});
for (const targetZ of grooveTargets) {
const points = [];
for (let i = 0; i <= 48; i++) {
const desiredX = THREE.MathUtils.lerp(-1.78, 1.78, i / 48);
let nx = desiredX / 2.32;
let nz = (targetZ - 0.05 * Math.sin(nx * 2.1)) / 1.52;
for (let iteration = 0; iteration < 4; iteration++) {
nz =
(targetZ - 0.05 * Math.sin(nx * 2.1 - nz * 1.3)) / 1.52;
}
const ny = Math.sqrt(
Math.max(0.001, 1 - nx * nx - nz * nz)
);
const p = deformBedrock(nx, ny, nz);
points.push(new THREE.Vector3(p.x, p.y + 0.012, p.z));
}
const curve = new THREE.CatmullRomCurve3(
points,
false,
"centripetal"
);
const groove = new THREE.Mesh(
new THREE.TubeGeometry(curve, 64, 0.012, 5, false),
grooveMaterial
);
groove.position.copy(bedrock.position);
groove.castShadow = true;
scene.add(groove);
}
// Angular stones
function fract(value) {
return value - Math.floor(value);
}
function makeAngularStoneGeometry(seed) {
const source = new THREE.DodecahedronGeometry(1, 0);
const geometry = source.index ? source.toNonIndexed() : source;
if (geometry !== source) {
source.dispose();
}
const position = geometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const x = position.getX(i);
const y = position.getY(i);
const z = position.getZ(i);
const hash = Math.sin(
seed * 91.7 +
x * 31.1 +
y * 57.3 +
z * 23.9
) * 43758.5453;
const variation = 0.82 + 0.28 * fract(hash);
position.setXYZ(
i,
x * variation * (1 + 0.10 * y),
y * variation * (1 + 0.08 * x),
z * variation * (1 + 0.12 * y)
);
}
position.needsUpdate = true;
geometry.computeVertexNormals();
geometry.computeBoundingBox();
return geometry;
}
const stonePalette = [
0x8f8778,
0x766f66,
0xa0927d,
0x9e907c,
0x81776a,
0xaaa08d,
0x6f6961,
0xb0a38d
];
const stonePlacements = [
{ x: 1.15, z: 0.86, sx: 0.63, sy: 0.60, sz: 0.49 },
{ x: 2.02, z: 0.39, sx: 0.46, sy: 0.53, sz: 0.37 },
{ x: 2.72, z: 0.98, sx: 0.56, sy: 0.46, sz: 0.44 },
{ x: 3.48, z: 0.49, sx: 0.73, sy: 0.68, sz: 0.56 },
{ x: 4.38, z: 0.92, sx: 0.39, sy: 0.47, sz: 0.33 },
{ x: 1.43, z: -0.54, sx: 0.39, sy: 0.49, sz: 0.35 },
{ x: 2.29, z: -0.76, sx: 0.63, sy: 0.58, sz: 0.47 },
{ x: 3.23, z: -0.93, sx: 0.47, sy: 0.39, sz: 0.38 },
{ x: 4.23, z: -0.33, sx: 0.69, sy: 0.60, sz: 0.52 },
{ x: 1.02, z: -1.42, sx: 0.24, sy: 0.28, sz: 0.21 },
{ x: 1.91, z: -1.66, sx: 0.28, sy: 0.23, sz: 0.21 },
{ x: 2.76, z: -1.72, sx: 0.19, sy: 0.16, sz: 0.17 },
{ x: 3.56, z: -1.65, sx: 0.31, sy: 0.27, sz: 0.25 },
{ x: 4.55, z: -1.42, sx: 0.25, sy: 0.21, sz: 0.22 },
{ x: 3.78, z: 1.37, sx: 0.23, sy: 0.20, sz: 0.19 },
{ x: 2.28, z: 1.58, sx: 0.21, sy: 0.17, sz: 0.18 }
];
const stones = new THREE.Group();
stonePlacements.forEach((placement, index) => {
const geometry = makeAngularStoneGeometry(index + 3.17);
const material = new THREE.MeshStandardMaterial({
color: stonePalette[index % stonePalette.length],
roughness: 0.94,
metalness: 0,
flatShading: true
});
const stone = new THREE.Mesh(geometry, material);
stone.scale.set(
placement.sx,
placement.sy,
placement.sz
);
stone.position.set(placement.x, 0, placement.z);
stone.rotation.set(
0.12 + fract(index * 0.41) * 0.8,
fract(index * 0.73) * Math.PI * 2,
(fract(index * 0.57) - 0.5) * 0.55
);
stone.updateMatrixWorld(true);
stone.castShadow = true;
stone.receiveShadow = true;
// Seat each stone on the plinth after applying its random rotation.
const bounds = new THREE.Box3().setFromObject(stone);
stone.position.y = baseTop - bounds.min.y + 0.008;
stones.add(stone);
});
scene.add(stones);
// Shared 1 m scale bar on the front of the plinth.
const scaleGroup = new THREE.Group();
const scaleMaterial = new THREE.MeshBasicMaterial({
color: 0x3f473a
});
const scaleBar = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.018, 0.035),
scaleMaterial
);
scaleBar.position.set(0.5, 0.015, 0);
scaleGroup.add(scaleBar);
for (const x of [0, 1]) {
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 0.018, 0.18),
scaleMaterial
);
tick.position.set(x, 0.015, 0);
scaleGroup.add(tick);
}
scaleGroup.position.set(-4.65, baseTop + 0.012, 2.08);
scene.add(scaleGroup);
// HTML labels projected from 3D positions.
const labels = [
{
element: document.getElementById("bedrockLabel"),
position: new THREE.Vector3(-2.7, 2.42, 0.76)
},
{
element: document.getElementById("stoneLabel"),
position: new THREE.Vector3(2.95, 1.02, 1.38)
},
{
element: document.getElementById("scaleLabel"),
position: new THREE.Vector3(-4.15, baseTop + 0.08, 2.08)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12;
label.element.classList.toggle("is-hidden", !visible);
if (visible) {
label.element.style.left =
`${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
}
// Camera controls are implemented directly without external addons.
const pointers = new Map();
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
const dx = values[0].x - values[1].x;
const dy = values[0].y - values[1].y;
return Math.hypot(dx, dy);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.focus({ preventScroll: true });
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
previousX = event.clientX;
previousY = event.clientY;
previousPinchDistance = pointerDistance();
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
controls.theta -= deltaX * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - deltaY * 0.005,
0.38,
1.43
);
previousX = event.clientX;
previousY = event.clientY;
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * (previousPinchDistance / distance),
7.5,
19
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointerDistance();
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
7.5,
19
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
controls.theta += 0.09;
break;
case "ArrowRight":
controls.theta -= 0.09;
break;
case "ArrowUp":
controls.phi = THREE.MathUtils.clamp(
controls.phi - 0.07,
0.38,
1.43
);
break;
case "ArrowDown":
controls.phi = THREE.MathUtils.clamp(
controls.phi + 0.07,
0.38,
1.43
);
break;
case "+":
case "=":
controls.radius = Math.max(7.5, controls.radius * 0.9);
break;
case "-":
case "_":
controls.radius = Math.min(19, controls.radius * 1.1);
break;
case "0":
resetView();
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
function resetView() {
controls.theta = initialControls.theta;
controls.phi = initialControls.phi;
controls.radius = initialControls.radius;
}
document.getElementById("resetView").addEventListener("click", resetView);
document.getElementById("zoomIn").addEventListener("click", () => {
controls.radius = Math.max(7.5, controls.radius * 0.88);
});
document.getElementById("zoomOut").addEventListener("click", () => {
controls.radius = Math.min(19, controls.radius * 1.12);
});
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```