Prompt specification
Build or customize the Three.js 3D scene "Visitor moving from Bellavista street to hill 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: Visitor moving from Bellavista street to hill access
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/visitor-moving-from-bellavista-street-to-hill-access-x2790
Scene Description Prompt:
Follow a voxel visitor from Santiago’s Bellavista sidewalk and crossing toward San Cristóbal hill access. Make one HTML file using Three.js from cdnjs.
Working Three.js Starter (visitor-moving-from-bellavista-street-to-hill-access-x2790):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bellavista → San Cristóbal — Voxel Walk</title>
<style>
:root {
--ink: #17332f;
--muted: #667b73;
--paper: rgba(250, 248, 238, 0.92);
--line: rgba(23, 51, 47, 0.14);
--green: #2c7a5b;
--yellow: #f2c84b;
--coral: #e56b4d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9e5df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 28px;
left: 30px;
max-width: 520px;
text-shadow: 0 1px 18px rgba(255, 255, 255, 0.8);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 3px;
content: "";
background: var(--coral);
}
h1 {
margin: 0;
font-size: clamp(29px, 4vw, 55px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 850;
}
h1 span {
color: var(--coral);
font-weight: 450;
}
.subtitle {
max-width: 430px;
margin: 13px 0 0;
color: #4f6961;
font-size: 13px;
line-height: 1.5;
}
.phase-card {
position: absolute;
top: 30px;
right: 30px;
width: min(330px, calc(100vw - 60px));
padding: 18px 19px 17px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 16px 45px rgba(28, 59, 52, 0.14);
backdrop-filter: blur(14px);
}
.phase-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 10px;
}
.phase-kicker {
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
color: var(--green);
}
.phase-number {
display: grid;
width: 34px;
height: 34px;
place-items: center;
border-radius: 50%;
background: var(--ink);
color: #fff;
font: 700 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.phase-card h2 {
margin: 0 0 7px;
font-size: 20px;
letter-spacing: -0.035em;
}
.phase-card p {
min-height: 55px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.remaining {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.remaining strong {
color: var(--coral);
font: 800 13px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.map-panel {
position: absolute;
right: 30px;
bottom: 150px;
width: 300px;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 16px 45px rgba(28, 59, 52, 0.13);
backdrop-filter: blur(14px);
}
.map-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin: 1px 3px 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#map {
display: block;
width: 100%;
height: auto;
overflow: hidden;
border-radius: 11px;
background: #e9eadf;
}
.map-caption {
margin: 8px 3px 1px;
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.bottom {
position: absolute;
right: 30px;
bottom: 28px;
left: 30px;
pointer-events: auto;
}
.timeline-panel {
max-width: 1080px;
margin: 0 auto;
padding: 13px 16px 11px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 15px 45px rgba(28, 59, 52, 0.14);
backdrop-filter: blur(14px);
}
.range-row {
display: flex;
align-items: center;
gap: 13px;
}
#scrub {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 10px;
outline: none;
background:
linear-gradient(
to right,
var(--coral) 0 var(--progress, 0%),
rgba(23, 51, 47, 0.15) var(--progress, 0%) 100%
);
cursor: pointer;
}
#scrub::-webkit-slider-thumb {
width: 16px;
height: 16px;
appearance: none;
border: 3px solid var(--paper);
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 0 1px var(--coral), 0 3px 8px rgba(0, 0, 0, 0.18);
}
#scrub::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid var(--paper);
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 0 1px var(--coral);
}
#percent {
flex: 0 0 38px;
color: var(--muted);
font: 700 10px ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
}
.stops {
display: grid;
grid-template-columns: repeat(4, 1fr);
margin-top: 8px;
}
.stop {
position: relative;
padding: 4px 0 0;
border: 0;
background: none;
color: #89968f;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
text-align: left;
cursor: pointer;
}
.stop:nth-child(2),
.stop:nth-child(3) {
text-align: center;
}
.stop:last-child {
text-align: right;
}
.stop::before {
position: absolute;
top: -10px;
left: 0;
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: #b7c0ba;
transform: translateY(-50%);
}
.stop:nth-child(2)::before,
.stop:nth-child(3)::before {
left: 50%;
transform: translate(-50%, -50%);
}
.stop:last-child::before {
left: 100%;
transform: translate(-100%, -50%);
}
.stop.active,
.stop.done {
color: var(--ink);
}
.stop.active::before {
background: var(--coral);
box-shadow: 0 0 0 4px rgba(229, 107, 77, 0.14);
}
.stop.done::before {
background: var(--green);
}
.controls {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
margin-top: 10px;
}
.control {
display: inline-flex;
min-height: 34px;
align-items: center;
justify-content: center;
gap: 7px;
padding: 7px 12px;
border: 1px solid rgba(23, 51, 47, 0.13);
border-radius: 10px;
background: rgba(250, 248, 238, 0.9);
box-shadow: 0 5px 18px rgba(28, 59, 52, 0.09);
font-size: 10px;
font-weight: 750;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
.control:hover {
background: #fffef7;
transform: translateY(-1px);
}
.control.primary {
min-width: 94px;
border-color: var(--ink);
background: var(--ink);
color: #fff;
}
.control svg {
width: 13px;
height: 13px;
fill: currentColor;
}
.hint {
position: absolute;
bottom: 35px;
left: 30px;
padding: 8px 11px;
border-radius: 10px;
background: rgba(250, 248, 238, 0.76);
color: #62756e;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.loader {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #c9e5df;
color: var(--ink);
transition: opacity 450ms ease, visibility 450ms ease;
}
.loader.hidden {
visibility: hidden;
opacity: 0;
}
.loader-box {
text-align: center;
}
.loader-cube {
width: 23px;
height: 23px;
margin: 0 auto 16px;
background: var(--coral);
box-shadow: 9px 9px 0 var(--yellow), -9px 9px 0 var(--green);
animation: hop 900ms ease-in-out infinite alternate;
}
.loader-box strong {
display: block;
font-size: 11px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
@keyframes hop {
to {
transform: translateY(-8px);
}
}
@media (max-width: 900px) {
.brand {
top: 20px;
left: 20px;
}
.phase-card {
top: 20px;
right: 20px;
width: 280px;
}
.map-panel {
display: none;
}
.bottom {
right: 18px;
bottom: 18px;
left: 18px;
}
.hint {
display: none;
}
}
@media (max-width: 650px) {
.brand {
right: 18px;
left: 18px;
}
h1 {
max-width: 340px;
font-size: 34px;
}
.subtitle {
display: none;
}
.phase-card {
top: 142px;
right: 18px;
width: 235px;
padding: 13px;
}
.phase-card p {
display: none;
}
.phase-card h2 {
margin-bottom: 0;
font-size: 16px;
}
.remaining {
margin-top: 9px;
padding-top: 9px;
}
.timeline-panel {
padding: 12px;
}
.stop {
font-size: 0;
}
.stop::before {
width: 8px;
height: 8px;
}
.control {
padding: 7px 10px;
}
.control .optional {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
role="img"
aria-label="Interactive voxel journey from Bellavista in Santiago toward the San Cristóbal hill access."
></canvas>
<div class="hud">
<header class="brand">
<div class="eyebrow">Santiago · Voxel field note 01</div>
<h1>Bellavista <span>→</span> San Cristóbal</h1>
<p class="subtitle">
Follow a small visitor from the Bellavista sidewalk, across the avenue,
and up through the greener parkland toward the hill access.
</p>
</header>
<section class="phase-card" aria-live="polite">
<div class="phase-top">
<div class="phase-kicker">Current chapter</div>
<div class="phase-number" id="phase-number">01</div>
</div>
<h2 id="phase-title">Bellavista sidewalk</h2>
<p id="phase-description">
Painted facades, pocket gardens, and café tables introduce the walk.
</p>
<div class="remaining">
<span>To hill access</span>
<strong id="remaining-distance">61 m</strong>
</div>
</section>
<aside class="map-panel">
<div class="map-heading">
<span>Route study</span>
<span>N ↑</span>
</div>
<canvas id="map" width="600" height="380" aria-label="Route minimap"></canvas>
<div class="map-caption">
Illustrative spatial journey, not a navigation map.
</div>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom · Space to pause</div>
<section class="bottom">
<div class="timeline-panel">
<div class="range-row">
<input
id="scrub"
type="range"
min="0"
max="1000"
value="0"
step="1"
aria-label="Journey progress"
>
<span id="percent">0%</span>
</div>
<div class="stops" aria-label="Journey chapters">
<button class="stop active" data-progress="0">Bellavista</button>
<button class="stop" data-progress="0.25">Crossing</button>
<button class="stop" data-progress="0.48">Park edge</button>
<button class="stop" data-progress="0.74">Hill access</button>
</div>
<div class="controls">
<button class="control primary" id="play" aria-label="Pause journey">
<svg id="play-icon" viewBox="0 0 16 16" aria-hidden="true">
<path d="M3 2h3.5v12H3zm6.5 0H13v12H9.5z"></path>
</svg>
<span id="play-label">Pause</span>
</button>
<button class="control" id="restart" aria-label="Restart journey">
<svg viewBox="0 0 16 16" aria-hidden="true">
<path d="M8 2a6 6 0 1 1-5.65 4H4.1A4.5 4.5 0 1 0 8 3.5V6L4 2.5 8-1z"></path>
</svg>
<span class="optional">Restart</span>
</button>
<button class="control" id="speed" aria-label="Change journey speed">
<svg viewBox="0 0 16 16" aria-hidden="true">
<path d="M8 1a7 7 0 1 0 7 7h-2a5 5 0 1 1-5-5zm0 3L4 8h3v5h2V8h3z"></path>
</svg>
<span id="speed-label">1×</span>
</button>
<button class="control" id="reset-view" aria-label="Reset camera view">
<svg viewBox="0 0 16 16" aria-hidden="true">
<path d="M2 6V2h4v2H4v2zm8-4h4v4h-2V4h-2zM2 10h2v2h2v2H2zm10 0h2v4h-4v-2h2zM7 6h2v4H7zm0 4h2v1H7z"></path>
</svg>
<span class="optional">Reset view</span>
</button>
</div>
</div>
</section>
</div>
<div class="loader" id="loader">
<div class="loader-box">
<div class="loader-cube"></div>
<strong>Building the route</strong>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loader = document.querySelector("#loader");
const scrub = document.querySelector("#scrub");
const percentLabel = document.querySelector("#percent");
const playButton = document.querySelector("#play");
const playLabel = document.querySelector("#play-label");
const playIcon = document.querySelector("#play-icon");
const speedButton = document.querySelector("#speed");
const speedLabel = document.querySelector("#speed-label");
const phaseNumber = document.querySelector("#phase-number");
const phaseTitle = document.querySelector("#phase-title");
const phaseDescription = document.querySelector("#phase-description");
const remainingDistance = document.querySelector("#remaining-distance");
const stopButtons = [...document.querySelectorAll(".stop")];
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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9e5df);
scene.fog = new THREE.Fog(0xc9e5df, 38, 100);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
180
);
const hemisphere = new THREE.HemisphereLight(0xe9fff7, 0x8b9275, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1c9, 3.1);
sun.position.set(-18, 34, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -48;
sun.shadow.camera.right = 48;
sun.shadow.camera.top = 48;
sun.shadow.camera.bottom = -48;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 100;
sun.shadow.bias = -0.0005;
scene.add(sun);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.86,
metalness: options.metalness ?? 0,
flatShading: true,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
const M = {
ground: material(0xb8c7b0),
road: material(0x424d4b),
curb: material(0xd8d4c5),
sidewalk: material(0xc9c6b7),
paving: material(0xe5dfc9),
grass: material(0x76a56d),
grassDark: material(0x568b5c),
hill: material(0x6f9a67),
hillLight: material(0x82aa70),
white: material(0xf6f2df),
yellow: material(0xf2c84b),
dark: material(0x263b38),
black: material(0x202a29),
wood: material(0x8c6046),
leaf: material(0x3d7c58),
leafLight: material(0x5d985f),
trunk: material(0x76503e),
metal: material(0x465450, { metalness: 0.22, roughness: 0.62 }),
window: material(0x3f5c5d, { roughness: 0.45 }),
windowLit: material(0xf4d98b, { emissive: 0xd6aa55, emissiveIntensity: 0.18 }),
route: material(0xf4c945, { emissive: 0xb26b0d, emissiveIntensity: 0.3 }),
coral: material(0xe56b4d),
blue: material(0x356e91),
cream: material(0xeee5cc),
glass: material(0x9cc6c2, { roughness: 0.25 })
};
function box(
width,
height,
depth,
x,
y,
z,
mat,
{
cast = true,
receive = true,
parent = scene
} = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Route geometry
// ---------------------------------------------------------------------
const route = [
new THREE.Vector3(-25, 0.24, -6.2),
new THREE.Vector3(-15, 0.24, -6.2),
new THREE.Vector3(-8, 0.24, -6.2),
new THREE.Vector3(-8, 0.24, 6.2),
new THREE.Vector3(-3, 0.24, 7.8),
new THREE.Vector3(3, 0.30, 9.4),
new THREE.Vector3(7, 0.62, 12.3),
new THREE.Vector3(10, 1.28, 16.3),
new THREE.Vector3(12, 2.22, 20.4),
new THREE.Vector3(13, 3.18, 24.5)
];
const cumulative = [0];
let totalLength = 0;
for (let i = 1; i < route.length; i++) {
totalLength += route[i].distanceTo(route[i - 1]);
cumulative.push(totalLength);
}
function sampleRoute(distance) {
const d = THREE.MathUtils.clamp(distance, 0, totalLength);
for (let i = 0; i < route.length - 1; i++) {
if (d <= cumulative[i + 1] || i === route.length - 2) {
const a = route[i];
const b = route[i + 1];
const segmentLength = cumulative[i + 1] - cumulative[i];
const t = segmentLength === 0
? 0
: (d - cumulative[i]) / segmentLength;
return {
position: a.clone().lerp(b, t),
tangent: b.clone().sub(a).normalize(),
segment: i
};
}
}
}
// ---------------------------------------------------------------------
// Terrain, street, and sidewalks
// ---------------------------------------------------------------------
box(82, 0.9, 76, 0, -0.72, 0, M.ground);
box(72, 0.2, 10, 0, -0.1, 0, M.road);
box(72, 0.3, 3.1, 0, 0.05, -6.5, M.sidewalk);
box(72, 0.3, 3.1, 0, 0.05, 6.5, M.sidewalk);
box(74, 0.18, 24, 0, -0.08, 18.8, M.grass);
// Road center dashes.
for (let x = -32; x <= 32; x += 5.5) {
box(2.7, 0.025, 0.16, x, 0.015, 0, M.white, {
cast: false
});
}
// Zebra crossing at x = -8.
for (let z = -4.35; z <= 4.5; z += 1.15) {
box(4.5, 0.028, 0.58, -8, 0.018, z, M.white, {
cast: false
});
}
// Small curb blocks along the park side.
for (let x = -30; x < 32; x += 2.1) {
if (Math.abs(x + 8) < 3) continue;
box(1.9, 0.24, 0.18, x, 0.1, 5.03, M.curb);
}
// ---------------------------------------------------------------------
// Bellavista buildings
// ---------------------------------------------------------------------
function makeBuilding(x, z, width, depth, height, color, style = 0) {
const facade = material(color);
const body = box(
width,
height,
depth,
x,
0.2 + height / 2,
z,
facade
);
box(
width + 0.35,
0.35,
depth + 0.35,
x,
0.2 + height + 0.15,
z,
style % 2 ? M.cream : M.curb
);
const front = z + depth / 2 + 0.025;
const columns = Math.max(2, Math.floor(width / 2.4));
const rows = Math.max(2, Math.floor((height - 1.2) / 2.25));
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const wx = x - width / 2 + 1.25 + column * ((width - 2.5) / Math.max(1, columns - 1));
const wy = 1.45 + row * 2.2;
if (wy + 0.55 > 0.2 + height) continue;
const windowMaterial = ((row + column + style) % 5 === 0)
? M.windowLit
: M.window;
box(0.74, 0.9, 0.055, wx, wy, front, windowMaterial, {
cast: false
});
box(0.93, 0.09, 0.12, wx, wy - 0.5, front + 0.03, M.cream, {
cast: false
});
if ((row + column + style) % 3 === 0) {
box(1.04, 0.12, 0.42, wx, wy - 0.57, front + 0.19, M.curb);
}
}
}
// Rooftop details.
box(
width * 0.22,
0.9,
depth * 0.25,
x + width * 0.18,
height + 0.78,
z - 0.6,
M.metal
);
return body;
}
makeBuilding(-25, -18, 8, 10, 10.5, 0xd78b6d, 0);
makeBuilding(-15, -18.5, 9, 10, 14.5, 0xe0bd75, 1);
makeBuilding(-4.5, -19, 10, 12, 9.5, 0xb87d69, 2);
makeBuilding(9, -18.5, 10, 10, 13.5, 0xd9d1b5, 0);
makeBuilding(22, -18, 8, 10, 18, 0x9eb3a1, 1);
// More distant urban blocks.
makeBuilding(-27, -32, 10, 10, 16, 0xa7b7b0, 2);
makeBuilding(-12, -33, 13, 11, 20, 0xc58d78, 0);
makeBuilding(5, -33, 14, 11, 15, 0xdecb9d, 1);
makeBuilding(23, -32, 12, 11, 22, 0x91aaa1, 2);
// A low wall creates the Bellavista neighborhood edge.
box(10, 1.35, 0.42, -19.5, 0.82, -11.1, M.cream);
for (let x = -24; x <= -15; x += 1.8) {
box(
1.05,
0.82,
0.06,
x,
0.95,
-10.87,
[M.coral, M.blue, M.yellow][Math.floor((x + 24) / 1.8) % 3],
{ cast: false }
);
}
// ---------------------------------------------------------------------
// Hill terraces and stair path
// ---------------------------------------------------------------------
box(22, 0.8, 10, 12, 0.5, 19, M.hill);
box(18, 1.5, 10, 13, 1.15, 24, M.hillLight);
box(14, 2.2, 10, 14, 2.0, 29, M.hill);
// Flat park path leaving the crossing.
for (let i = 3; i <= 4; i++) {
const a = route[i];
const b = route[i + 1];
const mid = a.clone().lerp(b, 0.5);
const length = a.distanceTo(b);
const path = box(
length + 0.3,
0.16,
2.45,
mid.x,
0.22,
mid.z,
M.paving
);
path.rotation.y = -Math.atan2(b.z - a.z, b.x - a.x);
}
// Voxel stair treads along the rising route.
for (let i = 5; i < route.length - 1; i++) {
const a = route[i];
const b = route[i + 1];
const length = a.distanceTo(b);
const count = Math.ceil(length / 0.72);
for (let j = 0; j < count; j++) {
const t = (j + 0.5) / count;
const point = a.clone().lerp(b, t);
const top = point.y - 0.03;
const base = 0.08;
const tread = box(
length / count + 0.12,
Math.max(0.16, top - base),
2.45,
point.x,
base + (top - base) / 2,
point.z,
j % 3 === 0 ? M.paving : M.curb
);
tread.rotation.y = -Math.atan2(b.z - a.z, b.x - a.x);
}
}
// Golden dotted wayfinding line.
for (let distance = 0; distance <= totalLength; distance += 1.12) {
const sample = sampleRoute(distance);
const dot = box(
0.48,
0.055,
0.16,
sample.position.x,
sample.position.y + 0.045,
sample.position.z,
M.route,
{ cast: false }
);
dot.rotation.y = -Math.atan2(
sample.tangent.z,
sample.tangent.x
);
}
// ---------------------------------------------------------------------
// Trees, shrubs, lamps, benches
// ---------------------------------------------------------------------
function tree(x, z, scale = 1, baseY = 0.12) {
const group = new THREE.Group();
group.position.set(x, baseY, z);
group.scale.setScalar(scale);
scene.add(group);
box(0.34, 1.4, 0.34, 0, 0.7, 0, M.trunk, { parent: group });
box(1.85, 1.25, 1.65, 0, 1.75, 0, M.leaf, { parent: group });
box(1.2, 1.15, 1.35, -0.35, 2.55, 0.1, M.leafLight, {
parent: group
});
box(1.05, 0.85, 1.1, 0.65, 2.45, -0.35, M.leaf, {
parent: group
});
}
function shrub(x, z, scale = 1, baseY = 0.12) {
box(
0.8 * scale,
0.65 * scale,
0.8 * scale,
x,
baseY + 0.325 * scale,
z,
M.leafLight
);
}
function streetLamp(x, z) {
box(0.12, 3.5, 0.12, x, 1.75, z, M.metal);
box(0.7, 0.12, 0.12, x + 0.28, 3.45, z, M.metal);
box(0.36, 0.24, 0.36, x + 0.55, 3.3, z, M.windowLit);
}
function bench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.2, z);
group.rotation.y = rotation;
scene.add(group);
box(2, 0.13, 0.52, 0, 0.5, 0, M.wood, { parent: group });
box(2, 0.65, 0.12, 0, 0.82, -0.25, M.wood, { parent: group });
box(0.12, 0.5, 0.45, -0.75, 0.25, 0, M.metal, {
parent: group
});
box(0.12, 0.5, 0.45, 0.75, 0.25, 0, M.metal, {
parent: group
});
}
[
[-30, -8.5, 0.9], [-21, -8.6, 0.75], [-12.7, -8.5, 0.8],
[-1.5, -8.7, 1], [5, -8.8, 0.8], [15, -8.5, 1.05],
[26, -8.4, 0.95]
].forEach(([x, z, s]) => tree(x, z, s));
[
[-29, 9.2, 0.8], [-22, 10.5, 1], [-16, 13, 0.9],
[-8, 11.5, 0.85], [-1, 13.5, 0.95], [4.7, 13.4, 0.75],
[17.6, 14.8, 1.05], [19.4, 20.7, 1.05], [5.1, 20.2, 1.15],
[7.2, 26.8, 1.15], [19.2, 27.3, 1.1], [4.5, 31.5, 1.2]
].forEach(([x, z, s]) => tree(x, z, s));
[
[-28, 11.2, 1], [-24.5, 12.8, 0.8], [-18, 11.7, 1.1],
[-12, 14.8, 0.9], [-4, 11.8, 0.85], [0.4, 15.2, 1],
[16.4, 17, 0.85], [20.5, 25, 0.95], [3, 24.3, 0.9]
].forEach(([x, z, s]) => shrub(x, z, s));
streetLamp(-20, -8.1);
streetLamp(-10.6, -8.1);
streetLamp(1.5, -8.1);
streetLamp(19.5, -8.1);
streetLamp(-11.1, 7.7);
streetLamp(2.2, 7.7);
bench(-17.2, -7.65, Math.PI);
bench(-12.1, -7.65, Math.PI);
bench(-1.5, 7.45, 0);
bench(5.2, 8.2, 0.3);
// Pedestrian signal.
box(0.14, 3.2, 0.14, -10.65, 1.6, 6.7, M.metal);
box(0.48, 0.72, 0.38, -10.65, 2.95, 6.7, M.dark);
box(0.22, 0.22, 0.06, -10.65, 2.73, 6.89, M.coral);
// ---------------------------------------------------------------------
// Cars, signs, flag, lookout
// ---------------------------------------------------------------------
function car(x, z, color, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
const paint = material(color);
box(2.8, 0.65, 1.25, 0, 0.54, 0, paint, { parent: group });
box(1.45, 0.62, 1.05, -0.1, 1.08, 0, M.glass, {
parent: group
});
box(0.55, 0.14, 0.08, 0.88, 0.53, 0.36, M.windowLit, {
parent: group
});
box(0.55, 0.14, 0.08, 0.88, 0.53, -0.36, M.windowLit, {
parent: group
});
for (const wx of [-0.85, 0.85]) {
for (const wz of [-0.65, 0.65]) {
box(0.5, 0.42, 0.2, wx, 0.24, wz, M.black, {
parent: group
});
}
}
}
car(13, -2.05, 0xd7d2bd);
car(-22, 2.0, 0x527a88);
car(4, 2.05, 0xb85843);
function makePanel(text, subtitle, width, height, bg, fg) {
const panelCanvas = document.createElement("canvas");
panelCanvas.width = 1024;
panelCanvas.height = 256;
const context = panelCanvas.getContext("2d");
context.fillStyle = bg;
context.fillRect(0, 0, 1024, 256);
context.fillStyle = fg;
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "800 72px Arial, sans-serif";
context.fillText(text, 512, subtitle ? 96 : 128);
if (subtitle) {
context.font = "700 34px Arial, sans-serif";
context.fillText(subtitle, 512, 184);
}
const texture = new THREE.CanvasTexture(panelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
return new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({ map: texture })
);
}
const bellavistaSign = makePanel(
"BELLAVISTA",
"PIO NONO · SANTIAGO",
6.2,
1.55,
"#17332f",
"#f5df88"
);
bellavistaSign.position.set(-19.4, 2.05, -10.86);
scene.add(bellavistaSign);
const accessSign = makePanel(
"SAN CRISTÓBAL",
"ACCESO ↑",
4.7,
1.18,
"#2c6e50",
"#fff8de"
);
accessSign.position.set(4.2, 2.35, 10.65);
accessSign.rotation.y = -0.18;
scene.add(accessSign);
box(0.13, 2.4, 0.13, 2.45, 1.2, 10.55, M.wood);
box(0.13, 2.4, 0.13, 5.95, 1.2, 10.75, M.wood);
// Small Chile flag beside the access sign.
box(0.08, 2.3, 0.08, 6.55, 1.15, 11.15, M.metal);
box(0.88, 0.55, 0.05, 6.99, 2.05, 11.15, M.white);
box(0.38, 0.3, 0.06, 6.71, 2.12, 11.18, M.blue);
box(0.16, 0.16, 0.06, 6.72, 1.94, 11.19, M.coral);
// Small lookout platform at the end of the route.
box(5.8, 0.35, 4.6, 13, 3.02, 26, M.paving);
box(0.16, 0.9, 4.6, 10.15, 3.55, 26, M.wood);
box(0.16, 0.9, 4.6, 15.85, 3.55, 26, M.wood);
box(5.8, 0.16, 0.16, 13, 3.9, 23.75, M.wood);
// ---------------------------------------------------------------------
// Blocky clouds
// ---------------------------------------------------------------------
function cloud(x, y, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
box(3.6, 1.2, 1.7, 0, 0, 0, M.white, {
cast: false,
parent: group
});
box(2.1, 1.8, 1.8, -1.25, 0.45, 0, M.white, {
cast: false,
parent: group
});
box(2.4, 2.2, 1.9, 0.8, 0.55, 0, M.white, {
cast: false,
parent: group
});
box(2.1, 1.2, 1.8, 2.25, -0.1, 0, M.white, {
cast: false,
parent: group
});
}
cloud(-28, 22, -35, 1.5);
cloud(3, 25, -42, 1.9);
cloud(29, 20, -26, 1.25);
cloud(-13, 29, 22, 1.35);
// ---------------------------------------------------------------------
// Voxel visitor
// ---------------------------------------------------------------------
const visitor = new THREE.Group();
scene.add(visitor);
const skin = material(0xc9825f);
const jacket = material(0x316f91);
const trousers = material(0x273b48);
const shoes = material(0x1d2729);
const hair = material(0x342925);
const backpack = material(0xe4a944);
// Torso and neck.
box(0.7, 0.72, 0.42, 0, 1.03, 0, jacket, { parent: visitor });
box(0.25, 0.16, 0.25, 0, 1.47, 0, skin, { parent: visitor });
box(0.58, 0.16, 0.43, 0, 0.72, 0, trousers, {
parent: visitor
});
// Head, hair, and face.
box(0.48, 0.46, 0.44, 0, 1.72, 0, skin, { parent: visitor });
box(0.5, 0.17, 0.46, 0, 1.98, -0.01, hair, {
parent: visitor
});
box(0.09, 0.09, 0.035, -0.11, 1.76, 0.235, M.black, {
cast: false,
parent: visitor
});
box(0.09, 0.09, 0.035, 0.11, 1.76, 0.235, M.black, {
cast: false,
parent: visitor
});
// Backpack.
box(0.52, 0.62, 0.28, 0, 1.13, -0.34, backpack, {
parent: visitor
});
box(0.36, 0.18, 0.08, 0, 1.22, -0.51, M.cream, {
parent: visitor
});
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.19, 0.69, 0);
rightLeg.position.set(0.19, 0.69, 0);
visitor.add(leftLeg, rightLeg);
box(0.23, 0.56, 0.25, 0, -0.25, 0, trousers, {
parent: leftLeg
});
box(0.23, 0.56, 0.25, 0, -0.25, 0, trousers, {
parent: rightLeg
});
box(0.26, 0.16, 0.38, 0, -0.56, 0.07, shoes, {
parent: leftLeg
});
box(0.26, 0.16, 0.38, 0, -0.56, 0.07, shoes, {
parent: rightLeg
});
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.44, 1.32, 0);
rightArm.position.set(0.44, 1.32, 0);
visitor.add(leftArm, rightArm);
box(0.18, 0.58, 0.2, 0, -0.25, 0, jacket, {
parent: leftArm
});
box(0.18, 0.58, 0.2, 0, -0.25, 0, jacket, {
parent: rightArm
});
box(0.18, 0.16, 0.2, 0, -0.57, 0, skin, {
parent: leftArm
});
box(0.18, 0.16, 0.2, 0, -0.57, 0, skin, {
parent: rightArm
});
// ---------------------------------------------------------------------
// Camera controls implemented directly, without addons
// ---------------------------------------------------------------------
const orbit = {
yaw: -0.82,
pitch: 0.57,
distance: 19
};
const cameraTarget = route[0].clone().add(new THREE.Vector3(0, 1.1, 0));
const desiredTarget = cameraTarget.clone();
function cameraOffset() {
const horizontal = Math.cos(orbit.pitch) * orbit.distance;
return new THREE.Vector3(
Math.sin(orbit.yaw) * horizontal,
Math.sin(orbit.pitch) * orbit.distance,
Math.cos(orbit.yaw) * horizontal
);
}
camera.position.copy(cameraTarget).add(cameraOffset());
camera.lookAt(cameraTarget);
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.004,
0.24,
1.12
);
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.distance = THREE.MathUtils.clamp(
orbit.distance * Math.exp(event.deltaY * 0.001),
9,
32
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
orbit.yaw = -0.82;
orbit.pitch = 0.57;
orbit.distance = 19;
});
// ---------------------------------------------------------------------
// Journey state and UI
// ---------------------------------------------------------------------
const phases = [
{
title: "Bellavista sidewalk",
description:
"Painted facades, pocket gardens, and café tables introduce the walk.",
start: 0
},
{
title: "The avenue crossing",
description:
"The visitor follows the white stripes across the road toward the greener south side.",
start: cumulative[2]
},
{
title: "Park edge",
description:
"A low wall, mature trees, and a shaded path mark the transition from city to parkland.",
start: cumulative[3]
},
{
title: "San Cristóbal access",
description:
"A stepped green promenade rises through the trees toward the San Cristóbal access.",
start: cumulative[6]
}
];
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
let playing = !reducedMotion;
let progress = 0;
let speed = 1;
const duration = 48;
function phaseAt(distance) {
let index = 0;
for (let i = 0; i < phases.length; i++) {
if (distance >= phases[i].start) index = i;
}
return index;
}
function updatePlayButton() {
playLabel.textContent = playing ? "Pause" : "Play";
playButton.setAttribute(
"aria-label",
playing ? "Pause journey" : "Play journey"
);
playIcon.innerHTML = playing
? '<path d="M3 2h3.5v12H3zm6.5 0H13v12H9.5z"></path>'
: '<path d="M4 2.2 13 8l-9 5.8z"></path>';
}
function setProgress(value, pause = false) {
progress = THREE.MathUtils.clamp(value, 0, 1);
if (pause) playing = false;
updatePlayButton();
}
playButton.addEventListener("click", () => {
if (progress >= 1) progress = 0;
playing = !playing;
updatePlayButton();
});
document.querySelector("#restart").addEventListener("click", () => {
progress = 0;
playing = true;
updatePlayButton();
});
speedButton.addEventListener("click", () => {
speed = speed === 1 ? 1.5 : speed === 1.5 ? 2 : 1;
speedLabel.textContent = `${speed}×`;
});
document.querySelector("#reset-view").addEventListener("click", () => {
orbit.yaw = -0.82;
orbit.pitch = 0.57;
orbit.distance = 19;
});
scrub.addEventListener("input", () => {
setProgress(Number(scrub.value) / 1000, true);
});
stopButtons.forEach((button) => {
button.addEventListener("click", () => {
setProgress(Number(button.dataset.progress), false);
playing = true;
updatePlayButton();
});
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.code === "Space") {
event.preventDefault();
if (progress >= 1) progress = 0;
playing = !playing;
updatePlayButton();
}
if (event.key.toLowerCase() === "r") {
progress = 0;
playing = true;
updatePlayButton();
}
if (event.key === "ArrowRight") {
setProgress(progress + 0.05, true);
}
if (event.key === "ArrowLeft") {
setProgress(progress - 0.05, true);
}
});
updatePlayButton();
remainingDistance.textContent = `${Math.round(totalLength)} m`;
// ---------------------------------------------------------------------
// Minimap
// ---------------------------------------------------------------------
const mapCanvas = document.querySelector("#map");
const mapContext = mapCanvas.getContext("2d");
const MAP_W = 300;
const MAP_H = 190;
function mapPoint(point) {
return {
x: 13 + ((point.x + 34) / 68) * 274,
y: 10 + ((point.z + 34) / 70) * 170
};
}
function drawMap(visitorPosition, phaseIndex) {
const context = mapContext;
context.setTransform(2, 0, 0, 2, 0, 0);
context.clearRect(0, 0, MAP_W, MAP_H);
context.fillStyle = "#e9eadf";
context.fillRect(0, 0, MAP_W, MAP_H);
// Building blocks.
context.fillStyle = "#c8c8bb";
const buildingRects = [
[-29, -24, 12, 15], [-19, -25, 12, 14], [-8, -27, 14, 16],
[4, -25, 12, 14], [18, -25, 12, 14], [-28, -37, 15, 15],
[-12, -39, 18, 16], [7, -39, 18, 16]
];
buildingRects.forEach(([x, z, w, h]) => {
const a = mapPoint(new THREE.Vector3(x, 0, z));
const b = mapPoint(new THREE.Vector3(x + w, 0, z + h));
context.fillRect(a.x, a.y, b.x - a.x, b.y - a.y);
});
// Road.
const roadTop = mapPoint(new THREE.Vector3(0, 0, -5));
const roadBottom = mapPoint(new THREE.Vector3(0, 0, 5));
context.fillStyle = "#727d78";
context.fillRect(0, roadTop.y, MAP_W, roadBottom.y - roadTop.y);
// Park.
const park = mapPoint(new THREE.Vector3(-34, 0, 5));
context.fillStyle = "#b7cbaa";
context.fillRect(
park.x,
roadBottom.y,
MAP_W - park.x,
MAP_H - roadBottom.y
);
// Crossing.
const crossing = mapPoint(new THREE.Vector3(-8, 0, 0));
context.fillStyle = "#e8e5d7";
context.fillRect(
crossing.x - 5,
roadTop.y,
10,
roadBottom.y - roadTop.y
);
// Route.
context.beginPath();
route.forEach((point, index) => {
const mapped = mapPoint(point);
if (index === 0) context.moveTo(mapped.x, mapped.y);
else context.lineTo(mapped.x, mapped.y);
});
context.lineWidth = 4;
context.lineJoin = "round";
context.lineCap = "round";
context.strokeStyle = "#fffdf4";
context.stroke();
context.lineWidth = 2;
context.strokeStyle = "#e5a82e";
context.stroke();
// Chapter points.
phases.slice(1).forEach((phase) => {
const sample = sampleRoute(phase.start);
const mapped = mapPoint(sample.position);
context.beginPath();
context.arc(mapped.x, mapped.y, 3.2, 0, Math.PI * 2);
context.fillStyle = phaseIndex >=
phases.indexOf(phase) ? "#2c7a5b" : "#fffdf4";
context.fill();
context.strokeStyle = "#2c7a5b";
context.lineWidth = 1.3;
context.stroke();
});
// Visitor marker.
const mapped = mapPoint(visitorPosition);
context.beginPath();
context.arc(mapped.x, mapped.y, 8, 0, Math.PI * 2);
context.fillStyle = "rgba(229,107,77,0.18)";
context.fill();
context.beginPath();
context.arc(mapped.x, mapped.y, 4.5, 0, Math.PI * 2);
context.fillStyle = "#e56b4d";
context.fill();
context.strokeStyle = "#fffaf0";
context.lineWidth = 2;
context.stroke();
// Labels.
context.font = "700 8px Arial";
context.fillStyle = "#536960";
context.textAlign = "left";
context.fillText("BELLAVISTA", 16, 24);
context.fillText("AV.", 14, 90);
context.fillText("SAN CRISTÓBAL", 188, 173);
}
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
let previousPhase = -1;
function dampAngle(current, target, lambda, dt) {
const difference = Math.atan2(
Math.sin(target - current),
Math.cos(target - current)
);
return current + difference * (1 - Math.exp(-lambda * dt));
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (playing) {
progress = Math.min(1, progress + (dt * speed) / duration);
if (progress >= 1) {
playing = false;
updatePlayButton();
}
}
const distance = progress * totalLength;
const sample = sampleRoute(distance);
const currentPhase = phaseAt(distance);
// Place and smoothly turn the visitor.
visitor.position.copy(sample.position);
const targetYaw = Math.atan2(
sample.tangent.x,
sample.tangent.z
);
visitor.rotation.y = dampAngle(
visitor.rotation.y,
targetYaw,
9,
dt
);
const walking = playing && progress < 1;
const swing = walking
? Math.sin(distance * 7.4) * 0.62
: 0;
leftLeg.rotation.x = swing;
rightLeg.rotation.x = -swing;
leftArm.rotation.x = -swing * 0.75;
rightArm.rotation.x = swing * 0.75;
visitor.position.y += walking
? Math.abs(Math.sin(distance * 7.4)) * 0.045
: 0;
// Follow the visitor while retaining an orbitable camera.
desiredTarget.copy(sample.position);
desiredTarget.y += 1.05;
cameraTarget.lerp(
desiredTarget,
1 - Math.exp(-dt * 4.8)
);
const desiredCameraPosition = cameraTarget.clone().add(
cameraOffset()
);
camera.position.lerp(
desiredCameraPosition,
1 - Math.exp(-dt * 5.5)
);
camera.lookAt(cameraTarget);
// HUD.
const percentage = Math.round(progress * 100);
scrub.value = Math.round(progress * 1000);
scrub.style.setProperty("--progress", `${percentage}%`);
percentLabel.textContent = `${percentage}%`;
remainingDistance.textContent =
`${Math.max(0, Math.ceil((1 - progress) * totalLength))} m`;
if (currentPhase !== previousPhase) {
phaseNumber.textContent = String(currentPhase + 1).padStart(2, "0");
phaseTitle.textContent = phases[currentPhase].title;
phaseDescription.textContent = phases[currentPhase].description;
stopButtons.forEach((button, index) => {
button.classList.toggle("active", index === currentPhase);
button.classList.toggle("done", index < currentPhase);
});
previousPhase = currentPhase;
}
drawMap(sample.position, currentPhase);
renderer.render(scene, camera);
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", onResize);
// Render one frame before removing the loading screen.
renderer.render(scene, camera);
loader.classList.add("hidden");
animate();
</script>
</body>
</html>
```