Prompt specification
Build or customize the Three.js 3D scene "Hide-and-revisit cache sequence" 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: Hide-and-revisit cache sequence
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/hide-and-revisit-cache-sequence-x0714
Scene Description Prompt:
Hide-and-revisit cache sequence. Animate a squirrel burying one acorn and later returning to its location; preserve the original landmark arrangement and leave one separate cache unrecovered in the story. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (hide-and-revisit-cache-sequence-x0714):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Squirrel — Hide and Revisit</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(20, 29, 25, 0.88);
--border: rgba(255, 255, 255, 0.16);
--cream: #fff2d0;
--muted: #c7d2c6;
--accent: #e8ae55;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b8d8d0;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
color: var(--cream);
background: var(--panel);
border: 1px solid var(--border);
border-radius: 16px;
box-shadow: 0 16px 42px rgba(20, 30, 22, 0.24);
backdrop-filter: blur(12px);
}
#story-panel {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 18px 19px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 5px;
color: #a9c7ac;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.35rem, 3vw, 1.9rem);
line-height: 1.08;
letter-spacing: -0.03em;
}
#stage {
display: inline-block;
margin-top: 14px;
padding: 5px 9px;
border: 1px solid rgba(232, 174, 85, 0.35);
border-radius: 999px;
color: #ffd99c;
background: rgba(232, 174, 85, 0.1);
font-size: 0.76rem;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#story {
min-height: 66px;
margin: 11px 0 0;
color: #e7eee5;
font-size: 0.94rem;
line-height: 1.48;
}
#separate-cache {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--border);
color: var(--muted);
font-size: 0.79rem;
line-height: 1.42;
}
#separate-cache strong {
color: #f3c87b;
}
#controls {
bottom: 18px;
left: 50%;
width: min(780px, calc(100vw - 36px));
padding: 12px 14px;
transform: translateX(-50%);
}
.control-row {
display: flex;
align-items: center;
gap: 10px;
}
button,
select {
min-height: 36px;
border: 1px solid var(--border);
border-radius: 9px;
color: var(--cream);
background: rgba(255, 255, 255, 0.08);
font: inherit;
font-size: 0.82rem;
font-weight: 700;
}
button {
padding: 0 13px;
cursor: pointer;
}
button:hover,
select:hover {
background: rgba(255, 255, 255, 0.15);
}
#play {
min-width: 94px;
color: #252016;
background: #e8ae55;
border-color: #f4c779;
}
#timeline {
flex: 1;
min-width: 80px;
accent-color: var(--accent);
cursor: pointer;
}
#time {
min-width: 70px;
color: #dbe5da;
font-size: 0.76rem;
font-variant-numeric: tabular-nums;
text-align: right;
}
#camera-help {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 9;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 10px;
color: rgba(255, 255, 255, 0.88);
background: rgba(20, 29, 25, 0.62);
font-size: 0.7rem;
line-height: 1.45;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
color: #243229;
background: #b8d8d0;
font-weight: 800;
letter-spacing: 0.05em;
}
@media (max-width: 700px) {
#story-panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px 15px;
}
#story {
min-height: auto;
font-size: 0.83rem;
}
#separate-cache {
font-size: 0.72rem;
}
#controls {
bottom: 10px;
width: calc(100vw - 20px);
padding: 10px;
}
.control-row {
flex-wrap: wrap;
}
#timeline {
order: 5;
flex-basis: 100%;
}
#time {
margin-left: auto;
}
#camera-help {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Building the voxel woodland…</div>
<section id="story-panel" class="panel">
<div class="eyebrow">Voxel woodland story</div>
<h1>Hide & Revisit</h1>
<div id="stage">At the great oak</div>
<p id="story"></p>
<div id="separate-cache">
<strong>Separate cache:</strong> another acorn remains buried beneath the
split boulder. It is never recovered in this story.
</div>
</section>
<section id="controls" class="panel">
<div class="control-row">
<button id="play" type="button">Pause</button>
<button id="replay" type="button">Replay</button>
<input
id="timeline"
type="range"
min="0"
max="34"
step="0.05"
value="0"
aria-label="Story timeline"
/>
<span id="time">00:00 / 00:34</span>
<select id="speed" aria-label="Playback speed">
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="1.5">1.5×</option>
<option value="2">2×</option>
</select>
</div>
</section>
<div id="camera-help">
Drag to orbit · Wheel/pinch to zoom · Arrow keys to orbit<br />
Double-click to reset the camera
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8d8d0);
scene.fog = new THREE.Fog(0xb8d8d0, 25, 48);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe9fff4, 0x53633d, 1.35);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffedbd, 2.55);
sun.position.set(-9, 15, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00035;
scene.add(sun);
// A shared box geometry makes every visible environmental object voxel-like.
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function cube(parent, position, size, color, options = {}) {
const mesh = new THREE.Mesh(cubeGeometry, material(color));
mesh.position.set(position[0], position[1], position[2]);
mesh.scale.set(size[0], size[1], size[2]);
mesh.castShadow = options.cast !== false;
mesh.receiveShadow = options.receive !== false;
parent.add(mesh);
return mesh;
}
function groupAt(x, y, z) {
const group = new THREE.Group();
group.position.set(x, y, z);
scene.add(group);
return group;
}
const clamp01 = (value) => Math.min(1, Math.max(0, value));
function smooth01(value, start, end) {
const x = clamp01((value - start) / (end - start));
return x * x * (3 - 2 * x);
}
function lerpAngle(a, b, t) {
let delta = (b - a) % (Math.PI * 2);
if (delta > Math.PI) delta -= Math.PI * 2;
if (delta < -Math.PI) delta += Math.PI * 2;
return a + delta * t;
}
function pseudoRandom(seed) {
const value = Math.sin(seed * 91.733) * 43758.5453;
return value - Math.floor(value);
}
// -------------------------------------------------------------------------
// Fixed landmark arrangement: great oak west, split boulder east, stump south
// -------------------------------------------------------------------------
const landmarks = new THREE.Group();
scene.add(landmarks);
// Grass made from individual, slightly separated voxel tiles.
const grassColors = [0x789b58, 0x83a55f, 0x719153, 0x8bab67, 0x769d59];
for (let ix = -7; ix <= 7; ix++) {
for (let iz = -7; iz <= 7; iz++) {
const color = grassColors[Math.floor(pseudoRandom(ix * 19 + iz * 43) * grassColors.length)];
cube(
landmarks,
[ix, -0.12, iz],
[0.94, 0.24, 0.94],
color
);
}
}
// A visible stepping-stone trail made of tan blocks.
const trail = [
[-5, 1], [-4, 1], [-3, 2], [-2, 2],
[-1, 2], [0, 2], [1, 2], [2, 2]
];
trail.forEach(([x, z], index) => {
const shade = index % 2 ? 0xb99b68 : 0xc6a873;
cube(landmarks, [x, 0.018, z], [0.68, 0.045, 0.68], shade);
});
// Great oak.
const oak = groupAt(-5.35, 0, -0.15);
oak.name = "Great oak landmark";
for (let i = 0; i < 7; i++) {
const width = 0.72 - i * 0.025;
cube(
oak,
[i % 2 === 0 ? 0.03 : -0.03, 0.36 + i * 0.64, 0],
[width, 0.61, width],
i % 2 ? 0x7f5736 : 0x8c613d
);
}
// Exposed roots leading toward the first cache.
cube(oak, [0.65, 0.18, 0.45], [1.55, 0.28, 0.35], 0x765036);
cube(oak, [1.35, 0.15, 0.85], [1.25, 0.25, 0.32], 0x805838);
cube(oak, [1.9, 0.13, 1.25], [1.05, 0.22, 0.28], 0x8c603c);
cube(oak, [2.25, 0.11, 1.62], [0.72, 0.19, 0.24], 0x765036);
// Branches.
cube(oak, [-0.72, 3.2, 0.05], [1.35, 0.34, 0.36], 0x775136);
cube(oak, [0.65, 3.65, -0.1], [1.25, 0.34, 0.35], 0x805739);
cube(oak, [0.1, 4.05, -0.65], [0.35, 0.35, 1.2], 0x795337);
const leafColors = [0x4f7b3f, 0x5d8a46, 0x426f38, 0x6c934c];
for (let gx = -3; gx <= 3; gx++) {
for (let gy = 0; gy <= 2; gy++) {
for (let gz = -3; gz <= 3; gz++) {
const distance =
Math.abs(gx) +
Math.abs(gz) * 0.72 +
Math.abs(gy - 1) * 0.95;
if (distance > 4.05) continue;
const color =
leafColors[Math.floor(pseudoRandom(gx * 31 + gy * 17 + gz * 11) * leafColors.length)];
cube(
oak,
[gx * 0.78, 4.48 + gy * 0.78, gz * 0.78],
[0.73, 0.73, 0.73],
color
);
}
}
}
// Split boulder, deliberately containing the separate unrecovered cache.
const boulder = groupAt(5.15, 0, -1.55);
boulder.name = "Split boulder landmark";
const boulderBlocks = [
[-1.05, 0.48, 0.10, 0.92],
[-0.48, 0.55, 0.38, 0.98],
[-1.02, 1.40, -0.02, 0.88],
[-0.42, 1.46, 0.26, 0.84],
[-1.02, 0.48, -0.86, 0.90],
[-0.42, 1.39, -0.78, 0.86],
[0.82, 0.48, 0.15, 0.94],
[1.32, 0.53, -0.30, 0.88],
[0.88, 1.39, 0.02, 0.86],
[1.28, 1.43, -0.55, 0.82],
[0.82, 0.49, -0.82, 0.89]
];
boulderBlocks.forEach(([x, y, z, size], index) => {
cube(
boulder,
[x, y, z],
[size, size * 0.92, size],
index % 3 === 0 ? 0x8a9290 : index % 3 === 1 ? 0x747e7d : 0x9ba19d
);
});
cube(boulder, [-0.05, 0.08, 0.55], [0.7, 0.18, 0.58], 0x6f7976);
cube(boulder, [-0.04, 0.08, -0.62], [0.62, 0.18, 0.55], 0x818a87);
// Mossy stump in the south.
const stump = groupAt(2.55, 0, 4.25);
stump.name = "Mossy stump landmark";
for (let level = 0; level < 3; level++) {
cube(
stump,
[0, 0.35 + level * 0.55, 0],
[1.45 - level * 0.08, 0.52, 1.45 - level * 0.08],
level % 2 ? 0x855d39 : 0x765036
);
}
cube(stump, [0, 1.56, 0], [1.18, 0.14, 1.18], 0xb98b55);
cube(stump, [0.22, 1.65, 0.18], [0.52, 0.08, 0.52], 0x8c623c);
cube(stump, [-0.28, 1.65, -0.26], [0.42, 0.08, 0.42], 0x765036);
cube(stump, [0.58, 0.27, 0.53], [0.34, 0.18, 0.52], 0x5f873f);
cube(stump, [-0.55, 0.19, -0.42], [0.45, 0.16, 0.42], 0x6d9348);
// Small voxel plants.
const mushroomSpots = [
[1.25, 3.15], [3.65, 3.3], [4.15, 2.55], [0.65, 4.55]
];
mushroomSpots.forEach(([x, z], index) => {
cube(landmarks, [x, 0.18, z], [0.12, 0.36, 0.12], 0xe7d7b0);
cube(
landmarks,
[x, 0.38, z],
[0.38 - index * 0.025, 0.18, 0.38 - index * 0.025],
index % 2 ? 0xc94f42 : 0xe26a4b
);
});
for (let i = 0; i < 34; i++) {
const x = -6.7 + pseudoRandom(i * 2.13) * 13.4;
const z = -6.4 + pseudoRandom(i * 5.71 + 2) * 12.8;
if (Math.abs(x + 5.35) < 1.5 && Math.abs(z + 0.15) < 1.6) continue;
if (Math.abs(x - 5.15) < 1.6 && Math.abs(z + 1.55) < 1.5) continue;
if (Math.abs(x - 2.55) < 1.2 && Math.abs(z - 4.25) < 1.2) continue;
const height = 0.16 + pseudoRandom(i * 9.2) * 0.2;
cube(
landmarks,
[x, height / 2, z],
[0.08, height, 0.08],
i % 2 ? 0x5f833e : 0x71954b
);
}
// -------------------------------------------------------------------------
// Acorns
// -------------------------------------------------------------------------
function createAcorn() {
const acorn = new THREE.Group();
cube(acorn, [0, 0.02, 0], [0.29, 0.34, 0.29], 0xc9924d);
cube(acorn, [0, 0.22, 0], [0.37, 0.12, 0.37], 0x70432c);
cube(acorn, [0, 0.34, 0], [0.1, 0.13, 0.1], 0x523526);
cube(acorn, [-0.08, 0.03, 0.151], [0.08, 0.14, 0.025], 0xe2b56d);
return acorn;
}
const carriedAcorn = createAcorn();
scene.add(carriedAcorn);
// This second, physically separate cache is under the split boulder.
// It remains buried and is never touched by the animation.
const unrecoveredAcorn = createAcorn();
unrecoveredAcorn.position.set(4.55, -0.38, -1.42);
unrecoveredAcorn.rotation.y = 0.42;
scene.add(unrecoveredAcorn);
// -------------------------------------------------------------------------
// Squirrel, built entirely from voxel blocks
// -------------------------------------------------------------------------
const squirrel = new THREE.Group();
squirrel.name = "Voxel squirrel";
squirrel.rotation.order = "YXZ";
scene.add(squirrel);
cube(squirrel, [0, 0.66, 0], [0.68, 0.62, 1.05], 0x9a5934);
cube(squirrel, [0, 0.59, 0.25], [0.58, 0.48, 0.72], 0xc98247);
cube(squirrel, [0, 1.12, 0.62], [0.64, 0.62, 0.62], 0xa96339);
cube(squirrel, [0, 1.03, 1.00], [0.49, 0.31, 0.38], 0xd28a4d);
cube(squirrel, [0, 1.06, 1.205], [0.17, 0.13, 0.08], 0x3b2a24);
cube(squirrel, [-0.20, 1.25, 0.91], [0.10, 0.11, 0.07], 0x171915);
cube(squirrel, [0.20, 1.25, 0.91], [0.10, 0.11, 0.07], 0x171915);
cube(squirrel, [-0.22, 1.50, 0.58], [0.22, 0.25, 0.20], 0x9a5934);
cube(squirrel, [0.22, 1.50, 0.58], [0.22, 0.25, 0.20], 0x9a5934);
cube(squirrel, [-0.22, 1.52, 0.665], [0.10, 0.11, 0.06], 0xe2a06b);
cube(squirrel, [0.22, 1.52, 0.665], [0.10, 0.11, 0.06], 0xe2a06b);
// Blocky front paws.
cube(squirrel, [-0.35, 0.70, 0.38], [0.18, 0.38, 0.22], 0x9a5934);
cube(squirrel, [0.35, 0.70, 0.38], [0.18, 0.38, 0.22], 0x9a5934);
const legPivots = [];
const legOffsets = [
[-0.25, 0.38, 0.35, 0],
[0.25, 0.38, 0.35, Math.PI],
[-0.27, 0.38, -0.34, Math.PI],
[0.27, 0.38, -0.34, 0]
];
legOffsets.forEach(([x, y, z, phase]) => {
const pivot = new THREE.Group();
pivot.position.set(x, y, z);
pivot.userData.phase = phase;
squirrel.add(pivot);
cube(pivot, [0, -0.17, 0], [0.21, 0.34, 0.24], 0x75422e);
cube(pivot, [0, -0.34, 0.055], [0.23, 0.12, 0.32], 0x5c3829);
legPivots.push(pivot);
});
// A curled tail assembled from square blocks.
const tail = new THREE.Group();
tail.position.set(0, 0.72, -0.61);
squirrel.add(tail);
cube(tail, [0, 0.03, -0.04], [0.49, 0.68, 0.48], 0x87472f);
cube(tail, [0, 0.49, -0.18], [0.49, 0.48, 0.48], 0x985233);
cube(tail, [0.02, 0.78, -0.38], [0.43, 0.35, 0.4], 0xb66b3b);
cube(tail, [0.02, 0.76, -0.62], [0.34, 0.28, 0.26], 0xc47a43);
// -------------------------------------------------------------------------
// Cache site and disturbed soil
// -------------------------------------------------------------------------
const oakStand = new THREE.Vector3(-5.0, 0, 1.55);
const cacheStand = new THREE.Vector3(-3.02, 0, 1.55);
const finalStand = new THREE.Vector3(2.12, 0, 2.08);
const holePosition = new THREE.Vector3(-3.02, 0.08, 2.25);
const patch = new THREE.Group();
patch.position.copy(holePosition);
patch.visible = false;
scene.add(patch);
const patchBlocks = [
[-0.22, -0.045, 0.08, 0.34, 0.06, 0.28],
[0.19, -0.043, -0.02, 0.32, 0.06, 0.30],
[0.00, -0.047, 0.30, 0.27, 0.06, 0.22],
[-0.03, -0.045, -0.27, 0.31, 0.06, 0.21]
];
patchBlocks.forEach(([x, y, z, sx, sy, sz]) => {
cube(patch, [x, y, z], [sx, sy, sz], 0x6f5036);
});
const mound = new THREE.Group();
mound.position.copy(holePosition);
mound.visible = false;
scene.add(mound);
cube(mound, [0, 0.07, 0], [0.46, 0.14, 0.46], 0x765238);
cube(mound, [-0.22, 0.04, 0.12], [0.27, 0.10, 0.27], 0x835c3c);
cube(mound, [0.22, 0.035, -0.10], [0.25, 0.09, 0.25], 0x6e4b33);
cube(mound, [0.03, 0.025, 0.25], [0.25, 0.08, 0.22], 0x805739);
const hole = cube(
scene,
[holePosition.x, 0.018, holePosition.z],
[0.47, 0.035, 0.47],
0x362c23
);
hole.visible = false;
// -------------------------------------------------------------------------
// Deterministic motion timeline
// -------------------------------------------------------------------------
const motionSegments = [
{ a: 0.0, b: 1.4, p0: oakStand, p1: oakStand, y0: Math.PI / 2, y1: Math.PI / 2, walk: 0 },
{ a: 1.4, b: 6.8, p0: oakStand, p1: cacheStand, y0: Math.PI / 2, y1: Math.PI / 2, walk: 1 },
{ a: 6.8, b: 7.8, p0: cacheStand, p1: cacheStand, y0: Math.PI / 2, y1: 0, walk: 0 },
{ a: 7.8, b: 9.7, p0: cacheStand, p1: cacheStand, y0: 0, y1: 0, walk: 0 },
{ a: 9.7, b: 10.8, p0: cacheStand, p1: cacheStand, y0: 0, y1: -Math.PI / 2, walk: 0 },
{ a: 10.8, b: 14.0, p0: cacheStand, p1: oakStand, y0: -Math.PI / 2, y1: -Math.PI / 2, walk: 1 },
{ a: 14.0, b: 17.5, p0: oakStand, p1: oakStand, y0: -Math.PI / 2, y1: -Math.PI / 2, walk: 0 },
{ a: 17.5, b: 18.5, p0: oakStand, p1: oakStand, y0: -Math.PI / 2, y1: Math.PI / 2, walk: 0 },
{ a: 18.5, b: 22.7, p0: oakStand, p1: cacheStand, y0: Math.PI / 2, y1: Math.PI / 2, walk: 1 },
{ a: 22.7, b: 23.7, p0: cacheStand, p1: cacheStand, y0: Math.PI / 2, y1: 0, walk: 0 },
{ a: 23.7, b: 26.7, p0: cacheStand, p1: cacheStand, y0: 0, y1: 0, walk: 0 },
{ a: 26.7, b: 27.7, p0: cacheStand, p1: cacheStand, y0: 0, y1: Math.PI / 2, walk: 0 },
{ a: 27.7, b: 31.3, p0: cacheStand, p1: finalStand, y0: Math.PI / 2, y1: Math.PI / 2, walk: 1 },
{ a: 31.3, b: 34.0, p0: finalStand, p1: finalStand, y0: Math.PI / 2, y1: Math.PI / 2, walk: 0 }
];
function sampleMotion(time) {
let segment = motionSegments[motionSegments.length - 1];
for (const candidate of motionSegments) {
if (time >= candidate.a && time < candidate.b) {
segment = candidate;
break;
}
}
const raw = clamp01((time - segment.a) / (segment.b - segment.a));
const eased = raw * raw * (3 - 2 * raw);
return {
x: THREE.MathUtils.lerp(segment.p0.x, segment.p1.x, eased),
z: THREE.MathUtils.lerp(segment.p0.z, segment.p1.z, eased),
yaw: lerpAngle(segment.y0, segment.y1, eased),
walk: segment.walk
};
}
const carryLocal = new THREE.Vector3(0, 0.94, 1.12);
const carryPoint = new THREE.Vector3();
const buryCarryStart = new THREE.Vector3(
cacheStand.x,
0.94,
cacheStand.z + 1.12
);
const daySky = new THREE.Color(0xb8d8d0);
const duskSky = new THREE.Color(0x68748d);
const daySun = new THREE.Color(0xffedbd);
const duskSun = new THREE.Color(0xf2a068);
const skyColor = new THREE.Color();
function updateTimeOfDay(time) {
let blend = 0;
if (time >= 13.5 && time < 15.5) {
blend = smooth01(time, 13.5, 15.5);
} else if (time >= 15.5 && time < 18.5) {
blend = 1;
} else if (time >= 18.5 && time < 21.0) {
blend = 1 - smooth01(time, 18.5, 21.0);
}
skyColor.lerpColors(daySky, duskSky, blend);
scene.background.copy(skyColor);
scene.fog.color.copy(skyColor);
sun.color.lerpColors(daySun, duskSun, blend);
sun.intensity = THREE.MathUtils.lerp(2.55, 0.78, blend);
hemi.intensity = THREE.MathUtils.lerp(1.35, 0.56, blend);
}
function updateScene(time) {
const motion = sampleMotion(time);
squirrel.position.set(motion.x, 0, motion.z);
squirrel.rotation.y = motion.yaw;
const buryCrouch =
smooth01(time, 7.65, 8.15) *
(1 - smooth01(time, 9.0, 9.55));
const digCrouch =
smooth01(time, 23.45, 24.05) *
(1 - smooth01(time, 25.25, 26.0));
const crouch = Math.max(buryCrouch, digCrouch);
squirrel.scale.set(1, 1 - crouch * 0.18, 1);
squirrel.rotation.x = crouch * 0.08;
const stride = time * 11;
legPivots.forEach((pivot) => {
pivot.rotation.x =
Math.sin(stride + pivot.userData.phase) *
0.58 *
motion.walk *
(1 - crouch);
});
tail.rotation.z = Math.sin(time * 5.5) * 0.13;
tail.rotation.y = Math.sin(time * 3.2) * 0.08;
squirrel.updateMatrixWorld(true);
carryPoint.copy(carryLocal).applyMatrix4(squirrel.matrixWorld);
// The primary acorn is carried, buried, hidden, dug up, and carried away.
if (time < 7.8) {
carriedAcorn.visible = true;
carriedAcorn.position.copy(carryPoint);
carriedAcorn.quaternion.copy(squirrel.quaternion);
} else if (time < 8.6) {
carriedAcorn.visible = true;
carriedAcorn.position.lerpVectors(
buryCarryStart,
holePosition,
smooth01(time, 7.8, 8.6)
);
carriedAcorn.rotation.set(0, 0, 0);
} else if (time < 9.3) {
carriedAcorn.visible = true;
const descent = smooth01(time, 8.6, 9.3);
carriedAcorn.position.set(
holePosition.x,
THREE.MathUtils.lerp(holePosition.y, -0.44, descent),
holePosition.z
);
carriedAcorn.rotation.set(0, 0, 0);
} else if (time < 24.2) {
carriedAcorn.visible = false;
} else if (time < 25.4) {
carriedAcorn.visible = true;
carriedAcorn.position.lerpVectors(
holePosition,
carryPoint,
smooth01(time, 24.2, 25.4)
);
carriedAcorn.quaternion.slerp(squirrel.quaternion, 0.12);
} else {
carriedAcorn.visible = true;
carriedAcorn.position.copy(carryPoint);
carriedAcorn.quaternion.copy(squirrel.quaternion);
}
// The soil mound rises after burial and is pushed aside during recovery.
patch.visible = time >= 8.8;
if (time < 8.6) {
mound.visible = false;
} else if (time < 9.3) {
mound.visible = true;
mound.scale.y = THREE.MathUtils.lerp(0.04, 1, smooth01(time, 8.6, 9.3));
} else if (time < 23.6) {
mound.visible = true;
mound.scale.y = 1;
} else if (time < 24.6) {
mound.visible = true;
mound.scale.y = THREE.MathUtils.lerp(1, 0.04, smooth01(time, 23.6, 24.6));
} else {
mound.visible = false;
}
hole.visible = time >= 9.0 && (time < 23.7 || time >= 25.5);
updateTimeOfDay(time);
}
// -------------------------------------------------------------------------
// Story display
// -------------------------------------------------------------------------
const stageElement = document.getElementById("stage");
const storyElement = document.getElementById("story");
let lastStage = "";
function updateStory(time) {
let stage;
let text;
if (time < 1.4) {
stage = "At the great oak";
text = "The squirrel carries a single acorn away from the old oak, where the three woodland landmarks still stand in their original places.";
} else if (time < 6.8) {
stage = "The first journey";
text = "It follows the block-stone trail to a gap among the oak roots, holding the acorn carefully in its mouth.";
} else if (time < 9.7) {
stage = "Burying the acorn";
text = "The squirrel pauses, lowers its body, and pushes the acorn into the soil. A small square of disturbed earth marks the cache.";
} else if (time < 14.0) {
stage = "Leaving the cache";
text = "With the acorn safely hidden, the squirrel turns away and walks back toward the great oak without disturbing the site.";
} else if (time < 18.5) {
stage = "Hours later";
text = "Dusk settles over the woodland. The squirrel waits near the oak, remembering the exact place where it buried the acorn.";
} else if (time < 23.7) {
stage = "Returning by memory";
text = "At first light, the squirrel retraces the trail and returns to the cache among the exposed roots.";
} else if (time < 26.7) {
stage = "Digging it up";
text = "It paws aside the small soil mound and pulls the familiar acorn from the ground. This cache is recovered.";
} else if (time < 31.3) {
stage = "Cache recovered";
text = "The squirrel lifts the recovered acorn and carries it away along the trail, leaving the oak, boulder, and stump exactly where they were.";
} else {
stage = "One remains";
text = "The recovered acorn is safe. Elsewhere, beneath the split boulder, a separate cache remains buried and unrecovered.";
}
if (stage !== lastStage) {
stageElement.textContent = stage;
lastStage = stage;
}
storyElement.textContent = text;
}
// -------------------------------------------------------------------------
// Custom camera controls, implemented without Three.js addons
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(-0.35, 0.75, 0.8),
radius: 23.5,
theta: 0.69,
phi: 0.91
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.target.set(-0.35, 0.75, 0.8);
cameraState.radius = 23.5;
cameraState.theta = 0.69;
cameraState.phi = 0.91;
updateCamera();
}
const canvas = renderer.domElement;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
let activePointers = new Map();
let pinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
dragging = false;
}
});
canvas.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / distance),
12,
38
);
updateCamera();
}
pinchDistance = distance;
return;
}
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + deltaY * 0.005,
0.32,
1.38
);
updateCamera();
});
function releasePointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) pinchDistance = 0;
if (activePointers.size === 0) dragging = false;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
12,
38
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (["INPUT", "SELECT", "BUTTON"].includes(document.activeElement.tagName)) {
return;
}
let changed = true;
switch (event.key) {
case "ArrowLeft":
cameraState.theta += 0.09;
break;
case "ArrowRight":
cameraState.theta -= 0.09;
break;
case "ArrowUp":
cameraState.phi = Math.max(0.32, cameraState.phi - 0.07);
break;
case "ArrowDown":
cameraState.phi = Math.min(1.38, cameraState.phi + 0.07);
break;
case "+":
case "=":
cameraState.radius = Math.max(12, cameraState.radius - 1);
break;
case "-":
cameraState.radius = Math.min(38, cameraState.radius + 1);
break;
case " ":
togglePlayback();
break;
case "r":
case "R":
replay();
break;
default:
changed = false;
}
if (changed) {
event.preventDefault();
updateCamera();
}
});
// -------------------------------------------------------------------------
// Playback UI
// -------------------------------------------------------------------------
const playButton = document.getElementById("play");
const replayButton = document.getElementById("replay");
const timeline = document.getElementById("timeline");
const timeLabel = document.getElementById("time");
const speedSelect = document.getElementById("speed");
const duration = 34;
let elapsed = 0;
let playing = true;
let speed = 1;
function formatTime(value) {
const seconds = Math.floor(value);
return `00:${String(seconds).padStart(2, "0")}`;
}
function syncPlayButton() {
playButton.textContent = playing ? "Pause" : "Play";
}
function togglePlayback() {
if (elapsed >= duration) {
elapsed = 0;
playing = true;
} else {
playing = !playing;
}
syncPlayButton();
}
function replay() {
elapsed = 0;
playing = true;
timeline.value = "0";
syncPlayButton();
}
playButton.addEventListener("click", togglePlayback);
replayButton.addEventListener("click", replay);
timeline.addEventListener("input", () => {
elapsed = Number(timeline.value);
playing = false;
syncPlayButton();
});
speedSelect.addEventListener("change", () => {
speed = Number(speedSelect.value);
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
elapsed += delta * speed;
if (elapsed >= duration) {
elapsed = duration;
playing = false;
syncPlayButton();
}
}
timeline.value = elapsed.toFixed(2);
timeLabel.textContent = `${formatTime(elapsed)} / ${formatTime(duration)}`;
updateScene(elapsed);
updateStory(elapsed);
renderer.render(scene, camera);
}
resetCamera();
updateScene(0);
updateStory(0);
syncPlayButton();
animate();
document.getElementById("loading").remove();
</script>
</body>
</html>
```