Prompt specification
Build or customize the Three.js 3D scene "Fallen log forest-floor community" 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: Fallen log forest-floor community
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/fallen-log-forest-floor-community-x0727
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts forest-floor decomposition. Build a log with moss, fungi, invertebrate shelters, seedlings, and leaf litter; partial cutaways reveal internal spaces while the log still anchors the overall scene. Voxel style.
Working Three.js Starter (fallen-log-forest-floor-community-x0727):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Forest Floor — Voxel Decomposition Scene</title>
<style>
:root {
color-scheme: dark;
--ink: #f2eadb;
--muted: #aeb5a8;
--panel: rgba(19, 28, 23, 0.84);
--line: rgba(231, 239, 219, 0.14);
--green: #8fba67;
--amber: #d39a52;
--rust: #c46d45;
--cream: #ead8ad;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101713;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 19px 16px;
border-radius: 15px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--ink);
font-size: clamp(21px, 3vw, 31px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.description {
max-width: 340px;
margin: 10px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 999px;
background: rgba(255, 255, 255, 0.035);
color: #d5d9d0;
font-size: 10px;
white-space: nowrap;
}
.legend i {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--c);
box-shadow: 0 0 8px color-mix(in srgb, var(--c), transparent 45%);
}
#controls {
top: 22px;
right: 22px;
display: flex;
gap: 7px;
padding: 7px;
border-radius: 12px;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 8px;
padding: 8px 11px;
background: rgba(255, 255, 255, 0.055);
color: var(--ink);
font: inherit;
font-size: 11px;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
button:hover {
border-color: rgba(255, 255, 255, 0.23);
background: rgba(255, 255, 255, 0.11);
}
button.active {
border-color: rgba(143, 186, 103, 0.55);
background: rgba(143, 186, 103, 0.13);
color: #cfe6b7;
}
#hint {
position: fixed;
z-index: 5;
right: 22px;
bottom: 20px;
padding: 9px 12px;
border-radius: 10px;
color: rgba(235, 239, 229, 0.72);
font-size: 10px;
letter-spacing: 0.02em;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.callout {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
transform: translate(-50%, -50%);
opacity: 0;
transition: opacity 100ms linear;
white-space: nowrap;
}
.callout::before {
content: "";
width: 7px;
height: 7px;
border: 2px solid rgba(255, 255, 255, 0.8);
border-radius: 50%;
background: var(--c);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--c), transparent 75%);
}
.callout span {
padding: 4px 7px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 5px;
background: rgba(14, 20, 16, 0.76);
color: #e6e8df;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 700px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px;
}
.description {
margin-bottom: 10px;
}
.legend span:nth-child(n + 4) {
display: none;
}
#controls {
top: auto;
right: 12px;
bottom: 12px;
}
#hint,
#labels {
display: none;
}
}
</style>
</head>
<body>
<section id="intro" class="panel">
<div class="eyebrow">Decomposition habitat · voxel study</div>
<h1>Forest Floor</h1>
<p class="description">
A fallen log anchors a small world of decay: moss, bracket fungi,
sheltered invertebrates, seedlings, leaf litter, and exposed galleries
where wood is being consumed from within.
</p>
<div class="legend">
<span><i style="--c:#7fa64f"></i>Moss</span>
<span><i style="--c:#c87545"></i>Fungi</span>
<span><i style="--c:#d1a060"></i>Cut wood</span>
<span><i style="--c:#697b55"></i>Shelter</span>
<span><i style="--c:#a8c56e"></i>Seedlings</span>
<span><i style="--c:#b6653e"></i>Leaf litter</span>
</div>
</section>
<nav id="controls" class="panel" aria-label="Scene controls">
<button id="reset" type="button">Reset view</button>
<button id="orbit" type="button">Auto-orbit</button>
</nav>
<div id="hint">Drag: orbit · Shift/right-drag: pan · Wheel/pinch: zoom · Double-click: reset</div>
<div id="labels" aria-hidden="true"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, and lighting
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.13;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel forest floor showing decomposition of a fallen log"
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x111813);
scene.fog = new THREE.Fog(0x111813, 18, 38);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
70
);
const hemisphere = new THREE.HemisphereLight(0xc7d9c1, 0x3b2518, 1.65);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe0aa, 3.1);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.0008;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8fb5a5, 0.65);
fill.position.set(8, 5, -8);
scene.add(fill);
const warmBounce = new THREE.PointLight(0xd77a3c, 8, 12, 2);
warmBounce.position.set(2, 1.2, 3);
scene.add(warmBounce);
// ------------------------------------------------------------
// Seeded random numbers and instanced voxel builder
// ------------------------------------------------------------
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(81472);
const rand = (a, b) => a + (b - a) * random();
const pick = (array) => array[Math.floor(random() * array.length)];
const batches = new Map();
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function box(
x, y, z,
sx, sy, sz,
color,
rotation = [0, 0, 0]
) {
const object = new THREE.Object3D();
object.position.set(x, y, z);
object.rotation.set(rotation[0], rotation[1], rotation[2]);
object.scale.set(sx, sy, sz);
object.updateMatrix();
if (!batches.has(color)) batches.set(color, []);
batches.get(color).push(object.matrix.clone());
}
function buildBatches() {
for (const [color, matrices] of batches) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
flatShading: true
});
const mesh = new THREE.InstancedMesh(
unitBox,
material,
matrices.length
);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.instanceMatrix.setUsage(THREE.StaticDrawUsage);
matrices.forEach((matrix, index) => {
mesh.setMatrixAt(index, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
scene.add(mesh);
}
}
// ------------------------------------------------------------
// Forest floor
// ------------------------------------------------------------
const earthColors = [
0x3d3324, 0x473927, 0x50402b, 0x3b3022,
0x59472f, 0x443827, 0x5c4932
];
// Raised diorama base.
box(0, -0.58, 0, 14.4, 0.62, 10.4, 0x2b2119);
box(0, -0.34, 0, 14.1, 0.2, 10.1, 0x35291d);
// Pixel-like soil tiles.
for (let ix = 0; ix < 17; ix++) {
for (let iz = 0; iz < 13; iz++) {
const x = -6.8 + ix * 0.85;
const z = -5.1 + iz * 0.85;
const height = rand(0.12, 0.22);
box(
x,
-0.14 - height * 0.18,
z,
0.82,
height,
0.82,
pick(earthColors)
);
}
}
// Soil clumps and small stones.
for (let i = 0; i < 80; i++) {
const x = rand(-6.8, 6.8);
const z = rand(-4.8, 4.8);
const size = rand(0.08, 0.2);
box(
x,
rand(-0.03, 0.06),
z,
size,
size * rand(0.5, 1),
size * rand(0.7, 1.4),
pick([0x65513a, 0x706048, 0x574a39, 0x7d6848])
);
}
// Exposed roots, made from blocky segments.
function rootPath(points, color = 0x6a4c31) {
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
const angle = Math.atan2(dx, dz);
box(
(a[0] + b[0]) * 0.5,
0.015,
(a[1] + b[1]) * 0.5,
0.1,
0.08,
length + 0.1,
color,
[0, angle, 0]
);
}
}
rootPath([
[-5.8, 1.7], [-4.9, 1.25], [-4.2, 1.55], [-3.4, 1.0]
]);
rootPath([
[4.9, -1.5], [4.25, -1.85], [3.65, -1.6]
]);
rootPath([
[-1.0, 3.6], [-0.3, 3.25], [0.35, 3.5]
]);
// ------------------------------------------------------------
// Main voxel log, with a side cutaway and an internal gallery
// ------------------------------------------------------------
const LOG_Y = 0.75;
const CROSS = 0.4;
const SEGMENTS = 20;
const DX = 0.45;
const RADIUS = 1.34;
const barkColors = [
0x4a3021, 0x553823, 0x422b1e, 0x5b3c27,
0x49301f, 0x60402a
];
const woodColors = [
0x95613a, 0xa16b3e, 0x8d5934,
0xaa7143, 0x9b6338
];
const cutWoodColors = [
0xc18a52, 0xd09a60, 0xb87c46,
0xd5a166, 0xc68e56
];
const galleryWoodColors = [
0x5a3823, 0x684128, 0x4c301d
];
function windowRemoved(ix, iy, iz) {
const x = -4.275 + ix * DX;
return x > -1.85 && x < 1.65 && iy >= 0 && iz >= 0;
}
function galleryRemoved(ix, iy, iz) {
const x = -4.275 + ix * DX;
const y = LOG_Y + (iy + 0.5) * CROSS;
const z = (iz + 0.5) * CROSS;
const tunnelY = 0.4 + 0.06 * Math.sin(x * 1.4);
return x > -2.45 &&
Math.abs(y - tunnelY) < 0.25 &&
Math.abs(z) < 0.34;
}
function removalReason(ix, iy, iz) {
if (windowRemoved(ix, iy, iz)) return "window";
if (galleryRemoved(ix, iy, iz)) return "gallery";
return null;
}
for (let ix = 0; ix < SEGMENTS; ix++) {
const x = -4.275 + ix * DX;
for (let iy = -3; iy <= 3; iy++) {
for (let iz = -3; iz <= 3; iz++) {
const y = LOG_Y + (iy + 0.5) * CROSS;
const z = (iz + 0.5) * CROSS;
const radius = Math.hypot(y - LOG_Y, z);
if (radius > RADIUS) continue;
if (windowRemoved(ix, iy, iz)) continue;
if (galleryRemoved(ix, iy, iz)) continue;
let touchesWindow = false;
let touchesGallery = false;
const neighbors = [
[ix + 1, iy, iz],
[ix - 1, iy, iz],
[ix, iy + 1, iz],
[ix, iy - 1, iz],
[ix, iy, iz + 1],
[ix, iy, iz - 1]
];
for (const [nx, ny, nz] of neighbors) {
const reason = removalReason(nx, ny, nz);
if (reason === "window") touchesWindow = true;
if (reason === "gallery") touchesGallery = true;
}
let color;
if (touchesGallery) {
color = pick(galleryWoodColors);
} else if (touchesWindow) {
color = pick(cutWoodColors);
} else if (radius > 0.84) {
color = pick(barkColors);
} else {
color = pick(woodColors);
}
box(
x, y, z,
CROSS * 0.97, CROSS * 0.97, CROSS * 0.97,
color
);
}
}
}
// Dark surfaces behind the exposed gallery prevent it from
// reading as a see-through tunnel.
box(1.05, 0.37, -0.34, 6.85, 0.48, 0.07, 0x2f1d15);
box(1.05, 0.105, 0.02, 6.85, 0.09, 0.62, 0x261710);
box(1.1, 0.64, -0.18, 6.7, 0.12, 0.34, 0x3d271b);
// Growth-ring pixels on the exposed positive end.
for (let iy = -3; iy <= 3; iy++) {
for (let iz = -3; iz <= 3; iz++) {
const y = LOG_Y + (iy + 0.5) * CROSS;
const z = (iz + 0.5) * CROSS;
const r = Math.hypot(y - LOG_Y, z);
if (
(r > 0.73 && r < 0.93) ||
(r > 0.46 && r < 0.59)
) {
box(
4.515,
y,
z,
0.045,
0.27,
0.27,
random() > 0.5 ? 0xd09b61 : 0xb97d48
);
}
}
}
// ------------------------------------------------------------
// Moss and lichen
// ------------------------------------------------------------
const mossColors = [
0x597d35, 0x668c3d, 0x789e4b,
0x466e2e, 0x85aa55
];
function mossPatch(x, y, z, scale = 1) {
for (let i = 0; i < 9; i++) {
const size = rand(0.16, 0.34) * scale;
box(
x + rand(-0.35, 0.35) * scale,
y + rand(0, 0.16) * scale,
z + rand(-0.28, 0.28) * scale,
size,
size * rand(0.45, 0.9),
size * rand(0.7, 1.35),
pick(mossColors),
[0, rand(-0.3, 0.3), rand(-0.15, 0.15)]
);
}
}
for (const x of [-4.35, -3.65, -2.95, 2.1, 2.85, 3.55, 4.05]) {
mossPatch(x, 1.98, rand(-0.8, 0.45), rand(0.8, 1.15));
}
mossPatch(-4.08, 0.05, 1.23, 0.9);
mossPatch(-3.75, -0.25, 0.95, 0.75);
mossPatch(3.9, 0.02, 1.1, 0.8);
mossPatch(-5.65, 0.02, -1.8, 1.2);
mossPatch(5.2, 0.02, 2.4, 0.95);
// Pale lichen colonies on bark.
for (let i = 0; i < 25; i++) {
const x = rand(-4.2, 4.1);
const y = rand(-0.15, 1.45);
box(
x,
y,
1.29,
rand(0.12, 0.3),
rand(0.09, 0.2),
0.045,
pick([0xa8b18a, 0xbdc4a4, 0x8c9d79]),
[0, 0, rand(-0.2, 0.2)]
);
}
// ------------------------------------------------------------
// Fungi: bracket shelves and small clustered mushrooms
// ------------------------------------------------------------
function bracketFungus(x, y, z, scale = 1) {
box(x, y, z + 0.18 * scale,
0.12 * scale, 0.2 * scale, 0.36 * scale,
0xd8c59d);
box(x, y + 0.11 * scale, z + 0.43 * scale,
0.64 * scale, 0.16 * scale, 0.48 * scale,
0xa94f2d);
box(x, y + 0.22 * scale, z + 0.45 * scale,
0.47 * scale, 0.12 * scale, 0.34 * scale,
0xc36a38);
box(x, y + 0.015 * scale, z + 0.45 * scale,
0.51 * scale, 0.055 * scale, 0.36 * scale,
0xe0cda3);
}
bracketFungus(-3.35, 0.35, 1.12, 0.85);
bracketFungus(-2.75, 0.08, 1.12, 0.58);
bracketFungus(2.65, 0.45, 1.12, 0.95);
bracketFungus(3.18, 0.1, 1.12, 0.62);
bracketFungus(0.95, -0.17, 1.12, 0.55);
function topMushroom(x, z, scale = 1, color = 0xc16c3d) {
const baseY = 1.97;
box(
x,
baseY + 0.18 * scale,
z,
0.13 * scale,
0.36 * scale,
0.13 * scale,
0xd8c9a8
);
box(
x,
baseY + 0.39 * scale,
z,
0.48 * scale,
0.13 * scale,
0.43 * scale,
color
);
box(
x,
baseY + 0.48 * scale,
z,
0.31 * scale,
0.09 * scale,
0.29 * scale,
0xd1814d
);
}
topMushroom(-3.85, -0.25, 0.85);
topMushroom(-3.48, -0.18, 0.55, 0xa95131);
topMushroom(-4.15, -0.04, 0.48, 0xd18a4f);
topMushroom(3.0, -0.45, 0.8);
topMushroom(3.32, -0.3, 0.52, 0xa85531);
// Pale fungal threads/mycelium around the decaying wood.
for (let i = 0; i < 32; i++) {
const x = rand(-4.2, 4.2);
const y = rand(-0.35, 1.6);
box(
x,
y,
1.315,
rand(0.08, 0.23),
0.025,
0.025,
pick([0xd8d0ad, 0xc8c5a4, 0xe2d9ba]),
[0, 0, rand(-0.7, 0.7)]
);
}
// ------------------------------------------------------------
// Seedlings
// ------------------------------------------------------------
function seedling(x, z, height = 1.2, damaged = false) {
const baseY = -0.03;
for (let i = 0; i < 5; i++) {
box(
x + Math.sin(i * 0.55) * 0.025,
baseY + height * (i / 5),
z,
0.1,
height / 5 + 0.03,
0.1,
damaged && i < 2 ? 0x74633c : 0x6f7540
);
}
const leafColors = damaged
? [0x8a8c45, 0x77843f, 0xa29b4d]
: [0x8eb354, 0x9fc466, 0x6f9841];
for (let i = 0; i < 5; i++) {
const y = baseY + height * rand(0.43, 0.9);
const side = i % 2 === 0 ? -1 : 1;
const length = rand(0.3, 0.52);
box(
x + side * length * 0.5,
y,
z + rand(-0.09, 0.09),
length,
0.075,
rand(0.2, 0.3),
pick(leafColors),
[rand(-0.16, 0.16), rand(-0.3, 0.3), side * rand(0.2, 0.52)]
);
}
}
seedling(3.55, -2.35, 1.38);
seedling(4.12, -2.12, 0.82, true);
seedling(-3.25, -2.7, 1.1);
seedling(-2.75, -2.95, 0.68, true);
seedling(-5.35, 2.65, 1.28);
seedling(5.3, -0.7, 0.95);
// ------------------------------------------------------------
// Leaf litter
// ------------------------------------------------------------
const leafColors = [
0xa85835, 0xb56b3b, 0x8e472c, 0xc28a45,
0x8c6336, 0x9c4f30, 0xb97739, 0x775034
];
function leaf(x, z, scale = 1, angle = random() * Math.PI) {
const y = rand(-0.005, 0.065);
const color = pick(leafColors);
box(
x,
y,
z,
rand(0.24, 0.37) * scale,
0.045 * scale,
rand(0.11, 0.18) * scale,
color,
[rand(-0.08, 0.08), angle, rand(-0.08, 0.08)]
);
box(
x + Math.cos(angle) * 0.08 * scale,
y + 0.008,
z - Math.sin(angle) * 0.08 * scale,
0.12 * scale,
0.045 * scale,
0.1 * scale,
color,
[0, angle + rand(-0.3, 0.3), 0]
);
}
for (let i = 0; i < 115; i++) {
const x = rand(-6.7, 6.7);
const z = rand(-4.7, 4.7);
leaf(x, z, rand(0.75, 1.35));
}
// A thicker foreground drift.
for (let i = 0; i < 45; i++) {
const x = rand(-5.8, -2.0) + rand(-0.35, 0.35);
const z = rand(2.3, 4.4) + rand(-0.3, 0.3);
leaf(x, z, rand(0.85, 1.45));
}
// Twigs.
for (let i = 0; i < 12; i++) {
const x = rand(-6.2, 6.2);
const z = rand(-4.2, 4.2);
box(
x,
0.035,
z,
rand(0.55, 1.1),
0.07,
0.08,
pick([0x5b412a, 0x69492d, 0x473326]),
[0, random() * Math.PI, 0]
);
}
// ------------------------------------------------------------
// Invertebrate shelters and tiny decomposers
// ------------------------------------------------------------
// Shelter 1: stone canopy with a dark cavity underneath.
box(-2.72, 0.015, 2.25, 0.85, 0.05, 0.65, 0x252019);
box(-3.03, 0.26, 2.25, 0.2, 0.55, 0.6, 0x65655a);
box(-2.47, 0.25, 2.25, 0.2, 0.54, 0.6, 0x737064);
box(-2.73, 0.51, 2.2, 0.92, 0.22, 0.72, 0x777465);
box(-2.88, 0.66, 2.18, 0.45, 0.17, 0.48, 0x85806c);
// Pillbug under the stone.
for (let i = 0; i < 7; i++) {
const size = 0.13 - Math.abs(i - 3) * 0.012;
box(
-2.98 + i * 0.105,
0.085,
2.34,
size,
0.095,
size,
i % 2 ? 0x6b6651 : 0x81775a
);
}
for (let i = 0; i < 6; i++) {
box(
-2.91 + i * 0.105,
0.04,
2.18 + (i % 2) * 0.14,
0.025,
0.07,
0.025,
0x35372c
);
}
// Shelter 2: curled leaf around a small beetle.
box(-0.55, 0.06, 2.35, 0.74, 0.11, 0.23, 0x9b542f, [0, -0.2, 0]);
box(-0.62, 0.18, 2.48, 0.7, 0.1, 0.2, 0xb46a37, [0, -0.2, 0.12]);
box(-0.4, 0.13, 2.19, 0.55, 0.09, 0.18, 0x77432a, [0, -0.2, -0.1]);
box(-0.56, 0.085, 2.34, 0.25, 0.17, 0.19, 0x2f251c);
box(-0.55, 0.18, 2.32, 0.15, 0.035, 0.11, 0x874c28);
// Shelter 3: loose bark plates leaning against the log.
box(1.55, 0.025, 2.13, 0.92, 0.06, 0.62, 0x211b15);
box(1.48, 0.22, 2.16, 0.2, 0.43, 0.72, 0x5a3925, [0.12, 0, 0.16]);
box(1.78, 0.2, 2.12, 0.2, 0.4, 0.68, 0x69432a, [0.08, 0, -0.14]);
box(1.65, 0.43, 2.12, 0.64, 0.1, 0.67, 0x755033, [0.08, 0, 0]);
// Small segmented millipede crawling over the log.
for (let i = 0; i < 9; i++) {
box(
1.9 + i * 0.115,
1.47 + Math.sin(i * 0.8) * 0.025,
1.18 - Math.sin(i * 0.5) * 0.035,
0.13,
0.1,
0.12,
i % 2 ? 0x342d25 : 0x5a4330
);
}
// ------------------------------------------------------------
// Background stones and broken branches
// ------------------------------------------------------------
function rock(x, z, scale = 1) {
box(x, 0.15 * scale, z,
0.65 * scale, 0.38 * scale, 0.48 * scale, 0x5b5b51);
box(x - 0.15 * scale, 0.33 * scale, z + 0.04 * scale,
0.38 * scale, 0.28 * scale, 0.36 * scale, 0x6d6b5d);
box(x + 0.18 * scale, 0.29 * scale, z - 0.08 * scale,
0.28 * scale, 0.25 * scale, 0.3 * scale, 0x505248);
}
rock(-5.7, -1.15, 1.25);
rock(5.55, 1.65, 0.95);
rock(4.85, -3.6, 0.72);
rock(-5.75, 3.55, 0.66);
box(-5.8, 0.28, -3.45, 1.7, 0.18, 0.24, 0x4e3725, [0, 0.4, 0.08]);
box(-5.25, 0.43, -3.36, 0.95, 0.15, 0.18, 0x60442c, [0, 0.4, -0.12]);
box(5.5, 0.23, -2.3, 1.35, 0.16, 0.22, 0x493526, [0, -0.7, 0.05]);
// ------------------------------------------------------------
// Ambient dust motes
// ------------------------------------------------------------
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = [];
for (let i = 0; i < 120; i++) {
dustPositions.push(
rand(-7, 7),
rand(0.15, 4.5),
rand(-5, 5)
);
}
dustGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xe8d9aa,
size: 0.035,
transparent: true,
opacity: 0.38,
depthWrite: false
})
);
scene.add(dust);
buildBatches();
// ------------------------------------------------------------
// Screen-space feature labels
// ------------------------------------------------------------
const labelRoot = document.querySelector("#labels");
const features = [
{
id: "moss",
text: "Moss",
color: "#7fa64f",
position: new THREE.Vector3(-3.65, 2.25, 0.1)
},
{
id: "fungi",
text: "Bracket fungi",
color: "#c87545",
position: new THREE.Vector3(2.75, 1.15, 1.65)
},
{
id: "gallery",
text: "Wood gallery",
color: "#d1a060",
position: new THREE.Vector3(0.2, 0.75, 0.95)
},
{
id: "shelter",
text: "Microhabitat",
color: "#697b55",
position: new THREE.Vector3(-2.75, 0.48, 2.45)
},
{
id: "seedling",
text: "Seedling",
color: "#a8c56e",
position: new THREE.Vector3(3.65, 1.35, -2.25)
},
{
id: "litter",
text: "Leaf litter",
color: "#b6653e",
position: new THREE.Vector3(-4.7, 0.18, 2.6)
}
];
for (const feature of features) {
const element = document.createElement("div");
element.className = "callout";
element.style.setProperty("--c", feature.color);
element.innerHTML = `<span>${feature.text}</span>`;
labelRoot.appendChild(element);
feature.element = element;
}
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const feature of features) {
const projected = feature.position.clone().project(camera);
const cameraSpace = feature.position.clone()
.applyMatrix4(camera.matrixWorldInverse);
const visible =
cameraSpace.z < 0 &&
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
feature.element.style.opacity = visible ? "1" : "0";
feature.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
feature.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// ------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, touch pinch
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0.68, 0),
radius: 15.6,
theta: 0.69,
phi: 0.98
};
const initialControls = {
target: controls.target.clone(),
radius: controls.radius,
theta: controls.theta,
phi: controls.phi
};
let autoOrbit = false;
function applyCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y +
controls.radius * Math.cos(controls.phi),
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
function resetCamera() {
controls.target.copy(initialControls.target);
controls.radius = initialControls.radius;
controls.theta = initialControls.theta;
controls.phi = initialControls.phi;
applyCamera();
}
function panCamera(dx, dy) {
const scale = controls.radius * 0.00115;
const right = new THREE.Vector3(
Math.cos(controls.theta),
0,
-Math.sin(controls.theta)
);
const forward = new THREE.Vector3(
-Math.sin(controls.theta),
0,
-Math.cos(controls.theta)
);
controls.target.addScaledVector(right, -dx * scale);
controls.target.addScaledVector(forward, -dy * scale);
controls.target.y += dy * scale * 0.45;
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -4, 4);
controls.target.y = THREE.MathUtils.clamp(controls.target.y, 0.1, 2.4);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -3.5, 3.5);
}
const pointers = new Map();
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 pointerMidpoint() {
const values = [...pointers.values()];
if (values.length < 2) return { x: 0, y: 0 };
return {
x: (values[0].x + values[1].x) * 0.5,
y: (values[0].y + values[1].y) * 0.5
};
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
renderer.domElement.dataset.mode =
event.shiftKey || event.button === 2 ? "pan" : "orbit";
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
if (renderer.domElement.dataset.mode === "pan") {
panCamera(dx, dy);
} else {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.005,
0.36,
1.43
);
}
previous.x = event.clientX;
previous.y = event.clientY;
} else if (pointers.size === 2) {
const oldDistance = pointerDistance();
const oldMidpoint = pointerMidpoint();
previous.x = event.clientX;
previous.y = event.clientY;
const newDistance = pointerDistance();
const newMidpoint = pointerMidpoint();
if (oldDistance > 0 && newDistance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * (oldDistance / newDistance),
8.5,
25
);
}
panCamera(
newMidpoint.x - oldMidpoint.x,
newMidpoint.y - oldMidpoint.y
);
}
applyCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
renderer.domElement.dataset.mode = "";
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("lostpointercapture", releasePointer);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
8.5,
25
);
applyCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
document.querySelector("#reset").addEventListener("click", resetCamera);
document.querySelector("#orbit").addEventListener("click", (event) => {
autoOrbit = !autoOrbit;
event.currentTarget.classList.toggle("active", autoOrbit);
event.currentTarget.textContent = autoOrbit ? "Auto-orbit on" : "Auto-orbit";
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (autoOrbit) {
controls.theta += delta * 0.11;
}
dust.rotation.y += delta * 0.008;
dust.position.y = Math.sin(clock.elapsedTime * 0.18) * 0.08;
applyCamera();
updateLabels();
renderer.render(scene, camera);
}
resetCamera();
animate();
</script>
</body>
</html>
```