Prompt specification
Build or customize the Three.js 3D scene "Groceries delivered along a Gamcheon stair route" 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: Groceries delivered along a Gamcheon stair route
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/groceries-delivered-along-a-gamcheon-stair-route-x2974
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Gamcheon's hillside lanes in Busan. Create a compact neighborhood vignette with an original resident carrying groceries through stairs and landings. Show realistic route continuity without stereotyping daily life in the district. Low-poly.
Working Three.js Starter (groceries-delivered-along-a-gamcheon-stair-route-x2974):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gamcheon Hillside — Busan</title>
<style>
:root {
color-scheme: dark;
--ink: #f4f1e8;
--muted: rgba(244, 241, 232, 0.72);
--panel: rgba(20, 34, 41, 0.74);
--line: rgba(255, 255, 255, 0.16);
--accent: #e5b879;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d5df;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
color: var(--ink);
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(380px, calc(100vw - 48px));
padding: 18px 20px 17px;
border: 1px solid var(--line);
border-radius: 15px;
background: linear-gradient(
145deg,
rgba(24, 42, 49, 0.86),
rgba(24, 42, 49, 0.62)
);
box-shadow: 0 15px 45px rgba(22, 34, 40, 0.15);
backdrop-filter: blur(14px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 42px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.controls {
position: absolute;
top: 24px;
right: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 38px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--ink);
background: var(--panel);
box-shadow: 0 8px 30px rgba(24, 36, 42, 0.12);
backdrop-filter: blur(12px);
font: inherit;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.02em;
cursor: pointer;
}
button:hover {
border-color: rgba(255, 255, 255, 0.38);
background: rgba(31, 52, 61, 0.9);
}
.legend {
position: absolute;
left: 24px;
bottom: 22px;
display: flex;
align-items: center;
gap: 10px;
max-width: calc(100vw - 48px);
padding: 9px 13px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
background: rgba(20, 34, 41, 0.6);
backdrop-filter: blur(12px);
font-size: 10px;
letter-spacing: 0.02em;
}
.dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(229, 184, 121, 0.13);
}
.credit {
position: absolute;
right: 24px;
bottom: 23px;
color: rgba(255, 255, 255, 0.65);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: #20363e;
background: #b9d5df;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 0.6s ease, visibility 0.6s ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
@media (max-width: 640px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
.subtitle {
max-width: 75%;
margin-top: 8px;
}
.controls {
top: auto;
right: 14px;
bottom: 56px;
flex-direction: column;
}
.legend {
left: 14px;
bottom: 14px;
}
.credit {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly hillside neighborhood inspired by Gamcheon, Busan"></canvas>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Busan · Coastal hillside</div>
<h1>Gamcheon,<br />in passing</h1>
<p class="subtitle">
A compact, original neighborhood vignette: pastel homes, stacked lanes,
and one resident carrying groceries along a continuous stair route.
</p>
</section>
<div class="controls">
<button id="pauseButton" type="button">Pause walk</button>
<button id="resetButton" type="button">Reset view</button>
</div>
<div class="legend">
<span class="dot"></span>
<span>Drag to orbit · Scroll to zoom · Space to pause · R to reset</span>
</div>
<div class="credit">Inspired by Gamcheon · A quiet, non-documentary study</div>
</div>
<div id="loading">Building hillside lanes…</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 loading = document.querySelector("#loading");
const pauseButton = document.querySelector("#pauseButton");
const resetButton = document.querySelector("#resetButton");
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(0xb9d5df);
scene.fog = new THREE.Fog(0xb9d5df, 27, 83);
const camera = new THREE.PerspectiveCamera(
41,
window.innerWidth / window.innerHeight,
0.1,
220
);
const clock = new THREE.Clock();
// -----------------------------------------------------------------------
// Lighting
// -----------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xe5f6ff, 0x756957, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe5bd, 3.1);
sun.position.set(-12, 19, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xa9d7ef, 0.75);
rim.position.set(14, 8, -18);
scene.add(rim);
// -----------------------------------------------------------------------
// Materials and geometry helpers
// -----------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.88,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
side: options.side ?? THREE.FrontSide,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
const mats = {
stone: material(0x8d918b),
stoneLight: material(0xb8b5a9),
stoneDark: material(0x656d6b),
paving: material(0xc2beb1),
terrace: material(0x7f8b83),
soil: material(0x716e5e),
metal: material(0x475459, { metalness: 0.35, roughness: 0.58 }),
rail: material(0x526267, { metalness: 0.28, roughness: 0.56 }),
glass: material(0x476b79, { roughness: 0.28, metalness: 0.12 }),
warmGlass: material(0xe8c88d, {
roughness: 0.42,
emissive: 0x6b3e12,
emissiveIntensity: 0.22
}),
trim: material(0xe4dfcf),
darkTrim: material(0x465052),
roofTile: material(0x9b5f4f),
roofDark: material(0x48565a),
roofBlue: material(0x577077),
pot: material(0xa65f48),
leaf: material(0x55785c),
leafLight: material(0x78956a),
water: material(0x5793a4, { roughness: 0.3, metalness: 0.05 }),
waterLight: material(0x80b8c4, { roughness: 0.25 }),
skin: material(0xc78f70),
hair: material(0x343331),
jacket: material(0x435d69),
trousers: material(0x9d6752),
shoe: material(0x313536),
bag: material(0xb88b58),
vegetable: material(0x78904f),
orange: material(0xd4853f),
cloud: material(0xf1f3eb, { roughness: 1 })
};
function addBox(parent, width, height, depth, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinderBetween(parent, a, b, radius, mat, radialSegments = 8) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBeamBetween(parent, a, b, width, depth, mat) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, length, depth),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, radiusTop, radiusBottom, height, mat, x, y, z, segments = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addIcosahedron(parent, radius, mat, x, y, z, detail = 0) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, detail),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -----------------------------------------------------------------------
// Sea and atmosphere
// -----------------------------------------------------------------------
const sea = new THREE.Mesh(
new THREE.PlaneGeometry(190, 190, 1, 1),
mats.water
);
sea.rotation.x = -Math.PI / 2;
sea.position.y = -1.02;
sea.receiveShadow = true;
scene.add(sea);
const glints = [];
const glintMaterial = material(0xd6edf0, {
transparent: true,
opacity: 0.27,
roughness: 0.2,
depthWrite: false
});
let seed = 4287;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
for (let i = 0; i < 54; i++) {
const glint = new THREE.Mesh(
new THREE.PlaneGeometry(0.6 + random() * 1.8, 0.035 + random() * 0.055),
glintMaterial
);
glint.rotation.x = -Math.PI / 2;
glint.rotation.z = (random() - 0.5) * 0.28;
glint.position.set(
(random() - 0.5) * 92,
-0.99,
-11 - random() * 63
);
glint.userData.speed = 0.08 + random() * 0.11;
glints.push(glint);
scene.add(glint);
}
const sunDisc = new THREE.Mesh(
new THREE.IcosahedronGeometry(3.2, 2),
new THREE.MeshBasicMaterial({ color: 0xffe7b4 })
);
sunDisc.position.set(-29, 25, -57);
scene.add(sunDisc);
function createCloud(x, y, z, scale) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
addIcosahedron(cloud, 1.45, mats.cloud, -1.4, 0, 0, 1);
addIcosahedron(cloud, 1.8, mats.cloud, 0, 0.2, 0, 1);
addIcosahedron(cloud, 1.3, mats.cloud, 1.65, -0.05, 0.1, 1);
addIcosahedron(cloud, 1.05, mats.cloud, 0.25, -0.35, 0.4, 1);
scene.add(cloud);
}
createCloud(-16, 13, -38, 1.6);
createCloud(13, 16, -48, 1.25);
createCloud(27, 11, -34, 0.9);
// A restrained far shore gives the sea a readable scale.
addBox(scene, 74, 1.1, 7, material(0x788985), 0, -0.73, -57);
for (let i = 0; i < 15; i++) {
const width = 1 + random() * 2.4;
const height = 0.8 + random() * 2.2;
const building = addBox(
scene,
width,
height,
1.2 + random(),
material(i % 2 ? 0xa9b3aa : 0x8d9e99),
-31 + i * 4.3 + random() * 1.5,
-0.15 + height / 2,
-56.5 + random()
);
building.castShadow = false;
}
// -----------------------------------------------------------------------
// Terraced hillside
// -----------------------------------------------------------------------
const terraces = [
{ z: 7.1, depth: 4.0, width: 14.2, top: 0.03 },
{ z: 3.1, depth: 3.6, width: 13.4, top: 0.55 },
{ z: -0.3, depth: 3.4, width: 12.8, top: 1.45 },
{ z: -4.0, depth: 4.0, width: 12.0, top: 2.45 },
{ z: -7.3, depth: 3.2, width: 10.5, top: 3.55 }
];
for (const terrace of terraces) {
const bottom = -1.05;
const height = terrace.top - bottom;
addBox(
scene,
terrace.width,
height,
terrace.depth,
mats.terrace,
0,
bottom + height / 2,
terrace.z
);
const cap = addBox(
scene,
terrace.width + 0.06,
0.08,
terrace.depth + 0.06,
mats.stone,
0,
terrace.top - 0.025,
terrace.z
);
cap.castShadow = false;
// Sparse horizontal seams keep the retaining walls low-poly but readable.
const seamCount = Math.max(1, Math.floor(height / 0.65));
for (let row = 1; row <= seamCount; row++) {
const y = bottom + (height * row) / (seamCount + 1);
const seam = addBox(
scene,
terrace.width - 0.08,
0.018,
0.025,
mats.stoneDark,
0,
y,
terrace.z + terrace.depth / 2 + 0.012
);
seam.castShadow = false;
}
}
// Front apron at the foot of the neighborhood.
addBox(scene, 14.6, 0.16, 2.3, mats.paving, 0, -0.05, 10.0);
addBox(scene, 3.8, 0.18, 3.1, mats.stoneLight, -4.6, -0.08, 9.0);
// -----------------------------------------------------------------------
// The shared route: every stair and landing shares these exact endpoints.
// -----------------------------------------------------------------------
const route = [
{ a: [-3.0, 0.05, 10.0], b: [-3.0, 0.05, 7.4], type: "flat" },
{ a: [-3.0, 0.05, 7.4], b: [-3.0, 0.70, 5.0], type: "stair" },
{ a: [-3.0, 0.70, 5.0], b: [-0.7, 0.70, 5.0], type: "landing" },
{ a: [-0.7, 0.70, 5.0], b: [2.0, 1.40, 5.0], type: "stair" },
{ a: [2.0, 1.40, 5.0], b: [2.0, 1.40, 2.7], type: "landing" },
{ a: [2.0, 1.40, 2.7], b: [2.0, 1.80, 1.0], type: "stair" },
{ a: [2.0, 1.80, 1.0], b: [4.1, 1.80, 1.0], type: "landing" },
{ a: [4.1, 1.80, 1.0], b: [4.1, 2.55, -1.1], type: "stair" },
{ a: [4.1, 2.55, -1.1], b: [4.1, 2.55, -3.1], type: "landing" },
{ a: [4.1, 2.55, -3.1], b: [1.1, 2.55, -3.1], type: "landing" },
{ a: [1.1, 2.55, -3.1], b: [1.1, 3.30, -4.9], type: "stair" },
{ a: [1.1, 3.30, -4.9], b: [-1.8, 3.30, -4.9], type: "landing" },
{ a: [-1.8, 3.30, -4.9], b: [-1.8, 4.15, -6.8], type: "stair" },
{ a: [-1.8, 4.15, -6.8], b: [-1.8, 4.15, -8.2], type: "landing" }
];
let cumulativeLength = 0;
route.forEach((segment, index) => {
const a = new THREE.Vector3(...segment.a);
const b = new THREE.Vector3(...segment.b);
const horizontalLength = Math.hypot(b.x - a.x, b.z - a.z);
const rise = b.y - a.y;
const length = a.distanceTo(b);
const angle = Math.atan2(b.x - a.x, b.z - a.z);
segment.startDistance = cumulativeLength;
segment.length = length;
segment.horizontalLength = horizontalLength;
segment.rise = rise;
segment.angle = angle;
segment.index = index;
cumulativeLength += length;
const group = new THREE.Group();
group.position.copy(a);
group.rotation.y = angle;
scene.add(group);
if (segment.type === "stair") {
const stepCount = Math.max(3, Math.ceil(Math.abs(rise) / 0.17));
const stepLength = horizontalLength / stepCount;
const riserHeight = rise / stepCount;
for (let step = 0; step < stepCount; step++) {
const top = rise * ((step + 1) / stepCount);
const z = (step + 0.5) * stepLength;
addBox(
group,
1.72,
0.13,
stepLength + 0.035,
mats.stoneLight,
0,
top - 0.065,
z
);
addBox(
group,
1.72,
Math.abs(riserHeight) + 0.025,
0.035,
mats.stone,
0,
top - riserHeight / 2,
step * stepLength
);
}
for (const side of [-0.79, 0.79]) {
addBeamBetween(
group,
[side, -0.14, 0],
[side, rise - 0.14, horizontalLength],
0.15,
0.18,
mats.stoneDark
);
addCylinderBetween(
group,
[side, 0.73, 0],
[side, rise + 0.73, horizontalLength],
0.025,
mats.rail,
7
);
const postCount = Math.max(2, Math.round(stepCount / 2));
for (let post = 0; post <= postCount; post++) {
const t = post / postCount;
const z = t * horizontalLength;
const baseY = rise * t;
addCylinderBetween(
group,
[side, baseY, z],
[side, baseY + 0.74, z],
0.022,
mats.rail,
7
);
}
}
const supportHeight = Math.max(0.25, rise + 0.15);
addBox(
group,
0.52,
supportHeight,
0.52,
mats.stoneDark,
0,
-supportHeight / 2 - 0.03,
horizontalLength * 0.5
);
} else {
addBox(
group,
segment.type === "flat" ? 1.92 : 1.88,
0.17,
horizontalLength + 0.06,
segment.type === "flat" ? mats.paving : mats.stoneLight,
0,
-0.085,
horizontalLength / 2
);
if (horizontalLength > 1.2) {
addBox(
group,
0.68,
0.38,
horizontalLength * 0.72,
mats.stoneDark,
0,
-0.31,
horizontalLength * 0.5
);
}
}
});
const routeLength = cumulativeLength;
function sampleRoute(distance, reverse = false) {
const d = THREE.MathUtils.clamp(distance, 0, routeLength);
for (let i = 0; i < route.length; i++) {
const segment = route[i];
const local = d - segment.startDistance;
if (local <= segment.length || i === route.length - 1) {
const t = THREE.MathUtils.clamp(local / segment.length, 0, 1);
const a = new THREE.Vector3(...segment.a);
const b = new THREE.Vector3(...segment.b);
const position = a.clone().lerp(b, t);
let tangent = b.clone().sub(a).normalize();
// Anticipate the next landing so corners are not approached sideways.
if (t > 0.999 && i < route.length - 1) {
tangent = new THREE.Vector3(...route[i + 1].b)
.sub(new THREE.Vector3(...route[i + 1].a))
.normalize();
}
if (reverse) tangent.multiplyScalar(-1);
return { position, tangent };
}
}
}
// -----------------------------------------------------------------------
// Houses
// -----------------------------------------------------------------------
const facadeColors = [
0xb9c7bb,
0xd7a08d,
0xe0d4b9,
0x9eb9c1,
0xc6b7c9,
0xd3c28e,
0xb8c7c5,
0xc9977d
];
const roofColors = [0x985e4f, 0x4e5b5e, 0x597079, 0x8a6555];
function createGableRoof(width, depth, height, mat) {
const w = width / 2;
const d = depth / 2;
const vertices = new Float32Array([
-w, 0, -d,
w, 0, -d,
0, height, -d,
-w, 0, d,
w, 0, d,
0, height, d
]);
const indices = [
0, 1, 2,
3, 5, 4,
0, 2, 5, 0, 5, 3,
1, 4, 5, 1, 5, 2,
0, 3, 4, 0, 4, 1
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(vertices, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const roofMaterial = mat.clone();
roofMaterial.side = THREE.DoubleSide;
const mesh = new THREE.Mesh(geometry, roofMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function addWindow(group, x, y, z, width = 0.52, height = 0.58, warm = false) {
addBox(group, width + 0.09, height + 0.09, 0.055, mats.trim, x, y, z);
addBox(
group,
width,
height,
0.065,
warm ? mats.warmGlass : mats.glass,
x,
y,
z + 0.012
);
addBox(group, 0.025, height, 0.075, mats.darkTrim, x, y, z + 0.035);
}
function addPottedPlant(group, x, y, z) {
addCylinder(group, 0.13, 0.10, 0.20, mats.pot, x, y + 0.10, z, 7);
addIcosahedron(group, 0.15, mats.leaf, x, y + 0.28, z, 0);
addIcosahedron(group, 0.10, mats.leafLight, x + 0.08, y + 0.36, z, 0);
}
function createHouse(config, index) {
const group = new THREE.Group();
group.position.set(config.x, config.base, config.z);
group.rotation.y = config.yaw ?? 0;
scene.add(group);
const facade = material(facadeColors[index % facadeColors.length]);
const roof = material(roofColors[(index + 1) % roofColors.length]);
const width = config.w;
const depth = config.d;
const height = config.h;
const bodyBottom = 0.16;
const bodyTop = bodyBottom + height;
addBox(group, width + 0.14, 0.18, depth + 0.14, mats.stoneDark, 0, 0.09, 0);
addBox(group, width, height, depth, facade, 0, bodyBottom + height / 2, 0);
// Front door.
addBox(group, 0.61, 1.28, 0.07, mats.darkTrim, 0, 0.80, depth / 2 + 0.025);
addBox(group, 0.49, 1.12, 0.08, material(0x6e6658), 0, 0.77, depth / 2 + 0.06);
addIcosahedron(group, 0.035, mats.trim, 0.16, 0.78, depth / 2 + 0.115, 0);
const frontZ = depth / 2 + 0.045;
addWindow(group, -width * 0.27, bodyTop - 0.68, frontZ, 0.48, 0.55, index % 3 === 0);
addWindow(group, width * 0.27, bodyTop - 0.68, frontZ, 0.48, 0.55, index % 4 === 0);
// A side window makes the varied orientations legible.
addBox(
group,
0.055,
0.56,
0.48,
index % 2 ? mats.glass : mats.warmGlass,
width / 2 + 0.03,
bodyTop - 0.66,
0.08
);
if (config.balcony) {
const balconyY = 1.14;
const balconyZ = depth / 2 + 0.30;
addBox(group, width * 0.72, 0.11, 0.64, mats.trim, 0, balconyY, balconyZ);
addBox(group, width * 0.72, 0.64, 0.055, mats.darkTrim, 0, balconyY + 0.35, balconyZ + 0.29);
for (let rail = -2; rail <= 2; rail++) {
const x = (rail / 2) * width * 0.31;
addCylinderBetween(
group,
[x, balconyY + 0.04, balconyZ + 0.29],
[x, balconyY + 0.68, balconyZ + 0.29],
0.016,
mats.metal,
6
);
}
addBox(group, width * 0.72, 0.025, 0.025, mats.metal, 0, balconyY + 0.66, balconyZ + 0.29);
addPottedPlant(group, -width * 0.24, balconyY + 0.06, balconyZ);
}
if (index % 3 !== 1) {
const roofMesh = createGableRoof(width + 0.34, depth + 0.32, 0.62, roof);
roofMesh.position.y = bodyTop;
group.add(roofMesh);
addBox(group, 0.35, 0.56, 0.38, facade, width * 0.22, bodyTop + 0.28, -0.15);
} else {
addBox(group, width + 0.28, 0.16, depth + 0.28, roof, 0, bodyTop + 0.08, 0);
addBox(group, width + 0.18, 0.16, 0.12, mats.trim, 0, bodyTop + 0.34, depth / 2 + 0.04);
addBox(group, 0.12, 0.16, depth + 0.18, mats.trim, -width / 2 - 0.03, bodyTop + 0.34, 0);
addBox(group, 0.12, 0.16, depth + 0.18, mats.trim, width / 2 + 0.03, bodyTop + 0.34, 0);
}
// Rooftop water tanks are common, compact details rather than set pieces.
if (index % 2 === 0) {
const tankX = -width * 0.21;
const tankZ = -depth * 0.14;
addCylinder(group, 0.27, 0.27, 0.46, mats.trim, tankX, bodyTop + 0.47, tankZ, 8);
const cap = new THREE.Mesh(
new THREE.ConeGeometry(0.29, 0.16, 8),
mats.metal
);
cap.position.set(tankX, bodyTop + 0.78, tankZ);
cap.castShadow = true;
group.add(cap);
}
// External utility box.
if (index % 3 === 0) {
addBox(group, 0.38, 0.43, 0.28, mats.trim, -width / 2 - 0.16, 1.2, 0.18);
for (let vent = -2; vent <= 2; vent++) {
addBox(
group,
0.24,
0.018,
0.015,
mats.darkTrim,
-width / 2 - 0.16,
1.2 + vent * 0.07,
0.327
);
}
}
if (index % 3 === 1) {
addPottedPlant(group, width * 0.36, 0.18, depth / 2 + 0.25);
}
}
const houseConfigs = [
{ x: -6.3, z: 7.25, base: 0.03, w: 2.65, d: 2.15, h: 2.15, yaw: Math.PI / 2, balcony: true },
{ x: 4.75, z: 7.55, base: 0.03, w: 2.75, d: 2.10, h: 2.40, yaw: -Math.PI / 2, balcony: false },
{ x: -6.15, z: 3.25, base: 0.55, w: 2.80, d: 2.20, h: 2.35, yaw: Math.PI / 2, balcony: true },
{ x: 5.65, z: 3.25, base: 0.55, w: 2.55, d: 2.25, h: 2.15, yaw: -Math.PI / 2, balcony: false },
{ x: -6.15, z: -0.25, base: 1.45, w: 2.65, d: 2.10, h: 2.30, yaw: Math.PI / 2, balcony: true },
{ x: 6.10, z: -0.25, base: 1.45, w: 2.70, d: 2.10, h: 2.55, yaw: -Math.PI / 2, balcony: false },
{ x: -6.00, z: -3.75, base: 2.45, w: 2.70, d: 2.10, h: 2.20, yaw: Math.PI / 2, balcony: true },
{ x: 6.05, z: -3.75, base: 2.45, w: 2.55, d: 2.10, h: 2.35, yaw: -Math.PI / 2, balcony: false },
{ x: -5.05, z: -7.35, base: 3.55, w: 2.60, d: 2.00, h: 2.25, yaw: Math.PI / 2, balcony: true },
{ x: 4.55, z: -7.35, base: 3.55, w: 2.75, d: 2.00, h: 2.30, yaw: -Math.PI / 2, balcony: false },
{ x: -0.25, z: 8.35, base: 0.03, w: 2.15, d: 1.75, h: 1.90, yaw: 0, balcony: false },
{ x: 1.15, z: -8.10, base: 3.55, w: 2.05, d: 1.65, h: 1.85, yaw: Math.PI, balcony: false }
];
houseConfigs.forEach(createHouse);
// -----------------------------------------------------------------------
// Utility poles and wires
// -----------------------------------------------------------------------
function createUtilityPole(x, z, base, height) {
addCylinder(scene, 0.065, 0.085, height, mats.metal, x, base + height / 2, z, 7);
addBox(scene, 1.05, 0.08, 0.09, mats.metal, x, base + height - 0.18, z);
addCylinder(scene, 0.075, 0.075, 0.14, mats.trim, x - 0.38, base + height - 0.10, z, 7);
addCylinder(scene, 0.075, 0.075, 0.14, mats.trim, x + 0.38, base + height - 0.10, z, 7);
}
createUtilityPole(-8.0, 6.0, 0.03, 3.6);
createUtilityPole(8.0, 1.5, 0.55, 3.6);
createUtilityPole(-8.0, -2.4, 1.45, 3.8);
createUtilityPole(8.0, -5.6, 2.45, 3.7);
function createWire(points) {
const curve = new THREE.CatmullRomCurve3(points.map(p => new THREE.Vector3(...p)));
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 20, 0.012, 4, false),
mats.darkTrim
);
scene.add(mesh);
}
createWire([
[-8, 3.35, 6],
[-4.8, 3.15, 6.1],
[0, 2.95, 6.05],
[4.8, 2.9, 6],
[8, 3.05, 6]
]);
createWire([
[-8, 4.78, -2.4],
[-3, 4.55, -2.45],
[2.5, 4.35, -2.5],
[8, 4.5, -2.4]
]);
// -----------------------------------------------------------------------
// Original resident and grocery bag
// -----------------------------------------------------------------------
const resident = new THREE.Group();
scene.add(resident);
const bodyRig = new THREE.Group();
resident.add(bodyRig);
// Torso and clothing.
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.245, 0.28, 0.60, 7),
mats.jacket
);
torso.position.y = 1.06;
torso.castShadow = true;
bodyRig.add(torso);
addBox(bodyRig, 0.50, 0.13, 0.31, mats.trousers, 0, 0.77, 0);
addBox(bodyRig, 0.055, 0.50, 0.035, mats.darkTrim, 0, 1.07, 0.245);
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.08, 0.13, 7),
mats.skin
);
neck.position.y = 1.40;
neck.castShadow = true;
bodyRig.add(neck);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.185, 1),
mats.skin
);
head.position.y = 1.60;
head.scale.set(0.92, 1.08, 0.92);
head.castShadow = true;
bodyRig.add(head);
const hair = new THREE.Mesh(
new THREE.SphereGeometry(0.19, 8, 5, 0, Math.PI * 2, 0, Math.PI * 0.52),
mats.hair
);
hair.position.set(0, 1.625, -0.012);
hair.scale.set(0.96, 1.02, 0.96);
hair.castShadow = true;
bodyRig.add(hair);
function createLeg(side) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.14, 0.77, 0);
bodyRig.add(pivot);
const leg = new THREE.Mesh(
new THREE.CylinderGeometry(0.085, 0.075, 0.58, 7),
mats.trousers
);
leg.position.y = -0.29;
leg.castShadow = true;
pivot.add(leg);
addBox(pivot, 0.16, 0.11, 0.28, mats.shoe, 0, -0.60, 0.065);
return pivot;
}
const leftLeg = createLeg(-1);
const rightLeg = createLeg(1);
function createArm(side) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.27, 1.29, 0);
bodyRig.add(pivot);
const sleeve = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.068, 0.37, 7),
mats.jacket
);
sleeve.position.y = -0.18;
sleeve.castShadow = true;
pivot.add(sleeve);
const hand = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.075, 0),
mats.skin
);
hand.position.y = -0.40;
hand.castShadow = true;
pivot.add(hand);
return pivot;
}
const leftArm = createArm(-1);
const rightArm = createArm(1);
// The bag remains attached to the hand; the arm does not swing freely.
const groceryBag = new THREE.Group();
groceryBag.position.set(0, -0.46, 0);
rightArm.add(groceryBag);
addBox(groceryBag, 0.36, 0.40, 0.25, mats.bag, 0, -0.20, 0);
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.105, 0.012, 4, 10, Math.PI),
mats.bag
);
handle.position.y = 0.005;
handle.rotation.z = Math.PI;
handle.castShadow = true;
groceryBag.add(handle);
addIcosahedron(groceryBag, 0.105, mats.vegetable, -0.065, 0.015, 0.015, 0);
addIcosahedron(groceryBag, 0.095, mats.leafLight, 0.075, 0.018, -0.025, 0);
addIcosahedron(groceryBag, 0.075, mats.orange, 0.02, 0.025, 0.065, 0);
// A soft contact mark helps the figure remain readable between stair treads.
const contactShadow = new THREE.Mesh(
new THREE.CircleGeometry(0.29, 16),
new THREE.MeshBasicMaterial({
color: 0x182024,
transparent: true,
opacity: 0.17,
depthWrite: false
})
);
contactShadow.rotation.x = -Math.PI / 2;
contactShadow.position.y = 0.015;
resident.add(contactShadow);
// -----------------------------------------------------------------------
// Resident motion
// -----------------------------------------------------------------------
const walkState = {
progress: 1.4,
mode: "up",
turnTimer: 0,
speed: 1.15,
currentYaw: 0,
paused: false
};
const firstDirection = new THREE.Vector3(...route[1].b)
.sub(new THREE.Vector3(...route[1].a))
.normalize();
const lastDirection = new THREE.Vector3(...route[route.length - 1].b)
.sub(new THREE.Vector3(...route[route.length - 1].a))
.normalize();
function angleToward(current, target, factor) {
const difference = Math.atan2(
Math.sin(target - current),
Math.cos(target - current)
);
return current + difference * factor;
}
function updateResident(delta) {
let moving = false;
if (!walkState.paused) {
if (walkState.mode === "up") {
walkState.progress += walkState.speed * delta;
moving = true;
if (walkState.progress >= routeLength) {
walkState.progress = routeLength;
walkState.mode = "turnDown";
walkState.turnTimer = 1.35;
}
} else if (walkState.mode === "down") {
walkState.progress -= walkState.speed * delta;
moving = true;
if (walkState.progress <= 0) {
walkState.progress = 0;
walkState.mode = "turnUp";
walkState.turnTimer = 1.35;
}
} else {
walkState.turnTimer -= delta;
if (walkState.turnTimer <= 0) {
walkState.mode = walkState.mode === "turnDown" ? "down" : "up";
}
}
}
let sample;
let desiredYaw;
if (walkState.mode === "turnDown") {
sample = sampleRoute(routeLength, false);
desiredYaw = Math.atan2(lastDirection.x, lastDirection.z) + Math.PI;
} else if (walkState.mode === "turnUp") {
sample = sampleRoute(0, false);
desiredYaw = Math.atan2(firstDirection.x, firstDirection.z);
} else {
const reverse = walkState.mode === "down";
sample = sampleRoute(walkState.progress, reverse);
desiredYaw = Math.atan2(sample.tangent.x, sample.tangent.z);
}
const turnFactor = 1 - Math.exp(-delta * 10);
walkState.currentYaw = angleToward(
walkState.currentYaw,
desiredYaw,
turnFactor
);
resident.position.copy(sample.position);
resident.rotation.y = walkState.currentYaw;
const walkedDistance = walkState.mode === "down"
? routeLength - walkState.progress
: walkState.progress;
const phase = walkedDistance * 4.3;
const swing = moving ? Math.sin(phase) * 0.43 : 0;
const oppositeSwing = moving ? Math.sin(phase + Math.PI) * 0.43 : 0;
leftLeg.rotation.x = swing;
rightLeg.rotation.x = oppositeSwing;
leftArm.rotation.x = oppositeSwing * 0.58;
rightArm.rotation.x = -0.07;
rightArm.rotation.z = -0.04;
const bob = moving ? Math.abs(Math.sin(phase)) * 0.018 : 0;
bodyRig.position.y = bob;
bodyRig.rotation.z = moving ? Math.sin(phase) * 0.012 : 0;
groceryBag.rotation.z = moving ? Math.sin(phase) * 0.018 : 0;
}
// -----------------------------------------------------------------------
// Custom orbit camera controls — no addons used
// -----------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 2.05, -1.25),
azimuth: 0.47,
elevation: 0.53,
distance: 24.8
};
const defaultCamera = { ...cameraState };
function updateCamera() {
const horizontal = Math.cos(cameraState.elevation) * cameraState.distance;
const offset = new THREE.Vector3(
Math.sin(cameraState.azimuth) * horizontal,
Math.sin(cameraState.elevation) * cameraState.distance,
Math.cos(cameraState.azimuth) * horizontal
);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.target.copy(defaultCamera.target);
cameraState.azimuth = defaultCamera.azimuth;
cameraState.elevation = defaultCamera.elevation;
cameraState.distance = defaultCamera.distance;
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.azimuth -= dx * 0.0055;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.0042,
0.22,
1.08
);
});
canvas.addEventListener("pointerup", event => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.012,
13,
39
);
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
function togglePause() {
walkState.paused = !walkState.paused;
pauseButton.textContent = walkState.paused ? "Resume walk" : "Pause walk";
}
pauseButton.addEventListener("click", togglePause);
resetButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
togglePause();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// -----------------------------------------------------------------------
// Render loop
// -----------------------------------------------------------------------
updateCamera();
updateResident(0);
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateResident(delta);
updateCamera();
for (const glint of glints) {
glint.position.z += glint.userData.speed * delta;
if (glint.position.z > -10) {
glint.position.z = -74;
glint.position.x = (random() - 0.5) * 92;
}
}
renderer.render(scene, camera);
}
animate();
loading.classList.add("hidden");
</script>
</body>
</html>
```