Prompt specification
Build or customize the Three.js 3D scene "Animal Proxy Crosses a Connected Hedgerow" 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: Animal Proxy Crosses a Connected Hedgerow
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/animal-proxy-crosses-a-connected-hedgerow-x3942
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: animal proxy crosses a connected hedgerow. Animate an original small-animal proxy following connected cover under an explicit toy movement rule. Show the route failing when a gap exceeds the declared threshold. Return one self-contained HTML file.
Working Three.js Starter (animal-proxy-crosses-a-connected-hedgerow-x3942):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<title>Pip & the Broken Hedge — Voxel Cover Lab</title>
<style>
:root {
--ink: #25352d;
--muted: #68756d;
--paper: rgba(255, 253, 247, 0.94);
--line: rgba(37, 53, 45, 0.13);
--green: #2f7250;
--green-soft: #e4efe5;
--gold: #e7a62f;
--gold-soft: #fff0cb;
--red: #c94a43;
--red-soft: #fde8e5;
--shadow: 0 18px 50px rgba(49, 58, 50, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #f2efe7;
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;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 22px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 24px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(15px);
pointer-events: auto;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--green);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 3px;
border-radius: 4px;
background: var(--gold);
}
h1 {
margin: 0;
font-size: clamp(27px, 3vw, 37px);
line-height: 1.03;
letter-spacing: -0.045em;
}
.intro {
margin: 12px 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.rule {
display: grid;
grid-template-columns: auto 1fr;
gap: 11px;
align-items: center;
margin-bottom: 16px;
padding: 12px 13px;
border: 1px solid #dce6da;
border-radius: 15px;
background: var(--green-soft);
}
.rule-icon {
display: grid;
place-items: center;
width: 34px;
height: 34px;
border-radius: 10px;
color: white;
background: var(--green);
font-size: 18px;
font-weight: 900;
}
.rule strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.rule span {
display: block;
color: #53665a;
font-size: 12px;
line-height: 1.42;
}
.status {
padding: 14px;
border: 1px solid var(--line);
border-radius: 17px;
background: rgba(255, 255, 255, 0.68);
}
.status-top {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #9aa39d;
box-shadow: 0 0 0 4px rgba(154, 163, 157, 0.14);
}
.dot.running {
background: var(--gold);
box-shadow: 0 0 0 4px rgba(231, 166, 47, 0.15);
animation: pulse 1s ease-in-out infinite;
}
.dot.failed {
background: var(--red);
box-shadow: 0 0 0 4px rgba(201, 74, 67, 0.14);
}
.dot.success {
background: var(--green);
box-shadow: 0 0 0 4px rgba(47, 114, 80, 0.14);
}
#stepLabel {
margin-left: auto;
color: #879189;
letter-spacing: 0.04em;
}
#statusTitle {
margin: 9px 0 5px;
font-size: 16px;
letter-spacing: -0.015em;
}
#statusDetail {
min-height: 34px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.progress {
height: 6px;
margin-top: 13px;
overflow: hidden;
border-radius: 99px;
background: #e9ebe6;
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--green), #6d9b58);
transition: width 220ms ease;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 10px 0 14px;
}
.metric {
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.52);
}
.metric small {
display: block;
margin-bottom: 4px;
color: #8a938c;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric b {
font-size: 12px;
letter-spacing: 0.02em;
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
}
.actions button {
min-height: 44px;
border: 0;
border-radius: 13px;
cursor: pointer;
transition: transform 150ms ease, box-shadow 150ms ease, opacity 150ms ease;
}
.actions button:hover:not(:disabled) {
transform: translateY(-1px);
}
.actions button:active:not(:disabled) {
transform: translateY(1px);
}
.actions button:disabled {
cursor: wait;
opacity: 0.62;
}
#primaryButton {
padding: 0 16px;
color: white;
background: var(--green);
box-shadow: 0 8px 18px rgba(47, 114, 80, 0.22);
font-size: 13px;
font-weight: 800;
}
#primaryButton.detour {
color: #2a4938;
background: #dcebcf;
box-shadow: 0 8px 18px rgba(47, 114, 80, 0.14);
}
#resetButton {
width: 46px;
color: var(--ink);
background: #eceee9;
font-size: 19px;
}
.threshold {
position: absolute;
top: 22px;
right: 22px;
padding: 11px 14px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 15px;
background: var(--paper);
box-shadow: 0 10px 30px rgba(49, 58, 50, 0.11);
backdrop-filter: blur(12px);
pointer-events: auto;
text-align: right;
}
.threshold small {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.threshold b {
display: block;
margin-top: 2px;
color: var(--green);
font-size: 18px;
letter-spacing: -0.03em;
}
.legend {
position: absolute;
left: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
gap: 13px;
max-width: 380px;
padding: 11px 14px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 15px;
background: var(--paper);
box-shadow: 0 10px 30px rgba(49, 58, 50, 0.1);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
white-space: nowrap;
}
.swatch {
width: 18px;
height: 4px;
border-radius: 9px;
background: var(--green);
}
.swatch.route { background: var(--gold); }
.swatch.bad { background: var(--red); }
.camera-help {
position: absolute;
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 10px;
padding: 8px 9px 8px 13px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 15px;
background: var(--paper);
box-shadow: 0 10px 30px rgba(49, 58, 50, 0.1);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.camera-help span {
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
#viewButton {
width: 34px;
height: 34px;
border: 0;
border-radius: 10px;
color: var(--green);
background: var(--green-soft);
cursor: pointer;
font-size: 17px;
}
.toast {
position: absolute;
top: 22px;
left: 50%;
min-width: 285px;
padding: 13px 17px;
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 16px;
background: rgba(255, 253, 247, 0.96);
box-shadow: var(--shadow);
opacity: 0;
transform: translate(-50%, -18px);
transition: opacity 220ms ease, transform 220ms ease;
pointer-events: none;
text-align: center;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.toast.error { border-color: rgba(201, 74, 67, 0.32); }
.toast.success { border-color: rgba(47, 114, 80, 0.3); }
.toast b {
display: block;
margin-bottom: 3px;
color: var(--red);
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.toast.success b { color: var(--green); }
.toast span {
color: var(--muted);
font-size: 11px;
}
@keyframes pulse {
50% { transform: scale(0.72); opacity: 0.65; }
}
@media (max-width: 760px) {
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 49vh;
overflow-y: auto;
padding: 17px;
border-radius: 20px;
}
h1 { font-size: 26px; }
.intro { margin: 9px 0 12px; }
.rule { margin-bottom: 12px; padding: 9px 11px; }
.status { padding: 11px; }
.metrics { margin: 8px 0 11px; }
.legend { display: none; }
.threshold {
top: 12px;
right: 12px;
padding: 9px 11px;
}
.camera-help {
top: 12px;
left: 12px;
right: auto;
bottom: auto;
}
.camera-help span { display: none; }
.toast {
top: 79px;
min-width: 250px;
max-width: calc(100vw - 28px);
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel scene of Pip testing a route across a connected hedgerow"></canvas>
<div id="ui">
<section class="panel" aria-label="Route controls and movement rule">
<div class="eyebrow">Voxel Cover Lab · 01</div>
<h1>Pip & the broken hedge</h1>
<p class="intro">
Pip is a tiny sprig-mouse proxy. The short route crosses a break, while a legal
eastern loop keeps the hedgerow connected.
</p>
<div class="rule">
<div class="rule-icon">↗</div>
<div>
<strong>Toy movement rule</strong>
<span>Move one cardinal cover tile at a time. Center-to-center gap must be ≤ 1.20u.</span>
</div>
</div>
<div class="status" aria-live="polite">
<div class="status-top">
<span id="stateDot" class="dot"></span>
<span id="phaseLabel">Ready</span>
<span id="stepLabel">0 / 11</span>
</div>
<h2 id="statusTitle">Direct route armed</h2>
<p id="statusDetail">The marked shortcut contains one break. Pip is ready to test it.</p>
<div class="progress"><div id="progressFill"></div></div>
</div>
<div class="metrics">
<div class="metric">
<small>Active route</small>
<b id="routeValue">DIRECT</b>
</div>
<div class="metric">
<small>Maximum gap</small>
<b>1.20u</b>
</div>
</div>
<div class="actions">
<button id="primaryButton" type="button">Run direct route</button>
<button id="resetButton" type="button" title="Reset route" aria-label="Reset route">↺</button>
</div>
</section>
<div class="threshold">
<small>Declared move limit</small>
<b>1.20u</b>
</div>
<div class="legend" aria-label="Scene legend">
<div class="legend-item"><span class="swatch"></span>connected cover</div>
<div class="legend-item"><span class="swatch route"></span>planned route</div>
<div class="legend-item"><span class="swatch bad"></span>rejected gap</div>
</div>
<div class="camera-help">
<span>Drag to orbit · wheel to zoom</span>
<button id="viewButton" type="button" title="Reset camera" aria-label="Reset camera">⌂</button>
</div>
<div id="toast" class="toast" role="status">
<b id="toastTitle"></b>
<span id="toastDetail"></span>
</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 primaryButton = document.querySelector("#primaryButton");
const resetButton = document.querySelector("#resetButton");
const viewButton = document.querySelector("#viewButton");
const stateDot = document.querySelector("#stateDot");
const phaseLabel = document.querySelector("#phaseLabel");
const stepLabel = document.querySelector("#stepLabel");
const statusTitle = document.querySelector("#statusTitle");
const statusDetail = document.querySelector("#statusDetail");
const progressFill = document.querySelector("#progressFill");
const routeValue = document.querySelector("#routeValue");
const toast = document.querySelector("#toast");
const toastTitle = document.querySelector("#toastTitle");
const toastDetail = document.querySelector("#toastDetail");
const MAX_GAP = 1.20;
const BASE_Y = 0.145;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf2efe7);
scene.fog = new THREE.Fog(0xf2efe7, 19, 37);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 80);
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const hemisphere = new THREE.HemisphereLight(0xfff8df, 0x718277, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2cf, 3.0);
sun.position.set(-7, 14, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0005;
scene.add(sun);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = {
ground: new THREE.MeshStandardMaterial({ color: 0xeeeadd, roughness: 1, flatShading: true }),
base: new THREE.MeshStandardMaterial({ color: 0xd9d3c3, roughness: 0.95, flatShading: true }),
path: new THREE.MeshStandardMaterial({ color: 0xb9b875, roughness: 0.96, flatShading: true }),
pathLight: new THREE.MeshStandardMaterial({ color: 0xc8c487, roughness: 0.96, flatShading: true }),
hedgeA: new THREE.MeshStandardMaterial({ color: 0x3f7548, roughness: 0.88, flatShading: true }),
hedgeB: new THREE.MeshStandardMaterial({ color: 0x4d844d, roughness: 0.9, flatShading: true }),
hedgeC: new THREE.MeshStandardMaterial({ color: 0x315f40, roughness: 0.9, flatShading: true }),
hedgeTop: new THREE.MeshStandardMaterial({ color: 0x6b974f, roughness: 0.88, flatShading: true }),
trunk: new THREE.MeshStandardMaterial({ color: 0x74523b, roughness: 0.95, flatShading: true }),
leafA: new THREE.MeshStandardMaterial({ color: 0x5f8c4d, roughness: 0.9, flatShading: true }),
leafB: new THREE.MeshStandardMaterial({ color: 0x789d55, roughness: 0.9, flatShading: true }),
rock: new THREE.MeshStandardMaterial({ color: 0x9c9a8e, roughness: 1, flatShading: true }),
straw: new THREE.MeshStandardMaterial({ color: 0xd6b65c, roughness: 0.95, flatShading: true }),
oat: new THREE.MeshStandardMaterial({ color: 0xe4bd57, roughness: 0.9, flatShading: true }),
dark: new THREE.MeshStandardMaterial({ color: 0x283129, roughness: 0.75, flatShading: true }),
fur: new THREE.MeshStandardMaterial({ color: 0xb87943, roughness: 0.88, flatShading: true }),
furDark: new THREE.MeshStandardMaterial({ color: 0x8e5738, roughness: 0.88, flatShading: true }),
cream: new THREE.MeshStandardMaterial({ color: 0xf2dfb6, roughness: 0.86, flatShading: true }),
leafTuft: new THREE.MeshStandardMaterial({ color: 0x5b8d43, roughness: 0.9, flatShading: true })
};
function box(parent, w, h, d, x, y, z, material, shadow = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function textSprite(lines, options = {}) {
const width = options.width || 512;
const height = options.height || 144;
const c = document.createElement("canvas");
c.width = width;
c.height = height;
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, width, height);
if (options.background !== "transparent") {
ctx.fillStyle = options.background || "#fffdf6";
roundedRect(ctx, 5, 5, width - 10, height - 10, 24);
ctx.fill();
ctx.strokeStyle = options.border || "#d9dfd6";
ctx.lineWidth = 5;
ctx.stroke();
}
const array = Array.isArray(lines) ? lines : [lines];
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = options.color || "#2f7250";
const lineHeight = options.lineHeight || 42;
const startY = height / 2 - ((array.length - 1) * lineHeight) / 2;
array.forEach((line, i) => {
ctx.font = options.font || "800 35px system-ui, sans-serif";
ctx.fillText(line, width / 2, startY + i * lineHeight);
});
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: options.depthTest ?? false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(options.scaleX || 2.1, options.scaleY || 0.59, 1);
sprite.renderOrder = 20;
return sprite;
}
// Diorama ground.
const ground = new THREE.Mesh(new THREE.PlaneGeometry(30, 24), materials.ground);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.015;
ground.receiveShadow = true;
scene.add(ground);
box(scene, 16.5, 0.36, 14.2, -0.3, -0.22, 2.1, materials.base);
const grid = new THREE.GridHelper(22, 22, 0xc9c6bd, 0xdedbd2);
grid.position.set(-0.3, 0.002, 2.1);
grid.material.transparent = true;
grid.material.opacity = 0.36;
scene.add(grid);
// Cover nodes. The direct route intentionally contains a 2.00u break.
const nodes = {
nest: { x: -3, z: 7, type: "nest" },
n1: { x: -3, z: 6 },
n2: { x: -3, z: 5 },
edge: { x: -3, z: 4 },
after: { x: -3, z: 2 },
n4: { x: -3, z: 1 },
n5: { x: -3, z: 0 },
n6: { x: -3, z: -1 },
n7: { x: -3, z: -2 },
n8: { x: -2, z: -2 },
goal: { x: -1, z: -2, type: "goal" },
r1: { x: -2, z: 4 },
r2: { x: -1, z: 4 },
r3: { x: 0, z: 4 },
r4: { x: 1, z: 4 },
r5: { x: 2, z: 4 },
r6: { x: 2, z: 3 },
r7: { x: 2, z: 2 },
r8: { x: 1, z: 2 },
r9: { x: 0, z: 2 },
r10:{ x: -1, z: 2 },
r11:{ x: -2, z: 2 }
};
const directRoute = [
"nest", "n1", "n2", "edge", "after", "n4", "n5", "n6", "n7", "n8", "goal"
];
const detourRoute = [
"nest", "n1", "n2", "edge",
"r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11",
"after", "n4", "n5", "n6", "n7", "n8", "goal"
];
function nodeDistance(a, b) {
return Math.hypot(nodes[a].x - nodes[b].x, nodes[a].z - nodes[b].z);
}
function legalMove(a, b) {
const dx = Math.abs(nodes[a].x - nodes[b].x);
const dz = Math.abs(nodes[a].z - nodes[b].z);
const cardinal = (dx < 0.0001 && dz > 0.0001) || (dz < 0.0001 && dx > 0.0001);
return cardinal && nodeDistance(a, b) <= MAX_GAP + 0.0001;
}
function hashString(s) {
let h = 0;
for (let i = 0; i < s.length; i++) h = (h * 31 + s.charCodeAt(i)) | 0;
return Math.abs(h);
}
const hedgeGroups = new Map();
function createCoverNode(id, node) {
const group = new THREE.Group();
group.position.set(node.x, 0, node.z);
scene.add(group);
hedgeGroups.set(id, group);
const h = hashString(id);
box(group, 0.78, 0.10, 0.78, 0, 0.055, 0, (h & 1) ? materials.path : materials.pathLight);
box(group, 0.36, 0.025, 0.36, 0, 0.115, 0, materials.pathLight, false);
const offsets = [
[-0.39, -0.39], [0.39, -0.39],
[-0.39, 0.39], [0.39, 0.39]
];
offsets.forEach(([x, z], i) => {
const palette = [materials.hedgeA, materials.hedgeB, materials.hedgeC];
const mat = palette[(h + i) % palette.length];
const height = 0.59 + ((h + i * 3) % 4) * 0.035;
box(group, 0.37, height, 0.37, x, 0.02 + height / 2, z, mat);
if ((h + i) % 3 !== 0) {
box(
group,
0.23,
0.17 + ((i + h) % 2) * 0.04,
0.23,
x,
0.04 + height + 0.075,
z,
(i % 2) ? materials.hedgeTop : materials.hedgeB
);
}
});
if (node.type === "nest") {
box(group, 0.34, 0.30, 0.28, -0.63, 0.16, 0.35, materials.rock);
box(group, 0.25, 0.22, 0.24, 0.61, 0.12, 0.35, materials.rock);
box(group, 0.55, 0.045, 0.34, 0.08, 0.12, 0.53, materials.straw);
}
if (node.type === "goal") {
const oatPositions = [
[0.55, 0.33], [0.48, 0.18], [0.57, 0.02], [0.43, -0.15]
];
oatPositions.forEach(([x, z], i) => {
const hgt = 0.38 + (i % 2) * 0.1;
box(group, 0.035, hgt, 0.035, x, hgt / 2, z, materials.straw);
box(group, 0.075, 0.14, 0.065, x, hgt + 0.055, z, materials.oat);
});
}
}
Object.entries(nodes).forEach(([id, node]) => createCoverNode(id, node));
const nestLabel = textSprite("NEST", {
background: "#fff8df", color: "#76532e", scaleX: 1.45, scaleY: 0.42
});
nestLabel.position.set(nodes.nest.x, 1.18, nodes.nest.z + 0.12);
scene.add(nestLabel);
const goalLabel = textSprite("OAT PATCH", {
background: "#fff3c9", color: "#8b651e", scaleX: 1.85, scaleY: 0.42
});
goalLabel.position.set(nodes.goal.x, 1.22, nodes.goal.z - 0.05);
scene.add(goalLabel);
function createTree(x, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.scale.setScalar(scale);
scene.add(g);
box(g, 0.28, 1.35, 0.28, 0, 0.68, 0, materials.trunk);
box(g, 1.05, 0.72, 0.95, 0, 1.55, 0, materials.leafA);
box(g, 0.72, 0.72, 0.72, -0.36, 1.98, 0.08, materials.leafB);
box(g, 0.72, 0.70, 0.72, 0.38, 1.95, -0.04, materials.leafA);
box(g, 0.66, 0.65, 0.66, 0.02, 2.35, 0.08, materials.leafB);
}
createTree(-6.2, 5.7, 1.05);
createTree(5.0, 5.2, 0.95);
createTree(5.2, -2.6, 1.12);
createTree(-5.7, -2.4, 0.92);
createTree(-6.2, 0.0, 0.72);
function createRock(x, z, s = 1) {
box(scene, 0.45 * s, 0.28 * s, 0.38 * s, x, 0.14 * s, z, materials.rock);
box(scene, 0.24 * s, 0.18 * s, 0.22 * s, x + 0.18 * s, 0.28 * s, z + 0.05 * s, materials.rock);
}
createRock(-5.2, 7.8, 1.1);
createRock(3.8, 6.6, 0.8);
createRock(4.1, 0.3, 1.0);
createRock(-5.3, -1.0, 0.72);
const flowerStem = new THREE.MeshStandardMaterial({ color: 0x5c7d42, roughness: 1 });
const flowerA = new THREE.MeshStandardMaterial({ color: 0xe6a548, roughness: 1 });
const flowerB = new THREE.MeshStandardMaterial({ color: 0xd87972, roughness: 1 });
function createFlower(x, z, color) {
box(scene, 0.035, 0.23, 0.035, x, 0.115, z, flowerStem, false);
box(scene, 0.11, 0.07, 0.11, x, 0.25, z, color, false);
}
[
[-4.8, 6.5, flowerA], [-4.8, 2.4, flowerB], [-4.5, -2.7, flowerA],
[3.7, 3.1, flowerB], [4.2, -0.7, flowerA], [1.8, 7.0, flowerB],
[-5.1, 4.0, flowerA]
].forEach(([x, z, m]) => createFlower(x, z, m));
// The legal connected-cover graph.
const nodeIds = Object.keys(nodes);
const networkPositions = [];
for (let i = 0; i < nodeIds.length; i++) {
for (let j = i + 1; j < nodeIds.length; j++) {
const a = nodeIds[i];
const b = nodeIds[j];
if (legalMove(a, b)) {
networkPositions.push(
nodes[a].x, 0.17, nodes[a].z,
nodes[b].x, 0.17, nodes[b].z
);
}
}
}
const networkGeometry = new THREE.BufferGeometry();
networkGeometry.setAttribute("position", new THREE.Float32BufferAttribute(networkPositions, 3));
const networkMaterial = new THREE.LineBasicMaterial({
color: 0x397958,
transparent: true,
opacity: 0.36
});
scene.add(new THREE.LineSegments(networkGeometry, networkMaterial));
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const routeMarkerMaterial = new THREE.MeshBasicMaterial({
color: 0xf1b83c,
transparent: true,
opacity: 0.92
});
const routeValidMaterial = new THREE.LineBasicMaterial({
color: 0xf1b83c,
transparent: true,
opacity: 0.98
});
const routeInvalidMaterial = new THREE.LineDashedMaterial({
color: 0xcf4c45,
dashSize: 0.16,
gapSize: 0.10,
transparent: true,
opacity: 0.95
});
function clearRouteGeometry() {
routeGroup.traverse((child) => {
if (child.isLine && child.geometry) child.geometry.dispose();
});
routeGroup.clear();
}
function createRouteVisual(route) {
clearRouteGeometry();
route.forEach((id) => {
const marker = new THREE.Mesh(unitBox, routeMarkerMaterial);
marker.scale.set(0.13, 0.035, 0.13);
marker.position.set(nodes[id].x, 0.19, nodes[id].z);
marker.renderOrder = 4;
routeGroup.add(marker);
});
for (let i = 0; i < route.length - 1; i++) {
const a = route[i];
const b = route[i + 1];
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(nodes[a].x, 0.205, nodes[a].z),
new THREE.Vector3(nodes[b].x, 0.205, nodes[b].z)
]);
const line = new THREE.Line(
geometry,
legalMove(a, b) ? routeValidMaterial : routeInvalidMaterial
);
if (!legalMove(a, b)) line.computeLineDistances();
line.renderOrder = 3;
routeGroup.add(line);
}
}
// Original voxel animal: Pip, a button-eared sprig-mouse.
const animalRoot = new THREE.Group();
const animalModel = new THREE.Group();
animalModel.scale.setScalar(0.72);
animalRoot.add(animalModel);
scene.add(animalRoot);
box(animalModel, 0.49, 0.36, 0.58, 0, 0.34, 0.03, materials.fur);
box(animalModel, 0.40, 0.35, 0.38, 0, 0.52, -0.34, materials.furDark);
box(animalModel, 0.29, 0.18, 0.23, 0, 0.43, -0.57, materials.cream);
box(animalModel, 0.09, 0.07, 0.07, 0, 0.46, -0.705, materials.dark);
const eyeMaterial = new THREE.MeshBasicMaterial({ color: 0x18231d });
box(animalModel, 0.052, 0.058, 0.025, -0.115, 0.56, -0.539, eyeMaterial, false);
box(animalModel, 0.052, 0.058, 0.025, 0.115, 0.56, -0.539, eyeMaterial, false);
const earPivots = [];
[-1, 1].forEach((side) => {
const pivot = new THREE.Group();
pivot.position.set(side * 0.14, 0.68, -0.31);
animalModel.add(pivot);
box(pivot, 0.13, 0.25, 0.14, 0, 0.105, 0, materials.furDark);
box(pivot, 0.065, 0.13, 0.025, 0, 0.11, -0.079, materials.cream);
earPivots.push(pivot);
});
box(animalModel, 0.12, 0.08, 0.12, -0.07, 0.76, -0.29, materials.leafTuft);
box(animalModel, 0.12, 0.10, 0.12, 0.04, 0.78, -0.29, materials.leafTuft);
box(animalModel, 0.10, 0.08, 0.11, 0, 0.88, -0.28, materials.hedgeTop);
const legPivots = [];
[
[-0.16, -0.18], [0.16, -0.18],
[-0.16, 0.20], [0.16, 0.20]
].forEach(([x, z], i) => {
const pivot = new THREE.Group();
pivot.position.set(x, 0.19, z);
animalModel.add(pivot);
box(pivot, 0.105, 0.22, 0.13, 0, -0.10, 0, i < 2 ? materials.furDark : materials.fur);
legPivots.push(pivot);
});
const tailPivot = new THREE.Group();
tailPivot.position.set(0, 0.34, 0.30);
animalModel.add(tailPivot);
box(tailPivot, 0.16, 0.16, 0.31, 0, 0.01, 0.17, materials.furDark);
box(tailPivot, 0.13, 0.13, 0.20, 0, 0.04, 0.40, materials.fur);
animalRoot.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
const currentRing = new THREE.Mesh(
new THREE.RingGeometry(0.32, 0.40, 32),
new THREE.MeshBasicMaterial({
color: 0xf0b83f,
transparent: true,
opacity: 0.72,
side: THREE.DoubleSide,
depthWrite: false
})
);
currentRing.rotation.x = -Math.PI / 2;
currentRing.position.y = 0.175;
currentRing.renderOrder = 5;
scene.add(currentRing);
const failureGroup = new THREE.Group();
scene.add(failureGroup);
const failureArcMaterial = new THREE.LineDashedMaterial({
color: 0xd84f47,
dashSize: 0.18,
gapSize: 0.11,
transparent: true,
opacity: 0.95,
depthTest: false
});
function clearFailure() {
failureGroup.traverse((child) => {
if (child.isLine && child.geometry) child.geometry.dispose();
if (child.isSprite) {
if (child.material.map) child.material.map.dispose();
child.material.dispose();
}
});
failureGroup.clear();
}
function createFailureVisual(fromId, toId) {
clearFailure();
const a = new THREE.Vector3(nodes[fromId].x, 0.23, nodes[fromId].z);
const b = new THREE.Vector3(nodes[toId].x, 0.23, nodes[toId].z);
const mid = a.clone().lerp(b, 0.5);
const control = mid.clone();
control.y = 1.72;
const curve = new THREE.QuadraticBezierCurve3(a, control, b);
const arc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(curve.getPoints(48)),
failureArcMaterial
);
arc.computeLineDistances();
arc.renderOrder = 12;
failureGroup.add(arc);
const marker = box(
failureGroup,
0.19, 0.19, 0.19,
mid.x, 0.72, mid.z,
new THREE.MeshBasicMaterial({ color: 0xd84f47 }),
false
);
marker.rotation.y = Math.PI / 4;
marker.renderOrder = 13;
const label = textSprite(
["× GAP REJECTED", `${nodeDistance(fromId, toId).toFixed(2)}u > ${MAX_GAP.toFixed(2)}u`],
{
background: "#fff0ed",
border: "#e6a49e",
color: "#bd3e38",
width: 560,
height: 170,
scaleX: 2.65,
scaleY: 0.8,
lineHeight: 52,
font: "850 34px system-ui, sans-serif"
}
);
label.position.set(mid.x, 1.43, mid.z);
failureGroup.add(label);
}
const burstParticles = [];
const particleMaterials = [
new THREE.MeshBasicMaterial({ color: 0xe7ae36 }),
new THREE.MeshBasicMaterial({ color: 0x4f8a54 }),
new THREE.MeshBasicMaterial({ color: 0xf0d879 })
];
function clearBurst() {
for (const p of burstParticles) failureGroup.remove(p.mesh);
burstParticles.length = 0;
}
function spawnBurst() {
clearBurst();
const goal = nodes.goal;
for (let i = 0; i < 18; i++) {
const mesh = new THREE.Mesh(unitBox, particleMaterials[i % particleMaterials.length]);
mesh.scale.setScalar(0.07 + Math.random() * 0.055);
mesh.position.set(goal.x, 0.55 + Math.random() * 0.25, goal.z);
mesh.rotation.set(Math.random() * 3, Math.random() * 3, Math.random() * 3);
failureGroup.add(mesh);
burstParticles.push({
mesh,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 1.5,
1.2 + Math.random() * 1.25,
(Math.random() - 0.5) * 1.5
),
life: 2.3
});
}
}
function updateBurst(dt) {
for (let i = burstParticles.length - 1; i >= 0; i--) {
const p = burstParticles[i];
p.life -= dt;
p.velocity.y -= 3.6 * dt;
p.mesh.position.addScaledVector(p.velocity, dt);
p.mesh.rotation.x += dt * 3;
p.mesh.rotation.z += dt * 2;
if (p.life <= 0) {
failureGroup.remove(p.mesh);
burstParticles.splice(i, 1);
}
}
}
const state = {
phase: "idle",
routeMode: "direct",
routeIds: [...directRoute],
routeIndex: 0,
validSteps: 0,
tween: null,
detourIntro: false
};
function setAnimalAtNode(id) {
const node = nodes[id];
animalRoot.position.set(node.x, BASE_Y, node.z);
animalRoot.rotation.y = 0;
currentRing.position.set(node.x, 0.175, node.z);
}
function setToast(title, detail, type = "error") {
toastTitle.textContent = title;
toastDetail.textContent = detail;
toast.className = `toast show ${type}`;
}
function hideToast() {
toast.className = "toast";
}
function updateHUD() {
const total = Math.max(1, state.routeIds.length - 1);
const progress = Math.min(100, (state.routeIndex / total) * 100);
progressFill.style.width = `${progress}%`;
stepLabel.textContent = `${state.routeIndex} / ${total}`;
routeValue.textContent = state.routeMode.toUpperCase();
stateDot.className = "dot";
if (state.phase === "idle") {
phaseLabel.textContent = "Ready";
statusTitle.textContent = "Direct route armed";
statusDetail.textContent = "The marked shortcut contains one break. Pip is ready to test it.";
primaryButton.textContent = "Run direct route";
primaryButton.classList.remove("detour");
primaryButton.disabled = false;
}
if (state.phase === "running") {
stateDot.classList.add("running");
phaseLabel.textContent = "Moving";
if (state.detourIntro) {
statusTitle.textContent = "Connected detour selected";
statusDetail.textContent = "Pip is rejoining the legal cover chain around the wide break.";
} else {
statusTitle.textContent = state.routeMode === "direct"
? "Following the short route"
: "Following connected cover";
statusDetail.textContent = state.routeMode === "direct"
? "Pip advances only between adjacent, legal cover tiles."
: "The eastern loop reconnects the two sides of the hedgerow.";
}
primaryButton.textContent = "Route running…";
primaryButton.classList.remove("detour");
primaryButton.disabled = true;
}
if (state.phase === "failed") {
stateDot.classList.add("failed");
phaseLabel.textContent = "Failed";
statusTitle.textContent = "Route failed at the wide gap";
statusDetail.textContent =
`The ${nodeDistance(state.routeIds[state.routeIndex], state.routeIds[state.routeIndex + 1]).toFixed(2)}u gap exceeds the ${MAX_GAP.toFixed(2)}u move limit. Pip stays on cover.`;
primaryButton.textContent = "Take connected detour";
primaryButton.classList.add("detour");
primaryButton.disabled = false;
}
if (state.phase === "success") {
stateDot.classList.add("success");
phaseLabel.textContent = "Complete";
statusTitle.textContent = "Hedgerow crossing complete";
statusDetail.textContent = "Pip reached the oat patch using only legal cover-to-cover steps.";
primaryButton.textContent = "Replay direct route";
primaryButton.classList.remove("detour");
primaryButton.disabled = false;
}
}
function startDirect() {
clearFailure();
clearBurst();
hideToast();
state.phase = "running";
state.routeMode = "direct";
state.routeIds = [...directRoute];
state.routeIndex = 0;
state.validSteps = 0;
state.tween = null;
state.detourIntro = false;
createRouteVisual(state.routeIds);
setAnimalAtNode(state.routeIds[0]);
updateHUD();
advance();
}
function startDetour() {
const currentId = state.routeIds[state.routeIndex];
clearFailure();
hideToast();
state.phase = "running";
state.routeMode = "detour";
state.routeIds = [...detourRoute];
state.routeIndex = state.routeIds.indexOf(currentId);
state.validSteps = 0;
state.tween = null;
state.detourIntro = true;
createRouteVisual(state.routeIds);
updateHUD();
advance();
}
function resetToIdle() {
clearFailure();
clearBurst();
hideToast();
state.phase = "idle";
state.routeMode = "direct";
state.routeIds = [...directRoute];
state.routeIndex = 0;
state.validSteps = 0;
state.tween = null;
state.detourIntro = false;
createRouteVisual(state.routeIds);
setAnimalAtNode(state.routeIds[0]);
updateHUD();
}
function triggerFailure(fromId, toId) {
state.phase = "failed";
state.tween = null;
state.detourIntro = false;
createFailureVisual(fromId, toId);
currentRing.material.color.set(0xd84f47);
updateHUD();
setToast(
"Route rejected",
`${nodeDistance(fromId, toId).toFixed(2)}u gap > ${MAX_GAP.toFixed(2)}u limit`,
"error"
);
}
function finishRoute() {
state.phase = "success";
state.tween = null;
state.detourIntro = false;
currentRing.visible = false;
spawnBurst();
updateHUD();
setToast(
"Crossing complete",
"The connected detour carried Pip safely to the oats.",
"success"
);
}
function advance() {
if (state.routeIndex >= state.routeIds.length - 1) {
finishRoute();
return;
}
const fromId = state.routeIds[state.routeIndex];
const toId = state.routeIds[state.routeIndex + 1];
if (!legalMove(fromId, toId)) {
triggerFailure(fromId, toId);
return;
}
const from = nodes[fromId];
const to = nodes[toId];
const distance = nodeDistance(fromId, toId);
state.tween = {
from: new THREE.Vector3(from.x, BASE_Y, from.z),
to: new THREE.Vector3(to.x, BASE_Y, to.z),
elapsed: 0,
duration: 0.46 + distance * 0.12
};
animalRoot.rotation.y = Math.atan2(
-(to.x - from.x),
-(to.z - from.z)
);
updateHUD();
}
function completeTween() {
state.routeIndex += 1;
state.validSteps += 1;
const id = state.routeIds[state.routeIndex];
setAnimalAtNode(id);
state.detourIntro = false;
if (state.routeIndex >= state.routeIds.length - 1) {
finishRoute();
} else {
updateHUD();
advance();
}
}
// Custom camera controls: no addon imports.
const cameraState = {
target: new THREE.Vector3(-0.35, 0.35, 2.25),
theta: 0.47,
phi: 0.83,
radius: 16.7,
desiredTheta: 0.47,
desiredPhi: 0.83,
desiredRadius: 16.7
};
function updateCamera(dt, shake = 0) {
const k = 1 - Math.exp(-dt * 9);
cameraState.theta += (cameraState.desiredTheta - cameraState.theta) * k;
cameraState.phi += (cameraState.desiredPhi - cameraState.phi) * k;
cameraState.radius += (cameraState.desiredRadius - cameraState.radius) * k;
const sinPhi = Math.sin(cameraState.phi);
const desired = new THREE.Vector3(
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.position.lerp(desired, k);
if (shake > 0) {
camera.position.x += Math.sin(performance.now() * 0.045) * shake;
camera.position.y += Math.cos(performance.now() * 0.052) * shake * 0.55;
}
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.desiredTheta = 0.47;
cameraState.desiredPhi = 0.83;
cameraState.desiredRadius = 16.7;
}
const pointers = new Map();
let pinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
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)) return;
const previous = pointers.get(event.pointerId);
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
cameraState.desiredTheta -= dx * 0.006;
cameraState.desiredPhi = THREE.MathUtils.clamp(
cameraState.desiredPhi - dy * 0.005,
0.42,
1.23
);
}
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius * (pinchDistance / distance),
10.5,
24
);
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
10.5,
24
);
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
viewButton.addEventListener("click", resetCamera);
let autoTimer = setTimeout(() => {
if (state.phase === "idle") startDirect();
}, 900);
primaryButton.addEventListener("click", () => {
clearTimeout(autoTimer);
if (state.phase === "failed") startDetour();
else startDirect();
});
resetButton.addEventListener("click", () => {
clearTimeout(autoTimer);
resetToIdle();
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight, false);
});
createRouteVisual(directRoute);
setAnimalAtNode("nest");
updateHUD();
updateCamera(1);
const clock = new THREE.Clock();
let elapsed = 0;
let walkPhase = 0;
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
if (state.tween) {
state.tween.elapsed += dt;
const t = Math.min(1, state.tween.elapsed / state.tween.duration);
const eased = t * t * (3 - 2 * t);
animalRoot.position.lerpVectors(state.tween.from, state.tween.to, eased);
animalRoot.position.y = BASE_Y + Math.sin(t * Math.PI) * 0.075;
walkPhase += dt * 13;
legPivots.forEach((leg, i) => {
leg.rotation.x = Math.sin(walkPhase + (i % 2) * Math.PI + (i > 1 ? 0.4 : 0)) * 0.48;
});
animalModel.rotation.z = Math.sin(walkPhase) * 0.025;
if (t >= 1) completeTween();
} else {
legPivots.forEach((leg, i) => {
const target = Math.sin(elapsed * 2 + i) * 0.025;
leg.rotation.x += (target - leg.rotation.x) * Math.min(1, dt * 8);
});
animalModel.rotation.z *= 0.9;
}
if (state.phase === "failed") {
animalModel.position.x = Math.sin(elapsed * 42) * 0.045;
animalModel.rotation.z = Math.sin(elapsed * 34) * 0.035;
earPivots[0].rotation.z = 0.12 + Math.sin(elapsed * 9) * 0.03;
earPivots[1].rotation.z = -0.12 - Math.sin(elapsed * 9) * 0.03;
currentRing.material.opacity = 0.55 + Math.sin(elapsed * 6) * 0.22;
} else {
animalModel.position.x *= 0.8;
earPivots[0].rotation.z *= 0.85;
earPivots[1].rotation.z *= 0.85;
currentRing.material.opacity = 0.72;
}
animalModel.position.y = state.tween
? animalModel.position.y
: Math.sin(elapsed * 2.3) * 0.012;
tailPivot.rotation.y = Math.sin(elapsed * 5.5) * 0.26;
tailPivot.rotation.x = Math.sin(elapsed * 3.1) * 0.07;
currentRing.material.color.set(
state.phase === "failed" ? 0xd84f47 :
state.phase === "success" ? 0x3f8555 :
0xf0b83f
);
if (state.phase !== "success") currentRing.visible = true;
const shake = state.phase === "failed" ? 0.018 : 0;
updateCamera(dt, shake);
updateBurst(dt);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```