Prompt specification
Build or customize the Three.js 3D scene "Bukchon roofscape and lane junction scene" 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: Bukchon roofscape and lane junction scene
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bukchon-roofscape-and-lane-junction-scene-x3019
Scene Description Prompt:
Bukchon roofscape and lane junction scene. Build a bounded low-poly slice with referenced roof forms, narrow lanes, and hillside levels. Distinguish public streets from private courtyards through clear gates and boundary walls. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (bukchon-roofscape-and-lane-junction-scene-x3019):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bukchon Roofscape — Low-Poly Study</title>
<style>
:root {
--ink: #282722;
--paper: rgba(244, 239, 226, 0.92);
--accent: #8a4432;
--line: rgba(40, 39, 34, 0.2);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7d2c7;
color: var(--ink);
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;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid var(--line);
box-shadow: 0 10px 30px rgba(49, 43, 31, 0.13);
backdrop-filter: blur(10px);
}
#title-card {
top: 22px;
left: 22px;
width: min(350px, calc(100vw - 44px));
padding: 17px 19px 16px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 6px;
font-size: 10px;
line-height: 1;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
color: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 28px;
line-height: 1.05;
font-weight: 500;
letter-spacing: -0.025em;
}
.subtitle {
margin: 9px 0 0;
max-width: 290px;
font-size: 12px;
line-height: 1.5;
color: rgba(40, 39, 34, 0.68);
}
#legend {
left: 22px;
bottom: 22px;
padding: 13px 15px;
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 6px 0;
font-size: 11px;
font-weight: 650;
}
.swatch {
width: 19px;
height: 10px;
border: 1px solid rgba(0, 0, 0, 0.14);
border-radius: 2px;
}
.swatch.public {
background: #777b73;
}
.swatch.private {
background: #c8b99b;
}
.swatch.roof {
background: #41494b;
}
#controls {
right: 22px;
top: 22px;
display: flex;
gap: 6px;
padding: 6px;
}
button {
appearance: none;
border: 1px solid transparent;
background: transparent;
color: var(--ink);
padding: 9px 11px;
border-radius: 4px;
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 700;
transition: background 150ms ease, border-color 150ms ease;
}
button:hover,
button:focus-visible {
background: rgba(138, 68, 50, 0.09);
border-color: rgba(138, 68, 50, 0.18);
outline: none;
}
#hint {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 9;
padding: 9px 12px;
border-radius: 4px;
background: rgba(35, 34, 30, 0.72);
color: rgba(255, 255, 255, 0.88);
font-size: 10px;
letter-spacing: 0.03em;
pointer-events: none;
}
@media (max-width: 680px) {
#title-card {
top: 12px;
left: 12px;
padding: 13px 15px;
}
h1 {
font-size: 23px;
}
.subtitle {
display: none;
}
#controls {
top: auto;
right: 12px;
bottom: 50px;
}
#legend {
left: 12px;
bottom: 12px;
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly Bukchon roofscape"></canvas>
<section id="title-card" class="panel">
<p class="eyebrow">Architectural landscape study</p>
<h1>Bukchon Roofscape</h1>
<p class="subtitle">
A bounded hillside slice of tiled hanok roofs, stepped public lanes,
and enclosed courtyard homes.
</p>
</section>
<nav id="controls" class="panel" aria-label="Camera views">
<button data-view="overview">Overview</button>
<button data-view="junction">Lane junction</button>
<button data-view="roofs">Upper roofs</button>
</nav>
<aside id="legend" class="panel">
<div class="legend-row">
<span class="swatch public"></span>
<span>Public stone lane</span>
</div>
<div class="legend-row">
<span class="swatch private"></span>
<span>Walled private courtyard</span>
</div>
<div class="legend-row">
<span class="swatch roof"></span>
<span>Traditional gray giwa roof</span>
</div>
</aside>
<div id="hint">Drag to orbit · Wheel to zoom · Shift-drag to pan · Double-click to reset</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 canvas = document.querySelector("#scene");
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.06;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd7d2c7);
scene.fog = new THREE.Fog(0xd7d2c7, 58, 105);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
160
);
const hemi = new THREE.HemisphereLight(0xfff4dc, 0x7d8982, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe4b5, 3.1);
sun.position.set(-22, 34, 20);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -32;
sun.shadow.camera.right = 32;
sun.shadow.camera.top = 32;
sun.shadow.camera.bottom = -32;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 90;
sun.shadow.normalBias = 0.035;
sun.shadow.bias = -0.00012;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc9d8dc, 0.55);
fill.position.set(24, 14, -22);
scene.add(fill);
// ---------------------------------------------------------------------
// Materials
// ---------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
const M = {
base: material(0x746a58),
cutEarth: material(0x887762),
terrace: material(0x9b9d87),
terraceDark: material(0x858a76),
grass: material(0x929b7c),
lane: material(0x626863),
paving: [
material(0x858981),
material(0x96988f),
material(0x777c75),
material(0x8d9088)
],
wall: material(0xc5b697),
wallLight: material(0xd3c5a8),
wallCap: material(0x68675d),
foundation: material(0x777970),
plaster: material(0xe1d4b8),
plasterShade: material(0xcbbda1),
wood: material(0x49372c),
woodLight: material(0x6b4b35),
gate: material(0x763d2d),
roof: [
material(0x3f4749, { side: THREE.DoubleSide }),
material(0x4a5152, { side: THREE.DoubleSide }),
material(0x555b5b, { side: THREE.DoubleSide })
],
roofEdge: material(0x656d6c),
window: material(0x293235),
water: material(0x66827e, { roughness: 0.28 }),
shrub: material(0x687a5b),
shrubLight: material(0x81916d),
tree: material(0x6d7d5e),
trunk: material(0x62503b),
jar: material(0x6f6654),
dark: material(0x343734)
};
// ---------------------------------------------------------------------
// Utility functions
// ---------------------------------------------------------------------
let seed = 82417;
function random() {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
function addBox(parent, w, h, d, x, y, z, mat, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
x,
y,
z,
mat,
radialSegments = 6
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, radialSegments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBeam(parent, from, to, radius, mat) {
const start = new THREE.Vector3(...from);
const end = new THREE.Vector3(...to);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 5),
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 addGroundPlane() {
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(220, 220),
material(0xc9c5ba)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.86;
ground.receiveShadow = true;
scene.add(ground);
}
// ---------------------------------------------------------------------
// Bounded, stepped terrain slice
// ---------------------------------------------------------------------
addGroundPlane();
addBox(scene, 46, 1.8, 46, 0, -0.9, 0, M.base);
addBox(scene, 46.15, 0.18, 46.15, 0, -1.62, 0, M.cutEarth);
// Lower terrace: z = 7 ... 23, top = 0.72
addBox(scene, 44, 0.72, 16, 0, 0.36, 15, M.terraceDark);
addBox(scene, 44, 0.06, 16, 0, 0.74, 15, M.terrace, false);
// Middle terrace: z = -10 ... 7, top = 2.55
addBox(scene, 44, 2.55, 17, 0, 1.275, -1.5, M.terraceDark);
addBox(scene, 44, 0.06, 17, 0, 2.57, -1.5, M.terrace, false);
// Upper terrace: z = -22 ... -10, top = 5.35
addBox(scene, 44, 5.35, 12, 0, 2.675, -16, M.terraceDark);
addBox(scene, 44, 0.06, 12, 0, 5.37, -16, M.terrace, false);
// Exposed cutaway strata on the front and sides.
for (let i = 0; i < 4; i++) {
addBox(
scene,
44.05,
0.055,
0.05,
0,
-1.45 + i * 0.32,
23.025,
M.cutEarth,
false
);
}
function retainingWall(z, lowerY, upperY) {
const blockWidth = 1.35;
for (let x = -21.2; x <= 21.2; x += blockWidth) {
if (Math.abs(x) < 3.0) continue;
const h = upperY - lowerY - 0.12;
const block = addBox(
scene,
blockWidth - 0.07,
h,
0.42,
x,
lowerY + h / 2,
z + 0.12,
random() > 0.5 ? M.foundation : M.wallCap
);
block.rotation.y = (random() - 0.5) * 0.025;
}
}
retainingWall(7, 0.72, 2.55);
retainingWall(-10, 2.55, 5.35);
// Low perimeter walls emphasize the bounded architectural model.
addBox(scene, 0.35, 0.55, 16, -22.1, 1.0, 15, M.wallCap);
addBox(scene, 0.35, 0.55, 16, 22.1, 1.0, 15, M.wallCap);
addBox(scene, 0.35, 2.1, 17, -22.1, 2.0, -1.5, M.wallCap);
addBox(scene, 0.35, 2.1, 17, 22.1, 2.0, -1.5, M.wallCap);
addBox(scene, 0.35, 4.8, 12, -22.1, 4.2, -16, M.wallCap);
addBox(scene, 0.35, 4.8, 12, 22.1, 4.2, -16, M.wallCap);
addBox(scene, 44, 0.48, 0.35, 0, 5.6, -22.1, M.wallCap);
// ---------------------------------------------------------------------
// Public lanes and paver instances
// ---------------------------------------------------------------------
function paveSegment(x1, z1, x2, z2, width, y) {
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const along = Math.max(1, Math.ceil(length / 1.0));
const across = Math.max(1, Math.ceil(width / 1.05));
const tileLength = length / along;
const tileWidth = width / across;
const angle = -Math.atan2(dz, dx);
const geometry = new THREE.BoxGeometry(1, 1, 1);
const mat = material(0xffffff);
const mesh = new THREE.InstancedMesh(
geometry,
mat,
along * across
);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
let index = 0;
for (let i = 0; i < along; i++) {
for (let j = 0; j < across; j++) {
const t = (i + 0.5) / along;
const s = (j + 0.5) / across - 0.5;
const px = x1 + dx * t - Math.sin(angle) * s * tileWidth;
const pz = z1 + dz * t - Math.cos(angle) * s * tileWidth;
dummy.position.set(px, y + 0.055, pz);
dummy.rotation.set(0, angle, 0);
dummy.scale.set(
Math.max(0.04, tileLength - 0.055),
0.09,
Math.max(0.04, tileWidth - 0.055)
);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
color.setHex(
M.paving[Math.floor(random() * M.paving.length)].color.getHex()
);
color.offsetHSL(0, 0, (random() - 0.5) * 0.035);
mesh.setColorAt(index, color);
index++;
}
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.receiveShadow = true;
mesh.computeBoundingSphere();
scene.add(mesh);
}
// Lower public lane: east-west road and southern approach.
addBox(scene, 42, 0.11, 4.6, 0, 0.77, 14, M.lane, false);
addBox(scene, 5.4, 0.11, 5.7, 0, 0.77, 19.15, M.lane, false);
paveSegment(-21, 14, 21, 14, 4.6, 0.82);
paveSegment(0, 16.3, 0, 22, 5.4, 0.82);
// Middle and upper public lanes.
addBox(scene, 4.5, 0.11, 12.5, 0, 2.60, 0.75, M.lane, false);
paveSegment(0, 7, 0, -5.5, 4.5, 2.65);
addBox(scene, 4.2, 0.11, 10, 0, 5.40, -15, M.lane, false);
paveSegment(0, -10, 0, -20, 4.2, 5.45);
function makeStairs(startZ, endZ, width, startY, endY, count) {
const run = Math.abs(endZ - startZ) / count;
const rise = (endY - startY) / count;
for (let i = 0; i < count; i++) {
const z = startZ + Math.sign(endZ - startZ) * (i + 0.5) * run;
const top = startY + (i + 1) * rise;
const bottom = startY - 0.08;
addBox(
scene,
width,
top - bottom,
run + 0.012,
0,
(top + bottom) / 2,
z,
i % 2 ? M.foundation : M.wallCap
);
}
}
makeStairs(11.7, 7, 4.8, 0.72, 2.55, 16);
makeStairs(-5.5, -10, 4.5, 2.55, 5.35, 19);
// Low lane curbs, leaving the stair openings unobstructed.
for (let x = -20; x <= 20; x += 2.6) {
addBox(scene, 1.5, 0.18, 0.22, x, 0.91, 11.52, M.foundation);
addBox(scene, 1.5, 0.18, 0.22, x, 0.91, 16.48, M.foundation);
}
// ---------------------------------------------------------------------
// Traditional low-poly hanok roof
// ---------------------------------------------------------------------
function addGable(parent, x, wallTop, ridgeTop, depth, mat) {
const positions = new Float32Array([
x, wallTop, -depth / 2,
x, wallTop, depth / 2,
x, ridgeTop, 0
]);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setIndex([0, 1, 2]);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: mat.color,
roughness: 0.9,
side: THREE.DoubleSide,
flatShading: true
})
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
}
function addGiwaRoof(parent, width, depth, eaveY, ridgeY) {
const roofWidth = width + 1.15;
const roofDepth = depth + 1.05;
const panels = 8;
const cornerLift = (x) =>
0.16 * Math.pow(Math.abs(x) / (roofWidth / 2), 6);
for (const side of [-1, 1]) {
for (let i = 0; i < panels; i++) {
const x0 = -roofWidth / 2 + (roofWidth * i) / panels;
const x1 = -roofWidth / 2 + (roofWidth * (i + 1)) / panels;
const e0 = eaveY + cornerLift(x0);
const e1 = eaveY + cornerLift(x1);
const r0 = ridgeY + cornerLift(x0) * 0.35;
const r1 = ridgeY + cornerLift(x1) * 0.35;
const positions = new Float32Array([
x0, e0, side * roofDepth / 2,
x1, e1, side * roofDepth / 2,
x1, r1, 0,
x0, r0, 0
]);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
M.roof[(i + (side > 0 ? 1 : 0)) % M.roof.length]
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
}
// Low-poly tile ribs running down the roof slope.
for (let i = 0; i <= panels; i++) {
const x = -roofWidth / 2 + (roofWidth * i) / panels;
const lift = cornerLift(x);
const from = new THREE.Vector3(x, ridgeY + lift * 0.35, 0);
const to = new THREE.Vector3(
x,
eaveY + lift,
side * roofDepth / 2
);
const direction = to.clone().sub(from);
const length = direction.length();
const center = from.clone().add(to).multiplyScalar(0.5);
center.y += 0.035;
const rib = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, length, 4),
M.roofEdge
);
rib.position.copy(center);
rib.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
rib.castShadow = true;
parent.add(rib);
}
}
addBox(
parent,
roofWidth + 0.18,
0.13,
0.15,
0,
ridgeY + 0.07,
0,
M.roofEdge
);
for (const side of [-1, 1]) {
addBox(
parent,
roofWidth + 0.12,
0.14,
0.14,
0,
eaveY + 0.04,
side * roofDepth / 2,
M.roofEdge
);
}
addGable(
parent,
-width / 2,
eaveY - 0.02,
ridgeY - 0.05,
depth,
M.plaster
);
addGable(
parent,
width / 2,
eaveY - 0.02,
ridgeY - 0.05,
depth,
M.plaster
);
for (const x of [-width / 2, width / 2]) {
addBeam(
parent,
[x, eaveY + 0.04, -roofDepth / 2],
[x, ridgeY + 0.03, 0],
0.07,
M.wood
);
addBeam(
parent,
[x, eaveY + 0.04, roofDepth / 2],
[x, ridgeY + 0.03, 0],
0.07,
M.wood
);
}
}
// ---------------------------------------------------------------------
// Hanok building
// ---------------------------------------------------------------------
function addWindow(parent, x, y, z, width = 1.35) {
addBox(
parent,
width,
1.0,
0.08,
x,
y,
z,
M.window
);
addBox(parent, width + 0.12, 0.08, 0.12, x, y + 0.52, z + 0.02, M.wood);
addBox(parent, width + 0.12, 0.08, 0.12, x, y - 0.52, z + 0.02, M.wood);
for (let i = -1; i <= 1; i++) {
addBox(
parent,
0.045,
0.98,
0.055,
x + i * width * 0.28,
y,
z + 0.065,
M.woodLight
);
}
addBox(
parent,
width,
0.045,
0.055,
x,
y,
z + 0.065,
M.woodLight
);
}
function addHouse(parent, x, z, width, depth) {
const house = new THREE.Group();
house.position.set(x, 0, z);
parent.add(house);
const wallHeight = 2.2;
const bodyBottom = 0.36;
const bodyTop = bodyBottom + wallHeight;
addBox(
house,
width + 0.32,
0.36,
depth + 0.32,
0,
0.18,
0,
M.foundation
);
addBox(
house,
width,
wallHeight,
depth,
0,
bodyBottom + wallHeight / 2,
0,
M.plaster
);
// Timber frame.
addBox(house, width + 0.12, 0.13, depth + 0.12, 0, 0.47, 0, M.wood);
addBox(house, width + 0.14, 0.16, depth + 0.14, 0, bodyTop, 0, M.wood);
const columnCount = Math.max(3, Math.round(width / 1.6));
for (let i = 0; i <= columnCount; i++) {
const px = -width / 2 + (width * i) / columnCount;
for (const side of [-1, 1]) {
addBox(
house,
0.13,
wallHeight,
0.13,
px,
bodyBottom + wallHeight / 2,
side * (depth / 2 + 0.04),
M.wood
);
}
}
for (const side of [-1, 1]) {
addBox(
house,
0.13,
wallHeight,
0.13,
side * (width / 2 + 0.03),
bodyBottom + wallHeight / 2,
0,
M.wood
);
}
// Courtyard-facing facade.
addWindow(house, -width * 0.28, 1.48, depth / 2 + 0.09);
addWindow(house, width * 0.28, 1.48, depth / 2 + 0.09);
addBox(
house,
0.8,
1.65,
0.12,
0,
1.18,
depth / 2 + 0.1,
M.woodLight
);
addBox(
house,
0.035,
1.6,
0.035,
0,
1.18,
depth / 2 + 0.17,
M.wood
);
// Rear facade.
addWindow(house, -width * 0.24, 1.48, -depth / 2 - 0.09, 1.15);
addWindow(house, width * 0.24, 1.48, -depth / 2 - 0.09, 1.15);
addGiwaRoof(house, width, depth, bodyTop + 0.10, bodyTop + 1.34);
return house;
}
// ---------------------------------------------------------------------
// Private compounds: courtyard, walls, and obvious gated entrances
// ---------------------------------------------------------------------
function addWallSegment(parent, x, z, length, axis, height = 1.32) {
const w = axis === "x" ? length : 0.30;
const d = axis === "x" ? 0.30 : length;
addBox(parent, w, 0.38, d, x, 0.19, z, M.foundation);
addBox(
parent,
w - 0.02,
height - 0.49,
d - 0.02,
x,
0.38 + (height - 0.49) / 2,
z,
M.wall
);
addBox(
parent,
w + 0.07,
0.11,
d + 0.07,
x,
height + 0.04,
z,
M.wallCap
);
}
function addGate(parent, z, gapWidth) {
for (const side of [-1, 1]) {
addBox(
parent,
0.22,
1.8,
0.25,
side * gapWidth / 2,
0.9,
z,
M.wood
);
addBox(
parent,
0.29,
0.16,
0.31,
side * gapWidth / 2,
1.78,
z,
M.woodLight
);
}
addBox(parent, gapWidth + 0.45, 0.18, 0.22, 0, 1.68, z, M.gate);
addBox(parent, gapWidth + 0.62, 0.15, 0.70, 0, 1.91, z, M.roof[1]);
for (const side of [-1, 1]) {
const leafWidth = gapWidth * 0.40;
const leaf = addBox(
parent,
leafWidth,
1.22,
0.12,
side * gapWidth * 0.22,
0.76,
z,
M.gate
);
leaf.rotation.y = side * 0.23;
for (let i = -1; i <= 1; i++) {
const slat = addBox(
parent,
0.045,
1.15,
0.05,
side * gapWidth * 0.22 + i * leafWidth * 0.27,
0.76,
z + 0.09,
M.woodLight
);
slat.rotation.y = side * 0.23;
}
}
addBox(parent, gapWidth + 0.15, 0.11, 0.55, 0, 0.06, z, M.foundation);
addBox(parent, 0.30, 0.38, 0.07, -gapWidth / 2 - 0.22, 1.12, z + 0.16, M.wallLight);
}
function addShrub(parent, x, z, scale = 1) {
const shrub = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.38 * scale, 0),
random() > 0.5 ? M.shrub : M.shrubLight
);
shrub.position.set(x, 0.31 * scale, z);
shrub.scale.y = 0.78;
shrub.rotation.y = random() * Math.PI;
shrub.castShadow = true;
shrub.receiveShadow = true;
parent.add(shrub);
}
function addCompound({
x,
y,
z,
width = 9,
depth = 7,
angle = 0,
houseWidth = 5.8,
houseDepth = 3.4
}) {
const compound = new THREE.Group();
compound.position.set(x, y, z);
compound.rotation.y = angle;
scene.add(compound);
// Courtyard paving and property plinth.
addBox(
compound,
width - 0.38,
0.12,
depth - 0.38,
0,
0.06,
0,
M.foundation,
false
);
addBox(
compound,
width - 0.72,
0.035,
depth - 0.72,
0,
0.135,
0,
M.wallLight,
false
);
const gateWidth = 1.9;
const frontZ = depth / 2;
const sideLength = depth - 0.2;
addWallSegment(compound, -width / 2 + 0.12, 0, sideLength, "z");
addWallSegment(compound, width / 2 - 0.12, 0, sideLength, "z");
addWallSegment(compound, 0, -depth / 2 + 0.12, width - 0.2, "x");
const frontLength = (width - gateWidth) / 2;
addWallSegment(
compound,
-(gateWidth / 2 + frontLength / 2),
frontZ,
frontLength,
"x"
);
addWallSegment(
compound,
gateWidth / 2 + frontLength / 2,
frontZ,
frontLength,
"x"
);
addGate(compound, frontZ, gateWidth);
const houseZ = -depth * 0.13;
addHouse(compound, 0, houseZ, houseWidth, houseDepth);
// Stepping stones across the private courtyard.
for (let i = 0; i < 4; i++) {
addBox(
compound,
0.72,
0.045,
0.38,
0.05 * Math.sin(i),
0.18,
houseZ + houseDepth / 2 + 0.35 + i * 0.48,
M.foundation,
false
);
}
// Small water vessel and planting.
addCylinder(
compound,
0.27,
0.34,
0.46,
width * 0.29,
0.39,
depth * 0.18,
M.jar,
8
);
addCylinder(
compound,
0.24,
0.24,
0.035,
width * 0.29,
0.63,
depth * 0.18,
M.water,
8
);
addShrub(compound, -width * 0.31, depth * 0.21, 1.0);
addShrub(compound, width * 0.32, depth * 0.29, 0.8);
return compound;
}
// Lower hillside compounds.
addCompound({
x: -11, y: 0.78, z: 8.7,
width: 9, depth: 6, angle: 0,
houseWidth: 5.7, houseDepth: 2.8
});
addCompound({
x: 11, y: 0.78, z: 8.7,
width: 9, depth: 6, angle: 0,
houseWidth: 5.7, houseDepth: 2.8
});
addCompound({
x: -11, y: 0.78, z: 19.5,
width: 9, depth: 6.4, angle: Math.PI,
houseWidth: 5.8, houseDepth: 3.1
});
addCompound({
x: 11, y: 0.78, z: 19.5,
width: 9, depth: 6.4, angle: Math.PI,
houseWidth: 5.8, houseDepth: 3.1
});
// Middle terrace compounds face the uphill public lane.
addCompound({
x: -8, y: 2.61, z: 0.4,
width: 8.6, depth: 7, angle: Math.PI / 2,
houseWidth: 5.6, houseDepth: 3.3
});
addCompound({
x: 8, y: 2.61, z: 0.4,
width: 8.6, depth: 7, angle: -Math.PI / 2,
houseWidth: 5.6, houseDepth: 3.3
});
// Upper terrace compounds.
addCompound({
x: -8, y: 5.41, z: -16,
width: 8.8, depth: 7, angle: Math.PI / 2,
houseWidth: 5.8, houseDepth: 3.5
});
addCompound({
x: 8, y: 5.41, z: -16,
width: 8.8, depth: 7, angle: -Math.PI / 2,
houseWidth: 5.8, houseDepth: 3.5
});
// ---------------------------------------------------------------------
// Trees, stones, lamps, and street details
// ---------------------------------------------------------------------
function addTree(x, y, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, y, z);
tree.scale.setScalar(scale);
scene.add(tree);
addCylinder(tree, 0.10, 0.16, 1.8, 0, 0.9, 0, M.trunk, 6);
const canopy = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.05, 0),
M.tree
);
canopy.position.y = 2.25;
canopy.scale.set(1, 1.18, 0.95);
canopy.castShadow = true;
canopy.receiveShadow = true;
tree.add(canopy);
const canopy2 = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.72, 0),
M.shrubLight
);
canopy2.position.set(0.55, 2.65, 0.10);
canopy2.castShadow = true;
tree.add(canopy2);
}
addTree(-19.5, 0.78, 21.2, 1.0);
addTree(19.5, 0.78, 21.0, 0.9);
addTree(-20, 0.78, 7.8, 0.9);
addTree(20, 0.78, 8.3, 1.0);
addTree(-19.5, 2.61, -8.3, 0.85);
addTree(19.4, 2.61, -8.3, 0.92);
addTree(-19.5, 5.41, -20.4, 0.85);
addTree(19.6, 5.41, -20.4, 0.95);
function addBoulder(x, y, z, scale = 1) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.42 * scale, 0),
M.foundation
);
rock.position.set(x, y + 0.22 * scale, z);
rock.scale.y = 0.65;
rock.rotation.set(random(), random(), random());
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
for (let i = 0; i < 18; i++) {
const side = i % 2 ? -1 : 1;
addBoulder(
side * (20.5 + random() * 1.0),
i < 9 ? 0.78 : 2.61,
-8 + random() * 14,
0.6 + random() * 0.7
);
}
function addStreetLamp(x, y, z) {
const lamp = new THREE.Group();
lamp.position.set(x, y, z);
scene.add(lamp);
addBox(lamp, 0.42, 0.14, 0.42, 0, 0.07, 0, M.foundation);
addBox(lamp, 0.18, 1.25, 0.18, 0, 0.7, 0, M.wood);
addBox(lamp, 0.40, 0.46, 0.40, 0, 1.48, 0, M.wallLight);
addBox(lamp, 0.32, 0.28, 0.32, 0, 1.48, 0, M.window);
addBox(lamp, 0.58, 0.12, 0.58, 0, 1.78, 0, M.roof[1]);
addBox(lamp, 0.12, 0.20, 0.12, 0, 1.92, 0, M.roofEdge);
}
addStreetLamp(3.25, 0.78, 17.7);
addStreetLamp(-3.25, 0.78, 17.7);
addStreetLamp(3.05, 2.61, -4.2);
addStreetLamp(-3.05, 5.41, -18.7);
function makeTextTexture(title, subtitle) {
const c = document.createElement("canvas");
c.width = 640;
c.height = 220;
const ctx = c.getContext("2d");
ctx.fillStyle = "#343936";
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = "#d8d2bf";
ctx.lineWidth = 8;
ctx.strokeRect(12, 12, c.width - 24, c.height - 24);
ctx.fillStyle = "#eee7d5";
ctx.textAlign = "center";
ctx.font = "600 48px sans-serif";
ctx.fillText(title, c.width / 2, 96);
ctx.fillStyle = "#c79b73";
ctx.font = "600 23px sans-serif";
ctx.fillText(subtitle, c.width / 2, 148);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addStreetSign(x, y, z, title, subtitle, rotation = 0) {
const sign = new THREE.Group();
sign.position.set(x, y, z);
sign.rotation.y = rotation;
scene.add(sign);
addBox(sign, 0.12, 2.5, 0.12, -1.05, 1.25, 0, M.wood);
addBox(sign, 0.12, 2.5, 0.12, 1.05, 1.25, 0, M.wood);
addBox(sign, 3.25, 1.12, 0.16, 0, 2.25, 0, M.wood);
const face = new THREE.Mesh(
new THREE.PlaneGeometry(3.05, 0.94),
new THREE.MeshBasicMaterial({
map: makeTextTexture(title, subtitle),
side: THREE.DoubleSide
})
);
face.position.set(0, 2.25, 0.091);
sign.add(face);
}
addStreetSign(
3.65, 0.78, 15.7,
"BUKCHON-GIL",
"PUBLIC LANE / 08",
-0.25
);
addStreetSign(
-3.55, 5.41, -18.8,
"NORTH RIDGE",
"UPPER TERRACE",
0.30
);
// Small public-street bollards emphasize the lane edge.
for (const z of [17.4, 19.0, 20.6]) {
for (const x of [-3.05, 3.05]) {
addCylinder(scene, 0.10, 0.14, 0.48, x, 1.02, z, M.wallCap, 6);
}
}
// ---------------------------------------------------------------------
// Custom camera controls — no Three.js addons
// ---------------------------------------------------------------------
const rig = {
theta: 0.58,
phi: 0.96,
radius: 52,
target: new THREE.Vector3(0, 2.0, 0),
goal: null
};
function applyCamera() {
const sinPhi = Math.sin(rig.phi);
camera.position.set(
rig.target.x + rig.radius * sinPhi * Math.sin(rig.theta),
rig.target.y + rig.radius * Math.cos(rig.phi),
rig.target.z + rig.radius * sinPhi * Math.cos(rig.theta)
);
camera.lookAt(rig.target);
}
function setView(name) {
if (name === "junction") {
rig.goal = {
theta: 0.12,
phi: 1.16,
radius: 29,
target: new THREE.Vector3(0, 2.7, 13.7)
};
} else if (name === "roofs") {
rig.goal = {
theta: 0.76,
phi: 0.72,
radius: 31,
target: new THREE.Vector3(0, 5.2, -15)
};
} else {
rig.goal = {
theta: 0.58,
phi: 0.96,
radius: 52,
target: new THREE.Vector3(0, 2.0, 0)
};
}
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
setView(button.dataset.view);
});
});
const pointers = new Map();
let lastPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button
});
rig.goal = null;
if (pointers.size === 2) {
lastPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: previous.button
});
if (pointers.size === 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
rig.radius *= lastPinchDistance / distance;
rig.radius = THREE.MathUtils.clamp(rig.radius, 15, 78);
}
lastPinchDistance = distance;
return;
}
if (event.shiftKey || previous.button === 2) {
const panScale = rig.radius * 0.0014;
const right = new THREE.Vector3(
Math.cos(rig.theta),
0,
-Math.sin(rig.theta)
);
const forward = new THREE.Vector3(
-Math.sin(rig.theta),
0,
-Math.cos(rig.theta)
);
rig.target.addScaledVector(right, -dx * panScale);
rig.target.addScaledVector(forward, -dy * panScale);
rig.target.x = THREE.MathUtils.clamp(rig.target.x, -18, 18);
rig.target.z = THREE.MathUtils.clamp(rig.target.z, -19, 19);
} else {
rig.theta -= dx * 0.005;
rig.phi = THREE.MathUtils.clamp(
rig.phi - dy * 0.005,
0.32,
1.43
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
rig.goal = null;
rig.radius *= Math.exp(event.deltaY * 0.001);
rig.radius = THREE.MathUtils.clamp(rig.radius, 15, 78);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => setView("overview"));
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function animate() {
requestAnimationFrame(animate);
if (rig.goal) {
const smoothing = 0.075;
rig.theta += (rig.goal.theta - rig.theta) * smoothing;
rig.phi += (rig.goal.phi - rig.phi) * smoothing;
rig.radius += (rig.goal.radius - rig.radius) * smoothing;
rig.target.lerp(rig.goal.target, smoothing);
if (
Math.abs(rig.goal.theta - rig.theta) < 0.001 &&
Math.abs(rig.goal.phi - rig.phi) < 0.001 &&
Math.abs(rig.goal.radius - rig.radius) < 0.01 &&
rig.target.distanceTo(rig.goal.target) < 0.01
) {
rig.goal = null;
}
}
applyCamera();
renderer.render(scene, camera);
}
applyCamera();
animate();
</script>
</body>
</html>
```