Prompt specification
Build or customize the Three.js 3D scene "Trace customer and delivery paths through a shophouse block" 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: Trace customer and delivery paths through a shophouse block
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/trace-customer-and-delivery-paths-through-a-shophouse-x3016
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows George Town's shophouses in Penang. Let users compare routes from street to front shop and rear service area. Preserve residential thresholds and show how narrow plots organize different activities in depth. Low-poly.
Working Three.js Starter (trace-customer-and-delivery-paths-through-a-shophouse-x3016):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>George Town Shophouses — Route Comparison</title>
<style>
:root {
--ink: #17282b;
--muted: #657477;
--paper: #f3efe4;
--panel: rgba(250, 247, 239, 0.94);
--line: rgba(23, 40, 43, 0.16);
--retail: #00aeb9;
--service: #f07845;
--residential: #6f8e72;
--threshold: #d65b45;
--accent: #d2a84c;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
height: 100dvh;
min-height: 640px;
display: grid;
grid-template-rows: auto minmax(300px, 1fr) auto;
}
header {
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 14px 20px;
border-bottom: 1px solid var(--line);
background: rgba(248, 245, 236, 0.96);
}
.brand {
min-width: 0;
}
.eyebrow {
margin-bottom: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(19px, 2.1vw, 29px);
font-weight: 500;
line-height: 1.05;
}
.subtitle {
margin-top: 5px;
color: var(--muted);
font-size: 12px;
}
.view-switch {
display: flex;
flex: 0 0 auto;
gap: 5px;
padding: 4px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.48);
}
.view-switch button,
.layer {
border: 0;
border-radius: 8px;
background: transparent;
cursor: pointer;
transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}
.view-switch button {
padding: 8px 12px;
color: var(--muted);
font-size: 12px;
font-weight: 700;
white-space: nowrap;
}
.view-switch button:hover {
color: var(--ink);
background: rgba(23, 40, 43, 0.06);
}
.view-switch button.active {
color: white;
background: var(--ink);
box-shadow: 0 4px 12px rgba(23, 40, 43, 0.16);
}
#stage {
position: relative;
min-height: 0;
overflow: hidden;
background: #e7e2d7;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.pane-tag {
position: absolute;
z-index: 4;
width: min(290px, calc(50% - 28px));
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 10px;
background: rgba(248, 245, 236, 0.88);
box-shadow: 0 8px 26px rgba(30, 42, 43, 0.09);
backdrop-filter: blur(8px);
pointer-events: none;
}
#paneA {
top: 14px;
left: 14px;
}
#paneB {
top: 14px;
left: calc(50% + 14px);
}
.pane-kicker {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 4px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.route-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--retail);
box-shadow: 0 0 0 3px rgba(0, 174, 185, 0.15);
}
.route-dot.service {
background: var(--service);
box-shadow: 0 0 0 3px rgba(240, 120, 69, 0.16);
}
.pane-title {
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
}
.pane-description {
margin-top: 4px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
#divider {
position: absolute;
z-index: 3;
top: 0;
bottom: 0;
left: 50%;
width: 1px;
background: rgba(23, 40, 43, 0.2);
pointer-events: none;
}
#divider::after {
content: "VS";
position: absolute;
top: 50%;
left: 0;
width: 34px;
height: 34px;
display: grid;
place-items: center;
transform: translate(-50%, -50%);
border: 1px solid var(--line);
border-radius: 50%;
color: var(--muted);
background: var(--paper);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
}
.stage-hint {
position: absolute;
z-index: 4;
right: 12px;
bottom: 10px;
padding: 6px 9px;
border-radius: 7px;
color: rgba(23, 40, 43, 0.65);
background: rgba(248, 245, 236, 0.72);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
pointer-events: none;
}
#loading {
position: absolute;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #e7e2d7;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.08em;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
footer {
z-index: 10;
display: grid;
grid-template-columns: minmax(420px, 1.25fr) minmax(240px, 0.8fr) minmax(200px, 0.55fr);
gap: 18px;
padding: 14px 20px 16px;
border-top: 1px solid var(--line);
background: rgba(248, 245, 236, 0.98);
}
.route-cards {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.route-card {
position: relative;
overflow: hidden;
padding: 10px 12px 10px 15px;
border: 1px solid var(--line);
border-radius: 11px;
text-align: left;
background: rgba(255, 255, 255, 0.56);
cursor: pointer;
transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}
.route-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--retail);
}
.route-card.service::before {
background: var(--service);
}
.route-card:hover {
transform: translateY(-1px);
border-color: rgba(23, 40, 43, 0.32);
}
.route-card.active {
border-color: rgba(23, 40, 43, 0.42);
background: white;
box-shadow: 0 5px 15px rgba(23, 40, 43, 0.07);
}
.route-card strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
}
.route-card small {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.journey,
.layers {
display: flex;
flex-direction: column;
justify-content: center;
}
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#progressValue {
color: var(--ink);
font-variant-numeric: tabular-nums;
}
.progress-row {
display: flex;
align-items: center;
gap: 9px;
}
input[type="range"] {
width: 100%;
accent-color: var(--ink);
cursor: pointer;
}
#replay {
width: 34px;
height: 34px;
flex: 0 0 auto;
border: 1px solid var(--line);
border-radius: 50%;
background: white;
cursor: pointer;
}
#replay:hover {
background: #ece7dc;
}
.layer-row {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.layer {
padding: 7px 9px;
border: 1px solid var(--line);
color: var(--muted);
background: rgba(255, 255, 255, 0.45);
font-size: 10px;
font-weight: 750;
}
.layer.active {
color: white;
border-color: var(--ink);
background: var(--ink);
}
.legend {
display: flex;
gap: 10px;
margin-top: 9px;
color: var(--muted);
font-size: 9px;
}
.legend span {
display: flex;
align-items: center;
gap: 4px;
}
.swatch {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--residential);
}
.swatch.retail {
background: var(--accent);
}
.swatch.service {
background: #5f9fc1;
}
@media (max-width: 900px) {
header {
align-items: flex-start;
flex-direction: column;
gap: 10px;
padding: 12px 14px;
}
.view-switch {
width: 100%;
}
.view-switch button {
flex: 1;
}
footer {
grid-template-columns: 1fr 1fr;
padding: 12px 14px;
}
.route-cards {
grid-column: 1 / -1;
}
}
@media (max-width: 620px) {
#app {
min-height: 720px;
}
.subtitle {
display: none;
}
.pane-tag {
width: calc(100% - 28px);
padding: 8px 10px;
}
#paneA {
left: 14px;
}
#paneB {
top: calc(50% + 14px);
left: 14px;
}
#divider {
top: 50%;
bottom: auto;
left: 0;
width: 100%;
height: 1px;
}
#divider::after {
top: 0;
left: 50%;
transform: translate(-50%, -50%);
}
footer {
grid-template-columns: 1fr;
}
.route-cards {
grid-column: auto;
}
.journey,
.layers {
justify-content: flex-start;
}
.stage-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="eyebrow">Penang · George Town · Spatial Study</div>
<h1>One narrow plot, two layers of access</h1>
<div class="subtitle">A low-poly shophouse section comparing the public retail edge with the deeper service journey.</div>
</div>
<nav class="view-switch" aria-label="View selection">
<button class="active" data-view="compare">Compare</button>
<button data-view="front">Front shop</button>
<button data-view="service">Rear service</button>
</nav>
</header>
<main id="stage">
<canvas id="canvas" aria-label="Interactive low-poly model of George Town shophouses"></canvas>
<div class="pane-tag" id="paneA">
<div class="pane-kicker"><span class="route-dot"></span> Route A · Shallow retail</div>
<div class="pane-title">Street → front shop</div>
<div class="pane-description">Direct access through the five-foot way. The residential threshold is not crossed.</div>
</div>
<div class="pane-tag" id="paneB">
<div class="pane-kicker"><span class="route-dot service"></span> Route B · Deep service</div>
<div class="pane-title">Street → rear service</div>
<div class="pane-description">Passes the controlled residential threshold and keeps the upper dwelling private.</div>
</div>
<div id="divider"></div>
<div class="stage-hint">DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET</div>
<div id="loading">Building the shophouse section…</div>
</main>
<footer>
<div class="route-cards">
<button class="route-card active" data-route="front">
<strong>A — Public retail edge</strong>
<small>Street · five-foot arcade · shop<br />No residential threshold crossing</small>
</button>
<button class="route-card service" data-route="service">
<strong>B — Deep service journey</strong>
<small>Street · shop · controlled threshold · rear court<br />Residential access remains above</small>
</button>
</div>
<div class="journey">
<div class="control-heading">
<span>Journey depth</span>
<span id="progressValue">100%</span>
</div>
<div class="progress-row">
<button id="replay" title="Replay both journeys" aria-label="Replay both journeys">↻</button>
<input id="progress" type="range" min="0" max="100" value="100" aria-label="Journey progress" />
</div>
</div>
<div class="layers">
<div class="control-heading"><span>Section layers</span><span>5.4 × 18 m</span></div>
<div class="layer-row">
<button class="layer active" data-layer="zones" aria-pressed="true">Zones</button>
<button class="layer" data-layer="roof" aria-pressed="false">Roof</button>
<button class="layer active" data-layer="dimensions" aria-pressed="true">Dimensions</button>
</div>
<div class="legend">
<span><i class="swatch retail"></i>Retail</span>
<span><i class="swatch"></i>Residential</span>
<span><i class="swatch service"></i>Service</span>
</div>
</div>
</footer>
</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("#canvas");
const stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7e2d7);
scene.fog = new THREE.Fog(0xe7e2d7, 44, 86);
const cameraFront = new THREE.PerspectiveCamera(43, 1, 0.1, 120);
const cameraService = new THREE.PerspectiveCamera(43, 1, 0.1, 120);
const hemi = new THREE.HemisphereLight(0xfff4dc, 0x667878, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe3b6, 3.1);
sun.position.set(-13, 24, -16);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 30;
sun.shadow.camera.bottom = -30;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d7df, 0.75);
fill.position.set(18, 11, 22);
scene.add(fill);
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...extra
});
const M = {
ground: material(0xded7c5),
road: material(0x536064),
roadStripe: material(0xe9dfbc),
sidewalk: material(0xc9c3b5),
curb: material(0xeee8dc),
drain: material(0x333f42, { metalness: 0.45, roughness: 0.6 }),
concrete: material(0xb8b4a7),
dark: material(0x263437),
window: material(0x233b40, { roughness: 0.36 }),
timber: material(0x704c35),
timberLight: material(0xa77a50),
white: material(0xeee8db),
cream: material(0xdfcfaa),
green: material(0x657d68),
serviceBlue: material(0x759ba6),
metal: material(0x798589, { metalness: 0.42, roughness: 0.62 }),
foliage: material(0x5d7d5c),
foliageLight: material(0x78916a),
trunk: material(0x6c5140)
};
function box(parent, w, h, d, mat, x = 0, y = 0, z = 0, 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 cylinder(parent, rt, rb, h, mat, x = 0, y = 0, z = 0, sides = 8) {
const mesh = new THREE.Mesh(new THREE.CylinderGeometry(rt, rb, h, sides), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeCanvasTexture(draw, width = 1024, height = 256) {
const c = document.createElement("canvas");
c.width = width;
c.height = height;
draw(c.getContext("2d"), width, height);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeSign(text, subtitle, background, foreground, width = 3.4, height = 0.72) {
const texture = makeCanvasTexture((ctx, w, h) => {
ctx.fillStyle = background;
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = foreground;
ctx.globalAlpha = 0.5;
ctx.lineWidth = 8;
ctx.strokeRect(13, 13, w - 26, h - 26);
ctx.globalAlpha = 1;
ctx.textAlign = "center";
ctx.fillStyle = foreground;
ctx.font = "700 76px Georgia";
ctx.fillText(text, w / 2, 116);
ctx.font = "700 25px sans-serif";
ctx.letterSpacing = "5px";
ctx.fillText(subtitle, w / 2, 176);
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({ map: texture, side: THREE.DoubleSide })
);
mesh.rotation.y = Math.PI;
return mesh;
}
function makeWorldLabel(text, accent = "#d2a84c", worldWidth = 3.7) {
const texture = makeCanvasTexture((ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = "rgba(20, 32, 34, 0.90)";
ctx.beginPath();
ctx.roundRect(3, 3, w - 6, h - 6, 18);
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 6;
ctx.stroke();
ctx.fillStyle = "#fffaf0";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "700 37px sans-serif";
ctx.fillText(text, w / 2, h / 2 + 1);
}, 768, 128);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(worldWidth, worldWidth / 6, 1);
sprite.renderOrder = 30;
return sprite;
}
function addLine(parent, points, color, opacity = 1) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({ color, transparent: opacity < 1, opacity })
);
parent.add(line);
return line;
}
// Urban ground and service lane.
box(scene, 48, 0.16, 56, M.ground, 0, -0.24, 9, false);
box(scene, 46, 0.12, 8.4, M.road, 0, -0.09, -6.8, false);
box(scene, 46, 0.16, 3.5, M.sidewalk, 0, -0.02, -1.25, false);
box(scene, 46, 0.12, 5.0, M.road, 0, -0.10, 20.1, false);
box(scene, 46, 0.24, 0.25, M.curb, 0, 0.02, -3.02, false);
box(scene, 46, 0.20, 0.20, M.curb, 0, -0.02, 17.55, false);
for (let x = -20; x <= 20; x += 5) {
box(scene, 2.4, 0.025, 0.13, M.roadStripe, x, -0.015, -7.25, false);
}
for (const x of [-12, 12]) {
box(scene, 1.5, 0.035, 0.42, M.drain, x, 0.065, -2.77, false);
}
// Plot edges emphasize the narrow, deep terrace.
const plotEdge = material(0xb8ad96);
for (const x of [-9, -3, 3, 9]) {
box(scene, 0.12, 0.15, 18.3, plotEdge, x, 0.01, 9, false);
}
const roofGroup = new THREE.Group();
const zoneGroup = new THREE.Group();
const dimensionGroup = new THREE.Group();
const frontLabels = new THREE.Group();
const serviceLabels = new THREE.Group();
const thresholdGroup = new THREE.Group();
scene.add(roofGroup, zoneGroup, dimensionGroup, frontLabels, serviceLabels, thresholdGroup);
function addFacade(parent, facadeMat, detailed = false) {
// Five-foot covered way.
box(parent, 5.55, 0.16, 1.95, M.cream, 0, 3.18, -0.95);
box(parent, 0.48, 3.10, 0.48, facadeMat, -2.38, 1.55, -1.37);
box(parent, 0.48, 3.10, 0.48, facadeMat, 2.38, 1.55, -1.37);
// Lower frontage.
box(parent, 0.52, 3.08, 0.42, facadeMat, -2.40, 1.54, 0);
box(parent, 0.52, 3.08, 0.42, facadeMat, 2.40, 1.54, 0);
box(parent, 5.30, 0.42, 0.42, facadeMat, 0, 2.94, 0);
if (detailed) {
// Open central doorway with timber shutters folded to the sides.
box(parent, 1.62, 2.45, 0.10, M.timber, -1.75, 1.26, -0.25);
box(parent, 1.62, 2.45, 0.10, M.timber, 1.75, 1.26, -0.25);
box(parent, 0.86, 2.58, 0.08, M.dark, 0, 1.30, -0.22);
box(parent, 1.05, 0.12, 0.12, M.timberLight, 0, 2.64, -0.30);
} else {
box(parent, 3.72, 2.55, 0.10, M.timber, 0, 1.30, -0.23);
for (let y = 0.3; y < 2.55; y += 0.25) {
box(parent, 3.60, 0.055, 0.04, M.timberLight, 0, y, -0.30);
}
}
// Upper plastered storeys.
box(parent, 5.30, 3.45, 0.32, facadeMat, 0, 4.90, 0);
const windowXs = [-1.28, 1.28];
const windowYs = [4.25, 5.70];
for (const x of windowXs) {
for (const y of windowYs) {
box(parent, 1.02, 1.12, 0.10, M.window, x, y, -0.20);
for (const side of [-1, 1]) {
const shutterX = x + side * 0.78;
for (let k = 0; k < 6; k++) {
box(
parent,
0.38,
0.085,
0.075,
M.timberLight,
shutterX,
y - 0.46 + k * 0.185,
-0.235
);
}
}
box(parent, 1.18, 0.09, 0.28, M.cream, x, y - 0.61, -0.23);
}
}
// Decorative string courses.
box(parent, 5.45, 0.13, 0.43, M.cream, 0, 3.23, 0);
box(parent, 5.45, 0.14, 0.43, M.cream, 0, 6.66, 0);
}
function addRoof(x, roofMat) {
const g = new THREE.Group();
g.position.x = x;
const angle = Math.atan2(1.35, 2.75);
const slopeLength = Math.sqrt(2.75 * 2.75 + 1.35 * 1.35);
const left = box(g, slopeLength, 0.16, 18.45, roofMat, -1.36, 7.72, 9);
left.rotation.z = angle;
const right = box(g, slopeLength, 0.16, 18.45, roofMat, 1.36, 7.72, 9);
right.rotation.z = -angle;
box(g, 0.23, 0.22, 18.55, M.timber, 0, 8.41, 9);
roofGroup.add(g);
}
function buildOuterShophouse(x, color, name, subtitle, roofColor) {
const g = new THREE.Group();
g.position.x = x;
scene.add(g);
const facadeMat = material(color);
addFacade(g, facadeMat, false);
box(g, 5.20, 0.18, 18.0, M.concrete, 0, 0.02, 9, false);
const sign = makeSign(name, subtitle, "#244a47", "#f4e7c4", 3.3, 0.62);
sign.position.set(0, 2.68, -0.31);
g.add(sign);
addRoof(x, material(roofColor));
return g;
}
buildOuterShophouse(-6, 0xc78c75, "SENG HONG", "TEA MERCHANT · EST. 1932", 0x9f5f4d);
buildOuterShophouse(6, 0x789a91, "KEDAI KOPI", "COFFEE · RUNCIT · FRIED FOOD", 0x9f5f4d);
// Central, fully sectioned shophouse.
const house = new THREE.Group();
scene.add(house);
const facadeMat = material(0xd19a77);
addFacade(house, facadeMat, true);
box(house, 5.20, 0.18, 18.0, M.concrete, 0, 0.02, 9, false);
const centralSign = makeSign(
"HABU COFFEE",
"KEDAI KOPI · RUNCIT · LIMITS",
"#24433f",
"#f4e5bd",
3.55,
0.70
);
centralSign.position.set(0, 2.62, -0.32);
house.add(centralSign);
addRoof(0, material(0x9f5f4d));
// Party wall is retained on the far side; the near side is cut away.
box(house, 0.22, 3.25, 18.0, material(0xb8ad96), -2.64, 1.62, 9);
box(house, 5.22, 2.85, 0.22, material(0xa69b87), 0, 1.43, 17.92);
box(house, 0.18, 0.52, 18.0, material(0xb8ad96), 2.65, 0.26, 9);
// Retail floor: counter, tables and hanging fixtures.
box(house, 1.15, 0.95, 2.75, M.timber, 1.57, 0.49, 2.65);
box(house, 1.28, 0.11, 2.88, M.timberLight, 1.57, 1.01, 2.65);
for (const z of [2.0, 4.4]) {
cylinder(house, 0.07, 0.07, 0.72, M.metal, -1.15, 0.38, z);
cylinder(house, 0.64, 0.64, 0.09, M.timberLight, -1.15, 0.78, z, 10);
cylinder(house, 0.22, 0.29, 0.34, material(0x9a5f45), -1.15, 0.22, z);
}
for (const x of [-1.6, 0, 1.6]) {
cylinder(house, 0.025, 0.025, 0.64, M.dark, x, 2.74, 2.4, 6);
cylinder(house, 0.19, 0.10, 0.18, M.cream, x, 2.42, 2.4, 8);
}
// Controlled residential / private threshold at the rear of the shop.
box(house, 0.62, 2.75, 0.22, material(0xb5a990), -2.30, 1.38, 6.35);
box(house, 3.78, 2.75, 0.22, material(0xb5a990), 0.77, 1.38, 6.35);
box(house, 1.34, 0.54, 0.22, material(0xb5a990), -1.34, 2.48, 6.35);
// Door leaf held open toward the private lobby.
const door = box(house, 0.10, 2.35, 1.25, M.timber, -1.98, 1.19, 6.93);
door.rotation.y = -0.12;
const privateSign = makeSign(
"PRIVATE",
"RESIDENTIAL + SERVICE",
"#783d32",
"#f7e6c9",
1.22,
0.46
);
privateSign.position.set(-1.34, 2.49, 6.21);
house.add(privateSign);
// Stair rises behind the threshold, separate from the lower service passage.
for (let i = 0; i < 12; i++) {
const h = (i + 1) * 0.25;
box(
house,
1.05,
h,
0.31,
M.timberLight,
1.72,
h / 2,
6.73 + i * 0.31
);
}
box(house, 1.12, 0.12, 1.05, M.timber, 1.72, 3.06, 10.37);
// Partial upper residential floor, cut open for legibility.
const upperFloorMat = material(0xc6bda8, { transparent: true, opacity: 0.86 });
box(house, 1.50, 0.16, 13.20, upperFloorMat, -1.84, 3.34, 9.20, false);
box(house, 5.20, 0.16, 3.90, upperFloorMat, 0, 3.34, 15.35, false);
// Upper dwelling: bed, bath partition and kitchen.
box(house, 1.10, 0.38, 2.05, M.timber, -1.77, 3.60, 8.25);
box(house, 1.02, 0.20, 1.92, M.white, -1.77, 3.88, 8.25);
box(house, 0.95, 0.12, 0.48, M.cream, -1.77, 4.02, 7.42);
box(house, 0.12, 2.25, 2.25, material(0xb9c4bd), -0.55, 4.62, 6.35);
box(house, 1.95, 0.88, 0.75, M.timberLight, 1.35, 3.86, 14.15);
box(house, 1.98, 0.10, 0.80, M.white, 1.35, 4.34, 14.15);
cylinder(house, 0.08, 0.08, 0.30, M.metal, 1.35, 4.50, 14.15);
// Rear service court.
box(house, 1.18, 0.82, 0.78, M.serviceBlue, -1.68, 0.41, 16.58);
box(house, 1.18, 0.82, 0.78, M.green, 1.68, 0.41, 16.58);
box(house, 0.92, 0.62, 0.85, material(0xb36f4f), 0.75, 0.31, 15.65);
box(house, 1.25, 0.16, 0.74, M.metal, -1.15, 0.90, 12.10);
// Sink and utility bench.
box(house, 1.70, 0.13, 0.76, M.metal, 1.48, 0.94, 11.80);
box(house, 0.72, 0.38, 0.58, M.metal, 1.28, 0.72, 11.80);
cylinder(house, 0.035, 0.035, 0.55, M.metal, 1.55, 1.22, 11.56, 6);
// Air-conditioning condenser.
box(house, 0.82, 0.58, 0.40, M.metal, -2.18, 1.15, 15.85);
cylinder(house, 0.22, 0.22, 0.06, M.dark, -2.18, 1.15, 15.62, 12);
// Rear lane and neighboring service details.
box(scene, 0.75, 0.95, 0.78, M.serviceBlue, -5.8, 0.48, 18.6);
box(scene, 0.75, 0.95, 0.78, M.green, -4.8, 0.48, 18.7);
box(scene, 1.05, 0.65, 0.85, material(0xa56b4f), 5.4, 0.33, 18.9);
box(scene, 0.85, 0.55, 0.65, M.metal, 7.0, 0.28, 18.8);
// Low-poly street trees.
function addTree(x, z) {
const g = new THREE.Group();
cylinder(g, 0.16, 0.22, 1.8, M.trunk, 0, 0.9, 0, 7);
const crown = new THREE.Mesh(new THREE.IcosahedronGeometry(1.35, 0), M.foliage);
crown.position.y = 2.65;
crown.scale.set(1, 1.18, 0.9);
crown.castShadow = true;
g.add(crown);
const crown2 = new THREE.Mesh(new THREE.DodecahedronGeometry(0.78, 0), M.foliageLight);
crown2.position.set(0.55, 3.05, 0.15);
crown2.castShadow = true;
g.add(crown2);
g.position.set(x, 0, z);
scene.add(g);
}
addTree(-10.4, -2.1);
addTree(10.7, -2.0);
addTree(-12.2, 19.0);
addTree(11.5, 19.2);
// Simple human-scale figures.
function addPerson(x, z, color, rotation = 0) {
const g = new THREE.Group();
const clothes = material(color);
cylinder(g, 0.16, 0.22, 0.62, clothes, 0, 0.76, 0, 6);
const head = new THREE.Mesh(new THREE.SphereGeometry(0.15, 7, 5), material(0xb77d5c));
head.position.y = 1.20;
head.castShadow = true;
g.add(head);
box(g, 0.12, 0.50, 0.14, M.dark, -0.10, 0.28, 0);
box(g, 0.12, 0.50, 0.14, M.dark, 0.10, 0.28, 0);
g.position.set(x, 0, z);
g.rotation.y = rotation;
scene.add(g);
}
addPerson(-3.55, -2.15, 0x2e6d70, 0.2);
addPerson(2.85, 18.4, 0xb56c4e, -0.4);
// Colored floor zones reveal the sequence of activities in depth.
function addZone(w, d, x, y, z, color, opacity) {
const mat = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false,
side: THREE.DoubleSide
});
const plane = new THREE.Mesh(new THREE.PlaneGeometry(w, d), mat);
plane.rotation.x = -Math.PI / 2;
plane.position.set(x, y, z);
zoneGroup.add(plane);
}
addZone(4.95, 5.75, 0, 0.145, 3.15, 0xd2a84c, 0.28);
addZone(4.95, 12.1, 0, 3.445, 9.45, 0x6f8e72, 0.22);
addZone(4.95, 6.0, 0, 0.145, 14.3, 0x5f9fc1, 0.25);
addZone(1.25, 1.30, -1.34, 0.16, 6.52, 0xd65b45, 0.58);
// Threshold emphasis remains visible in every view.
const thresholdFrameMat = new THREE.MeshBasicMaterial({
color: 0xd65b45,
transparent: true,
opacity: 0.9,
depthTest: false
});
box(thresholdGroup, 0.08, 2.45, 0.08, thresholdFrameMat, -1.99, 1.23, 6.22);
box(thresholdGroup, 0.08, 2.45, 0.08, thresholdFrameMat, -0.69, 1.23, 6.22);
box(thresholdGroup, 1.38, 0.08, 0.08, thresholdFrameMat, -1.34, 2.45, 6.22);
const thresholdRing = new THREE.Mesh(
new THREE.TorusGeometry(0.36, 0.035, 6, 30),
new THREE.MeshBasicMaterial({
color: 0xf18b66,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
thresholdRing.rotation.y = Math.PI / 2;
thresholdRing.position.set(-1.34, 1.25, 6.18);
thresholdRing.renderOrder = 28;
thresholdGroup.add(thresholdRing);
// Depth ruler and plot-width annotation.
addLine(dimensionGroup, [
new THREE.Vector3(3.55, 0.24, 0),
new THREE.Vector3(3.55, 0.24, 18)
], 0x43575a, 0.8);
for (let z = 0; z <= 18; z += 3) {
addLine(dimensionGroup, [
new THREE.Vector3(3.28, 0.24, z),
new THREE.Vector3(3.82, 0.24, z)
], 0x43575a, 0.9);
}
const depthTexts = [
["0 m · STREET", 0],
["6 m · SHOP EDGE", 6],
["12 m · PRIVATE", 12],
["18 m · SERVICE", 18]
];
for (const [text, z] of depthTexts) {
const label = makeWorldLabel(text, "#d2a84c", 2.9);
label.position.set(4.35, 0.48, z);
dimensionGroup.add(label);
}
addLine(dimensionGroup, [
new THREE.Vector3(-2.65, 0.24, -2.72),
new THREE.Vector3(2.65, 0.24, -2.72)
], 0x43575a, 0.85);
for (const x of [-2.65, 2.65]) {
addLine(dimensionGroup, [
new THREE.Vector3(x, 0.24, -2.94),
new THREE.Vector3(x, 0.24, -2.50)
], 0x43575a, 0.85);
}
const widthLabel = makeWorldLabel("5.4 m · NARROW PLOT", "#d2a84c", 3.5);
widthLabel.position.set(0, 0.48, -3.18);
dimensionGroup.add(widthLabel);
// Spatial labels are separated by route so the comparison stays legible.
const streetLabel = makeWorldLabel("STREET", "#f3e7c9", 2.15);
streetLabel.position.set(-2.3, 0.65, -7.2);
frontLabels.add(streetLabel);
const arcadeLabel = makeWorldLabel("5-FOOT ARCADE", "#f3e7c9", 3.2);
arcadeLabel.position.set(0.8, 3.65, -0.9);
frontLabels.add(arcadeLabel);
const shopLabel = makeWorldLabel("FRONT SHOP", "#00aeb9", 2.75);
shopLabel.position.set(0, 1.85, 3.2);
frontLabels.add(shopLabel);
const serviceStreet = makeWorldLabel("REAR LANE", "#f3e7c9", 2.25);
serviceStreet.position.set(2.5, 0.65, 19.4);
serviceLabels.add(serviceStreet);
const thresholdLabel = makeWorldLabel("RESIDENTIAL THRESHOLD", "#d65b45", 4.7);
thresholdLabel.position.set(-1.34, 3.35, 6.35);
serviceLabels.add(thresholdLabel);
const aboveLabel = makeWorldLabel("RESIDENTIAL ABOVE", "#6f8e72", 3.9);
aboveLabel.position.set(0.3, 6.25, 10.1);
serviceLabels.add(aboveLabel);
const rearServiceLabel = makeWorldLabel("REAR SERVICE", "#5f9fc1", 3.1);
rearServiceLabel.position.set(0, 1.85, 14.4);
serviceLabels.add(rearServiceLabel);
// Route paths.
const routeAPoints = [
new THREE.Vector3(0, 0.34, -6.3),
new THREE.Vector3(0, 0.34, -1.35),
new THREE.Vector3(0, 0.34, 0.55),
new THREE.Vector3(0, 0.34, 3.45)
];
const routeBPoints = [
new THREE.Vector3(0, 0.34, -6.3),
new THREE.Vector3(0, 0.34, -1.35),
new THREE.Vector3(0, 0.34, 0.55),
new THREE.Vector3(0, 0.34, 4.55),
new THREE.Vector3(-1.34, 0.34, 6.25),
new THREE.Vector3(-1.34, 0.34, 8.65),
new THREE.Vector3(0, 0.34, 11.25),
new THREE.Vector3(0, 0.34, 14.55)
];
function makeRoute(points, color) {
const group = new THREE.Group();
const curve = new THREE.CurvePath();
for (let i = 0; i < points.length - 1; i++) {
curve.add(new THREE.LineCurve3(points[i], points[i + 1]));
}
const geometry = new THREE.TubeGeometry(curve, 140, 0.055, 7, false);
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.98,
depthTest: false,
depthWrite: false
})
);
mesh.renderOrder = 25;
group.add(mesh);
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.16, 10, 7),
new THREE.MeshBasicMaterial({ color, depthTest: false })
);
marker.renderOrder = 29;
group.add(marker);
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
total += length;
}
scene.add(group);
return { group, geometry, marker, points, lengths, total };
}
const routeA = makeRoute(routeAPoints, 0x00aeb9);
const routeB = makeRoute(routeBPoints, 0xf07845);
function pointAlongRoute(route, t) {
let remaining = THREE.MathUtils.clamp(t, 0, 1) * route.total;
for (let i = 0; i < route.lengths.length; i++) {
if (remaining <= route.lengths[i] || i === route.lengths.length - 1) {
const localT = remaining / route.lengths[i];
return route.points[i].clone().lerp(route.points[i + 1], localT);
}
remaining -= route.lengths[i];
}
return route.points.at(-1).clone();
}
let progress = 1;
let playing = false;
function updateRoute(route) {
const indexCount = route.geometry.index
? route.geometry.index.count
: route.geometry.attributes.position.count;
const drawCount = Math.floor(indexCount * progress / 3) * 3;
route.geometry.setDrawRange(0, drawCount);
route.marker.position.copy(pointAlongRoute(route, progress));
route.marker.position.y += 0.04;
}
// Direct camera controls: no examples/addons are used.
function cameraState(position, target) {
const offset = position.clone().sub(target);
return {
target: target.clone(),
radius: offset.length(),
theta: Math.atan2(offset.x, offset.z),
phi: Math.acos(THREE.MathUtils.clamp(offset.y / offset.length(), -1, 1))
};
}
const controls = {
front: cameraState(
new THREE.Vector3(9.4, 7.1, -16.4),
new THREE.Vector3(0, 1.65, 1.55)
),
service: cameraState(
new THREE.Vector3(20.0, 15.8, -10.0),
new THREE.Vector3(0, 2.0, 7.35)
)
};
function applyCamera(camera, state) {
const sinPhi = Math.sin(state.phi);
const offset = new THREE.Vector3(
state.radius * sinPhi * Math.sin(state.theta),
state.radius * Math.cos(state.phi),
state.radius * sinPhi * Math.cos(state.theta)
);
camera.position.copy(state.target).add(offset);
camera.lookAt(state.target);
}
let viewMode = "compare";
let drag = null;
function paneAt(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
const x = clientX - rect.left;
const y = clientY - rect.top;
if (viewMode === "front") return "front";
if (viewMode === "service") return "service";
if (rect.width < 620) {
return y < rect.height / 2 ? "front" : "service";
}
return x < rect.width / 2 ? "front" : "service";
}
canvas.addEventListener("pointerdown", (event) => {
const pane = paneAt(event.clientX, event.clientY);
drag = {
pane,
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY
};
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!drag || drag.pointerId !== event.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
const state = controls[drag.pane];
state.theta -= dx * 0.006;
state.phi = THREE.MathUtils.clamp(state.phi - dy * 0.005, 0.22, 1.46);
state.radius = THREE.MathUtils.clamp(state.radius, 7, 48);
drag.x = event.clientX;
drag.y = event.clientY;
});
function endDrag(event) {
if (!drag || event.pointerId !== drag.pointerId) return;
drag = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const pane = paneAt(event.clientX, event.clientY);
const state = controls[pane];
state.radius = THREE.MathUtils.clamp(
state.radius * Math.exp(event.deltaY * 0.001),
7,
48
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", (event) => {
const pane = paneAt(event.clientX, event.clientY);
if (pane === "front") {
controls.front = cameraState(
new THREE.Vector3(9.4, 7.1, -16.4),
new THREE.Vector3(0, 1.65, 1.55)
);
} else {
controls.service = cameraState(
new THREE.Vector3(20.0, 15.8, -10.0),
new THREE.Vector3(0, 2.0, 7.35)
);
}
});
// UI state.
const viewButtons = [...document.querySelectorAll("[data-view]")];
const routeCards = [...document.querySelectorAll("[data-route]")];
const paneA = document.querySelector("#paneA");
const paneB = document.querySelector("#paneB");
const divider = document.querySelector("#divider");
const progressInput = document.querySelector("#progress");
const progressValue = document.querySelector("#progressValue");
function setView(mode) {
viewMode = mode;
for (const button of viewButtons) {
button.classList.toggle("active", button.dataset.view === mode);
}
for (const card of routeCards) {
card.classList.toggle(
"active",
mode === "compare" || card.dataset.route === mode
);
}
const compare = mode === "compare";
paneA.style.display = mode === "service" ? "none" : "block";
paneB.style.display = mode === "front" ? "none" : "block";
divider.style.display = compare ? "block" : "none";
if (mode === "front") {
paneA.style.left = "14px";
paneA.style.top = "14px";
paneA.style.width = "min(290px, calc(100% - 28px))";
} else if (mode === "service") {
paneB.style.left = "14px";
paneB.style.top = "14px";
paneB.style.width = "min(290px, calc(100% - 28px))";
}
}
for (const button of viewButtons) {
button.addEventListener("click", () => setView(button.dataset.view));
}
for (const card of routeCards) {
card.addEventListener("click", () => setView(card.dataset.route));
}
progressInput.addEventListener("input", () => {
playing = false;
progress = Number(progressInput.value) / 100;
progressValue.textContent = `${Math.round(progress * 100)}%`;
});
document.querySelector("#replay").addEventListener("click", () => {
progress = 0;
playing = true;
progressInput.value = "0";
progressValue.textContent = "0%";
});
for (const button of document.querySelectorAll("[data-layer]")) {
button.addEventListener("click", () => {
const layer = button.dataset.layer;
let visible;
if (layer === "zones") {
zoneGroup.visible = !zoneGroup.visible;
visible = zoneGroup.visible;
} else if (layer === "roof") {
roofGroup.visible = !roofGroup.visible;
visible = roofGroup.visible;
} else {
dimensionGroup.visible = !dimensionGroup.visible;
visible = dimensionGroup.visible;
}
button.classList.toggle("active", visible);
button.setAttribute("aria-pressed", String(visible));
});
}
// Responsive split rendering with scissor rectangles.
let stageWidth = 1;
let stageHeight = 1;
function resize() {
stageWidth = Math.max(1, stage.clientWidth);
stageHeight = Math.max(1, stage.clientHeight);
renderer.setSize(stageWidth, stageHeight, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
function renderPane(name, x, y, width, height) {
const camera = name === "front" ? cameraFront : cameraService;
const state = controls[name];
camera.aspect = width / height;
camera.updateProjectionMatrix();
applyCamera(camera, state);
routeA.group.visible = name === "front";
routeB.group.visible = name === "service";
frontLabels.visible = name === "front";
serviceLabels.visible = name === "service";
renderer.setViewport(x, y, width, height);
renderer.setScissor(x, y, width, height);
renderer.render(scene, camera);
}
function renderScene() {
renderer.setScissorTest(true);
if (viewMode === "compare") {
if (stageWidth < 620) {
const half = Math.floor(stageHeight / 2);
renderPane("front", 0, half, stageWidth, stageHeight - half);
renderPane("service", 0, 0, stageWidth, half);
} else {
const half = Math.floor(stageWidth / 2);
renderPane("front", 0, 0, half, stageHeight);
renderPane("service", half, 0, stageWidth - half, stageHeight);
}
} else if (viewMode === "front") {
renderPane("front", 0, 0, stageWidth, stageHeight);
} else {
renderPane("service", 0, 0, stageWidth, stageHeight);
}
renderer.setScissorTest(false);
}
let lastTime = performance.now();
function animate(now) {
const dt = Math.min(0.05, (now - lastTime) / 1000);
lastTime = now;
if (playing) {
progress = Math.min(1, progress + dt / 7.5);
progressInput.value = String(Math.round(progress * 100));
progressValue.textContent = `${Math.round(progress * 100)}%`;
if (progress >= 1) playing = false;
}
updateRoute(routeA);
updateRoute(routeB);
const pulse = 1 + Math.sin(now * 0.0032) * 0.055;
thresholdRing.scale.setScalar(pulse);
routeA.marker.scale.setScalar(1 + Math.sin(now * 0.004) * 0.08);
routeB.marker.scale.setScalar(1 + Math.sin(now * 0.004 + 1.5) * 0.08);
renderScene();
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
setTimeout(() => loading.classList.add("hidden"), 350);
</script>
</body>
</html>
```