Prompt specification
Build or customize the Three.js 3D scene "Hutong lane with two connected courtyard compounds" 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: Hutong lane with two connected courtyard compounds
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/hutong-lane-with-two-connected-courtyard-compounds-x2971
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Beijing's hutongs and courtyard compounds. Build a bounded voxel scene with referenced roof forms, narrow lane, and selective cutaway courtyards. Preserve public-private boundaries and mark reconstructed interior arrangements as illustrative. Voxel style.
Working Three.js Starter (hutong-lane-with-two-connected-courtyard-compounds-x2971):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Beijing Hutongs — Voxel Courtyard Compounds</title>
<style>
:root {
--ink: #282b28;
--paper: #f1ecdf;
--paper-strong: #fbf8ef;
--muted: #706f66;
--line: rgba(40, 43, 40, 0.16);
--public: #7f9293;
--private: #a44b38;
--illustrative: #d98a2b;
--courtyard: #c6aa78;
--shadow: 0 12px 35px rgba(38, 35, 27, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d3c4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: rgba(251, 248, 239, 0.92);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title {
top: 18px;
left: 18px;
width: min(440px, calc(100vw - 36px));
padding: 17px 19px 16px;
border-radius: 4px;
}
.eyebrow {
margin: 0 0 7px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
color: #776e5d;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(24px, 3vw, 34px);
font-weight: 500;
line-height: 1.05;
letter-spacing: -0.025em;
}
#title .subtitle {
margin: 9px 0 0;
max-width: 390px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
#legend {
top: 18px;
right: 18px;
width: 275px;
padding: 15px 16px;
border-radius: 4px;
}
#legend h2 {
margin: 0 0 11px;
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 16px 1fr;
gap: 9px;
align-items: start;
margin: 9px 0;
font-size: 11px;
line-height: 1.4;
}
.swatch {
width: 12px;
height: 12px;
margin-top: 1px;
border: 1px solid rgba(0, 0, 0, 0.12);
}
.swatch.public {
background: var(--public);
}
.swatch.private {
background: var(--private);
}
.swatch.courtyard {
background: var(--courtyard);
}
.swatch.illustrative {
background: var(--illustrative);
}
.legend-note {
margin: 12px 0 0;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
#controls {
left: 50%;
bottom: 18px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 6px;
padding: 7px;
border-radius: 5px;
}
#controls button {
min-height: 34px;
padding: 0 12px;
border: 1px solid rgba(40, 43, 40, 0.12);
border-radius: 3px;
background: transparent;
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 700;
white-space: nowrap;
}
#controls button:hover {
background: rgba(40, 43, 40, 0.06);
}
#controls button.active {
border-color: rgba(164, 75, 56, 0.35);
background: rgba(164, 75, 56, 0.09);
}
#help {
position: fixed;
z-index: 9;
right: 18px;
bottom: 18px;
padding: 9px 11px;
border-radius: 3px;
background: rgba(251, 248, 239, 0.84);
color: #5e5d55;
font-size: 10px;
line-height: 1.45;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
overflow: hidden;
}
.map-label {
position: absolute;
max-width: 210px;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-left: 3px solid var(--public);
border-radius: 2px;
background: rgba(251, 248, 239, 0.92);
box-shadow: 0 5px 18px rgba(30, 30, 25, 0.13);
color: #343631;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.055em;
line-height: 1.35;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
transition: opacity 120ms ease;
}
.map-label.private {
border-left-color: var(--private);
}
.map-label.illustrative {
border-left-color: var(--illustrative);
color: #78420f;
}
.map-label.reference {
border-left-color: #596966;
}
#modal {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
padding: 20px;
background: rgba(30, 31, 28, 0.34);
backdrop-filter: blur(3px);
}
#modal[hidden] {
display: none;
}
.modal-card {
width: min(570px, 100%);
max-height: 84vh;
overflow: auto;
padding: 25px 27px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 5px;
background: var(--paper-strong);
box-shadow: 0 22px 70px rgba(30, 29, 24, 0.28);
}
.modal-card h2 {
margin: 0 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
font-weight: 500;
}
.modal-card p {
color: #5f605a;
font-size: 12px;
line-height: 1.65;
}
.modal-card ul {
padding-left: 19px;
color: #5f605a;
font-size: 12px;
line-height: 1.65;
}
.modal-card strong {
color: #32342f;
}
.warning {
margin: 17px 0;
padding: 12px 14px;
border-left: 3px solid var(--illustrative);
background: rgba(217, 138, 43, 0.1);
color: #704516;
font-size: 11px;
line-height: 1.55;
}
#closeModal {
float: right;
margin: -8px -8px 0 12px;
width: 31px;
height: 31px;
border: 1px solid var(--line);
border-radius: 50%;
background: transparent;
cursor: pointer;
font-size: 18px;
line-height: 1;
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #d8d3c4;
color: #5c5c54;
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 850px) {
#legend {
top: auto;
right: 12px;
bottom: 72px;
width: 235px;
}
#help {
display: none;
}
#title {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
}
#controls {
bottom: 10px;
max-width: calc(100vw - 20px);
overflow-x: auto;
}
#controls button {
padding: 0 9px;
}
}
@media (max-width: 560px) {
#legend {
display: none;
}
#title .subtitle {
font-size: 11px;
}
.map-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel model of Beijing hutong courtyard compounds"></main>
<section id="title" class="panel">
<p class="eyebrow">Typological reference model · Beijing</p>
<h1>Hutongs & Courtyard Compounds</h1>
<p class="subtitle">
A bounded voxel study of a narrow public lane, enclosed siheyuan-style compounds,
closed thresholds, and selectively cutaway rooms.
</p>
</section>
<aside id="legend" class="panel">
<h2>Reading the model</h2>
<div class="legend-row">
<span class="swatch public"></span>
<span><strong>Public lane</strong><br />Shared hutong paving and street edge.</span>
</div>
<div class="legend-row">
<span class="swatch private"></span>
<span><strong>Private threshold</strong><br />Closed red gates and continuous enclosure walls.</span>
</div>
<div class="legend-row">
<span class="swatch courtyard"></span>
<span><strong>Courtyard compound</strong><br />Axial rooms arranged around a protected court.</span>
</div>
<div class="legend-row">
<span class="swatch illustrative"></span>
<span><strong>Illustrative cutaway</strong><br />Reconstructed room arrangements, not verified records.</span>
</div>
<p class="legend-note">
Roof forms reference the gray-tile pitched silhouettes and lifted eaves associated
with Beijing courtyard vernacular. This is a typological model, not a surveyed property.
</p>
</aside>
<div id="labels" aria-hidden="true"></div>
<nav id="controls" class="panel" aria-label="Model controls">
<button id="cutawayButton" class="active" aria-pressed="true">Cutaways: on</button>
<button id="labelsButton" class="active" aria-pressed="true">Labels: on</button>
<button id="resetButton">Reset view</button>
<button id="referenceButton">References & limits</button>
</nav>
<div id="help">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom<br />
Arrow keys orbit · + / − zoom · R resets
</div>
<div id="modal" hidden role="dialog" aria-modal="true" aria-labelledby="modalTitle">
<article class="modal-card">
<button id="closeModal" aria-label="Close references">×</button>
<p class="eyebrow">References and interpretive limits</p>
<h2 id="modalTitle">A typological Beijing block</h2>
<p>
The model combines spatial references associated with traditional Beijing
<strong>hutongs</strong> and <strong>siheyuan</strong> compounds. It is designed
to communicate enclosure, access hierarchy, narrow-lane scale, and courtyard
organization rather than document one exact address.
</p>
<ul>
<li>
<strong>Public–private hierarchy:</strong> the gray lane is shared space;
brick-red gates, stone thresholds, and enclosing walls separate it from
private courts.
</li>
<li>
<strong>Roof reference:</strong> stepped gray-tile pitches, raised ridges,
dark eaves, and voxel corner lifts evoke the roof silhouettes commonly
seen in Beijing courtyard housing.
</li>
<li>
<strong>Compound reference:</strong> a gate faces the lane, rooms define
the sides and rear of a central court, and a principal hall occupies the
axial rear position.
</li>
<li>
<strong>Cutaways:</strong> only selected roofs and façades are removed.
Compound perimeter walls remain intact, preserving the public–private
boundary in every view.
</li>
</ul>
<div class="warning">
<strong>Illustrative reconstruction.</strong> Interior room use, furniture,
screens, beds, kitchens, and cutaway locations are schematic teaching
devices. They are not archival reconstructions, measured plans, or claims
about access to private dwellings.
</div>
<p>
The scene uses an original voxel vocabulary with no imported models or
textures. All architecture and furnishings are procedurally assembled in
the HTML file.
</p>
</article>
</div>
<div id="loading">Assembling voxel hutong…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneRoot = document.getElementById("scene");
const loading = document.getElementById("loading");
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
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;
sceneRoot.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d3c4);
scene.fog = new THREE.Fog(0xd8d3c4, 48, 95);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
150
);
const view = {
theta: 2.42,
phi: 0.93,
radius: 49,
target: new THREE.Vector3(0, 1.8, 1.4)
};
const homeView = {
theta: 2.42,
phi: 0.93,
radius: 49,
target: new THREE.Vector3(0, 1.8, 1.4)
};
function updateCamera() {
const spherical = new THREE.Spherical(view.radius, view.phi, view.theta);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(view.target).add(offset);
camera.lookAt(view.target);
camera.updateMatrixWorld();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff8e7, 0x797c72, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.1);
sun.position.set(-18, 30, -23);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -30;
sun.shadow.camera.right = 30;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 75;
sun.shadow.bias = -0.0005;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc5d7df, 0.75);
fill.position.set(20, 12, 20);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and voxel primitives
// -------------------------------------------------------------------------
function standard(color, roughness = 0.88, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
...extra
});
}
const M = {
base: standard(0x8e8778),
ground: standard(0xbdb094),
groundDark: standard(0xa89a7e),
lane: standard(0x7f8887),
laneAlt: standard(0x899190),
laneEdge: standard(0x596563),
paving: standard(0xb9b4a5),
pavingAlt: standard(0xc6c0b0),
wall: standard(0xd2bd98),
wallAlt: standard(0xc4ad88),
wallCap: standard(0x535c59),
roof: standard(0x526060),
roofAlt: standard(0x61706f),
roofDark: standard(0x3d4949),
roofSeam: standard(0x465454),
timber: standard(0x563c2d),
timberLight: standard(0x806045),
red: standard(0x914331),
redDark: standard(0x6c3027),
gold: standard(0xc69b4d, 0.65),
window: standard(0x31474a, 0.65),
stone: standard(0xa7a497),
stoneLight: standard(0xc5c0ae),
interior: standard(0xb99868),
interiorLight: standard(0xd0b783),
textile: standard(0x8e4435),
foliage: standard(0x60765a),
foliageLight: standard(0x7d8c66),
foliageDark: standard(0x485f48),
soil: standard(0x665846),
lantern: standard(0xb63d29, 0.55, {
emissive: 0x7a1e10,
emissiveIntensity: 0.42
}),
amber: new THREE.MeshBasicMaterial({
color: 0xe7a33b,
transparent: true,
opacity: 0.17,
depthWrite: false
}),
water: standard(0x597a78, 0.42)
};
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
function box(parent, w, h, d, x, y, z, material, castShadow = true) {
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(parent) {
const g = new THREE.Group();
parent.add(g);
return g;
}
// -------------------------------------------------------------------------
// Bounded ground and public lane
// -------------------------------------------------------------------------
box(scene, 42.4, 0.7, 29.2, 0, -0.48, 0, M.base);
box(scene, 41.8, 0.18, 28.6, 0, -0.08, 0, M.ground);
// Raised edge clearly defines the model boundary.
box(scene, 42.1, 0.28, 0.28, 0, 0.08, -14.35, M.groundDark);
box(scene, 42.1, 0.28, 0.28, 0, 0.08, 14.35, M.groundDark);
box(scene, 0.28, 0.28, 28.7, -20.95, 0.08, 0, M.groundDark);
box(scene, 0.28, 0.28, 28.7, 20.95, 0.08, 0, M.groundDark);
// Narrow, two-course lane.
for (let row = 0; row < 2; row++) {
for (let i = 0; i < 36; i++) {
const x = -19.65 + i * 1.12;
const z = row === 0 ? -0.79 : 0.79;
const material = (i + row) % 3 === 0 ? M.laneAlt : M.lane;
box(scene, 1.045, 0.095, 1.46, x, 0.055, z, material, false);
}
}
// Drainage lines and narrow stone shoulders.
box(scene, 40.6, 0.12, 0.16, 0, 0.09, -1.69, M.laneEdge, false);
box(scene, 40.6, 0.12, 0.16, 0, 0.09, 1.69, M.laneEdge, false);
box(scene, 40.6, 0.11, 0.48, 0, 0.065, -2.13, M.paving, false);
box(scene, 40.6, 0.11, 0.48, 0, 0.065, 2.13, M.paving, false);
// Sparse central drainage stones.
for (let x = -18; x <= 18; x += 3.2) {
box(scene, 0.65, 0.12, 0.7, x, 0.085, 0, M.laneEdge, false);
}
// -------------------------------------------------------------------------
// Trees and street-edge objects
// -------------------------------------------------------------------------
function addTree(parent, x, z, scale = 1, y = 0) {
const g = group(parent);
g.position.set(x, y, z);
g.scale.setScalar(scale);
box(g, 0.28, 1.55, 0.28, 0, 0.78, 0, M.timber);
box(g, 0.19, 0.95, 0.19, -0.33, 1.45, 0, M.timber);
box(g, 0.18, 0.85, 0.18, 0.30, 1.62, 0.04, M.timber);
const clusters = [
[-0.55, 1.9, 0.05, 0.88, 0.72, 0.82, M.foliage],
[0.34, 2.06, -0.08, 1.05, 0.86, 0.92, M.foliageLight],
[0.02, 2.45, 0.18, 0.82, 0.70, 0.75, M.foliage],
[-0.22, 1.75, -0.43, 0.78, 0.68, 0.70, M.foliageDark],
[0.52, 1.75, 0.38, 0.65, 0.62, 0.62, M.foliage]
];
for (const c of clusters) {
box(g, c[3], c[4], c[5], c[0], c[1], c[2], c[6]);
}
return g;
}
addTree(scene, -17.6, -2.55, 0.92);
addTree(scene, 5.3, 2.55, 0.83);
addTree(scene, 17.7, -2.55, 1.02);
addTree(scene, 18.1, 2.55, 0.72);
// -------------------------------------------------------------------------
// Referenced voxel roof form
// -------------------------------------------------------------------------
function makeRoofShape(ridgeLength, crossDepth, eaveY, detailed = false) {
const roof = new THREE.Group();
const steps = 6;
const rise = 1.28;
const rowDepth = crossDepth / (steps * 2);
// Two stepped slopes forming a pitched gray-tile roof.
for (const side of [-1, 1]) {
for (let i = 0; i < steps; i++) {
const t = (i + 0.5) / steps;
const z = side * (t * crossDepth) / 2;
const y = eaveY + rise * (1 - t);
const material = i % 2 === 0 ? M.roof : M.roofAlt;
box(
roof,
ridgeLength + 0.38,
0.22,
rowDepth + 0.045,
0,
y,
z,
material
);
// Sparse vertical seams retain a tiled, voxel-like surface.
if (detailed && ridgeLength < 9) {
const seamCount = Math.max(4, Math.floor(ridgeLength / 1.05));
for (let s = 1; s < seamCount; s++) {
const sx = -ridgeLength / 2 + (s * ridgeLength) / seamCount;
box(
roof,
0.035,
0.235,
rowDepth * 0.92,
sx,
y + 0.006,
z,
M.roofSeam,
false
);
}
}
}
// Dark projecting eave.
box(
roof,
ridgeLength + 0.58,
0.18,
0.24,
0,
eaveY + 0.04,
side * (crossDepth / 2),
M.roofDark
);
// Lifted corner blocks evoke the characteristic upturned eaves.
for (const x of [-ridgeLength / 2, ridgeLength / 2]) {
box(
roof,
0.34,
0.34,
0.34,
x,
eaveY + 0.27,
side * (crossDepth / 2),
M.roofDark
);
}
}
// Raised ridge cap.
box(
roof,
ridgeLength + 0.68,
0.28,
0.28,
0,
eaveY + rise + 0.12,
0,
M.roofDark
);
return roof;
}
function addRoof(
parent,
cx,
cz,
ridgeLength,
crossDepth,
eaveY,
axis = "x",
detailed = false
) {
const roof = makeRoofShape(ridgeLength, crossDepth, eaveY, detailed);
roof.position.set(cx, 0, cz);
if (axis === "z") {
roof.rotation.y = Math.PI / 2;
}
parent.add(roof);
return roof;
}
// -------------------------------------------------------------------------
// Cutaway state
// -------------------------------------------------------------------------
const cutRecords = [];
let cutawaysEnabled = true;
function registerCutaway(normalObjects, illustrativeObjects) {
const record = { normalObjects, illustrativeObjects };
cutRecords.push(record);
for (const object of normalObjects) object.visible = !cutawaysEnabled;
for (const object of illustrativeObjects) object.visible = cutawaysEnabled;
}
function setCutaways(enabled) {
cutawaysEnabled = enabled;
for (const record of cutRecords) {
for (const object of record.normalObjects) {
object.visible = !enabled;
}
for (const object of record.illustrativeObjects) {
object.visible = enabled;
}
}
const button = document.getElementById("cutawayButton");
button.textContent = `Cutaways: ${enabled ? "on" : "off"}`;
button.classList.toggle("active", enabled);
button.setAttribute("aria-pressed", String(enabled));
}
// -------------------------------------------------------------------------
// Architectural details and interior illustrations
// -------------------------------------------------------------------------
function addFrontDetails(parent, cx, frontZ, width, height, mainRoom) {
if (mainRoom) {
const doorWidth = 1.45;
box(
parent,
doorWidth,
1.82,
0.08,
cx,
0.91,
frontZ - 0.135,
M.red
);
box(parent, 0.08, 1.82, 0.11, cx, 0.91, frontZ - 0.19, M.redDark);
box(parent, doorWidth + 0.15, 0.12, 0.13, cx, 1.86, frontZ - 0.18, M.timber);
for (const dx of [-2.45, 2.45]) {
const wx = cx + dx;
box(parent, 1.28, 0.83, 0.07, wx, 1.43, frontZ - 0.145, M.window);
for (let b = -2; b <= 2; b++) {
box(
parent,
0.045,
0.84,
0.09,
wx + b * 0.25,
1.43,
frontZ - 0.19,
M.timberLight,
false
);
}
for (const y of [1.01, 1.84]) {
box(parent, 1.35, 0.06, 0.1, wx, y, frontZ - 0.19, M.timberLight, false);
}
}
} else {
box(parent, 0.76, 1.65, 0.08, cx, 0.825, frontZ - 0.13, M.red);
box(parent, 0.86, 0.11, 0.1, cx, 1.69, frontZ - 0.18, M.timber);
}
}
function addSideWindow(parent, side, x, z, width = 0.9) {
const px = x + side * (width * 0.5 + 0.025);
box(parent, 0.07, 0.78, 1.02, px, 1.48, z, M.window);
for (const dz of [-0.34, 0, 0.34]) {
box(parent, 0.1, 0.8, 0.04, px + side * 0.035, 1.48, z + dz, M.timberLight, false);
}
for (const y of [1.08, 1.88]) {
box(parent, 0.1, 0.05, 1.08, px + side * 0.035, y, z, M.timberLight, false);
}
}
function addMainInterior(parent, cx, cz, w, d) {
const g = group(parent);
// Raised sleeping platform at the rear.
box(g, 3.0, 0.28, 0.82, cx - 1.75, 0.25, cz + d / 2 - 0.58, M.timber);
box(g, 2.82, 0.08, 0.72, cx - 1.75, 0.43, cz + d / 2 - 0.58, M.textile);
// Central table and stools.
box(g, 1.48, 0.14, 1.0, cx + 0.65, 0.82, cz - 0.12, M.timberLight);
for (const dx of [-0.54, 0.54]) {
for (const dz of [-0.34, 0.34]) {
box(g, 0.12, 0.68, 0.12, cx + 0.65 + dx, 0.44, cz - 0.12 + dz, M.timber);
}
}
for (const [sx, sz] of [
[-0.55, -0.95],
[1.85, -0.95],
[-0.55, 0.75],
[1.85, 0.75]
]) {
box(g, 0.48, 0.34, 0.48, cx + sx, 0.27, cz + sz, M.timber);
box(g, 0.5, 0.08, 0.5, cx + sx, 0.47, cz + sz, M.textile);
}
// Cabinet and a folding screen.
box(g, 1.15, 1.15, 0.45, cx + 2.8, 0.7, cz + d / 2 - 0.35, M.timber);
box(g, 0.95, 0.75, 0.06, cx + 2.78, 0.78, cz + d / 2 - 0.61, M.timberLight);
for (let i = 0; i < 3; i++) {
box(
g,
0.56,
1.32,
0.08,
cx + 1.85 + i * 0.59,
0.8,
cz + d / 2 - 0.33,
M.interiorLight
);
}
return g;
}
function addWingInterior(parent, cx, cz) {
const g = group(parent);
// Sleeping platform.
box(g, 1.05, 0.32, 1.9, cx - 0.25, 0.25, cz + 0.8, M.timber);
box(g, 0.93, 0.08, 1.72, cx - 0.25, 0.45, cz + 0.8, M.textile);
// Work table and stool.
box(g, 0.75, 0.12, 0.68, cx + 0.25, 0.76, cz - 1.25, M.timberLight);
box(g, 0.42, 0.3, 0.42, cx + 0.2, 0.25, cz - 1.25, M.timber);
// Shelf and square jars.
box(g, 0.12, 1.4, 1.6, cx + 0.72, 0.8, cz + 2.05, M.timber);
box(g, 0.72, 0.1, 1.65, cx + 0.42, 1.16, cz + 2.05, M.timberLight);
box(g, 0.34, 0.38, 0.34, cx + 0.35, 1.4, cz + 1.65, M.interiorLight);
box(g, 0.28, 0.32, 0.28, cx + 0.35, 1.37, cz + 2.25, M.stoneLight);
return g;
}
function makeRoom(parent, options) {
const {
cx,
cz,
w,
d,
h,
axis = "x",
mainRoom = false,
cutFront = false,
cutSide = null
} = options;
// Floor is always present.
box(parent, w, 0.12, d, cx, 0.13, cz, M.interior, false);
// Rear and side enclosure.
box(parent, w, h, 0.22, cx, h / 2, cz + d / 2, M.wall);
const leftWall = group(parent);
box(leftWall, 0.22, h, d, cx - w / 2, h / 2, cz, M.wall);
addSideWindow(leftWall, -1, cx - w / 2, cz, 0.22);
const rightWall = group(parent);
box(rightWall, 0.22, h, d, cx + w / 2, h / 2, cz, M.wall);
addSideWindow(rightWall, 1, cx + w / 2, cz, 0.22);
// Front façade is grouped so it can be selectively removed.
const frontWall = group(parent);
const frontZ = cz - d / 2;
box(frontWall, w, h, 0.22, cx, h / 2, frontZ, M.wall);
addFrontDetails(frontWall, cx, frontZ, w, h, mainRoom);
// Roof is grouped for selective cutaway.
const roof = addRoof(
parent,
cx,
cz,
axis === "x" ? w + 0.6 : d + 0.6,
axis === "x" ? d + 0.7 : w + 0.7,
h,
axis,
mainRoom
);
const cutAny = cutFront || cutSide;
const normalObjects = [];
const illustrativeObjects = [];
if (cutFront) normalObjects.push(frontWall);
if (cutSide === "right") normalObjects.push(rightWall);
if (cutSide === "left") normalObjects.push(leftWall);
normalObjects.push(roof);
if (cutAny) {
const tint = group(parent);
box(tint, w - 0.25, 0.022, d - 0.25, cx, 0.205, cz, M.amber, false);
const furniture = mainRoom
? addMainInterior(parent, cx, cz, w, d)
: addWingInterior(parent, cx, cz);
illustrativeObjects.push(tint, furniture);
registerCutaway(normalObjects, illustrativeObjects);
}
}
// -------------------------------------------------------------------------
// Compound gates, walls, and arrangement
// -------------------------------------------------------------------------
function addGate(parent, z, width = 1.85) {
const g = group(parent);
// Masonry piers.
for (const x of [-width / 2 - 0.18, width / 2 + 0.18]) {
box(g, 0.48, 2.24, 0.58, x, 1.12, z, M.stone);
box(g, 0.58, 0.15, 0.66, x, 2.26, z, M.stoneLight);
}
// Closed red double doors preserve the private threshold.
box(g, width - 0.08, 1.83, 0.14, 0, 0.95, z - 0.07, M.red);
box(g, 0.07, 1.84, 0.18, 0, 0.96, z - 0.16, M.redDark);
box(g, width + 0.18, 0.13, 0.2, 0, 1.94, z - 0.14, M.timber);
// Door studs.
for (const x of [-0.52, -0.22, 0.22, 0.52]) {
for (const y of [0.66, 1.05]) {
box(g, 0.075, 0.075, 0.05, x, y, z - 0.17, M.gold, false);
}
}
// Plaque and threshold.
box(g, 0.75, 0.3, 0.09, 0, 1.64, z - 0.18, M.timber);
box(g, 0.6, 0.16, 0.04, 0, 1.64, z - 0.235, M.gold, false);
box(g, width + 0.55, 0.15, 0.78, 0, 0.11, z + 0.12, M.stoneLight, false);
// Small canopy roof.
addRoof(g, 0, z - 0.03, 2.7, 1.35, 2.22, "x", false);
// Lanterns.
for (const x of [-width / 2 - 0.47, width / 2 + 0.47]) {
box(g, 0.31, 0.39, 0.31, x, 1.98, z - 0.05, M.lantern);
box(g, 0.35, 0.06, 0.35, x, 2.19, z - 0.05, M.gold, false);
box(g, 0.35, 0.06, 0.35, x, 1.77, z - 0.05, M.gold, false);
box(g, 0.04, 0.25, 0.04, x, 2.36, z - 0.05, M.timber, false);
}
}
function addCompound(worldX, worldZ, rotation, options = {}) {
const {
cutMain = false,
cutWing = false,
tree = true
} = options;
const compound = group(scene);
compound.position.set(worldX, 0, worldZ);
compound.rotation.y = rotation;
const w = 9.6;
const d = 10.8;
const wallHeight = 1.78;
const frontZ = -d / 2;
// Warm courtyard floor.
box(compound, w - 0.55, 0.075, d - 0.55, 0, 0.075, 0, M.interiorLight, false);
// Continuous side and rear enclosure.
for (const x of [-w / 2 + 0.2, w / 2 - 0.2]) {
box(compound, 0.38, wallHeight, d, x, wallHeight / 2, 0, M.wallAlt);
box(compound, 0.49, 0.15, d + 0.08, x, wallHeight + 0.06, 0, M.wallCap);
}
box(compound, w, wallHeight, 0.38, 0, wallHeight / 2, d / 2 - 0.2, M.wallAlt);
box(compound, w + 0.08, 0.15, 0.49, 0, wallHeight + 0.06, d / 2 - 0.2, M.wallCap);
// Front wall is broken only by the narrow gate.
const opening = 1.85;
const segment = (w - opening) / 2;
for (const side of [-1, 1]) {
const x = side * (opening / 2 + segment / 2);
box(compound, segment, wallHeight, 0.38, x, wallHeight / 2, frontZ + 0.2, M.wallAlt);
box(compound, segment + 0.08, 0.15, 0.49, x, wallHeight + 0.06, frontZ + 0.2, M.wallCap);
}
addGate(compound, frontZ + 0.2);
// Offset screen wall creates privacy without closing the compound.
box(compound, 3.8, 1.38, 0.28, 1.35, 0.72, frontZ + 1.25, M.wall);
box(compound, 3.94, 0.14, 0.4, 1.35, 1.47, frontZ + 1.25, M.wallCap);
// Stone path bends around the screen.
for (let i = 0; i < 6; i++) {
const z = frontZ + 0.65 + i * 0.55;
const x = i < 3 ? -0.2 : -0.75;
box(compound, 0.62, 0.05, 0.48, x, 0.14, z, M.stoneLight, false);
}
// Principal rear hall.
makeRoom(compound, {
cx: 0,
cz: 3.78,
w: 7.8,
d: 2.75,
h: 2.55,
axis: "x",
mainRoom: true,
cutFront: cutMain
});
// Side ranges with roofs ridged along their long axes.
makeRoom(compound, {
cx: -3.68,
cz: -0.02,
w: 2.0,
d: 6.1,
h: 2.34,
axis: "z",
mainRoom: false
});
makeRoom(compound, {
cx: 3.68,
cz: -0.02,
w: 2.0,
d: 6.1,
h: 2.34,
axis: "z",
mainRoom: false,
cutSide: cutWing ? "right" : null
});
// Courtyard tree, basin, and small stone plinths.
if (tree) {
addTree(compound, 1.52, -1.45, 0.62, 0.1);
}
box(compound, 0.85, 0.23, 0.85, -0.8, 0.2, -2.35, M.stone);
box(compound, 0.58, 0.04, 0.58, -0.8, 0.335, -2.35, M.water, false);
for (const x of [-2.55, 2.8]) {
box(compound, 0.42, 0.24, 0.42, x, 0.2, 0.85, M.stoneLight);
}
return compound;
}
// Five bounded courtyard compounds; two have selective interior cutaways.
addCompound(-11, 7.4, 0, {});
addCompound(0, 7.4, 0, {});
addCompound(11, 7.4, 0, { cutMain: true, cutWing: true });
addCompound(-10, -8.0, Math.PI, { cutMain: true });
addCompound(4.5, -8.0, Math.PI, {});
// A few low boundary stones and lane-side blocks give the diorama scale.
for (const x of [-18.7, -5.5, 7.5, 19]) {
box(scene, 0.55, 0.55, 0.55, x, 0.32, 2.55, M.stone);
box(scene, 0.63, 0.12, 0.63, x, 0.64, 2.55, M.stoneLight);
}
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelLayer = document.getElementById("labels");
const labels = [];
let labelsEnabled = true;
function addLabel(text, kind, x, y, z) {
const element = document.createElement("div");
element.className = `map-label ${kind}`;
element.textContent = text;
labelLayer.appendChild(element);
labels.push({
element,
position: new THREE.Vector3(x, y, z)
});
}
addLabel("Public · hutong lane", "public", -4.8, 0.75, -0.4);
addLabel("Private threshold", "private", -11, 2.95, 2.05);
addLabel("Enclosed courtyard compound", "private", 0, 2.95, 9.7);
addLabel("Roof reference · gray-tile pitch & lifted eaves", "reference", -10.6, 4.95, 11.2);
addLabel("Illustrative cutaway · room arrangement", "illustrative", 12.2, 2.6, 9.6);
addLabel("Illustrative interior · not an access route", "illustrative", -10, 2.35, -10.5);
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible =
labelsEnabled &&
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12;
label.element.style.opacity = visible ? "1" : "0";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, keyboard
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
const pointer = {
active: false,
id: null,
x: 0,
y: 0,
mode: "orbit"
};
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
if (pointer.active) return;
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.mode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.mode === "orbit") {
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(view.phi - dy * 0.005, 0.28, 1.38);
} else {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 1);
const scale = view.radius * 0.00125;
view.target.addScaledVector(right, -dx * scale);
view.target.addScaledVector(up, dy * scale);
view.target.x = THREE.MathUtils.clamp(view.target.x, -14, 14);
view.target.y = THREE.MathUtils.clamp(view.target.y, 0, 6);
view.target.z = THREE.MathUtils.clamp(view.target.z, -9, 9);
}
});
function releasePointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = Math.exp(event.deltaY * 0.001);
view.radius = THREE.MathUtils.clamp(view.radius * factor, 22, 72);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => resetView());
function resetView() {
view.theta = homeView.theta;
view.phi = homeView.phi;
view.radius = homeView.radius;
view.target.copy(homeView.target);
}
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") closeModal();
if (document.getElementById("modal").hidden === false) return;
switch (event.key) {
case "ArrowLeft":
view.theta += 0.08;
break;
case "ArrowRight":
view.theta -= 0.08;
break;
case "ArrowUp":
view.phi = Math.max(0.28, view.phi - 0.06);
break;
case "ArrowDown":
view.phi = Math.min(1.38, view.phi + 0.06);
break;
case "+":
case "=":
view.radius = Math.max(22, view.radius - 2);
break;
case "-":
case "_":
view.radius = Math.min(72, view.radius + 2);
break;
case "r":
case "R":
resetView();
break;
}
});
// -------------------------------------------------------------------------
// Interface controls
// -------------------------------------------------------------------------
const cutawayButton = document.getElementById("cutawayButton");
const labelsButton = document.getElementById("labelsButton");
const resetButton = document.getElementById("resetButton");
const referenceButton = document.getElementById("referenceButton");
const modal = document.getElementById("modal");
const closeModalButton = document.getElementById("closeModal");
cutawayButton.addEventListener("click", () => {
setCutaways(!cutawaysEnabled);
});
labelsButton.addEventListener("click", () => {
labelsEnabled = !labelsEnabled;
labelsButton.textContent = `Labels: ${labelsEnabled ? "on" : "off"}`;
labelsButton.classList.toggle("active", labelsEnabled);
labelsButton.setAttribute("aria-pressed", String(labelsEnabled));
});
resetButton.addEventListener("click", resetView);
function openModal() {
modal.hidden = false;
closeModalButton.focus();
}
function closeModal() {
modal.hidden = true;
referenceButton.focus();
}
referenceButton.addEventListener("click", openModal);
closeModalButton.addEventListener("click", closeModal);
modal.addEventListener("click", (event) => {
if (event.target === modal) closeModal();
});
// -------------------------------------------------------------------------
// 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));
});
setCutaways(true);
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
animate();
loading.remove();
</script>
</body>
</html>
```