Prompt specification
Build or customize the Three.js 3D scene "Cloud-forest branch 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: Cloud-forest branch community
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/cloud-forest-branch-community-x0735
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts epiphytes and their host supports. Compose a bounded canopy branch with moss, epiphytes, insects, and filtered light; separate attachment locations and moisture pockets so the layered community remains readable. Voxel style.
Working Three.js Starter (cloud-forest-branch-community-x0735):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Canopy Commons — Voxel Epiphyte Diorama</title>
<style>
:root {
--ink: #233329;
--muted: #657366;
--paper: rgba(244, 241, 224, 0.88);
--line: rgba(42, 61, 44, 0.16);
--leaf: #668b55;
--moss: #91aa63;
--water: #56a9ad;
--flower: #d98291;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 38% 18%, #eef0d9 0, transparent 38%),
linear-gradient(145deg, #c7d3bd, #aebca9);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(350px, calc(100vw - 48px));
padding: 18px 20px 16px;
border: 1px solid var(--line);
border-radius: 5px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(37, 55, 42, 0.12);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 8px;
color: #647661;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 39px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 12px 0 0;
max-width: 290px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.rule {
display: flex;
align-items: center;
gap: 9px;
margin-top: 14px;
color: #596857;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.rule::before {
content: "";
width: 28px;
height: 2px;
background: var(--leaf);
}
.legend {
position: absolute;
right: 24px;
bottom: 24px;
width: 270px;
padding: 16px 17px;
border: 1px solid var(--line);
border-radius: 5px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(37, 55, 42, 0.11);
backdrop-filter: blur(12px);
}
.legend h2 {
margin: 0 0 12px;
font-size: 10px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 12px 1fr;
gap: 9px;
align-items: start;
margin-top: 9px;
font-size: 11px;
line-height: 1.4;
}
.swatch {
width: 10px;
height: 10px;
margin-top: 2px;
border-radius: 1px;
}
.legend-note {
margin: 13px 0 0;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.view-tools {
position: absolute;
top: 24px;
right: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid var(--line);
border-radius: 4px;
padding: 9px 12px;
background: var(--paper);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
box-shadow: 0 6px 20px rgba(37, 55, 42, 0.09);
backdrop-filter: blur(10px);
}
button:hover { background: #fffef0; }
button:active { transform: translateY(1px); }
.controls-hint {
position: absolute;
left: 24px;
bottom: 24px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 4px;
background: rgba(244, 241, 224, 0.76);
color: #586656;
font-size: 10px;
letter-spacing: 0.04em;
backdrop-filter: blur(10px);
}
.scene-label {
position: absolute;
z-index: 4;
min-width: 118px;
padding: 7px 9px 7px 10px;
border: 1px solid rgba(49, 68, 50, 0.18);
border-left: 3px solid var(--leaf);
border-radius: 3px;
background: rgba(247, 244, 228, 0.91);
color: var(--ink);
box-shadow: 0 5px 18px rgba(28, 43, 31, 0.12);
transform: translate(-50%, -100%);
transition: opacity 150ms ease;
backdrop-filter: blur(8px);
}
.scene-label strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 13px;
font-weight: 600;
}
.scene-label small {
display: block;
margin-top: 2px;
color: #71806f;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.scene-label.water {
border-left-color: var(--water);
}
#loader {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #c7d3bd;
color: #526451;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 450ms ease;
}
#loader.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.title-card {
top: 14px;
left: 14px;
width: 250px;
padding: 14px 15px;
}
.title-card .subtitle { display: none; }
.rule { margin-top: 10px; }
.legend { display: none; }
.view-tools { top: 14px; right: 14px; }
.controls-hint { left: 14px; bottom: 14px; }
.scene-label { min-width: 94px; padding: 5px 7px; }
.scene-label strong { font-size: 11px; }
.scene-label small { display: none; }
}
</style>
</head>
<body>
<div id="loader">Growing canopy…</div>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Forest field study · 07</div>
<h1>Canopy<br>Commons</h1>
<p class="subtitle">
A layered miniature of moss, bromeliads, orchids, and ferns sharing
one host branch without competing for the same wet surfaces.
</p>
<div class="rule">Voxel epiphyte community</div>
</section>
<section class="legend">
<h2>Field layers</h2>
<div class="legend-row">
<span class="swatch" style="background:#668b55"></span>
<span><strong>Epiphyte hosts</strong><br>Branches and raised bark shelves</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#91aa63"></span>
<span><strong>Moss carpets</strong><br>Attached between plant zones</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#56a9ad"></span>
<span><strong>Moisture pockets</strong><br>Reserved at forks and bark seams</span>
</div>
<p class="legend-note">
Attachment sites are spaced along distinct branch segments;
blue pools remain clear of root zones.
</p>
</section>
<div class="view-tools">
<button id="reset" type="button" title="Restore the initial camera">Reset view</button>
</div>
<div class="controls-hint">Drag to orbit · Scroll to zoom · Arrow keys to rotate</div>
<div id="label-bromeliad" class="scene-label" aria-hidden="true">
<strong>Bromeliad</strong><small>Rosette · zone A</small>
</div>
<div id="label-orchid" class="scene-label" aria-hidden="true">
<strong>Orchid</strong><small>Bark shelf · zone B</small>
</div>
<div id="label-fern" class="scene-label" aria-hidden="true">
<strong>Fern</strong><small>Upper fork · zone C</small>
</div>
<div id="label-water" class="scene-label water" aria-hidden="true">
<strong>Moisture pocket</strong><small>Fork basin</small>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbfcdbb);
scene.fog = new THREE.Fog(0xbfcdbb, 28, 62);
const camera = new THREE.PerspectiveCamera(
40,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const clock = new THREE.Clock();
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const X_AXIS = new THREE.Vector3(1, 0, 0);
const Y_AXIS = new THREE.Vector3(0, 1, 0);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
bark: material(0x674b36),
barkLight: material(0x856044),
barkDark: material(0x46382c),
barkCut: material(0xb68a59),
soil: material(0x5d4b3a),
soilDark: material(0x43382f),
earth: material(0x75604a),
leafDark: material(0x365b3e),
leaf: material(0x4f7d4b),
leafLight: material(0x739956),
moss: material(0x829b5a),
mossLight: material(0x9fb46d),
mossDark: material(0x607746),
bromelia: material(0x5e9254),
bromeliaLight: material(0x8aaf5f),
bromeliaRed: material(0xb65e52),
orchid: material(0x47734a),
orchidPink: material(0xd77f91),
orchidPinkLight: material(0xefa2ad),
pollen: material(0xe5bf55),
fern: material(0x39714b),
fernLight: material(0x5d9559),
lichen: material(0xa8c1a0),
lichenBlue: material(0x82aaa1),
water: material(0x5db8bd, {
transparent: true,
opacity: 0.67,
roughness: 0.18,
depthWrite: false
}),
waterBright: material(0xc5eeee, {
transparent: true,
opacity: 0.9,
roughness: 0.1
}),
insectBlack: material(0x252a25),
insectYellow: material(0xe1b744),
wing: material(0xe8e7d4, {
transparent: true,
opacity: 0.62,
depthWrite: false,
side: THREE.DoubleSide
}),
butterflyPink: material(0xd8799c, {
transparent: true,
opacity: 0.85,
side: THREE.DoubleSide
}),
pebble: material(0x8b8b73),
litter: material(0xa87945)
};
function voxel(
parent,
sx,
sy,
sz,
x,
y,
z,
mat,
rotationY = 0
) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.rotation.y = rotationY;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function segment(parent, a, b, thickness, depth, mat) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(length + 0.12, thickness, depth);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(X_AXIS, direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Deterministic randomness keeps the composition repeatable.
let randomSeed = 73921;
function random() {
randomSeed |= 0;
randomSeed = (randomSeed + 0x6d2b79f5) | 0;
let t = Math.imul(randomSeed ^ (randomSeed >>> 15), 1 | randomSeed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
function range(min, max) {
return min + (max - min) * random();
}
// -------------------------------------------------------------------------
// Direct camera controls — no external controls addon
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 1.0, 0),
yaw: 0.56,
pitch: 0.43,
radius: 27,
targetYaw: 0.56,
targetPitch: 0.43,
targetRadius: 27
};
function updateCamera(delta) {
const smoothing = 1 - Math.pow(0.0015, delta);
controls.yaw += (controls.targetYaw - controls.yaw) * smoothing;
controls.pitch += (controls.targetPitch - controls.pitch) * smoothing;
controls.radius += (controls.targetRadius - controls.radius) * smoothing;
const cosPitch = Math.cos(controls.pitch);
camera.position.set(
controls.target.x +
controls.radius * Math.cos(controls.pitch) * Math.sin(controls.yaw),
controls.target.y + controls.radius * Math.sin(controls.pitch),
controls.target.z +
controls.radius * Math.cos(controls.pitch) * Math.cos(controls.yaw)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
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;
controls.targetYaw -= dx * 0.006;
controls.targetPitch = THREE.MathUtils.clamp(
controls.targetPitch + dy * 0.005,
0.13,
1.18
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.targetRadius = THREE.MathUtils.clamp(
controls.targetRadius * Math.exp(event.deltaY * 0.001),
14,
45
);
},
{ passive: false }
);
addEventListener("keydown", event => {
if (event.key === "ArrowLeft") controls.targetYaw += 0.09;
if (event.key === "ArrowRight") controls.targetYaw -= 0.09;
if (event.key === "ArrowUp") {
controls.targetPitch = Math.min(1.18, controls.targetPitch + 0.06);
}
if (event.key === "ArrowDown") {
controls.targetPitch = Math.max(0.13, controls.targetPitch - 0.06);
}
if (event.key === "+" || event.key === "=") {
controls.targetRadius = Math.max(14, controls.targetRadius - 1.5);
}
if (event.key === "-") {
controls.targetRadius = Math.min(45, controls.targetRadius + 1.5);
}
});
function resetView() {
controls.target.set(0, 1.0, 0);
controls.targetYaw = 0.56;
controls.targetPitch = 0.43;
controls.targetRadius = innerWidth < 760 ? 34 : 27;
}
document.getElementById("reset").addEventListener("click", resetView);
// -------------------------------------------------------------------------
// Lighting and filtered sunbeams
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf0f3d9, 0x4e5849, 1.65);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight(0xffe5ad, 2.65);
sunlight.position.set(-8, 15, 10);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -18;
sunlight.shadow.camera.right = 18;
sunlight.shadow.camera.top = 15;
sunlight.shadow.camera.bottom = -10;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 45;
sunlight.shadow.bias = -0.0006;
scene.add(sunlight);
const fillLight = new THREE.DirectionalLight(0xbad7d2, 0.75);
fillLight.position.set(10, 7, -8);
scene.add(fillLight);
const leafSpot = new THREE.SpotLight(0xffe9b7, 55, 30, 0.46, 0.75, 1.5);
leafSpot.position.set(-4, 11, 5);
leafSpot.target.position.set(-4, 0, 0);
scene.add(leafSpot, leafSpot.target);
function lightBeam(from, to, width, opacity) {
const start = new THREE.Vector3(...from);
const end = new THREE.Vector3(...to);
const direction = end.clone().sub(start);
const length = direction.length();
const beamMaterial = new THREE.MeshBasicMaterial({
color: 0xffe7a8,
transparent: true,
opacity,
depthWrite: false,
blending: THREE.AdditiveBlending,
side: THREE.DoubleSide
});
const beam = new THREE.Mesh(unitBox, beamMaterial);
beam.scale.set(width, length, width * 0.68);
beam.position.copy(start).add(end).multiplyScalar(0.5);
beam.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
scene.add(beam);
}
lightBeam([-7.5, 12, -4.5], [-4.8, -1.6, 1.2], 1.25, 0.045);
lightBeam([-3.8, 11.5, -2.7], [0.4, -1.7, 2.0], 0.9, 0.032);
lightBeam([6.7, 11, -2.5], [5.2, -1.7, 1.4], 1.1, 0.038);
// -------------------------------------------------------------------------
// Bounded diorama base
// -------------------------------------------------------------------------
voxel(scene, 100, 0.3, 100, 0, -3.38, 0, material(0xaebba7));
voxel(scene, 28, 1.2, 17, 0, -2.72, 0, M.soilDark);
voxel(scene, 27.2, 0.48, 16.2, 0, -1.88, 0, M.soil);
voxel(scene, 26.2, 0.12, 15.2, 0, -1.59, 0, M.earth);
// Soil edge blocks and scattered forest-floor debris.
for (let i = 0; i < 48; i++) {
const edge = Math.floor(random() * 4);
let x, z;
if (edge === 0) {
x = range(-13, 13);
z = range(-7.7, -7.2);
} else if (edge === 1) {
x = range(-13, 13);
z = range(7.2, 7.7);
} else if (edge === 2) {
x = range(-13.4, -12.9);
z = range(-7.5, 7.5);
} else {
x = range(12.9, 13.4);
z = range(-7.5, 7.5);
}
const size = range(0.16, 0.42);
voxel(
scene,
size,
range(0.08, 0.2),
size,
x,
-1.47,
z,
random() > 0.5 ? M.soilDark : M.pebble
);
}
for (let i = 0; i < 24; i++) {
const leaf = voxel(
scene,
range(0.18, 0.38),
0.045,
range(0.1, 0.24),
range(-12.3, 12.3),
-1.48,
range(-6.7, 6.7),
random() > 0.45 ? M.litter : M.leafDark,
range(0, Math.PI)
);
leaf.rotation.z = range(-0.15, 0.15);
}
// -------------------------------------------------------------------------
// Host branch, trunk, and supporting forks
// -------------------------------------------------------------------------
const branch = new THREE.Group();
scene.add(branch);
const mainPoints = [
[-10.4, 0.20, -1.10],
[-8.5, 0.55, -0.90],
[-6.5, 0.55, -0.55],
[-4.5, 0.90, -0.35],
[-2.4, 0.85, 0.00],
[-0.3, 1.15, 0.20],
[1.8, 1.05, 0.10],
[3.8, 1.35, 0.40],
[5.8, 1.30, 0.70],
[7.8, 1.65, 0.50],
[9.7, 1.75, 0.15]
];
for (let i = 0; i < mainPoints.length - 1; i++) {
segment(
branch,
mainPoints[i],
mainPoints[i + 1],
1.02,
1.12,
i % 3 === 0 ? M.barkLight : M.bark
);
}
// Trunk supporting the left end of the branch.
voxel(branch, 1.95, 2.48, 1.95, -10.45, -0.40, -1.12, M.barkDark);
voxel(branch, 2.28, 0.32, 2.25, -10.45, 0.85, -1.12, M.bark);
voxel(branch, 2.38, 0.12, 2.32, -10.45, 1.02, -1.12, M.barkLight);
segment(
branch,
[-10.7, -1.35, -1.1],
[-12.1, -1.48, -2.0],
0.82,
0.85,
M.barkDark
);
segment(
branch,
[-10.2, -1.2, -0.7],
[-9.0, -1.48, 0.1],
0.72,
0.78,
M.bark
);
// Pale square cut face at the right end.
voxel(branch, 0.16, 1.04, 1.10, 9.78, 1.76, 0.15, M.barkCut);
voxel(branch, 0.04, 0.68, 0.74, 9.87, 1.76, 0.15, M.barkLight);
// Forks that carry the orchid and canopy.
segment(branch, [-1.6, 1.02, 0.05], [-0.6, 1.72, 0.56], 0.48, 0.55, M.bark);
segment(branch, [-0.6, 1.72, 0.56], [-1.25, 2.03, 1.25], 0.40, 0.46, M.barkLight);
segment(branch, [4.0, 1.40, 0.48], [4.8, 3.00, -0.40], 0.62, 0.68, M.bark);
segment(branch, [4.8, 3.00, -0.40], [7.0, 3.90, -0.90], 0.56, 0.62, M.barkLight);
segment(branch, [-9.1, 0.72, -0.92], [-9.7, 2.20, -1.80], 0.58, 0.64, M.bark);
segment(branch, [-9.7, 2.20, -1.80], [-8.0, 3.00, -2.50], 0.50, 0.57, M.barkLight);
// Small bark plates and seams break up the larger branch blocks.
for (let i = 0; i < 55; i++) {
const index = Math.floor(random() * (mainPoints.length - 1));
const a = new THREE.Vector3(...mainPoints[index]);
const b = new THREE.Vector3(...mainPoints[index + 1]);
const point = a.lerp(b, random());
const front = random() > 0.45;
const plate = voxel(
branch,
range(0.16, 0.44),
range(0.08, 0.23),
front ? 0.08 : range(0.16, 0.34),
point.x,
point.y + range(-0.25, 0.31),
point.z + (front ? 0.57 : range(-0.25, 0.25)),
random() > 0.48 ? M.barkDark : M.barkLight
);
plate.rotation.z = range(-0.08, 0.08);
}
// -------------------------------------------------------------------------
// Voxel canopy clusters
// -------------------------------------------------------------------------
function foliageCluster(center, count, spread) {
const group = new THREE.Group();
group.position.set(...center);
scene.add(group);
const palette = [M.leafDark, M.leaf, M.leafLight];
for (let i = 0; i < count; i++) {
const angle = range(0, Math.PI * 2);
const radius = Math.sqrt(random());
const x = Math.cos(angle) * radius * spread[0];
const z = Math.sin(angle) * radius * spread[2];
const y = range(-spread[1], spread[1]);
const leaf = voxel(
group,
range(0.42, 0.95),
range(0.22, 0.50),
range(0.38, 0.82),
x,
y,
z,
palette[Math.floor(random() * palette.length)],
range(0, Math.PI)
);
leaf.rotation.z = range(-0.24, 0.24);
leaf.rotation.x = range(-0.18, 0.18);
}
}
foliageCluster([-9.2, 4.15, -2.55], 58, [2.25, 1.25, 1.0]);
foliageCluster([7.8, 5.05, -1.75], 66, [2.55, 1.25, 1.15]);
// A few hanging voxel vines.
function hangingVine(x, z, top, length) {
for (let i = 0; i < length; i++) {
const y = top - i * 0.28;
const sway = Math.sin(i * 0.6) * 0.17;
voxel(scene, 0.07, 0.28, 0.07, x + sway, y, z, M.leafDark);
if (i % 2 === 0) {
const leaf = voxel(
scene,
0.38,
0.11,
0.25,
x + sway + (i % 4 === 0 ? 0.18 : -0.18),
y,
z,
i % 4 === 0 ? M.leaf : M.leafLight
);
leaf.rotation.z = range(-0.28, 0.28);
}
}
}
hangingVine(-8.5, -2.2, 3.9, 8);
hangingVine(6.6, -1.9, 4.9, 9);
// -------------------------------------------------------------------------
// Moss zones, deliberately placed between epiphyte attachment areas
// -------------------------------------------------------------------------
function mossPatch(x, y, z, radiusX, radiusZ, count) {
for (let i = 0; i < count; i++) {
const angle = range(0, Math.PI * 2);
const radius = Math.sqrt(random());
const px = x + Math.cos(angle) * radius * radiusX;
const pz = z + Math.sin(angle) * radius * radiusZ;
const height = range(0.09, 0.27);
const width = range(0.14, 0.34);
voxel(
scene,
width,
height,
width,
px,
y + height * 0.5,
pz,
random() > 0.72 ? M.mossLight : random() > 0.45 ? M.moss : M.mossDark
);
}
}
mossPatch(-7.6, 1.07, -0.77, 0.78, 0.40, 34);
mossPatch(1.65, 1.62, 0.08, 0.84, 0.42, 38);
mossPatch(7.65, 2.20, 0.55, 0.78, 0.40, 35);
// -------------------------------------------------------------------------
// Moisture pockets at bark seams and branch forks
// -------------------------------------------------------------------------
function moisturePocket(x, y, z) {
const group = new THREE.Group();
group.position.set(x, y, z);
scene.add(group);
voxel(group, 1.02, 0.16, 0.76, 0, 0, 0, M.barkDark);
voxel(group, 0.74, 0.08, 0.51, 0, 0.13, 0, M.water);
voxel(group, 0.24, 0.025, 0.07, -0.13, 0.18, 0.06, M.waterBright);
voxel(group, 0.10, 0.20, 0.10, 0.20, 0.31, 0.08, M.water, 0.4);
voxel(group, 0.07, 0.14, 0.07, 0.27, 0.52, 0.03, M.waterBright);
// A small mineral rim makes the water read as a separate pocket.
voxel(group, 0.13, 0.08, 0.10, -0.43, 0.10, 0.24, M.lichenBlue);
voxel(group, 0.10, 0.08, 0.12, 0.40, 0.10, -0.23, M.lichenBlue);
}
moisturePocket(-8.95, 1.10, -0.62);
moisturePocket(-3.55, 1.43, 0.02);
moisturePocket(3.52, 1.91, 0.79);
// -------------------------------------------------------------------------
// Bromeliad rosette
// -------------------------------------------------------------------------
function makeBromeliad(position) {
const group = new THREE.Group();
group.position.set(...position);
scene.add(group);
for (let i = 0; i < 13; i++) {
const angle = i * Math.PI * 2 / 13;
const leaf = new THREE.Group();
leaf.rotation.y = -angle;
group.add(leaf);
const length = i % 2 === 0 ? 1.35 : 1.12;
const color = i < 4
? M.bromeliaLight
: i % 3 === 0
? M.bromelia
: M.leaf;
const lower = voxel(
leaf, length * 0.58, 0.17, 0.40,
length * 0.22, 0.27, 0, color
);
lower.rotation.z = 0.36;
const middle = voxel(
leaf, length * 0.48, 0.16, 0.34,
length * 0.57, 0.69, 0, i % 4 === 0 ? M.bromeliaLight : color
);
middle.rotation.z = 0.54;
const tip = voxel(
leaf, length * 0.31, 0.14, 0.25,
length * 0.83, 1.08, 0, M.bromeliaLight
);
tip.rotation.z = 0.69;
}
// Red inner leaves suggest water held in the rosette.
for (let i = 0; i < 5; i++) {
const angle = i * Math.PI * 2 / 5;
const inner = voxel(
group, 0.60, 0.18, 0.25,
Math.cos(angle) * 0.18,
0.43,
Math.sin(angle) * 0.18,
i % 2 ? M.bromeliaRed : M.bromeliaLight,
-angle
);
inner.rotation.z = 0.55;
}
voxel(group, 0.38, 0.28, 0.38, 0, 0.38, 0, M.bromeliaRed);
voxel(group, 0.20, 0.12, 0.20, 0, 0.56, 0, M.waterBright);
}
makeBromeliad([-6.5, 1.13, -0.55]);
// -------------------------------------------------------------------------
// Orchid on a raised bark shelf
// -------------------------------------------------------------------------
function makeOrchid(position) {
const group = new THREE.Group();
group.position.set(...position);
scene.add(group);
for (let i = 0; i < 5; i++) {
const angle = i * Math.PI * 2 / 5 + 0.2;
const leaf = voxel(
group,
0.76,
0.14,
0.25,
Math.cos(angle) * 0.28,
0.20,
Math.sin(angle) * 0.28,
i % 2 ? M.orchid : M.leaf,
-angle
);
leaf.rotation.z = 0.08;
}
voxel(group, 0.11, 0.40, 0.11, 0.03, 0.42, 0, M.leafDark);
voxel(group, 0.10, 0.38, 0.10, 0.08, 0.76, 0.02, M.leafDark);
voxel(group, 0.09, 0.34, 0.09, 0.12, 1.08, 0.03, M.leafDark);
const flower = new THREE.Group();
flower.position.set(0.12, 1.30, 0.03);
group.add(flower);
for (let i = 0; i < 5; i++) {
const angle = i * Math.PI * 2 / 5;
const petal = voxel(
flower,
0.48,
0.12,
0.24,
Math.cos(angle) * 0.28,
0,
Math.sin(angle) * 0.28,
i % 2 ? M.orchidPink : M.orchidPinkLight,
-angle
);
petal.rotation.z = i % 2 ? 0.12 : -0.10;
}
voxel(flower, 0.27, 0.17, 0.27, 0, 0.03, 0, M.pollen);
voxel(flower, 0.20, 0.27, 0.13, -0.14, 0.19, 0, M.orchidPinkLight);
voxel(flower, 0.20, 0.27, 0.13, 0.14, 0.19, 0, M.orchidPinkLight);
// Two small buds on separate voxel stems.
voxel(group, 0.06, 0.27, 0.06, -0.24, 0.91, 0.08, M.leafDark);
voxel(group, 0.16, 0.14, 0.16, -0.24, 1.08, 0.08, M.orchidPink);
voxel(group, 0.06, 0.23, 0.06, 0.29, 0.82, -0.07, M.leafDark);
voxel(group, 0.13, 0.12, 0.13, 0.29, 0.98, -0.07, M.orchidPinkLight);
}
makeOrchid([-0.60, 1.84, 0.62]);
// -------------------------------------------------------------------------
// Fern with segmented fronds
// -------------------------------------------------------------------------
function makeFern(position) {
const group = new THREE.Group();
group.position.set(...position);
scene.add(group);
voxel(group, 0.42, 0.24, 0.42, 0, 0.08, 0, M.fern);
for (let f = 0; f < 7; f++) {
const angle = f * Math.PI * 2 / 7 + 0.18;
const frond = new THREE.Group();
frond.rotation.y = -angle;
group.add(frond);
for (let j = 0; j < 7; j++) {
const t = j / 6;
const x = 0.16 + t * 1.75;
const y = 0.18 + t * 1.60 - 0.42 * t * t;
const nextT = (j + 1) / 6;
const nextY = 0.18 + nextT * 1.60 - 0.42 * nextT * nextT;
const angleZ = Math.atan2(nextY - y, 1.75 / 6);
const width = 0.48 - t * 0.16;
const stem = voxel(
frond, width, 0.10, 0.12,
x, y, 0,
j % 2 ? M.fernLight : M.fern
);
stem.rotation.z = angleZ;
const leafletSize = 0.34 - t * 0.10;
for (const side of [-1, 1]) {
const leaflet = voxel(
frond,
leafletSize,
0.065,
0.16,
x,
y + 0.02,
side * (0.18 - t * 0.05),
j % 2 ? M.fernLight : M.fern
);
leaflet.rotation.z = angleZ + side * 0.12;
leaflet.rotation.y = side * 0.18;
}
}
}
}
makeFern([5.75, 1.91, 0.72]);
// -------------------------------------------------------------------------
// Crustose lichen on the far-right bark face
// -------------------------------------------------------------------------
const lichen = new THREE.Group();
scene.add(lichen);
for (let i = 0; i < 38; i++) {
const x = range(8.05, 9.48);
const y = range(1.64, 2.38);
const size = range(0.11, 0.30);
const patch = voxel(
lichen,
size,
size * 0.70,
0.09,
x,
y,
0.86 + range(-0.05, 0.06),
random() > 0.68 ? M.lichenBlue : M.lichen,
range(0, Math.PI)
);
patch.rotation.z = range(-0.22, 0.22);
}
// -------------------------------------------------------------------------
// Sun-dappled patches on the base and branch
// -------------------------------------------------------------------------
const dappleMaterial = new THREE.MeshBasicMaterial({
color: 0xffe3a0,
transparent: true,
opacity: 0.10,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const dappleLocations = [
[-7.8, -1.48, -1.1, 1.1, 0.02, 0.65],
[-5.9, -1.48, 0.6, 0.75, 0.02, 0.45],
[-1.2, -1.48, 1.4, 1.25, 0.02, 0.68],
[2.1, -1.48, -1.0, 0.86, 0.02, 0.48],
[4.9, -1.48, 0.5, 1.18, 0.02, 0.62],
[8.0, -1.48, -1.7, 0.82, 0.02, 0.50]
];
for (const [x, y, z, sx, sy, sz] of dappleLocations) {
const patch = new THREE.Mesh(unitBox, dappleMaterial);
patch.scale.set(sx, sy, sz);
patch.position.set(x, y, z);
scene.add(patch);
}
// -------------------------------------------------------------------------
// Insects
// -------------------------------------------------------------------------
function makeBee() {
const root = new THREE.Group();
const wings = [];
voxel(root, 0.22, 0.18, 0.19, -0.18, 0, 0, M.insectBlack);
voxel(root, 0.15, 0.20, 0.20, 0.00, 0, 0, M.insectYellow);
voxel(root, 0.18, 0.19, 0.19, 0.16, 0, 0, M.insectBlack);
voxel(root, 0.19, 0.18, 0.18, 0.31, 0, 0, M.insectYellow);
const leftWing = voxel(root, 0.28, 0.025, 0.20, 0.02, 0.13, 0.14, M.wing);
const rightWing = voxel(root, 0.28, 0.025, 0.20, 0.02, 0.13, -0.14, M.wing);
wings.push(leftWing, rightWing);
voxel(root, 0.03, 0.13, 0.03, 0.42, 0.09, 0.06, M.insectBlack);
voxel(root, 0.03, 0.13, 0.03, 0.42, 0.09, -0.06, M.insectBlack);
scene.add(root);
return { root, wings };
}
function makeButterfly() {
const root = new THREE.Group();
const wings = [];
voxel(root, 0.30, 0.11, 0.13, 0, 0, 0, M.insectBlack);
voxel(root, 0.15, 0.14, 0.15, 0.18, 0.03, 0, M.insectBlack);
const leftUpper = voxel(root, 0.39, 0.045, 0.34, -0.04, 0.08, 0.23, M.butterflyPink);
const leftLower = voxel(root, 0.29, 0.045, 0.27, -0.09, -0.02, 0.20, M.orchidPinkLight);
const rightUpper = voxel(root, 0.39, 0.045, 0.34, -0.04, 0.08, -0.23, M.butterflyPink);
const rightLower = voxel(root, 0.29, 0.045, 0.27, -0.09, -0.02, -0.20, M.orchidPinkLight);
wings.push(leftUpper, rightUpper, leftLower, rightLower);
voxel(root, 0.025, 0.18, 0.025, 0.25, 0.12, 0.05, M.insectBlack);
voxel(root, 0.025, 0.18, 0.025, 0.25, 0.12, -0.05, M.insectBlack);
scene.add(root);
return { root, wings };
}
function makeBeetle() {
const root = new THREE.Group();
voxel(root, 0.26, 0.18, 0.21, 0, 0, 0, M.insectBlack);
voxel(root, 0.15, 0.17, 0.19, 0.20, 0.01, 0, M.leafDark);
voxel(root, 0.04, 0.03, 0.09, 0.29, 0.05, 0.06, M.pollen);
voxel(root, 0.04, 0.03, 0.09, 0.29, 0.05, -0.06, M.pollen);
scene.add(root);
return { root, wings: [] };
}
const bee = makeBee();
const butterfly = makeButterfly();
const beetle = makeBeetle();
const insects = [
{
...bee,
anchor: new THREE.Vector3(-6.5, 2.78, -0.45),
radius: 0.83,
speed: 1.12,
phase: 0.4,
flap: 28
},
{
...butterfly,
anchor: new THREE.Vector3(-0.55, 3.30, 0.70),
radius: 1.02,
speed: 0.66,
phase: 2.1,
flap: 13
},
{
...beetle,
anchor: new THREE.Vector3(5.75, 2.80, 0.85),
radius: 0.72,
speed: 0.90,
phase: 4.4,
flap: 0
}
];
function animateInsects(time) {
for (const insect of insects) {
const angle = time * insect.speed + insect.phase;
const x = insect.anchor.x + Math.cos(angle) * insect.radius;
const z = insect.anchor.z + Math.sin(angle) * insect.radius * 0.68;
const y = insect.anchor.y + Math.sin(time * 1.7 + insect.phase) * 0.20;
insect.root.position.set(x, y, z);
const dx = -Math.sin(angle) * insect.radius;
const dz = Math.cos(angle) * insect.radius * 0.68;
insect.root.rotation.y = -Math.atan2(dz, dx);
insect.root.rotation.z = Math.sin(time * 2.4 + insect.phase) * 0.09;
const flap = Math.sin(time * insect.flap) * 0.72;
if (insect.wings[0]) insect.wings[0].rotation.x = flap;
if (insect.wings[1]) insect.wings[1].rotation.x = -flap;
if (insect.wings.length === 4) {
insect.wings[2].rotation.x = -flap * 0.8;
insect.wings[3].rotation.x = flap * 0.8;
}
}
}
// -------------------------------------------------------------------------
// Floating cube motes in the filtered light
// -------------------------------------------------------------------------
const moteCount = 52;
const moteMaterial = new THREE.MeshBasicMaterial({
color: 0xf7edb5,
transparent: true,
opacity: 0.55,
depthWrite: false
});
const motes = new THREE.InstancedMesh(unitBox, moteMaterial, moteCount);
motes.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
scene.add(motes);
const moteData = [];
const dummy = new THREE.Object3D();
for (let i = 0; i < moteCount; i++) {
moteData.push({
x: range(-10, 10),
y: range(-0.8, 7.4),
z: range(-4.8, 4.8),
phase: range(0, Math.PI * 2),
speed: range(0.12, 0.34),
size: range(0.025, 0.065)
});
}
function animateMotes(time) {
for (let i = 0; i < moteCount; i++) {
const data = moteData[i];
const wrappedY = -0.8 + ((data.y + time * data.speed + 0.8) % 8.2);
dummy.position.set(
data.x + Math.sin(time * 0.42 + data.phase) * 0.35,
wrappedY,
data.z + Math.cos(time * 0.31 + data.phase) * 0.28
);
dummy.scale.setScalar(data.size);
dummy.updateMatrix();
motes.setMatrixAt(i, dummy.matrix);
}
motes.instanceMatrix.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Projected scene labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById("label-bromeliad"),
position: new THREE.Vector3(-6.5, 3.02, -0.55),
offsetX: -8,
offsetY: -12
},
{
element: document.getElementById("label-orchid"),
position: new THREE.Vector3(-0.55, 3.58, 0.65),
offsetX: 8,
offsetY: -12
},
{
element: document.getElementById("label-fern"),
position: new THREE.Vector3(5.75, 3.42, 0.72),
offsetX: 10,
offsetY: -12
},
{
element: document.getElementById("label-water"),
position: new THREE.Vector3(3.52, 2.34, 0.79),
offsetX: 25,
offsetY: 5
}
];
function updateLabels() {
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * innerWidth + label.offsetX;
const y = (-projected.y * 0.5 + 0.5) * innerHeight + label.offsetY;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.fov = innerWidth < 760 ? 49 : 40;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
if (innerWidth < 760) {
controls.targetRadius = 34;
controls.radius = 34;
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
updateCamera(delta);
animateInsects(time);
animateMotes(time);
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.getElementById("loader").classList.add("hidden");
});
</script>
</body>
</html>
```