Prompt specification
Build or customize the Three.js 3D scene "Woodland autumn caching scene" 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 autumn caching scene
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/woodland-autumn-caching-scene-x0715
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring squirrel food caches. Compose oak tree, fallen leaves, logs, and several cache locations; squirrels follow varied paths while a time slider reveals some remaining seeds beginning simplified germination. Stylized solid forms.
Working Three.js Starter (woodland-autumn-caching-scene-x0715):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Squirrel Cache Study — Three.js</title>
<style>
:root {
--ink: #26332b;
--muted: #657168;
--paper: rgba(250, 247, 236, 0.9);
--line: rgba(50, 67, 54, 0.18);
--green: #52724b;
--green-dark: #35513a;
--gold: #bd873d;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce5dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene.dragging { cursor: grabbing; }
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 44%, transparent 45%, rgba(25, 39, 30, 0.12) 100%);
}
.panel {
position: fixed;
z-index: 5;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.65);
box-shadow:
0 18px 50px rgba(39, 55, 43, 0.14),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 20px 22px 18px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 4px rgba(189, 135, 61, 0.13);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3.2vw, 40px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.intro p {
margin: 12px 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.38);
color: #536056;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--gold);
}
.dot.seed { background: #8a5e31; }
.dot.sprout { background: #6b9d55; }
.dot.route { background: #71806d; }
.tools {
top: 22px;
right: 22px;
display: flex;
align-items: center;
gap: 10px;
}
.hint {
padding: 9px 12px;
border-radius: 999px;
color: #58645b;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
}
button {
border: 0;
font: inherit;
cursor: pointer;
}
.icon-button {
display: grid;
place-items: center;
width: 40px;
height: 40px;
border-radius: 50%;
background: var(--paper);
color: var(--green-dark);
box-shadow:
0 10px 28px rgba(39, 55, 43, 0.13),
inset 0 0 0 1px var(--line);
font-size: 19px;
transition: transform 160ms ease, background 160ms ease;
}
.icon-button:hover {
transform: translateY(-2px);
background: #fffdf5;
}
.timeline-panel {
left: 50%;
bottom: 22px;
width: min(690px, calc(100vw - 44px));
padding: 15px 17px 13px;
border-radius: 18px;
transform: translateX(-50%);
}
.timeline-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 11px;
}
.timeline-title {
display: flex;
align-items: baseline;
gap: 9px;
}
.timeline-title strong {
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.timeline-title span {
color: var(--muted);
font-size: 11px;
}
.timeline-meta {
display: flex;
align-items: center;
gap: 9px;
white-space: nowrap;
}
#seed-count {
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
#day-output {
min-width: 48px;
color: var(--green-dark);
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
text-align: right;
}
.timeline-row {
display: flex;
align-items: center;
gap: 13px;
}
#play {
flex: 0 0 auto;
display: grid;
place-items: center;
width: 35px;
height: 35px;
border-radius: 50%;
background: var(--green);
color: white;
font-size: 13px;
transition: transform 150ms ease, background 150ms ease;
}
#play:hover {
transform: scale(1.06);
background: var(--green-dark);
}
.range-wrap {
position: relative;
flex: 1;
}
input[type="range"] {
--p: 0%;
display: block;
width: 100%;
height: 20px;
margin: 0;
appearance: none;
-webkit-appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 6px;
border-radius: 999px;
background: linear-gradient(
to right,
var(--gold) 0%,
var(--gold) var(--p),
rgba(67, 84, 70, 0.16) var(--p),
rgba(67, 84, 70, 0.16) 100%
);
}
input[type="range"]::-moz-range-track {
height: 6px;
border-radius: 999px;
background: rgba(67, 84, 70, 0.16);
}
input[type="range"]::-moz-range-progress {
height: 6px;
border-radius: 999px;
background: var(--gold);
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
margin-top: -6px;
appearance: none;
-webkit-appearance: none;
border: 3px solid #fffdf5;
border-radius: 50%;
background: var(--green);
box-shadow: 0 2px 8px rgba(35, 50, 39, 0.28);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid #fffdf5;
border-radius: 50%;
background: var(--green);
box-shadow: 0 2px 8px rgba(35, 50, 39, 0.28);
}
.stage-label {
display: flex;
justify-content: space-between;
margin: 7px 48px 0;
color: #7a827a;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
#status {
position: fixed;
z-index: 4;
left: 50%;
bottom: 142px;
padding: 7px 11px;
border-radius: 999px;
background: rgba(249, 246, 234, 0.74);
color: #667066;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
transform: translateX(-50%);
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 700px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 78px);
padding: 15px 16px;
}
.intro p, .legend { display: none; }
.tools { top: 12px; right: 12px; }
.hint { display: none; }
.timeline-panel {
bottom: 12px;
width: calc(100vw - 24px);
padding: 13px 14px 11px;
}
.timeline-title span, #seed-count { display: none; }
#status { bottom: 128px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive stylized woodland with squirrels and seed caches"></canvas>
<div class="vignette"></div>
<section class="panel intro">
<div class="eyebrow">Oak Woodland Field Study</div>
<h1>Squirrel Cache</h1>
<p>
Five squirrels patrol overlapping routes through an old oak grove.
Scrub the calendar to follow the stores from winter cache to spring shoot.
</p>
<div class="legend">
<span><i class="dot seed"></i>Stored acorn</span>
<span><i class="dot sprout"></i>Germination</span>
<span><i class="dot route"></i>Moving route</span>
</div>
</section>
<div class="tools">
<div class="panel hint">Drag to orbit · Scroll to zoom</div>
<button class="icon-button" id="reset-view" title="Reset camera" aria-label="Reset camera">↺</button>
</div>
<div id="status">Winter stores intact</div>
<section class="panel timeline-panel" aria-label="Season timeline">
<div class="timeline-head">
<div class="timeline-title">
<strong>Cache Calendar</strong>
<span>Late winter → spring</span>
</div>
<div class="timeline-meta">
<span id="seed-count">40 seeds remain</span>
<output id="day-output" for="timeline">Day 0</output>
</div>
</div>
<div class="timeline-row">
<button id="play" aria-label="Play timeline">▶</button>
<div class="range-wrap">
<input
id="timeline"
type="range"
min="0"
max="60"
step="1"
value="0"
aria-label="Season day"
>
</div>
</div>
<div class="stage-label">
<span>Cache</span>
<span>Foraging</span>
<span>Germination</span>
</div>
</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 scene
// ---------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce5dc);
scene.fog = new THREE.Fog(0xdce5dc, 15, 34);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
70
);
// Direct camera controls: no addons are used.
const cameraTarget = new THREE.Vector3(0, 1.55, 0);
const cameraSpherical = new THREE.Spherical(13.6, 1.08, 0.72);
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
camera.position.setFromSpherical(cameraSpherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraTarget.set(0, 1.55, 0);
cameraSpherical.set(13.6, 1.08, 0.72);
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraSpherical.theta -= dx * 0.006;
cameraSpherical.phi = THREE.MathUtils.clamp(
cameraSpherical.phi - dy * 0.005,
0.28,
Math.PI / 2.04
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraSpherical.radius = THREE.MathUtils.clamp(
cameraSpherical.radius * Math.exp(event.deltaY * 0.001),
6.2,
23
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#reset-view").addEventListener("click", resetCamera);
updateCamera();
// ---------------------------------------------------------------------
// Lighting and material palette
// ---------------------------------------------------------------------
const hemi = new THREE.HemisphereLight(0xf7f1d7, 0x53634d, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe6b8, 3.1);
sun.position.set(-7, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfd8cf, 0.75);
fill.position.set(8, 5, -9);
scene.add(fill);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0,
flatShading: true,
...options
});
const mat = {
ground: material(0x738263),
earth: material(0x5d5840),
moss: material(0x6f8052),
bark: material(0x6b4932),
barkLight: material(0x855b3a),
cutWood: material(0xc29a67),
trunk: material(0x684831),
canopy: [
material(0x486849),
material(0x557850),
material(0x66885a),
material(0x3f6247)
],
acorn: material(0x9b6634),
cap: material(0x62452d),
stem: material(0x62452d),
sprout: material(0x67984d),
leaf: material(0x75954c),
stone: material(0x8b8e7d),
stoneDark: material(0x686e62)
};
// ---------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------
let randomSeed = 49271;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const range = (min, max) => min + (max - min) * random();
const choose = (items) => items[Math.floor(random() * items.length)];
function addMesh(parent, geometry, surface, position, scale) {
const mesh = new THREE.Mesh(geometry, surface);
if (position) mesh.position.set(...position);
if (scale) mesh.scale.set(...scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(parent, a, b, bottomRadius, topRadius, surface, sides = 8) {
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(
new THREE.CylinderGeometry(topRadius, bottomRadius, length, sides),
surface
);
mesh.position.copy(start).add(end).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;
}
function leafGeometry() {
const shape = new THREE.Shape();
shape.moveTo(0, -0.24);
shape.bezierCurveTo(0.17, -0.12, 0.19, 0.12, 0, 0.27);
shape.bezierCurveTo(-0.19, 0.12, -0.17, -0.12, 0, -0.24);
return new THREE.ShapeGeometry(shape, 5);
}
const sharedLeafGeometry = leafGeometry();
// ---------------------------------------------------------------------
// Diorama ground
// ---------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.CylinderGeometry(12, 12.35, 0.7, 64),
[mat.earth, mat.ground, mat.earth]
);
ground.position.y = -0.38;
ground.receiveShadow = true;
scene.add(ground);
// Soft moss islands.
for (let i = 0; i < 12; i++) {
const patch = new THREE.Mesh(
new THREE.CircleGeometry(range(0.45, 1.45), 18),
mat.moss
);
patch.rotation.x = -Math.PI / 2;
patch.position.set(range(-9.5, 9.5), 0.012, range(-9.5, 9.5));
patch.scale.set(range(1, 1.8), range(0.55, 1), 1);
patch.receiveShadow = true;
scene.add(patch);
}
// Fallen leaves, with denser piles around some caches.
const leafColors = [0xb56b35, 0xc2853e, 0x8e6935, 0x9a4e2d, 0xd29a49];
const leafMaterials = leafColors.map((color) => material(color));
function addLeaf(parent, x, z, size = 1) {
const leaf = new THREE.Mesh(sharedLeafGeometry, choose(leafMaterials));
leaf.rotation.x = -Math.PI / 2;
leaf.rotation.z = range(0, Math.PI * 2);
leaf.position.set(x, range(0.02, 0.045), z);
leaf.scale.setScalar(size * range(0.65, 1.15));
leaf.receiveShadow = true;
parent.add(leaf);
}
for (let i = 0; i < 115; i++) {
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random()) * 10.8;
addLeaf(scene, Math.cos(angle) * radius, Math.sin(angle) * radius, range(0.65, 1.1));
}
// ---------------------------------------------------------------------
// Large oak tree
// ---------------------------------------------------------------------
const tree = new THREE.Group();
tree.position.set(-1.25, 0, -0.75);
scene.add(tree);
addMesh(
tree,
new THREE.CylinderGeometry(0.48, 0.86, 4.65, 9),
mat.trunk,
[0, 2.28, 0],
[1, 1, 0.92]
);
// Main branching structure.
const branches = [
[[0.05, 3.0, 0], [-1.5, 4.45, 0.2], 0.27, 0.11],
[[0.05, 3.35, 0], [1.55, 4.6, -0.25], 0.3, 0.1],
[[-0.1, 3.6, 0], [-0.35, 5.0, -1.35], 0.22, 0.08],
[[0.0, 3.8, 0], [0.55, 5.1, 1.3], 0.2, 0.07],
[[-1.45, 4.4, 0.2], [-2.25, 5.25, 0.7], 0.13, 0.05],
[[1.45, 4.5, -0.2], [2.25, 5.2, -0.8], 0.13, 0.05]
];
for (const [a, b, r1, r2] of branches) {
cylinderBetween(tree, a, b, r1, r2, mat.bark, 7);
}
// Exposed roots.
const roots = [
[[0.25, 0.65, 0], [2.35, 0.06, 0.55]],
[[-0.15, 0.58, 0.05], [-2.1, 0.05, 0.3]],
[[0.0, 0.52, -0.1], [0.2, 0.05, -2.15]],
[[0.0, 0.48, 0.05], [-1.45, 0.05, -1.55]]
];
for (const [a, b] of roots) {
cylinderBetween(tree, a, b, 0.3, 0.09, mat.bark, 7);
}
// Broad, clustered stylized crown.
const crown = [
[[-1.8, 5.25, 0.25], 1.8, 1.45, 1.6],
[[0.3, 5.65, -0.35], 2.25, 1.55, 1.8],
[[1.95, 5.3, -0.55], 1.7, 1.35, 1.55],
[[-0.75, 6.35, 0.15], 1.75, 1.25, 1.55],
[[0.95, 6.1, 0.75], 1.55, 1.2, 1.4],
[[-0.1, 5.1, 1.7], 1.55, 1.25, 1.25],
[[-0.15, 5.0, -1.8], 1.5, 1.2, 1.25]
];
for (let i = 0; i < crown.length; i++) {
const [position, sx, sy, sz] = crown[i];
addMesh(
tree,
new THREE.IcosahedronGeometry(1, 1),
mat.canopy[i % mat.canopy.length],
position,
[sx, sy, sz]
);
}
// A few acorns still hanging from the oak.
function createAcorn(scale = 1) {
const group = new THREE.Group();
addMesh(
group,
new THREE.SphereGeometry(0.16, 8, 6),
mat.acorn,
[0, 0, 0],
[0.92, 1.25, 0.92]
);
addMesh(
group,
new THREE.CylinderGeometry(0.19, 0.145, 0.12, 8),
mat.cap,
[0, 0.17, 0]
);
addMesh(
group,
new THREE.CylinderGeometry(0.025, 0.035, 0.15, 6),
mat.stem,
[0, 0.29, 0]
);
group.scale.setScalar(scale);
return group;
}
const hangingAcorns = [
[-2.05, 4.55, 0.65],
[-1.9, 4.4, 0.9],
[2.05, 4.75, -0.75],
[2.15, 4.65, -0.95],
[0.25, 4.9, -1.55]
];
for (const position of hangingAcorns) {
const acorn = createAcorn(0.68);
acorn.position.set(...position);
acorn.rotation.z = range(-0.22, 0.22);
tree.add(acorn);
}
// ---------------------------------------------------------------------
// Fallen logs
// ---------------------------------------------------------------------
function createLog(position, length, radius, rotationY) {
const group = new THREE.Group();
group.position.set(...position);
group.rotation.y = rotationY;
const logMesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius * 0.9, radius, length, 11),
[mat.bark, mat.cutWood, mat.cutWood]
);
logMesh.rotation.z = Math.PI / 2;
logMesh.castShadow = true;
logMesh.receiveShadow = true;
group.add(logMesh);
// End-grain ring.
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius * 0.57, radius * 0.055, 5, 16),
mat.barkLight
);
ring.position.x = length * 0.505;
ring.rotation.y = Math.PI / 2;
group.add(ring);
cylinderBetween(
group,
[-0.2, radius * 0.65, 0],
[0.75, radius * 1.35, 0.3],
radius * 0.25,
radius * 0.12,
mat.bark,
7
);
scene.add(group);
return group;
}
createLog([4.25, 0.43, -2.1], 3.7, 0.48, -0.26);
createLog([-4.45, 0.3, 3.1], 2.65, 0.34, 0.52);
// ---------------------------------------------------------------------
// Grass, stones, and mushrooms
// ---------------------------------------------------------------------
const grassMaterials = [
material(0x607b47),
material(0x789052),
material(0x4f6b42)
];
for (let i = 0; i < 48; i++) {
const angle = random() * Math.PI * 2;
const radius = range(2.5, 10.8);
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
for (let j = 0; j < 3; j++) {
const blade = new THREE.Mesh(
new THREE.ConeGeometry(0.055, range(0.22, 0.43), 3),
choose(grassMaterials)
);
blade.position.set(x + range(-0.12, 0.12), 0.12, z + range(-0.12, 0.12));
blade.rotation.z = range(-0.28, 0.28);
blade.castShadow = true;
scene.add(blade);
}
}
for (let i = 0; i < 36; i++) {
const angle = random() * Math.PI * 2;
const radius = range(2, 10.8);
const stone = addMesh(
scene,
new THREE.DodecahedronGeometry(range(0.06, 0.16), 0),
random() > 0.5 ? mat.stone : mat.stoneDark,
[Math.cos(angle) * radius, 0.06, Math.sin(angle) * radius]
);
stone.scale.y = range(0.45, 0.75);
stone.rotation.set(random(), random(), random());
}
function createMushroom(x, z, size) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(size);
addMesh(
group,
new THREE.CylinderGeometry(0.06, 0.085, 0.35, 7),
material(0xe3d3ac),
[0, 0.17, 0]
);
const cap = addMesh(
group,
new THREE.SphereGeometry(0.21, 8, 5, 0, Math.PI * 2, 0, Math.PI / 2),
material(0xb85c3f),
[0, 0.34, 0],
[1, 0.65, 1]
);
cap.rotation.x = Math.PI;
scene.add(group);
}
createMushroom(3.35, -1.25, 1);
createMushroom(3.62, -1.45, 0.72);
createMushroom(-3.55, 2.5, 0.82);
// ---------------------------------------------------------------------
// Seed caches and simplified germination
// ---------------------------------------------------------------------
const cacheLocations = [
{ position: [-2.8, 0.02, 1.7], count: 8 },
{ position: [3.55, 0.02, -1.7], count: 8 },
{ position: [0.55, 0.02, 3.45], count: 8 },
{ position: [-2.0, 0.02, -2.75], count: 8 },
{ position: [4.45, 0.02, 2.55], count: 8 }
];
const seedRecords = [];
const sproutMaterial = material(0x6b9c4c);
const youngLeafMaterial = material(0x83a95b);
function createSprout() {
const group = new THREE.Group();
// A small solid root visible just above the soil.
cylinderBetween(
group,
[0, 0.025, 0],
[0.2, 0.018, -0.04],
0.035,
0.018,
mat.cap,
5
);
const stem = addMesh(
group,
new THREE.CylinderGeometry(0.026, 0.042, 0.48, 6),
sproutMaterial,
[0, 0.27, 0]
);
stem.rotation.z = -0.08;
const leftLeaf = addMesh(
group,
new THREE.SphereGeometry(0.12, 7, 4),
youngLeafMaterial,
[-0.11, 0.47, 0],
[1.35, 0.22, 0.68]
);
leftLeaf.rotation.z = 0.55;
const rightLeaf = addMesh(
group,
new THREE.SphereGeometry(0.13, 7, 4),
youngLeafMaterial,
[0.12, 0.52, 0],
[1.4, 0.22, 0.65]
);
rightLeaf.rotation.z = -0.58;
return group;
}
cacheLocations.forEach((cache, cacheIndex) => {
const [cx, cy, cz] = cache.position;
// Exposed-earth patch marks the cache.
const patch = new THREE.Mesh(
new THREE.CircleGeometry(0.72, 22),
material(0x554c36)
);
patch.rotation.x = -Math.PI / 2;
patch.position.set(cx, cy + 0.006, cz);
patch.scale.set(1.45, 0.92, 1);
patch.receiveShadow = true;
scene.add(patch);
// Small stones around each cache.
for (let i = 0; i < 9; i++) {
const angle = (i / 9) * Math.PI * 2 + range(-0.15, 0.15);
const stone = addMesh(
scene,
new THREE.DodecahedronGeometry(range(0.07, 0.12), 0),
i % 2 ? mat.stone : mat.stoneDark,
[
cx + Math.cos(angle) * range(0.75, 0.94),
0.06,
cz + Math.sin(angle) * range(0.48, 0.65)
]
);
stone.scale.y = 0.65;
stone.rotation.set(random(), random(), random());
}
// Leaf cover makes the stores feel buried rather than arranged.
for (let i = 0; i < 16; i++) {
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random()) * 0.9;
addLeaf(
scene,
cx + Math.cos(angle) * radius,
cz + Math.sin(angle) * radius,
range(0.5, 0.85)
);
}
for (let i = 0; i < cache.count; i++) {
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random()) * 0.57;
const x = cx + Math.cos(angle) * radius;
const z = cz + Math.sin(angle) * radius;
const acorn = createAcorn(range(0.72, 0.96));
acorn.position.set(x, 0.13, z);
acorn.rotation.y = random() * Math.PI * 2;
acorn.rotation.z = range(-0.32, 0.32);
scene.add(acorn);
const sprout = createSprout();
sprout.position.set(x, 0.12, z);
sprout.visible = false;
scene.add(sprout);
// The first three seeds are taken early; the rest remain to sprout.
const eatenAt = i < 3
? 5 + cacheIndex * 5 + i * 7
: Infinity;
const sproutAt = i < 3
? Infinity
: 31 + cacheIndex * 4 + (i - 3) * 4;
seedRecords.push({ acorn, sprout, eatenAt, sproutAt });
}
});
// ---------------------------------------------------------------------
// Squirrels
// ---------------------------------------------------------------------
const squirrelFur = [
material(0x9a5434),
material(0x6d4937),
material(0xb06a3b),
material(0x4f4b43),
material(0x8c6944)
];
const creamFur = material(0xe2cbaa);
const eyeMaterial = material(0x171815, { roughness: 0.35 });
const noseMaterial = material(0x362a25, { roughness: 0.5 });
function createSquirrel(colorIndex, scale = 1) {
const root = new THREE.Group();
const model = new THREE.Group();
root.add(model);
const fur = squirrelFur[colorIndex % squirrelFur.length];
// Rounded body and lighter belly.
addMesh(
model,
new THREE.SphereGeometry(1, 10, 7),
fur,
[0, 0.52, -0.04],
[0.39, 0.5, 0.62]
);
addMesh(
model,
new THREE.SphereGeometry(1, 9, 6),
creamFur,
[0, 0.48, 0.35],
[0.28, 0.38, 0.35]
);
// Head, muzzle, and nose.
addMesh(
model,
new THREE.SphereGeometry(1, 10, 7),
fur,
[0, 0.99, 0.54],
[0.36, 0.37, 0.36]
);
addMesh(
model,
new THREE.SphereGeometry(1, 9, 6),
creamFur,
[0, 0.88, 0.8],
[0.24, 0.19, 0.27]
);
addMesh(
model,
new THREE.SphereGeometry(0.055, 6, 4),
noseMaterial,
[0, 0.9, 1.04]
);
// Eyes.
for (const side of [-1, 1]) {
addMesh(
model,
new THREE.SphereGeometry(0.043, 7, 5),
eyeMaterial,
[side * 0.145, 1.06, 0.84]
);
}
// Rounded ears.
for (const side of [-1, 1]) {
const ear = addMesh(
model,
new THREE.ConeGeometry(0.115, 0.28, 7),
fur,
[side * 0.19, 1.31, 0.48]
);
ear.rotation.z = side * -0.14;
addMesh(
model,
new THREE.SphereGeometry(0.065, 6, 4),
creamFur,
[side * 0.19, 1.3, 0.54],
[0.7, 1, 0.35]
);
}
// Front legs use pivots so they can visibly trot.
const frontLegs = [];
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.22, 0.36, 0.34);
model.add(pivot);
addMesh(
pivot,
new THREE.CylinderGeometry(0.055, 0.068, 0.37, 6),
fur,
[0, -0.15, 0]
);
frontLegs.push(pivot);
}
// Large hindquarters and rear feet.
for (const side of [-1, 1]) {
addMesh(
model,
new THREE.SphereGeometry(0.2, 8, 6),
fur,
[side * 0.24, 0.35, -0.22],
[0.9, 1.05, 1.35]
);
addMesh(
model,
new THREE.SphereGeometry(0.13, 7, 5),
fur,
[side * 0.26, 0.12, 0.12],
[0.8, 0.5, 1.5]
);
}
// Curled, segmented tail.
const tail = new THREE.Group();
tail.position.set(0, 0.6, -0.43);
model.add(tail);
const tailPositions = [
[0, 0, 0],
[0, 0.2, -0.18],
[0.02, 0.51, -0.31],
[0.04, 0.82, -0.25],
[0.02, 1.02, -0.05]
];
tailPositions.forEach((position, index) => {
const tailPiece = addMesh(
tail,
new THREE.SphereGeometry(1, 8, 6),
index === tailPositions.length - 1 ? creamFur : fur,
position,
[0.21, 0.29, 0.23]
);
tailPiece.rotation.z = index * 0.13;
});
root.scale.setScalar(scale);
scene.add(root);
return { root, model, tail, frontLegs };
}
const squirrelRoutes = [
{
points: [
[-4.2, 0.03, 0.7], [-3.3, 0.03, 3.5], [-0.8, 0.03, 4.3],
[2.8, 0.03, 3.5], [4.7, 0.03, 1.0], [2.4, 0.03, -1.4],
[-0.4, 0.03, -4.0], [-4.1, 0.03, -2.4]
],
speed: 0.023,
offset: 0.04,
reverse: false
},
{
points: [
[1.0, 0.03, 2.5], [2.4, 0.03, 3.5], [4.7, 0.03, 3.3],
[5.4, 0.03, 1.6], [3.8, 0.03, 0.1], [2.1, 0.03, 0.8],
[0.5, 0.03, 1.5]
],
speed: 0.032,
offset: 0.35,
reverse: true
},
{
points: [
[-7.1, 0.03, -3.6], [-4.7, 0.03, -5.1], [-1.1, 0.03, -5.4],
[2.0, 0.03, -5.0], [3.0, 0.03, -3.4], [0.4, 0.03, -2.7],
[-3.4, 0.03, -2.1], [-6.0, 0.03, -1.4]
],
speed: 0.019,
offset: 0.62,
reverse: false
},
{
points: [
[-3.8, 0.03, 2.5], [-2.1, 0.03, 2.7], [-0.9, 0.03, 1.9],
[-0.3, 0.03, 0.4], [-1.8, 0.03, 0.0], [-3.2, 0.03, 0.8]
],
speed: 0.037,
offset: 0.18,
reverse: true
},
{
points: [
[6.4, 0.03, -4.8], [3.2, 0.03, -5.4], [0.2, 0.03, -5.6],
[-3.4, 0.03, -5.0], [-6.3, 0.03, -3.2], [-6.6, 0.03, 0.3],
[-4.5, 0.03, 2.4], [0.8, 0.03, 3.6], [4.8, 0.03, 1.2],
[5.8, 0.03, -2.1]
],
speed: 0.016,
offset: 0.78,
reverse: false
}
];
const squirrels = squirrelRoutes.map((route, index) => {
const curve = new THREE.CatmullRomCurve3(
route.points.map((point) => new THREE.Vector3(...point)),
true,
"catmullrom",
0.35
);
return {
...createSquirrel(index, [0.76, 0.68, 0.82, 0.72, 0.78][index]),
curve,
speed: route.speed,
offset: route.offset,
reverse: route.reverse,
phase: index * 1.73
};
});
// ---------------------------------------------------------------------
// Timeline and playback
// ---------------------------------------------------------------------
const timeline = document.querySelector("#timeline");
const dayOutput = document.querySelector("#day-output");
const seedCount = document.querySelector("#seed-count");
const status = document.querySelector("#status");
const playButton = document.querySelector("#play");
let currentDay = 0;
let playing = false;
function updateTimeline() {
let remaining = 0;
for (const record of seedRecords) {
const survives = currentDay < record.eatenAt;
record.acorn.visible = survives;
if (survives) remaining++;
const growth = survives
? THREE.MathUtils.clamp((currentDay - record.sproutAt) / 13, 0, 1)
: 0;
record.sprout.visible = growth > 0.001;
record.sprout.scale.setScalar(Math.max(0.001, growth));
}
timeline.value = currentDay;
timeline.style.setProperty("--p", `${(currentDay / 60) * 100}%`);
dayOutput.textContent = `Day ${Math.round(currentDay)}`;
seedCount.textContent = `${remaining} seed${remaining === 1 ? "" : "s"} remain`;
if (currentDay < 10) {
status.textContent = "Winter stores intact";
} else if (currentDay < 31) {
status.textContent = "Squirrels are raiding the caches";
} else if (currentDay < 50) {
status.textContent = "Remaining acorns begin to germinate";
} else {
status.textContent = "Young oak shoots break the soil";
}
}
timeline.addEventListener("input", () => {
currentDay = Number(timeline.value);
playing = false;
playButton.textContent = "▶";
updateTimeline();
});
playButton.addEventListener("click", () => {
if (currentDay >= 60) currentDay = 0;
playing = !playing;
playButton.textContent = playing ? "Ⅱ" : "▶";
updateTimeline();
});
updateTimeline();
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animateSquirrels(elapsed) {
for (const squirrel of squirrels) {
let u = (squirrel.offset + elapsed * squirrel.speed) % 1;
if (squirrel.reverse) u = 1 - u;
const point = squirrel.curve.getPointAt(u);
const lookU = squirrel.reverse
? (u - 0.012 + 1) % 1
: (u + 0.012) % 1;
const next = squirrel.curve.getPointAt(lookU);
const dx = next.x - point.x;
const dz = next.z - point.z;
squirrel.root.position.copy(point);
squirrel.root.rotation.y = Math.atan2(dx, dz);
const gait = elapsed * (squirrel.reverse ? -11 : 11) + squirrel.phase;
squirrel.model.position.y = Math.abs(Math.sin(gait)) * 0.035;
squirrel.model.rotation.z = Math.sin(gait * 0.5) * 0.018;
squirrel.frontLegs[0].rotation.x = Math.sin(gait) * 0.48;
squirrel.frontLegs[1].rotation.x = -Math.sin(gait) * 0.48;
squirrel.tail.rotation.y = Math.sin(elapsed * 2.2 + squirrel.phase) * 0.19;
squirrel.tail.rotation.z = Math.sin(elapsed * 1.4 + squirrel.phase) * 0.075;
}
}
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (playing) {
currentDay = Math.min(60, currentDay + delta * 3.5);
if (currentDay >= 60) {
playing = false;
playButton.textContent = "▶";
}
updateTimeline();
}
animateSquirrels(elapsed);
renderer.render(scene, camera);
});
// ---------------------------------------------------------------------
// Resize handling
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
</script>
</body>
</html>
```