Prompt specification
Build or customize the Three.js 3D scene "Town and region nested map display" 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: Town and region nested map display
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/town-and-region-nested-map-display-x1331
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: town and region nested map display. Show a town model, municipal outline, and broader regional map in nested frames. Use consistent selection colors and separate administrative boundaries from terrain features.
Working Three.js Starter (town-and-region-nested-map-display-x1331):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Nested Atlas — North Vale</title>
<style>
:root {
--paper: #ece9df;
--panel: #f7f4ec;
--ink: #28322e;
--muted: #778078;
--line: rgba(40, 50, 46, 0.15);
--selection: #f46b45;
--admin: #25a9c7;
--terrain: #8d9d72;
--water: #74b4c4;
--road: #cabd9f;
--shadow: 0 18px 45px rgba(39, 47, 42, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
color: var(--ink);
background:
radial-gradient(circle at 12% 8%, rgba(255,255,255,0.75), transparent 28%),
var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
min-width: 320px;
}
button {
font: inherit;
}
.app-header {
min-height: 88px;
padding: 16px 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
border-bottom: 1px solid var(--line);
background: rgba(247, 244, 236, 0.76);
backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 250px;
}
.brand-mark {
position: relative;
width: 42px;
height: 42px;
flex: 0 0 42px;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
border: 1.5px solid var(--ink);
border-radius: 6px;
transform: rotate(-7deg);
}
.brand-mark::before {
inset: 1px 8px 8px 1px;
}
.brand-mark::after {
inset: 8px 1px 1px 8px;
border-color: var(--selection);
}
.brand-copy {
display: grid;
gap: 2px;
}
.brand-copy strong {
font-size: 14px;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.brand-copy span {
color: var(--muted);
font-size: 12px;
}
.legend {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
gap: 9px 17px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
color: #59635d;
font-size: 11px;
white-space: nowrap;
}
.swatch {
width: 12px;
height: 12px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}
.swatch.selection { background: var(--selection); }
.swatch.admin { background: var(--admin); }
.swatch.terrain { background: var(--terrain); }
.swatch.water { background: var(--water); }
.swatch.road { background: var(--road); }
.header-actions {
display: flex;
align-items: center;
gap: 12px;
}
.path {
color: var(--muted);
font-size: 10px;
line-height: 1.5;
letter-spacing: 0.12em;
text-align: right;
text-transform: uppercase;
}
.reset-button {
cursor: pointer;
border: 1px solid rgba(40, 50, 46, 0.22);
border-radius: 999px;
padding: 9px 13px;
color: var(--ink);
background: rgba(255,255,255,0.52);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
transition: background 160ms ease, transform 160ms ease;
}
.reset-button:hover {
background: #fff;
transform: translateY(-1px);
}
.stage {
position: relative;
height: calc(100vh - 89px);
min-height: 620px;
margin: 14px;
isolation: isolate;
}
.map-card {
position: absolute;
overflow: hidden;
border: 1px solid rgba(40, 50, 46, 0.17);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
}
#region-card {
left: 0;
top: 0;
width: 47%;
height: 100%;
z-index: 1;
}
#municipality-card {
left: 38%;
top: 9%;
width: 34%;
height: 82%;
z-index: 2;
}
#town-card {
left: 67%;
top: 0;
width: 33%;
height: 100%;
z-index: 3;
}
.panel-head {
position: absolute;
inset: 0 0 auto;
z-index: 5;
min-height: 68px;
padding: 12px 15px 11px;
border-bottom: 1px solid var(--line);
background: rgba(250, 248, 242, 0.94);
backdrop-filter: blur(12px);
}
.panel-kicker {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.level-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--selection);
box-shadow: 0 0 0 3px rgba(244, 107, 69, 0.13);
}
.panel-title-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 8px;
}
.panel-head h2 {
margin: 0;
overflow: hidden;
font-size: clamp(16px, 1.45vw, 23px);
font-weight: 650;
letter-spacing: -0.035em;
text-overflow: ellipsis;
white-space: nowrap;
}
.scale {
flex: 0 0 auto;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
}
.panel-subtitle {
margin-top: 3px;
overflow: hidden;
color: var(--muted);
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.viewport {
position: absolute;
inset: 68px 0 0;
overflow: hidden;
background: #e9e7dd;
}
.viewport canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
.viewport canvas:active {
cursor: grabbing;
}
.map-chip,
.map-caption {
position: absolute;
z-index: 4;
pointer-events: none;
border: 1px solid rgba(40, 50, 46, 0.13);
background: rgba(250, 248, 242, 0.9);
box-shadow: 0 6px 18px rgba(40, 50, 46, 0.08);
backdrop-filter: blur(10px);
}
.map-chip {
top: 13px;
left: 13px;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border-radius: 999px;
color: #59635d;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.map-chip::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--selection);
}
.map-caption {
right: 12px;
bottom: 12px;
left: 12px;
display: flex;
justify-content: space-between;
gap: 10px;
padding: 8px 10px;
border-radius: 9px;
color: #667069;
font-size: 9px;
line-height: 1.35;
}
.caption-key {
color: var(--ink);
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.caption-admin {
color: var(--admin);
}
.caption-selection {
color: var(--selection);
}
.instruction {
position: absolute;
z-index: 4;
right: 13px;
top: 13px;
padding: 5px 8px;
border-radius: 999px;
color: rgba(40, 50, 46, 0.55);
background: rgba(250, 248, 242, 0.7);
pointer-events: none;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 1050px) {
.legend {
display: none;
}
.path {
display: none;
}
}
@media (max-width: 820px) {
.app-header {
align-items: flex-start;
}
.stage {
display: flex;
flex-direction: column;
gap: 14px;
height: auto;
min-height: 0;
}
.map-card {
position: relative !important;
inset: auto !important;
width: 100% !important;
height: 560px !important;
}
#municipality-card {
height: 500px !important;
}
}
@media (max-width: 520px) {
.app-header {
padding: 14px;
}
.brand-copy span {
display: none;
}
.reset-button {
padding: 8px 10px;
}
.stage {
margin: 10px;
}
.panel-head {
padding-inline: 12px;
}
}
</style>
</head>
<body>
<header class="app-header">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<strong>Nested Atlas</strong>
<span>Administrative terrain explorer</span>
</div>
</div>
<div class="legend" aria-label="Map legend">
<span class="legend-item">
<i class="swatch selection"></i> Selection
</span>
<span class="legend-item">
<i class="swatch admin"></i> Administrative limit
</span>
<span class="legend-item">
<i class="swatch terrain"></i> Terrain
</span>
<span class="legend-item">
<i class="swatch water"></i> Water
</span>
<span class="legend-item">
<i class="swatch road"></i> Roads
</span>
</div>
<div class="header-actions">
<div class="path" id="path-label">North Vale / Alderwick / Old Quay</div>
<button class="reset-button" id="reset-view" type="button">Reset views</button>
</div>
</header>
<main class="stage">
<section class="map-card" id="region-card" aria-label="Regional map">
<header class="panel-head">
<div class="panel-kicker"><i class="level-dot"></i> Level 01 · Broader region</div>
<div class="panel-title-row">
<h2>North Vale</h2>
<span class="scale">1 : 24,000</span>
</div>
<div class="panel-subtitle">Three municipalities · terrain and transport context</div>
</header>
<div class="viewport" id="region-viewport"></div>
<div class="map-chip" id="region-focus">Focused: Alderwick</div>
<div class="instruction">Drag · scroll</div>
<div class="map-caption">
<span><span class="caption-key caption-selection">Orange</span> focused municipality</span>
<span><span class="caption-key caption-admin">Cyan</span> municipal limits</span>
</div>
</section>
<section class="map-card" id="municipality-card" aria-label="Municipal map">
<header class="panel-head">
<div class="panel-kicker"><i class="level-dot"></i> Level 02 · Municipality</div>
<div class="panel-title-row">
<h2 id="municipality-name">Alderwick</h2>
<span class="scale">1 : 8,000</span>
</div>
<div class="panel-subtitle">Parent: North Vale · cyan edge marks the municipal limit</div>
</header>
<div class="viewport" id="municipality-viewport"></div>
<div class="map-chip" id="municipality-focus">Town: Alderwick</div>
<div class="instruction">Drag · scroll</div>
<div class="map-caption">
<span><span class="caption-key caption-admin">Cyan posts</span> administrative boundary</span>
<span><span class="caption-key caption-selection">Orange</span> selected town</span>
</div>
</section>
<section class="map-card" id="town-card" aria-label="Town model">
<header class="panel-head">
<div class="panel-kicker"><i class="level-dot"></i> Level 03 · Town model</div>
<div class="panel-title-row">
<h2 id="town-name">Alderwick</h2>
<span class="scale">1 : 2,400</span>
</div>
<div class="panel-subtitle">Focus: <span id="district-name">Old Quay</span> · click a roof to change focus</div>
</header>
<div class="viewport" id="town-viewport"></div>
<div class="map-chip" id="town-focus">Old Quay selected</div>
<div class="instruction">Drag · scroll · double-click</div>
<div class="map-caption">
<span><span class="caption-key caption-selection">Orange</span> selected district</span>
<span>Roofs, river and parks remain terrain features</span>
</div>
</section>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const COLORS = {
selection: 0xf46b45,
admin: 0x25a9c7,
terrain: 0x8d9d72,
terrainLight: 0xa8aa7d,
water: 0x74b4c4,
road: 0xcabd9f,
base: 0xc7bca5,
roof: 0x756f65,
roofAlt: 0x8a8174,
wall: 0xe3ddcf
};
const municipalities = [
{
name: "Alderwick",
town: "Alderwick",
center: [-3, 0.6],
shape: [
[-5, -1], [-3.2, -2.4], [-0.6, -1.9], [1, 0],
[-0.2, 2.2], [-3, 2.8], [-4.6, 1.6]
]
},
{
name: "Pine Reach",
town: "Pine Reach",
center: [4, 2],
shape: [
[2.1, 0.2], [3, -0.8], [6, -0.5], [7, 1.8],
[5.5, 3.8], [2.7, 3.2]
]
},
{
name: "Bexley",
town: "Bexley",
center: [-1, -4],
shape: [
[-4.8, -2.8], [-2, -4.6], [0.8, -4], [2, -2.4],
[0.3, -0.4], [-2.5, -0.6]
]
}
];
const districtNames = ["Old Quay", "Mill Ward", "Northbank"];
const districtCenters = [
{ x: -2.8, z: -1.6 },
{ x: 1.5, z: -1.6 },
{ x: -0.7, z: 2.0 }
];
const state = {
municipality: 0,
district: 0
};
const views = {};
const cameraRigs = [];
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let regionPickables = [];
let municipalPickables = [];
let townPickables = [];
let selectedRegionMaterial = null;
let selectedMunicipalMaterial = null;
class CameraRig {
constructor(camera, canvas, options = {}) {
this.camera = camera;
this.canvas = canvas;
this.target = new THREE.Vector3(...(options.target || [0, 0, 0]));
this.home = {
target: this.target.clone(),
yaw: options.yaw ?? 0.62,
pitch: options.pitch ?? 0.68,
distance: options.distance ?? 22
};
this.yaw = this.home.yaw;
this.pitch = this.home.pitch;
this.distance = this.home.distance;
this.dragging = false;
this.moved = false;
this.lastX = 0;
this.lastY = 0;
this.onTap = null;
canvas.addEventListener("pointerdown", this.onPointerDown.bind(this));
canvas.addEventListener("pointermove", this.onPointerMove.bind(this));
canvas.addEventListener("pointerup", this.onPointerUp.bind(this));
canvas.addEventListener("pointercancel", this.onPointerUp.bind(this));
canvas.addEventListener("wheel", this.onWheel.bind(this), { passive: false });
canvas.addEventListener("dblclick", this.reset.bind(this));
}
onPointerDown(event) {
if (event.button !== 0) return;
this.dragging = true;
this.moved = false;
this.lastX = event.clientX;
this.lastY = event.clientY;
this.canvas.setPointerCapture(event.pointerId);
}
onPointerMove(event) {
if (!this.dragging) return;
const dx = event.clientX - this.lastX;
const dy = event.clientY - this.lastY;
this.lastX = event.clientX;
this.lastY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 2) this.moved = true;
this.yaw -= dx * 0.007;
this.pitch = THREE.MathUtils.clamp(
this.pitch + dy * 0.006,
0.30,
1.20
);
}
onPointerUp(event) {
if (!this.dragging) return;
this.dragging = false;
if (this.canvas.hasPointerCapture(event.pointerId)) {
this.canvas.releasePointerCapture(event.pointerId);
}
if (!this.moved && this.onTap) {
this.onTap(event);
}
}
onWheel(event) {
event.preventDefault();
this.distance = THREE.MathUtils.clamp(
this.distance + event.deltaY * 0.012,
11,
42
);
}
reset() {
this.target.copy(this.home.target);
this.yaw = this.home.yaw;
this.pitch = this.home.pitch;
this.distance = this.home.distance;
}
update() {
const horizontal = Math.cos(this.pitch) * this.distance;
this.camera.position.set(
this.target.x + Math.sin(this.yaw) * horizontal,
this.target.y + Math.sin(this.pitch) * this.distance,
this.target.z + Math.cos(this.yaw) * horizontal
);
this.camera.lookAt(this.target);
}
}
function createView(id, cameraOptions) {
const viewport = document.getElementById(id);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e7dd);
const camera = new THREE.PerspectiveCamera(
36,
1,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xfffbed,
0x777c68,
2.25
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffffff, 3.1);
sun.position.set(9, 15, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rig = new CameraRig(camera, renderer.domElement, cameraOptions);
cameraRigs.push(rig);
const view = { viewport, scene, camera, renderer, rig };
views[id] = view;
const resize = () => {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
};
new ResizeObserver(resize).observe(viewport);
resize();
return view;
}
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.92,
metalness: 0,
flatShading: true,
...options
});
}
function shapeFromXZ(points) {
const shape = new THREE.Shape();
shape.moveTo(points[0][0], -points[0][1]);
for (let i = 1; i < points.length; i++) {
shape.lineTo(points[i][0], -points[i][1]);
}
shape.closePath();
return shape;
}
function addBase(scene, width, depth) {
const base = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.65, depth),
standardMaterial(COLORS.base)
);
base.position.y = -0.38;
base.receiveShadow = true;
base.castShadow = true;
scene.add(base);
const underlay = new THREE.Mesh(
new THREE.BoxGeometry(width * 0.96, 0.22, depth * 0.96),
standardMaterial(0x9f9783)
);
underlay.position.y = -0.74;
underlay.receiveShadow = true;
scene.add(underlay);
}
function addTerrain(scene, width, depth, segments, amplitude, color) {
const geometry = new THREE.PlaneGeometry(
width,
depth,
segments,
segments
);
geometry.rotateX(-Math.PI / 2);
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const z = positions.getZ(i);
const height = amplitude * (
Math.sin(x * 0.72 + z * 0.19) * 0.42 +
Math.cos(z * 0.91 - x * 0.16) * 0.34 +
Math.sin((x + z) * 0.37) * 0.24
);
positions.setY(i, height);
}
geometry.computeVertexNormals();
const terrain = new THREE.Mesh(
geometry,
standardMaterial(color)
);
terrain.receiveShadow = true;
scene.add(terrain);
return terrain;
}
function addRoad(scene, start, end, width = 0.12, y = 0.12) {
const dx = end[0] - start[0];
const dz = end[1] - start[1];
const length = Math.hypot(dx, dz);
const road = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.045, width),
standardMaterial(COLORS.road)
);
road.position.set(
(start[0] + end[0]) / 2,
y,
(start[1] + end[1]) / 2
);
road.rotation.y = -Math.atan2(dz, dx);
road.receiveShadow = true;
scene.add(road);
return road;
}
function addWater(scene, points, y = 0.19) {
const geometry = new THREE.ShapeGeometry(shapeFromXZ(points));
geometry.rotateX(-Math.PI / 2);
const water = new THREE.Mesh(
geometry,
standardMaterial(COLORS.water, {
roughness: 0.38,
metalness: 0.04,
side: THREE.DoubleSide
})
);
water.position.y = y;
water.receiveShadow = true;
scene.add(water);
return water;
}
function addHill(scene, x, z, radius, height, color = COLORS.terrain) {
const hill = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, 5),
standardMaterial(color)
);
hill.position.set(x, height / 2 + 0.06, z);
hill.rotation.y = x * 0.31 + z * 0.17;
hill.castShadow = true;
hill.receiveShadow = true;
scene.add(hill);
return hill;
}
function addTree(scene, x, z, scale = 1) {
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.055, 0.34 * scale, 5),
standardMaterial(0x78634e)
);
trunk.position.set(x, 0.18 * scale, z);
trunk.castShadow = true;
scene.add(trunk);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(0.22 * scale, 0.7 * scale, 6),
standardMaterial(0x667e5d)
);
crown.position.set(x, 0.55 * scale, z);
crown.castShadow = true;
scene.add(crown);
}
function addBoundary(parent, points, y = 0.38, radius = 0.035) {
const material = standardMaterial(COLORS.admin, {
roughness: 0.6,
emissive: 0x073e49,
emissiveIntensity: 0.22
});
const up = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < points.length; i++) {
const current = points[i];
const next = points[(i + 1) % points.length];
const a = new THREE.Vector3(current[0], y, current[1]);
const b = new THREE.Vector3(next[0], y, next[1]);
const direction = b.clone().sub(a);
const length = direction.length();
const edge = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 5),
material
);
edge.position.copy(a).add(b).multiplyScalar(0.5);
edge.quaternion.setFromUnitVectors(up, direction.normalize());
edge.castShadow = true;
parent.add(edge);
const post = new THREE.Mesh(
new THREE.CylinderGeometry(radius * 1.7, radius * 1.7, 0.18, 6),
material
);
post.position.set(current[0], y + 0.05, current[1]);
post.castShadow = true;
parent.add(post);
}
}
function addPolygonMesh(parent, points, y, material) {
const geometry = new THREE.ShapeGeometry(shapeFromXZ(points));
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = y;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function randomSize(seed) {
const value = Math.sin(seed * 91.371) * 43758.5453;
return value - Math.floor(value);
}
function addBuilding(scene, x, z, width, depth, height, district, index) {
const wall = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
standardMaterial(COLORS.wall)
);
wall.position.set(x, height / 2 + 0.08, z);
wall.castShadow = true;
wall.receiveShadow = true;
wall.userData.district = district;
scene.add(wall);
const roofMaterial = standardMaterial(
index % 2 === 0 ? COLORS.roof : COLORS.roofAlt
);
const roof = new THREE.Mesh(
new THREE.BoxGeometry(width + 0.08, 0.13, depth + 0.08),
roofMaterial
);
roof.position.set(x, height + 0.15, z);
roof.castShadow = true;
roof.userData.district = district;
roof.userData.roof = true;
scene.add(roof);
townPickables.push(roof);
if (index % 4 === 0) {
const detail = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.25, 0.12),
standardMaterial(0x5f5a52)
);
detail.position.set(x + width * 0.22, height + 0.3, z);
detail.castShadow = true;
scene.add(detail);
}
}
function buildRegion(view) {
const scene = view.scene;
addBase(scene, 21, 16);
addTerrain(scene, 20.8, 15.8, 24, 0.18, 0x9da57d);
addWater(scene, [
[-10, 2.6], [-6, 1.7], [-2, 2.1], [2, 3.2],
[6, 3.7], [10, 3.2], [10, 4.2], [6, 4.8],
[2, 4.3], [-2, 3.2], [-6, 2.8], [-10, 3.7]
], 0.20);
addRoad(scene, [-9, -1.8], [9, 0.5], 0.12, 0.42);
addRoad(scene, [-2.7, -7], [-0.6, 6.5], 0.10, 0.43);
addRoad(scene, [3.5, -6.5], [6.8, 5.7], 0.09, 0.43);
addHill(scene, -8.3, 5.2, 1.5, 2.5, 0x788b69);
addHill(scene, -6.5, 5.8, 1.05, 1.8, 0x87946f);
addHill(scene, 8.0, 5.5, 1.4, 2.2, 0x7c8f6a);
addHill(scene, 8.3, -5.5, 1.1, 1.7, 0x8c9873);
addHill(scene, -7.5, -6.1, 0.95, 1.35, 0x929d76);
const treePositions = [
[-8.8, 0.7], [-8.0, -0.4], [-7.3, 0.8],
[7.6, 1.0], [8.1, 0.1], [7.0, -1.1],
[4.2, -6.2], [3.3, -6.6], [-3.5, -6.5],
[-2.6, -6.1], [1.8, 6.1], [2.7, 6.0]
];
treePositions.forEach(([x, z], i) => {
addTree(scene, x, z, 0.8 + (i % 3) * 0.1);
});
municipalities.forEach((municipality, index) => {
const material = standardMaterial(
index === state.municipality ? COLORS.selection : 0xb6b495,
{
transparent: true,
opacity: index === state.municipality ? 0.72 : 0.24,
depthWrite: false,
side: THREE.DoubleSide
}
);
const mesh = addPolygonMesh(
scene,
municipality.shape,
0.34,
material
);
mesh.userData.municipality = index;
regionPickables.push(mesh);
addBoundary(scene, municipality.shape, 0.52, 0.036);
});
selectedRegionMaterial = regionPickables[state.municipality].material;
}
function updateRegionSelection() {
regionPickables.forEach((mesh, index) => {
const selected = index === state.municipality;
mesh.material.color.setHex(selected ? COLORS.selection : 0xb6b495);
mesh.material.opacity = selected ? 0.72 : 0.24;
mesh.material.needsUpdate = true;
});
selectedRegionMaterial = regionPickables[state.municipality].material;
}
function clearGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
materials.forEach(material => material.dispose());
}
});
}
}
function districtPolygon(index, scale = 1) {
const center = districtCenters[index];
const localPoints = [
[-0.78, -0.62], [0.72, -0.68], [0.87, 0.48],
[0.18, 0.72], [-0.84, 0.56]
];
return localPoints.map(([x, z]) => [
center.x + x * scale,
center.z + z * scale
]);
}
function buildMunicipality(view) {
const scene = view.scene;
if (!view.dynamicGroup) {
view.dynamicGroup = new THREE.Group();
scene.add(view.dynamicGroup);
}
clearGroup(view.dynamicGroup);
municipalPickables = [];
addBase(scene, 13, 10);
addTerrain(scene, 12.8, 9.8, 18, 0.13, 0xa1aa80);
addWater(scene, [
[-6.2, -3.6], [-2.6, -3.0], [1.0, -3.5],
[6.2, -2.6], [6.2, -3.4], [1.0, -4.2],
[-2.7, -3.7], [-6.2, -4.3]
], 0.18);
addRoad(scene, [-5.8, -1.5], [5.8, 1.9], 0.12, 0.24);
addRoad(scene, [-2.2, -4.1], [1.0, 4.2], 0.10, 0.25);
addRoad(scene, [2.0, -4.0], [4.0, 4.0], 0.09, 0.25);
addHill(scene, -4.9, 3.2, 0.9, 1.2, 0x82916c);
addHill(scene, 4.9, 3.2, 1.0, 1.45, 0x87956f);
addHill(scene, 5.2, -3.8, 0.72, 0.9, 0x949d77);
[
[-5.5, 0.1], [-5.0, 0.7], [5.3, 0.4],
[4.8, -4.0], [-3.6, 4.0]
].forEach(([x, z], i) => addTree(scene, x, z, 0.8 + (i % 2) * 0.15));
const municipality = municipalities[state.municipality];
const localBoundary = municipality.shape.map(([x, z]) => [
x - municipality.center[0],
z - municipality.center[1]
]);
addBoundary(view.dynamicGroup, localBoundary, 0.37, 0.04);
districtCenters.forEach((_, index) => {
const selected = index === state.district;
const material = standardMaterial(
selected ? COLORS.selection : 0xc4bda5,
{
transparent: true,
opacity: selected ? 0.83 : 0.5,
depthWrite: false,
side: THREE.DoubleSide
}
);
const footprint = addPolygonMesh(
view.dynamicGroup,
districtPolygon(index, 0.68),
0.31,
material
);
if (selected) {
selectedMunicipalMaterial = material;
footprint.userData.district = index;
municipalPickables.push(footprint);
}
});
const center = districtCenters[state.district];
const pin = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.42, 5),
standardMaterial(COLORS.selection, {
emissive: COLORS.selection,
emissiveIntensity: 0.12
})
);
pin.position.set(center.x, 0.65, center.z);
pin.rotation.x = Math.PI;
pin.castShadow = true;
view.dynamicGroup.add(pin);
}
function buildTown(view) {
const scene = view.scene;
addBase(scene, 12, 9);
addTerrain(scene, 11.8, 8.8, 18, 0.07, 0xa5ad83);
addWater(scene, [
[-5.7, -4.0], [-5.1, -4.0], [-5.0, -1.1],
[-4.7, 1.2], [-5.1, 4.0], [-5.8, 4.0],
[-5.3, 1.1], [-5.7, -1.2], [-6.2, -4.0]
], 0.13);
addRoad(scene, [-5.0, 0.2], [5.4, 0.2], 0.2, 0.14);
addRoad(scene, [-4.7, 2.9], [5.3, 2.9], 0.15, 0.14);
addRoad(scene, [-0.4, -3.8], [-0.4, 3.9], 0.16, 0.145);
addRoad(scene, [3.1, -3.9], [3.1, 2.8], 0.11, 0.145);
const park = addPolygonMesh(
scene,
[[3.8, 1.4], [5.1, 1.5], [5.3, 3.5], [3.8, 3.7]],
0.11,
standardMaterial(0x788b62)
);
park.receiveShadow = true;
addTree(scene, 4.2, 2.0, 0.7);
addTree(scene, 4.8, 2.7, 0.65);
addTree(scene, 4.0, 3.1, 0.58);
const districtHighlights = [];
for (let district = 0; district < 3; district++) {
const material = standardMaterial(COLORS.selection, {
transparent: true,
opacity: 0.48,
depthWrite: false,
side: THREE.DoubleSide
});
const highlight = addPolygonMesh(
scene,
districtPolygon(district, 1),
0.16,
material
);
districtHighlights.push(highlight);
}
view.districtHighlights = districtHighlights;
const buildingSets = [
[
[-3.9, -2.15], [-2.9, -2.25], [-1.9, -2.0],
[-3.7, -1.05], [-2.6, -0.95], [-1.6, -1.25]
],
[
[0.35, -2.1], [1.35, -2.25], [2.3, -1.9],
[0.75, -1.0], [1.85, -0.95]
],
[
[-3.0, 1.25], [-2.0, 1.35], [-1.0, 1.2],
[-3.05, 2.45], [-1.95, 2.55], [-0.95, 2.4]
]
];
let buildingIndex = 0;
buildingSets.forEach((positions, district) => {
positions.forEach(([x, z]) => {
const width = 0.36 + randomSize(buildingIndex) * 0.28;
const depth = 0.32 + randomSize(buildingIndex + 11) * 0.28;
const height = 0.38 + randomSize(buildingIndex + 21) * 0.9;
addBuilding(
scene,
x,
z,
width,
depth,
height,
district,
buildingIndex
);
buildingIndex++;
});
});
const townBoundary = [
[-5.7, -4.0], [-4.9, -4.25], [4.9, -4.15],
[5.65, -3.65], [5.55, 3.9], [4.8, 4.2],
[-4.9, 4.1], [-5.7, 3.45]
];
addBoundary(scene, townBoundary, 0.22, 0.028);
}
function updateTownSelection() {
const townView = views["town-viewport"];
townView.districtHighlights.forEach((highlight, index) => {
highlight.visible = index === state.district;
});
townPickables.forEach(roof => {
const selected = roof.userData.district === state.district;
roof.material.color.setHex(
selected ? COLORS.selection :
roof.userData.roof && townPickables.indexOf(roof) % 2 === 0
? COLORS.roof
: COLORS.roofAlt
);
});
}
function updateHeader() {
const municipality = municipalities[state.municipality];
const district = districtNames[state.district];
document.getElementById("municipality-name").textContent = municipality.name;
document.getElementById("town-name").textContent = municipality.town;
document.getElementById("district-name").textContent = district;
document.getElementById("path-label").textContent =
`North Vale / ${municipality.name} / ${district}`;
document.getElementById("region-focus").textContent =
`Focused: ${municipality.name}`;
document.getElementById("municipality-focus").textContent =
`Town: ${municipality.town}`;
document.getElementById("town-focus").textContent =
`${district} selected`;
}
function setMunicipality(index) {
state.municipality = index;
state.district = 0;
updateRegionSelection();
buildMunicipality(views["municipality-viewport"]);
updateTownSelection();
updateHeader();
}
function setDistrict(index) {
state.district = index;
buildMunicipality(views["municipality-viewport"]);
updateTownSelection();
updateHeader();
}
function pick(event, camera, objects) {
if (!objects.length) return null;
const canvas = camera.userData?.canvas;
const rect = event.currentTarget.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);
return raycaster.intersectObjects(objects, false)[0] || null;
}
const regionView = createView("region-viewport", {
target: [0, 0.2, 0],
distance: 29,
yaw: 0.52,
pitch: 0.72
});
const municipalityView = createView("municipality-viewport", {
target: [0, 0.15, 0],
distance: 21,
yaw: 0.70,
pitch: 0.66
});
const townView = createView("town-viewport", {
target: [0, 0.2, 0],
distance: 17.5,
yaw: 0.64,
pitch: 0.63
});
buildRegion(regionView);
buildMunicipality(municipalityView);
buildTown(townView);
updateTownSelection();
updateHeader();
regionView.rig.onTap = event => {
const hit = pick(event, regionView.camera, regionPickables);
if (!hit) return;
const index = hit.object.userData.municipality;
if (Number.isInteger(index)) setMunicipality(index);
};
municipalityView.rig.onTap = event => {
const hit = pick(event, municipalityView.camera, municipalPickables);
if (!hit) return;
const index = hit.object.userData.district;
if (Number.isInteger(index)) setDistrict(index);
};
townView.rig.onTap = event => {
const hit = pick(event, townView.camera, townPickables);
if (!hit) return;
const index = hit.object.userData.district;
if (Number.isInteger(index)) setDistrict(index);
};
document.getElementById("reset-view").addEventListener("click", () => {
cameraRigs.forEach(rig => rig.reset());
});
function animate(time) {
cameraRigs.forEach(rig => rig.update());
if (selectedRegionMaterial) {
selectedRegionMaterial.opacity =
0.68 + Math.sin(time * 0.0028) * 0.06;
}
if (selectedMunicipalMaterial) {
selectedMunicipalMaterial.opacity =
0.79 + Math.sin(time * 0.0032) * 0.06;
}
Object.values(views).forEach(view => {
view.renderer.render(view.scene, view.camera);
});
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```