Prompt specification
Build or customize the Three.js 3D scene "Naschmarkt row and surrounding street slice" 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: Naschmarkt row and surrounding street slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/naschmarkt-row-and-surrounding-street-slice-x2879
Scene Description Prompt:
A voxel slice of Vienna's Naschmarkt with varied produce stalls, pedestrian aisle, shoppers, and surrounding road edges. Three.js from cdnjs, one HTML file.
Working Three.js Starter (naschmarkt-row-and-surrounding-street-slice-x2879):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Naschmarkt — Voxel Slice</title>
<style>
:root {
--ink: #24333a;
--paper: rgba(255, 248, 232, 0.92);
--accent: #c94c3f;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d1d9;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
touch-action: none;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
}
.panel {
position: fixed;
z-index: 5;
pointer-events: none;
background: var(--paper);
border: 1px solid rgba(36, 51, 58, 0.13);
box-shadow: 0 12px 35px rgba(32, 47, 55, 0.16);
backdrop-filter: blur(12px);
}
#title {
top: 20px;
left: 20px;
padding: 15px 18px 14px;
border-radius: 4px;
max-width: min(360px, calc(100vw - 40px));
}
#title .eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: #6c7778;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
#title .eyebrow::before {
content: "";
width: 8px;
height: 8px;
background: var(--accent);
box-shadow: 3px 3px 0 #e0a43c;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 44px);
font-weight: 700;
line-height: 0.95;
letter-spacing: -0.045em;
}
#title p {
margin: 9px 0 0;
color: #667174;
font-size: 12px;
line-height: 1.45;
}
#views {
right: 20px;
top: 20px;
padding: 8px;
border-radius: 4px;
display: flex;
gap: 6px;
pointer-events: auto;
}
button {
appearance: none;
border: 0;
border-radius: 3px;
padding: 10px 12px;
background: transparent;
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}
button:hover {
background: var(--ink);
color: white;
}
button:active { transform: translateY(1px); }
#help {
left: 20px;
bottom: 20px;
padding: 10px 13px;
border-radius: 4px;
color: #536165;
font-size: 11px;
line-height: 1.55;
}
#help strong {
color: var(--ink);
font-weight: 800;
}
#stamp {
position: fixed;
z-index: 4;
right: 22px;
bottom: 20px;
color: rgba(36, 51, 58, 0.65);
font-family: Georgia, serif;
font-size: 11px;
font-style: italic;
pointer-events: none;
}
@media (max-width: 700px) {
#title {
top: 12px;
left: 12px;
padding: 12px 14px;
}
#title p { display: none; }
#views {
top: auto;
right: 12px;
bottom: 58px;
flex-direction: column;
}
#help {
left: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
}
#stamp { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<header id="title" class="panel">
<div class="eyebrow">Vienna · 48°12′N</div>
<h1>Naschmarkt</h1>
<p>A lively voxel slice of Vienna’s open-air market, with produce stalls, browsers, streetcars, and neighborhood façades.</p>
</header>
<nav id="views" class="panel" aria-label="Camera views">
<button data-view="overview">Overview</button>
<button data-view="aisle">Aisle</button>
<button data-view="top">Plan</button>
</nav>
<div id="help" class="panel">
<strong>Drag</strong> to orbit · <strong>Right-drag / Shift-drag</strong> to pan · <strong>Scroll / pinch</strong> to zoom
</div>
<div id="stamp">Wiener Alltag, in little squares.</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const container = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#b9d1d9");
scene.fog = new THREE.Fog("#b9d1d9", 43, 86);
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.06;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-25, 25, 20, -20, 0.1, 160);
const cameraTarget = new THREE.Vector3(0, 0.8, 0);
const orbit = {
theta: 0.72,
phi: 1.02,
radius: 48,
zoom: 1.08
};
scene.add(new THREE.HemisphereLight("#d9eef2", "#8b7661", 2.15));
const sun = new THREE.DirectionalLight("#fff0ce", 3.25);
sun.position.set(-18, 30, 17);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -31;
sun.shadow.camera.right = 31;
sun.shadow.camera.top = 34;
sun.shadow.camera.bottom = -34;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#8bb9d1", 0.65);
fill.position.set(20, 12, -18);
scene.add(fill);
// ------------------------------------------------------------
// Shared geometry and helpers
// ------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
base: material("#bcae98"),
ground: material("#d4c9b5"),
pavementA: material("#d7d0c2"),
pavementB: material("#cbc4b6"),
pavementC: material("#e0d8c8"),
curb: material("#eee4d2"),
curbDark: material("#77766e"),
road: material("#4d5558"),
roadMark: material("#e4dfce"),
rail: material("#879092", { metalness: 0.65, roughness: 0.38 }),
sidewalk: material("#c9c3b6"),
wood: material("#78503b"),
woodLight: material("#a7744d"),
woodDark: material("#4f392f"),
metal: material("#59666a", { metalness: 0.45, roughness: 0.48 }),
dark: material("#273238"),
glass: material("#294653", { metalness: 0.2, roughness: 0.26 }),
glassLight: material("#7ca3ad", { metalness: 0.12, roughness: 0.3 }),
cream: material("#f0dfbd"),
white: material("#f4efe2"),
orange: material("#db633c"),
orangeDark: material("#a94431"),
yellow: material("#e2ad3b"),
red: material("#cf463b"),
green: material("#477c52"),
greenDark: material("#315c3e"),
leaf: material("#6d9250"),
leafDark: material("#4e7542"),
purple: material("#765273"),
pink: material("#d77d8d"),
bread: material("#bf8246"),
breadDark: material("#87532f"),
lamp: material("#ffe6a1", { emissive: "#f7b84d", emissiveIntensity: 1.35 }),
tramOrange: material("#e56a3e"),
tramCream: material("#f1dfbd"),
tramWindow: material("#355562", { metalness: 0.2, roughness: 0.28 })
};
function box(parent, mat, x, y, z, width, height, depth, cast = true, receive = true) {
const mesh = new THREE.Mesh(cubeGeometry, mat);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
let randomState = 49127;
function random() {
randomState |= 0;
randomState = randomState + 0x6D2B79F5 | 0;
let value = Math.imul(randomState ^ randomState >>> 15, 1 | randomState);
value = value + Math.imul(value ^ value >>> 7, 61 | value) ^ value;
return ((value ^ value >>> 14) >>> 0) / 4294967296;
}
function randomRange(min, max) {
return min + random() * (max - min);
}
function choose(list) {
return list[Math.floor(random() * list.length)];
}
function makeLabel(text, background = "#29383c", foreground = "#fff4d7", worldWidth = 2.15) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(255,255,255,0.12)";
context.fillRect(0, 0, canvas.width, 10);
context.fillRect(0, canvas.height - 10, canvas.width, 10);
context.fillStyle = foreground;
context.font = `700 ${text.length > 12 ? 37 : 48}px Arial, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
}));
sprite.scale.set(worldWidth, worldWidth * 0.25, 1);
return sprite;
}
// ------------------------------------------------------------
// Ground, paving, sidewalks, roads, and rails
// ------------------------------------------------------------
box(scene, M.base, 0, -0.58, 0, 40, 0.75, 48, false);
box(scene, M.ground, 0, -0.14, 0, 8.2, 0.22, 44, false);
const pavingMaterials = [M.pavementA, M.pavementB, M.pavementC];
for (let row = 0; row < 26; row++) {
for (let column = 0; column < 5; column++) {
box(
scene,
choose(pavingMaterials),
-3.2 + column * 1.6,
0.005,
-20.7 + row * 1.67,
1.54,
0.055,
1.61,
false
);
}
}
for (const side of [-1, 1]) {
box(scene, M.sidewalk, side * 7.35, -0.08, 0, 2.05, 0.24, 44, false);
box(scene, M.road, side * 10.8, -0.09, 0, 4.95, 0.26, 44, false);
box(scene, M.curb, side * 4.02, 0.08, 0, 0.22, 0.3, 44, false);
box(scene, M.curb, side * 8.35, 0.05, 0, 0.18, 0.26, 44, false);
box(scene, M.curbDark, side * 13.25, 0.05, 0, 0.18, 0.26, 44, false);
box(scene, M.rail, side * 9.55, 0.12, 0, 0.085, 0.09, 43.5, false);
box(scene, M.rail, side * 12.05, 0.12, 0, 0.085, 0.09, 43.5, false);
for (let z = -21; z <= 21; z += 1.2) {
box(scene, M.woodDark, side * 9.55, 0.07, z, 1.8, 0.05, 0.13, false);
box(scene, M.woodDark, side * 12.05, 0.07, z, 1.8, 0.05, 0.13, false);
}
for (let z = -20; z < 21; z += 3.2) {
box(scene, M.roadMark, side * 8.72, 0.055, z, 0.09, 0.025, 1.45, false);
}
for (let i = 0; i < 6; i++) {
box(scene, M.roadMark, side * 10.8, 0.06, 18.15 + i * 0.48, 4.55, 0.025, 0.25, false);
}
}
// ------------------------------------------------------------
// Market stalls
// ------------------------------------------------------------
const stallSpecs = [
{
title: "FRUCHT",
canopy: ["#d34b3e", "#f2dfbd"],
produce: ["#d8493d", "#e98b32", "#e5b93e", "#6f9848", "#a85c39"]
},
{
title: "GEMÜSE",
canopy: ["#397653", "#ecd29c"],
produce: ["#4c884d", "#76a653", "#d16e35", "#e0b43c", "#8a9c43"]
},
{
title: "BLUMEN",
canopy: ["#bc4d64", "#f2dfc0"],
produce: ["#e66f89", "#f0b54e", "#8c5aa3", "#e8d56c", "#b74b63"]
},
{
title: "BROT",
canopy: ["#b87938", "#f0dfbb"],
produce: ["#c98a48", "#a96232", "#e0b66e", "#75452b", "#d8a55c"]
},
{
title: "KÄSE",
canopy: ["#446d83", "#efe2c4"],
produce: ["#ead493", "#d5b85d", "#f1e0ad", "#b99142", "#f4e8c8"]
},
{
title: "GEWÜRZE",
canopy: ["#4d7860", "#ead6ac"],
produce: ["#a85036", "#c47a35", "#d5aa42", "#78613c", "#7d934e"]
}
];
function addProduce(parent, side, spec, seedOffset) {
const counterX = -side * 0.63;
for (let crate = 0; crate < 3; crate++) {
const z = -0.95 + crate * 0.95;
const crateMat = crate % 2 ? M.wood : M.woodLight;
box(parent, crateMat, counterX, 1.13, z, 0.83, 0.18, 0.78, false);
box(parent, M.woodDark, counterX, 1.02, z - 0.37, 0.84, 0.18, 0.055, false);
box(parent, M.woodDark, counterX, 1.02, z + 0.37, 0.84, 0.18, 0.055, false);
for (let item = 0; item < 7; item++) {
const size = randomRange(0.14, 0.21);
const px = counterX + randomRange(-0.23, 0.23);
const pz = z + randomRange(-0.25, 0.25);
const py = 1.27 + size * 0.5 + randomRange(0, 0.035);
const produce = box(
parent,
material(choose(spec.produce)),
px, py, pz,
size, size, size,
false
);
produce.rotation.y = randomRange(-0.35, 0.35);
produce.rotation.z = randomRange(-0.12, 0.12);
}
}
for (let shelf = 0; shelf < 3; shelf++) {
const y = 0.72 + shelf * 0.65;
box(parent, M.wood, side * 0.95, y, 0, 0.62, 0.11, 2.75, false);
for (let item = 0; item < 9; item++) {
const size = randomRange(0.13, 0.19);
box(
parent,
material(choose(spec.produce)),
side * 0.95 + randomRange(-0.13, 0.13),
y + 0.11 + size * 0.5,
-1.16 + item * 0.29,
size, size, size,
false
);
}
}
}
function addStall(side, z, index) {
const spec = stallSpecs[(index + (side === 1 ? 2 : 0)) % stallSpecs.length];
const group = new THREE.Group();
group.position.set(side * 5.12, 0, z);
scene.add(group);
// Counter and lower cabinet.
box(group, M.wood, -side * 0.64, 0.68, 0, 0.92, 0.72, 2.95);
box(group, M.woodLight, -side * 0.64, 1.075, 0, 1.02, 0.12, 3.08);
// Back rack and canvas wall.
box(group, M.cream, side * 1.02, 1.58, 0, 0.12, 2.3, 3.2);
for (let shelf = 0; shelf < 3; shelf++) {
box(group, M.wood, side * 0.75, 0.72 + shelf * 0.65, 0, 0.62, 0.1, 2.75);
}
// Four posts.
for (const px of [-1.18, 1.18]) {
for (const pz of [-1.62, 1.62]) {
box(group, M.woodDark, px, 1.53, pz, 0.1, 3.06, 0.1);
}
}
// Striped canopy.
const stripeCount = 8;
for (let stripe = 0; stripe < stripeCount; stripe++) {
const depth = 3.72 / stripeCount;
const color = stripe % 2 ? spec.canopy[1] : spec.canopy[0];
box(
group,
material(color),
0,
3.02,
-1.86 + depth * (stripe + 0.5),
2.72,
0.18,
depth + 0.015
);
box(
group,
material(color),
-side * 1.34,
2.72,
-1.86 + depth * (stripe + 0.5),
0.11,
0.45,
depth + 0.015
);
}
// Sign and a small striped price board.
const sign = makeLabel(spec.title, spec.canopy[0], "#fff3d3", 2.0);
sign.position.set(0, 3.55, 0);
group.add(sign);
const price = makeLabel("FRISCH", "#f3e2bd", "#344047", 1.15);
price.position.set(-side * 0.95, 1.9, -1.1);
group.add(price);
addProduce(group, side, spec, index);
// Crates and a stool at the aisle side.
box(group, M.woodLight, -side * 0.48, 0.2, 1.88, 0.72, 0.36, 0.62);
box(group, M.woodDark, -side * 0.48, 0.39, 1.88, 0.76, 0.08, 0.65);
box(group, M.wood, -side * 0.78, 0.48, 1.12, 0.38, 0.12, 0.38);
box(group, M.woodDark, -side * 0.78, 0.23, 1.12, 0.11, 0.48, 0.11);
}
const stallPositions = [-15.6, -9.3, -3.1, 3.1, 9.3, 15.6];
for (const side of [-1, 1]) {
stallPositions.forEach((z, index) => addStall(side, z, index));
}
// ------------------------------------------------------------
// Entrance sign
// ------------------------------------------------------------
const arch = new THREE.Group();
arch.position.z = 20.3;
scene.add(arch);
box(arch, M.woodDark, -4.03, 2.15, 0, 0.2, 4.3, 0.2);
box(arch, M.woodDark, 4.03, 2.15, 0, 0.2, 4.3, 0.2);
box(arch, M.wood, 0, 4.2, 0, 8.25, 0.2, 0.2);
const archSign = makeLabel("NASCHMARKT", "#b74436", "#fff0cc", 4.3);
archSign.position.set(0, 4.65, 0);
arch.add(archSign);
// Small hanging pennants.
for (let i = 0; i < 9; i++) {
const x = -3.5 + i * 0.875;
const pennant = box(
arch,
material(i % 2 ? "#e6b64a" : "#4c7d61"),
x, 3.72, 0,
0.44, 0.48, 0.08
);
pennant.rotation.z = (i % 2 ? 1 : -1) * 0.08;
}
// ------------------------------------------------------------
// Trees, lamps, bins, and miscellaneous street furniture
// ------------------------------------------------------------
function addTree(x, z, variant = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(group, M.woodDark, 0, 1.05, 0, 0.28, 2.1, 0.28);
box(group, M.wood, 0.28, 1.9, 0, 0.7, 0.16, 0.16).rotation.z = -0.45;
const leafMaterial = variant ? M.leafDark : M.leaf;
box(group, leafMaterial, 0, 2.65, 0, 1.55, 1.25, 1.5);
box(group, leafMaterial, -0.55, 2.25, 0.1, 0.9, 0.85, 1.0);
box(group, variant ? M.leaf : M.leafDark, 0.55, 2.95, -0.1, 0.9, 0.85, 1.05);
box(group, M.leafDark, 0.05, 3.38, 0.1, 0.9, 0.55, 0.8);
}
function addLamp(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(group, M.metal, 0, 1.75, 0, 0.11, 3.5, 0.11);
box(group, M.metal, 0.32, 3.42, 0, 0.72, 0.09, 0.1);
box(group, M.dark, 0.61, 3.3, 0, 0.42, 0.22, 0.42);
box(group, M.lamp, 0.61, 3.15, 0, 0.32, 0.12, 0.32, false);
}
for (const side of [-1, 1]) {
addTree(side * 7.47, -12.2, side === 1 ? 1 : 0);
addTree(side * 7.47, 0, side === 1 ? 0 : 1);
addTree(side * 7.47, 12.2, side === 1 ? 1 : 0);
for (const z of [-18, -6, 6, 18]) {
addLamp(side * 7.95, z);
}
for (const z of [-16.5, -3.2, 10.2]) {
box(scene, M.metal, side * 7.92, 0.46, z, 0.5, 0.9, 0.5);
box(scene, M.dark, side * 7.92, 0.95, z, 0.56, 0.1, 0.56);
}
}
// ------------------------------------------------------------
// Voxel pedestrians
// ------------------------------------------------------------
const pedestrians = [];
const browsers = [];
const shirtMaterials = [
material("#c75242"),
material("#3f7287"),
material("#d4a33e"),
material("#5b8055"),
material("#795b76"),
material("#e1d7bf"),
material("#263f51")
];
const skinMaterials = [
material("#e6b48d"),
material("#c98c65"),
material("#9b6348"),
material("#f0c7a3"),
material("#754832")
];
const pantsMaterials = [
material("#303b43"),
material("#405462"),
material("#5b473d"),
material("#73726d")
];
function createPerson(options = {}) {
const group = new THREE.Group();
const shirt = options.shirt || choose(shirtMaterials);
const skin = options.skin || choose(skinMaterials);
const pants = options.pants || choose(pantsMaterials);
const hair = choose([M.dark, M.woodDark, material("#b2824f"), material("#5b4436")]);
// Torso.
box(group, shirt, 0, 1.22, 0, 0.48, 0.68, 0.31);
box(group, skin, 0, 1.64, 0, 0.13, 0.13, 0.15);
// Head, hair, eyes, and nose.
box(group, skin, 0, 1.88, 0, 0.39, 0.4, 0.38);
box(group, hair, 0, 2.075, -0.01, 0.41, 0.11, 0.4);
box(group, hair, 0, 1.99, -0.17, 0.42, 0.2, 0.07);
box(group, M.dark, -0.085, 1.92, 0.197, 0.04, 0.045, 0.025, false);
box(group, M.dark, 0.085, 1.92, 0.197, 0.04, 0.045, 0.025, false);
box(group, skin, 0, 1.83, 0.215, 0.08, 0.08, 0.08, false);
// Legs on pivots.
const legs = [];
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.135, 0.89, 0);
group.add(pivot);
box(pivot, pants, 0, -0.34, 0, 0.18, 0.68, 0.2);
box(pivot, M.dark, 0, -0.7, 0.06, 0.2, 0.12, 0.32);
legs.push(pivot);
}
// Arms on pivots.
const arms = [];
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.31, 1.48, 0);
group.add(pivot);
box(pivot, shirt, 0, -0.25, 0, 0.16, 0.5, 0.18);
box(pivot, skin, 0, -0.54, 0, 0.14, 0.17, 0.15);
arms.push(pivot);
}
// Some shoppers carry a tote.
if (options.bag) {
const bagMaterial = choose([M.cream, M.orange, M.green]);
box(group, bagMaterial, 0.42, 0.9, 0.04, 0.27, 0.34, 0.17);
box(group, M.woodDark, 0.42, 1.13, 0.04, 0.04, 0.25, 0.04, false);
}
// Occasional backpack.
if (options.backpack) {
box(group, options.backpack, 0, 1.23, -0.25, 0.36, 0.48, 0.16);
}
group.scale.setScalar(options.scale || randomRange(0.9, 1.05));
return { group, legs, arms };
}
for (let i = 0; i < 17; i++) {
const person = createPerson({
bag: random() > 0.48,
backpack: random() > 0.78
});
const direction = random() > 0.5 ? 1 : -1;
person.group.position.set(randomRange(-2.8, 2.8), 0, randomRange(-20, 20));
person.group.rotation.y = direction === 1 ? 0 : Math.PI;
scene.add(person.group);
pedestrians.push({
...person,
direction,
speed: randomRange(0.42, 0.82),
phase: randomRange(0, Math.PI * 2)
});
}
// Browsers stand close to the counters.
for (let i = 0; i < 14; i++) {
const side = i % 2 === 0 ? -1 : 1;
const person = createPerson({ bag: random() > 0.45 });
person.group.position.set(side * 3.62, 0, randomRange(-18.5, 18.5));
person.group.rotation.y = side === 1 ? Math.PI / 2 : -Math.PI / 2;
scene.add(person.group);
browsers.push(person);
}
// A few seated café customers at the end of the aisle.
for (let i = 0; i < 4; i++) {
const person = createPerson({ shirt: choose(shirtMaterials) });
const side = i % 2 === 0 ? -1 : 1;
person.group.position.set(side * 2.8, 0.1, 17.7 + Math.floor(i / 2) * 1.8);
person.group.rotation.y = side * Math.PI * 0.5;
person.group.scale.multiplyScalar(0.95);
scene.add(person.group);
browsers.push(person);
box(scene, M.wood, side * 3.2, 0.62, person.group.position.z, 0.5, 0.1, 0.5);
box(scene, M.woodDark, side * 3.2, 0.3, person.group.position.z, 0.12, 0.55, 0.12);
}
// ------------------------------------------------------------
// Urban façades beyond the roads
// ------------------------------------------------------------
const facadeColors = [
"#d59b78",
"#e2c39b",
"#91aaa0",
"#c7b28e",
"#a8a0a0",
"#d8b18a",
"#8fa5b0"
];
function addBuilding(side, z, height, index) {
const group = new THREE.Group();
group.position.set(side * 16.55, 0, z);
scene.add(group);
const facade = material(facadeColors[index % facadeColors.length]);
const width = 5.55;
const depth = 6.05;
box(group, facade, 0, height / 2, 0, width, height, depth);
box(group, M.cream, 0, height + 0.08, 0, width + 0.22, 0.22, depth + 0.22);
box(group, M.woodDark, 0, height + 0.27, 0.8, 1.1, 0.75, 1.0);
const innerX = -side * (width / 2 + 0.035);
for (let floor = 0; floor < Math.floor((height - 1.1) / 2.05); floor++) {
const y = 2.2 + floor * 2.05;
for (const windowZ of [-1.75, 0, 1.75]) {
box(group, M.cream, innerX, y, windowZ, 0.12, 1.48, 1.05);
box(group, M.glass, innerX - side * 0.02, y, windowZ, 0.08, 1.23, 0.82, false);
box(group, M.cream, innerX - side * 0.07, y, windowZ, 0.07, 1.25, 0.055, false);
box(group, M.cream, innerX - side * 0.07, y + 0.02, windowZ, 0.07, 0.055, 0.85, false);
}
box(group, M.cream, innerX - side * 0.28, y - 0.81, 0, 0.72, 0.12, 4.75);
box(group, M.metal, innerX - side * 0.62, y - 0.47, 0, 0.06, 0.6, 4.75, false);
}
// Ground-floor shopfront.
box(group, M.woodDark, innerX, 1.05, 0, 0.12, 1.7, 3.9);
box(group, M.glassLight, innerX - side * 0.025, 1.15, 0, 0.08, 1.4, 3.55, false);
// Little awning.
box(group, index % 2 ? M.green : M.orange, innerX - side * 0.48, 2.02, 0, 0.9, 0.12, 4.15);
}
for (const side of [-1, 1]) {
for (let i = 0; i < 7; i++) {
const z = -18 + i * 6;
const height = [7.3, 8.8, 6.7, 9.2, 7.8, 8.4, 6.9][i];
addBuilding(side, z, height, i + (side === 1 ? 3 : 0));
}
}
// ------------------------------------------------------------
// Vienna-style streetcar and parked delivery van
// ------------------------------------------------------------
function addTram() {
const tram = new THREE.Group();
tram.position.set(10.8, 0, -3);
scene.add(tram);
box(tram, M.tramOrange, 0, 1.23, 0, 1.6, 1.32, 7.25);
box(tram, M.tramCream, 0, 2.05, -0.1, 1.48, 0.58, 6.95);
box(tram, M.tramOrange, 0, 2.42, -0.08, 1.36, 0.18, 6.72);
box(tram, M.cream, 0, 1.38, 3.65, 1.62, 0.24, 0.08);
box(tram, M.cream, 0, 1.38, -3.65, 1.62, 0.24, 0.08);
// Side windows.
for (const side of [-1, 1]) {
for (const z of [-2.45, -1.23, 0, 1.23, 2.45]) {
box(tram, M.tramWindow, side * 0.81, 2.06, z, 0.055, 0.69, 0.96, false);
box(tram, M.cream, side * 0.84, 2.06, z, 0.025, 0.75, 0.055, false);
}
}
// Front and rear windshields.
box(tram, M.tramWindow, 0, 2.08, 3.52, 1.28, 0.72, 0.055, false);
box(tram, M.tramWindow, 0, 2.08, -3.52, 1.28, 0.72, 0.055, false);
// Lights and bumpers.
box(tram, M.lamp, -0.5, 1.4, 3.69, 0.2, 0.2, 0.06, false);
box(tram, M.lamp, 0.5, 1.4, 3.69, 0.2, 0.2, 0.06, false);
box(tram, M.dark, 0, 0.66, 3.68, 1.42, 0.18, 0.16);
// Bogies and blocky wheels.
for (const z of [-2.2, 2.2]) {
box(tram, M.dark, 0, 0.52, z, 1.22, 0.28, 0.65);
for (const side of [-1, 1]) {
box(tram, M.dark, side * 0.78, 0.43, z, 0.18, 0.52, 0.52);
}
}
const destination = makeLabel("WIKIA", "#25383d", "#f4dda4", 0.72);
destination.position.set(0, 2.62, 3.65);
tram.add(destination);
return tram;
}
const tram = addTram();
function addVan(x, z, color) {
const van = new THREE.Group();
van.position.set(x, 0, z);
scene.add(van);
const bodyMaterial = material(color);
box(van, bodyMaterial, 0, 0.9, 0, 1.65, 1.3, 3.35);
box(van, bodyMaterial, 0, 1.65, -0.65, 1.5, 0.5, 1.75);
box(van, M.glass, 0, 1.58, 0.28, 1.28, 0.48, 0.06, false);
box(van, M.glass, 0.76, 1.58, -0.65, 0.05, 0.43, 1.28, false);
box(van, M.glass, -0.76, 1.58, -0.65, 0.05, 0.43, 1.28, false);
box(van, M.cream, 0, 0.86, 1.69, 1.62, 0.2, 0.08);
for (const side of [-1, 1]) {
for (const wz of [-1.05, 1.05]) {
box(van, M.dark, side * 0.84, 0.46, wz, 0.18, 0.55, 0.55);
}
}
}
addVan(-11.9, -12.5, "#e1b33d");
addVan(-11.9, 7.7, "#547c89");
// ------------------------------------------------------------
// Camera controls implemented directly, without add-ons
// ------------------------------------------------------------
const pointerState = {
pointers: new Map(),
mode: "orbit",
lastX: 0,
lastY: 0,
pinchDistance: 0
};
const rendererCanvas = renderer.domElement;
rendererCanvas.addEventListener("contextmenu", event => event.preventDefault());
rendererCanvas.addEventListener("pointerdown", event => {
rendererCanvas.setPointerCapture(event.pointerId);
pointerState.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerState.pointers.size === 1) {
pointerState.mode =
event.button === 2 || event.shiftKey || event.ctrlKey ? "pan" : "orbit";
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
} else if (pointerState.pointers.size === 2) {
pointerState.mode = "pinch";
pointerState.pinchDistance = getPinchDistance();
}
});
rendererCanvas.addEventListener("pointermove", event => {
if (!pointerState.pointers.has(event.pointerId)) return;
pointerState.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerState.mode === "pinch" && pointerState.pointers.size >= 2) {
const distance = getPinchDistance();
if (pointerState.pinchDistance > 0) {
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * (distance / pointerState.pinchDistance),
0.62,
4.2
);
}
pointerState.pinchDistance = distance;
updateCamera();
return;
}
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
if (pointerState.mode === "orbit") {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.16, 1.42);
} else if (pointerState.mode === "pan") {
const scale = 0.025 / orbit.zoom;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const horizontalForward = new THREE.Vector3(-right.z, 0, right.x).normalize();
cameraTarget.addScaledVector(right, -dx * scale);
cameraTarget.addScaledVector(horizontalForward, -dy * scale);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -18, 18);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -25, 25);
}
updateCamera();
});
function endPointer(event) {
pointerState.pointers.delete(event.pointerId);
if (pointerState.pointers.size === 0) {
pointerState.mode = "orbit";
} else if (pointerState.pointers.size === 1) {
const remaining = [...pointerState.pointers.values()][0];
pointerState.lastX = remaining.x;
pointerState.lastY = remaining.y;
pointerState.mode = "orbit";
}
}
rendererCanvas.addEventListener("pointerup", endPointer);
rendererCanvas.addEventListener("pointercancel", endPointer);
rendererCanvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
4.2
);
updateCamera();
}, { passive: false });
function getPinchDistance() {
const points = [...pointerState.pointers.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
const presets = {
overview: {
target: [0, 0.8, 0],
theta: 0.72,
phi: 1.02,
zoom: 1.08
},
aisle: {
target: [0, 1.35, 2],
theta: 0.04,
phi: 1.25,
zoom: 1.7
},
top: {
target: [0, 0, 0],
theta: 0.001,
phi: 0.16,
zoom: 0.95
}
};
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => {
const preset = presets[button.dataset.view];
cameraTarget.set(...preset.target);
orbit.theta = preset.theta;
orbit.phi = preset.phi;
orbit.zoom = preset.zoom;
updateCamera();
});
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(38, 50 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const delta = Math.min(clock.getDelta(), 0.05);
for (const person of pedestrians) {
person.group.position.z += person.direction * person.speed * delta;
if (person.group.position.z > 22.5) person.group.position.z = -22.5;
if (person.group.position.z < -22.5) person.group.position.z = 22.5;
const swing = Math.sin(elapsed * person.speed * 5.4 + person.phase) * 0.46;
person.legs[0].rotation.x = swing;
person.legs[1].rotation.x = -swing;
person.arms[0].rotation.x = -swing * 0.75;
person.arms[1].rotation.x = swing * 0.75;
person.group.position.y = Math.abs(Math.sin(elapsed * 5 + person.phase)) * 0.018;
}
for (const person of browsers) {
const sway = Math.sin(elapsed * 1.6 + person.group.position.z) * 0.025;
person.group.rotation.z = sway;
person.arms[0].rotation.x = -0.15 + sway;
person.arms[1].rotation.x = 0.1 - sway;
}
tram.position.z += delta * 0.74;
if (tram.position.z > 25) tram.position.z = -25;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```