Prompt specification
Build or customize the Three.js 3D scene "Woodland cavity succession story" 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: Woodland cavity succession story
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/woodland-cavity-succession-story-x0719
Scene Description Prompt:
Animate a voxel woodland timeline: a woodpecker leaves a tree cavity, then another bird occupies it. Build standalone HTML with Three.js from cdnjs.
Working Three.js Starter (woodland-cavity-succession-story-x0719):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Woodland — A Change of Tenants</title>
<style>
:root {
--ink: #26362f;
--muted: #65766d;
--cream: #f6f1e5;
--panel: rgba(248, 244, 232, 0.88);
--line: rgba(38, 54, 47, 0.17);
--red: #d6533e;
--blue: #397fc3;
--green: #506d58;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9cbb8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.intro {
position: fixed;
top: clamp(22px, 4vw, 54px);
left: clamp(22px, 4vw, 58px);
z-index: 3;
width: min(430px, calc(100vw - 44px));
pointer-events: none;
text-shadow: 0 1px 18px rgba(246, 241, 229, 0.55);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
color: #42594d;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 31px;
height: 2px;
content: "";
background: var(--red);
}
h1 {
margin: 0;
color: #263a30;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(43px, 6vw, 82px);
font-weight: 500;
line-height: 0.92;
letter-spacing: -0.055em;
}
.intro p {
max-width: 350px;
margin: 18px 0 0;
color: #4f6559;
font-size: 14px;
line-height: 1.65;
}
.top-actions {
position: fixed;
top: clamp(20px, 3vw, 38px);
right: clamp(20px, 3vw, 38px);
z-index: 6;
display: flex;
gap: 10px;
}
.icon-button {
display: grid;
width: 42px;
height: 42px;
padding: 0;
place-items: center;
border: 1px solid var(--line);
border-radius: 50%;
background: rgba(248, 244, 232, 0.72);
box-shadow: 0 8px 30px rgba(34, 54, 43, 0.09);
cursor: pointer;
backdrop-filter: blur(10px);
transition:
transform 160ms ease,
background 160ms ease;
}
.icon-button:hover {
transform: translateY(-2px);
background: rgba(255, 252, 243, 0.94);
}
.icon-button svg {
width: 18px;
height: 18px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.8;
}
.chapter-card {
position: fixed;
top: 50%;
right: clamp(20px, 3vw, 38px);
z-index: 3;
width: 220px;
padding: 18px;
transform: translateY(-50%);
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(34, 54, 43, 0.12);
pointer-events: none;
backdrop-filter: blur(14px);
}
.chapter-number {
display: flex;
align-items: center;
justify-content: space-between;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.bird-key {
display: flex;
gap: 9px;
}
.bird-key span {
width: 7px;
height: 7px;
border-radius: 50%;
}
.bird-key .red {
background: var(--red);
}
.bird-key .blue {
background: var(--blue);
}
.chapter-card h2 {
margin: 17px 0 8px;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 500;
line-height: 1.08;
}
.chapter-card p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.camera-hint {
position: fixed;
right: clamp(20px, 3vw, 38px);
bottom: 174px;
z-index: 3;
color: rgba(38, 54, 47, 0.66);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.timeline-panel {
position: fixed;
right: clamp(16px, 3vw, 38px);
bottom: clamp(16px, 3vw, 32px);
left: clamp(16px, 3vw, 38px);
z-index: 5;
padding: 18px 20px 16px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 18px 65px rgba(34, 54, 43, 0.15);
backdrop-filter: blur(18px);
}
.timeline-top {
display: flex;
align-items: center;
gap: 16px;
}
.play-button {
display: grid;
flex: 0 0 auto;
width: 46px;
height: 46px;
padding: 0;
place-items: center;
border: 0;
border-radius: 50%;
background: var(--ink);
color: var(--cream);
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease;
}
.play-button:hover {
transform: scale(1.05);
background: #3c5145;
}
.play-button svg {
width: 17px;
height: 17px;
fill: currentColor;
}
.restart-button {
display: grid;
flex: 0 0 auto;
width: 38px;
height: 38px;
padding: 0;
place-items: center;
border: 1px solid var(--line);
border-radius: 50%;
background: transparent;
cursor: pointer;
}
.restart-button:hover {
background: rgba(38, 54, 47, 0.07);
}
.restart-button svg {
width: 15px;
height: 15px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.8;
}
.scrubber-wrap {
flex: 1;
min-width: 0;
}
#timeline {
--p: 0%;
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 999px;
outline: none;
background: linear-gradient(
to right,
var(--red) 0%,
var(--red) var(--p),
rgba(38, 54, 47, 0.16) var(--p),
rgba(38, 54, 47, 0.16) 100%
);
cursor: pointer;
}
#timeline::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 3px solid var(--cream);
border-radius: 50%;
background: var(--ink);
box-shadow: 0 1px 8px rgba(38, 54, 47, 0.25);
}
#timeline::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid var(--cream);
border-radius: 50%;
background: var(--ink);
box-shadow: 0 1px 8px rgba(38, 54, 47, 0.25);
}
.timecode {
flex: 0 0 auto;
color: var(--muted);
font-variant-numeric: tabular-nums;
font-size: 11px;
font-weight: 700;
}
.chapter-row {
display: grid;
grid-template-columns: repeat(5, 1fr);
margin: 14px 0 0 100px;
}
.chapter-button {
position: relative;
padding: 7px 4px 0;
border: 0;
background: transparent;
color: #7b887f;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.05em;
text-align: left;
text-transform: uppercase;
cursor: pointer;
transition: color 160ms ease;
}
.chapter-button::before {
position: absolute;
top: -8px;
left: 0;
width: 1px;
height: 7px;
content: "";
background: rgba(38, 54, 47, 0.24);
}
.chapter-button.active {
color: var(--ink);
}
.chapter-button.active::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--red);
transform: translateY(-1px);
}
@media (max-width: 760px) {
.intro {
top: 22px;
}
.intro p {
display: none;
}
.chapter-card {
top: auto;
right: 16px;
bottom: 164px;
width: 180px;
padding: 13px;
transform: none;
}
.chapter-card h2 {
margin-top: 10px;
font-size: 19px;
}
.chapter-card p {
display: none;
}
.camera-hint {
display: none;
}
.timeline-panel {
padding: 14px;
}
.timeline-top {
gap: 9px;
}
.restart-button {
display: none;
}
.chapter-row {
margin-left: 0;
}
.chapter-button {
overflow: hidden;
font-size: 8px;
text-overflow: ellipsis;
white-space: nowrap;
}
}
@media (max-width: 470px) {
h1 {
font-size: 43px;
}
.top-actions {
top: 20px;
right: 16px;
}
.icon-button {
width: 38px;
height: 38px;
}
.chapter-card {
display: none;
}
.timecode {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated voxel woodland scene"></canvas>
<header class="intro">
<div class="eyebrow">Voxel field notes · 06:40 AM</div>
<h1>A change<br>of tenants.</h1>
<p>
One small hollow in an old oak. Two very different birds.
Watch the woodland turn over its daily arrangement.
</p>
</header>
<div class="top-actions">
<button id="reset-view" class="icon-button" title="Reset camera" aria-label="Reset camera">
<svg viewBox="0 0 24 24">
<path d="M4 8V4h4"></path>
<path d="M5.2 5.2A9 9 0 1 1 3 12"></path>
</svg>
</button>
</div>
<aside class="chapter-card">
<div class="chapter-number">
<span id="chapter-index">01 / 05</span>
<span class="bird-key">
<span class="red"></span>
<span class="blue"></span>
</span>
</div>
<h2 id="chapter-title">The resident</h2>
<p id="chapter-description">
A red-crowned woodpecker holds the hollow.
</p>
</aside>
<div class="camera-hint">Drag to orbit · Scroll to zoom</div>
<section class="timeline-panel" aria-label="Animation timeline">
<div class="timeline-top">
<button id="play" class="play-button" aria-label="Pause animation">
<svg id="play-icon" viewBox="0 0 24 24">
<path d="M7 5h4v14H7zM13 5h4v14h-4z"></path>
</svg>
</button>
<button id="restart" class="restart-button" title="Restart" aria-label="Restart animation">
<svg viewBox="0 0 24 24">
<path d="M4 8V4h4"></path>
<path d="M5.2 5.2A9 9 0 1 1 3 12"></path>
</svg>
</button>
<div class="scrubber-wrap">
<input
id="timeline"
type="range"
min="0"
max="14.5"
step="0.01"
value="0"
aria-label="Timeline position"
>
</div>
<div id="timecode" class="timecode">00.0 / 14.5</div>
</div>
<nav class="chapter-row" aria-label="Timeline chapters">
<button class="chapter-button active" data-time="0">Resident</button>
<button class="chapter-button" data-time="1.4">Departure</button>
<button class="chapter-button" data-time="4.7">Vacant</button>
<button class="chapter-button" data-time="5.8">Arrival</button>
<button class="chapter-button" data-time="9.3">Occupied</button>
</nav>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and camera
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb9cbb8);
scene.fog = new THREE.Fog(0xb9cbb8, 14, 29);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(-0.35, 2.35, 0);
const cameraState = {
azimuth: 0.56,
polar: 1.13,
radius: 13.8
};
function updateCamera() {
const { azimuth, polar, radius } = cameraState;
const sinPolar = Math.sin(polar);
camera.position.set(
cameraTarget.x + radius * sinPolar * Math.sin(azimuth),
cameraTarget.y + radius * Math.cos(polar),
cameraTarget.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xe9f1dd, 0x53634e, 2.0));
const sun = new THREE.DirectionalLight(0xffe3ae, 3.4);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.0008;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9ec9d6, 0.65);
fill.position.set(8, 5, -7);
scene.add(fill);
// ------------------------------------------------------------
// Voxel construction helpers
// ------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
flatShading: true
})
);
}
return materialCache.get(color);
}
function addBox(
parent,
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0
) {
const mesh = new THREE.Mesh(cubeGeometry, getMaterial(color));
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value += 0x6d2b79f5;
let result = value;
result = Math.imul(result ^ (result >>> 15), result | 1);
result ^= result + Math.imul(result ^ (result >>> 7), result | 61);
return ((result ^ (result >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(20240640);
// ------------------------------------------------------------
// Ground island
// ------------------------------------------------------------
addBox(scene, 20.2, 1.15, 13.8, 0x655443, 0, -0.78, 0);
addBox(scene, 20.35, 0.28, 13.95, 0x596f4e, 0, -0.26, 0);
const columns = 36;
const rows = 24;
const cellSize = 0.55;
const groundCount = columns * rows;
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
});
const ground = new THREE.InstancedMesh(
cubeGeometry,
groundMaterial,
groundCount
);
ground.receiveShadow = true;
const dummy = new THREE.Object3D();
const grassColors = [
0x71895c,
0x789160,
0x829764,
0x6d8558,
0x8c9d6c,
0x758d5d
];
let instance = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = (column - (columns - 1) / 2) * cellSize;
const z = (row - (rows - 1) / 2) * cellSize;
const height = 0.28 + random() * 0.08;
dummy.position.set(x, -height / 2 + 0.01, z);
dummy.scale.set(cellSize * 0.985, height, cellSize * 0.985);
dummy.updateMatrix();
ground.setMatrixAt(instance, dummy.matrix);
ground.setColorAt(
instance,
new THREE.Color(
grassColors[Math.floor(random() * grassColors.length)]
)
);
instance++;
}
}
scene.add(ground);
// A short path of square stones leading toward the old tree.
const pathPoints = [
[3.7, 4.4],
[3.0, 3.4],
[2.3, 2.6],
[1.65, 1.8],
[1.05, 1.0],
[0.48, 0.25],
[-0.05, -0.45],
[-0.55, -1.1]
];
pathPoints.forEach(([x, z], index) => {
const stone = addBox(
scene,
0.55 + random() * 0.16,
0.09,
0.46 + random() * 0.13,
index % 2 ? 0xa39d83 : 0xb1aa8f,
x,
0.06,
z
);
stone.rotation.y = (random() - 0.5) * 0.16;
});
// ------------------------------------------------------------
// Main oak and cavity
// ------------------------------------------------------------
const treeX = -1.25;
const treeZ = -0.2;
const trunkWidth = 1.46;
const trunkDepth = 1.46;
const barkColors = [
0x715039,
0x79563d,
0x654a36,
0x815c41,
0x6f4d38
];
for (let i = 0; i < 11; i++) {
addBox(
scene,
trunkWidth + (random() - 0.5) * 0.07,
0.51,
trunkDepth + (random() - 0.5) * 0.07,
barkColors[i % barkColors.length],
treeX + (random() - 0.5) * 0.04,
0.25 + i * 0.5,
treeZ
);
}
// Branch to the resident's perch.
for (let i = 0; i < 6; i++) {
addBox(
scene,
0.55,
0.29,
0.42,
i % 2 ? 0x684832 : 0x76523a,
-1.55 - i * 0.43,
3.05 - i * 0.055,
-0.05 + i * 0.015
);
}
// Branch to the arriving bird.
for (let i = 0; i < 8; i++) {
addBox(
scene,
0.56,
0.28,
0.4,
i % 2 ? 0x694a35 : 0x77533b,
-0.7 + i * 0.53,
2.75 + i * 0.035,
-0.08 - i * 0.008
);
}
// Dark recess and chunky bark rim.
addBox(scene, 0.59, 0.76, 0.045, 0x201f1b, treeX, 3.43, 0.548);
addBox(scene, 0.19, 0.76, 0.13, 0x553b2c, treeX - 0.38, 3.43, 0.58);
addBox(scene, 0.19, 0.76, 0.13, 0x634530, treeX + 0.38, 3.43, 0.58);
addBox(scene, 0.82, 0.18, 0.13, 0x634530, treeX, 3.88, 0.58);
addBox(scene, 0.82, 0.18, 0.13, 0x523b2c, treeX, 2.98, 0.58);
// Main canopy.
const canopy = [
[-2.65, 5.25, -0.5, 1.35, 1.1, 1.25],
[-1.85, 5.8, -0.25, 1.6, 1.35, 1.4],
[-0.75, 5.75, -0.25, 1.45, 1.25, 1.35],
[0.15, 5.25, -0.45, 1.3, 1.1, 1.25],
[-2.45, 6.25, -0.6, 1.15, 1.05, 1.05],
[-1.25, 6.45, -0.45, 1.45, 1.15, 1.15],
[-0.1, 6.05, -0.55, 1.15, 1.0, 1.05],
[-3.15, 5.75, -0.75, 0.95, 0.95, 0.95],
[0.55, 5.85, -0.75, 1.05, 0.95, 1.0]
];
const leafColors = [
0x49683e,
0x557444,
0x627f4b,
0x3f6038,
0x6b874f
];
canopy.forEach(([x, y, z, w, h, d], index) => {
addBox(
scene,
w,
h,
d,
leafColors[index % leafColors.length],
x,
y,
z
);
});
// Small canopy overhangs near the branches.
addBox(scene, 1.2, 0.8, 1.15, 0x4d6d42, -3.25, 4.35, -0.25);
addBox(scene, 1.15, 0.8, 1.0, 0x5f7b49, 3.2, 4.1, -0.25);
// ------------------------------------------------------------
// Background woodland
// ------------------------------------------------------------
function addBackgroundTree(x, z, scale = 1) {
const trunkColor = x < 0 ? 0x604936 : 0x70503a;
for (let i = 0; i < 6; i++) {
addBox(
scene,
0.62 * scale,
0.58 * scale,
0.62 * scale,
i % 2 ? trunkColor : 0x76533b,
x,
0.29 * scale + i * 0.56 * scale,
z
);
}
const clusters = [
[0, 3.55, 0, 2.0, 1.4, 1.7],
[-0.85, 3.05, 0.05, 1.4, 1.3, 1.35],
[0.9, 3.15, -0.05, 1.5, 1.3, 1.35],
[-0.2, 4.45, -0.1, 1.35, 1.15, 1.3]
];
clusters.forEach((cluster, index) => {
addBox(
scene,
cluster[3] * scale,
cluster[4] * scale,
cluster[5] * scale,
leafColors[(index + Math.floor(random() * 3)) % leafColors.length],
x + cluster[0] * scale,
cluster[1] * scale,
z + cluster[2] * scale
);
});
}
addBackgroundTree(-6.4, -3.8, 1.18);
addBackgroundTree(-4.4, -4.9, 0.9);
addBackgroundTree(2.8, -4.6, 1.05);
addBackgroundTree(5.6, -3.4, 1.22);
addBackgroundTree(-7.2, 1.6, 0.95);
addBackgroundTree(6.7, 1.7, 0.88);
// Blocky clouds.
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xe8ead7,
roughness: 1,
transparent: true,
opacity: 0.72
});
function addCloud(x, y, z, scale = 1) {
const pieces = [
[-0.9, 0, 0, 1.25, 0.55, 0.65],
[0, 0.18, 0, 1.45, 0.78, 0.75],
[1.05, 0, 0.05, 1.05, 0.5, 0.6],
[0.35, -0.23, 0.12, 1.55, 0.42, 0.55]
];
pieces.forEach((piece) => {
const cloud = new THREE.Mesh(cubeGeometry, cloudMaterial);
cloud.scale.set(
piece[3] * scale,
piece[4] * scale,
piece[5] * scale
);
cloud.position.set(
x + piece[0] * scale,
y + piece[1] * scale,
z + piece[2] * scale
);
scene.add(cloud);
});
}
addCloud(-5.7, 8.2, -7.5, 1.15);
addCloud(3.4, 7.6, -8.5, 0.9);
addCloud(7.2, 9.1, -10, 1.25);
// A square morning sun.
const sunBlock = addBox(scene, 1.15, 1.15, 0.35, 0xf2c879, -7.6, 7.1, -7.4);
sunBlock.castShadow = false;
// ------------------------------------------------------------
// Ground details
// ------------------------------------------------------------
function addMushroom(x, z, scale = 1) {
addBox(
scene,
0.12 * scale,
0.35 * scale,
0.12 * scale,
0xe2d4ad,
x,
0.17 * scale,
z
);
addBox(
scene,
0.42 * scale,
0.16 * scale,
0.38 * scale,
0xc84f3d,
x,
0.39 * scale,
z
);
addBox(
scene,
0.24 * scale,
0.06 * scale,
0.22 * scale,
0xf0d8ba,
x + 0.04 * scale,
0.49 * scale,
z
);
}
function addRock(x, z, scale = 1) {
addBox(
scene,
0.62 * scale,
0.35 * scale,
0.47 * scale,
0x777b70,
x,
0.16 * scale,
z
);
addBox(
scene,
0.34 * scale,
0.25 * scale,
0.31 * scale,
0x85887d,
x + 0.2 * scale,
0.12 * scale,
z + 0.04 * scale
);
}
addMushroom(-3.25, 1.85, 1.0);
addMushroom(-3.55, 1.55, 0.72);
addMushroom(4.55, -1.2, 0.95);
addMushroom(4.8, -1.05, 0.64);
addRock(-4.85, -1.4, 1.2);
addRock(2.25, -2.55, 0.9);
addRock(5.65, 2.8, 0.75);
// Instanced grass blades.
const bladeCount = 180;
const blades = new THREE.InstancedMesh(
cubeGeometry,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
}),
bladeCount
);
for (let i = 0; i < bladeCount; i++) {
const x = (random() - 0.5) * 18.5;
const z = (random() - 0.5) * 12.2;
const height = 0.12 + random() * 0.24;
const width = 0.035 + random() * 0.035;
dummy.position.set(x, height / 2, z);
dummy.scale.set(width, height, width);
dummy.rotation.set(0, random() * Math.PI, 0);
dummy.updateMatrix();
blades.setMatrixAt(i, dummy.matrix);
blades.setColorAt(
i,
new THREE.Color(
random() > 0.5 ? 0x9caf72 : 0x839c62
)
);
}
blades.receiveShadow = true;
scene.add(blades);
// Tiny flowers.
const flowerColors = [0xf1d477, 0xe9e3cc, 0xd98272];
for (let i = 0; i < 20; i++) {
const x = (random() - 0.5) * 17;
const z = (random() - 0.5) * 11;
const height = 0.2 + random() * 0.15;
addBox(scene, 0.035, height, 0.035, 0x668453, x, height / 2, z);
addBox(
scene,
0.12,
0.09,
0.12,
flowerColors[i % flowerColors.length],
x,
height,
z
);
}
// ------------------------------------------------------------
// Floating pollen
// ------------------------------------------------------------
const moteCount = 55;
const motePositions = new Float32Array(moteCount * 3);
const moteBase = [];
for (let i = 0; i < moteCount; i++) {
const x = (random() - 0.5) * 15;
const y = 0.5 + random() * 5.5;
const z = (random() - 0.5) * 10;
moteBase.push({ x, y, z, phase: random() * Math.PI * 2 });
motePositions[i * 3] = x;
motePositions[i * 3 + 1] = y;
motePositions[i * 3 + 2] = z;
}
const moteGeometry = new THREE.BufferGeometry();
moteGeometry.setAttribute(
"position",
new THREE.BufferAttribute(motePositions, 3)
);
const motes = new THREE.Points(
moteGeometry,
new THREE.PointsMaterial({
color: 0xfff3b0,
size: 0.075,
transparent: true,
opacity: 0.72,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(motes);
// ------------------------------------------------------------
// Voxel birds
// Local forward direction is +Z.
// ------------------------------------------------------------
function createBird(kind) {
const root = new THREE.Group();
const isWoodpecker = kind === "woodpecker";
const bodyColor = isWoodpecker ? 0xd34c39 : 0x397fc3;
const headColor = isWoodpecker ? 0x303536 : 0x55a7df;
const wingColor = isWoodpecker ? 0x30383a : 0x285b92;
const chestColor = isWoodpecker ? 0xeee4c8 : 0xeea346;
const beakColor = isWoodpecker ? 0xe6d9b5 : 0x263b42;
addBox(root, 0.35, 0.46, 0.3, bodyColor, 0, 0, 0);
addBox(root, 0.27, 0.29, 0.075, chestColor, 0, -0.015, 0.165);
addBox(root, 0.3, 0.3, 0.3, headColor, 0, 0.32, 0.035);
addBox(root, 0.17, 0.105, 0.27, beakColor, 0, 0.3, 0.29);
// Eyes.
addBox(root, 0.055, 0.06, 0.045, 0x151b1a, -0.09, 0.38, 0.185);
addBox(root, 0.055, 0.06, 0.045, 0x151b1a, 0.09, 0.38, 0.185);
// White cheek marks on the woodpecker.
if (isWoodpecker) {
addBox(root, 0.045, 0.15, 0.055, 0xf2ead5, -0.155, 0.29, 0.04);
addBox(root, 0.045, 0.15, 0.055, 0xf2ead5, 0.155, 0.29, 0.04);
// Red crest.
addBox(root, 0.11, 0.19, 0.13, 0xe14332, -0.09, 0.56, 0.025);
addBox(root, 0.12, 0.25, 0.14, 0xd9372c, 0, 0.59, 0.025);
addBox(root, 0.1, 0.17, 0.12, 0xe14332, 0.09, 0.55, 0.025);
} else {
addBox(root, 0.09, 0.13, 0.09, 0x286fb1, -0.08, 0.51, 0.02);
addBox(root, 0.09, 0.12, 0.09, 0x286fb1, 0.08, 0.5, 0.02);
}
// Tail feathers.
addBox(root, 0.08, 0.28, 0.28, wingColor, -0.08, -0.19, -0.24);
addBox(root, 0.08, 0.3, 0.3, wingColor, 0, -0.2, -0.27);
addBox(root, 0.08, 0.26, 0.26, wingColor, 0.08, -0.18, -0.23);
// Wing pivots.
const leftWing = new THREE.Group();
const rightWing = new THREE.Group();
leftWing.position.set(-0.19, 0.1, -0.015);
rightWing.position.set(0.19, 0.1, -0.015);
addBox(leftWing, 0.13, 0.36, 0.35, wingColor, -0.085, -0.025, -0.025);
addBox(rightWing, 0.13, 0.36, 0.35, wingColor, 0.085, -0.025, -0.025);
root.add(leftWing, rightWing);
// Tiny feet.
addBox(root, 0.055, 0.12, 0.055, 0x9a7444, -0.1, -0.28, 0.025);
addBox(root, 0.055, 0.12, 0.055, 0x9a7444, 0.1, -0.28, 0.025);
root.userData.leftWing = leftWing;
root.userData.rightWing = rightWing;
root.rotation.order = "YXZ";
scene.add(root);
return root;
}
const woodpecker = createBird("woodpecker");
const bluebird = createBird("bluebird");
// ------------------------------------------------------------
// Timeline animation
// ------------------------------------------------------------
const DURATION = 14.5;
const HOLE = new THREE.Vector3(treeX, 3.43, 0.69);
const LEFT_PERCH = new THREE.Vector3(-3.62, 3.35, 0.015);
const RIGHT_PERCH = new THREE.Vector3(3.52, 3.12, -0.13);
const woodFlight = {
p0: HOLE.clone(),
p1: new THREE.Vector3(-1.2, 4.35, 2.65),
p2: new THREE.Vector3(-3.15, 4.05, 0.92),
p3: LEFT_PERCH.clone()
};
const blueFlight = {
p0: RIGHT_PERCH.clone(),
p1: new THREE.Vector3(3.7, 4.65, 2.0),
p2: new THREE.Vector3(0.05, 4.65, 2.65),
p3: HOLE.clone()
};
function cubicBezier(out, p0, p1, p2, p3, t) {
const inverse = 1 - t;
const inverse2 = inverse * inverse;
const t2 = t * t;
out.set(
inverse2 * inverse * p0.x +
3 * inverse2 * t * p1.x +
3 * inverse * t2 * p2.x +
t2 * t * p3.x,
inverse2 * inverse * p0.y +
3 * inverse2 * t * p1.y +
3 * inverse * t2 * p2.y +
t2 * t * p3.y,
inverse2 * inverse * p0.z +
3 * inverse2 * t * p1.z +
3 * inverse * t2 * p2.z +
t2 * t * p3.z
);
return out;
}
function cubicTangent(out, p0, p1, p2, p3, t) {
const inverse = 1 - t;
const inverse2 = inverse * inverse;
const t2 = t * t;
out.set(
3 * inverse2 * (p1.x - p0.x) +
6 * inverse * t * (p2.x - p1.x) +
3 * t2 * (p3.x - p2.x),
3 * inverse2 * (p1.y - p0.y) +
6 * inverse * t * (p2.y - p1.y) +
3 * t2 * (p3.y - p2.y),
3 * inverse2 * (p1.z - p0.z) +
6 * inverse * t * (p2.z - p1.z) +
3 * t2 * (p3.z - p2.z)
).normalize();
return out;
}
function smoothstep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function lerpAngle(a, b, t) {
const difference = Math.atan2(Math.sin(b - a), Math.cos(b - a));
return a + difference * t;
}
function setFlightOrientation(bird, tangent, targetYaw, turnStart = 0.78) {
const horizontal = Math.hypot(tangent.x, tangent.z);
const yaw = Math.atan2(tangent.x, tangent.z);
const pitch = -Math.atan2(tangent.y, horizontal);
bird.rotation.y = yaw;
bird.rotation.x = pitch;
bird.rotation.z = THREE.MathUtils.clamp(tangent.x * 0.1, -0.13, 0.13);
if (turnStart > 0) {
const turn = smoothstep((turnStart - 0.78) / 0.22);
bird.rotation.y = lerpAngle(yaw, targetYaw, turn);
bird.rotation.z *= 1 - turn;
}
}
function setWings(bird, amount) {
const flap = Math.sin(amount * 17.5) * 0.88;
const lift = 0.08 + Math.max(0, flap) * 0.9;
const lower = 0.08 + Math.max(0, -flap) * 0.72;
bird.userData.leftWing.rotation.z = -lift;
bird.userData.rightWing.rotation.z = lift;
bird.userData.leftWing.rotation.x = -0.08 + Math.abs(flap) * 0.06;
bird.userData.rightWing.rotation.x = -0.08 + Math.abs(flap) * 0.06;
}
const position = new THREE.Vector3();
const tangent = new THREE.Vector3();
function updateBirds(time) {
// Woodpecker: hollow → departure → left branch.
if (time < 1.4) {
woodpecker.position.copy(HOLE);
woodpecker.position.y += Math.sin(time * 7) * 0.012;
woodpecker.rotation.set(0, 0, 0);
setWings(woodpecker, 0);
} else if (time < 4.7) {
const raw = (time - 1.4) / 3.3;
const u = smoothstep(raw);
cubicBezier(
position,
woodFlight.p0,
woodFlight.p1,
woodFlight.p2,
woodFlight.p3,
u
);
cubicTangent(
tangent,
woodFlight.p0,
woodFlight.p1,
woodFlight.p2,
woodFlight.p3,
u
);
woodpecker.position.copy(position);
setFlightOrientation(woodpecker, tangent, Math.PI / 2, 0.78);
setWings(woodpecker, time);
} else {
woodpecker.position.copy(LEFT_PERCH);
woodpecker.position.y += Math.sin(time * 4) * 0.008;
woodpecker.rotation.set(0, Math.PI / 2, 0);
setWings(woodpecker, 0);
}
// Bluebird: waiting branch → approach → hollow.
if (time < 5.8) {
bluebird.position.copy(RIGHT_PERCH);
bluebird.position.y += Math.sin(time * 5 + 1) * 0.012;
bluebird.rotation.set(0, -Math.PI / 2, 0);
setWings(bluebird, 0);
} else if (time < 9.3) {
const raw = (time - 5.8) / 3.5;
const u = smoothstep(raw);
cubicBezier(
position,
blueFlight.p0,
blueFlight.p1,
blueFlight.p2,
blueFlight.p3,
u
);
cubicTangent(
tangent,
blueFlight.p0,
blueFlight.p1,
blueFlight.p2,
blueFlight.p3,
u
);
bluebird.position.copy(position);
setFlightOrientation(bluebird, tangent, 0, 0.8);
setWings(bluebird, time + 2.3);
} else {
bluebird.position.copy(HOLE);
bluebird.position.y += Math.sin(time * 6) * 0.01;
bluebird.rotation.set(0, 0, 0);
setWings(bluebird, 0);
}
}
// ------------------------------------------------------------
// Timeline UI
// ------------------------------------------------------------
const timelineInput = document.querySelector("#timeline");
const playButton = document.querySelector("#play");
const playIcon = document.querySelector("#play-icon");
const restartButton = document.querySelector("#restart");
const timecode = document.querySelector("#timecode");
const chapterIndex = document.querySelector("#chapter-index");
const chapterTitle = document.querySelector("#chapter-title");
const chapterDescription = document.querySelector("#chapter-description");
const chapterButtons = [...document.querySelectorAll(".chapter-button")];
const chapters = [
{
start: 0,
title: "The resident",
description: "A red-crowned woodpecker holds the hollow."
},
{
start: 1.4,
title: "A sudden departure",
description: "Wings beat. The old tenant leaves the tree."
},
{
start: 4.7,
title: "An open hollow",
description: "For a moment, the cavity belongs to no one."
},
{
start: 5.8,
title: "A bluebird approaches",
description: "A second bird crosses the clearing toward the opening."
},
{
start: 9.3,
title: "A new occupant",
description: "The bluebird settles into the old woodpecker’s hollow."
}
];
let timelineTime = 0;
let playing = true;
let activeChapter = -1;
const pauseIcon = `
<svg viewBox="0 0 24 24">
<path d="M7 5h4v14H7zM13 5h4v14h-4z"></path>
</svg>
`;
const playIconMarkup = `
<svg viewBox="0 0 24 24">
<path d="M8 5v14l11-7z"></path>
</svg>
`;
function setPlaying(value) {
playing = value;
playButton.innerHTML = value ? pauseIcon : playIconMarkup;
playButton.setAttribute(
"aria-label",
value ? "Pause animation" : "Play animation"
);
}
function getChapter(time) {
let index = 0;
for (let i = 0; i < chapters.length; i++) {
if (time >= chapters[i].start) {
index = i;
}
}
return index;
}
function updateTimelineUI() {
timelineInput.value = timelineTime.toFixed(2);
timelineInput.style.setProperty(
"--p",
`${(timelineTime / DURATION) * 100}%`
);
timecode.textContent = `${timelineTime.toFixed(1).padStart(4, "0")} / ${DURATION.toFixed(1)}`;
const index = getChapter(timelineTime);
if (index !== activeChapter) {
activeChapter = index;
const chapter = chapters[index];
chapterIndex.textContent = `${String(index + 1).padStart(2, "0")} / 05`;
chapterTitle.textContent = chapter.title;
chapterDescription.textContent = chapter.description;
chapterButtons.forEach((button, buttonIndex) => {
button.classList.toggle("active", buttonIndex === index);
});
}
}
playButton.addEventListener("click", () => {
setPlaying(!playing);
});
restartButton.addEventListener("click", () => {
timelineTime = 0;
setPlaying(true);
updateTimelineUI();
});
timelineInput.addEventListener("input", (event) => {
timelineTime = Number(event.target.value);
updateTimelineUI();
});
chapterButtons.forEach((button) => {
button.addEventListener("click", () => {
timelineTime = Number(button.dataset.time);
setPlaying(false);
updateTimelineUI();
});
});
// ------------------------------------------------------------
// Direct camera controls — no external controls addon
// ------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) {
return;
}
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.azimuth -= deltaX * 0.005;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + deltaY * 0.004,
0.55,
1.36
);
updateCamera();
});
function stopDragging(event) {
if (!dragging) {
return;
}
dragging = false;
canvas.classList.remove("dragging");
if (pointerId !== null && canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
pointerId = null;
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("lostpointercapture", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
8,
19
);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
cameraState.azimuth = 0.56;
cameraState.polar = 1.13;
cameraState.radius = 13.8;
updateCamera();
}
document.querySelector("#reset-view").addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
setPlaying(!playing);
}
if (event.key === "ArrowLeft") {
cameraState.azimuth -= 0.08;
}
if (event.key === "ArrowRight") {
cameraState.azimuth += 0.08;
}
if (event.key === "ArrowUp") {
cameraState.polar = Math.max(0.55, cameraState.polar - 0.05);
}
if (event.key === "ArrowDown") {
cameraState.polar = Math.min(1.36, cameraState.polar + 0.05);
}
if (event.key === "+" || event.key === "=") {
cameraState.radius = Math.max(8, cameraState.radius - 0.5);
}
if (event.key === "-" || event.key === "_") {
cameraState.radius = Math.min(19, cameraState.radius + 0.5);
}
updateCamera();
});
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (playing) {
timelineTime += delta;
if (timelineTime >= DURATION) {
timelineTime %= DURATION;
}
}
updateBirds(timelineTime);
updateTimelineUI();
// Gentle pollen drift.
const positions = moteGeometry.attributes.position.array;
for (let i = 0; i < moteCount; i++) {
const base = moteBase[i];
positions[i * 3] =
base.x + Math.sin(elapsed * 0.28 + base.phase) * 0.34;
positions[i * 3 + 1] =
base.y + Math.sin(elapsed * 0.42 + base.phase * 1.7) * 0.22;
positions[i * 3 + 2] =
base.z + Math.cos(elapsed * 0.24 + base.phase) * 0.28;
}
moteGeometry.attributes.position.needsUpdate = true;
renderer.render(scene, camera);
}
updateTimelineUI();
animate();
</script>
</body>
</html>
```