Prompt specification
Build or customize the Three.js 3D scene "Jointed rock with weathered edges" 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: Jointed rock with weathered edges
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/jointed-rock-with-weathered-edges-x1197
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: jointed rock with weathered edges. Model a cracked rock block beside a rounded fragment, with altered outer surfaces highlighted; distinguish material breakdown from the later movement of debris.
Working Three.js Starter (jointed-rock-with-weathered-edges-x1197):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jointed Rock — Alteration and Later Debris Movement</title>
<style>
:root {
--ink: #253034;
--muted: #657176;
--paper: rgba(247, 244, 237, 0.91);
--line: rgba(45, 58, 62, 0.16);
--altered: #d8733f;
--altered-light: #e3a168;
--fresh: #667b82;
--movement: #27aebe;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 35%, #eee9df 0%, #d8d2c6 75%, #c7c0b3 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.55);
box-shadow: 0 16px 40px rgba(52, 49, 41, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title-card {
top: 22px;
left: 22px;
width: min(370px, calc(100vw - 44px));
padding: 19px 20px 17px;
border-radius: 17px;
}
.eyebrow {
margin-bottom: 8px;
color: #727c7e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 330px;
font-size: clamp(23px, 2.4vw, 31px);
font-weight: 720;
line-height: 1.04;
letter-spacing: -0.035em;
}
.intro {
margin: 10px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.52;
}
.legend {
display: grid;
gap: 8px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.legend-row {
display: grid;
grid-template-columns: 13px 1fr;
align-items: start;
gap: 9px;
font-size: 11px;
line-height: 1.35;
}
.swatch {
width: 11px;
height: 11px;
margin-top: 1px;
border-radius: 3px;
border: 1px solid rgba(0, 0, 0, 0.1);
}
.swatch.altered {
background: var(--altered);
}
.swatch.fresh {
background: var(--fresh);
}
.swatch.movement {
background: var(--movement);
}
.legend-row strong {
display: block;
font-size: 11px;
font-weight: 750;
}
.legend-row span:last-child {
color: var(--muted);
}
#process-panel {
left: 22px;
bottom: 22px;
width: min(500px, calc(100vw - 44px));
padding: 13px;
border-radius: 17px;
}
.steps {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.step {
min-height: 45px;
padding: 8px 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.45);
color: #526065;
font: inherit;
font-size: 10px;
font-weight: 750;
line-height: 1.15;
text-align: left;
cursor: pointer;
transition: 160ms ease;
}
.step span {
display: block;
margin-bottom: 3px;
color: #9a9e9c;
font-size: 9px;
letter-spacing: 0.12em;
}
.step:hover {
background: rgba(255, 255, 255, 0.78);
border-color: rgba(45, 58, 62, 0.28);
}
.step.active {
color: #fff;
background: #344348;
border-color: #344348;
}
.step.active span {
color: #aebdc0;
}
.process-copy {
min-height: 34px;
margin: 10px 2px 7px;
color: #59676b;
font-size: 11px;
line-height: 1.45;
}
.toggles {
display: flex;
flex-wrap: wrap;
gap: 16px;
padding: 9px 2px 1px;
border-top: 1px solid var(--line);
}
.toggle {
display: inline-flex;
align-items: center;
gap: 7px;
color: #526065;
font-size: 10px;
font-weight: 650;
cursor: pointer;
user-select: none;
}
.toggle input {
width: 14px;
height: 14px;
margin: 0;
accent-color: #344348;
cursor: pointer;
}
#controls-hint {
position: fixed;
z-index: 5;
right: 22px;
bottom: 23px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.42);
border-radius: 999px;
background: rgba(248, 245, 239, 0.68);
color: #657174;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.025em;
backdrop-filter: blur(8px);
pointer-events: none;
}
.annotation {
position: fixed;
z-index: 6;
width: 0;
height: 0;
opacity: 1;
transition: opacity 180ms ease;
pointer-events: none;
}
.annotation.hidden {
opacity: 0;
}
.annotation .pin {
position: absolute;
left: -4px;
top: -4px;
width: 8px;
height: 8px;
border: 2px solid rgba(255, 255, 255, 0.9);
border-radius: 50%;
background: var(--altered);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.annotation .card {
position: absolute;
left: 15px;
top: -22px;
min-width: 126px;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-left: 3px solid var(--altered);
border-radius: 8px;
background: rgba(248, 245, 239, 0.86);
box-shadow: 0 7px 22px rgba(48, 45, 39, 0.11);
color: #354247;
backdrop-filter: blur(8px);
white-space: nowrap;
}
.annotation .card strong {
display: block;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
}
.annotation .card small {
display: block;
margin-top: 2px;
color: #768084;
font-size: 9px;
}
.annotation.fresh .pin {
background: var(--fresh);
}
.annotation.fresh .card {
border-left-color: var(--fresh);
}
.annotation.movement .pin {
background: var(--movement);
}
.annotation.movement .card {
border-left-color: var(--movement);
}
.annotation.left .card {
left: auto;
right: 15px;
text-align: right;
}
.annotation.below .card {
left: 50%;
top: 15px;
transform: translateX(-50%);
text-align: center;
}
@media (max-width: 720px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
h1 {
font-size: 22px;
}
.intro {
display: none;
}
.legend {
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.legend-row {
grid-template-columns: 10px 1fr;
gap: 6px;
}
.legend-row span:last-child {
display: none;
}
#process-panel {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
#controls-hint,
.annotation {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="title-card" class="panel">
<div class="eyebrow">Field note 07 · Structural geology</div>
<h1>Jointed block & detached fragment</h1>
<p class="intro">
Warm faces record alteration of the rock’s exposed skin. Cool faces are
newer fractures. Cyan shows debris displacement after detachment.
</p>
<div class="legend">
<div class="legend-row">
<i class="swatch altered"></i>
<span>
<strong>Altered outer surfaces</strong>
<span>Pre-existing breakdown of exposed material</span>
</span>
</div>
<div class="legend-row">
<i class="swatch fresh"></i>
<span>
<strong>Fresh fracture surfaces</strong>
<span>Cool faces exposed by jointing or breakage</span>
</span>
</div>
<div class="legend-row">
<i class="swatch movement"></i>
<span>
<strong>Later debris movement</strong>
<span>Post-break displacement, not surface alteration</span>
</span>
</div>
</div>
</section>
<section id="process-panel" class="panel">
<nav class="steps" aria-label="Process stages">
<button class="step" data-stage="0">
<span>STAGE 1</span>Alter in place
</button>
<button class="step" data-stage="1">
<span>STAGE 2</span>Joint & detach
</button>
<button class="step active" data-stage="2">
<span>STAGE 3</span>Move debris
</button>
</nav>
<p id="process-copy" class="process-copy"></p>
<div class="toggles">
<label class="toggle">
<input id="highlight-toggle" type="checkbox" checked>
Highlight altered skin
</label>
<label class="toggle">
<input id="path-toggle" type="checkbox" checked>
Show later movement
</label>
</div>
</section>
<div id="controls-hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div id="label-altered" class="annotation">
<span class="pin"></span>
<div class="card">
<strong>ALTERED SKIN</strong>
<small>warm exposed outer surfaces</small>
</div>
</div>
<div id="label-fresh" class="annotation fresh left">
<span class="pin"></span>
<div class="card">
<strong>FRESH JOINT</strong>
<small>cool newly broken surface</small>
</div>
</div>
<div id="label-fragment" class="annotation">
<span class="pin"></span>
<div class="card">
<strong>ROUNDED FRAGMENT</strong>
<small>older altered skin retained</small>
</div>
</div>
<div id="label-movement" class="annotation movement below">
<span class="pin"></span>
<div class="card">
<strong>LATER DEBRIS SHIFT</strong>
<small>cyan path · movement after breakage</small>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xded9cf);
scene.fog = new THREE.FogExp2(0xded9cf, 0.026);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly geological scene showing altered rock surfaces and later debris movement"
);
document.querySelector("#scene").appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf7f0df, 0x6a7378, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d7, 3.0);
keyLight.position.set(-3.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0006;
keyLight.target.position.set(0, -0.4, 0);
scene.add(keyLight, keyLight.target);
const fillLight = new THREE.DirectionalLight(0xb7d4dc, 1.15);
fillLight.position.set(5, 3, -5);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Shared surface palette
// 0–1: fresh fracture surfaces
// 2–5: weathered/outer surfaces
// -------------------------------------------------------------------------
const materials = [
new THREE.MeshStandardMaterial({
color: 0x536970,
roughness: 0.96,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x7c8c8e,
roughness: 0.93,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xb66a42,
roughness: 0.95,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xe07b43,
roughness: 0.91,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xd7975e,
roughness: 0.96,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x9d5938,
roughness: 0.98,
flatShading: true
})
];
const weatheredMaterialDefs = [
{ material: materials[2], muted: 0x8c8276, hot: 0xb66a42, glow: 0x351207 },
{ material: materials[3], muted: 0x9d9589, hot: 0xe07b43, glow: 0x4b1708 },
{ material: materials[4], muted: 0xaaa397, hot: 0xd7975e, glow: 0x3f1b0b },
{ material: materials[5], muted: 0x82786d, hot: 0x9d5938, glow: 0x2c0d05 }
];
function setSurfaceHighlight(enabled) {
for (const def of weatheredMaterialDefs) {
def.material.color.setHex(enabled ? def.hot : def.muted);
def.material.emissive.setHex(enabled ? def.glow : 0x000000);
def.material.emissiveIntensity = enabled ? 0.16 : 0;
}
}
setSurfaceHighlight(true);
// -------------------------------------------------------------------------
// Low-poly jointed block
// -------------------------------------------------------------------------
function createBlockGeometry() {
const positions = [];
const groups = [];
let vertexOffset = 0;
const halfX = 1.7;
const halfZ = 1.25;
const chamferX = 0.28;
const chamferZ = 0.21;
const footprint = [
[ halfX, -halfZ + chamferZ],
[ halfX, halfZ - chamferZ],
[ halfX - chamferX, halfZ],
[-halfX + chamferX, halfZ],
[-halfX, halfZ - chamferZ],
[-halfX, -halfZ + chamferZ],
[-halfX + chamferX, -halfZ],
[ halfX - chamferX, -halfZ]
];
const levels = [
{ y: -1.25, sx: 0.90, sz: 0.90 },
{ y: -0.94, sx: 1.00, sz: 1.00 },
{ y: 0.74, sx: 1.00, sz: 0.98 },
{ y: 1.10, sx: 0.88, sz: 0.90 }
];
const rings = levels.map((level, levelIndex) =>
footprint.map(([x, z], pointIndex) => {
const edgeNoise = Math.sin(pointIndex * 2.17 + levelIndex * 1.31);
const crossNoise = Math.cos(pointIndex * 1.73 - levelIndex * 0.91);
// Keep the fresh right-hand face planar.
const isRightFace = pointIndex === 0 || pointIndex === 1;
return new THREE.Vector3(
x * level.sx + (isRightFace ? 0 : edgeNoise * 0.045),
level.y + (levelIndex === 3 ? 0 : crossNoise * 0.035),
z * level.sz + (isRightFace ? 0 : crossNoise * 0.04)
);
})
);
function addTriangle(a, b, c, materialIndex) {
positions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
groups.push([vertexOffset, 3, materialIndex]);
vertexOffset += 3;
}
// Side and bevel surfaces.
for (let level = 0; level < rings.length - 1; level++) {
const lower = rings[level];
const upper = rings[level + 1];
for (let side = 0; side < 8; side++) {
const next = (side + 1) % 8;
let materialIndex;
if (level === 1 && side === 0) {
materialIndex = 0; // fresh planar fracture face
} else if (level === 0) {
materialIndex = 5; // dark lower weathered bevel
} else if (level === 2) {
materialIndex = 3; // emphasized upper weathered edge
} else {
materialIndex = side % 3 === 0 ? 4 : 2;
}
addTriangle(lower[side], upper[side], upper[next], materialIndex);
addTriangle(lower[side], upper[next], lower[next], materialIndex);
}
}
const top = rings[rings.length - 1];
const bottom = rings[0];
const topCenter = new THREE.Vector3(0, 1.105, 0);
const bottomCenter = new THREE.Vector3(0, -1.255, 0);
for (let i = 0; i < 8; i++) {
const next = (i + 1) % 8;
// Top normals point upward.
addTriangle(topCenter, top[next], top[i], 4);
// Bottom normals point downward.
addTriangle(bottomCenter, bottom[i], bottom[next], 5);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
for (const [start, count, materialIndex] of groups) {
geometry.addGroup(start, count, materialIndex);
}
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
const block = new THREE.Mesh(createBlockGeometry(), materials);
block.position.set(-1.25, 0, 0);
block.castShadow = true;
block.receiveShadow = true;
scene.add(block);
// Continuous irregular crack across the top and down the fresh side.
const crackMaterial = new THREE.MeshStandardMaterial({
color: 0x252b2c,
roughness: 1,
metalness: 0
});
const crackPoints = [
new THREE.Vector3(-0.52, 1.135, -0.72),
new THREE.Vector3(-0.18, 1.138, -0.45),
new THREE.Vector3( 0.10, 1.138, -0.54),
new THREE.Vector3( 0.43, 1.138, -0.16),
new THREE.Vector3( 0.80, 1.138, -0.10),
new THREE.Vector3( 1.15, 1.138, 0.30),
new THREE.Vector3( 1.47, 1.137, 0.45),
new THREE.Vector3( 1.61, 0.94, 0.46),
new THREE.Vector3( 1.71, 0.64, 0.42),
new THREE.Vector3( 1.72, 0.28, 0.35),
new THREE.Vector3( 1.71, -0.18, 0.30)
];
const crackCurve = new THREE.CatmullRomCurve3(
crackPoints,
false,
"catmullrom",
0.12
);
const crack = new THREE.Mesh(
new THREE.TubeGeometry(crackCurve, 34, 0.038, 4, false),
crackMaterial
);
crack.castShadow = true;
scene.add(crack);
const branchCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0.43, 1.14, -0.16),
new THREE.Vector3(0.33, 1.14, 0.17),
new THREE.Vector3(0.50, 1.14, 0.48)
]);
const branch = new THREE.Mesh(
new THREE.TubeGeometry(branchCurve, 10, 0.026, 3, false),
crackMaterial
);
scene.add(branch);
// -------------------------------------------------------------------------
// Rounded low-poly fragment with a fresh planar break
// -------------------------------------------------------------------------
function createFragmentGeometry() {
let geometry = new THREE.DodecahedronGeometry(1, 0);
if (geometry.index) geometry = geometry.toNonIndexed();
geometry.clearGroups();
const position = geometry.attributes.position;
const faceMaterials = [];
// Decide face materials from the original dodecahedral orientation.
for (let i = 0; i < position.count; i += 3) {
const cx = (
position.getX(i) +
position.getX(i + 1) +
position.getX(i + 2)
) / 3;
const cy = (
position.getY(i) +
position.getY(i + 1) +
position.getY(i + 2)
) / 3;
const cz = (
position.getZ(i) +
position.getZ(i + 1) +
position.getZ(i + 2)
) / 3;
let materialIndex;
if (cz > 0.22) {
materialIndex = cy > 0 ? 1 : 0;
} else if (cy > 0.34) {
materialIndex = 4;
} else if (cy < -0.38) {
materialIndex = 5;
} else {
materialIndex = Math.abs(Math.sin(cx * 4.1 + cy * 3.7)) > 0.46 ? 3 : 2;
}
faceMaterials.push(materialIndex);
}
// Deform the silhouette, then flatten the front into a fresh break.
for (let i = 0; i < position.count; i++) {
const x = position.getX(i);
const y = position.getY(i);
const z = position.getZ(i);
const noise =
Math.sin(x * 17.1 + y * 31.7 + z * 13.3) * 0.035 +
Math.cos(x * 9.4 - y * 19.2 + z * 27.1) * 0.025;
let nx = x * 1.10 + noise;
let ny = y * 0.86 + noise * 0.7;
let nz = z * 0.82 + noise * 0.8;
if (z > 0.28) nz = 0.43;
position.setXYZ(i, nx, ny, nz);
}
position.needsUpdate = true;
for (let face = 0; face < faceMaterials.length; face++) {
geometry.addGroup(face * 3, 3, faceMaterials[face]);
}
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
const fragmentGeometry = createFragmentGeometry();
const fragment = new THREE.Mesh(fragmentGeometry, materials);
fragment.castShadow = true;
fragment.receiveShadow = true;
scene.add(fragment);
const originPosition = new THREE.Vector3(1.55, -0.36, 0.05);
const finalPosition = new THREE.Vector3(2.90, -0.36, -0.16);
const movementCurve = new THREE.CubicBezierCurve3(
originPosition.clone(),
new THREE.Vector3(1.78, -0.29, 0.76),
new THREE.Vector3(2.45, -0.38, 0.57),
finalPosition.clone()
);
const startQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(0.08, 0.15, -0.08)
);
const endQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(0.13, -0.55, 0.16)
);
// -------------------------------------------------------------------------
// Cyan path: explicitly records later debris displacement
// -------------------------------------------------------------------------
const pathGroup = new THREE.Group();
scene.add(pathGroup);
const groundPathPoints = [];
for (let i = 0; i <= 40; i++) {
const point = movementCurve.getPoint(i / 40);
point.y = -1.285;
groundPathPoints.push(point);
}
const pathGeometry = new THREE.BufferGeometry().setFromPoints(
groundPathPoints
);
const pathMaterial = new THREE.LineDashedMaterial({
color: 0x25b3c3,
dashSize: 0.17,
gapSize: 0.105,
transparent: true,
opacity: 0.92,
depthTest: true
});
const movementLine = new THREE.Line(pathGeometry, pathMaterial);
movementLine.computeLineDistances();
pathGroup.add(movementLine);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.115, 0.30, 5),
new THREE.MeshBasicMaterial({ color: 0x25b3c3 })
);
const arrowTangent = movementCurve.getTangent(0.98).normalize();
arrow.position.copy(movementCurve.getPoint(0.98));
arrow.position.y = -1.265;
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
arrowTangent
);
pathGroup.add(arrow);
const originRing = new THREE.Mesh(
new THREE.RingGeometry(0.77, 0.80, 32),
new THREE.MeshBasicMaterial({
color: 0x25b3c3,
transparent: true,
opacity: 0.45,
side: THREE.DoubleSide,
depthWrite: false
})
);
originRing.rotation.x = -Math.PI / 2;
originRing.position.set(originPosition.x, -1.276, originPosition.z);
pathGroup.add(originRing);
const ghostFragment = new THREE.Mesh(
fragmentGeometry,
new THREE.MeshBasicMaterial({
color: 0x25b3c3,
wireframe: true,
transparent: true,
opacity: 0.23,
depthWrite: false
})
);
ghostFragment.position.copy(originPosition);
ghostFragment.quaternion.copy(startQuaternion);
pathGroup.add(ghostFragment);
// -------------------------------------------------------------------------
// Ground
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(32, 32),
new THREE.MeshStandardMaterial({
color: 0xc9c2b4,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.32;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(24, 48, 0x928c82, 0xa9a296);
grid.position.y = -1.312;
grid.material.transparent = true;
grid.material.opacity = 0.16;
grid.material.depthWrite = false;
scene.add(grid);
// -------------------------------------------------------------------------
// Interface and stage logic
// -------------------------------------------------------------------------
const state = {
stage: 2,
fragmentT: 1,
targetT: 1,
highlight: true,
showPath: true
};
const stageButtons = [...document.querySelectorAll(".step")];
const processCopy = document.querySelector("#process-copy");
const highlightToggle = document.querySelector("#highlight-toggle");
const pathToggle = document.querySelector("#path-toggle");
const stageCopy = [
"The exposed skin breaks down chemically and physically while the block remains in place. Warm tones identify these altered outer surfaces.",
"A joint opens and a fragment detaches. The newly exposed break is cool gray; much of the fragment’s older altered skin remains around its rounded exterior.",
"Only after detachment is the fragment transported. The cyan trail and ghost outline show this later displacement rather than the earlier surface breakdown."
];
function selectStage(index, replay = false) {
state.stage = index;
if (index === 0) {
state.fragmentT = 0;
state.targetT = 0;
fragment.visible = false;
} else {
fragment.visible = true;
if (index === 1) {
state.fragmentT = 0;
state.targetT = 0;
} else {
state.targetT = 1;
// Clicking the active final stage replays the displacement.
if (replay) state.fragmentT = 0;
}
}
stageButtons.forEach((button, i) => {
button.classList.toggle("active", i === index);
});
processCopy.textContent = stageCopy[index];
updatePathVisibility();
}
function updatePathVisibility() {
pathGroup.visible =
state.stage === 2 &&
state.showPath;
}
stageButtons.forEach((button) => {
button.addEventListener("click", () => {
const index = Number(button.dataset.stage);
selectStage(index, index === 2 && state.stage === 2);
});
});
highlightToggle.addEventListener("change", () => {
state.highlight = highlightToggle.checked;
setSurfaceHighlight(state.highlight);
});
pathToggle.addEventListener("change", () => {
state.showPath = pathToggle.checked;
updatePathVisibility();
});
processCopy.textContent = stageCopy[state.stage];
updatePathVisibility();
// -------------------------------------------------------------------------
// Camera controls implemented locally, without examples or addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0.25, -0.18, 0);
const spherical = new THREE.Spherical(9.6, 1.10, 0.73);
const initialSpherical = spherical.clone();
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(
spherical.phi,
0.28,
Math.PI * 0.48
);
spherical.radius = THREE.MathUtils.clamp(
spherical.radius,
6.2,
16
);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.005;
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
spherical.copy(initialSpherical);
cameraTarget.set(0.25, -0.18, 0);
updateCamera();
});
updateCamera();
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labels = {
altered: {
element: document.querySelector("#label-altered"),
position: new THREE.Vector3(-2.15, 1.42, -0.18)
},
fresh: {
element: document.querySelector("#label-fresh"),
position: new THREE.Vector3(0.46, 0.31, 0.38)
},
fragment: {
element: document.querySelector("#label-fragment"),
position: new THREE.Vector3()
},
movement: {
element: document.querySelector("#label-movement"),
position: movementCurve.getPoint(0.52).add(new THREE.Vector3(0, 0.10, 0))
}
};
const projected = new THREE.Vector3();
function updateLabels() {
labels.fragment.position.copy(fragment.position).add(
new THREE.Vector3(0.05, 0.72, -0.12)
);
for (const [key, label] of Object.entries(labels)) {
let visible = true;
if (key === "altered") {
visible = state.highlight;
} else if (key === "fragment") {
visible = state.stage >= 1 && state.highlight;
} else if (key === "movement") {
visible = state.stage === 2 && state.showPath;
}
projected.copy(label.position).project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
label.element.classList.toggle(
"hidden",
!visible || !onScreen
);
label.element.style.left =
`${(projected.x * 0.5 + 0.5) * innerWidth}px`;
label.element.style.top =
`${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
}
// -------------------------------------------------------------------------
// Animation and resize
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const temporaryPoint = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (state.stage === 2 && state.fragmentT < state.targetT) {
state.fragmentT = Math.min(
state.targetT,
state.fragmentT + delta * 0.34
);
}
temporaryPoint.copy(
movementCurve.getPoint(state.fragmentT)
);
fragment.position.copy(temporaryPoint);
fragment.quaternion.slerpQuaternions(
startQuaternion,
endQuaternion,
state.fragmentT
);
updateLabels();
renderer.render(scene, camera);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.fov = innerWidth < 720 ? 54 : 42;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
resize();
animate();
</script>
</body>
</html>
```