Prompt specification
Build or customize the Three.js 3D scene "Slope scenario teaching model" 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: Slope scenario teaching model
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/slope-scenario-teaching-model-x1160
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a bounded voxel hillside for comparing slope conditions. Cut away one side to expose a few simplified ground layers, and place vegetation, a bare patch, and a small drainage channel on the surface. Let users toggle schematic saturation and surface cover while the underlying hill geometry stays fixed. Highlight the relevant conceptual factors with short labels and color-independent symbols, without producing a numerical failure prediction. Any soil movement should be an explicitly illustrative authored state. Keep the model separate from a real named site or engineering recommendation, and show which assumptions are changing in each comparison.
Working Three.js Starter (slope-scenario-teaching-model-x1160):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Generic Voxel Slope Comparison</title>
<style>
:root {
color-scheme: light;
--ink: #18252d;
--muted: #60717a;
--panel: #17242c;
--panel-2: #22343e;
--line: #3a4d57;
--paper: #e8ece8;
--accent: #d7eee8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background: var(--paper);
}
button,
input {
font: inherit;
}
#viewport {
position: fixed;
inset: 0 370px 0 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 38%, #f7f8f5 0, #e6ebe7 56%, #d9e0dc 100%);
}
#viewport canvas {
position: absolute;
inset: 0;
z-index: 0;
display: block;
touch-action: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
#labels {
position: absolute;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
#leaders {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
}
.scene-label {
position: absolute;
display: flex;
align-items: center;
gap: 0.38rem;
padding: 0.34rem 0.52rem;
border: 1px solid rgba(24, 37, 45, 0.36);
border-radius: 0.35rem;
background: rgba(250, 251, 248, 0.92);
box-shadow: 0 0.18rem 0.65rem rgba(31, 47, 54, 0.12);
color: #1d2b32;
font-size: 0.72rem;
font-weight: 650;
letter-spacing: 0.01em;
line-height: 1;
white-space: nowrap;
transform: translate(-50%, -50%);
backdrop-filter: blur(5px);
}
.scene-label .symbol {
display: inline-grid;
width: 1.15rem;
height: 1.15rem;
place-items: center;
border: 1px solid currentColor;
border-radius: 0.22rem;
font-size: 0.78rem;
font-weight: 800;
}
#viewport-note {
position: absolute;
z-index: 4;
left: 18px;
bottom: 16px;
max-width: min(520px, calc(100% - 36px));
padding: 0.58rem 0.72rem;
border: 1px solid rgba(24, 37, 45, 0.2);
border-radius: 0.45rem;
background: rgba(249, 250, 247, 0.87);
color: #42545c;
font-size: 0.72rem;
line-height: 1.45;
pointer-events: none;
backdrop-filter: blur(5px);
}
#panel {
position: fixed;
z-index: 10;
top: 14px;
right: 14px;
bottom: 14px;
width: 342px;
overflow-y: auto;
padding: 1.15rem;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 0.9rem;
background:
linear-gradient(145deg, rgba(255, 255, 255, 0.035), transparent 40%),
var(--panel);
box-shadow: 0 1.2rem 3rem rgba(25, 39, 46, 0.24);
color: #edf3f1;
scrollbar-width: thin;
scrollbar-color: #526771 transparent;
}
.eyebrow {
margin-bottom: 0.35rem;
color: #8eb3b7;
font-size: 0.66rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #f5f8f6;
font-size: 1.38rem;
line-height: 1.15;
letter-spacing: -0.025em;
}
.intro {
margin: 0.65rem 0 1rem;
color: #b8c6ca;
font-size: 0.77rem;
line-height: 1.5;
}
.notice {
margin-bottom: 1rem;
padding: 0.7rem;
border: 1px solid #49606a;
border-radius: 0.55rem;
background: #20323b;
color: #d5e1df;
font-size: 0.71rem;
line-height: 1.45;
}
.notice strong {
color: #f2f7f5;
}
section {
margin-top: 1rem;
padding-top: 0.95rem;
border-top: 1px solid var(--line);
}
h2 {
margin: 0 0 0.68rem;
color: #f0f5f3;
font-size: 0.76rem;
letter-spacing: 0.045em;
text-transform: uppercase;
}
.toggle {
display: flex;
align-items: flex-start;
gap: 0.65rem;
margin: 0.62rem 0;
cursor: pointer;
}
.toggle input {
width: 1rem;
height: 1rem;
margin: 0.12rem 0 0;
accent-color: #83b9b4;
cursor: pointer;
}
.toggle .copy {
min-width: 0;
}
.toggle strong {
display: block;
color: #edf4f2;
font-size: 0.77rem;
line-height: 1.25;
}
.toggle small {
display: block;
margin-top: 0.18rem;
color: #9fb0b6;
font-size: 0.67rem;
line-height: 1.4;
}
.preset-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.42rem;
margin-top: 0.72rem;
}
.preset {
min-height: 3.15rem;
padding: 0.55rem;
border: 1px solid #435862;
border-radius: 0.48rem;
background: #20323b;
color: #d8e2e0;
text-align: left;
cursor: pointer;
transition: 140ms ease;
}
.preset:hover,
.preset:focus-visible {
border-color: #8eb9b5;
outline: none;
}
.preset[aria-pressed="true"] {
border-color: #a9d2cd;
background: #304b52;
color: #ffffff;
}
.preset b {
display: block;
margin-bottom: 0.18rem;
font-size: 0.72rem;
}
.preset span {
display: block;
color: #afbec2;
font-size: 0.63rem;
line-height: 1.35;
}
.comparison {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: stretch;
gap: 0.35rem;
}
.compare-card {
min-width: 0;
padding: 0.62rem;
border: 1px solid #425761;
border-radius: 0.48rem;
background: #1e3039;
}
.compare-card.current {
border-color: #709b98;
background: #263e43;
}
.compare-card .caption {
display: block;
margin-bottom: 0.42rem;
color: #91a7ad;
font-size: 0.61rem;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.compare-card b {
display: block;
margin-top: 0.27rem;
color: #e6efed;
font-size: 0.66rem;
font-weight: 600;
line-height: 1.35;
}
.compare-arrow {
display: grid;
place-items: center;
color: #a9c8c6;
font-weight: 800;
}
.changed {
margin-top: 0.62rem;
padding: 0.62rem;
border-left: 3px solid #91bbb6;
border-radius: 0.2rem 0.42rem 0.42rem 0.2rem;
background: #21353d;
color: #d8e3e1;
font-size: 0.69rem;
line-height: 1.45;
}
.changed strong {
display: block;
margin-bottom: 0.3rem;
color: #f3f8f6;
}
.changed ul {
margin: 0;
padding-left: 1.05rem;
}
.fixed-list {
display: flex;
flex-wrap: wrap;
gap: 0.35rem;
margin: 0;
padding: 0;
list-style: none;
}
.fixed-list li {
padding: 0.32rem 0.44rem;
border: 1px solid #435862;
border-radius: 999px;
color: #c8d6d5;
font-size: 0.63rem;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.36rem 0.5rem;
margin: 0;
color: #c5d2d2;
font-size: 0.66rem;
}
.legend div {
display: flex;
align-items: center;
gap: 0.42rem;
}
.legend .symbol {
display: inline-grid;
width: 1.2rem;
height: 1.2rem;
flex: 0 0 auto;
place-items: center;
border: 1px solid #789194;
border-radius: 0.25rem;
color: #ecf4f2;
font-weight: 800;
}
.button-row {
display: flex;
gap: 0.45rem;
}
.action {
flex: 1;
padding: 0.55rem 0.65rem;
border: 1px solid #587078;
border-radius: 0.45rem;
background: #243943;
color: #e8f0ee;
font-size: 0.69rem;
font-weight: 700;
cursor: pointer;
}
.action:hover,
.action:focus-visible {
border-color: #a3c9c5;
outline: none;
}
.fine-print {
margin: 0.8rem 0 0;
color: #91a6ac;
font-size: 0.62rem;
line-height: 1.45;
}
@media (max-width: 900px) {
#viewport {
inset: 0 0 47% 0;
}
#panel {
inset: auto 10px 10px;
width: auto;
height: 43%;
}
#viewport-note {
font-size: 0.66rem;
}
}
@media (max-width: 540px) {
.preset-grid {
grid-template-columns: 1fr;
}
.scene-label {
padding: 0.28rem 0.38rem;
font-size: 0.62rem;
}
.scene-label .symbol {
width: 1rem;
height: 1rem;
font-size: 0.68rem;
}
}
</style>
</head>
<body>
<main id="viewport" aria-label="Interactive generic voxel hillside">
<div id="labels" aria-hidden="true">
<svg id="leaders"></svg>
</div>
<div id="viewport-note">
Drag to orbit · wheel to zoom · right-drag or Shift-drag to pan.
The generic voxel geometry stays fixed while assumptions are toggled.
</div>
</main>
<aside id="panel" aria-label="Conceptual comparison controls">
<div class="eyebrow">Conceptual comparison</div>
<h1>Generic Voxel Slope Lab</h1>
<p class="intro">
Compare schematic saturation and surface-cover assumptions on the same
bounded hillside. The form, cut-away, drainage route, and bare patch do
not change.
</p>
<div class="notice">
<strong>Not a named site or engineering assessment.</strong>
This scene provides no failure probability, stability threshold, design
recommendation, or numerical prediction.
</div>
<section>
<h2>Changeable depictions</h2>
<label class="toggle">
<input id="saturation-toggle" type="checkbox">
<span class="copy">
<strong>◎ Schematic saturation</strong>
<small>
Adds patterned moisture markers only. “Off” means not depicted,
not an assumption of zero moisture.
</small>
</span>
</label>
<label class="toggle">
<input id="cover-toggle" type="checkbox" checked>
<span class="copy">
<strong>♣ Surface cover</strong>
<small>
Shows or hides the authored grass and shrub layer. The soil voxels
remain in place.
</small>
</span>
</label>
<div class="preset-grid" aria-label="Comparison presets">
<button
class="preset"
type="button"
data-saturation="false"
data-cover="true"
aria-pressed="true"
>
<b>A · Reference</b>
<span>Saturation not shown<br>Cover shown</span>
</button>
<button
class="preset"
type="button"
data-saturation="true"
data-cover="true"
aria-pressed="false"
>
<b>Saturation only</b>
<span>Saturation shown<br>Cover shown</span>
</button>
<button
class="preset"
type="button"
data-saturation="false"
data-cover="false"
aria-pressed="false"
>
<b>Cover removed</b>
<span>Saturation not shown<br>Cover hidden</span>
</button>
<button
class="preset"
type="button"
data-saturation="true"
data-cover="false"
aria-pressed="false"
>
<b>Combined</b>
<span>Saturation shown<br>Cover hidden</span>
</button>
</div>
</section>
<section>
<h2>What changes in the comparison?</h2>
<div class="comparison">
<div class="compare-card">
<span class="caption">A · Reference</span>
<b>Saturation: not depicted</b>
<b>Surface cover: shown</b>
</div>
<div class="compare-arrow" aria-hidden="true">→</div>
<div class="compare-card current">
<span class="caption">B · Current</span>
<b id="current-saturation">Saturation: not depicted</b>
<b id="current-cover">Surface cover: shown</b>
</div>
</div>
<div id="changed-assumptions" class="changed" aria-live="polite">
<strong>Changed assumptions</strong>
No toggle differs from Reference A.
</div>
</section>
<section>
<h2>Fixed in every comparison</h2>
<ul class="fixed-list">
<li>Voxel heights</li>
<li>Model footprint</li>
<li>Layer sequence</li>
<li>Drainage alignment</li>
<li>Bare-patch location</li>
<li>Authored feature positions</li>
</ul>
</section>
<section>
<h2>Illustrative movement state</h2>
<label class="toggle">
<input id="movement-toggle" type="checkbox">
<span class="copy">
<strong>↘ Show authored movement overlay</strong>
<small>
A static, hand-authored set of ghost blocks and a trajectory arrow.
It is not calculated, not animated, and does not deform the hill.
</small>
</span>
</label>
</section>
<section>
<h2>Color-independent key</h2>
<div class="legend">
<div><span class="symbol">◎</span><span>Saturation</span></div>
<div><span class="symbol">♣</span><span>Surface cover</span></div>
<div><span class="symbol">○</span><span>Bare patch</span></div>
<div><span class="symbol">◇</span><span>Drainage</span></div>
<div><span class="symbol">≡</span><span>Surficial soil</span></div>
<div><span class="symbol">▧</span><span>Weathered zone</span></div>
<div><span class="symbol">▦</span><span>Bedrock</span></div>
<div><span class="symbol">↘</span><span>Authored movement</span></div>
</div>
</section>
<section>
<h2>View</h2>
<label class="toggle">
<input id="labels-toggle" type="checkbox" checked>
<span class="copy">
<strong>Show conceptual labels</strong>
<small>Symbols and leader lines remain readable without color.</small>
</span>
</label>
<div class="button-row">
<button id="reset-camera" class="action" type="button">
Reset camera
</button>
</div>
<p class="fine-print">
Saturation and surface cover are depiction assumptions for qualitative
comparison, not measurements. Any depicted soil displacement is an
explicitly authored illustrative state.
</p>
</section>
</aside>
<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 labelHost = document.getElementById("labels");
const leaderSvg = document.getElementById("leaders");
// ------------------------------------------------------------
// Renderer, camera, and lights
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8ece8);
scene.fog = new THREE.Fog(0xe8ece8, 20, 35);
const camera = new THREE.PerspectiveCamera(
39,
viewport.clientWidth / viewport.clientHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Generic bounded voxel hillside with conceptual comparison overlays"
);
viewport.insertBefore(renderer.domElement, labelHost);
const hemisphere = new THREE.HemisphereLight(0xf8fbf8, 0x69736e, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff8e9, 3.15);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc7e4ea, 0.85);
fill.position.set(8, 5, -9);
scene.add(fill);
// ------------------------------------------------------------
// Direct camera controls: no external controls module
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 1.55, -0.35),
radius: 17.2,
theta: 0.72,
phi: 0.96
};
const defaultCamera = {
target: new THREE.Vector3(0, 1.55, -0.35),
radius: 17.2,
theta: 0.72,
phi: 0.96
};
function updateCamera() {
const { target, radius, theta, phi } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
let panMode = false;
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
panMode = event.button === 2 || event.shiftKey;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (panMode) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0)
.normalize();
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 1)
.normalize();
const scale = cameraState.radius * 0.00125;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(up, dy * scale);
cameraState.target.y = THREE.MathUtils.clamp(
cameraState.target.y,
-0.5,
5
);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.43,
1.36
);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
panMode = false;
if (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();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
10.5,
27
);
updateCamera();
},
{ passive: false }
);
document.getElementById("reset-camera").addEventListener("click", () => {
cameraState.target.copy(defaultCamera.target);
cameraState.radius = defaultCamera.radius;
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
updateCamera();
});
// ------------------------------------------------------------
// Generic model dimensions and deterministic authored layout
// ------------------------------------------------------------
const NX = 13;
const NZ = 9;
const CELL = 0.78;
const BLOCK_H = 0.62;
const OCCUPIED_ROWS = NZ - 1; // front row removed to create the cut-away
const xFor = (i) => (i - (NX - 1) / 2) * CELL;
const zFor = (j) => (j - (NZ - 1) / 2) * CELL;
const backEdge = zFor(0) - CELL / 2;
const frontEdge = zFor(OCCUPIED_ROWS - 1) + CELL / 2;
const modelWidth = NX * CELL;
const modelDepth = frontEdge - backEdge;
function deterministicRandom(i, j, salt = 0) {
const value = Math.sin(
i * 127.1 + j * 311.7 + salt * 74.7
) * 43758.5453123;
return value - Math.floor(value);
}
const drainPath = [
[6, 0],
[6, 1],
[6, 2],
[7, 3],
[7, 4],
[7, 5],
[7, 6],
[7, 7]
];
const drainSet = new Set(drainPath.map(([i, j]) => `${i},${j}`));
function isDrainCell(i, j) {
return drainSet.has(`${i},${j}`);
}
function isBareCell(i, j) {
// A small blocky, vegetation-free patch near the front-left.
return Math.abs(i - 3) + Math.abs(j - 5.5) <= 1.55;
}
const heights = Array.from({ length: NZ }, () => Array(NX).fill(0));
const blocks = [];
const COLORS = {
bedrock: new THREE.Color(0x59656d),
weathered: new THREE.Color(0x9a826b),
soil: new THREE.Color(0x7f6d52),
bare: new THREE.Color(0xb69a70),
channel: new THREE.Color(0x496a78)
};
for (let j = 0; j < OCCUPIED_ROWS; j++) {
for (let i = 0; i < NX; i++) {
const x = xFor(i);
const z = zFor(j);
const ridge =
2.7 *
Math.exp(
-(
((x + 0.5) * (x + 0.5)) / 12 +
((z + 1.0) * (z + 1.0)) / 9
)
);
const slopeTerm = (4.2 - z) * 0.5;
let height = Math.round(1.15 + ridge + slopeTerm);
height = THREE.MathUtils.clamp(height, 2, 7);
// The channel is a fixed feature in the authored terrain.
if (isDrainCell(i, j)) {
height = Math.max(2, height - 1);
}
heights[j][i] = height;
for (let k = 0; k < height; k++) {
let color;
if (k === 0) {
color = COLORS.bedrock;
} else if (k === height - 1) {
if (isDrainCell(i, j)) color = COLORS.channel;
else if (isBareCell(i, j)) color = COLORS.bare;
else color = COLORS.soil;
} else {
color = COLORS.weathered;
}
blocks.push({
position: new THREE.Vector3(
x,
k * BLOCK_H + BLOCK_H / 2,
z
),
color: color.clone()
});
}
}
}
// ------------------------------------------------------------
// Bounded base and ground
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
new THREE.MeshStandardMaterial({
color: 0xdce2de,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.225;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(28, 28, 0xb7c1bc, 0xd2d9d5);
grid.position.y = -0.205;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const plinthGeometry = new THREE.BoxGeometry(
modelWidth + 0.42,
0.2,
modelDepth + 0.42
);
const plinth = new THREE.Mesh(
plinthGeometry,
new THREE.MeshStandardMaterial({
color: 0x394850,
roughness: 0.88
})
);
plinth.position.set(
0,
-0.1,
(backEdge + frontEdge) / 2
);
plinth.receiveShadow = true;
plinth.castShadow = true;
scene.add(plinth);
const plinthEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(plinthGeometry),
new THREE.LineBasicMaterial({ color: 0x72838a })
);
plinthEdges.position.copy(plinth.position);
scene.add(plinthEdges);
// ------------------------------------------------------------
// Instanced voxel blocks
// ------------------------------------------------------------
const voxelGeometry = new THREE.BoxGeometry(
CELL * 0.965,
BLOCK_H * 0.965,
CELL * 0.965
);
const voxelMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.93,
metalness: 0
});
const voxelMesh = new THREE.InstancedMesh(
voxelGeometry,
voxelMaterial,
blocks.length
);
const dummy = new THREE.Object3D();
blocks.forEach((block, index) => {
dummy.position.copy(block.position);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
voxelMesh.setMatrixAt(index, dummy.matrix);
voxelMesh.setColorAt(index, block.color);
});
voxelMesh.instanceMatrix.needsUpdate = true;
if (voxelMesh.instanceColor) voxelMesh.instanceColor.needsUpdate = true;
voxelMesh.castShadow = true;
voxelMesh.receiveShadow = true;
scene.add(voxelMesh);
// A thin outline emphasizes the front cut-away profile.
const cutProfilePoints = [];
for (let i = 0; i < NX; i++) {
const x = xFor(i);
const y = heights[OCCUPIED_ROWS - 1][i] * BLOCK_H + 0.012;
cutProfilePoints.push(new THREE.Vector3(x, y, frontEdge + 0.014));
}
const cutProfile = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(cutProfilePoints),
new THREE.LineBasicMaterial({ color: 0xf4f5ef })
);
scene.add(cutProfile);
// ------------------------------------------------------------
// Fixed drainage channel: bed tiles and directional chevrons
// ------------------------------------------------------------
const drainageGroup = new THREE.Group();
scene.add(drainageGroup);
const drainTileGeometry = new THREE.BoxGeometry(
CELL * 0.43,
0.035,
CELL * 0.86
);
const drainTileMaterial = new THREE.MeshStandardMaterial({
color: 0x3e6675,
roughness: 0.68,
metalness: 0.05
});
const chevronMaterial = new THREE.LineBasicMaterial({
color: 0xf3f7f5
});
drainPath.forEach(([i, j], pathIndex) => {
const x = xFor(i);
const z = zFor(j);
const top = heights[j][i] * BLOCK_H;
const tile = new THREE.Mesh(drainTileGeometry, drainTileMaterial);
tile.position.set(x, top + 0.018, z);
tile.receiveShadow = true;
drainageGroup.add(tile);
const next = drainPath[Math.min(pathIndex + 1, drainPath.length - 1)];
const current = drainPath[pathIndex];
const dir = new THREE.Vector2(
xFor(next[0]) - xFor(current[0]),
zFor(next[1]) - zFor(current[1])
).normalize();
const angle = Math.atan2(dir.x, dir.y);
const localPoints = [
new THREE.Vector3(-0.09, 0, -0.08),
new THREE.Vector3(0, 0, 0.08),
new THREE.Vector3(0.09, 0, -0.08)
];
localPoints.forEach((point) => {
point.applyAxisAngle(new THREE.Vector3(0, 1, 0), angle);
point.add(new THREE.Vector3(x, top + 0.047, z));
});
const chevron = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(localPoints),
chevronMaterial
);
drainageGroup.add(chevron);
});
// ------------------------------------------------------------
// Bare-patch outline
// ------------------------------------------------------------
const bareOutlineGroup = new THREE.Group();
scene.add(bareOutlineGroup);
const bareOutlineMaterial = new THREE.LineBasicMaterial({
color: 0x5f523e
});
for (let j = 0; j < OCCUPIED_ROWS; j++) {
for (let i = 0; i < NX; i++) {
if (!isBareCell(i, j)) continue;
const x = xFor(i);
const z = zFor(j);
const y = heights[j][i] * BLOCK_H + 0.025;
const half = CELL * 0.43;
const points = [
new THREE.Vector3(x - half, y, z - half),
new THREE.Vector3(x + half, y, z - half),
new THREE.Vector3(x + half, y, z + half),
new THREE.Vector3(x - half, y, z + half)
];
bareOutlineGroup.add(
new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
bareOutlineMaterial
)
);
}
}
// ------------------------------------------------------------
// Authored surface cover: grass and shrubs
// ------------------------------------------------------------
const coverGroup = new THREE.Group();
scene.add(coverGroup);
const grassLocations = [];
const shrubLocations = [];
for (let j = 0; j < OCCUPIED_ROWS; j++) {
for (let i = 0; i < NX; i++) {
if (isBareCell(i, j) || isDrainCell(i, j)) continue;
const random = deterministicRandom(i, j, 1);
if (random > 0.38) {
const x = xFor(i) + (deterministicRandom(i, j, 2) - 0.5) * 0.46;
const z = zFor(j) + (deterministicRandom(i, j, 3) - 0.5) * 0.46;
const top = heights[j][i] * BLOCK_H;
grassLocations.push({
x,
z,
y: top,
rotation: deterministicRandom(i, j, 4) * Math.PI * 2
});
if (deterministicRandom(i, j, 5) > 0.88) {
shrubLocations.push({ x, z, y: top });
}
}
}
}
const grassBladeGeometry = new THREE.BoxGeometry(0.034, 0.21, 0.034);
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const grassMesh = new THREE.InstancedMesh(
grassBladeGeometry,
grassMaterial,
grassLocations.length * 3
);
let grassIndex = 0;
grassLocations.forEach((location, locationIndex) => {
for (let blade = 0; blade < 3; blade++) {
const bladeOffset = (blade - 1) * 0.065;
dummy.position.set(
location.x + bladeOffset,
location.y + 0.105,
location.z + (blade % 2) * 0.025
);
dummy.rotation.set(
(blade - 1) * 0.12,
location.rotation + blade * 0.55,
(blade - 1) * 0.18
);
dummy.scale.set(1, 0.85 + blade * 0.12, 1);
dummy.updateMatrix();
grassMesh.setMatrixAt(grassIndex, dummy.matrix);
const green = new THREE.Color().setHSL(
0.27 + deterministicRandom(locationIndex, blade, 8) * 0.055,
0.28,
0.34 + deterministicRandom(locationIndex, blade, 9) * 0.09
);
grassMesh.setColorAt(grassIndex, green);
grassIndex++;
}
});
grassMesh.instanceMatrix.needsUpdate = true;
if (grassMesh.instanceColor) grassMesh.instanceColor.needsUpdate = true;
grassMesh.castShadow = true;
coverGroup.add(grassMesh);
const trunkGeometry = new THREE.BoxGeometry(0.065, 0.29, 0.065);
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x6c5841,
roughness: 1
});
const trunkMesh = new THREE.InstancedMesh(
trunkGeometry,
trunkMaterial,
shrubLocations.length
);
const canopyGeometry = new THREE.IcosahedronGeometry(0.19, 0);
const canopyMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
});
const canopyMesh = new THREE.InstancedMesh(
canopyGeometry,
canopyMaterial,
shrubLocations.length
);
shrubLocations.forEach((location, index) => {
dummy.position.set(location.x, location.y + 0.145, location.z);
dummy.rotation.set(0, location.x * 0.4, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
trunkMesh.setMatrixAt(index, dummy.matrix);
dummy.position.set(location.x, location.y + 0.37, location.z);
dummy.rotation.set(
deterministicRandom(index, 0, 10) * 0.3,
deterministicRandom(index, 1, 10) * Math.PI,
deterministicRandom(index, 2, 10) * 0.25
);
dummy.scale.set(
0.9 + deterministicRandom(index, 3, 10) * 0.25,
0.85 + deterministicRandom(index, 4, 10) * 0.3,
0.9 + deterministicRandom(index, 5, 10) * 0.25
);
dummy.updateMatrix();
canopyMesh.setMatrixAt(index, dummy.matrix);
canopyMesh.setColorAt(
index,
new THREE.Color().setHSL(
0.25 + deterministicRandom(index, 6, 10) * 0.06,
0.25,
0.36 + deterministicRandom(index, 7, 10) * 0.08
)
);
});
trunkMesh.instanceMatrix.needsUpdate = true;
canopyMesh.instanceMatrix.needsUpdate = true;
if (canopyMesh.instanceColor) canopyMesh.instanceColor.needsUpdate = true;
trunkMesh.castShadow = true;
canopyMesh.castShadow = true;
coverGroup.add(trunkMesh, canopyMesh);
// ------------------------------------------------------------
// Schematic saturation overlay
// The texture uses hatching and circles, not color alone.
// ------------------------------------------------------------
function makeSaturationTexture() {
const canvas = document.createElement("canvas");
canvas.width = 96;
canvas.height = 96;
const context = canvas.getContext("2d");
context.clearRect(0, 0, 96, 96);
context.fillStyle = "rgba(40, 135, 161, 0.30)";
context.fillRect(0, 0, 96, 96);
context.strokeStyle = "rgba(255,255,255,0.92)";
context.lineWidth = 5;
context.beginPath();
context.moveTo(-20, 20);
context.lineTo(75, 115);
context.moveTo(20, -20);
context.lineTo(115, 75);
context.stroke();
context.strokeStyle = "#164f64";
context.fillStyle = "rgba(255,255,255,0.88)";
context.lineWidth = 3;
const drawMarker = (x, y) => {
context.beginPath();
context.arc(x, y, 10, 0, Math.PI * 2);
context.fill();
context.stroke();
context.beginPath();
context.moveTo(x - 5, y);
context.lineTo(x + 5, y);
context.moveTo(x, y - 5);
context.lineTo(x, y + 5);
context.stroke();
};
drawMarker(27, 27);
drawMarker(70, 70);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const saturationGroup = new THREE.Group();
scene.add(saturationGroup);
const saturationCells = [];
for (let j = 0; j < OCCUPIED_ROWS; j++) {
for (let i = 0; i < NX; i++) {
if (isDrainCell(i, j)) continue;
saturationCells.push([i, j]);
}
}
const saturationGeometry = new THREE.PlaneGeometry(
CELL * 0.88,
CELL * 0.88
);
const saturationMaterial = new THREE.MeshBasicMaterial({
map: makeSaturationTexture(),
transparent: true,
depthWrite: false,
side: THREE.DoubleSide,
polygonOffset: true,
polygonOffsetFactor: -2
});
const saturationMesh = new THREE.InstancedMesh(
saturationGeometry,
saturationMaterial,
saturationCells.length
);
saturationCells.forEach(([i, j], index) => {
dummy.position.set(
xFor(i),
heights[j][i] * BLOCK_H + 0.026,
zFor(j)
);
dummy.rotation.set(-Math.PI / 2, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
saturationMesh.setMatrixAt(index, dummy.matrix);
});
saturationMesh.instanceMatrix.needsUpdate = true;
saturationMesh.renderOrder = 3;
saturationGroup.add(saturationMesh);
// ------------------------------------------------------------
// Explicitly authored movement overlay
// This is deliberately separate from the fixed terrain.
// ------------------------------------------------------------
const movementGroup = new THREE.Group();
scene.add(movementGroup);
const sourceI = 4;
const sourceJ = 2;
const sourceX = xFor(sourceI);
const sourceZ = zFor(sourceJ);
const sourceTop = heights[sourceJ][sourceI] * BLOCK_H;
const sourceOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(CELL * 0.72, 0.16, CELL * 0.72)
),
new THREE.LineBasicMaterial({ color: 0x5b4937 })
);
sourceOutline.position.set(sourceX, sourceTop + 0.08, sourceZ);
movementGroup.add(sourceOutline);
const ghostGeometry = new THREE.BoxGeometry(0.30, 0.24, 0.30);
const ghostMaterial = new THREE.MeshStandardMaterial({
color: 0xd4a064,
transparent: true,
opacity: 0.28,
roughness: 0.9,
depthWrite: false
});
const ghostEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x6c4d2e
});
const ghostPositions = [
new THREE.Vector3(sourceX + 0.12, sourceTop - 0.28, sourceZ + 0.34),
new THREE.Vector3(sourceX + 0.25, sourceTop - 0.62, sourceZ + 0.68),
new THREE.Vector3(sourceX + 0.38, sourceTop - 0.96, sourceZ + 1.02)
];
ghostPositions.forEach((position) => {
const ghost = new THREE.Mesh(ghostGeometry, ghostMaterial);
ghost.position.copy(position);
ghost.renderOrder = 4;
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(ghostGeometry),
ghostEdgeMaterial
);
edges.position.copy(position);
edges.renderOrder = 5;
movementGroup.add(ghost, edges);
});
const movementLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(sourceX, sourceTop + 0.11, sourceZ),
ghostPositions[ghostPositions.length - 1]
]),
new THREE.LineDashedMaterial({
color: 0x654a2e,
dashSize: 0.12,
gapSize: 0.08,
transparent: true,
opacity: 0.9
})
);
movementLine.computeLineDistances();
movementGroup.add(movementLine);
const movementDirection = ghostPositions[2]
.clone()
.sub(ghostPositions[1])
.normalize();
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.095, 0.25, 12),
new THREE.MeshBasicMaterial({ color: 0x654a2e })
);
arrowHead.position.copy(ghostPositions[2]).addScaledVector(movementDirection, 0.11);
arrowHead.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
movementDirection
);
movementGroup.add(arrowHead);
// ------------------------------------------------------------
// Projected DOM labels with leader lines
// ------------------------------------------------------------
const labelDefinitions = [];
function addLabel(symbol, text, anchor, offset, visible = () => true) {
const element = document.createElement("div");
element.className = "scene-label";
element.innerHTML = `
<span class="symbol">${symbol}</span>
<span class="label-text">${text}</span>
`;
labelHost.appendChild(element);
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
line.setAttribute("stroke", "rgba(30,48,56,0.55)");
line.setAttribute("stroke-width", "1");
leaderSvg.appendChild(line);
const dot = document.createElementNS(
"http://www.w3.org/2000/svg",
"circle"
);
dot.setAttribute("r", "3");
dot.setAttribute("fill", "#f8faf7");
dot.setAttribute("stroke", "rgba(30,48,56,0.75)");
dot.setAttribute("stroke-width", "1.2");
leaderSvg.appendChild(dot);
const definition = {
element,
textElement: element.querySelector(".label-text"),
anchor: anchor.clone(),
offset: new THREE.Vector2(offset[0], offset[1]),
visible,
line,
dot
};
labelDefinitions.push(definition);
return definition;
}
const coverLabel = addLabel(
"♣",
"Surface cover shown",
new THREE.Vector3(
xFor(1),
heights[2][1] * BLOCK_H + 0.28,
zFor(2)
),
[-65, -45]
);
const saturationLabel = addLabel(
"◎",
"Schematic saturation",
new THREE.Vector3(
xFor(9),
heights[3][9] * BLOCK_H + 0.08,
zFor(3)
),
[40, -55],
() => state.saturation
);
addLabel(
"○",
"Bare patch",
new THREE.Vector3(
xFor(3),
heights[5][3] * BLOCK_H + 0.05,
zFor(5)
),
[-65, 42]
);
addLabel(
"◇",
"Drainage channel",
new THREE.Vector3(
xFor(7),
heights[5][7] * BLOCK_H + 0.08,
zFor(5)
),
[80, 25]
);
function frontCellForLayer(minimumHeight = 2) {
for (let i = 0; i < NX; i++) {
if (heights[OCCUPIED_ROWS - 1][i] >= minimumHeight) {
return i;
}
}
return 5;
}
const topLayerCell = frontCellForLayer(3);
const weatherLayerCell = Math.min(NX - 1, topLayerCell + 4);
const bedLayerCell = Math.min(NX - 1, topLayerCell + 8);
addLabel(
"≡",
"Surficial soil",
new THREE.Vector3(
xFor(topLayerCell),
heights[OCCUPIED_ROWS - 1][topLayerCell] * BLOCK_H -
BLOCK_H / 2,
frontEdge + 0.04
),
[-55, -85]
);
addLabel(
"▧",
"Weathered zone",
new THREE.Vector3(
xFor(weatherLayerCell),
BLOCK_H * 1.5,
frontEdge + 0.04
),
[-80, 0]
);
addLabel(
"▦",
"Bedrock",
new THREE.Vector3(
xFor(bedLayerCell),
BLOCK_H * 0.5,
frontEdge + 0.04
),
[-35, 70]
);
addLabel(
"▥",
"Cut-away section",
new THREE.Vector3(
xFor(6),
heights[OCCUPIED_ROWS - 1][6] * BLOCK_H + 0.03,
frontEdge + 0.05
),
[45, -108]
);
addLabel(
"↘",
"Authored movement · not calculated",
ghostPositions[1],
[105, -65],
() => state.movement
);
const projected = new THREE.Vector3();
const cameraSpace = new THREE.Vector3();
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
for (const label of labelDefinitions) {
const shouldShow = state.labels && label.visible();
if (!shouldShow) {
label.element.style.display = "none";
label.line.style.display = "none";
label.dot.style.display = "none";
continue;
}
cameraSpace.copy(label.anchor).applyMatrix4(camera.matrixWorldInverse);
if (cameraSpace.z >= 0) {
label.element.style.display = "none";
label.line.style.display = "none";
label.dot.style.display = "none";
continue;
}
projected.copy(label.anchor).project(camera);
if (
projected.z < -1 ||
projected.z > 1 ||
Math.abs(projected.x) > 1.35 ||
Math.abs(projected.y) > 1.35
) {
label.element.style.display = "none";
label.line.style.display = "none";
label.dot.style.display = "none";
continue;
}
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
let labelX = anchorX + label.offset.x;
let labelY = anchorY + label.offset.y;
labelX = THREE.MathUtils.clamp(labelX, 78, width - 78);
labelY = THREE.MathUtils.clamp(labelY, 22, height - 22);
label.element.style.display = "flex";
label.element.style.left = `${labelX}px`;
label.element.style.top = `${labelY}px`;
label.line.style.display = "";
label.dot.style.display = "";
label.line.setAttribute("x1", anchorX);
label.line.setAttribute("y1", anchorY);
label.line.setAttribute("x2", labelX);
label.line.setAttribute("y2", labelY);
label.dot.setAttribute("cx", anchorX);
label.dot.setAttribute("cy", anchorY);
}
}
// ------------------------------------------------------------
// Comparison state and assumptions display
// ------------------------------------------------------------
const reference = {
saturation: false,
cover: true
};
const state = {
saturation: false,
cover: true,
movement: false,
labels: true
};
const saturationToggle = document.getElementById("saturation-toggle");
const coverToggle = document.getElementById("cover-toggle");
const movementToggle = document.getElementById("movement-toggle");
const labelsToggle = document.getElementById("labels-toggle");
const presetButtons = [...document.querySelectorAll(".preset")];
const currentSaturationText = document.getElementById(
"current-saturation"
);
const currentCoverText = document.getElementById("current-cover");
const changedAssumptions = document.getElementById(
"changed-assumptions"
);
function applyState() {
saturationGroup.visible = state.saturation;
coverGroup.visible = state.cover;
movementGroup.visible = state.movement;
saturationToggle.checked = state.saturation;
coverToggle.checked = state.cover;
movementToggle.checked = state.movement;
labelsToggle.checked = state.labels;
currentSaturationText.textContent = state.saturation
? "Saturation: schematic shown"
: "Saturation: not depicted";
currentCoverText.textContent = state.cover
? "Surface cover: shown"
: "Surface cover: hidden";
coverLabel.textElement.textContent = state.cover
? "Surface cover shown"
: "Surface cover hidden";
const changes = [];
if (state.saturation !== reference.saturation) {
changes.push(
reference.saturation
? "Saturation depiction: schematic shown → not depicted."
: "Saturation depiction: not depicted → schematic shown."
);
}
if (state.cover !== reference.cover) {
changes.push(
reference.cover
? "Surface cover: shown → hidden."
: "Surface cover: hidden → shown."
);
}
if (state.movement) {
changes.push(
"Movement depiction: hidden → static authored ghost blocks and arrow; no calculation."
);
}
changedAssumptions.innerHTML = `
<strong>Changed assumptions</strong>
${
changes.length
? `<ul>${changes
.map((change) => `<li>${change}</li>`)
.join("")}</ul>`
: "No toggle differs from Reference A."
}
`;
presetButtons.forEach((button) => {
const buttonSaturation =
button.dataset.saturation === "true";
const buttonCover = button.dataset.cover === "true";
const selected =
state.saturation === buttonSaturation &&
state.cover === buttonCover;
button.setAttribute("aria-pressed", String(selected));
});
}
saturationToggle.addEventListener("change", () => {
state.saturation = saturationToggle.checked;
applyState();
});
coverToggle.addEventListener("change", () => {
state.cover = coverToggle.checked;
applyState();
});
movementToggle.addEventListener("change", () => {
state.movement = movementToggle.checked;
applyState();
});
labelsToggle.addEventListener("change", () => {
state.labels = labelsToggle.checked;
applyState();
});
presetButtons.forEach((button) => {
button.addEventListener("click", () => {
state.saturation = button.dataset.saturation === "true";
state.cover = button.dataset.cover === "true";
applyState();
});
});
applyState();
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
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();
}
new ResizeObserver(resize).observe(viewport);
resize();
updateCamera();
renderer.setAnimationLoop(() => {
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```