Prompt specification
Build or customize the Three.js 3D scene "Inspect habitat connectivity after a hypothetical corridor gap" 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: Inspect habitat connectivity after a hypothetical corridor gap
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/inspect-habitat-connectivity-after-a-hypothetical-corr-x3056
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Cerrado grasslands and gallery-forest corridors. Let users remove a clearly fictional segment of riparian cover. Show geometric corridor fragmentation while avoiding unsupported numerical claims about species survival or ecosystem response. Low-poly.
Working Three.js Starter (inspect-habitat-connectivity-after-a-hypothetical-corr-x3056):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cerrado Gallery-Forest Fragmentation — Fictional Low-Poly Scene</title>
<style>
:root {
--ink: #263128;
--muted: #667064;
--paper: rgba(250, 248, 236, 0.92);
--line: rgba(48, 65, 47, 0.16);
--green: #5e743b;
--gold: #b58b47;
--water: #4f9298;
--magenta: #d94682;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9dfcf;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
top: 24px;
left: 24px;
width: min(370px, calc(100vw - 48px));
max-height: calc(100vh - 48px);
overflow: auto;
padding: 22px;
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
box-shadow:
0 20px 50px rgba(46, 55, 35, 0.16),
inset 0 0 0 1px rgba(42, 60, 38, 0.06);
backdrop-filter: blur(14px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: #6b3e53;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--magenta);
box-shadow: 0 0 0 4px rgba(217, 70, 130, 0.13);
content: "";
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 3vw, 39px);
font-weight: 500;
line-height: 1.02;
letter-spacing: -0.025em;
}
h1 em {
color: var(--green);
font-weight: 500;
}
.intro {
margin: 15px 0 18px;
color: #586257;
font-size: 13.5px;
line-height: 1.55;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 9px;
}
button {
appearance: none;
min-height: 42px;
padding: 0 15px;
border-radius: 11px;
font: inherit;
font-size: 12.5px;
font-weight: 750;
cursor: pointer;
transition:
transform 150ms ease,
box-shadow 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
button:focus-visible {
outline: 3px solid rgba(217, 70, 130, 0.3);
outline-offset: 2px;
}
.primary {
flex: 1 1 210px;
color: white;
background: #3f5438;
border: 1px solid #3f5438;
box-shadow: 0 7px 18px rgba(55, 75, 48, 0.18);
}
.primary:hover {
background: #35492f;
box-shadow: 0 9px 22px rgba(55, 75, 48, 0.24);
}
.secondary {
color: #43503e;
background: rgba(255, 255, 255, 0.58);
border: 1px solid rgba(63, 84, 56, 0.18);
}
.state {
margin-top: 12px;
padding: 10px 12px;
color: #5f675e;
background: rgba(93, 116, 59, 0.08);
border: 1px solid rgba(93, 116, 59, 0.12);
border-radius: 10px;
font-size: 11.5px;
font-weight: 700;
}
.state strong {
color: #384536;
}
.note {
margin-top: 13px;
padding-top: 13px;
color: #6b7168;
border-top: 1px solid var(--line);
font-size: 11px;
line-height: 1.5;
}
.note strong {
color: #454f43;
}
.legend {
position: absolute;
top: 24px;
right: 24px;
width: 208px;
padding: 15px 16px;
color: #445044;
background: rgba(250, 248, 236, 0.84);
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 14px;
box-shadow: 0 14px 36px rgba(47, 58, 37, 0.12);
backdrop-filter: blur(12px);
font-size: 11px;
}
.legend-title {
margin-bottom: 10px;
color: #737b70;
font-size: 9.5px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 7px;
}
.swatch {
width: 18px;
height: 9px;
flex: 0 0 auto;
border-radius: 2px;
}
.swatch.grass {
background: #a2a05a;
}
.swatch.forest {
background: #5e743b;
}
.swatch.water {
background: var(--water);
}
.swatch.trace {
height: 3px;
background: #e0d47d;
}
.swatch.fictional {
height: 0;
border-top: 2px dashed var(--magenta);
border-radius: 0;
}
.world-label {
position: absolute;
top: 0;
left: 0;
min-width: 150px;
max-width: 210px;
padding: 9px 11px;
color: #3d4939;
background: rgba(255, 252, 239, 0.94);
border: 1px solid rgba(60, 75, 52, 0.18);
border-radius: 10px;
box-shadow: 0 9px 25px rgba(47, 55, 36, 0.13);
opacity: 0;
transition: opacity 160ms ease;
will-change: transform;
}
.world-label.visible {
opacity: 1;
}
.world-label.fictional {
color: #633348;
border-color: rgba(217, 70, 130, 0.44);
box-shadow:
0 9px 25px rgba(47, 55, 36, 0.13),
0 0 0 3px rgba(217, 70, 130, 0.08);
}
.label-kicker {
display: block;
margin-bottom: 3px;
color: var(--magenta);
font-size: 8.5px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.world-label strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 14px;
font-weight: 600;
line-height: 1.2;
}
.world-label small {
display: block;
margin-top: 4px;
color: #747b70;
font-size: 9.5px;
line-height: 1.35;
}
.hint {
position: absolute;
bottom: 23px;
left: 50%;
padding: 9px 13px;
color: #52604f;
background: rgba(250, 248, 236, 0.82);
border: 1px solid rgba(255, 255, 255, 0.64);
border-radius: 999px;
box-shadow: 0 9px 24px rgba(47, 58, 37, 0.11);
backdrop-filter: blur(10px);
font-size: 10.5px;
font-weight: 650;
transform: translateX(-50%);
white-space: nowrap;
}
.concept-stamp {
position: absolute;
right: 24px;
bottom: 24px;
padding: 9px 12px;
color: #5e685a;
background: rgba(250, 248, 236, 0.82);
border: 1px solid rgba(255, 255, 255, 0.64);
border-radius: 10px;
backdrop-filter: blur(10px);
font-size: 9.5px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: #44513f;
background: #d9dfcf;
font-size: 13px;
font-weight: 700;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.panel {
top: 12px;
left: 12px;
width: min(350px, calc(100vw - 24px));
max-height: 56vh;
padding: 17px;
border-radius: 15px;
}
h1 {
font-size: 28px;
}
.intro {
margin: 11px 0 13px;
font-size: 12px;
}
.note {
font-size: 10px;
}
.legend {
display: none;
}
.hint {
bottom: 13px;
max-width: calc(100vw - 24px);
overflow: hidden;
text-overflow: ellipsis;
}
.concept-stamp {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive fictional low-poly Cerrado landscape"></canvas>
<div class="overlay">
<section class="panel" aria-label="Scene controls">
<div class="eyebrow">Clearly fictional · not a real site</div>
<h1>Cerrado grasslands<br><em>& gallery-forest corridors</em></h1>
<p class="intro">
An imagined, Cerrado-inspired landscape of open grassland and a winding
forest corridor. Clear the magenta-marked fictional section to expose
a geometric break in the rendered riparian cover.
</p>
<div class="actions">
<button id="toggleSegment" class="primary" type="button">
Remove fictional segment
</button>
<button id="resetScene" class="secondary" type="button">Reset scene</button>
<button id="toggleView" class="secondary" type="button">Top view</button>
</div>
<div class="state" aria-live="polite">
Scene state: <strong id="sceneState">fictional segment present</strong>
</div>
<div class="note">
<strong>Conceptual geometry only.</strong>
The stream remains as visual context. This vignette does not estimate
habitat quality, connectivity, species survival, or ecosystem response.
</div>
</section>
<aside class="legend" aria-label="Visual legend">
<div class="legend-title">Scene legend</div>
<div class="legend-row"><span class="swatch grass"></span>Cerrado-inspired grassland</div>
<div class="legend-row"><span class="swatch forest"></span>Gallery-forest cover</div>
<div class="legend-row"><span class="swatch water"></span>Illustrated stream</div>
<div class="legend-row"><span class="swatch trace"></span>Diagrammatic corridor trace</div>
<div class="legend-row"><span class="swatch fictional"></span>Fictional removable segment</div>
</aside>
<div id="segmentLabel" class="world-label fictional visible">
<span class="label-kicker">Clearly fictional</span>
<strong id="segmentLabelTitle">Removable riparian-cover segment</strong>
<small id="segmentLabelHint">Click the magenta section to clear it</small>
</div>
<div id="corridorLabel" class="world-label">
<strong>Gallery-forest corridor</strong>
<small>Illustrative arrangement</small>
</div>
<div class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom · Click the magenta segment</div>
<div class="concept-stamp">Conceptual geometry · no ecological forecast</div>
</div>
<div id="loading">Building the fictional landscape…</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.querySelector("#scene");
const loading = document.querySelector("#loading");
const toggleSegmentButton = document.querySelector("#toggleSegment");
const resetButton = document.querySelector("#resetScene");
const viewButton = document.querySelector("#toggleView");
const sceneState = document.querySelector("#sceneState");
const segmentLabel = document.querySelector("#segmentLabel");
const segmentLabelTitle = document.querySelector("#segmentLabelTitle");
const segmentLabelHint = document.querySelector("#segmentLabelHint");
const corridorLabel = document.querySelector("#corridorLabel");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
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(0xd9dfcf);
scene.fog = new THREE.Fog(0xd9dfcf, 145, 330);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
500
);
const WORLD_WIDTH = 120;
const WORLD_DEPTH = 86;
const SEGMENT_START = 0.49;
const SEGMENT_END = 0.64;
const cameraTarget = new THREE.Vector3(1, 0, 0);
const cameraSpherical = new THREE.Spherical(
window.innerWidth / window.innerHeight < 0.8 ? 215 : 112,
1.02,
0.69
);
const initialCamera = {
target: cameraTarget.clone(),
spherical: cameraSpherical.clone()
};
let topView = false;
function updateCamera() {
camera.position.setFromSpherical(cameraSpherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf8f0d5, 0x596044, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe0a4, 3.15);
sun.position.set(-38, 62, 28);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -80;
sun.shadow.camera.right = 80;
sun.shadow.camera.top = 65;
sun.shadow.camera.bottom = -65;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 180;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8e0d2, 0.55);
fill.position.set(45, 28, -45);
scene.add(fill);
function fract(value) {
return value - Math.floor(value);
}
function hash2(x, z) {
return fract(Math.sin(x * 127.1 + z * 311.7) * 43758.5453123);
}
let randomSeed = 481516;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function terrainHeight(x, z) {
return (
Math.sin(x * 0.052) * 0.55 +
Math.cos(z * 0.071) * 0.45 +
Math.sin((x + z) * 0.106) * 0.25 +
Math.cos((x - z) * 0.041) * 0.22
);
}
// Low-poly terrain with individually colored triangular faces.
let terrainGeometry = new THREE.PlaneGeometry(
WORLD_WIDTH,
WORLD_DEPTH,
22,
16
);
terrainGeometry.rotateX(-Math.PI / 2);
let terrainPositions = terrainGeometry.attributes.position;
for (let i = 0; i < terrainPositions.count; i++) {
const x = terrainPositions.getX(i);
const z = terrainPositions.getZ(i);
terrainPositions.setY(i, terrainHeight(x, z));
}
terrainGeometry = terrainGeometry.toNonIndexed();
terrainPositions = terrainGeometry.attributes.position;
const terrainPalette = [
0x989956,
0xa6a45d,
0x8f9551,
0xb0a667,
0x929b58,
0xa9a15a,
0x838f4e
];
const terrainColors = new Float32Array(terrainPositions.count * 3);
const triangleColor = new THREE.Color();
for (let i = 0; i < terrainPositions.count; i += 3) {
const cx =
(terrainPositions.getX(i) +
terrainPositions.getX(i + 1) +
terrainPositions.getX(i + 2)) /
3;
const cz =
(terrainPositions.getZ(i) +
terrainPositions.getZ(i + 1) +
terrainPositions.getZ(i + 2)) /
3;
const index = Math.min(
terrainPalette.length - 1,
Math.floor(hash2(cx * 0.43, cz * 0.43) * terrainPalette.length)
);
triangleColor.setHex(terrainPalette[index]);
triangleColor.offsetHSL(
(hash2(cx, cz) - 0.5) * 0.025,
(hash2(cz, cx) - 0.5) * 0.04,
(hash2(cx + 7, cz - 4) - 0.5) * 0.045
);
for (let j = 0; j < 3; j++) {
const colorIndex = (i + j) * 3;
terrainColors[colorIndex] = triangleColor.r;
terrainColors[colorIndex + 1] = triangleColor.g;
terrainColors[colorIndex + 2] = triangleColor.b;
}
}
terrainGeometry.setAttribute("color", new THREE.BufferAttribute(terrainColors, 3));
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true
})
);
terrain.receiveShadow = true;
scene.add(terrain);
const baseGeometry = new THREE.BoxGeometry(WORLD_WIDTH, 4.2, WORLD_DEPTH);
const base = new THREE.Mesh(
baseGeometry,
new THREE.MeshStandardMaterial({
color: 0x8d7958,
roughness: 1,
flatShading: true
})
);
base.position.y = -3.55;
base.receiveShadow = true;
scene.add(base);
const baseEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(baseGeometry),
new THREE.LineBasicMaterial({
color: 0x665d45,
transparent: true,
opacity: 0.38
})
);
baseEdges.position.copy(base.position);
scene.add(baseEdges);
// The corridor is intentionally fictional and ungeoreferenced.
const corridorCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-56, 0, 13),
new THREE.Vector3(-44, 0, -7),
new THREE.Vector3(-30, 0, 8),
new THREE.Vector3(-15, 0, -6),
new THREE.Vector3(2, 0, 7),
new THREE.Vector3(19, 0, -8),
new THREE.Vector3(36, 0, 8),
new THREE.Vector3(56, 0, -5)
],
false,
"catmullrom",
0.35
);
function createRibbon(start, end, width, elevation, segments = 80) {
const positions = [];
const indices = [];
const side = new THREE.Vector3();
for (let i = 0; i <= segments; i++) {
const t = THREE.MathUtils.lerp(start, end, i / segments);
const point = corridorCurve.getPointAt(t);
const tangent = corridorCurve.getTangentAt(t).setY(0).normalize();
side.set(-tangent.z, 0, tangent.x);
for (const sign of [-1, 1]) {
const x = point.x + side.x * width * 0.5 * sign;
const z = point.z + side.z * width * 0.5 * sign;
positions.push(x, terrainHeight(x, z) + elevation, z);
}
}
for (let i = 0; i < segments; i++) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, b, c, b, d, c);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const corridorGreen = 0x61783b;
const clearedOchre = 0xb28a49;
const corridorMaterial = new THREE.MeshStandardMaterial({
color: corridorGreen,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
});
const corridorBefore = new THREE.Mesh(
createRibbon(0, SEGMENT_START, 7.8, 0.08),
corridorMaterial
);
const corridorAfter = new THREE.Mesh(
createRibbon(SEGMENT_END, 1, 7.8, 0.08),
corridorMaterial
);
scene.add(corridorBefore, corridorAfter);
const segmentFloorMaterial = new THREE.MeshStandardMaterial({
color: corridorGreen,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
});
const segmentFloor = new THREE.Mesh(
createRibbon(SEGMENT_START, SEGMENT_END, 7.8, 0.095),
segmentFloorMaterial
);
segmentFloor.receiveShadow = true;
scene.add(segmentFloor);
const stream = new THREE.Mesh(
createRibbon(0, 1, 0.92, 0.15, 150),
new THREE.MeshStandardMaterial({
color: 0x4f9298,
roughness: 0.32,
metalness: 0.05,
flatShading: true,
side: THREE.DoubleSide
})
);
stream.receiveShadow = true;
scene.add(stream);
const traceMaterial = new THREE.MeshBasicMaterial({
color: 0xe4d77e,
side: THREE.DoubleSide
});
const traceBefore = new THREE.Mesh(
createRibbon(0, SEGMENT_START, 0.25, 0.20, 65),
traceMaterial
);
const traceAfter = new THREE.Mesh(
createRibbon(SEGMENT_END, 1, 0.25, 0.20, 65),
traceMaterial
);
scene.add(traceBefore, traceAfter);
const removableTraceMaterial = new THREE.MeshBasicMaterial({
color: 0xe4d77e,
transparent: true,
opacity: 1,
side: THREE.DoubleSide
});
const removableTrace = new THREE.Mesh(
createRibbon(SEGMENT_START, SEGMENT_END, 0.25, 0.205, 45),
removableTraceMaterial
);
scene.add(removableTrace);
// Shared low-poly tree geometry.
const trunkGeometry = new THREE.CylinderGeometry(0.14, 0.22, 1, 5);
const canopyGeometry = new THREE.IcosahedronGeometry(1, 0);
function createTreeInstances(entries, parent, animated = false) {
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true,
transparent: animated,
opacity: animated ? 1 : 1
});
const canopyMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true,
transparent: animated,
opacity: animated ? 1 : 1
});
const trunks = new THREE.InstancedMesh(
trunkGeometry,
trunkMaterial,
entries.length
);
const canopies = new THREE.InstancedMesh(
canopyGeometry,
canopyMaterial,
entries.length
);
trunks.castShadow = true;
trunks.receiveShadow = true;
canopies.castShadow = true;
canopies.receiveShadow = true;
trunks.frustumCulled = false;
canopies.frustumCulled = false;
const dummy = new THREE.Object3D();
const tint = new THREE.Color();
entries.forEach((entry, index) => {
const baseY = terrainHeight(entry.x, entry.z);
dummy.position.set(
entry.x,
baseY + entry.height * 0.43,
entry.z
);
dummy.rotation.set(0, entry.rotation, entry.lean ?? 0);
dummy.scale.set(
entry.radius * 0.72,
entry.height * 0.86,
entry.radius * 0.72
);
dummy.updateMatrix();
trunks.setMatrixAt(index, dummy.matrix);
dummy.position.set(
entry.x,
baseY + entry.height * 0.87,
entry.z
);
dummy.rotation.set(0, entry.rotation + 0.4, 0);
dummy.scale.set(
entry.radius,
entry.radius * 0.62,
entry.radius
);
dummy.updateMatrix();
canopies.setMatrixAt(index, dummy.matrix);
tint.setHex(entry.color);
tint.offsetHSL(
(random() - 0.5) * 0.025,
(random() - 0.5) * 0.05,
(random() - 0.5) * 0.035
);
canopies.setColorAt(index, tint);
});
if (canopies.instanceColor) {
canopies.instanceColor.needsUpdate = true;
}
trunks.instanceMatrix.needsUpdate = true;
canopies.instanceMatrix.needsUpdate = true;
parent.add(trunks, canopies);
return { trunks, canopies };
}
const galleryCanopyColors = [
0x355d38,
0x3e693c,
0x4c7342,
0x2f5737,
0x587b43,
0x426640
];
const outerTrees = [];
const removableTrees = [];
const gallerySamples = 66;
for (let i = 0; i < gallerySamples; i++) {
const t = i / (gallerySamples - 1);
const point = corridorCurve.getPointAt(t);
const tangent = corridorCurve.getTangentAt(t).setY(0).normalize();
const side = new THREE.Vector3(-tangent.z, 0, tangent.x);
for (const sign of [-1, 1]) {
if (random() < 0.12) continue;
const offset = 2.35 + random() * 0.55;
const x = point.x + side.x * offset * sign;
const z = point.z + side.z * offset * sign;
const entry = {
x,
z,
height: 2.8 + random() * 1.4,
radius: 1.25 + random() * 0.48,
rotation: random() * Math.PI * 2,
lean: (random() - 0.5) * 0.08,
color: galleryCanopyColors[
Math.floor(random() * galleryCanopyColors.length)
]
};
if (t >= SEGMENT_START && t <= SEGMENT_END) {
removableTrees.push(entry);
} else {
outerTrees.push(entry);
}
}
}
const outerTreeGroup = new THREE.Group();
scene.add(outerTreeGroup);
createTreeInstances(outerTrees, outerTreeGroup, false);
const removableTreeGroup = new THREE.Group();
scene.add(removableTreeGroup);
const removableTreeInstances = createTreeInstances(
removableTrees,
removableTreeGroup,
true
);
// Sparse, broad-canopy trees evoke an imagined Cerrado mosaic.
const scatteredTrees = [];
const curveSamples = corridorCurve.getPoints(120);
function distanceToCorridorSquared(x, z) {
let minimum = Infinity;
for (const sample of curveSamples) {
const dx = sample.x - x;
const dz = sample.z - z;
minimum = Math.min(minimum, dx * dx + dz * dz);
}
return minimum;
}
let attempts = 0;
while (scatteredTrees.length < 38 && attempts < 600) {
attempts++;
const x = (random() - 0.5) * (WORLD_WIDTH - 9);
const z = (random() - 0.5) * (WORLD_DEPTH - 9);
if (distanceToCorridorSquared(x, z) < 28) continue;
scatteredTrees.push({
x,
z,
height: 2.0 + random() * 1.65,
radius: 1.0 + random() * 0.72,
rotation: random() * Math.PI * 2,
lean: (random() - 0.5) * 0.11,
color: [0x526f3c, 0x627844, 0x455f38, 0x6f7d42][
Math.floor(random() * 4)
]
});
}
const scatteredTreeGroup = new THREE.Group();
scene.add(scatteredTreeGroup);
createTreeInstances(scatteredTrees, scatteredTreeGroup, false);
// Low-poly shrubs and grass-like spikes add texture without dense geometry.
const shrubGeometry = new THREE.DodecahedronGeometry(0.62, 0);
const shrubMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
});
const shrubs = new THREE.InstancedMesh(
shrubGeometry,
shrubMaterial,
105
);
shrubs.castShadow = true;
shrubs.receiveShadow = true;
shrubs.frustumCulled = false;
const shrubDummy = new THREE.Object3D();
const shrubColor = new THREE.Color();
for (let i = 0; i < 105; i++) {
let x;
let z;
do {
x = (random() - 0.5) * (WORLD_WIDTH - 7);
z = (random() - 0.5) * (WORLD_DEPTH - 7);
} while (distanceToCorridorSquared(x, z) < 20);
const size = 0.45 + random() * 0.55;
shrubDummy.position.set(x, terrainHeight(x, z) + size * 0.45, z);
shrubDummy.rotation.set(random(), random() * Math.PI, random() * 0.3);
shrubDummy.scale.set(size, size * 0.68, size);
shrubDummy.updateMatrix();
shrubs.setMatrixAt(i, shrubDummy.matrix);
shrubColor.setHex(
[0x7b8745, 0x8b914d, 0x687b3e, 0x979653][
Math.floor(random() * 4)
]
);
shrubs.setColorAt(i, shrubColor);
}
if (shrubs.instanceColor) shrubs.instanceColor.needsUpdate = true;
shrubs.instanceMatrix.needsUpdate = true;
scene.add(shrubs);
const grassGeometry = new THREE.ConeGeometry(0.18, 0.68, 3);
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
});
const grass = new THREE.InstancedMesh(
grassGeometry,
grassMaterial,
145
);
grass.frustumCulled = false;
const grassDummy = new THREE.Object3D();
for (let i = 0; i < 145; i++) {
let x;
let z;
do {
x = (random() - 0.5) * (WORLD_WIDTH - 5);
z = (random() - 0.5) * (WORLD_DEPTH - 5);
} while (distanceToCorridorSquared(x, z) < 15);
const size = 0.55 + random() * 0.75;
grassDummy.position.set(x, terrainHeight(x, z) + 0.31 * size, z);
grassDummy.rotation.set(
(random() - 0.5) * 0.25,
random() * Math.PI,
(random() - 0.5) * 0.25
);
grassDummy.scale.set(size, size, size);
grassDummy.updateMatrix();
grass.setMatrixAt(i, grassDummy.matrix);
grass.setColorAt(
i,
new THREE.Color(
[0xa9a05a, 0xb3a660, 0x8d9650][Math.floor(random() * 3)]
)
);
}
if (grass.instanceColor) grass.instanceColor.needsUpdate = true;
grass.instanceMatrix.needsUpdate = true;
scene.add(grass);
// Magenta dashed boundary makes the fictional removable section explicit.
const outlineMaterial = new THREE.LineDashedMaterial({
color: 0xd94682,
dashSize: 0.9,
gapSize: 0.55,
transparent: true,
opacity: 0.92,
depthTest: true
});
function createSegmentOutline(offset) {
const points = [];
const side = new THREE.Vector3();
const steps = 55;
for (let i = 0; i <= steps; i++) {
const t = THREE.MathUtils.lerp(
SEGMENT_START,
SEGMENT_END,
i / steps
);
const point = corridorCurve.getPointAt(t);
const tangent = corridorCurve.getTangentAt(t).setY(0).normalize();
side.set(-tangent.z, 0, tangent.x);
const x = point.x + side.x * offset;
const z = point.z + side.z * offset;
points.push(new THREE.Vector3(x, terrainHeight(x, z) + 0.30, z));
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
outlineMaterial
);
line.computeLineDistances();
return line;
}
const outlineGroup = new THREE.Group();
outlineGroup.add(createSegmentOutline(-4.15), createSegmentOutline(4.15));
function createEndConnector(t) {
const point = corridorCurve.getPointAt(t);
const tangent = corridorCurve.getTangentAt(t).setY(0).normalize();
const side = new THREE.Vector3(-tangent.z, 0, tangent.x);
const points = [];
for (const sign of [-1, 1]) {
const x = point.x + side.x * 4.15 * sign;
const z = point.z + side.z * 4.15 * sign;
points.push(new THREE.Vector3(x, terrainHeight(x, z) + 0.30, z));
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
outlineMaterial
);
line.computeLineDistances();
return line;
}
outlineGroup.add(
createEndConnector(SEGMENT_START),
createEndConnector(SEGMENT_END)
);
scene.add(outlineGroup);
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0xd94682,
transparent: true,
opacity: 0.92
});
const endpointMarkers = [];
for (const t of [SEGMENT_START, SEGMENT_END]) {
const point = corridorCurve.getPointAt(t);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.92, 0.11, 5, 24),
markerMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.set(point.x, terrainHeight(point.x, point.z) + 0.32, point.z);
outlineGroup.add(ring);
const pin = new THREE.Mesh(
new THREE.OctahedronGeometry(0.42, 0),
markerMaterial
);
pin.position.set(point.x, terrainHeight(point.x, point.z) + 2.35, point.z);
outlineGroup.add(pin);
endpointMarkers.push({ ring, pin });
}
// Invisible but raycastable ribbon for easy clicking.
const selectionHit = new THREE.Mesh(
createRibbon(SEGMENT_START, SEGMENT_END, 8.2, 0.34, 45),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false,
side: THREE.DoubleSide
})
);
scene.add(selectionHit);
const segmentCenter = corridorCurve.getPointAt(
(SEGMENT_START + SEGMENT_END) * 0.5
);
const segmentLabelPosition = new THREE.Vector3(
segmentCenter.x,
terrainHeight(segmentCenter.x, segmentCenter.z) + 5.4,
segmentCenter.z
);
const corridorLabelPoint = corridorCurve.getPointAt(0.19);
const corridorLabelPosition = new THREE.Vector3(
corridorLabelPoint.x,
terrainHeight(corridorLabelPoint.x, corridorLabelPoint.z) + 4.4,
corridorLabelPoint.z
);
let segmentRemoved = false;
let coverAmount = 1;
const intactColor = new THREE.Color(corridorGreen);
const clearedColor = new THREE.Color(clearedOchre);
function setSegmentRemoved(value) {
segmentRemoved = value;
if (value) {
toggleSegmentButton.textContent = "Restore fictional segment";
sceneState.textContent = "fictional segment removed";
segmentLabelTitle.textContent = "Removed riparian-cover segment";
segmentLabelHint.textContent = "Rendered corridor gap · click to restore";
} else {
toggleSegmentButton.textContent = "Remove fictional segment";
sceneState.textContent = "fictional segment present";
segmentLabelTitle.textContent = "Removable riparian-cover segment";
segmentLabelHint.textContent = "Click the magenta section to clear it";
}
}
toggleSegmentButton.addEventListener("click", () => {
setSegmentRemoved(!segmentRemoved);
});
resetButton.addEventListener("click", () => {
setSegmentRemoved(false);
topView = false;
viewButton.textContent = "Top view";
cameraTarget.copy(initialCamera.target);
cameraSpherical.copy(initialCamera.spherical);
updateCamera();
});
viewButton.addEventListener("click", () => {
topView = !topView;
if (topView) {
cameraSpherical.phi = 0.075;
cameraSpherical.theta = 0.03;
cameraSpherical.radius =
window.innerWidth / window.innerHeight < 0.8 ? 220 : 116;
viewButton.textContent = "Oblique view";
} else {
cameraSpherical.phi = 1.02;
cameraSpherical.theta = 0.69;
cameraSpherical.radius =
window.innerWidth / window.innerHeight < 0.8 ? 215 : 112;
viewButton.textContent = "Top view";
}
});
// Custom camera controls: orbit, pan, wheel zoom, and pointer pinch zoom.
const pointers = new Map();
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
let dragDistance = 0;
let multiTouchGesture = false;
let pinchDistance = 0;
let downButton = 0;
function clampCamera() {
cameraSpherical.phi = THREE.MathUtils.clamp(
cameraSpherical.phi,
0.07,
Math.PI * 0.47
);
cameraSpherical.radius = THREE.MathUtils.clamp(
cameraSpherical.radius,
42,
320
);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -35, 35);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -28, 28);
}
function panCamera(dx, dy) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const scale = cameraSpherical.radius * 0.00145;
cameraTarget.addScaledVector(right, -dx * scale);
cameraTarget.addScaledVector(forward, dy * scale);
clampCamera();
}
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function segmentHitAt(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointerNDC.x =
((clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y =
-((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(
[selectionHit, segmentFloor, removableTreeInstances.canopies],
false
);
return hits.length > 0;
}
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragDistance = 0;
multiTouchGesture = false;
downButton = event.button;
} else {
multiTouchGesture = true;
pinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
const pointer = pointers.get(event.pointerId);
if (!pointer) {
if (event.pointerType === "mouse") {
canvas.style.cursor = segmentHitAt(
event.clientX,
event.clientY
)
? "pointer"
: "grab";
}
return;
}
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointers.size === 1) {
dragDistance += Math.abs(dx) + Math.abs(dy);
if (event.shiftKey || downButton === 2) {
panCamera(dx, dy);
} else {
cameraSpherical.theta -= dx * 0.0052;
cameraSpherical.phi -= dy * 0.0044;
clampCamera();
}
canvas.style.cursor = "grabbing";
} else if (pointers.size === 2) {
const currentDistance = pointerDistance();
if (pinchDistance > 0 && currentDistance > 0) {
cameraSpherical.radius *=
pinchDistance / currentDistance;
clampCamera();
}
pinchDistance = currentDistance;
}
});
canvas.addEventListener("pointerup", (event) => {
const shouldClick =
!multiTouchGesture &&
dragDistance < 7 &&
downButton === 0;
pointers.delete(event.pointerId);
if (shouldClick && segmentHitAt(event.clientX, event.clientY)) {
setSegmentRemoved(!segmentRemoved);
}
if (pointers.size === 0) {
multiTouchGesture = false;
dragDistance = 0;
canvas.style.cursor = "grab";
}
});
canvas.addEventListener("pointercancel", (event) => {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
multiTouchGesture = false;
dragDistance = 0;
}
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraSpherical.radius *= Math.exp(event.deltaY * 0.001);
clampCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraTarget.copy(initialCamera.target);
cameraSpherical.copy(initialCamera.spherical);
updateCamera();
});
function projectLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
element.classList.toggle("visible", visible);
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -100%)`;
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const targetCover = segmentRemoved ? 0 : 1;
const smoothing = 1 - Math.exp(-delta * 7.5);
coverAmount = THREE.MathUtils.lerp(
coverAmount,
targetCover,
smoothing
);
if (Math.abs(coverAmount - targetCover) < 0.002) {
coverAmount = targetCover;
}
removableTreeGroup.visible =
coverAmount > 0.003 || !segmentRemoved;
removableTreeInstances.trunks.material.opacity = coverAmount;
removableTreeInstances.canopies.material.opacity = coverAmount;
removableTreeInstances.trunks.visible = coverAmount > 0.003;
removableTreeInstances.canopies.visible = coverAmount > 0.003;
removableTraceMaterial.opacity = coverAmount;
removableTrace.visible = coverAmount > 0.003;
segmentFloorMaterial.color.lerpColors(
intactColor,
clearedColor,
1 - coverAmount
);
const pulse = 1 + Math.sin(clock.elapsedTime * 3.2) * 0.055;
for (const marker of endpointMarkers) {
marker.ring.scale.setScalar(pulse);
marker.pin.rotation.y += delta * 0.8;
marker.pin.position.y +=
Math.sin(clock.elapsedTime * 2.1 + marker.pin.position.x) *
delta *
0.035;
}
outlineMaterial.opacity =
0.78 + Math.sin(clock.elapsedTime * 2.4) * 0.16;
updateCamera();
camera.updateMatrixWorld();
scene.updateMatrixWorld();
projectLabel(segmentLabel, segmentLabelPosition);
projectLabel(corridorLabel, corridorLabelPosition);
renderer.render(scene, camera);
}
resize();
renderer.setAnimationLoop(animate);
loading.classList.add("hidden");
window.setTimeout(() => loading.remove(), 400);
</script>
</body>
</html>
```