Prompt specification
Build or customize the Three.js 3D scene "Forest gap regeneration vignette" 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: Forest gap regeneration vignette
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/forest-gap-regeneration-vignette-x0723
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this stylized scene: Build a small forest cross-section with mature crowns, shaded understory, and one canopy gap; younger plants occupy visibly different light conditions across the same ground.
Working Three.js Starter (forest-gap-regeneration-vignette-x0723):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Where the Light Lands — Forest Cross-Section</title>
<style>
:root {
color-scheme: light;
--ink: #17382b;
--panel: rgba(246, 249, 239, 0.86);
--line: rgba(23, 56, 43, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8e4d9;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 19px 21px 17px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 15px 45px rgba(31, 63, 45, 0.12);
backdrop-filter: blur(13px);
}
.eyebrow {
margin-bottom: 7px;
color: #64816b;
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, 4vw, 40px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 320px;
margin: 10px 0 0;
color: #526c5d;
font-size: 12px;
line-height: 1.55;
}
.legend {
position: absolute;
left: 24px;
bottom: 24px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: calc(100vw - 48px);
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 12px 36px rgba(31, 63, 45, 0.1);
backdrop-filter: blur(13px);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
padding: 5px 8px;
border-radius: 10px;
color: #4c6656;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
white-space: nowrap;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.sun {
background: #b9dc62;
}
.swatch.filtered {
background: #579a59;
}
.swatch.shade {
background: #285947;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
.hint {
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 12px;
background: var(--panel);
color: #607667;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.04em;
backdrop-filter: blur(10px);
}
button {
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 12px;
padding: 10px 13px;
background: var(--panel);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.05em;
cursor: pointer;
backdrop-filter: blur(10px);
}
button:hover {
background: rgba(255, 255, 255, 0.96);
}
.scene-label {
position: absolute;
left: 0;
top: 0;
display: none;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 999px;
background: rgba(250, 249, 223, 0.88);
box-shadow: 0 6px 20px rgba(35, 63, 43, 0.13);
color: #56652d;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
white-space: nowrap;
transform: translate(-50%, -100%);
}
.scene-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 25px;
background: rgba(91, 104, 50, 0.6);
}
@media (max-width: 650px) {
.title-card {
top: 14px;
left: 14px;
padding: 15px 17px;
}
.subtitle {
display: none;
}
.legend {
left: 14px;
bottom: 14px;
gap: 2px;
}
.legend-item {
padding: 4px 5px;
font-size: 9px;
}
.controls {
right: 14px;
bottom: 76px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Forest ecology / light gradient</div>
<h1>Where the<br />Light Lands</h1>
<p class="subtitle">
One continuous forest floor beneath a single canopy opening.
Younger plants reveal the changing light conditions.
</p>
</section>
<section class="legend" aria-label="Light condition legend">
<div class="legend-item">
<span class="swatch sun"></span>
SUNLIT GAP
</div>
<div class="legend-item">
<span class="swatch filtered"></span>
FILTERED EDGE
</div>
<div class="legend-item">
<span class="swatch shade"></span>
DEEP SHADE
</div>
</section>
<div class="controls">
<div class="hint">DRAG TO ORBIT · SCROLL TO ZOOM</div>
<button id="reset-view" type="button">RESET</button>
</div>
<div id="gap-label" class="scene-label">CANOPY GAP</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, scene and camera
// ------------------------------------------------------------
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.08;
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd6e3d8);
scene.fog = new THREE.Fog(0xd6e3d8, 27, 56);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
target: new THREE.Vector3(0, 3.8, 0),
desiredTheta: 0.62,
desiredPhi: 1.29,
desiredRadius: 23.5,
theta: 0.62,
phi: 1.29,
radius: 23.5
};
function updateCamera() {
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);
}
updateCamera();
// Direct, dependency-free orbit controls.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
controls.desiredTheta -= dx * 0.006;
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi - dy * 0.005,
0.58,
1.48
);
});
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("contextmenu", (event) =>
event.preventDefault()
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius + event.deltaY * 0.012,
15,
33
);
},
{ passive: false }
);
function resetView() {
controls.desiredTheta = 0.62;
controls.desiredPhi = 1.29;
controls.desiredRadius = 23.5;
}
document.getElementById("reset-view").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xe8f4ef, 0x594330, 1.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0bd, 2.9);
sun.position.set(-8, 15, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.035;
scene.add(sun);
scene.add(sun.target);
const coolFill = new THREE.DirectionalLight(0x91b9c7, 0.55);
coolFill.position.set(9, 7, -8);
scene.add(coolFill);
const gapLight = new THREE.SpotLight(
0xffe4a0,
35,
30,
Math.PI / 7,
0.65,
1.3
);
gapLight.position.set(-4.5, 13, 5.5);
gapLight.target.position.set(0.35, 0, 0.25);
gapLight.castShadow = true;
gapLight.shadow.mapSize.set(1024, 1024);
gapLight.shadow.bias = -0.0003;
scene.add(gapLight);
scene.add(gapLight.target);
// ------------------------------------------------------------
// Shared helpers and materials
// ------------------------------------------------------------
function randomGenerator(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 = randomGenerator(74291);
const barkMaterial = new THREE.MeshStandardMaterial({
color: 0x684835,
roughness: 1,
flatShading: true
});
const rootMaterial = new THREE.MeshStandardMaterial({
color: 0x513727,
roughness: 1,
flatShading: true
});
const stemMaterial = new THREE.MeshStandardMaterial({
color: 0x654d2d,
roughness: 1
});
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x7b8274,
roughness: 1,
flatShading: true
});
const crownGeometry = new THREE.IcosahedronGeometry(1, 1);
const leafGeometry = new THREE.SphereGeometry(1, 8, 5);
const swayables = [];
const plantGroups = [];
function cylinderBetween(
parent,
pointA,
pointB,
radiusA,
radiusB,
material,
radialSegments = 8
) {
const direction = new THREE.Vector3().subVectors(pointB, pointA);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radiusB,
radiusA,
length,
radialSegments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(pointA).add(pointB).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Soil cross-section and continuous ground
// ------------------------------------------------------------
const soilLayers = [
{
height: 0.58,
y: -0.29,
color: 0x59432f
},
{
height: 0.78,
y: -0.97,
color: 0x76533a
},
{
height: 0.58,
y: -1.65,
color: 0x8b6745
},
{
height: 0.32,
y: -2.1,
color: 0x66665a
}
];
for (const layer of soilLayers) {
const material = new THREE.MeshStandardMaterial({
color: layer.color,
roughness: 1,
flatShading: true
});
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(18, layer.height, 11),
material
);
mesh.position.y = layer.y;
mesh.receiveShadow = true;
scene.add(mesh);
}
const groundGeometry = new THREE.PlaneGeometry(18, 11, 22, 15);
groundGeometry.rotateX(-Math.PI / 2);
const groundPositions = groundGeometry.attributes.position;
for (let i = 0; i < groundPositions.count; i++) {
const x = groundPositions.getX(i);
const z = groundPositions.getZ(i);
const edge = Math.max(Math.abs(x) / 9, Math.abs(z) / 5.5);
const height =
(random() - 0.5) * 0.055 * (0.35 + edge * 0.65);
groundPositions.setY(i, height);
}
groundGeometry.computeVertexNormals();
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x718654,
roughness: 1,
flatShading: true
});
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.position.y = 0.025;
ground.receiveShadow = true;
scene.add(ground);
// A quiet pool of light helps mark the same continuous ground.
const lightPool = new THREE.Mesh(
new THREE.CircleGeometry(2.35, 64),
new THREE.MeshBasicMaterial({
color: 0xfff1a4,
transparent: true,
opacity: 0.12,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
lightPool.rotation.x = -Math.PI / 2;
lightPool.position.set(0.35, 0.075, 0.25);
scene.add(lightPool);
// ------------------------------------------------------------
// Mature trees and broad, faceted crowns
// ------------------------------------------------------------
const treeSpecifications = [
{ x: -6.0, z: 3.3, height: 9.1, size: 1.0 },
{ x: -5.2, z: -1.8, height: 10.1, size: 1.05 },
{ x: -7.1, z: -3.8, height: 8.9, size: 0.92 },
{ x: -2.8, z: -4.25, height: 9.5, size: 0.93 },
{ x: 2.8, z: -4.05, height: 9.6, size: 0.96 },
{ x: 5.2, z: -1.5, height: 10.0, size: 1.04 },
{ x: 6.2, z: 3.2, height: 9.25, size: 1.0 }
];
const crownPalettes = [
[0x315f3d, 0x3c7044, 0x4b7d4b, 0x56874f],
[0x2b5838, 0x376a41, 0x467b48, 0x527f49],
[0x376847, 0x44764a, 0x527f4c, 0x608b54]
];
function buildMatureTree(spec, index) {
const group = new THREE.Group();
group.position.set(spec.x, 0, spec.z);
scene.add(group);
const h = spec.height;
const trunkTop = new THREE.Vector3(
(random() - 0.5) * 0.25,
h * 0.68,
(random() - 0.5) * 0.2
);
cylinderBetween(
group,
new THREE.Vector3(0, 0, 0),
trunkTop,
0.23 * spec.size,
0.105 * spec.size,
barkMaterial,
9
);
const crownCenter = new THREE.Vector3(
trunkTop.x,
h * 0.8,
trunkTop.z
);
const offsets = [
[0, 0, 0, 2.05, 1.3, 1.8],
[-1.28, 0.14, 0.12, 1.43, 1.08, 1.4],
[1.28, 0.12, 0.24, 1.46, 1.12, 1.42],
[-0.2, 0.48, -1.04, 1.52, 1.05, 1.22],
[-0.22, 0.4, 1.06, 1.54, 1.1, 1.3],
[-0.82, 0.72, -0.6, 1.18, 0.94, 1.08],
[0.82, 0.7, -0.57, 1.16, 0.95, 1.06],
[0.02, 0.9, 0.05, 1.2, 0.92, 1.18]
];
const palette = crownPalettes[index % crownPalettes.length];
offsets.forEach((offset, clusterIndex) => {
const center = crownCenter.clone().add(
new THREE.Vector3(
offset[0] * spec.size,
offset[1] * spec.size,
offset[2] * spec.size
)
);
const branchStart = trunkTop
.clone()
.multiplyScalar(0.72)
.add(
new THREE.Vector3(
offset[0] * 0.18,
-0.18,
offset[2] * 0.18
)
);
cylinderBetween(
group,
branchStart,
center.clone().add(new THREE.Vector3(0, -0.35, 0)),
0.075 * spec.size,
0.025 * spec.size,
barkMaterial,
7
);
const color = new THREE.Color(
palette[(clusterIndex + index) % palette.length]
);
color.offsetHSL(
(random() - 0.5) * 0.018,
(random() - 0.5) * 0.06,
(random() - 0.5) * 0.045
);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.94,
flatShading: true
});
const crown = new THREE.Mesh(crownGeometry, material);
crown.position.copy(center);
crown.scale.set(
offset[3] * spec.size,
offset[4] * spec.size,
offset[5] * spec.size
);
crown.rotation.set(
random() * 0.45,
random() * Math.PI,
random() * 0.25
);
crown.castShadow = true;
crown.receiveShadow = true;
group.add(crown);
swayables.push({
object: crown,
baseY: crown.position.y,
baseRotationZ: crown.rotation.z,
phase: random() * Math.PI * 2,
amount: 0.011
});
});
// Buttress roots around the visible tree bases.
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2 + random() * 0.5;
const length = 0.45 + random() * 0.55;
cylinderBetween(
group,
new THREE.Vector3(0, 0.34, 0),
new THREE.Vector3(
Math.cos(angle) * length,
0.015,
Math.sin(angle) * length
),
0.09,
0.025,
rootMaterial,
6
);
}
}
treeSpecifications.forEach(buildMatureTree);
// ------------------------------------------------------------
// Exposed roots on the front cut face
// ------------------------------------------------------------
const frontZ = 5.535;
function addFrontRootTree(x, sourceZ) {
cylinderBetween(
scene,
new THREE.Vector3(x, 0.055, sourceZ),
new THREE.Vector3(x + 0.1, 0.045, 4.55),
0.085,
0.045,
rootMaterial,
7
);
cylinderBetween(
scene,
new THREE.Vector3(x + 0.1, 0.045, 4.55),
new THREE.Vector3(x, -0.12, frontZ),
0.055,
0.04,
rootMaterial,
7
);
cylinderBetween(
scene,
new THREE.Vector3(x, -0.1, frontZ),
new THREE.Vector3(x - 0.2, -0.95, frontZ),
0.07,
0.025,
rootMaterial,
6
);
cylinderBetween(
scene,
new THREE.Vector3(x, -0.1, frontZ),
new THREE.Vector3(x + 0.25, -0.85, frontZ),
0.055,
0.02,
rootMaterial,
6
);
cylinderBetween(
scene,
new THREE.Vector3(x - 0.15, -0.75, frontZ),
new THREE.Vector3(x - 0.72, -1.35, frontZ),
0.03,
0.009,
rootMaterial,
5
);
cylinderBetween(
scene,
new THREE.Vector3(x + 0.18, -0.64, frontZ),
new THREE.Vector3(x + 0.76, -1.15, frontZ),
0.026,
0.008,
rootMaterial,
5
);
}
addFrontRootTree(-6, 3.3);
addFrontRootTree(6.2, 3.2);
// Small stones embedded in the cut face.
for (let i = 0; i < 24; i++) {
const stone = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.13 + random() * 0.16, 0),
rockMaterial
);
stone.position.set(
-8.4 + random() * 16.8,
-0.65 - random() * 1.65,
frontZ + 0.02
);
stone.scale.set(
0.8 + random() * 1.4,
0.45 + random() * 0.7,
0.25
);
stone.rotation.set(random(), random(), random());
stone.receiveShadow = true;
scene.add(stone);
}
// ------------------------------------------------------------
// Younger plants: broad leaves in the gap, smaller transition
// plants, and low ferns under the deepest shade.
// ------------------------------------------------------------
function makeLeafMaterial(color, emissive = 0x000000) {
return new THREE.MeshStandardMaterial({
color,
emissive,
emissiveIntensity: emissive ? 0.08 : 0,
roughness: 0.85,
flatShading: true
});
}
const gapLeafMaterial = makeLeafMaterial(0x9bcf4e, 0x263600);
const gapLeafLightMaterial = makeLeafMaterial(0xb7d967, 0x263600);
const edgeLeafMaterial = makeLeafMaterial(0x579b59);
const edgeLeafLightMaterial = makeLeafMaterial(0x70b567);
const shadeLeafMaterial = makeLeafMaterial(0x285a47);
const shadeLeafLightMaterial = makeLeafMaterial(0x367057);
function createBroadleafPlant(x, z, scale, palette, phase) {
const group = new THREE.Group();
group.position.set(x, 0.025, z);
group.rotation.y = random() * Math.PI * 2;
scene.add(group);
const height = 1.6 * scale;
const stemTop = new THREE.Vector3(
(random() - 0.5) * 0.08,
height * 0.78,
(random() - 0.5) * 0.08
);
cylinderBetween(
group,
new THREE.Vector3(0, 0, 0),
stemTop,
0.035 * scale,
0.012 * scale,
stemMaterial,
6
);
const levels = [0.34, 0.54, 0.72];
const leafCount = 3;
levels.forEach((level, levelIndex) => {
for (let i = 0; i < leafCount; i++) {
const angle =
(i / leafCount) * Math.PI * 2 +
levelIndex * 1.15 +
phase * 0.1;
const start = new THREE.Vector3(
0,
height * level,
0
);
const direction = new THREE.Vector3(
Math.cos(angle),
0.24 + random() * 0.2,
Math.sin(angle)
).normalize();
const reach = (0.3 + random() * 0.1) * scale;
const end = start
.clone()
.add(direction.clone().multiplyScalar(reach));
cylinderBetween(
group,
start,
end,
0.012 * scale,
0.005 * scale,
stemMaterial,
5
);
const material =
(i + levelIndex) % 3 === 0
? palette[1]
: palette[0];
const leaf = new THREE.Mesh(leafGeometry, material);
leaf.position.copy(end).add(
direction.clone().multiplyScalar(0.17 * scale)
);
leaf.scale.set(
0.16 * scale,
0.055 * scale,
0.39 * scale
);
leaf.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction
);
leaf.castShadow = true;
leaf.receiveShadow = true;
group.add(leaf);
}
});
plantGroups.push({
object: group,
baseRotationZ: group.rotation.z,
phase,
amount: 0.018
});
return group;
}
function createFern(x, z, scale, phase) {
const group = new THREE.Group();
group.position.set(x, 0.025, z);
group.rotation.y = random() * Math.PI * 2;
scene.add(group);
const frondCount = 5;
for (let i = 0; i < frondCount; i++) {
const angle = (i / frondCount) * Math.PI * 2 + phase * 0.2;
const length = (0.58 + random() * 0.2) * scale;
const height = (0.38 + random() * 0.15) * scale;
const start = new THREE.Vector3(0, 0.02, 0);
const middle = new THREE.Vector3(
Math.cos(angle) * length * 0.48,
height,
Math.sin(angle) * length * 0.48
);
const end = new THREE.Vector3(
Math.cos(angle) * length,
height * 0.35,
Math.sin(angle) * length
);
const curve = new THREE.QuadraticBezierCurve3(
start,
middle,
end
);
const frond = new THREE.Mesh(
new THREE.TubeGeometry(curve, 8, 0.014 * scale, 4, false),
shadeLeafLightMaterial
);
frond.castShadow = true;
group.add(frond);
for (let j = 1; j <= 4; j++) {
const t = j / 5;
const point = curve.getPoint(t);
const tangent = curve.getTangent(t).normalize();
for (const side of [-1, 1]) {
const sideDirection = new THREE.Vector3()
.crossVectors(tangent, new THREE.Vector3(0, 1, 0))
.normalize()
.multiplyScalar(side);
const leafDirection = tangent
.clone()
.multiplyScalar(0.35)
.add(sideDirection.multiplyScalar(0.8))
.add(new THREE.Vector3(0, 0.12, 0))
.normalize();
const leaf = new THREE.Mesh(
leafGeometry,
j % 2 ? shadeLeafMaterial : shadeLeafLightMaterial
);
leaf.position.copy(point);
leaf.scale.set(
0.07 * scale,
0.025 * scale,
0.19 * scale
);
leaf.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
leafDirection
);
leaf.castShadow = true;
group.add(leaf);
}
}
}
plantGroups.push({
object: group,
baseRotationZ: group.rotation.z,
phase,
amount: 0.022
});
return group;
}
// Sunlit gap: taller, broader, yellow-green foliage.
const gapPlants = [
[-0.75, 1.75, 1.1],
[0.35, 0.55, 1.25],
[1.45, 1.85, 1.05],
[0.15, -1.45, 0.95],
[2.0, -0.65, 0.9],
[-0.2, 3.35, 0.78]
];
gapPlants.forEach(([x, z, scale], index) => {
createBroadleafPlant(
x,
z,
scale,
[gapLeafMaterial, gapLeafLightMaterial],
index * 0.8
);
});
// Filtered edge: medium-height, cooler green plants.
const edgePlants = [
[-3.1, 2.1, 0.82],
[-3.55, -0.35, 0.72],
[-3.8, -2.8, 0.64],
[3.05, 1.85, 0.82],
[3.55, -0.6, 0.7],
[4.15, -2.75, 0.62],
[2.85, 3.5, 0.65]
];
edgePlants.forEach(([x, z, scale], index) => {
createBroadleafPlant(
x,
z,
scale,
[edgeLeafMaterial, edgeLeafLightMaterial],
index * 0.9
);
});
// Deep shade: low, sparse, blue-green ferns.
const shadePlants = [
[-5.1, 2.65, 1.0],
[-5.7, -0.8, 0.9],
[-4.9, -3.0, 0.85],
[-6.55, 0.5, 0.95],
[5.3, 2.6, 1.0],
[5.7, -0.7, 0.9],
[4.9, -3.1, 0.86],
[6.45, 0.45, 0.92]
];
shadePlants.forEach(([x, z, scale], index) => {
createFern(x, z, scale, index * 0.77);
});
// ------------------------------------------------------------
// Ground cover, rocks, litter and mushrooms
// ------------------------------------------------------------
const grassGeometry = new THREE.ConeGeometry(0.025, 0.28, 3);
grassGeometry.translate(0, 0.14, 0);
const grassMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
vertexColors: true
});
const grassCount = 180;
const grass = new THREE.InstancedMesh(
grassGeometry,
grassMaterial,
grassCount
);
const dummy = new THREE.Object3D();
const grassColor = new THREE.Color();
for (let i = 0; i < grassCount; i++) {
let x = random() * 16.6 - 8.3;
let z = random() * 9.7 - 4.85;
// Keep the visible cross-section edge readable.
if (Math.abs(x) > 8.4 || Math.abs(z) > 4.95) continue;
const gapDistance = Math.hypot(x - 0.35, z - 0.25);
dummy.position.set(x, 0.03, z);
dummy.rotation.set(
(random() - 0.5) * 0.2,
random() * Math.PI,
(random() - 0.5) * 0.25
);
const scale = 0.55 + random() * 0.85;
dummy.scale.set(scale, scale, scale);
dummy.updateMatrix();
grass.setMatrixAt(i, dummy.matrix);
if (gapDistance < 2.1) {
grassColor.set(0x9bbb56);
} else if (gapDistance < 4.4) {
grassColor.set(0x648d50);
} else {
grassColor.set(0x355f46);
}
grass.setColorAt(i, grassColor);
}
grass.instanceMatrix.needsUpdate = true;
if (grass.instanceColor) grass.instanceColor.needsUpdate = true;
scene.add(grass);
// Scattered stones.
for (let i = 0; i < 13; i++) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.16 + random() * 0.25, 0),
rockMaterial
);
rock.position.set(
random() * 16 - 8,
0.1,
random() * 9.4 - 4.7
);
rock.scale.y = 0.55 + random() * 0.4;
rock.rotation.set(random(), random(), random());
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
// Fallen log and a lighter cut end.
const log = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.34, 3.4, 10),
barkMaterial
);
log.position.set(-3.45, 0.31, 4.15);
log.rotation.z = Math.PI / 2;
log.rotation.y = -0.08;
log.castShadow = true;
log.receiveShadow = true;
scene.add(log);
const logEnd = new THREE.Mesh(
new THREE.CircleGeometry(0.275, 16),
new THREE.MeshStandardMaterial({
color: 0xb5925d,
roughness: 1,
side: THREE.DoubleSide
})
);
logEnd.position.set(-1.755, 0.31, 4.15);
logEnd.rotation.y = Math.PI / 2;
scene.add(logEnd);
// Leaf litter.
const litterGeometry = new THREE.CircleGeometry(0.08, 5);
litterGeometry.rotateX(-Math.PI / 2);
const litterMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
vertexColors: true,
side: THREE.DoubleSide
});
const litter = new THREE.InstancedMesh(
litterGeometry,
litterMaterial,
65
);
for (let i = 0; i < 65; i++) {
dummy.position.set(
random() * 16.5 - 8.25,
0.045 + random() * 0.025,
random() * 9.5 - 4.75
);
dummy.rotation.set(
0,
random() * Math.PI * 2,
0
);
const scale = 0.55 + random() * 0.9;
dummy.scale.set(scale, 1, scale);
dummy.updateMatrix();
litter.setMatrixAt(i, dummy.matrix);
grassColor.set(
random() > 0.5 ? 0x8e6237 : 0xb08947
);
grassColor.multiplyScalar(0.75 + random() * 0.3);
litter.setColorAt(i, grassColor);
}
litter.instanceMatrix.needsUpdate = true;
if (litter.instanceColor) litter.instanceColor.needsUpdate = true;
scene.add(litter);
// A few shaded mushrooms.
const mushroomStemMaterial = new THREE.MeshStandardMaterial({
color: 0xd9cfad,
roughness: 1
});
const mushroomCapMaterial = new THREE.MeshStandardMaterial({
color: 0xb85e43,
roughness: 1,
flatShading: true
});
function addMushroom(x, z, scale) {
const group = new THREE.Group();
group.position.set(x, 0.03, z);
group.scale.setScalar(scale);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.055, 0.24, 7),
mushroomStemMaterial
);
stem.position.y = 0.12;
stem.castShadow = true;
group.add(stem);
const cap = new THREE.Mesh(
new THREE.SphereGeometry(
0.13,
10,
6,
0,
Math.PI * 2,
0,
Math.PI / 2
),
mushroomCapMaterial
);
cap.position.y = 0.23;
cap.scale.y = 0.8;
cap.castShadow = true;
group.add(cap);
scene.add(group);
}
addMushroom(-4.75, 3.45, 1);
addMushroom(-5.05, 3.7, 0.7);
addMushroom(5.45, 3.15, 0.9);
addMushroom(5.7, 3.42, 0.65);
// ------------------------------------------------------------
// Stylized shafts of light and floating dust
// ------------------------------------------------------------
const beamStart = new THREE.Vector3(-4.5, 13, 5.5);
const beamEnd = new THREE.Vector3(0.35, 0.08, 0.25);
const beamDirection = new THREE.Vector3().subVectors(
beamEnd,
beamStart
);
const beamLength = beamDirection.length();
const beamMaterial = new THREE.MeshBasicMaterial({
color: 0xffefaa,
transparent: true,
opacity: 0.055,
depthWrite: false,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending
});
const beam = new THREE.Mesh(
new THREE.CylinderGeometry(2.05, 0.38, beamLength, 24, 1, true),
beamMaterial
);
beam.position.copy(beamStart).add(beamEnd).multiplyScalar(0.5);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
beamDirection.normalize()
);
scene.add(beam);
const innerBeamMaterial = beamMaterial.clone();
innerBeamMaterial.opacity = 0.035;
const innerBeam = new THREE.Mesh(
new THREE.CylinderGeometry(1.18, 0.16, beamLength, 20, 1, true),
innerBeamMaterial
);
innerBeam.position.copy(beam.position);
innerBeam.quaternion.copy(beam.quaternion);
scene.add(innerBeam);
const moteCount = 85;
const motePositions = new Float32Array(moteCount * 3);
const moteOrigins = [];
for (let i = 0; i < moteCount; i++) {
const t = random();
const center = beamStart.clone().lerp(beamEnd, t);
const radius = THREE.MathUtils.lerp(0.25, 1.65, t);
const angle = random() * Math.PI * 2;
const radial = Math.sqrt(random()) * radius;
const origin = new THREE.Vector3(
center.x + Math.cos(angle) * radial,
center.y + (random() - 0.5) * 0.4,
center.z + Math.sin(angle) * radial
);
moteOrigins.push(origin);
motePositions[i * 3] = origin.x;
motePositions[i * 3 + 1] = origin.y;
motePositions[i * 3 + 2] = origin.z;
}
const moteGeometry = new THREE.BufferGeometry();
moteGeometry.setAttribute(
"position",
new THREE.BufferAttribute(motePositions, 3)
);
const motes = new THREE.Points(
moteGeometry,
new THREE.PointsMaterial({
color: 0xfff2b4,
size: 0.065,
transparent: true,
opacity: 0.72,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
scene.add(motes);
// ------------------------------------------------------------
// DOM label projected from the actual canopy opening
// ------------------------------------------------------------
const gapLabel = document.getElementById("gap-label");
const labelAnchor = new THREE.Vector3(0.25, 7.4, -0.5);
const projectedLabel = new THREE.Vector3();
function updateGapLabel() {
projectedLabel.copy(labelAnchor).project(camera);
const visible =
projectedLabel.z > -1 &&
projectedLabel.z < 1 &&
Math.abs(projectedLabel.x) < 1.2 &&
Math.abs(projectedLabel.y) < 1.2;
gapLabel.style.display = visible ? "block" : "none";
if (visible) {
const x = (projectedLabel.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projectedLabel.y * 0.5 + 0.5) * window.innerHeight;
gapLabel.style.left = `${x}px`;
gapLabel.style.top = `${y}px`;
}
}
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
controls.theta +=
(controls.desiredTheta - controls.theta) * 0.075;
controls.phi +=
(controls.desiredPhi - controls.phi) * 0.075;
controls.radius +=
(controls.desiredRadius - controls.radius) * 0.075;
updateCamera();
for (const item of swayables) {
item.object.rotation.z =
item.baseRotationZ +
Math.sin(elapsed * 0.52 + item.phase) * item.amount;
item.object.position.y =
item.baseY +
Math.sin(elapsed * 0.7 + item.phase) * 0.025;
}
for (const item of plantGroups) {
item.object.rotation.z =
item.baseRotationZ +
Math.sin(elapsed * 0.9 + item.phase) * item.amount;
}
beamMaterial.opacity = 0.05 + Math.sin(elapsed * 0.65) * 0.008;
innerBeamMaterial.opacity = 0.032 + Math.cos(elapsed * 0.53) * 0.006;
const positions = moteGeometry.attributes.position;
for (let i = 0; i < moteCount; i++) {
const origin = moteOrigins[i];
positions.setXYZ(
i,
origin.x + Math.sin(elapsed * 0.45 + i) * 0.055,
origin.y + Math.sin(elapsed * 0.7 + i * 0.4) * 0.12,
origin.z + Math.cos(elapsed * 0.38 + i) * 0.045
);
}
positions.needsUpdate = true;
updateGapLabel();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```