Prompt specification
Build or customize the Three.js 3D scene "Layered hillside with slip surface" 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 hillside with slip surface
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/layered-hillside-with-slip-surface-x1157
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: layered hillside with slip surface. Create a hillside cross section containing an inclined potential slip boundary and several surface markers; distinguish the conceptual sliding mass from the stable underlying block. Return one self-contained HTML file.
Working Three.js Starter (layered-hillside-with-slip-surface-x1157):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hillside Cross-Section — Potential Slip Surface</title>
<style>
:root {
--bg: #08131d;
--panel: rgba(10, 24, 34, 0.82);
--line: rgba(170, 207, 221, 0.16);
--text: #eef7fa;
--muted: #9bb2be;
--amber: #e4974b;
--teal: #438f86;
--coral: #ff596b;
--yellow: #ffd166;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 58% 46%, transparent 38%, rgba(1, 7, 12, 0.22) 100%),
linear-gradient(180deg, rgba(3, 10, 16, 0.1), rgba(3, 10, 16, 0.25));
}
.panel {
position: fixed;
top: 24px;
left: 24px;
width: min(350px, calc(100vw - 48px));
padding: 20px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #b9d0dc;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 16px rgba(255, 89, 107, 0.7);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 34px);
line-height: 1.04;
letter-spacing: -0.035em;
font-weight: 720;
}
.subtitle {
margin: 12px 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
display: grid;
gap: 9px;
padding-top: 16px;
border-top: 1px solid var(--line);
}
.legend-item {
display: flex;
align-items: center;
gap: 10px;
color: #d8e7ed;
font-size: 12px;
}
.swatch {
width: 19px;
height: 8px;
flex: 0 0 auto;
border-radius: 99px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.swatch.mass {
background: var(--amber);
}
.swatch.stable {
background: var(--teal);
}
.swatch.slip {
background: var(--coral);
}
.swatch.marker {
width: 8px;
height: 8px;
margin: 0 6px;
border-radius: 2px;
background: var(--yellow);
transform: rotate(45deg);
}
.note {
margin-top: 15px;
color: #7993a1;
font-size: 10px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.controls {
position: fixed;
top: 24px;
right: 24px;
display: flex;
align-items: center;
gap: 10px;
}
.section-badge,
button {
border: 1px solid var(--line);
border-radius: 999px;
color: #d8e7ed;
background: rgba(10, 24, 34, 0.75);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
font: inherit;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.04em;
}
.section-badge {
padding: 10px 14px;
color: #a8c0cc;
text-transform: uppercase;
}
button {
padding: 10px 14px;
cursor: pointer;
transition:
color 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
button:hover {
color: white;
border-color: rgba(255, 255, 255, 0.32);
background: rgba(25, 48, 62, 0.9);
}
.hint {
position: fixed;
right: 24px;
bottom: 22px;
padding: 9px 13px;
border: 1px solid rgba(170, 207, 221, 0.12);
border-radius: 999px;
color: #7f99a7;
background: rgba(8, 19, 29, 0.62);
font-size: 10px;
letter-spacing: 0.03em;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
z-index: 20;
color: #aec5d0;
background: var(--bg);
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition:
opacity 350ms ease,
visibility 350ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
@media (max-width: 700px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px;
}
h1 {
font-size: 24px;
}
.subtitle {
display: none;
}
.legend {
grid-template-columns: 1fr 1fr;
gap: 8px 12px;
padding-top: 12px;
}
.legend-item {
font-size: 10px;
}
.note {
display: none;
}
.controls {
top: auto;
right: 12px;
bottom: 12px;
}
.section-badge {
display: none;
}
.hint {
left: 12px;
right: auto;
bottom: 15px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional hillside cross-section with a potential slip surface"></canvas>
<div class="vignette"></div>
<section class="panel">
<div class="eyebrow">Geotechnical study / 01</div>
<h1>Hillside cross-section</h1>
<p class="subtitle">
A conceptual slope model distinguishing the potentially unstable surface mass
from the layered, stable block beneath the inclined slip boundary.
</p>
<div class="legend" aria-label="Scene legend">
<div class="legend-item">
<span class="swatch mass"></span>
Conceptual sliding mass
</div>
<div class="legend-item">
<span class="swatch stable"></span>
Stable underlying block
</div>
<div class="legend-item">
<span class="swatch slip"></span>
Potential slip boundary
</div>
<div class="legend-item">
<span class="swatch marker"></span>
Surface survey markers
</div>
</div>
<div class="note">Illustrative geometry · Not to scale</div>
</section>
<div class="controls">
<span class="section-badge">Section A–A′</span>
<button id="reset" type="button">Reset view</button>
</div>
<div class="hint">Drag to orbit · Wheel to zoom · Arrow keys to rotate</div>
<div id="loading">Building hillside model…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const loading = document.getElementById("loading");
const resetButton = document.getElementById("reset");
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
loading.textContent = "WebGL is required to view this model";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08131d);
scene.fog = new THREE.Fog(0x08131d, 17, 31);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const target = new THREE.Vector3(0.25, 1.25, -0.45);
const hemiLight = new THREE.HemisphereLight(0xc9e5ff, 0x182129, 1.65);
scene.add(hemiLight);
const keyLight = new THREE.DirectionalLight(0xffe5bd, 3.25);
keyLight.position.set(-5, 9, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00035;
keyLight.target.position.set(0, 1, -0.5);
scene.add(keyLight, keyLight.target);
const rimLight = new THREE.DirectionalLight(0x8ebfff, 1.45);
rimLight.position.set(8, 5, -7);
scene.add(rimLight);
const frontLight = new THREE.DirectionalLight(0xffd4a3, 0.8);
frontLight.position.set(0, 2, 10);
scene.add(frontLight);
const groundProfile = [
[-5.8, 3.95],
[-4.8, 3.72],
[-3.8, 3.43],
[-2.8, 3.17],
[-1.6, 2.84],
[-0.4, 2.54],
[0.8, 2.20],
[2.0, 1.84],
[3.0, 1.49],
[3.8, 1.20],
[4.7, 0.83],
[5.8, 0.48]
];
const crown = new THREE.Vector2(-3.8, 3.22);
const toe = new THREE.Vector2(3.8, 0.72);
const sectionFront = 0.50;
const sectionBack = -0.65;
function standardMaterial(color, roughness = 0.88) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0.015,
flatShading: true
});
}
function sideMaterial(color, factor = 0.68) {
const c = new THREE.Color(color).multiplyScalar(factor);
return standardMaterial(c, 0.94);
}
function signedArea(points) {
let area = 0;
for (let i = 0; i < points.length; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
area += a[0] * b[1] - b[0] * a[1];
}
return area / 2;
}
function cleanPolygon(points) {
const result = [];
for (const p of points) {
const previous = result[result.length - 1];
if (!previous || Math.hypot(p[0] - previous[0], p[1] - previous[1]) > 1e-6) {
result.push([p[0], p[1]]);
}
}
if (
result.length > 1 &&
Math.hypot(
result[0][0] - result[result.length - 1][0],
result[0][1] - result[result.length - 1][1]
) < 1e-6
) {
result.pop();
}
return result;
}
function cross2(a, b, c) {
return (b[0] - a[0]) * (c[1] - a[1]) -
(b[1] - a[1]) * (c[0] - a[0]);
}
function makePrism(points, zFront, zBack, frontMaterial, sideMat) {
const contour = cleanPolygon(points).map((p) => new THREE.Vector2(p[0], p[1]));
if (signedArea(contour) < 0) {
contour.reverse();
}
const triangles = THREE.ShapeUtils.triangulateShape(contour, []);
const orientedTriangles = triangles.map((tri) => {
let a = contour[tri[0]];
let b = contour[tri[1]];
let c = contour[tri[2]];
if (cross2(a, b, c) < 0) {
const temp = b;
b = c;
c = temp;
}
return [a, b, c];
});
const positions = [];
const pushTriangle = (a, b, c) => {
positions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
};
for (const [a, b, c] of orientedTriangles) {
pushTriangle(
new THREE.Vector3(a.x, a.y, zFront),
new THREE.Vector3(b.x, b.y, zFront),
new THREE.Vector3(c.x, c.y, zFront)
);
}
const frontVertexCount = positions.length / 3;
for (const [a, b, c] of orientedTriangles) {
pushTriangle(
new THREE.Vector3(c.x, c.y, zBack),
new THREE.Vector3(b.x, b.y, zBack),
new THREE.Vector3(a.x, a.y, zBack)
);
}
for (let i = 0; i < contour.length; i++) {
const a = contour[i];
const b = contour[(i + 1) % contour.length];
const af = new THREE.Vector3(a.x, a.y, zFront);
const bf = new THREE.Vector3(b.x, b.y, zFront);
const ab = new THREE.Vector3(a.x, a.y, zBack);
const bb = new THREE.Vector3(b.x, b.y, zBack);
pushTriangle(af, ab, bf);
pushTriangle(bf, ab, bb);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
const totalVertexCount = positions.length / 3;
geometry.addGroup(0, frontVertexCount, 0);
geometry.addGroup(frontVertexCount, totalVertexCount - frontVertexCount, 1);
const mesh = new THREE.Mesh(geometry, [frontMaterial, sideMat]);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function clipPolygonY(points, boundary, keepAbove) {
const result = [];
const inside = (p) =>
keepAbove ? p[1] >= boundary - 1e-7 : p[1] <= boundary + 1e-7;
const intersection = (a, b) => {
const t = (boundary - a[1]) / (b[1] - a[1]);
return [a[0] + (b[0] - a[0]) * t, boundary];
};
for (let i = 0; i < points.length; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
const aInside = inside(a);
const bInside = inside(b);
if (aInside && bInside) {
result.push(b);
} else if (aInside && !bInside) {
result.push(intersection(a, b));
} else if (!aInside && bInside) {
result.push(intersection(a, b));
result.push(b);
}
}
return cleanPolygon(result);
}
function groundAt(x) {
for (let i = 0; i < groundProfile.length - 1; i++) {
const a = groundProfile[i];
const b = groundProfile[i + 1];
if (x >= a[0] && x <= b[0]) {
const t = (x - a[0]) / (b[0] - a[0]);
return THREE.MathUtils.lerp(a[1], b[1], t);
}
}
return groundProfile[groundProfile.length - 1][1];
}
function slipAt(x) {
const t = (x - crown.x) / (toe.x - crown.x);
return THREE.MathUtils.lerp(crown.y, toe.y, t);
}
// Recessed hillside volume behind the analytical section.
const hillPolygon = [
...groundProfile,
[5.8, -0.75],
[-5.8, -0.75]
];
makePrism(
hillPolygon,
-0.68,
-2.75,
standardMaterial(0x304653, 0.96),
sideMaterial(0x304653, 0.52)
);
// Geological strata in the recessed hillside face.
const strataVertices = [];
const strataLevels = [0.05, 0.75, 1.45, 2.15, 2.85, 3.55];
for (const level of strataLevels) {
for (let i = 0; i < groundProfile.length - 1; i++) {
const a = groundProfile[i];
const b = groundProfile[i + 1];
const aAbove = a[1] >= level;
const bAbove = b[1] >= level;
if (aAbove && bAbove) {
strataVertices.push(a[0], level, -0.645, b[0], level, -0.645);
} else if (aAbove !== bAbove) {
const t = (level - a[1]) / (b[1] - a[1]);
const x = THREE.MathUtils.lerp(a[0], b[0], t);
if (aAbove) {
strataVertices.push(x, level, -0.645, a[0], level, -0.645);
} else {
strataVertices.push(x, level, -0.645, b[0], level, -0.645);
}
}
}
}
const strataGeometry = new THREE.BufferGeometry();
strataGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(strataVertices, 3)
);
const strataLines = new THREE.LineSegments(
strataGeometry,
new THREE.LineBasicMaterial({
color: 0x91aab4,
transparent: true,
opacity: 0.22
})
);
scene.add(strataLines);
// Stable underlying block, split into horizontal geological layers.
const stablePolygon = [
[-3.8, -0.75],
[3.8, -0.75],
[3.8, toe.y],
[crown.x, crown.y]
];
const stableBands = [
[-0.75, -0.05, 0x235d64],
[-0.05, 0.65, 0x286f70],
[0.65, 1.35, 0x318078],
[1.35, 2.05, 0x3c8980],
[2.05, 2.75, 0x4a9186],
[2.75, 3.25, 0x5b978b]
];
for (const [minimum, maximum, color] of stableBands) {
let band = clipPolygonY(stablePolygon, minimum, true);
band = clipPolygonY(band, maximum, false);
if (band.length >= 3) {
makePrism(
band,
sectionFront,
sectionBack,
standardMaterial(color, 0.92),
sideMaterial(color, 0.58)
);
}
}
// Conceptual sliding mass.
const slideGround = groundProfile.filter((p) => p[0] >= crown.x && p[0] <= toe.x);
const slidePolygon = [
...slideGround,
[toe.x, toe.y],
[crown.x, crown.y]
];
makePrism(
slidePolygon,
sectionFront,
sectionBack,
standardMaterial(0xdf8c40, 0.83),
sideMaterial(0xdf8c40, 0.57)
);
function lineFrom(points, material, closed = false) {
const vertices = closed ? [...points, points[0]] : points;
const geometry = new THREE.BufferGeometry().setFromPoints(vertices);
return new THREE.Line(geometry, material);
}
function lineSegmentsFrom(points, material) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(points, 3)
);
return new THREE.LineSegments(geometry, material);
}
// Faceting on the conceptual sliding mass.
const facetVertices = [];
const facetXs = [-2.8, -1.6, -0.4, 0.8, 2.0, 3.0];
for (const x of facetXs) {
facetVertices.push(
x, groundAt(x), 0.535,
x, slipAt(x), 0.535
);
}
facetVertices.push(
-2.8, groundAt(-2.8), 0.536,
-1.9, slipAt(-1.9), 0.536,
-1.6, groundAt(-1.6), 0.536,
-0.8, slipAt(-0.8), 0.536,
-0.4, groundAt(-0.4), 0.536,
0.4, slipAt(0.4), 0.536,
0.8, groundAt(0.8), 0.536,
1.4, slipAt(1.4), 0.536,
2.0, groundAt(2.0), 0.536,
2.6, slipAt(2.6), 0.536
);
const facets = lineSegmentsFrom(
facetVertices,
new THREE.LineBasicMaterial({
color: 0x744523,
transparent: true,
opacity: 0.47
})
);
scene.add(facets);
const topSurfacePoints = slideGround.map(
(p) => new THREE.Vector3(p[0], p[1], 0.545)
);
scene.add(
lineFrom(
topSurfacePoints,
new THREE.LineBasicMaterial({
color: 0xffdfb2,
transparent: true,
opacity: 0.88
})
)
);
function cylinderBetween(start, end, radius, material, radialSegments = 10) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
// Bright, emphasized potential slip boundary.
const slipMaterial = new THREE.MeshStandardMaterial({
color: 0xff5364,
emissive: 0x8d1022,
emissiveIntensity: 1.15,
roughness: 0.45,
metalness: 0.03
});
const slipStart = new THREE.Vector3(crown.x, crown.y, 0.585);
const slipEnd = new THREE.Vector3(toe.x, toe.y, 0.585);
cylinderBetween(slipStart, slipEnd, 0.042, slipMaterial, 12);
// Small crown and toe release indicators.
const releaseMaterial = new THREE.MeshStandardMaterial({
color: 0xff9a86,
emissive: 0x5d1820,
emissiveIntensity: 0.65,
roughness: 0.65
});
cylinderBetween(
new THREE.Vector3(crown.x, crown.y, 0.585),
new THREE.Vector3(crown.x, groundAt(crown.x), 0.585),
0.025,
releaseMaterial
);
cylinderBetween(
new THREE.Vector3(toe.x, toe.y, 0.585),
new THREE.Vector3(toe.x, groundAt(toe.x), 0.585),
0.025,
releaseMaterial
);
// Down-dip arrowheads communicate the conceptual movement direction.
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xffe5cf,
emissive: 0x4f1b18,
emissiveIntensity: 0.35,
roughness: 0.55
});
const slipDirection = new THREE.Vector3().subVectors(slipEnd, slipStart).normalize();
for (const t of [0.27, 0.53, 0.79]) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.11, 0.27, 12),
arrowMaterial
);
arrow.position.copy(slipStart).lerp(slipEnd, t);
arrow.position.z += 0.025;
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
slipDirection
);
arrow.castShadow = true;
scene.add(arrow);
}
// Surface survey markers.
const markerXs = [-2.8, -1.6, 0.0, 1.8, 3.0];
const poleMaterial = standardMaterial(0xf3ead6, 0.72);
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0x7b5310,
emissiveIntensity: 0.55,
roughness: 0.45
});
const markerBaseMaterial = standardMaterial(0x243641, 0.9);
for (const x of markerXs) {
const y = groundAt(x);
const z = 0.31;
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.11, 0.035, 12),
markerBaseMaterial
);
base.position.set(x, y + 0.018, z);
base.castShadow = true;
scene.add(base);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.026, 0.034, 0.43, 7),
poleMaterial
);
pole.position.set(x, y + 0.245, z);
pole.castShadow = true;
scene.add(pole);
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.095, 0),
markerMaterial
);
marker.position.set(x, y + 0.535, z);
marker.rotation.y = Math.PI / 4;
marker.castShadow = true;
scene.add(marker);
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeLabel(text, accent, position) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 640;
labelCanvas.height = 128;
const ctx = labelCanvas.getContext("2d");
roundedRect(ctx, 5, 8, 630, 112, 25);
ctx.fillStyle = "rgba(7, 17, 25, 0.91)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = accent;
ctx.beginPath();
ctx.arc(40, 64, 13, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#f4f8fa";
ctx.font = "700 39px Inter, system-ui, sans-serif";
ctx.textBaseline = "middle";
ctx.fillText(text, 68, 66, 535);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
const width = THREE.MathUtils.clamp(text.length * 0.115, 1.3, 3.15);
sprite.scale.set(width, width / 5, 1);
sprite.position.copy(position);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
makeLabel(
"CONCEPTUAL SLIDING MASS",
"#efa054",
new THREE.Vector3(-0.85, 2.42, 0.72)
);
makeLabel(
"STABLE UNDERLYING BLOCK",
"#54a89c",
new THREE.Vector3(0.0, -0.22, 0.72)
);
makeLabel(
"POTENTIAL SLIP SURFACE",
"#ff6473",
new THREE.Vector3(2.55, 0.77, 0.72)
);
const slipLeader = lineSegmentsFrom(
[
2.48, 0.92, 0.70,
2.05, 1.18, 0.63,
1.72, slipAt(1.72), 0.59
],
new THREE.LineBasicMaterial({
color: 0xff7782,
transparent: true,
opacity: 0.85,
depthTest: false
})
);
slipLeader.renderOrder = 19;
scene.add(slipLeader);
// Display plinth and ground grid.
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(12.45, 0.16, 4.45),
standardMaterial(0x10252e, 0.96)
);
plinth.position.set(0, -0.83, -1.0);
plinth.receiveShadow = true;
plinth.castShadow = true;
scene.add(plinth);
const plinthEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(plinth.geometry),
new THREE.LineBasicMaterial({
color: 0x36505b,
transparent: true,
opacity: 0.45
})
);
plinthEdges.position.copy(plinth.position);
scene.add(plinthEdges);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 32),
standardMaterial(0x09151e, 1.0)
);
floor.rotation.x = -Math.PI / 2;
floor.position.set(0, -0.925, -1.2);
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(34, 34, 0x2e4854, 0x172d38);
grid.position.set(0, -0.918, -1.2);
const gridMaterials = Array.isArray(grid.material)
? grid.material
: [grid.material];
for (const material of gridMaterials) {
material.transparent = true;
material.opacity = 0.28;
}
scene.add(grid);
// Camera controls implemented directly without external controls modules.
let compact = window.innerWidth < 700;
let desiredYaw = 0.27;
let desiredPitch = 0.20;
let desiredRadius = compact ? 20.5 : 13.25;
let currentYaw = desiredYaw;
let currentPitch = desiredPitch;
let currentRadius = desiredRadius;
let dragging = false;
let previousX = 0;
let previousY = 0;
function resetView() {
desiredYaw = 0.27;
desiredPitch = 0.20;
desiredRadius = compact ? 20.5 : 13.25;
target.set(compact ? 0 : 0.25, 1.25, -0.45);
}
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-8 * delta);
currentYaw += (desiredYaw - currentYaw) * smoothing;
currentPitch += (desiredPitch - currentPitch) * smoothing;
currentRadius += (desiredRadius - currentRadius) * smoothing;
const horizontalRadius = currentRadius * Math.cos(currentPitch);
camera.position.set(
target.x + Math.sin(currentYaw) * horizontalRadius,
target.y + Math.sin(currentPitch) * currentRadius,
target.z + Math.cos(currentYaw) * horizontalRadius
);
camera.lookAt(target);
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredYaw -= dx * 0.0055;
desiredPitch = THREE.MathUtils.clamp(
desiredPitch + dy * 0.0045,
0.035,
0.72
);
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * Math.exp(event.deltaY * 0.001),
8.5,
compact ? 27 : 19
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
resetButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
let handled = true;
if (key === "arrowleft") desiredYaw += 0.08;
else if (key === "arrowright") desiredYaw -= 0.08;
else if (key === "arrowup") {
desiredPitch = THREE.MathUtils.clamp(desiredPitch + 0.055, 0.035, 0.72);
} else if (key === "arrowdown") {
desiredPitch = THREE.MathUtils.clamp(desiredPitch - 0.055, 0.035, 0.72);
} else {
handled = false;
}
if (handled) event.preventDefault();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const nextCompact = width < 700;
if (nextCompact !== compact) {
compact = nextCompact;
desiredRadius = compact ? 20.5 : 13.25;
currentRadius = desiredRadius;
target.set(compact ? 0 : 0.25, 1.25, -0.45);
}
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
let firstFrame = true;
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(delta);
if (!reducedMotion) {
slipMaterial.emissiveIntensity = 1.12 + Math.sin(elapsed * 2.1) * 0.16;
}
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
}
});
</script>
</body>
</html>
```