Prompt specification
Build or customize the Three.js 3D scene "Choose a visitor route that preserves residential access" 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: Choose a visitor route that preserves residential access
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/choose-a-visitor-route-that-preserves-residential-acce-x3020
Scene Description Prompt:
Plan a fictional voxel walking route through Seoul’s Bukchon, excluding private courtyards and preserving household access. Three.js from cdnjs in standalone HTML.
Working Three.js Starter (choose-a-visitor-route-that-preserves-residential-acce-x3020):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bukchon Commons Loop — Fictional Voxel Walk</title>
<style>
:root {
color-scheme: light;
--ink: #17332f;
--muted: #5e716c;
--paper: rgba(250, 248, 238, 0.94);
--paper-solid: #faf8ee;
--line: rgba(23, 51, 47, 0.16);
--teal: #087e79;
--teal-dark: #075e5b;
--gold: #e8ad3d;
--shadow: 0 16px 48px rgba(23, 51, 47, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e3;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
cursor: pointer;
}
button:focus-visible,
input:focus-visible {
outline: 3px solid rgba(232, 173, 61, 0.9);
outline-offset: 2px;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#labelLayer {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.map-label {
position: absolute;
transform: translate(-50%, -100%);
display: flex;
align-items: center;
gap: 7px;
max-width: 190px;
padding: 7px 10px 7px 7px;
border: 1px solid rgba(23, 51, 47, 0.16);
border-radius: 9px;
background: rgba(250, 248, 238, 0.94);
color: var(--ink);
box-shadow: 0 6px 20px rgba(23, 51, 47, 0.15);
font-size: 11px;
font-weight: 750;
line-height: 1.2;
text-align: left;
pointer-events: auto;
}
.map-label span {
display: grid;
flex: 0 0 24px;
width: 24px;
height: 24px;
place-items: center;
border-radius: 6px;
background: var(--teal);
color: white;
font-size: 11px;
}
#titleCard {
position: fixed;
top: 20px;
left: 20px;
z-index: 5;
width: min(440px, calc(100vw - 420px));
padding: 17px 19px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.eyebrow {
margin: 0 0 5px;
color: var(--teal-dark);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(24px, 3vw, 36px);
font-weight: 600;
letter-spacing: -0.035em;
line-height: 1.02;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.badges {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 12px;
}
.badge {
padding: 5px 8px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.48);
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.badge.route {
border-color: rgba(8, 126, 121, 0.25);
background: rgba(8, 126, 121, 0.09);
color: var(--teal-dark);
}
#panel {
position: fixed;
top: 20px;
right: 20px;
bottom: 20px;
z-index: 5;
display: flex;
width: 370px;
flex-direction: column;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.panel-scroll {
min-height: 0;
flex: 1;
overflow-y: auto;
padding: 18px;
scrollbar-width: thin;
scrollbar-color: rgba(23, 51, 47, 0.25) transparent;
}
.panel-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
padding: 14px 18px 0;
}
.control-button {
min-height: 42px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.6);
color: var(--ink);
font-size: 12px;
font-weight: 800;
}
.control-button.primary {
border-color: var(--teal);
background: var(--teal);
color: white;
}
.control-button:hover {
filter: brightness(0.97);
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin: 16px 0;
}
.stat {
padding: 10px 8px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.42);
text-align: center;
}
.stat strong {
display: block;
font-size: 16px;
}
.stat span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.section-title {
margin: 20px 0 9px;
font-size: 11px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#waypoints {
display: grid;
gap: 5px;
margin: 0;
padding: 0;
list-style: none;
}
.waypoint {
width: 100%;
display: grid;
grid-template-columns: 28px 1fr auto;
align-items: center;
gap: 9px;
padding: 9px;
border: 1px solid transparent;
border-radius: 9px;
background: transparent;
color: var(--ink);
text-align: left;
}
.waypoint:hover,
.waypoint.current {
border-color: rgba(8, 126, 121, 0.2);
background: rgba(8, 126, 121, 0.08);
}
.waypoint-number {
display: grid;
width: 27px;
height: 27px;
place-items: center;
border-radius: 7px;
background: var(--teal);
color: white;
font-size: 11px;
font-weight: 900;
}
.waypoint-name {
display: block;
font-size: 12px;
font-weight: 800;
}
.waypoint-kind {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.waypoint-time {
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.progress-card {
margin-top: 18px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.42);
}
.progress-row {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
#progress {
width: 100%;
accent-color: var(--teal);
}
.access-card {
margin-top: 16px;
padding: 13px;
border: 1px solid rgba(8, 126, 121, 0.2);
border-radius: 11px;
background: rgba(8, 126, 121, 0.08);
}
.access-card h3 {
margin: 0 0 8px;
color: var(--teal-dark);
font-size: 12px;
}
.access-card ul {
margin: 0;
padding-left: 17px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.note {
margin: 14px 0 0;
padding-top: 13px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
#legend {
position: fixed;
bottom: 20px;
left: 20px;
z-index: 5;
display: flex;
flex-wrap: wrap;
gap: 10px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 11px;
background: var(--paper);
box-shadow: var(--shadow);
color: var(--muted);
font-size: 10px;
font-weight: 750;
backdrop-filter: blur(10px);
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 18px;
height: 5px;
border-radius: 999px;
background: var(--gold);
}
.swatch.street {
background: #737b78;
}
.swatch.private {
background: #be7655;
}
#help {
position: fixed;
right: 410px;
bottom: 20px;
z-index: 4;
max-width: 340px;
padding: 9px 12px;
border-radius: 10px;
background: rgba(23, 51, 47, 0.78);
color: white;
font-size: 10px;
line-height: 1.45;
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e7eee8;
color: var(--teal-dark);
font-size: 13px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
[hidden] {
display: none !important;
}
@media (max-width: 780px) {
#titleCard {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 12px 14px;
}
.subtitle,
.badges {
display: none;
}
#panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
height: 49vh;
}
.panel-scroll {
padding: 14px;
}
.panel-actions {
padding: 10px 14px 0;
}
#help,
#legend {
display: none;
}
.map-label {
max-width: 145px;
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive voxel model of a fictional public-street walking loop through Bukchon, Seoul"
></canvas>
<div id="labelLayer" aria-hidden="false"></div>
<header id="titleCard">
<p class="eyebrow">Seoul · Bukchon Hanok Village</p>
<h1>Bukchon Commons Loop</h1>
<p class="subtitle">
A fictional public-street walk through a schematic voxel neighborhood.
Courtyards and residential gates remain off-route.
</p>
<div class="badges" aria-label="Route characteristics">
<span class="badge route">Public-road route</span>
<span class="badge">Household access preserved</span>
<span class="badge">Schematic—not GPS navigation</span>
</div>
</header>
<aside id="panel" aria-label="Route plan">
<div class="panel-actions">
<button class="control-button" id="overviewBtn" type="button">
Overview
</button>
<button class="control-button primary" id="walkBtn" type="button">
Start walk
</button>
</div>
<div class="panel-scroll">
<p class="eyebrow">Walking plan</p>
<div class="stats" aria-label="Route statistics">
<div class="stat">
<strong>2.4 km</strong>
<span>Loop</span>
</div>
<div class="stat">
<strong>45 min</strong>
<span>Walking</span>
</div>
<div class="stat">
<strong>7</strong>
<span>Junctions</span>
</div>
</div>
<ol id="waypoints"></ol>
<div class="progress-card">
<div class="progress-row">
<span id="progressText">0 / 45 minutes</span>
<span id="modeText">Overview</span>
</div>
<label for="progress" class="eyebrow">Route position</label>
<input
id="progress"
type="range"
min="0"
max="1000"
value="0"
aria-label="Position along the route"
>
</div>
<section class="access-card" aria-labelledby="accessTitle">
<h3 id="accessTitle">Household access rules</h3>
<ul>
<li>Use only the marked public street corridor.</li>
<li>Do not enter gates, private lanes, or courtyards.</li>
<li>Keep the route side clear for residents and deliveries.</li>
<li>Pause only at widened public areas, not at driveways.</li>
<li>Yield to household vehicles and emergency access.</li>
</ul>
</section>
<p class="note">
<strong>Planning note:</strong> This is an illustrative route, not a
surveyed itinerary or a substitute for official local guidance.
Check closures, resident signs, accessibility conditions, and opening
hours before visiting. Older lanes may include steps or steep grades;
use a lower public street when a step-free route is required.
</p>
</div>
</aside>
<div id="legend" aria-label="Map legend">
<span class="legend-item"><span class="swatch"></span> Walkable route</span>
<span class="legend-item"><span class="swatch street"></span> Public street</span>
<span class="legend-item"><span class="swatch private"></span> Private edge</span>
</div>
<div id="help">
Drag to orbit · wheel to zoom · click a numbered waypoint · press 2 for
walking view · W/S or arrow keys to move · space to pause
</div>
<div id="loading" role="status">Building the Bukchon voxel route…</div>
<noscript>This route visualization requires JavaScript.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Core setup
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const labelLayer = document.querySelector("#labelLayer");
const panel = document.querySelector("#panel");
const waypointList = document.querySelector("#waypoints");
const progressInput = document.querySelector("#progress");
const progressText = document.querySelector("#progressText");
const modeText = document.querySelector("#modeText");
const overviewBtn = document.querySelector("#overviewBtn");
const walkBtn = document.querySelector("#walkBtn");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e3);
scene.fog = new THREE.Fog(0xdce8e3, 105, 230);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
350
);
scene.add(new THREE.HemisphereLight(0xf8fff7, 0x738579, 2.15));
const sun = new THREE.DirectionalLight(0xfff1d2, 2.7);
sun.position.set(-48, 75, 38);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -85;
sun.shadow.camera.right = 85;
sun.shadow.camera.top = 90;
sun.shadow.camera.bottom = -90;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 190;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8e9ee, 0.55);
fill.position.set(55, 28, -60);
scene.add(fill);
const world = new THREE.Group();
scene.add(world);
const boxGeometry = new THREE.BoxGeometry(1, 1, 1);
const palette = {
ground: 0xc9d2b6,
pavement: 0xbfc3b9,
street: 0x707875,
route: 0xf0b743,
wall: 0xe5ddc7,
wallWarm: 0xd8cdb3,
roof: 0x3f4b4c,
roofWarm: 0x554c43,
wood: 0x7a5840,
window: 0x304947,
leaf: 0x5f8a63,
leafLight: 0x7fa172,
trunk: 0x76533d
};
function makeBox(width, height, depth, material, x, y, z, yaw = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.rotation.y = yaw;
mesh.receiveShadow = true;
mesh.castShadow = true;
world.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Schematic route geometry
// Coordinates are intentionally fictional and not georeferenced.
// ------------------------------------------------------------
const routeCoordinates = [
[-8, 42],
[-2, 32],
[2, 22],
[14, 12],
[24, -2],
[16, -16],
[2, -28],
[-8, -42],
[-8, -58],
[8, -68],
[24, -58],
[26, -38],
[18, -18],
[8, -2],
[-4, 12],
[-10, 28]
];
const routePoints = routeCoordinates.map(
([x, z]) => new THREE.Vector3(x, 0, z)
);
const segmentLengths = [];
let totalRouteLength = 0;
for (let i = 0; i < routePoints.length; i++) {
const a = routePoints[i];
const b = routePoints[(i + 1) % routePoints.length];
const length = Math.hypot(b.x - a.x, b.z - a.z);
segmentLengths.push(length);
totalRouteLength += length;
}
const cumulativeLengths = [0];
for (const length of segmentLengths) {
cumulativeLengths.push(cumulativeLengths.at(-1) + length);
}
function sampleRoute(distance) {
const d = ((distance % totalRouteLength) + totalRouteLength)
% totalRouteLength;
for (let i = 0; i < segmentLengths.length; i++) {
const end = cumulativeLengths[i + 1];
if (d <= end) {
const segment = segmentLengths[i];
const t = segment === 0 ? 0 : (d - cumulativeLengths[i]) / segment;
const a = routePoints[i];
const b = routePoints[(i + 1) % routePoints.length];
return {
position: a.clone().lerp(b, t),
tangent: b.clone().sub(a).normalize()
};
}
}
return {
position: routePoints[0].clone(),
tangent: routePoints[1].clone().sub(routePoints[0]).normalize()
};
}
function distanceToRoute(x, z) {
let minimum = Infinity;
for (let i = 0; i < routePoints.length; i++) {
const a = routePoints[i];
const b = routePoints[(i + 1) % routePoints.length];
const dx = b.x - a.x;
const dz = b.z - a.z;
const lengthSquared = dx * dx + dz * dz;
const t = lengthSquared
? THREE.MathUtils.clamp(
((x - a.x) * dx + (z - a.z) * dz) / lengthSquared,
0,
1
)
: 0;
const closestX = a.x + dx * t;
const closestZ = a.z + dz * t;
minimum = Math.min(
minimum,
Math.hypot(x - closestX, z - closestZ)
);
}
return minimum;
}
const groundMaterial = new THREE.MeshStandardMaterial({
color: palette.ground,
roughness: 1
});
const pavementMaterial = new THREE.MeshStandardMaterial({
color: palette.pavement,
roughness: 1
});
const streetMaterial = new THREE.MeshStandardMaterial({
color: palette.street,
roughness: 0.96
});
const routeMaterial = new THREE.MeshStandardMaterial({
color: palette.route,
emissive: 0x7b4b00,
emissiveIntensity: 0.16,
roughness: 0.68
});
makeBox(92, 1, 154, groundMaterial, 6, -0.55, -12);
// Public street corridors and the highlighted walking line.
for (let i = 0; i < routePoints.length; i++) {
const a = routePoints[i];
const b = routePoints[(i + 1) % routePoints.length];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const yaw = Math.atan2(dx, dz);
const midX = (a.x + b.x) / 2;
const midZ = (a.z + b.z) / 2;
const pavement = makeBox(
8.1,
0.12,
length + 0.45,
pavementMaterial,
midX,
0.03,
midZ,
yaw
);
pavement.castShadow = false;
const street = makeBox(
6.25,
0.12,
length + 0.2,
streetMaterial,
midX,
0.075,
midZ,
yaw
);
street.castShadow = false;
const route = makeBox(
0.66,
0.11,
length + 0.2,
routeMaterial,
midX,
0.17,
midZ,
yaw
);
route.castShadow = false;
}
// Small square route dashes create a more explicit voxel rhythm.
const dashEntries = [];
const dummy = new THREE.Object3D();
for (let d = 0; d < totalRouteLength; d += 2.15) {
const sample = sampleRoute(d);
dummy.position.copy(sample.position);
dummy.position.y = 0.25;
dummy.rotation.set(
0,
Math.atan2(sample.tangent.x, sample.tangent.z),
0
);
dummy.scale.set(0.82, 0.11, 0.55);
dummy.updateMatrix();
dashEntries.push(dummy.matrix.clone());
}
const dashMesh = new THREE.InstancedMesh(
boxGeometry,
routeMaterial,
dashEntries.length
);
dashEntries.forEach((matrix, index) => {
dashMesh.setMatrixAt(index, matrix);
dashMesh.setColorAt(index, new THREE.Color(0xffd267));
});
dashMesh.instanceMatrix.needsUpdate = true;
dashMesh.instanceColor.needsUpdate = true;
world.add(dashMesh);
// ------------------------------------------------------------
// Instanced voxel buildings
// ------------------------------------------------------------
const wallEntries = [];
const roofEntries = [];
const woodEntries = [];
const windowEntries = [];
function pushInstance(list, x, y, z, sx, sy, sz, color, yaw = 0, pitch = 0) {
dummy.position.set(x, y, z);
dummy.rotation.order = "YXZ";
dummy.rotation.set(pitch, yaw, 0);
dummy.scale.set(sx, sy, sz);
dummy.updateMatrix();
list.push({ matrix: dummy.matrix.clone(), color });
}
function localPoint(cx, cz, localX, localZ, yaw) {
const cos = Math.cos(yaw);
const sin = Math.sin(yaw);
return {
x: cx + localX * cos + localZ * sin,
z: cz - localX * sin + localZ * cos
};
}
let seed = 1729;
function random() {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
const buildingCenters = [];
for (let z = -72; z <= 45; z += 12.5) {
for (let x = -36; x <= 34; x += 12.5) {
const jitterX = (random() - 0.5) * 2.3;
const jitterZ = (random() - 0.5) * 2.3;
const bx = x + jitterX;
const bz = z + jitterZ;
// Keep all structures clear of the public walking corridor.
if (distanceToRoute(bx, bz) < 10.8 || random() < 0.12) {
continue;
}
buildingCenters.push({ x: bx, z: bz });
const width = 7.4 + random() * 1.8;
const depth = 8.1 + random() * 1.6;
const height = 3.8 + random() * 1.8;
const yaw = random() > 0.5 ? 0 : Math.PI / 2;
const wallColor = random() > 0.5
? palette.wall
: palette.wallWarm;
const roofColor = random() > 0.5
? palette.roof
: palette.roofWarm;
pushInstance(
wallEntries,
bx,
height / 2 + 0.1,
bz,
width,
height,
depth,
wallColor,
yaw
);
// Two sloping roof slabs form a simple pitched hanok silhouette.
for (const side of [-1, 1]) {
const roofCenter = localPoint(
bx,
bz,
0,
side * depth * 0.245,
yaw
);
pushInstance(
roofEntries,
roofCenter.x,
height + 1.15,
roofCenter.z,
width + 1.35,
0.38,
depth * 0.59,
roofColor,
yaw,
side * 0.56
);
}
// Front windows and a central doorway.
for (const localX of [-width * 0.25, width * 0.25]) {
const windowPoint = localPoint(
bx,
bz,
localX,
depth / 2 + 0.045,
yaw
);
pushInstance(
windowEntries,
windowPoint.x,
2.2,
windowPoint.z,
0.92,
1.12,
0.09,
palette.window,
yaw
);
}
const doorPoint = localPoint(bx, bz, 0, depth / 2 + 0.05, yaw);
pushInstance(
woodEntries,
doorPoint.x,
1.12,
doorPoint.z,
1.05,
2.05,
0.11,
palette.wood,
yaw
);
// A low timber lintel reinforces the private-house character.
pushInstance(
woodEntries,
bx,
height * 0.58,
bz,
width + 0.12,
0.18,
depth + 0.12,
palette.wood,
yaw
);
}
}
function buildInstancedMesh(entries, material, castShadow = true) {
const mesh = new THREE.InstancedMesh(
boxGeometry,
material,
entries.length
);
entries.forEach((entry, index) => {
mesh.setMatrixAt(index, entry.matrix);
mesh.setColorAt(index, new THREE.Color(entry.color));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) {
mesh.instanceColor.needsUpdate = true;
}
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
world.add(mesh);
return mesh;
}
buildInstancedMesh(
wallEntries,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96
})
);
buildInstancedMesh(
roofEntries,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.88
})
);
buildInstancedMesh(
woodEntries,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95
})
);
buildInstancedMesh(
windowEntries,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.38,
metalness: 0.08
})
);
// ------------------------------------------------------------
// Trees and public-edge landscaping
// ------------------------------------------------------------
const trunkEntries = [];
const leafEntries = [];
function addTree(x, z, scale = 1) {
if (distanceToRoute(x, z) < 6.8) return;
pushInstance(
trunkEntries,
x,
1.35 * scale,
z,
0.45 * scale,
2.7 * scale,
0.45 * scale,
palette.trunk
);
pushInstance(
leafEntries,
x,
3.4 * scale,
z,
2.65 * scale,
2.55 * scale,
2.65 * scale,
palette.leaf
);
pushInstance(
leafEntries,
x + 0.35 * scale,
4.6 * scale,
z - 0.15 * scale,
1.75 * scale,
1.7 * scale,
1.75 * scale,
palette.leafLight
);
}
// Street trees sit outside the walking width.
for (let d = 4; d < totalRouteLength; d += 9.5) {
const sample = sampleRoute(d);
const normalX = sample.tangent.z;
const normalZ = -sample.tangent.x;
addTree(
sample.position.x + normalX * 4.25,
sample.position.z + normalZ * 4.25,
0.72 + random() * 0.15
);
}
// Park-like clusters on the outer edges.
for (let i = 0; i < 28; i++) {
const x = -40 + random() * 78;
const z = -73 + random() * 120;
const nearBuilding = buildingCenters.some(
(building) =>
Math.hypot(building.x - x, building.z - z) < 5.5
);
if (!nearBuilding && distanceToRoute(x, z) > 8.5) {
addTree(x, z, 0.85 + random() * 0.45);
}
}
buildInstancedMesh(
trunkEntries,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
})
);
buildInstancedMesh(
leafEntries,
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
})
);
// ------------------------------------------------------------
// Waypoints
// ------------------------------------------------------------
const waypointData = [
{
index: 0,
name: "Jongno 3-ga plaza",
kind: "Public plaza · start",
time: 0,
note: "Begin on the open public plaza edge."
},
{
index: 2,
name: "Bukchon-ro 11-gil north",
kind: "Shared public street",
time: 6,
note: "Use the outer sidewalk and keep the center clear."
},
{
index: 4,
name: "Samcheong-dong junction",
kind: "Public intersection",
time: 12,
note: "Cross only where the public street continues."
},
{
index: 6,
name: "Wonseo-dong junction",
kind: "Public lane",
time: 18,
note: "This fictional segment includes a short incline."
},
{
index: 8,
name: "Bukchon-ro 11-gil south",
kind: "Shared public street",
time: 25,
note: "Yield to household vehicles before turning."
},
{
index: 10,
name: "Acroak Forest edge",
kind: "Public sidewalk",
time: 31,
note: "Stay on the public edge; do not cut through gardens."
},
{
index: 12,
name: "Gahoe-dong return",
kind: "Public lane · finish",
time: 38,
note: "Rejoin the public street and return toward the plaza."
}
];
const markerGroup = new THREE.Group();
world.add(markerGroup);
const markerBaseMaterial = new THREE.MeshStandardMaterial({
color: 0xf8f3df,
roughness: 0.8
});
const markerGoldMaterial = new THREE.MeshStandardMaterial({
color: palette.route,
emissive: 0x7b4b00,
emissiveIntensity: 0.18,
roughness: 0.55
});
const markerPostMaterial = new THREE.MeshStandardMaterial({
color: 0x2c5c57,
roughness: 0.75
});
function addBoxToGroup(group, width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
const labels = [];
waypointData.forEach((waypoint, index) => {
const point = routePoints[waypoint.index];
const group = new THREE.Group();
group.position.copy(point);
markerGroup.add(group);
addBoxToGroup(group, 1.35, 0.25, 1.35, markerBaseMaterial, 0, 0.27, 0);
addBoxToGroup(group, 0.18, 2.45, 0.18, markerPostMaterial, 0, 1.35, 0);
addBoxToGroup(group, 0.72, 0.72, 0.72, markerGoldMaterial, 0, 2.85, 0);
// Square frame around the marker cube.
addBoxToGroup(group, 1.25, 0.12, 0.12, markerGoldMaterial, 0, 2.85, 0.6);
addBoxToGroup(group, 1.25, 0.12, 0.12, markerGoldMaterial, 0, 2.85, -0.6);
addBoxToGroup(group, 0.12, 0.12, 1.25, markerGoldMaterial, 0.6, 2.85, 0);
addBoxToGroup(group, 0.12, 0.12, 1.25, markerGoldMaterial, -0.6, 2.85, 0);
const label = document.createElement("button");
label.type = "button";
label.className = "map-label";
label.innerHTML = `<span>${index + 1}</span>${waypoint.name}`;
label.setAttribute(
"aria-label",
`Focus waypoint ${index + 1}: ${waypoint.name}`
);
label.addEventListener("click", () => focusWaypoint(index));
labelLayer.appendChild(label);
const listItem = document.createElement("li");
const listButton = document.createElement("button");
listButton.type = "button";
listButton.className = "waypoint";
listButton.dataset.index = String(index);
listButton.innerHTML = `
<span class="waypoint-number">${index + 1}</span>
<span>
<span class="waypoint-name">${waypoint.name}</span>
<span class="waypoint-kind">${waypoint.kind}</span>
</span>
<span class="waypoint-time">${waypoint.time} min</span>
`;
listButton.addEventListener("click", () => focusWaypoint(index));
listItem.appendChild(listButton);
waypointList.appendChild(listItem);
labels.push({
element: label,
listButton,
marker: group,
waypoint
});
});
// ------------------------------------------------------------
// Walking avatar
// ------------------------------------------------------------
const avatar = new THREE.Group();
world.add(avatar);
const avatarBodyMaterial = new THREE.MeshStandardMaterial({
color: 0x087e79,
roughness: 0.72
});
const avatarDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x263d3a,
roughness: 0.86
});
const avatarSkinMaterial = new THREE.MeshStandardMaterial({
color: 0xe4b98f,
roughness: 0.88
});
addBoxToGroup(avatar, 0.68, 0.92, 0.42, avatarBodyMaterial, 0, 1.18, 0);
addBoxToGroup(avatar, 0.52, 0.5, 0.48, avatarSkinMaterial, 0, 1.88, 0);
addBoxToGroup(avatar, 0.23, 0.63, 0.25, avatarDarkMaterial, -0.2, 0.38, 0);
addBoxToGroup(avatar, 0.23, 0.63, 0.25, avatarDarkMaterial, 0.2, 0.38, 0);
addBoxToGroup(avatar, 0.2, 0.72, 0.22, avatarBodyMaterial, -0.49, 1.2, 0);
addBoxToGroup(avatar, 0.2, 0.72, 0.22, avatarBodyMaterial, 0.49, 1.2, 0);
// ------------------------------------------------------------
// Camera and interaction state
// ------------------------------------------------------------
const state = {
mode: "overview",
autoWalk: false,
progress: 0,
target: new THREE.Vector3(6, 0, -12),
radius: 126,
elevation: 0.78,
azimuth: 0.45,
lookYaw: 0,
lookPitch: -0.04,
dragging: false,
pointerX: 0,
pointerY: 0,
forward: false,
backward: false
};
function setMode(mode) {
state.mode = mode;
if (mode === "overview") {
state.autoWalk = false;
state.forward = false;
state.backward = false;
} else {
state.lookYaw = 0;
state.lookPitch = -0.04;
}
modeText.textContent = mode === "overview" ? "Overview" : "Walking view";
walkBtn.textContent =
mode === "overview"
? "Start walk"
: state.autoWalk
? "Pause walk"
: "Resume walk";
}
function focusWaypoint(index) {
const waypoint = waypointData[index];
setMode("overview");
state.target.copy(routePoints[waypoint.index]);
state.radius = 39;
state.elevation = 0.67;
}
overviewBtn.addEventListener("click", () => {
setMode("overview");
state.target.set(6, 0, -12);
state.radius = 126;
state.elevation = 0.78;
state.azimuth = 0.45;
});
walkBtn.addEventListener("click", () => {
if (state.mode === "overview") {
setMode("walk");
state.autoWalk = true;
} else {
state.autoWalk = !state.autoWalk;
}
walkBtn.textContent = state.autoWalk ? "Pause walk" : "Resume walk";
});
progressInput.addEventListener("input", () => {
state.progress =
(Number(progressInput.value) / 1000) * totalRouteLength;
state.autoWalk = false;
walkBtn.textContent = state.mode === "walk" ? "Resume walk" : "Start walk";
});
canvas.addEventListener("pointerdown", (event) => {
state.dragging = true;
state.pointerX = event.clientX;
state.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!state.dragging) return;
const dx = event.clientX - state.pointerX;
const dy = event.clientY - state.pointerY;
state.pointerX = event.clientX;
state.pointerY = event.clientY;
if (state.mode === "overview") {
state.azimuth -= dx * 0.006;
state.elevation = THREE.MathUtils.clamp(
state.elevation + dy * 0.004,
0.28,
1.35
);
} else {
state.lookYaw -= dx * 0.004;
state.lookPitch = THREE.MathUtils.clamp(
state.lookPitch - dy * 0.003,
-0.55,
0.5
);
}
});
function endDrag(event) {
state.dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
state.radius = THREE.MathUtils.clamp(
state.radius + event.deltaY * 0.08,
24,
175
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
state.autoWalk = !state.autoWalk;
walkBtn.textContent = state.autoWalk ? "Pause walk" : "Resume walk";
}
if (event.code === "KeyW" || event.code === "ArrowUp") {
state.forward = true;
}
if (event.code === "KeyS" || event.code === "ArrowDown") {
state.backward = true;
}
if (event.code === "Digit1") {
setMode("overview");
}
if (event.code === "Digit2") {
setMode("walk");
}
if (event.code === "Escape") {
setMode("overview");
}
});
window.addEventListener("keyup", (event) => {
if (event.code === "KeyW" || event.code === "ArrowUp") {
state.forward = false;
}
if (event.code === "KeyS" || event.code === "ArrowDown") {
state.backward = false;
}
});
// ------------------------------------------------------------
// UI updates and animation
// ------------------------------------------------------------
function updateWaypointUI() {
const simulatedMinutes = (state.progress / totalRouteLength) * 45;
progressText.textContent = `${simulatedMinutes.toFixed(1)} / 45 minutes`;
progressInput.value = String(
Math.round((state.progress / totalRouteLength) * 1000)
);
let nearestIndex = 0;
let nearestDifference = Infinity;
labels.forEach((label, index) => {
const waypointDistance = cumulativeLengths[label.waypoint.index];
const difference = Math.abs(state.progress - waypointDistance);
if (difference < nearestDifference) {
nearestDifference = difference;
nearestIndex = index;
}
label.listButton.classList.toggle(
"current",
index === nearestIndex
);
});
}
const projected = new THREE.Vector3();
const cameraDirection = new THREE.Vector3();
const desiredCameraPosition = new THREE.Vector3();
const lookTarget = new THREE.Vector3();
const avatarSample = sampleRoute(0);
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (state.mode === "walk") {
const autoSpeed = totalRouteLength / 105;
const manualSpeed = totalRouteLength / 28;
if (state.autoWalk) {
state.progress += autoSpeed * delta;
}
if (state.forward) {
state.progress += manualSpeed * delta;
}
if (state.backward) {
state.progress -= manualSpeed * delta;
}
state.progress =
((state.progress % totalRouteLength) + totalRouteLength)
% totalRouteLength;
const sample = sampleRoute(state.progress);
const ahead = sampleRoute(state.progress + 4);
avatar.position.copy(sample.position);
avatar.position.y = 0.23;
avatar.rotation.y = Math.atan2(sample.tangent.x, sample.tangent.z);
const eye = sample.position.clone();
eye.y = 2.55;
const routeYaw = Math.atan2(ahead.tangent.x, ahead.tangent.z);
const yaw = routeYaw + state.lookYaw;
cameraDirection.set(
Math.sin(yaw) * Math.cos(state.lookPitch),
Math.sin(state.lookPitch),
Math.cos(yaw) * Math.cos(state.lookPitch)
);
lookTarget.copy(eye).addScaledVector(cameraDirection, 12);
const walkingBlend = 1 - Math.exp(-delta * 10);
camera.position.lerp(eye, walkingBlend);
camera.lookAt(lookTarget);
} else {
const horizontalRadius =
state.radius * Math.cos(state.elevation);
desiredCameraPosition.set(
state.target.x + Math.sin(state.azimuth) * horizontalRadius,
state.target.y + Math.sin(state.elevation) * state.radius,
state.target.z + Math.cos(state.azimuth) * horizontalRadius
);
const overviewBlend = 1 - Math.exp(-delta * 6);
camera.position.lerp(desiredCameraPosition, overviewBlend);
camera.lookAt(state.target);
}
// Project waypoint labels into screen space.
labels.forEach((label) => {
label.marker.getWorldPosition(projected);
projected.y += 3.8;
projected.project(camera);
const inFront = projected.z > -1 && projected.z < 1;
const onScreen =
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
const nearInWalkingMode =
state.mode === "overview" ||
camera.position.distanceTo(label.marker.position) < 19;
const visible = inFront && onScreen && nearInWalkingMode;
label.element.style.display = visible ? "flex" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
});
updateWaypointUI();
renderer.render(scene, camera);
if (firstFrame) {
document.querySelector("#loading").hidden = true;
firstFrame = false;
}
requestAnimationFrame(animate);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
avatar.position.copy(avatarSample.position);
avatar.position.y = 0.23;
setMode("overview");
updateWaypointUI();
animate();
</script>
</body>
</html>
```