Prompt specification
Build or customize the Three.js 3D scene "Home layout for gradual exploration" 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: Home layout for gradual exploration
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/home-layout-for-gradual-exploration-x3844
Scene Description Prompt:
Create a fictional pet-arrival scene with configurable obstacles and quiet zones; users reveal connected exploration routes while captions distinguish the game from veterinary or behavioral advice. Use Three.js from cdnjs in a single HTML file, with low-poly forms.
Working Three.js Starter (home-layout-for-gradual-exploration-x3844):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Arrival Routes — Fictional Pet Garden</title>
<style>
:root {
--ink: #17352f;
--muted: #61756e;
--paper: #f7f5ed;
--panel: #fffdf7;
--line: #dce4da;
--green: #247b68;
--green-dark: #18594d;
--mint: #dff1e9;
--gold: #e6a93b;
--purple: #8e78c8;
--danger: #b44e45;
--shadow: 0 14px 38px rgba(29, 57, 47, 0.14);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, select, input { font: inherit; }
button {
border: 1px solid var(--line);
border-radius: 10px;
padding: 9px 11px;
background: #fff;
color: var(--ink);
cursor: pointer;
font-weight: 700;
transition: transform 120ms ease, background 120ms ease,
border-color 120ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
border-color: #aabdb3;
background: #f8fbf8;
}
button:disabled {
opacity: 0.42;
cursor: not-allowed;
}
button.primary {
background: var(--green);
border-color: var(--green);
color: white;
}
button.primary:hover:not(:disabled) {
background: var(--green-dark);
}
button.active {
border-color: var(--green);
box-shadow: 0 0 0 2px rgba(36, 123, 104, 0.13);
background: var(--mint);
}
select {
width: 100%;
border: 1px solid var(--line);
border-radius: 9px;
padding: 9px 10px;
color: var(--ink);
background: white;
}
#app {
display: grid;
grid-template-columns: minmax(0, 1fr) 350px;
width: 100%;
height: 100%;
}
#viewport {
position: relative;
min-width: 0;
overflow: hidden;
background: #dfeae0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#topbar {
position: absolute;
z-index: 5;
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid rgba(255,255,255,0.72);
border-radius: 14px;
background: rgba(255, 253, 247, 0.91);
box-shadow: var(--shadow);
backdrop-filter: blur(9px);
}
.brand-icon {
display: grid;
place-items: center;
width: 36px;
height: 36px;
border-radius: 11px;
background: var(--green);
color: white;
font-size: 20px;
}
.brand strong {
display: block;
font-size: 15px;
letter-spacing: 0.01em;
}
.brand small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 11px;
}
.game-badge {
max-width: 320px;
padding: 10px 12px;
border: 1px solid #e8d59d;
border-radius: 13px;
background: rgba(255, 249, 224, 0.94);
color: #6e571d;
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 800;
line-height: 1.35;
text-align: right;
}
#labels {
position: absolute;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
padding: 5px 8px;
border: 1px solid rgba(255,255,255,0.75);
border-radius: 8px;
background: rgba(255, 253, 247, 0.9);
color: var(--ink);
box-shadow: 0 5px 14px rgba(25, 60, 46, 0.12);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.09em;
white-space: nowrap;
}
.world-label.owner {
background: rgba(255, 242, 199, 0.94);
color: #765613;
}
.world-label.quiet {
background: rgba(239, 233, 255, 0.91);
color: #5f4b9b;
}
.world-label.arrival {
background: rgba(220, 245, 234, 0.94);
color: var(--green-dark);
}
#caption-card {
position: absolute;
z-index: 5;
left: 18px;
bottom: 18px;
width: min(460px, calc(100% - 36px));
padding: 14px 16px;
border: 1px solid rgba(255,255,255,0.8);
border-radius: 15px;
background: rgba(255, 253, 247, 0.94);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
pointer-events: none;
}
#caption-kicker {
margin-bottom: 4px;
color: var(--green);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#caption-title {
margin: 0 0 4px;
font-size: 16px;
}
#caption-copy {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#view-tools {
position: absolute;
z-index: 5;
right: 18px;
bottom: 18px;
display: flex;
align-items: center;
gap: 8px;
}
#view-tools button {
background: rgba(255, 253, 247, 0.92);
box-shadow: 0 5px 16px rgba(25,60,46,0.11);
}
#tool-status {
max-width: 190px;
padding: 8px 10px;
border-radius: 10px;
background: rgba(23, 53, 47, 0.88);
color: white;
font-size: 10px;
line-height: 1.35;
text-align: right;
}
#panel {
position: relative;
z-index: 8;
overflow-y: auto;
border-left: 1px solid var(--line);
background: var(--panel);
box-shadow: -8px 0 30px rgba(29, 57, 47, 0.08);
}
.panel-header {
padding: 20px 20px 16px;
border-bottom: 1px solid var(--line);
}
.panel-header h1 {
margin: 0 0 5px;
font-size: 19px;
}
.panel-header p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.section {
padding: 17px 20px;
border-bottom: 1px solid var(--line);
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin: 0 0 11px;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.section-title span:last-child {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0;
text-transform: none;
}
.button-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.button-grid .wide {
grid-column: 1 / -1;
}
.inline-row {
display: flex;
gap: 8px;
margin-top: 9px;
}
.inline-row > * { flex: 1; }
.route-stat {
margin-top: 10px;
padding: 9px 10px;
border-radius: 9px;
background: #f1f5ef;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 11px;
margin-top: 10px;
color: var(--muted);
font-size: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--green);
}
.legend-dot.gold { background: var(--gold); }
.legend-dot.purple { background: var(--purple); }
.control-label {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
text-transform: uppercase;
letter-spacing: 0.07em;
}
.range-row {
display: grid;
grid-template-columns: 1fr 58px;
align-items: center;
gap: 10px;
margin-top: 9px;
}
input[type="range"] {
width: 100%;
accent-color: var(--purple);
}
.range-value {
padding: 6px;
border-radius: 8px;
background: #f0ecfb;
color: #604c99;
font-size: 11px;
font-weight: 800;
text-align: center;
}
.object-list {
display: grid;
gap: 7px;
margin-top: 10px;
}
.object-row {
display: grid;
grid-template-columns: 30px minmax(0, 1fr) auto;
align-items: center;
gap: 8px;
padding: 8px;
border: 1px solid var(--line);
border-radius: 10px;
background: white;
}
.object-row.selected {
border-color: var(--green);
box-shadow: 0 0 0 2px rgba(36,123,104,0.1);
}
.object-row.disabled .object-name {
opacity: 0.48;
}
.object-icon {
display: grid;
place-items: center;
width: 28px;
height: 28px;
border-radius: 8px;
background: #e8f1eb;
font-size: 15px;
}
.object-icon.quiet {
background: #eee9fb;
}
.object-name {
min-width: 0;
font-size: 11px;
font-weight: 800;
}
.object-position {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 600;
}
.switch {
position: relative;
display: inline-block;
width: 30px;
height: 18px;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch span {
position: absolute;
inset: 0;
border-radius: 20px;
background: #c7d0c9;
cursor: pointer;
transition: 160ms ease;
}
.switch span::after {
content: "";
position: absolute;
width: 14px;
height: 14px;
left: 2px;
top: 2px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 3px rgba(0,0,0,0.18);
transition: 160ms ease;
}
.switch input:checked + span {
background: var(--green);
}
.switch input:checked + span::after {
transform: translateX(12px);
}
.mini-button {
padding: 5px 7px;
border-radius: 7px;
font-size: 9px;
}
.disclaimer {
margin: 16px 20px 22px;
padding: 12px;
border: 1px solid #ead9a8;
border-radius: 11px;
background: #fff9e8;
color: #715d2d;
font-size: 10px;
line-height: 1.5;
}
.disclaimer strong {
display: block;
margin-bottom: 3px;
color: #594716;
}
@media (max-width: 860px) {
html, body { overflow: auto; }
#app {
grid-template-columns: 1fr;
grid-template-rows: 58vh 42vh;
height: 100%;
}
#panel {
border-left: 0;
border-top: 1px solid var(--line);
}
#view-tools {
bottom: 128px;
}
.game-badge { display: none; }
}
@media (max-width: 520px) {
#topbar { left: 10px; right: 10px; top: 10px; }
#caption-card { left: 10px; bottom: 10px; width: calc(100% - 20px); }
#view-tools { right: 10px; bottom: 126px; }
#tool-status { display: none; }
}
</style>
</head>
<body>
<div id="app">
<section id="viewport" aria-label="Interactive low-poly pet arrival garden">
<div id="topbar">
<div class="brand">
<div class="brand-icon" aria-hidden="true">⌁</div>
<div>
<strong>Arrival Routes</strong>
<small>A fictional low-poly pet garden</small>
</div>
</div>
<div class="game-badge">
FICTIONAL GAME SCENE<br>
Not veterinary, medical, training, or behavioral advice
</div>
</div>
<div id="labels" aria-hidden="true"></div>
<div id="caption-card" role="status" aria-live="polite">
<div id="caption-kicker">Game caption</div>
<h2 id="caption-title">Milo has arrived</h2>
<p id="caption-copy">
Reveal connected route segments, then arrange obstacles and quiet zones
to create a different fictional garden map.
</p>
</div>
<div id="view-tools">
<div id="tool-status">Drag to orbit · Scroll to zoom</div>
<button id="reset-view" type="button">Reset view</button>
</div>
</section>
<aside id="panel" aria-label="Game configuration">
<div class="panel-header">
<h1>Garden controls</h1>
<p>
Configure the map, reveal connected exploration routes, and preview
the fictional pet’s journey.
</p>
</div>
<section class="section">
<h2 class="section-title">
Exploration routes <span id="route-mode">Connected network</span>
</h2>
<div class="button-grid">
<button id="reveal-next" class="primary" type="button">Reveal next</button>
<button id="reveal-all" type="button">Reveal connected</button>
<button id="trace-owner" class="wide" type="button">Trace route to owner</button>
<button id="preview-route" type="button">Preview walk</button>
<button id="reset-routes" type="button">Clear routes</button>
</div>
<div id="route-stat" class="route-stat">Preparing the route network…</div>
<div class="legend" aria-label="Map legend">
<span class="legend-item"><i class="legend-dot"></i> Connected route</span>
<span class="legend-item"><i class="legend-dot gold"></i> Owner route</span>
<span class="legend-item"><i class="legend-dot purple"></i> Quiet zone</span>
</div>
</section>
<section class="section">
<h2 class="section-title">
Obstacles <span>Blocking map cells</span>
</h2>
<label class="control-label" for="obstacle-type">Object type</label>
<select id="obstacle-type">
<option value="bench">Park bench</option>
<option value="planter">Flower planter</option>
<option value="bin">Waste bin</option>
<option value="toy">Toy cart</option>
</select>
<div class="inline-row">
<button id="place-obstacle" type="button">Place obstacle</button>
<button id="move-selected" type="button" disabled>Move selected</button>
</div>
<div id="obstacle-list" class="object-list"></div>
</section>
<section class="section">
<h2 class="section-title">
Quiet zones <span>Decorative rest areas</span>
</h2>
<div class="range-row">
<input id="quiet-radius" type="range" min="1" max="2" step="1" value="1"
aria-label="Quiet zone radius">
<div id="quiet-radius-value" class="range-value">1 cell</div>
</div>
<div class="inline-row">
<button id="place-quiet" type="button">Place quiet zone</button>
<button id="remove-selected" type="button" disabled>Remove selected</button>
</div>
<div id="quiet-list" class="object-list"></div>
</section>
<section class="section">
<h2 class="section-title">Arrival animation</h2>
<button id="replay-arrival" class="wide" type="button">
Replay fictional arrival
</button>
</section>
<div class="disclaimer">
<strong>Game content only.</strong>
This scene is an abstract route-building game. Quiet zones, obstacles,
pauses, and route choices are fictional map mechanics—not veterinary,
medical, safety, training, or behavioral recommendations.
</div>
</aside>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dfeae0");
scene.fog = new THREE.Fog("#dfeae0", 22, 42);
const camera = new THREE.PerspectiveCamera(
43,
viewport.clientWidth / viewport.clientHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute("aria-label", "Three-dimensional pet garden");
viewport.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight("#eff8ef", "#7c806b", 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff5d6", 3.4);
sun.position.set(6, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const mat = (color, extra = {}) => new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...extra
});
const materials = {
ground: mat("#a8c997"),
soil: mat("#927258"),
path: mat("#d7cdb0"),
wood: mat("#a86f43"),
woodDark: mat("#765039"),
leaf: mat("#4f8b62"),
leafLight: mat("#76a66d"),
leafDark: mat("#35654f"),
metal: mat("#668079"),
cream: mat("#f3e8ca"),
blue: mat("#638da8"),
purple: mat("#9b83ce"),
gold: mat("#e6b14d"),
dark: mat("#293f39"),
white: mat("#fffdf4"),
dog: mat("#c98552"),
dogLight: mat("#e2b17d"),
dogDark: mat("#674633")
};
const worldRoot = new THREE.Group();
const dynamicRoot = new THREE.Group();
const explorationGroup = new THREE.Group();
const pathGroup = new THREE.Group();
scene.add(worldRoot, dynamicRoot, explorationGroup, pathGroup);
const grid = {
minX: -6,
maxX: 6,
minZ: -4,
maxZ: 4
};
const start = { x: -5, z: 3 };
const goal = { x: 4, z: -3 };
const state = {
obstacles: [
{ id: "bench-1", type: "bench", x: 2, z: 1, enabled: true },
{ id: "planter-1", type: "planter", x: -1, z: -2, enabled: true },
{ id: "bin-1", type: "bin", x: 4, z: 0, enabled: true }
],
quietZones: [
{ id: "quiet-1", x: -2, z: 1, radius: 1, enabled: true },
{ id: "quiet-2", x: 3, z: -1, radius: 1, enabled: true }
],
selected: null,
tool: null,
placementType: "bench",
quietRadius: 1,
revealedCount: 0,
discoveryEdges: [],
connectedEdges: [],
reachable: new Set(),
computedOwnerPath: [],
ownerPath: [],
arrival: null,
walk: null
};
const objectNames = {
bench: "Park bench",
planter: "Flower planter",
bin: "Waste bin",
toy: "Toy cart"
};
const objectIcons = {
bench: "▰",
planter: "♣",
bin: "▥",
toy: "✦"
};
// -------------------------------------------------------------------------
// Low-poly garden
// -------------------------------------------------------------------------
function addMesh(parent, geometry, material, position = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const floor = addMesh(
worldRoot,
new THREE.BoxGeometry(13.8, 0.35, 9.8),
materials.ground,
[0, -0.19, 0]
);
const soilBorder = addMesh(
worldRoot,
new THREE.BoxGeometry(14.25, 0.18, 10.25),
materials.soil,
[0, -0.39, 0]
);
// Subtle grid, aligned with the path graph.
const gridVertices = [];
for (let x = grid.minX - 0.5; x <= grid.maxX + 0.5; x++) {
gridVertices.push(x, 0.015, grid.minZ - 0.5, x, 0.015, grid.maxZ + 0.5);
}
for (let z = grid.minZ - 0.5; z <= grid.maxZ + 0.5; z++) {
gridVertices.push(grid.minX - 0.5, 0.015, z, grid.maxX + 0.5, 0.015, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridVertices, 3)
);
worldRoot.add(new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: "#73946e",
transparent: true,
opacity: 0.22
})
));
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
addMesh(
group,
new THREE.CylinderGeometry(0.16, 0.22, 1.25, 6),
materials.woodDark,
[0, 0.6, 0]
);
addMesh(
group,
new THREE.ConeGeometry(0.83, 1.55, 7),
materials.leaf,
[0, 1.55, 0]
);
addMesh(
group,
new THREE.ConeGeometry(0.64, 1.25, 7),
materials.leafLight,
[0.08, 2.05, -0.04]
);
worldRoot.add(group);
}
[
[-7.0, -3.8, 1.05], [-7.1, 0.1, 0.85], [-7.0, 3.7, 1.1],
[-3.8, -5.2, 1.0], [0.2, -5.3, 0.86], [3.8, -5.25, 1.12],
[7.0, -3.7, 0.95], [7.1, 0.5, 1.15], [7.0, 4.0, 0.9],
[-5.8, 5.2, 0.75], [5.9, 5.2, 0.8]
].forEach(([x, z, s]) => addTree(x, z, s));
function addFencePost(x, z) {
addMesh(
worldRoot,
new THREE.BoxGeometry(0.14, 1.0, 0.14),
materials.cream,
[x, 0.47, z]
);
addMesh(
worldRoot,
new THREE.ConeGeometry(0.12, 0.18, 4),
materials.cream,
[x, 1.05, z]
);
}
for (let x = -6.5; x <= 6.5; x += 1.3) {
addFencePost(x, -4.85);
}
for (let z = -4.5; z <= 4.5; z += 1.3) {
addFencePost(-6.85, z);
addFencePost(6.85, z);
}
for (let x = -6.5; x < 6.5; x += 1.3) {
addMesh(
worldRoot,
new THREE.BoxGeometry(1.2, 0.1, 0.1),
materials.cream,
[x + 0.65, 0.63, -4.85]
);
}
// Arrival gate.
const gate = new THREE.Group();
gate.position.set(-5, 0, 4.65);
addMesh(gate, new THREE.BoxGeometry(0.16, 2.0, 0.16), materials.wood, [-0.75, 1, 0]);
addMesh(gate, new THREE.BoxGeometry(0.16, 2.0, 0.16), materials.wood, [0.75, 1, 0]);
addMesh(gate, new THREE.BoxGeometry(1.65, 0.16, 0.16), materials.wood, [0, 1.95, 0]);
addMesh(gate, new THREE.BoxGeometry(0.72, 0.35, 0.08), materials.gold, [0, 1.62, 0.05]);
worldRoot.add(gate);
// Owner and goal mat.
const goalMat = addMesh(
worldRoot,
new THREE.CylinderGeometry(0.68, 0.68, 0.055, 24),
mat("#e6bc63"),
[goal.x, 0.03, goal.z]
);
const owner = new THREE.Group();
owner.position.set(goal.x, 0, goal.z);
addMesh(owner, new THREE.CylinderGeometry(0.28, 0.36, 0.85, 7), materials.blue, [0, 0.55, 0]);
addMesh(owner, new THREE.SphereGeometry(0.25, 8, 6), mat("#d9a475"), [0, 1.16, 0]);
addMesh(owner, new THREE.ConeGeometry(0.26, 0.28, 7), materials.dark, [0, 1.34, -0.02]);
addMesh(owner, new THREE.CylinderGeometry(0.09, 0.09, 0.55, 6), materials.blue, [-0.34, 0.67, 0]);
addMesh(owner, new THREE.CylinderGeometry(0.09, 0.09, 0.55, 6), materials.blue, [0.34, 0.67, 0]);
addMesh(owner, new THREE.CylinderGeometry(0.11, 0.11, 0.48, 6), materials.dark, [-0.15, 0.18, 0]);
addMesh(owner, new THREE.CylinderGeometry(0.11, 0.11, 0.48, 6), materials.dark, [0.15, 0.18, 0]);
worldRoot.add(owner);
// Decorative stones.
[
[-4.6, 2.7], [-4.3, 2.8], [-4.0, 2.7],
[0.3, -3.4], [0.7, -3.5], [1.1, -3.4]
].forEach(([x, z]) => {
addMesh(
worldRoot,
new THREE.CylinderGeometry(0.18, 0.22, 0.08, 6),
materials.path,
[x, 0.035, z]
);
});
// -------------------------------------------------------------------------
// Low-poly pet
// -------------------------------------------------------------------------
const dog = new THREE.Group();
const body = addMesh(
dog,
new THREE.SphereGeometry(0.48, 8, 6),
materials.dog,
[0, 0.52, 0]
);
body.scale.set(0.78, 0.72, 1.28);
addMesh(
dog,
new THREE.SphereGeometry(0.34, 8, 6),
materials.dogLight,
[0, 0.9, 0.45]
);
addMesh(
dog,
new THREE.BoxGeometry(0.3, 0.2, 0.28),
materials.dogLight,
[0, 0.82, 0.72]
);
addMesh(
dog,
new THREE.SphereGeometry(0.055, 6, 5),
materials.dark,
[-0.13, 0.96, 0.71]
);
addMesh(
dog,
new THREE.SphereGeometry(0.055, 6, 5),
materials.dark,
[0.13, 0.96, 0.71]
);
addMesh(
dog,
new THREE.SphereGeometry(0.065, 6, 5),
materials.dark,
[0, 0.84, 0.86]
);
const leftEar = addMesh(
dog,
new THREE.ConeGeometry(0.14, 0.38, 5),
materials.dogDark,
[-0.25, 1.09, 0.43]
);
leftEar.rotation.z = -0.2;
const rightEar = addMesh(
dog,
new THREE.ConeGeometry(0.14, 0.38, 5),
materials.dogDark,
[0.25, 1.09, 0.43]
);
rightEar.rotation.z = 0.2;
[
[-0.22, -0.34], [0.22, -0.34],
[-0.22, 0.34], [0.22, 0.34]
].forEach(([x, z]) => {
addMesh(
dog,
new THREE.CylinderGeometry(0.075, 0.09, 0.42, 6),
materials.dog,
[x, 0.25, z]
);
});
const tail = addMesh(
dog,
new THREE.ConeGeometry(0.12, 0.58, 6),
materials.dogDark,
[0, 0.7, -0.68]
);
tail.rotation.x = -1.0;
dog.position.set(start.x, 0, start.z);
worldRoot.add(dog);
// -------------------------------------------------------------------------
// World labels
// -------------------------------------------------------------------------
const labelLayer = document.getElementById("labels");
const staticLabels = [];
let dynamicLabels = [];
function addLabel(text, anchor, className = "", dynamic = false) {
const el = document.createElement("div");
el.className = `world-label ${className}`;
el.textContent = text;
labelLayer.appendChild(el);
const label = { el, anchor };
if (dynamic) dynamicLabels.push(label);
else staticLabels.push(label);
return label;
}
addLabel("ARRIVAL", new THREE.Vector3(start.x, 1.55, start.z + 0.3), "arrival");
addLabel("OWNER", new THREE.Vector3(goal.x, 1.9, goal.z), "owner");
function updateLabels() {
const rect = renderer.domElement.getBoundingClientRect();
[...staticLabels, ...dynamicLabels].forEach(label => {
const p = label.anchor.clone().project(camera);
const visible = p.z > -1 && p.z < 1 &&
p.x > -1.15 && p.x < 1.15 &&
p.y > -1.15 && p.y < 1.15;
label.el.style.display = visible ? "block" : "none";
if (visible) {
label.el.style.left = `${(p.x * 0.5 + 0.5) * rect.width}px`;
label.el.style.top = `${(-p.y * 0.5 + 0.5) * rect.height}px`;
}
});
}
// -------------------------------------------------------------------------
// Configurable objects
// -------------------------------------------------------------------------
let obstacleGroups = [];
let quietGroups = [];
function createObstacle(object) {
const group = new THREE.Group();
group.position.set(object.x, 0, object.z);
group.userData = { kind: "obstacle", id: object.id };
if (object.type === "bench") {
addMesh(group, new THREE.BoxGeometry(1.15, 0.16, 0.48), materials.wood, [0, 0.53, 0]);
addMesh(group, new THREE.BoxGeometry(1.15, 0.48, 0.12), materials.woodDark, [0, 0.85, -0.2]);
[-0.45, 0.45].forEach(x => {
addMesh(group, new THREE.BoxGeometry(0.11, 0.48, 0.32), materials.dark, [x, 0.25, 0]);
});
} else if (object.type === "planter") {
addMesh(group, new THREE.CylinderGeometry(0.4, 0.33, 0.5, 8), materials.cream, [0, 0.25, 0]);
addMesh(group, new THREE.CylinderGeometry(0.34, 0.34, 0.06, 8), materials.soil, [0, 0.52, 0]);
addMesh(group, new THREE.ConeGeometry(0.32, 0.72, 6), materials.leaf, [0, 0.85, 0]);
addMesh(group, new THREE.SphereGeometry(0.18, 6, 5), materials.leafLight, [0.18, 0.85, 0.05]);
} else if (object.type === "bin") {
addMesh(group, new THREE.CylinderGeometry(0.3, 0.25, 0.68, 8), materials.metal, [0, 0.34, 0]);
addMesh(group, new THREE.CylinderGeometry(0.33, 0.33, 0.1, 8), materials.dark, [0, 0.72, 0]);
addMesh(group, new THREE.BoxGeometry(0.25, 0.06, 0.08), materials.cream, [0, 0.79, 0]);
} else if (object.type === "toy") {
addMesh(group, new THREE.BoxGeometry(0.9, 0.48, 0.7), materials.gold, [0, 0.48, 0]);
addMesh(group, new THREE.BoxGeometry(0.98, 0.1, 0.78), materials.cream, [0, 0.76, 0]);
[-0.32, 0.32].forEach(x => {
[-0.23, 0.23].forEach(z => {
addMesh(group, new THREE.CylinderGeometry(0.1, 0.1, 0.09, 8), materials.dark, [x, 0.15, z]);
});
});
}
dynamicRoot.add(group);
obstacleGroups.push(group);
return group;
}
function createQuietZone(zone) {
const group = new THREE.Group();
group.position.set(zone.x, 0, zone.z);
group.userData = { kind: "quiet", id: zone.id };
const disk = addMesh(
group,
new THREE.CylinderGeometry(zone.radius * 0.88, zone.radius * 0.88, 0.035, 28),
new THREE.MeshBasicMaterial({
color: "#9b83ce",
transparent: true,
opacity: 0.18,
depthWrite: false
}),
[0, 0.035, 0]
);
disk.castShadow = false;
disk.receiveShadow = false;
const ring = addMesh(
group,
new THREE.TorusGeometry(zone.radius * 0.88, 0.035, 6, 36),
new THREE.MeshBasicMaterial({
color: "#8067bd",
transparent: true,
opacity: 0.85
}),
[0, 0.065, 0]
);
ring.rotation.x = Math.PI / 2;
ring.castShadow = false;
ring.receiveShadow = false;
addMesh(
group,
new THREE.CylinderGeometry(0.035, 0.035, 0.55, 6),
materials.purple,
[0, 0.29, 0]
);
const marker = addMesh(
group,
new THREE.OctahedronGeometry(0.16, 0),
materials.purple,
[0, 0.62, 0]
);
marker.rotation.y = Math.PI / 4;
dynamicRoot.add(group);
quietGroups.push(group);
addLabel(
"QUIET",
new THREE.Vector3(zone.x, 1.0, zone.z),
"quiet",
true
);
}
const selectionRing = addMesh(
scene,
new THREE.TorusGeometry(0.65, 0.045, 6, 32),
new THREE.MeshBasicMaterial({ color: "#f4c64f" }),
[0, 0.11, 0]
);
selectionRing.rotation.x = Math.PI / 2;
selectionRing.visible = false;
selectionRing.castShadow = false;
function rebuildDynamicObjects() {
dynamicLabels.forEach(label => label.el.remove());
dynamicLabels = [];
dynamicRoot.clear();
obstacleGroups = [];
quietGroups = [];
state.obstacles.forEach(createObstacle);
state.quietZones.forEach(createQuietZone);
updateSelectionRing();
}
function updateSelectionRing() {
const selected = getSelectedObject();
selectionRing.visible = Boolean(selected);
if (selected) {
selectionRing.position.set(selected.x, 0.11, selected.z);
const radius = selected.kind === "quiet" ? selected.radius * 0.93 : 0.67;
selectionRing.scale.setScalar(radius / 0.65);
}
}
function getSelectedObject() {
if (!state.selected) return null;
if (state.selected.kind === "obstacle") {
return state.obstacles.find(o => o.id === state.selected.id) || null;
}
return state.quietZones.find(q => q.id === state.selected.id) || null;
}
// -------------------------------------------------------------------------
// Route graph
// -------------------------------------------------------------------------
const keyOf = (x, z) => `${x},${z}`;
const parseKey = key => {
const [x, z] = key.split(",").map(Number);
return { x, z };
};
function quietAt(x, z) {
return state.quietZones.some(zone => {
if (!zone.enabled) return false;
const dx = x - zone.x;
const dz = z - zone.z;
return Math.hypot(dx, dz) <= zone.radius + 0.05;
});
}
function isBlocked(x, z) {
return state.obstacles.some(o =>
o.enabled && o.x === x && o.z === z
);
}
function inGrid(x, z) {
return x >= grid.minX && x <= grid.maxX &&
z >= grid.minZ && z <= grid.maxZ;
}
function computeNetwork() {
const adjacency = new Map();
for (let x = grid.minX; x <= grid.maxX; x++) {
for (let z = grid.minZ; z <= grid.maxZ; z++) {
if (!isBlocked(x, z)) adjacency.set(keyOf(x, z), []);
}
}
adjacency.forEach((neighbors, key) => {
const { x, z } = parseKey(key);
[[1, 0], [-1, 0], [0, 1], [0, -1]].forEach(([dx, dz]) => {
const nx = x + dx;
const nz = z + dz;
const nextKey = keyOf(nx, nz);
if (adjacency.has(nextKey)) neighbors.push(nextKey);
});
});
const startKey = keyOf(start.x, start.z);
const goalKey = keyOf(goal.x, goal.z);
const reachable = new Set();
const discoveryEdges = [];
const parent = new Map();
if (adjacency.has(startKey)) {
const queue = [startKey];
reachable.add(startKey);
while (queue.length) {
const current = queue.shift();
for (const next of adjacency.get(current)) {
if (reachable.has(next)) continue;
reachable.add(next);
parent.set(next, current);
discoveryEdges.push({ from: current, to: next });
queue.push(next);
}
}
}
const connectedEdges = [];
const seenEdges = new Set();
reachable.forEach(key => {
adjacency.get(key).forEach(next => {
if (!reachable.has(next)) return;
const edgeKey = [key, next].sort().join("|");
if (seenEdges.has(edgeKey)) return;
seenEdges.add(edgeKey);
connectedEdges.push({ from: key, to: next });
});
});
// Weighted shortest route: quiet cells are more expensive in this game.
const computedOwnerPath = [];
if (adjacency.has(startKey) && adjacency.has(goalKey)) {
const distances = new Map([[startKey, 0]]);
const previous = new Map();
const open = [{ key: startKey, cost: 0 }];
const settled = new Set();
while (open.length) {
open.sort((a, b) => a.cost - b.cost);
const current = open.shift();
if (settled.has(current.key)) continue;
settled.add(current.key);
if (current.key === goalKey) break;
const { x, z } = parseKey(current.key);
for (const next of adjacency.get(current.key)) {
const nextPoint = parseKey(next);
const quietPenalty = quietAt(nextPoint.x, nextPoint.z) ? 1.6 : 0;
const nextCost = current.cost + 1 + quietPenalty;
if (nextCost < (distances.get(next) ?? Infinity)) {
distances.set(next, nextCost);
previous.set(next, current.key);
open.push({ key: next, cost: nextCost });
}
}
}
if (distances.has(goalKey)) {
let current = goalKey;
const reversed = [current];
while (current !== startKey) {
current = previous.get(current);
if (!current) break;
reversed.push(current);
}
computedOwnerPath.push(...reversed.reverse());
}
}
state.reachable = reachable;
state.discoveryEdges = discoveryEdges;
state.connectedEdges = connectedEdges;
state.computedOwnerPath = computedOwnerPath;
}
function routeMaterial(color) {
return new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92
});
}
function addRouteSegment(group, fromKey, toKey, color, radius = 0.055, height = 0.11) {
const a = parseKey(fromKey);
const b = parseKey(toKey);
const av = new THREE.Vector3(a.x, height, a.z);
const bv = new THREE.Vector3(b.x, height, b.z);
const direction = new THREE.Vector3().subVectors(bv, av);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 6),
routeMaterial(color)
);
mesh.position.copy(av).add(bv).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
group.add(mesh);
}
function addRouteNode(group, key, color, height = 0.13) {
const point = parseKey(key);
const node = new THREE.Mesh(
new THREE.SphereGeometry(0.085, 7, 5),
routeMaterial(color)
);
node.position.set(point.x, height, point.z);
group.add(node);
}
function disposeGroup(group) {
[...group.children].forEach(child => {
child.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materialsToDispose = Array.isArray(object.material)
? object.material
: [object.material];
materialsToDispose.forEach(material => material.dispose());
}
});
group.remove(child);
});
}
function clearRouteVisuals() {
disposeGroup(explorationGroup);
disposeGroup(pathGroup);
state.revealedCount = 0;
state.ownerPath = [];
}
function revealNext() {
if (state.revealedCount >= state.discoveryEdges.length) {
setCaption(
"The connected network is fully revealed",
"All currently reachable discovery segments are visible. Add or move an obstacle to create a new game map."
);
return;
}
const edge = state.discoveryEdges[state.revealedCount++];
addRouteSegment(explorationGroup, edge.from, edge.to, "#36b9a2", 0.055, 0.11);
addRouteNode(explorationGroup, edge.to, "#36b9a2");
setCaption(
`Route segment ${state.revealedCount} revealed`,
"This segment connects to the game’s arrival point. The line is a fictional map graphic, not guidance for a real animal."
);
updateRouteStat();
}
function revealAllConnected() {
disposeGroup(explorationGroup);
state.connectedEdges.forEach(edge => {
addRouteSegment(explorationGroup, edge.from, edge.to, "#36b9a2", 0.043, 0.105);
});
state.reachable.forEach(key => addRouteNode(explorationGroup, key, "#36b9a2"));
state.revealedCount = state.discoveryEdges.length;
setCaption(
"Connected exploration network revealed",
`The map contains ${state.reachable.size} reachable game cells and ${state.connectedEdges.length} connected links.`
);
updateRouteStat();
}
function traceOwnerRoute() {
disposeGroup(pathGroup);
state.ownerPath = [];
if (!state.computedOwnerPath.length) {
setCaption(
"No connected owner route",
"The current fictional map has no open path from the arrival gate to the owner. Adjust an obstacle and try again."
);
updateRouteStat();
return;
}
state.ownerPath = [...state.computedOwnerPath];
for (let i = 0; i < state.ownerPath.length - 1; i++) {
const from = state.ownerPath[i];
const to = state.ownerPath[i + 1];
addRouteSegment(pathGroup, from, to, "#e6a93b", 0.07, 0.16);
}
state.ownerPath.forEach(key => addRouteNode(pathGroup, key, "#f2bd57", 0.18));
setCaption(
"A game route to the owner is traced",
"The gold line shows a connected route through the current map. Quiet-zone cells are decorative game features only."
);
updateRouteStat();
}
function updateRouteStat() {
const routeLength = state.ownerPath.length
? ` • ${state.ownerPath.length - 1} owner-route steps`
: "";
document.getElementById("route-stat").textContent =
`${state.revealedCount}/${state.discoveryEdges.length} discovery segments revealed` +
` • ${state.connectedEdges.length} connected links` +
` • ${state.reachable.size} reachable cells${routeLength}`;
}
// -------------------------------------------------------------------------
// Animations
// -------------------------------------------------------------------------
function replayArrival() {
state.walk = null;
state.arrival = {
elapsed: 0,
duration: 2.2,
from: new THREE.Vector3(start.x, 0, 5.15),
to: new THREE.Vector3(start.x, 0, start.z)
};
dog.position.copy(state.arrival.from);
dog.rotation.y = Math.PI;
setCaption(
"Milo enters the fictional garden",
"The animated arrival is a playful scene setup and does not describe how a real pet should be handled or transported."
);
}
function previewWalk() {
if (!state.computedOwnerPath.length) {
setCaption(
"Preview unavailable",
"There is no connected fictional route to the owner in the current obstacle arrangement."
);
return;
}
if (!state.ownerPath.length) traceOwnerRoute();
state.arrival = null;
state.walk = {
points: state.ownerPath.map(key => {
const p = parseKey(key);
return new THREE.Vector3(p.x, 0, p.z);
}),
index: 0,
elapsed: 0
};
dog.position.copy(state.walk.points[0]);
setCaption(
"Fictional route preview",
"Milo follows the gold game route. Any slower movement near a quiet zone is an animation choice, not behavioral advice."
);
}
function updateDog(delta, elapsed) {
tail.rotation.z = Math.sin(elapsed * 8) * 0.16;
if (state.arrival) {
const arrival = state.arrival;
arrival.elapsed += delta;
const t = Math.min(arrival.elapsed / arrival.duration, 1);
const eased = t * t * (3 - 2 * t);
dog.position.lerpVectors(arrival.from, arrival.to, eased);
dog.position.y = Math.abs(Math.sin(t * Math.PI * 7)) * 0.09;
if (t >= 1) {
state.arrival = null;
dog.position.copy(arrival.to);
dog.position.y = 0;
setCaption(
"Milo has arrived",
"Reveal connected route segments, then configure obstacles and quiet zones to create a different fictional garden map."
);
}
return;
}
if (!state.walk) return;
const walk = state.walk;
const from = walk.points[walk.index];
const to = walk.points[walk.index + 1];
if (!to) {
state.walk = null;
dog.position.y = 0;
setCaption(
"Route preview complete",
"The fictional garden journey is complete. No real-animal care, training, or behavioral conclusion is being made."
);
return;
}
const targetPoint = parseKey(state.ownerPath[walk.index + 1]);
const duration = quietAt(targetPoint.x, targetPoint.z) ? 1.05 : 0.5;
walk.elapsed += delta;
const t = Math.min(walk.elapsed / duration, 1);
dog.position.lerpVectors(from, to, t);
dog.position.y = Math.abs(Math.sin(t * Math.PI * 5)) * 0.08;
const dx = to.x - from.x;
const dz = to.z - from.z;
if (dx || dz) dog.rotation.y = Math.atan2(dx, dz);
if (t >= 1) {
walk.index++;
walk.elapsed = 0;
}
}
// -------------------------------------------------------------------------
// Custom camera controls — no Three.js addons
// -------------------------------------------------------------------------
const cameraState = {
radius: 16.2,
theta: 0.61,
phi: 0.73,
target: new THREE.Vector3(0, 0.3, 0)
};
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 resetView() {
cameraState.radius = 16.2;
cameraState.theta = 0.61;
cameraState.phi = 0.73;
cameraState.target.set(0, 0.3, 0);
updateCamera();
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const groundPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
let drag = null;
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
renderer.domElement.setPointerCapture(event.pointerId);
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
distance: 0
};
});
renderer.domElement.addEventListener("pointermove", event => {
if (!drag || drag.id !== event.pointerId) return;
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
drag.distance += Math.abs(dx) + Math.abs(dy);
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.38,
1.18
);
});
renderer.domElement.addEventListener("pointerup", event => {
if (!drag || drag.id !== event.pointerId) return;
const wasClick = drag.distance < 7;
drag = null;
if (wasClick) handleSceneClick(event);
});
renderer.domElement.addEventListener("pointercancel", () => {
drag = null;
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
9,
25
);
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
function pointerToNdc(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function groundPoint(event) {
pointerToNdc(event);
const point = new THREE.Vector3();
const hit = raycaster.ray.intersectPlane(groundPlane, point);
return hit ? point : null;
}
function pickedObject(event) {
pointerToNdc(event);
const hits = raycaster.intersectObjects(
[...obstacleGroups, ...quietGroups],
true
);
if (!hits.length) return null;
let object = hits[0].object;
while (object) {
if (object.userData && object.userData.id) {
return {
kind: object.userData.kind,
id: object.userData.id
};
}
object = object.parent;
}
return null;
}
function handleSceneClick(event) {
const point = groundPoint(event);
if (!point) return;
const x = Math.round(point.x);
const z = Math.round(point.z);
if (state.tool === "obstacle") {
if (!inGrid(x, z)) {
setCaption(
"Place inside the garden grid",
"Choose a location inside the outlined game area."
);
return;
}
if ((x === start.x && z === start.z) || (x === goal.x && z === goal.z)) {
setCaption(
"That game location is reserved",
"The arrival gate and owner area cannot be blocked in this fictional map."
);
return;
}
if (state.obstacles.some(o => o.x === x && o.z === z)) {
setCaption(
"This game cell is already occupied",
"Choose an empty cell or move the existing object."
);
return;
}
const id = `${state.placementType}-${Date.now()}`;
state.obstacles.push({
id,
type: state.placementType,
x,
z,
enabled: true
});
state.selected = { kind: "obstacle", id };
applyConfiguration(
`${objectNames[state.placementType]} placed in the fictional map`
);
return;
}
if (state.tool === "quiet") {
if (!inGrid(x, z)) {
setCaption(
"Place inside the garden grid",
"Quiet zones are decorative game areas inside the outlined map."
);
return;
}
const id = `quiet-${Date.now()}`;
state.quietZones.push({
id,
x,
z,
radius: state.quietRadius,
enabled: true
});
state.selected = { kind: "quiet", id };
applyConfiguration("A decorative quiet zone was added to the game map");
return;
}
if (state.tool === "move") {
const selected = getSelectedObject();
if (!selected) return;
if (!inGrid(x, z)) {
setCaption(
"Move inside the garden grid",
"Choose a valid game cell for the selected object."
);
return;
}
if (selected.kind === "obstacle") {
if ((x === start.x && z === start.z) || (x === goal.x && z === goal.z)) {
setCaption(
"That game location is reserved",
"The arrival gate and owner area must remain open in this fictional map."
);
return;
}
const occupied = state.obstacles.some(o =>
o.id !== selected.id && o.x === x && o.z === z
);
if (occupied) {
setCaption(
"That game cell is occupied",
"Move the selected obstacle to an empty cell."
);
return;
}
}
selected.x = x;
selected.z = z;
applyConfiguration("The selected game object was moved");
return;
}
const picked = pickedObject(event);
if (picked) {
state.selected = picked;
updateSelectionRing();
renderConfiguration();
}
}
// -------------------------------------------------------------------------
// Interface
// -------------------------------------------------------------------------
function setCaption(title, copy) {
document.getElementById("caption-title").textContent = title;
document.getElementById("caption-copy").textContent = copy;
}
function setTool(tool) {
state.tool = state.tool === tool ? null : tool;
renderToolState();
}
function renderToolState() {
document.getElementById("place-obstacle").classList.toggle(
"active", state.tool === "obstacle"
);
document.getElementById("place-quiet").classList.toggle(
"active", state.tool === "quiet"
);
document.getElementById("move-selected").classList.toggle(
"active", state.tool === "move"
);
const status = document.getElementById("tool-status");
if (state.tool === "obstacle") {
status.textContent = "Placement mode: click an empty garden cell";
} else if (state.tool === "quiet") {
status.textContent = "Placement mode: click a cell for a quiet zone";
} else if (state.tool === "move") {
status.textContent = "Move mode: click the destination cell";
} else {
status.textContent = "Drag to orbit · Scroll to zoom";
}
}
function renderConfiguration() {
const obstacleList = document.getElementById("obstacle-list");
const quietList = document.getElementById("quiet-list");
obstacleList.innerHTML = state.obstacles.map(object => {
const selected = state.selected?.kind === "obstacle" &&
state.selected.id === object.id;
return `
<div class="object-row ${selected ? "selected" : ""} ${object.enabled ? "" : "disabled"}">
<div class="object-icon">${objectIcons[object.type]}</div>
<button class="object-select" data-kind="obstacle" data-id="${object.id}"
style="border:0;background:none;padding:0;text-align:left">
<span class="object-name">${objectNames[object.type]}</span>
<span class="object-position">Cell ${object.x}, ${object.z}</span>
</button>
<label class="switch" title="Enable or disable this game object">
<input type="checkbox" data-obstacle-toggle="${object.id}" ${object.enabled ? "checked" : ""}>
<span></span>
</label>
</div>
`;
}).join("");
quietList.innerHTML = state.quietZones.map(zone => {
const selected = state.selected?.kind === "quiet" &&
state.selected.id === zone.id;
return `
<div class="object-row ${selected ? "selected" : ""} ${zone.enabled ? "" : "disabled"}">
<div class="object-icon quiet">◌</div>
<button class="object-select" data-kind="quiet" data-id="${zone.id}"
style="border:0;background:none;padding:0;text-align:left">
<span class="object-name">Quiet zone</span>
<span class="object-position">Cell ${zone.x}, ${zone.z} • radius ${zone.radius}</span>
</button>
<label class="switch" title="Enable or disable this game zone">
<input type="checkbox" data-quiet-toggle="${zone.id}" ${zone.enabled ? "checked" : ""}>
<span></span>
</label>
</div>
`;
}).join("");
const selected = getSelectedObject();
document.getElementById("move-selected").disabled = !selected;
document.getElementById("remove-selected").disabled = !selected;
if (selected?.kind === "quiet") {
document.getElementById("quiet-radius").value = selected.radius;
} else {
document.getElementById("quiet-radius").value = state.quietRadius;
}
updateRadiusValue();
updateSelectionRing();
}
function updateRadiusValue() {
const value = Number(document.getElementById("quiet-radius").value);
document.getElementById("quiet-radius-value").textContent =
`${value} cell${value === 1 ? "" : "s"}`;
}
function applyConfiguration(message) {
rebuildDynamicObjects();
computeNetwork();
clearRouteVisuals();
updateRouteStat();
renderConfiguration();
if (message) {
setCaption(
"The fictional map was updated",
`${message}. Connected routes were recalculated; the quiet-zone choice remains a decorative game mechanic.`
);
}
}
document.getElementById("obstacle-type").addEventListener("change", event => {
state.placementType = event.target.value;
});
document.getElementById("place-obstacle").addEventListener("click", () => {
setTool("obstacle");
});
document.getElementById("place-quiet").addEventListener("click", () => {
setTool("quiet");
});
document.getElementById("move-selected").addEventListener("click", () => {
setTool("move");
});
document.getElementById("remove-selected").addEventListener("click", () => {
const selected = getSelectedObject();
if (!selected) return;
if (selected.kind === "obstacle") {
state.obstacles = state.obstacles.filter(o => o.id !== selected.id);
} else {
state.quietZones = state.quietZones.filter(q => q.id !== selected.id);
}
state.selected = null;
applyConfiguration("The selected game object was removed");
});
document.getElementById("quiet-radius").addEventListener("input", event => {
state.quietRadius = Number(event.target.value);
updateRadiusValue();
});
document.getElementById("quiet-radius").addEventListener("change", event => {
const selected = getSelectedObject();
if (selected?.kind === "quiet") {
selected.radius = Number(event.target.value);
applyConfiguration("The selected quiet-zone radius changed");
}
});
document.getElementById("obstacle-list").addEventListener("click", event => {
const selectButton = event.target.closest("[data-kind='obstacle']");
if (selectButton) {
state.selected = {
kind: "obstacle",
id: selectButton.dataset.id
};
state.tool = null;
renderToolState();
renderConfiguration();
}
});
document.getElementById("quiet-list").addEventListener("click", event => {
const selectButton = event.target.closest("[data-kind='quiet']");
if (selectButton) {
state.selected = {
kind: "quiet",
id: selectButton.dataset.id
};
state.tool = null;
renderToolState();
renderConfiguration();
}
});
document.getElementById("obstacle-list").addEventListener("change", event => {
const id = event.target.dataset.obstacleToggle;
if (!id) return;
const object = state.obstacles.find(o => o.id === id);
if (!object) return;
object.enabled = event.target.checked;
applyConfiguration(`${objectNames[object.type]} was ${object.enabled ? "enabled" : "disabled"}`);
});
document.getElementById("quiet-list").addEventListener("change", event => {
const id = event.target.dataset.quietToggle;
if (!id) return;
const zone = state.quietZones.find(q => q.id === id);
if (!zone) return;
zone.enabled = event.target.checked;
applyConfiguration(`A quiet zone was ${zone.enabled ? "enabled" : "disabled"}`);
});
document.getElementById("reveal-next").addEventListener("click", revealNext);
document.getElementById("reveal-all").addEventListener("click", revealAllConnected);
document.getElementById("trace-owner").addEventListener("click", traceOwnerRoute);
document.getElementById("preview-route").addEventListener("click", previewWalk);
document.getElementById("reset-routes").addEventListener("click", () => {
clearRouteVisuals();
updateRouteStat();
setCaption(
"Routes cleared",
"Reveal a new connected route or change the fictional obstacle arrangement."
);
});
document.getElementById("replay-arrival").addEventListener("click", replayArrival);
document.getElementById("reset-view").addEventListener("click", resetView);
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera();
updateDog(delta, elapsed);
updateLabels();
renderer.render(scene, camera);
}
rebuildDynamicObjects();
computeNetwork();
renderConfiguration();
updateRouteStat();
resetView();
replayArrival();
animate();
</script>
</body>
</html>
```