Prompt specification
Build or customize the Three.js 3D scene "Craft worker opening a San Blas shop" 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: Craft worker opening a San Blas shop
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/craft-worker-opening-a-san-blas-shop-x2734
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts San Blas in Cusco. Create a compact referenced lane vignette with an original craft shop, work display, and descending stairs. Keep the entrance and pedestrian passage accessible beside the display. Voxel style.
Working Three.js Starter (craft-worker-opening-a-san-blas-shop-x2734):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#cbbda3">
<title>San Blas, Cusco — Voxel Lane Study</title>
<style>
:root {
--ink: #352c26;
--paper: #efe5d0;
--accent: #9b3f32;
--line: rgba(53, 44, 38, 0.22);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbbda3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button { font: inherit; }
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 48% 45%, transparent 46%, rgba(48, 35, 27, 0.13) 115%),
linear-gradient(180deg, rgba(255,255,255,0.08), transparent 28%);
}
.brand {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
width: min(390px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 29px;
height: 2px;
background: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4.2vw, 60px);
font-weight: 500;
line-height: 0.92;
letter-spacing: -0.045em;
text-wrap: balance;
}
.subtitle {
max-width: 340px;
margin: 13px 0 0;
font-size: 12px;
line-height: 1.55;
color: rgba(53, 44, 38, 0.72);
}
.views {
position: fixed;
top: 28px;
right: 28px;
z-index: 6;
display: flex;
gap: 6px;
padding: 5px;
border: 1px solid rgba(255,255,255,0.42);
border-radius: 999px;
background: rgba(239, 229, 208, 0.73);
box-shadow: 0 12px 30px rgba(48, 35, 27, 0.1);
backdrop-filter: blur(14px);
}
.views button {
border: 0;
border-radius: 999px;
padding: 9px 13px;
color: rgba(53, 44, 38, 0.7);
background: transparent;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}
.views button:hover {
color: var(--ink);
transform: translateY(-1px);
}
.views button.active {
color: var(--paper);
background: var(--ink);
}
.pin {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px 8px 8px;
border: 1px solid rgba(255,255,255,0.46);
border-radius: 999px;
background: rgba(239, 229, 208, 0.88);
box-shadow: 0 10px 24px rgba(48, 35, 27, 0.12);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.025em;
pointer-events: none;
transform: translate(-50%, -125%);
transition: opacity 160ms ease;
white-space: nowrap;
}
.pin span {
display: grid;
width: 23px;
height: 23px;
place-items: center;
border-radius: 50%;
color: var(--paper);
background: var(--accent);
font-size: 9px;
}
.footer {
position: fixed;
right: 28px;
bottom: 24px;
z-index: 5;
display: flex;
align-items: center;
gap: 14px;
color: rgba(53, 44, 38, 0.68);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.footer .dot {
width: 3px;
height: 3px;
border-radius: 50%;
background: var(--accent);
}
.note {
position: fixed;
left: 30px;
bottom: 24px;
z-index: 5;
max-width: 310px;
color: rgba(53, 44, 38, 0.62);
font-family: Georgia, "Times New Roman", serif;
font-size: 12px;
font-style: italic;
line-height: 1.4;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: var(--ink);
background: #cbbda3;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.done {
opacity: 0;
visibility: hidden;
}
@media (max-width: 700px) {
.brand {
top: 18px;
left: 18px;
}
.subtitle {
max-width: 250px;
font-size: 11px;
}
.views {
top: auto;
right: 14px;
bottom: 16px;
left: 14px;
justify-content: center;
}
.views button {
flex: 1;
padding: 10px 7px;
}
.footer, .note, .pin {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
* { transition-duration: 0.01ms !important; }
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel scene of a craft lane in San Blas, Cusco"></main>
<div class="vignette" aria-hidden="true"></div>
<header class="brand">
<div class="eyebrow">Cusco, Peru · 13°31′S</div>
<h1>San Blas,<br>in blocks</h1>
<p class="subtitle">
A compact voxel study of the steep artisan lanes, ochre masonry,
colonial stonework, and descending stairways of San Blas.
</p>
</header>
<nav class="views" aria-label="Camera views">
<button type="button" class="active" data-view="lane">Lane</button>
<button type="button" data-view="shop">Workshop</button>
<button type="button" data-view="stairs">Stairs</button>
</nav>
<div class="pin" id="shopPin" aria-hidden="true">
<span>01</span> Ñawi · fictional craft atelier
</div>
<div class="note">The display stays to the lane edge; the entrance and descent remain open.</div>
<div class="footer" aria-hidden="true">
<span>Drag to orbit</span>
<span class="dot"></span>
<span>Scroll to zoom</span>
<span class="dot"></span>
<span>Arrow keys also work</span>
</div>
<div id="loading">Building the lane…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const mount = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const shopPin = document.querySelector("#shopPin");
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
mount.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Drag to orbit the San Blas voxel diorama. Use the mouse wheel to zoom."
);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbbda3);
scene.fog = new THREE.Fog(0xcbbda3, 21, 46);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xf8edd4, 0x6e6257, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2aa, 3.25);
sun.position.set(-9, 16, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9bb8c0, 0.7);
fill.position.set(9, 7, -8);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
function makeMaterial(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...extra
});
}
const M = {
stone: makeMaterial(0x817c70),
stoneDark: makeMaterial(0x605d56),
stoneLight: makeMaterial(0xaaa18d),
stoneWarm: makeMaterial(0x938976),
plaster: makeMaterial(0xc88251),
plasterLight: makeMaterial(0xd9aa68),
plasterRose: makeMaterial(0xb96f59),
plasterBlue: makeMaterial(0x537b78),
roof: makeMaterial(0xa74632),
roofDark: makeMaterial(0x78352b),
wood: makeMaterial(0x70432d),
woodDark: makeMaterial(0x3f2a23),
woodLight: makeMaterial(0xa7754d),
shadow: makeMaterial(0x292522),
cream: makeMaterial(0xe8d6ae),
red: makeMaterial(0xa93f35),
mustard: makeMaterial(0xd49a35),
teal: makeMaterial(0x2f7771),
indigo: makeMaterial(0x334e68),
green: makeMaterial(0x64744a),
terracotta: makeMaterial(0xbd6845),
clay: makeMaterial(0xd28a60),
leaf: makeMaterial(0x526849),
bg: makeMaterial(0xa89b84),
bgRoof: makeMaterial(0x9a5d48)
};
function box(parent, size, position, material, options = {}) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(...size);
mesh.position.set(...position);
mesh.castShadow = options.cast ?? true;
mesh.receiveShadow = options.receive ?? true;
parent.add(mesh);
return mesh;
}
function signMesh({
title,
subtitle = "",
width,
height,
background = "#71352e",
foreground = "#f0dfbd",
position,
rotationY = 0
}) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = Math.max(160, Math.round(1024 * height / width));
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = foreground;
ctx.globalAlpha = 0.6;
ctx.lineWidth = 8;
ctx.strokeRect(14, 14, canvas.width - 28, canvas.height - 28);
ctx.globalAlpha = 1;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.font = `700 ${Math.round(canvas.height * 0.38)}px Georgia`;
ctx.fillText(title, canvas.width / 2, canvas.height * 0.42);
if (subtitle) {
ctx.globalAlpha = 0.84;
ctx.font = `700 ${Math.round(canvas.height * 0.105)}px sans-serif`;
ctx.fillText(subtitle, canvas.width / 2, canvas.height * 0.73);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
side: THREE.DoubleSide,
toneMapped: false
})
);
mesh.position.set(...position);
mesh.rotation.y = rotationY;
return mesh;
}
let seed = 72419;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
// ── Ground planes and the stepped terrain ───────────────────────────────
const ground = box(
scene,
[90, 0.2, 90],
[0, -2.72, -3],
makeMaterial(0xb4a68e),
{ cast: false }
);
box(scene, [13.6, 1.0, 9.7], [0.4, -0.5, 1.25], M.stone);
box(scene, [13.6, 0.72, 5.9], [0.4, -2.56, -9.15], M.stoneDark);
// Retaining courses give the diorama a cutaway, terraced profile.
for (let i = 0; i < 5; i++) {
box(
scene,
[13.65, 0.10, 0.18],
[0.4, -0.86 + i * 0.17, 6.15],
i % 2 ? M.stoneLight : M.stoneWarm
);
}
// ── Cobbled pedestrian passage ─────────────────────────────────────────
const cobbleColors = [
0xaaa18d,
0x958d7c,
0xb8ad94,
0x8d877b,
0xc1b59a,
0x9e9582
];
const cobbleMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const cobbles = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.58, 0.10, 0.54),
cobbleMaterial,
9 * 14
);
cobbles.receiveShadow = true;
scene.add(cobbles);
let cobbleIndex = 0;
for (let row = 0; row < 14; row++) {
for (let col = 0; col < 9; col++) {
const x = -0.77 + col * 0.66 + (row % 2) * 0.08;
const z = 5.45 - row * 0.68;
dummy.position.set(x, 0.045, z);
dummy.rotation.set(0, (random() - 0.5) * 0.07, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
cobbles.setMatrixAt(cobbleIndex, dummy.matrix);
cobbles.setColorAt(
cobbleIndex,
new THREE.Color(cobbleColors[Math.floor(random() * cobbleColors.length)])
);
cobbleIndex++;
}
}
cobbles.instanceMatrix.needsUpdate = true;
if (cobbles.instanceColor) cobbles.instanceColor.needsUpdate = true;
// Low lane edges preserve a broad, unobstructed walking route.
box(scene, [0.18, 0.18, 9.1], [-1.03, 0.08, 0.95], M.stoneLight);
box(scene, [0.18, 0.18, 9.1], [5.02, 0.08, 0.95], M.stoneLight);
// ── Fictional craft shop: Ñawi ─────────────────────────────────────────
const shop = new THREE.Group();
shop.name = "Ñawi craft atelier";
scene.add(shop);
// Main masonry shell.
box(shop, [0.35, 5.1, 9.0], [-6.55, 2.55, 0.2], M.plaster);
box(shop, [3.8, 5.1, 0.35], [-4.70, 2.55, -4.3], M.plaster);
box(shop, [3.8, 5.1, 0.35], [-4.70, 2.55, 4.7], M.plaster);
// Facade with a genuine open doorway gap.
box(shop, [0.35, 5.1, 3.0], [-2.75, 2.55, -2.8], M.plaster);
box(shop, [0.35, 5.1, 4.6], [-2.75, 2.55, 2.4], M.plaster);
box(shop, [0.35, 2.35, 1.4], [-2.75, 3.93, -0.6], M.plasterLight);
// Rough stone base courses.
for (let i = 0; i < 3; i++) {
box(shop, [0.42, 0.18, 3.0], [-2.71, 0.18 + i * 0.28, -2.8], M.stoneWarm);
box(shop, [0.42, 0.18, 4.6], [-2.71, 0.18 + i * 0.28, 2.4], M.stoneWarm);
}
// Masonry accent bands.
box(shop, [0.08, 0.11, 3.0], [-2.53, 2.72, -2.8], M.cream);
box(shop, [0.08, 0.11, 4.6], [-2.53, 2.72, 2.4], M.cream);
box(shop, [0.08, 0.11, 3.0], [-2.53, 4.74, -2.8], M.cream);
box(shop, [0.08, 0.11, 4.6], [-2.53, 4.74, 2.4], M.cream);
// Recessed entrance and timber surround.
box(shop, [0.08, 2.65, 1.25], [-2.54, 1.32, -0.6], M.shadow, { cast: false });
box(shop, [0.20, 2.80, 0.15], [-2.44, 1.4, -1.31], M.woodDark);
box(shop, [0.20, 2.80, 0.15], [-2.44, 1.4, 0.11], M.woodDark);
box(shop, [0.20, 0.16, 1.56], [-2.44, 2.78, -0.6], M.woodDark);
box(shop, [0.82, 0.16, 1.62], [-2.13, 0.08, -0.6], M.stoneLight);
// Interior floor, shelf and warm light make the entrance read as usable.
box(shop, [3.65, 0.10, 4.4], [-4.65, 0.04, 0.8], M.wood);
box(shop, [0.36, 1.55, 3.1], [-6.05, 1.02, 0.6], M.woodDark);
box(shop, [0.42, 0.12, 3.2], [-6.02, 1.75, 0.6], M.woodLight);
box(shop, [0.10, 1.75, 0.42], [-3.0, 0.9, -1.12], M.red);
box(shop, [0.10, 1.75, 0.42], [-3.0, 0.9, -0.08], M.mustard);
const interiorLight = new THREE.PointLight(0xffb864, 11, 5, 2);
interiorLight.position.set(-3.4, 2.15, -0.6);
shop.add(interiorLight);
// Upper facade windows.
function shopWindow(z) {
box(shop, [0.09, 1.10, 1.05], [-2.53, 3.55, z], M.shadow);
box(shop, [0.14, 0.12, 1.25], [-2.44, 3.00, z], M.woodDark);
box(shop, [0.14, 0.12, 1.25], [-2.44, 4.10, z], M.woodDark);
box(shop, [0.14, 1.20, 0.12], [-2.44, 3.55, z - 0.56], M.woodDark);
box(shop, [0.14, 1.20, 0.12], [-2.44, 3.55, z + 0.56], M.woodDark);
box(shop, [0.12, 1.04, 0.09], [-2.42, 3.55, z], M.wood);
box(shop, [0.24, 1.28, 0.36], [-2.34, 3.55, z - 0.73], M.plasterRose);
box(shop, [0.24, 1.28, 0.36], [-2.34, 3.55, z + 0.73], M.plasterRose);
}
shopWindow(-2.65);
shopWindow(2.35);
// Stepped, terracotta roof.
box(shop, [4.30, 0.30, 9.55], [-4.70, 5.17, 0.2], M.roof);
box(shop, [3.85, 0.30, 9.05], [-4.85, 5.43, 0.2], M.roofDark);
box(shop, [0.48, 0.28, 9.12], [-4.94, 5.68, 0.2], M.roof);
for (let i = 0; i < 11; i++) {
box(
shop,
[4.05, 0.09, 0.18],
[-4.78, 5.35, -3.95 + i * 0.83],
i % 2 ? M.roof : M.roofDark
);
}
box(shop, [0.55, 0.85, 0.55], [-5.45, 5.78, 2.7], M.plasterLight);
// Original shop sign.
const atelierSign = signMesh({
title: "ÑAWI",
subtitle: "TALLER DE TEXTILES",
width: 2.7,
height: 0.72,
background: "#73362f",
foreground: "#f1dfba",
position: [-2.49, 3.53, -0.6],
rotationY: Math.PI / 2
});
shop.add(atelierSign);
// ── Outdoor work display ───────────────────────────────────────────────
const display = new THREE.Group();
shop.add(display);
// Workbench against the shop edge, outside the clear central passage.
box(display, [1.22, 0.18, 2.65], [-1.72, 1.02, 2.48], M.woodLight);
box(display, [1.14, 0.13, 2.48], [-1.72, 0.38, 2.48], M.wood);
for (const x of [-2.18, -1.26]) {
for (const z of [1.35, 3.58]) {
box(display, [0.16, 0.95, 0.16], [x, 0.48, z], M.woodDark);
}
}
// Folded woven pieces.
const textileColors = [M.red, M.mustard, M.teal, M.indigo, M.cream];
for (let stack = 0; stack < 3; stack++) {
for (let layer = 0; layer < 3; layer++) {
box(
display,
[0.82, 0.075, 0.48],
[-1.73, 1.15 + layer * 0.075, 1.52 + stack * 0.66],
textileColors[(stack + layer) % textileColors.length]
);
}
}
// Small stepped ceramic vessels.
function vessel(x, y, z, material, scale = 1) {
box(display, [0.25 * scale, 0.08 * scale, 0.25 * scale],
[x, y + 0.04 * scale, z], M.woodDark);
box(display, [0.34 * scale, 0.25 * scale, 0.34 * scale],
[x, y + 0.20 * scale, z], material);
box(display, [0.20 * scale, 0.12 * scale, 0.20 * scale],
[x, y + 0.385 * scale, z], material);
box(display, [0.25 * scale, 0.045 * scale, 0.25 * scale],
[x, y + 0.46 * scale, z], M.cream);
}
vessel(-1.48, 1.12, 2.20, M.terracotta, 0.72);
vessel(-1.98, 1.12, 2.28, M.teal, 0.62);
vessel(-1.48, 1.12, 2.88, M.clay, 0.58);
vessel(-1.96, 0.46, 2.45, M.mustard, 0.72);
// A sample textile hangs from the facade.
box(display, [0.075, 1.35, 0.72], [-2.48, 1.88, 3.70], M.indigo);
for (let i = 0; i < 5; i++) {
box(
display,
[0.085, 0.10, 0.72],
[-2.46, 1.35 + i * 0.25, 3.70],
i % 2 ? M.red : M.mustard
);
}
// Striped awning.
for (let i = 0; i < 7; i++) {
box(
display,
[1.30, 0.13, 0.37],
[-2.06, 2.80, 1.30 + i * 0.39],
i % 2 ? M.cream : M.red
);
}
box(display, [0.13, 0.36, 2.75], [-1.40, 2.62, 2.48], M.red);
box(display, [0.10, 2.60, 0.10], [-1.42, 1.34, 1.15], M.woodDark);
box(display, [0.10, 2.60, 0.10], [-1.42, 1.34, 3.81], M.woodDark);
// Small lantern beside the entrance.
box(shop, [0.42, 0.08, 0.08], [-2.32, 2.62, -1.48], M.woodDark);
box(shop, [0.28, 0.38, 0.28], [-2.08, 2.43, -1.48], M.mustard);
box(shop, [0.34, 0.08, 0.34], [-2.08, 2.66, -1.48], M.woodDark);
box(shop, [0.34, 0.08, 0.34], [-2.08, 2.20, -1.48], M.woodDark);
const lantern = new THREE.PointLight(0xffa84e, 12, 5.5, 2);
lantern.position.set(-1.94, 2.43, -1.48);
shop.add(lantern);
// ── Opposite wall and small colonial doorway ───────────────────────────
const opposite = new THREE.Group();
scene.add(opposite);
box(opposite, [1.50, 4.2, 7.0], [5.95, 2.1, 1.15], M.plasterRose);
box(opposite, [1.75, 0.25, 7.35], [5.95, 4.30, 1.15], M.roofDark);
box(opposite, [0.12, 0.12, 7.15], [5.16, 3.78, 1.15], M.cream);
// Door facing into the lane.
box(opposite, [0.09, 2.25, 1.15], [5.16, 1.13, 2.35], M.shadow);
box(opposite, [0.18, 2.40, 0.14], [5.07, 1.20, 1.72], M.woodDark);
box(opposite, [0.18, 2.40, 0.14], [5.07, 1.20, 2.98], M.woodDark);
box(opposite, [0.18, 0.16, 1.40], [5.07, 2.40, 2.35], M.woodDark);
box(opposite, [0.11, 2.14, 0.08], [5.04, 1.10, 2.35], M.plasterBlue);
// Upper window and a tiny balcony.
box(opposite, [0.10, 1.05, 0.95], [5.15, 3.10, -0.45], M.shadow);
box(opposite, [0.14, 1.20, 0.12], [5.06, 3.10, -0.97], M.woodDark);
box(opposite, [0.14, 1.20, 0.12], [5.06, 3.10, 0.07], M.woodDark);
box(opposite, [0.70, 0.12, 1.55], [4.83, 2.47, -0.45], M.wood);
for (let i = 0; i < 6; i++) {
box(opposite, [0.08, 0.48, 0.08], [4.56, 2.72, -1.08 + i * 0.25], M.woodDark);
}
const sanBlasPlaque = signMesh({
title: "SAN BLAS",
subtitle: "BARRIO DE ARTESANOS",
width: 1.8,
height: 0.62,
background: "#3e6664",
foreground: "#eee0be",
position: [5.08, 2.92, -1.95],
rotationY: -Math.PI / 2
});
opposite.add(sanBlasPlaque);
// ── Descending stairs ──────────────────────────────────────────────────
const stairCenterX = 1.58;
for (let i = 0; i < 7; i++) {
const top = -0.08 - i * 0.30;
const z = -3.78 - i * 0.72;
box(
scene,
[4.55, 0.34, 0.76],
[stairCenterX, top - 0.17, z],
i % 2 ? M.stoneLight : M.stoneWarm
);
if (i > 0) {
box(
scene,
[4.55, 0.31, 0.10],
[stairCenterX, top + 0.15, z - 0.32],
M.stoneDark
);
}
// Low stepped parapets frame, but do not close, the descent.
box(scene, [0.30, 0.48, 0.76], [-0.88, top + 0.24, z], M.stone);
box(scene, [0.30, 0.48, 0.76], [4.04, top + 0.24, z], M.stone);
}
box(scene, [4.55, 0.36, 1.45], [stairCenterX, -2.36, -8.22], M.stoneLight);
// Lower-lane paving.
const lowerCobbles = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.58, 0.10, 0.54),
cobbleMaterial,
7 * 4
);
lowerCobbles.receiveShadow = true;
scene.add(lowerCobbles);
let lowerIndex = 0;
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 7; col++) {
dummy.position.set(
-0.56 + col * 0.66 + (row % 2) * 0.08,
-2.14,
-8.90 - row * 0.68
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
lowerCobbles.setMatrixAt(lowerIndex, dummy.matrix);
lowerCobbles.setColorAt(
lowerIndex,
new THREE.Color(cobbleColors[(row + col) % cobbleColors.length])
);
lowerIndex++;
}
}
lowerCobbles.instanceMatrix.needsUpdate = true;
if (lowerCobbles.instanceColor) lowerCobbles.instanceColor.needsUpdate = true;
// ── San Blas church tower in the distance ──────────────────────────────
const church = new THREE.Group();
scene.add(church);
box(church, [5.4, 2.9, 2.8], [0.75, -0.74, -11.35], M.stoneWarm);
box(church, [5.7, 0.24, 3.05], [0.75, 0.83, -11.35], M.cream);
box(church, [4.9, 0.28, 2.45], [0.75, 1.03, -11.45], M.roofDark);
box(church, [4.25, 0.30, 2.02], [0.75, 1.28, -11.50], M.roof);
// Rectangular colonial bell tower.
box(church, [2.35, 5.35, 2.35], [0.75, 0.48, -9.72], M.stoneLight);
box(church, [2.52, 0.18, 2.52], [0.75, 1.02, -9.72], M.cream);
box(church, [2.52, 0.18, 2.52], [0.75, 2.76, -9.72], M.cream);
// Bell opening, recessed into the tower.
box(church, [0.72, 1.12, 0.10], [0.75, 1.85, -8.51], M.shadow);
box(church, [0.82, 0.13, 0.16], [0.75, 1.25, -8.47], M.cream);
box(church, [0.82, 0.13, 0.16], [0.75, 2.45, -8.47], M.cream);
// A small visible bell.
box(church, [0.38, 0.46, 0.32], [0.75, 1.82, -8.37], M.mustard);
box(church, [0.52, 0.12, 0.42], [0.75, 2.08, -8.37], M.woodDark);
// Stepped tiled tower roof.
box(church, [2.75, 0.28, 2.75], [0.75, 3.30, -9.72], M.roofDark);
box(church, [2.28, 0.30, 2.28], [0.75, 3.55, -9.72], M.roof);
box(church, [1.65, 0.30, 1.65], [0.75, 3.80, -9.72], M.roofDark);
box(church, [0.70, 0.26, 0.70], [0.75, 4.03, -9.72], M.roof);
// Simple voxel cross.
box(church, [0.10, 0.60, 0.10], [0.75, 4.46, -9.72], M.woodDark);
box(church, [0.34, 0.10, 0.10], [0.75, 4.53, -9.72], M.woodDark);
// Church entrance, set slightly to one side of the tower.
box(church, [0.85, 1.65, 0.10], [2.18, -1.35, -9.90], M.shadow);
box(church, [1.02, 0.14, 0.15], [2.18, -0.47, -9.84], M.cream);
// ── Distant San Blas roofscape ─────────────────────────────────────────
const distant = new THREE.Group();
scene.add(distant);
for (let i = 0; i < 11; i++) {
const x = -8.2 + i * 1.65 + (random() - 0.5) * 0.5;
const z = -14.0 - random() * 2.5;
const h = 2.0 + random() * 2.6;
const w = 1.1 + random() * 0.7;
box(
distant,
[w, h, 1.25],
[x, -2.2 + h / 2, z],
i % 3 === 0 ? M.bgRoof : M.bg
);
box(
distant,
[w + 0.18, 0.22, 1.5],
[x, -2.2 + h + 0.11, z],
M.bgRoof
);
}
// ── Small planted accents ──────────────────────────────────────────────
function planter(x, y, z, material) {
box(scene, [0.72, 0.48, 0.72], [x, y + 0.24, z], material);
box(scene, [0.60, 0.08, 0.60], [x, y + 0.50, z], M.woodDark);
box(scene, [0.28, 0.68, 0.28], [x, y + 0.79, z], M.leaf);
box(scene, [0.48, 0.30, 0.38], [x + 0.12, y + 0.70, z], M.leaf);
box(scene, [0.40, 0.42, 0.30], [x - 0.14, y + 0.76, z + 0.04], M.leaf);
}
planter(5.58, 0, -2.35, M.plasterBlue);
planter(-2.02, 0, -2.65, M.terracotta);
// ── Direct camera controls ─────────────────────────────────────────────
const orbit = {
target: new THREE.Vector3(0.25, 0.15, 0.25),
radius: 18.5,
theta: 0.62,
phi: 1.02
};
const views = {
lane: {
target: [0.25, 0.15, 0.25],
radius: 18.5,
theta: 0.62,
phi: 1.02
},
shop: {
target: [-1.30, 1.45, 1.05],
radius: 9.4,
theta: 0.76,
phi: 1.05
},
stairs: {
target: [1.35, -0.80, -4.65],
radius: 11.7,
theta: 0.23,
phi: 1.02
}
};
let cameraTween = null;
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
function moveToView(name, instant = false) {
const view = views[name];
if (!view) return;
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.toggle("active", button.dataset.view === name);
});
if (instant || reducedMotion) {
orbit.target.set(...view.target);
orbit.radius = view.radius;
orbit.theta = view.theta;
orbit.phi = view.phi;
cameraTween = null;
updateCamera();
return;
}
cameraTween = {
elapsed: 0,
duration: 0.95,
from: {
target: orbit.target.clone(),
radius: orbit.radius,
theta: orbit.theta,
phi: orbit.phi
},
to: {
target: new THREE.Vector3(...view.target),
radius: view.radius,
theta: view.theta,
phi: view.phi
}
};
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => moveToView(button.dataset.view));
});
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
cameraTween = null;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.focus({ preventScroll: true });
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (event.shiftKey) {
const right = new THREE.Vector3(
Math.cos(orbit.theta),
0,
-Math.sin(orbit.theta)
);
orbit.target.addScaledVector(right, -dx * orbit.radius * 0.0013);
orbit.target.y = clamp(
orbit.target.y + dy * orbit.radius * 0.0011,
-2.0,
4.8
);
} else {
orbit.theta -= dx * 0.005;
orbit.phi = clamp(orbit.phi - dy * 0.0045, 0.42, 1.40);
}
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraTween = null;
orbit.radius = clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
6.8,
29
);
},
{ passive: false }
);
window.addEventListener("keydown", event => {
if (event.target instanceof HTMLButtonElement) return;
let handled = true;
cameraTween = null;
switch (event.key) {
case "ArrowLeft": orbit.theta += 0.08; break;
case "ArrowRight": orbit.theta -= 0.08; break;
case "ArrowUp": orbit.phi = clamp(orbit.phi - 0.06, 0.42, 1.40); break;
case "ArrowDown": orbit.phi = clamp(orbit.phi + 0.06, 0.42, 1.40); break;
case "+":
case "=": orbit.radius = clamp(orbit.radius - 0.7, 6.8, 29); break;
case "-": orbit.radius = clamp(orbit.radius + 0.7, 6.8, 29); break;
case "r":
case "R": moveToView("lane"); break;
default: handled = false;
}
if (handled) event.preventDefault();
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
// ── Animation and annotation projection ────────────────────────────────
const shopAnchor = new THREE.Vector3(-2.45, 3.55, -0.6);
const projectedAnchor = new THREE.Vector3();
const clock = new THREE.Clock();
function updateTween(delta) {
if (!cameraTween) return;
cameraTween.elapsed += delta;
const t = clamp(cameraTween.elapsed / cameraTween.duration, 0, 1);
const eased = t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
orbit.target.lerpVectors(
cameraTween.from.target,
cameraTween.to.target,
eased
);
orbit.radius = THREE.MathUtils.lerp(
cameraTween.from.radius,
cameraTween.to.radius,
eased
);
orbit.theta = THREE.MathUtils.lerp(
cameraTween.from.theta,
cameraTween.to.theta,
eased
);
orbit.phi = THREE.MathUtils.lerp(
cameraTween.from.phi,
cameraTween.to.phi,
eased
);
if (t >= 1) cameraTween = null;
}
function updatePin() {
projectedAnchor.copy(shopAnchor).project(camera);
const visible =
projectedAnchor.z > -1 &&
projectedAnchor.z < 1 &&
Math.abs(projectedAnchor.x) < 0.96 &&
Math.abs(projectedAnchor.y) < 0.93;
shopPin.style.opacity = visible ? "1" : "0";
if (visible) {
const x = (projectedAnchor.x * 0.5 + 0.5) * innerWidth;
const y = (-projectedAnchor.y * 0.5 + 0.5) * innerHeight;
shopPin.style.left = `${x}px`;
shopPin.style.top = `${y}px`;
}
}
updateCamera();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
updateTween(delta);
updateCamera();
updatePin();
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
loading.classList.add("done");
});
</script>
</body>
</html>
```