Prompt specification
Build or customize the Three.js 3D scene "Acorn cache location markers" 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: Acorn cache location markers
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/acorn-cache-location-markers-x0713
Scene Description Prompt:
A stylized squirrel beside acorns cached in shallow soil pockets; removable markers reveal cache locations. Three.js from cdnjs, one HTML file.
Working Three.js Starter (acorn-cache-location-markers-x0713):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#e8ddc8" />
<title>The Acorn Cache</title>
<style>
:root {
--ink: #3b2b20;
--muted: #756252;
--paper: rgba(255, 250, 239, 0.84);
--line: rgba(76, 52, 34, 0.14);
--accent: #b95236;
--accent-dark: #8f3826;
--gold: #d69a42;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8ddc8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active { cursor: grabbing; }
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.intro {
position: absolute;
top: clamp(20px, 4vw, 42px);
left: clamp(20px, 4vw, 48px);
max-width: 360px;
text-shadow: 0 1px 0 rgba(255,255,255,.35);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--accent-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 2px;
border-radius: 4px;
background: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 5vw, 62px);
font-weight: 500;
line-height: .96;
letter-spacing: -.045em;
}
.intro p {
max-width: 315px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
position: absolute;
top: clamp(18px, 3vw, 34px);
right: clamp(18px, 3vw, 36px);
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
pointer-events: auto;
}
.control {
min-height: 40px;
padding: 0 15px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 28px rgba(72, 48, 29, .08);
backdrop-filter: blur(12px);
cursor: pointer;
transition: transform .18s ease, background .18s ease, box-shadow .18s ease;
}
.control:hover {
transform: translateY(-2px);
background: rgba(255, 252, 245, .96);
box-shadow: 0 11px 30px rgba(72, 48, 29, .13);
}
.control:focus-visible {
outline: 3px solid rgba(185, 82, 54, .28);
outline-offset: 2px;
}
.control.primary {
border-color: transparent;
background: var(--accent);
color: #fffaf0;
}
.control.primary:hover { background: var(--accent-dark); }
.hint {
position: absolute;
left: clamp(20px, 4vw, 48px);
bottom: clamp(20px, 4vw, 38px);
display: flex;
align-items: center;
gap: 11px;
padding: 10px 14px 10px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 250, 239, .74);
color: var(--muted);
font-size: 11px;
letter-spacing: .02em;
backdrop-filter: blur(10px);
}
.mouse-icon {
position: relative;
width: 20px;
height: 25px;
border: 1.5px solid var(--accent);
border-radius: 10px;
}
.mouse-icon::before {
content: "";
position: absolute;
top: 4px;
left: 50%;
width: 2px;
height: 6px;
border-radius: 2px;
background: var(--accent);
transform: translateX(-50%);
}
.counter {
position: absolute;
right: clamp(20px, 4vw, 40px);
bottom: clamp(20px, 4vw, 38px);
min-width: 150px;
padding: 12px 15px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(255, 250, 239, .78);
backdrop-filter: blur(10px);
}
.counter-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
.counter-value {
display: flex;
align-items: baseline;
gap: 6px;
margin-top: 3px;
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
}
.counter-value span {
color: var(--muted);
font-family: Inter, ui-sans-serif, system-ui, sans-serif;
font-size: 11px;
}
.counter-bar {
height: 3px;
margin-top: 8px;
overflow: hidden;
border-radius: 4px;
background: rgba(77, 53, 34, .1);
}
#counter-fill {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--accent), var(--gold));
transition: width .45s ease;
}
#status {
position: absolute;
left: 50%;
bottom: 30px;
padding: 9px 14px;
border-radius: 999px;
background: rgba(55, 40, 29, .86);
color: #fff9ee;
font-size: 11px;
opacity: 0;
transform: translate(-50%, 10px);
transition: opacity .2s ease, transform .2s ease;
}
#status.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 720px) {
.intro p { display: none; }
h1 { font-size: 39px; }
.controls {
top: auto;
right: 14px;
bottom: 76px;
max-width: 220px;
}
.control {
min-height: 36px;
padding: 0 12px;
font-size: 11px;
}
.hint {
left: 14px;
bottom: 16px;
max-width: calc(100vw - 195px);
border-radius: 13px;
}
.hint .desktop-copy { display: none; }
.counter {
right: 14px;
bottom: 16px;
min-width: 132px;
}
#status { bottom: 126px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive woodland scene featuring a squirrel and hidden acorn caches"></canvas>
<div class="ui">
<header class="intro">
<div class="eyebrow">Woodland field notes · 07</div>
<h1>The Acorn<br />Cache</h1>
<p>A curious squirrel has hidden a small harvest in the shallow soil. Lift the red markers to uncover each secret place.</p>
</header>
<nav class="controls" aria-label="Scene controls">
<button class="control primary" id="remove-all">Remove all markers</button>
<button class="control" id="restore">Restore</button>
<button class="control" id="reset-view">Reset view</button>
</nav>
<div class="hint">
<span class="mouse-icon" aria-hidden="true"></span>
<span><span class="desktop-copy">Drag to orbit · Scroll to zoom · </span>Tap a marker</span>
</div>
<div class="counter" aria-live="polite">
<div class="counter-label">Caches uncovered</div>
<div class="counter-value"><strong id="cache-count">0</strong><span id="cache-total">of 5 found</span></div>
<div class="counter-bar"><div id="counter-fill"></div></div>
</div>
<div id="status" role="status"></div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const cacheCount = document.querySelector("#cache-count");
const cacheTotal = document.querySelector("#cache-total");
const counterFill = document.querySelector("#counter-fill");
const status = document.querySelector("#status");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8ddc8);
scene.fog = new THREE.Fog(0xe8ddc8, 18, 38);
const camera = new THREE.PerspectiveCamera(38, window.innerWidth / window.innerHeight, 0.1, 80);
const cameraTarget = new THREE.Vector3(0, 1.15, 0);
const defaultView = { azimuth: 0.64, polar: 1.02, radius: 13.8 };
const view = { ...defaultView };
const desiredView = { ...defaultView };
const hemi = new THREE.HemisphereLight(0xfff3d7, 0x6c513b, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffedc4, 3.25);
sun.position.set(-6, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0xbad8df, 1.15);
rimLight.position.set(8, 5, -7);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffb96f, 14, 16, 2);
warmFill.position.set(-4, 4, 2);
scene.add(warmFill);
const mat = (color, roughness = 0.86, extra = {}) =>
new THREE.MeshStandardMaterial({ color, roughness, ...extra });
const materials = {
soilTop: mat(0xb58a5c),
soilSide: mat(0x775039),
soilDark: mat(0x4b3222),
soilRim: mat(0x795137),
stone: mat(0x8f8069),
stoneLight: mat(0xb2a087),
branch: mat(0x5a3926),
squirrel: mat(0x8a4c2e),
squirrelDark: mat(0x633522),
squirrelLight: mat(0xb86a38),
cream: mat(0xe7c89a),
innerEar: mat(0xd7947e),
eye: mat(0x211b18, 0.28),
nose: mat(0x3a211c, 0.38),
nut: mat(0xc87832),
cap: mat(0x694127),
stem: mat(0x4b3020),
markerPole: mat(0x5a3c29),
markerBase: mat(0x6b4730),
orange: mat(0xc24c38, 0.72, { emissive: 0x6e1b12, emissiveIntensity: 0.12 }),
white: new THREE.MeshBasicMaterial({ color: 0xfff8e8 }),
glow: mat(0xf0bd61, 0.48, { emissive: 0xe29b32, emissiveIntensity: 0.75 })
};
let seed = 73421;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
function mesh(geometry, material, parent, position, scale, rotation) {
const object = new THREE.Mesh(geometry, material);
if (position) object.position.set(...position);
if (scale) object.scale.set(...scale);
if (rotation) object.rotation.set(...rotation);
object.castShadow = true;
object.receiveShadow = true;
if (parent) parent.add(object);
return object;
}
function cylinderBetween(parent, a, b, radius, material, radiusTop = radius) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const object = mesh(
new THREE.CylinderGeometry(radiusTop, radius, length, 12),
material,
parent,
[0, 0, 0]
);
object.position.copy(start).add(end).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return object;
}
function taperedTube(curve, segments, radialSegments, startRadius, endRadius) {
const frames = curve.computeFrenetFrames(segments, false);
const positions = [];
const colors = [];
const indices = [];
const baseColor = new THREE.Color(0x8a4b2b);
const tipColor = new THREE.Color(0xc17a40);
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const point = curve.getPointAt(t);
const radius = THREE.MathUtils.lerp(startRadius, endRadius, t) *
(0.92 + Math.sin(t * Math.PI) * 0.12);
const normal = frames.normals[i];
const binormal = frames.binormals[i];
const color = baseColor.clone().lerp(tipColor, THREE.MathUtils.smoothstep(t, 0.55, 1));
for (let j = 0; j <= radialSegments; j++) {
const angle = (j / radialSegments) * Math.PI * 2;
const vertex = point.clone()
.addScaledVector(normal, Math.cos(angle) * radius)
.addScaledVector(binormal, Math.sin(angle) * radius);
positions.push(vertex.x, vertex.y, vertex.z);
colors.push(color.r, color.g, color.b);
}
}
for (let i = 0; i < segments; i++) {
for (let j = 0; j < radialSegments; j++) {
const a = i * (radialSegments + 1) + j;
const b = (i + 1) * (radialSegments + 1) + j;
const c = (i + 1) * (radialSegments + 1) + j + 1;
const d = i * (radialSegments + 1) + j + 1;
indices.push(a, b, d, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
// Woodland diorama base.
const ground = mesh(
new THREE.CylinderGeometry(8.15, 8.5, 0.72, 80),
[materials.soilSide, materials.soilTop, materials.soilDark],
scene,
[0, -0.36, 0]
);
const groundRim = mesh(
new THREE.TorusGeometry(8.16, 0.09, 10, 80),
materials.soilSide,
scene,
[0, -0.035, 0],
null,
[Math.PI / 2, 0, 0]
);
const backdrop = mesh(
new THREE.PlaneGeometry(80, 80),
mat(0xd9cdb5),
scene,
[0, -0.73, 0],
null,
[-Math.PI / 2, 0, 0]
);
backdrop.castShadow = false;
// Scattered stones.
for (let i = 0; i < 38; i++) {
const angle = random() * Math.PI * 2;
const radius = 2.2 + random() * 5.2;
const size = 0.06 + random() * 0.15;
mesh(
new THREE.DodecahedronGeometry(size, 0),
random() > 0.5 ? materials.stone : materials.stoneLight,
scene,
[Math.cos(angle) * radius, 0.05 + size * 0.25, Math.sin(angle) * radius],
[1, 0.55 + random() * 0.3, 0.85 + random() * 0.5],
[random(), random() * Math.PI, random()]
);
}
// A small fallen branch.
const branch = new THREE.Group();
branch.position.set(-5.7, 0.08, -0.4);
branch.rotation.y = 0.45;
scene.add(branch);
cylinderBetween(branch, [0, 0, 0], [1.65, 0.04, 0.15], 0.09, materials.branch, 0.055);
cylinderBetween(branch, [0.82, 0.03, 0.08], [1.32, 0.27, 0.31], 0.045, materials.branch, 0.018);
// Procedural leaves.
function makeLeaf(color, x, z, scale, rotation) {
const group = new THREE.Group();
group.position.set(x, 0.045, z);
group.rotation.set((random() - 0.5) * 0.12, rotation, (random() - 0.5) * 0.08);
group.scale.setScalar(scale);
const shape = new THREE.Shape();
shape.moveTo(0, -0.66);
shape.bezierCurveTo(0.42, -0.38, 0.52, 0.2, 0, 0.72);
shape.bezierCurveTo(-0.52, 0.2, -0.42, -0.38, 0, -0.66);
const leaf = mesh(
new THREE.ShapeGeometry(shape, 8),
mat(color),
group,
[0, 0, 0]
);
leaf.rotation.x = -Math.PI / 2;
leaf.castShadow = true;
const veinGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.015, -0.55),
new THREE.Vector3(0, 0.015, 0.58)
]);
const vein = new THREE.Line(
veinGeometry,
new THREE.LineBasicMaterial({ color: 0x76502c, transparent: true, opacity: 0.42 })
);
group.add(vein);
scene.add(group);
}
const leafColors = [0xb96a36, 0xc28a45, 0x7d8249, 0x9f6531, 0xb8a05c];
for (let i = 0; i < 24; i++) {
const angle = random() * Math.PI * 2;
const radius = 2.8 + random() * 4.8;
makeLeaf(
leafColors[Math.floor(random() * leafColors.length)],
Math.cos(angle) * radius,
Math.sin(angle) * radius,
0.65 + random() * 0.65,
random() * Math.PI * 2
);
}
// Acorn construction.
function makeAcorn(scale = 1) {
const group = new THREE.Group();
group.scale.setScalar(scale);
mesh(
new THREE.SphereGeometry(0.42, 18, 14),
materials.nut,
group,
[0, 0, 0],
[0.88, 1.08, 0.88]
);
mesh(
new THREE.SphereGeometry(0.405, 18, 8, 0, Math.PI * 2, 0, Math.PI / 2),
materials.cap,
group,
[0, 0.18, 0],
[1, 0.72, 1]
);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
mesh(
new THREE.BoxGeometry(0.022, 0.18, 0.025),
materials.soilDark,
group,
[Math.cos(angle) * 0.31, 0.31, Math.sin(angle) * 0.31],
null,
[0, -angle, 0]
);
}
cylinderBetween(group, [0, 0.43, 0], [0.025, 0.66, 0], 0.045, materials.stem, 0.032);
group.rotation.z = 0.08;
group.rotation.x = -0.08;
return group;
}
const looseAcorns = [];
[
[0.05, 1.45, 0.86],
[2.72, 0.63, 0.79],
[-2.7, 2.55, 0.68]
].forEach(([x, z, scale], index) => {
const acorn = makeAcorn(scale);
acorn.position.set(x, 0.36 * scale, z);
acorn.rotation.y = index * 1.8;
scene.add(acorn);
looseAcorns.push(acorn);
});
// Stylized squirrel.
const squirrel = new THREE.Group();
squirrel.position.set(1.55, 0, 0.45);
squirrel.rotation.y = -0.24;
scene.add(squirrel);
const tailCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0.56, 0.66, 0.28),
new THREE.Vector3(1.28, 0.72, 0.36),
new THREE.Vector3(1.83, 1.35, 0.42),
new THREE.Vector3(2.02, 2.25, 0.45),
new THREE.Vector3(1.69, 3.18, 0.43),
new THREE.Vector3(1.03, 3.57, 0.39),
new THREE.Vector3(0.56, 3.18, 0.36)
]);
const tailMaterial = mat(0xffffff);
tailMaterial.vertexColors = true;
mesh(taperedTube(tailCurve, 52, 14, 0.61, 0.20), tailMaterial, squirrel);
mesh(
new THREE.SphereGeometry(1, 28, 22),
materials.squirrel,
squirrel,
[0, 1.34, 0],
[0.88, 1.25, 0.70],
[0.12, 0, 0]
);
mesh(
new THREE.SphereGeometry(1, 24, 18),
materials.cream,
squirrel,
[0, 1.24, -0.58],
[0.61, 0.86, 0.18]
);
// Hind legs and broad feet.
[-1, 1].forEach((side) => {
mesh(
new THREE.SphereGeometry(1, 20, 16),
materials.squirrelDark,
squirrel,
[side * 0.51, 0.52, 0.05],
[0.46, 0.52, 0.47]
);
mesh(
new THREE.SphereGeometry(1, 18, 14),
materials.squirrel,
squirrel,
[side * 0.46, 0.21, -0.35],
[0.29, 0.18, 0.58]
);
});
// Head and muzzle.
mesh(
new THREE.SphereGeometry(1, 28, 22),
materials.squirrel,
squirrel,
[0, 2.53, -0.52],
[0.79, 0.81, 0.72],
[-0.08, 0, 0]
);
mesh(
new THREE.SphereGeometry(1, 24, 18),
materials.cream,
squirrel,
[0, 2.37, -1.05],
[0.59, 0.42, 0.31]
);
[-1, 1].forEach((side) => {
mesh(
new THREE.SphereGeometry(1, 20, 14),
materials.cream,
squirrel,
[side * 0.32, 2.43, -1.10],
[0.30, 0.26, 0.16]
);
});
// Ears.
[-1, 1].forEach((side) => {
const ear = new THREE.Group();
ear.position.set(side * 0.49, 3.31, -0.40);
ear.rotation.z = side * -0.13;
squirrel.add(ear);
mesh(
new THREE.ConeGeometry(0.31, 0.78, 4),
materials.squirrel,
ear,
[0, 0, 0],
[1, 1, 0.72],
[0, Math.PI / 4, 0]
);
mesh(
new THREE.ConeGeometry(0.19, 0.54, 4),
materials.innerEar,
ear,
[0, -0.02, -0.17],
[1, 1, 0.65],
[0, Math.PI / 4, 0]
);
});
// Eyes, highlights, and nose.
[-1, 1].forEach((side) => {
mesh(
new THREE.SphereGeometry(0.155, 18, 14),
materials.eye,
squirrel,
[side * 0.34, 2.69, -1.075],
[1, 1.1, 0.62]
);
mesh(
new THREE.SphereGeometry(0.044, 12, 8),
materials.white,
squirrel,
[side * 0.34 - 0.035, 2.735, -1.165],
[1, 1, 0.45]
);
mesh(
new THREE.SphereGeometry(0.018, 10, 8),
materials.white,
squirrel,
[side * 0.34 + 0.04, 2.64, -1.168],
[1, 1, 0.45]
);
});
mesh(
new THREE.SphereGeometry(0.115, 16, 12),
materials.nose,
squirrel,
[0, 2.48, -1.345],
[1.15, 0.82, 0.76]
);
const smileCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.19, 2.37, -1.31),
new THREE.Vector3(0, 2.285, -1.35),
new THREE.Vector3(0.19, 2.37, -1.31)
]);
mesh(
new THREE.TubeGeometry(smileCurve, 18, 0.012, 5, false),
materials.nose,
squirrel
);
// Whiskers.
[-1, 1].forEach((side) => {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(side * 0.41, 2.41, -1.19),
new THREE.Vector3(side * 0.83, 2.46, -1.12)
]);
squirrel.add(new THREE.Line(
geometry,
new THREE.LineBasicMaterial({ color: 0x4c3325, transparent: true, opacity: 0.68 })
));
});
// Front arms and paws.
[-1, 1].forEach((side) => {
cylinderBetween(
squirrel,
[side * 0.42, 1.78, -0.48],
[side * 0.40, 0.98, -0.64],
0.14,
materials.squirrel,
0.105
);
mesh(
new THREE.SphereGeometry(1, 16, 12),
materials.cream,
squirrel,
[side * 0.39, 0.93, -0.69],
[0.16, 0.15, 0.19]
);
});
// A few fur tufts along the tail edge.
for (let i = 0; i < 8; i++) {
const t = 0.12 + (i / 7) * 0.73;
const point = tailCurve.getPointAt(t);
const outward = new THREE.Vector3(0.55, 0.12, 0).applyAxisAngle(
new THREE.Vector3(0, 1, 0),
(t - 0.5) * 1.4
).normalize();
mesh(
new THREE.ConeGeometry(0.16, 0.42, 5),
materials.squirrelLight,
squirrel,
[point.x + outward.x * 0.48, point.y + outward.y * 0.48, point.z],
[1, 1, 0.7],
[0, 0, -0.35]
);
}
// Cache pockets and removable markers.
const pocketDefinitions = [
{ x: -3.15, z: 1.35, rx: 0.78, rz: 0.56, rotation: 0.20 },
{ x: -1.45, z: -1.85, rx: 0.70, rz: 0.50, rotation: -0.35 },
{ x: 0.10, z: -3.05, rx: 0.84, rz: 0.58, rotation: 0.10 },
{ x: 3.45, z: -1.65, rx: 0.70, rz: 0.52, rotation: 0.40 },
{ x: -4.25, z: -1.35, rx: 0.64, rz: 0.47, rotation: -0.20 }
];
const markers = [];
const markerTargets = [];
function createMarker(pocket, index) {
const group = new THREE.Group();
const basePosition = new THREE.Vector3(
pocket.x + pocket.rx * 0.75,
0.045,
pocket.z + 0.04
);
group.position.copy(basePosition);
group.rotation.y = -0.05 + index * 0.02;
scene.add(group);
const poleMaterial = materials.markerPole.clone();
const flagMaterial = materials.orange.clone();
const baseMaterial = materials.markerBase.clone();
mesh(
new THREE.CylinderGeometry(0.13, 0.16, 0.07, 16),
baseMaterial,
group,
[0, 0.035, 0]
);
mesh(
new THREE.CylinderGeometry(0.026, 0.036, 0.96, 10),
poleMaterial,
group,
[0, 0.50, 0]
);
const flagGeometry = new THREE.BufferGeometry();
flagGeometry.setAttribute("position", new THREE.Float32BufferAttribute([
0, 0, 0,
0.74, -0.12, 0,
0, -0.46, 0
], 3));
flagGeometry.computeVertexNormals();
const flag = mesh(
flagGeometry,
flagMaterial,
group,
[0, 0.94, 0]
);
flag.material.side = THREE.DoubleSide;
const crossA = mesh(
new THREE.BoxGeometry(0.035, 0.20, 0.025),
materials.white,
group,
[0.26, 0.72, 0.025],
null,
[0, 0, 0.67]
);
const crossB = mesh(
new THREE.BoxGeometry(0.035, 0.20, 0.025),
materials.white,
group,
[0.26, 0.72, 0.025],
null,
[0, 0, -0.67]
);
const hitArea = mesh(
new THREE.SphereGeometry(0.43, 12, 8),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
}),
group,
[0.25, 0.67, 0]
);
hitArea.castShadow = false;
hitArea.receiveShadow = false;
const marker = {
index,
group,
pocket,
basePosition,
flagMaterial,
poleMaterial,
baseMaterial,
removed: false,
removing: false,
removalTime: 0,
hover: false
};
group.traverse((object) => {
if (object.isMesh) {
object.userData.marker = marker;
markerTargets.push(object);
}
});
markers.push(marker);
return marker;
}
pocketDefinitions.forEach((definition, index) => {
const pocketGroup = new THREE.Group();
pocketGroup.position.set(definition.x, 0, definition.z);
pocketGroup.rotation.y = definition.rotation;
scene.add(pocketGroup);
const cavity = mesh(
new THREE.CircleGeometry(1, 48),
materials.soilDark,
pocketGroup,
[0, 0.025, 0],
[definition.rx, definition.rz, 1],
[-Math.PI / 2, 0, 0]
);
cavity.castShadow = false;
const ringShape = new THREE.Shape();
ringShape.absellipse(
0, 0,
definition.rx + 0.13,
definition.rz + 0.13,
0, Math.PI * 2, false
);
const hole = new THREE.Path();
hole.absellipse(
0, 0,
definition.rx * 0.91,
definition.rz * 0.91,
0, Math.PI * 2, true
);
ringShape.holes.push(hole);
mesh(
new THREE.ShapeGeometry(ringShape, 48),
materials.soilRim,
pocketGroup,
[0, 0.043, 0],
null,
[-Math.PI / 2, 0, 0]
);
// Uneven soil around the pocket.
for (let i = 0; i < 10; i++) {
const angle = (i / 10) * Math.PI * 2 + random() * 0.18;
mesh(
new THREE.DodecahedronGeometry(0.09 + random() * 0.055, 0),
i % 2 ? materials.soilRim : materials.soilTop,
pocketGroup,
[
Math.cos(angle) * (definition.rx + 0.08),
0.055,
Math.sin(angle) * (definition.rz + 0.08)
],
[1.2, 0.5, 0.8],
[random(), random(), random()]
);
}
const acorn = makeAcorn(0.86);
acorn.visible = false;
pocketGroup.add(acorn);
const sparkleGroup = new THREE.Group();
pocketGroup.add(sparkleGroup);
const sparkles = [];
for (let i = 0; i < 9; i++) {
const sparkle = mesh(
new THREE.IcosahedronGeometry(0.035 + random() * 0.025, 0),
materials.glow,
sparkleGroup,
[0, 0, 0]
);
sparkle.visible = false;
sparkles.push({
mesh: sparkle,
angle: random() * Math.PI * 2,
radius: 0.2 + random() * 0.55,
height: 0.25 + random() * 0.5,
delay: random() * 0.35
});
}
const marker = createMarker(definition, index);
definition.pocketGroup = pocketGroup;
definition.acorn = acorn;
definition.sparkleGroup = sparkleGroup;
definition.sparkles = sparkles;
definition.reveal = 0;
definition.revealed = false;
marker.pocket = definition;
});
// Fine airborne dust.
const dustCount = 130;
const dustPositions = new Float32Array(dustCount * 3);
const dustSeeds = [];
for (let i = 0; i < dustCount; i++) {
const x = (random() - 0.5) * 18;
const y = 0.4 + random() * 5;
const z = (random() - 0.5) * 16;
dustPositions.set([x, y, z], i * 3);
dustSeeds.push({ x, y, z, phase: random() * Math.PI * 2 });
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xffe7ae,
size: 0.045,
transparent: true,
opacity: 0.48,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(dust);
let uncovered = 0;
let statusTimer;
function updateCounter() {
cacheCount.textContent = String(uncovered);
cacheTotal.textContent = `of ${markers.length} found`;
counterFill.style.width = `${(uncovered / markers.length) * 100}%`;
}
function showStatus(message) {
status.textContent = message;
status.classList.add("show");
clearTimeout(statusTimer);
statusTimer = setTimeout(() => status.classList.remove("show"), 2200);
}
function revealPocket(pocket) {
if (pocket.revealed) return;
pocket.revealed = true;
pocket.reveal = 0;
pocket.acorn.visible = true;
pocket.acorn.position.y = -0.38;
pocket.acorn.scale.setScalar(0.86);
uncovered++;
updateCounter();
}
function removeMarker(marker) {
if (marker.removed || marker.removing) return;
marker.removing = true;
marker.removalTime = 0;
revealPocket(marker.pocket);
showStatus(marker.removed ? "Cache uncovered" : "Marker removed — cache uncovered");
}
function restoreAll() {
markers.forEach((marker) => {
marker.removed = false;
marker.removing = false;
marker.removalTime = 0;
marker.group.visible = true;
marker.group.position.copy(marker.basePosition);
marker.group.scale.setScalar(1);
marker.group.rotation.set(0, marker.group.rotation.y, 0);
const pocket = marker.pocket;
pocket.revealed = false;
pocket.reveal = 0;
pocket.acorn.visible = false;
pocket.sparkles.forEach((sparkle) => {
sparkle.mesh.visible = false;
});
});
uncovered = 0;
updateCounter();
showStatus("All markers restored");
}
document.querySelector("#remove-all").addEventListener("click", () => {
markers.forEach((marker, index) => {
setTimeout(() => removeMarker(marker), index * 90);
});
});
document.querySelector("#restore").addEventListener("click", restoreAll);
document.querySelector("#reset-view").addEventListener("click", () => {
Object.assign(desiredView, defaultView);
showStatus("View reset");
});
// Raycasting and direct camera controls.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointers = new Map();
let dragged = false;
let pinchDistance = 0;
function setPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function findMarker(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(markerTargets, false);
for (const hit of hits) {
const marker = hit.object.userData.marker;
if (marker && marker.group.visible && !marker.removed) return marker;
}
return null;
}
function setHover(marker) {
markers.forEach((item) => {
item.hover = item === marker;
item.flagMaterial.emissiveIntensity = item.hover ? 0.65 : 0.12;
item.flagMaterial.color.set(item.hover ? 0xdf654b : 0xc24c38);
});
canvas.style.cursor = marker ? "pointer" : "grab";
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragged = false;
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) {
setHover(findMarker(event));
return;
}
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size === 1) {
if (Math.abs(dx) + Math.abs(dy) > 0) dragged = true;
desiredView.azimuth -= dx * 0.006;
desiredView.polar = THREE.MathUtils.clamp(
desiredView.polar + dy * 0.005,
0.55,
1.43
);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0 && distance > 0) {
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius * (pinchDistance / distance),
8.5,
20
);
}
pinchDistance = distance;
}
});
function endPointer(event) {
if (pointers.size === 1 && !dragged) {
const marker = findMarker(event);
if (marker) removeMarker(marker);
}
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
if (pointers.size === 0) {
dragged = false;
canvas.style.cursor = "grab";
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
desiredView.radius = THREE.MathUtils.clamp(
desiredView.radius * Math.exp(event.deltaY * 0.001),
8.5,
20
);
}, { passive: false });
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") restoreAll();
if (event.key.toLowerCase() === "m") {
markers.forEach((marker, index) => setTimeout(() => removeMarker(marker), index * 80));
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
const tempCameraPosition = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
// Smooth camera movement.
view.azimuth = THREE.MathUtils.damp(view.azimuth, desiredView.azimuth, 8, dt);
view.polar = THREE.MathUtils.damp(view.polar, desiredView.polar, 8, dt);
view.radius = THREE.MathUtils.damp(view.radius, desiredView.radius, 8, dt);
const sinPolar = Math.sin(view.polar);
tempCameraPosition.set(
cameraTarget.x + view.radius * sinPolar * Math.sin(view.azimuth),
cameraTarget.y + view.radius * Math.cos(view.polar),
cameraTarget.z + view.radius * sinPolar * Math.cos(view.azimuth)
);
camera.position.copy(tempCameraPosition);
camera.lookAt(cameraTarget);
// Gentle life in the scene.
squirrel.position.y = Math.sin(elapsed * 1.65) * 0.018;
squirrel.rotation.z = Math.sin(elapsed * 0.8) * 0.006;
looseAcorns.forEach((acorn, index) => {
acorn.rotation.y += dt * (index % 2 ? 0.035 : -0.025);
});
// Marker removal animation.
markers.forEach((marker) => {
if (!marker.removing) return;
marker.removalTime += dt;
const t = Math.min(marker.removalTime / 0.55, 1);
const eased = 1 - Math.pow(1 - t, 3);
marker.group.position.y = marker.basePosition.y + eased * 1.15;
marker.group.scale.setScalar(Math.max(0.001, 1 - eased));
marker.group.rotation.z = eased * 0.7;
if (t >= 1) {
marker.removing = false;
marker.removed = true;
marker.group.visible = false;
}
});
// Cache reveal animation.
pocketDefinitions.forEach((pocket) => {
if (!pocket.revealed) return;
pocket.reveal = Math.min(1, pocket.reveal + dt / 0.85);
const t = pocket.reveal;
const overshoot = 1 + 2.2 * Math.pow(t - 1, 3) + 1.2 * Math.pow(t - 1, 2);
pocket.acorn.position.y = THREE.MathUtils.lerp(-0.38, 0.38, overshoot);
pocket.acorn.rotation.y = -0.45 + t * 0.75;
pocket.sparkles.forEach((sparkle) => {
const local = THREE.MathUtils.clamp((t - sparkle.delay) / 0.65, 0, 1);
sparkle.mesh.visible = local > 0 && local < 1;
sparkle.mesh.position.set(
Math.cos(sparkle.angle) * sparkle.radius * local,
0.12 + local * sparkle.height,
Math.sin(sparkle.angle) * sparkle.radius * local
);
const size = Math.sin(local * Math.PI);
sparkle.mesh.scale.setScalar(Math.max(0.001, size));
});
});
// Floating dust.
const positions = dustGeometry.attributes.position.array;
dustSeeds.forEach((particle, index) => {
positions[index * 3] = particle.x + Math.sin(elapsed * 0.19 + particle.phase) * 0.13;
positions[index * 3 + 1] = particle.y + Math.sin(elapsed * 0.27 + particle.phase) * 0.10;
positions[index * 3 + 2] = particle.z + Math.cos(elapsed * 0.16 + particle.phase) * 0.11;
});
dustGeometry.attributes.position.needsUpdate = true;
renderer.render(scene, camera);
}
updateCounter();
animate();
</script>
</body>
</html>
```