Prompt specification
Build or customize the Three.js 3D scene "Old wall with a new doorway insert" 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: Old wall with a new doorway insert
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/old-wall-with-a-new-doorway-insert-x2165
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts adaptive reuse of existing buildings. Model a worn masonry wall with a clearly distinct new doorway frame. Make the boundary between retained material and reversible new intervention visible through geometry. Stylized solid forms.
Working Three.js Starter (old-wall-with-a-new-doorway-insert-x2165):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Adaptive Reuse — Reversible Threshold</title>
<style>
:root {
--ink: #233033;
--paper: rgba(247, 242, 231, 0.92);
--accent: #d76343;
--frame: #195e69;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7e0d4;
font-family: Inter, "Helvetica Neue", Arial, sans-serif;
color: var(--ink);
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.title-block {
position: fixed;
top: 28px;
left: 30px;
z-index: 10;
max-width: 360px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 38px);
font-weight: 500;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
margin-top: 12px;
max-width: 310px;
color: rgba(35, 48, 51, 0.72);
font-size: 12px;
line-height: 1.55;
}
.controls {
position: fixed;
right: 26px;
top: 26px;
z-index: 20;
display: flex;
gap: 8px;
align-items: center;
}
button {
border: 1px solid rgba(35, 48, 51, 0.2);
border-radius: 999px;
padding: 9px 13px;
background: var(--paper);
color: var(--ink);
font: inherit;
font-size: 11px;
cursor: pointer;
backdrop-filter: blur(8px);
}
button:hover {
background: #fffdf7;
}
.scene-label {
position: fixed;
z-index: 8;
display: none;
transform: translate(-50%, -100%);
padding: 7px 10px;
border: 1px solid rgba(35, 48, 51, 0.13);
border-radius: 3px;
background: rgba(247, 242, 231, 0.92);
box-shadow: 0 5px 18px rgba(40, 35, 29, 0.08);
color: var(--ink);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(7px);
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 19px;
background: rgba(35, 48, 51, 0.45);
}
.scene-label::before {
content: "";
position: absolute;
left: calc(50% - 3px);
top: calc(100% + 16px);
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--ink);
}
#label-frame {
color: var(--frame);
}
#label-addition {
color: var(--accent);
}
.legend {
position: fixed;
left: 30px;
bottom: 26px;
z-index: 10;
display: flex;
gap: 18px;
align-items: center;
padding: 10px 13px;
border: 1px solid rgba(35, 48, 51, 0.13);
border-radius: 4px;
background: rgba(247, 242, 231, 0.84);
color: rgba(35, 48, 51, 0.72);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
backdrop-filter: blur(8px);
}
.legend-item {
display: flex;
gap: 7px;
align-items: center;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
}
.swatch.masonry {
background: #98614d;
}
.swatch.frame {
background: var(--frame);
}
.swatch.new {
background: var(--accent);
}
@media (max-width: 760px) {
.title-block {
top: 18px;
left: 18px;
}
.subtitle,
.legend {
display: none;
}
.controls {
top: 18px;
right: 18px;
}
.scene-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<header class="title-block">
<div class="eyebrow">Adaptive Reuse / Study 04</div>
<h1>Reversible<br>Threshold</h1>
<div class="subtitle">
A retained masonry shell is adapted with a bolted, demountable frame
and a new inhabitable volume.
</div>
</header>
<div class="controls">
<button id="reset" type="button">Reset view</button>
</div>
<div id="label-masonry" class="scene-label">Retained masonry</div>
<div id="label-frame" class="scene-label">Reversible bolted frame</div>
<div id="label-addition" class="scene-label">New inhabitable volume</div>
<div class="legend">
<div class="legend-item">
<span class="swatch masonry"></span>
Existing fabric
</div>
<div class="legend-item">
<span class="swatch frame"></span>
Demountable insert
</div>
<div class="legend-item">
<span class="swatch new"></span>
New construction
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene and camera
// ------------------------------------------------------------
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7e0d4);
scene.fog = new THREE.Fog(0xe7e0d4, 20, 42);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive architectural diorama. Drag to orbit and scroll to zoom."
);
// ------------------------------------------------------------
// Small utilities
// ------------------------------------------------------------
let seed = 7319;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function range(a, b) {
return a + (b - a) * random();
}
function pick(array) {
return array[Math.floor(random() * array.length)];
}
function addBox(
parent,
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function subtractIntervals(start, end, cuts) {
let intervals = [[start, end]];
for (const [cutStart, cutEnd] of cuts) {
const next = [];
for (const [a, b] of intervals) {
if (cutEnd <= a || cutStart >= b) {
next.push([a, b]);
} else {
if (cutStart > a) next.push([a, cutStart]);
if (cutEnd < b) next.push([cutEnd, b]);
}
}
intervals = next;
}
return intervals.filter(([a, b]) => b - a > 0.01);
}
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const brickMaterials = [
new THREE.MeshStandardMaterial({
color: 0x99604b,
roughness: 0.96
}),
new THREE.MeshStandardMaterial({
color: 0x875747,
roughness: 1
}),
new THREE.MeshStandardMaterial({
color: 0xaa7055,
roughness: 0.94
}),
new THREE.MeshStandardMaterial({
color: 0x76685e,
roughness: 1
}),
new THREE.MeshStandardMaterial({
color: 0xa3927c,
roughness: 1
}),
new THREE.MeshStandardMaterial({
color: 0x705b50,
roughness: 1
}),
new THREE.MeshStandardMaterial({
color: 0x8e7764,
roughness: 1
})
];
const mortarMaterial = new THREE.MeshStandardMaterial({
color: 0x665b52,
roughness: 1
});
const plasterMaterial = new THREE.MeshStandardMaterial({
color: 0xc3b8a2,
roughness: 1,
side: THREE.DoubleSide,
polygonOffset: true,
polygonOffsetFactor: -1,
polygonOffsetUnits: -1
});
const concreteMaterial = new THREE.MeshStandardMaterial({
color: 0xd5cdbf,
roughness: 0.87
});
const darkConcreteMaterial = new THREE.MeshStandardMaterial({
color: 0x817b70,
roughness: 0.9
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x195e69,
roughness: 0.38,
metalness: 0.42
});
const frameEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x2b7780,
roughness: 0.32,
metalness: 0.5
});
const boltMaterial = new THREE.MeshStandardMaterial({
color: 0xc8c5b8,
roughness: 0.28,
metalness: 0.85
});
const gapMaterial = new THREE.MeshStandardMaterial({
color: 0x242b2b,
roughness: 0.8
});
const oldWindowMaterial = new THREE.MeshStandardMaterial({
color: 0x27383b,
roughness: 0.24,
metalness: 0.18
});
const oldWindowFrameMaterial = new THREE.MeshStandardMaterial({
color: 0x4b514e,
roughness: 0.7,
metalness: 0.15
});
const doorMaterial = new THREE.MeshStandardMaterial({
color: 0x365f62,
roughness: 0.46,
metalness: 0.16
});
const additionMaterial = new THREE.MeshStandardMaterial({
color: 0xd76343,
roughness: 0.56
});
const additionSideMaterial = new THREE.MeshStandardMaterial({
color: 0xb84d35,
roughness: 0.62
});
const modernGlassMaterial = new THREE.MeshStandardMaterial({
color: 0x294a50,
roughness: 0.2,
metalness: 0.28
});
const paleFrameMaterial = new THREE.MeshStandardMaterial({
color: 0xead7bd,
roughness: 0.48,
metalness: 0.12
});
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xd8d1c3,
roughness: 1
});
const plinthMaterial = new THREE.MeshStandardMaterial({
color: 0xbeb6a7,
roughness: 0.93
});
const pavingMaterial = new THREE.MeshStandardMaterial({
color: 0xc9c0b1,
roughness: 0.98
});
const soilMaterial = new THREE.MeshStandardMaterial({
color: 0x51483b,
roughness: 1
});
const foliageMaterial = new THREE.MeshStandardMaterial({
color: 0x617d56,
roughness: 0.93,
flatShading: true
});
const foliageLightMaterial = new THREE.MeshStandardMaterial({
color: 0x83976a,
roughness: 0.93,
flatShading: true
});
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x68503c,
roughness: 1
});
// ------------------------------------------------------------
// Chipped brick geometry
// ------------------------------------------------------------
function chippedBrickGeometry(width, height, depth, variant) {
const x0 = -width / 2;
const x1 = width / 2;
const y0 = -height / 2;
const y1 = height / 2;
const chip = Math.min(width, height) * range(0.1, 0.19);
const shape = new THREE.Shape();
if (variant === 0) {
shape.moveTo(x0 + chip, y0);
shape.lineTo(x1, y0);
shape.lineTo(x1, y1 - chip);
shape.lineTo(x1 - chip, y1);
shape.lineTo(x0, y1);
} else if (variant === 1) {
shape.moveTo(x0, y0);
shape.lineTo(x1, y0);
shape.lineTo(x1, y1);
shape.lineTo(x0 + chip, y1);
shape.lineTo(x0, y1 - chip);
} else if (variant === 2) {
shape.moveTo(x0, y0);
shape.lineTo(x1 - chip, y0);
shape.lineTo(x1, y0 + chip);
shape.lineTo(x1, y1);
shape.lineTo(x0, y1);
} else if (variant === 3) {
shape.moveTo(x0 + chip, y0);
shape.lineTo(x1, y0);
shape.lineTo(x1, y1);
shape.lineTo(x0, y1);
shape.lineTo(x0, y0 + chip);
} else {
shape.moveTo(x0 + chip, y0);
shape.lineTo(x1 - chip, y0);
shape.lineTo(x1, y0 + chip);
shape.lineTo(x1, y1 - chip);
shape.lineTo(x1 - chip, y1);
shape.lineTo(x0 + chip, y1);
shape.lineTo(x0, y1 - chip);
shape.lineTo(x0, y0 + chip);
}
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
bevelEnabled: false,
curveSegments: 1
});
geometry.translate(0, 0, -depth / 2);
return geometry;
}
// ------------------------------------------------------------
// Masonry wall builder
// ------------------------------------------------------------
function fillBrickInterval(group, start, end, y0, y1, rowIndex) {
const mortarGap = 0.034;
let cursor = start;
let first = true;
while (cursor < end - 0.08) {
let desired = range(0.58, 1.04);
if (rowIndex % 2 === 1 && first) {
desired *= 0.62;
}
const brickEnd = Math.min(cursor + desired, end);
const width = brickEnd - cursor - mortarGap;
if (width < 0.12) break;
// Occasional missing or deeply recessed brick exposes the mortar.
if (random() > 0.028 || width < 0.35) {
const brickHeight = Math.max(0.08, y1 - y0 - mortarGap);
const geometry = chippedBrickGeometry(
width,
brickHeight,
0.46,
Math.floor(random() * 5)
);
const brick = new THREE.Mesh(
geometry,
pick(brickMaterials)
);
brick.position.set(
cursor + width / 2 + mortarGap / 2,
(y0 + y1) / 2,
range(-0.012, 0.012)
);
brick.rotation.z = range(-0.009, 0.009);
brick.castShadow = true;
brick.receiveShadow = true;
group.add(brick);
}
cursor = brickEnd;
first = false;
}
}
function makeBrickWall(width, height, openings = []) {
const group = new THREE.Group();
const brickHeight = 0.44;
const wallDepth = 0.46;
// Horizontal cuts include masonry courses and exact opening edges.
const yCuts = [0, height];
for (let y = brickHeight; y < height; y += brickHeight) {
yCuts.push(y);
}
for (const opening of openings) {
yCuts.push(opening.y1, opening.y2);
}
const sortedYCuts = [...new Set(yCuts)]
.filter((value) => value >= 0 && value <= height)
.sort((a, b) => a - b);
// Recessed mortar backing, also cut around the openings.
for (let i = 0; i < sortedYCuts.length - 1; i++) {
const y0 = sortedYCuts[i];
const y1 = sortedYCuts[i + 1];
const middle = (y0 + y1) / 2;
const activeOpenings = openings.filter(
(opening) => opening.y1 <= middle && opening.y2 >= middle
);
const intervals = subtractIntervals(
-width / 2,
width / 2,
activeOpenings.map((opening) => [opening.x1, opening.x2])
);
for (const [start, end] of intervals) {
addBox(
group,
end - start,
y1 - y0,
0.25,
mortarMaterial,
(start + end) / 2,
(y0 + y1) / 2,
-0.2,
false,
true
);
}
}
// Individual worn masonry units.
for (let row = 0; row < sortedYCuts.length - 1; row++) {
const y0 = sortedYCuts[row];
const y1 = sortedYCuts[row + 1];
const middle = (y0 + y1) / 2;
const activeOpenings = openings.filter(
(opening) => opening.y1 <= middle && opening.y2 >= middle
);
const intervals = subtractIntervals(
-width / 2,
width / 2,
activeOpenings.map((opening) => [opening.x1, opening.x2])
);
for (const [start, end] of intervals) {
fillBrickInterval(group, start, end, y0, y1, row);
}
}
return group;
}
function addPlasterPatch(parent, x, y, width, height) {
const shape = new THREE.Shape();
const points = 10;
for (let i = 0; i < points; i++) {
const angle = (i / points) * Math.PI * 2;
const radius = range(0.72, 1.0);
const px = Math.cos(angle) * width * 0.5 * radius;
const py = Math.sin(angle) * height * 0.5 * radius;
if (i === 0) shape.moveTo(px, py);
else shape.lineTo(px, py);
}
shape.closePath();
const patch = new THREE.Mesh(
new THREE.ShapeGeometry(shape),
plasterMaterial
);
patch.position.set(x, y, 0.238);
patch.receiveShadow = true;
parent.add(patch);
}
function addOldWindow(parent, opening) {
const width = opening.x2 - opening.x1;
const height = opening.y2 - opening.y1;
const centerX = (opening.x1 + opening.x2) / 2;
const centerY = (opening.y1 + opening.y2) / 2;
const bar = 0.07;
addBox(
parent,
width - 0.06,
height - 0.06,
0.055,
oldWindowMaterial,
centerX,
centerY,
-0.05,
false,
true
);
addBox(
parent,
width + 0.08,
bar,
0.27,
oldWindowFrameMaterial,
centerX,
opening.y1,
0.08
);
addBox(
parent,
width + 0.08,
bar,
0.27,
oldWindowFrameMaterial,
centerX,
opening.y2,
0.08
);
addBox(
parent,
bar,
height,
0.27,
oldWindowFrameMaterial,
opening.x1,
centerY,
0.08
);
addBox(
parent,
bar,
height,
0.27,
oldWindowFrameMaterial,
opening.x2,
centerY,
0.08
);
addBox(
parent,
0.045,
height,
0.18,
oldWindowFrameMaterial,
centerX,
centerY,
0.10
);
addBox(
parent,
width + 0.18,
0.09,
0.42,
concreteMaterial,
centerX,
opening.y1 - 0.025,
0.16
);
}
// ------------------------------------------------------------
// Ground and urban base
// ------------------------------------------------------------
const ground = addBox(
scene,
60,
0.2,
60,
groundMaterial,
0,
-0.45,
0,
false,
true
);
addBox(
scene,
16.4,
0.36,
9.6,
plinthMaterial,
0.9,
-0.2,
-0.15,
false,
true
);
for (let row = 0; row < 2; row++) {
for (let column = 0; column < 6; column++) {
addBox(
scene,
1.5,
0.07,
0.7,
pavingMaterial,
-4.65 + column * 1.62,
0.025,
3.22 + row * 0.78,
false,
true
);
}
}
addBox(
scene,
10.2,
0.12,
0.18,
darkConcreteMaterial,
-0.55,
0.03,
4.85,
false,
true
);
// ------------------------------------------------------------
// Retained main masonry building
// ------------------------------------------------------------
const building = new THREE.Group();
scene.add(building);
const MAIN_WIDTH = 9.2;
const MAIN_HEIGHT = 4.4;
const MAIN_DEPTH = 4.0;
const BUILDING_BASE = 0.18;
addBox(
building,
9.55,
0.22,
4.55,
concreteMaterial,
0,
0.09,
0,
false,
true
);
addBox(
building,
9.05,
0.12,
3.85,
darkConcreteMaterial,
0,
0.23,
0,
false,
true
);
// Dark rear surface gives the windows and doorway visual depth.
addBox(
building,
9.18,
MAIN_HEIGHT,
0.25,
mortarMaterial,
0,
BUILDING_BASE + MAIN_HEIGHT / 2,
-2.0,
true,
true
);
const doorOpening = {
x1: -1.12,
x2: 1.12,
y1: 0,
y2: 3.08
};
const leftWindow = {
x1: -3.75,
x2: -2.25,
y1: 2.2,
y2: 3.08
};
const rightWindow = {
x1: 2.25,
x2: 3.75,
y1: 2.2,
y2: 3.08
};
const frontWall = makeBrickWall(
MAIN_WIDTH,
MAIN_HEIGHT,
[doorOpening, leftWindow, rightWindow]
);
frontWall.position.set(0, BUILDING_BASE, 2.0);
building.add(frontWall);
addOldWindow(frontWall, leftWindow);
addOldWindow(frontWall, rightWindow);
const sideWindow = {
x1: -0.55,
x2: 0.65,
y1: 2.2,
y2: 3.08
};
const rightWall = makeBrickWall(
MAIN_DEPTH,
MAIN_HEIGHT,
[sideWindow]
);
rightWall.position.set(4.6, BUILDING_BASE, 0);
rightWall.rotation.y = Math.PI / 2;
building.add(rightWall);
addOldWindow(rightWall, sideWindow);
// Irregular remnants of old render/plaster.
addPlasterPatch(frontWall, -4.05, 1.0, 0.72, 0.55);
addPlasterPatch(frontWall, -4.05, 3.6, 0.58, 0.75);
addPlasterPatch(frontWall, 4.12, 1.2, 0.62, 0.48);
addPlasterPatch(frontWall, 3.95, 3.65, 0.78, 0.62);
addPlasterPatch(frontWall, -1.8, 4.0, 0.58, 0.3);
// Fine geometric cracks and spalled marks.
const crackMaterial = new THREE.MeshStandardMaterial({
color: 0x51453d,
roughness: 1
});
const crackSpecs = [
[-4.2, 1.55, 0.42, 0.38],
[-4.12, 1.68, 0.28, -0.22],
[4.08, 2.85, 0.35, 0.42],
[-2.05, 0.52, 0.3, -0.18]
];
for (const [x, y, length, angle] of crackSpecs) {
const crack = addBox(
frontWall,
length,
0.012,
0.012,
crackMaterial,
x,
y,
0.244,
false,
false
);
crack.rotation.z = angle;
}
// Existing roof slab, reused as the base of the new volume.
addBox(
building,
9.65,
0.22,
4.65,
concreteMaterial,
0,
4.69,
0,
true,
true
);
// ------------------------------------------------------------
// New door leaf
// ------------------------------------------------------------
addBox(
frontWall,
2.08,
2.94,
0.08,
doorMaterial,
0,
1.5,
-0.07,
true,
true
);
addBox(
frontWall,
0.48,
2.54,
0.022,
oldWindowMaterial,
0.27,
1.54,
-0.018,
false,
false
);
const handle = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.56, 12),
boltMaterial
);
handle.position.set(0.79, 1.43, 0.03);
handle.castShadow = true;
frontWall.add(handle);
addBox(
frontWall,
0.05,
0.08,
0.09,
boltMaterial,
0.79,
1.67,
-0.01
);
addBox(
frontWall,
0.05,
0.08,
0.09,
boltMaterial,
0.79,
1.19,
-0.01
);
// ------------------------------------------------------------
// Reversible new doorway frame
// ------------------------------------------------------------
const threshold = addBox(
frontWall,
2.34,
0.06,
0.34,
frameEdgeMaterial,
0,
0.045,
0.41
);
threshold.castShadow = true;
// Exposed shadow gap between old masonry and the new frame.
addBox(
frontWall,
0.045,
3.08,
0.05,
gapMaterial,
-1.142,
1.54,
0.265,
false,
false
);
addBox(
frontWall,
0.045,
3.08,
0.05,
gapMaterial,
1.142,
1.54,
0.265,
false,
false
);
addBox(
frontWall,
2.32,
0.045,
0.05,
gapMaterial,
0,
3.102,
0.265,
false,
false
);
// Frame members stand physically away from the retained wall.
addBox(
frontWall,
0.17,
3.18,
0.24,
frameMaterial,
-1.25,
1.59,
0.42
);
addBox(
frontWall,
0.17,
3.18,
0.24,
frameMaterial,
1.25,
1.59,
0.42
);
addBox(
frontWall,
2.67,
0.18,
0.24,
frameMaterial,
0,
3.21,
0.42
);
// Small raised edge gives the frame a crisp, fabricated profile.
addBox(
frontWall,
0.035,
3.12,
0.045,
frameEdgeMaterial,
-1.15,
1.59,
0.558,
false,
false
);
addBox(
frontWall,
0.035,
3.12,
0.045,
frameEdgeMaterial,
1.15,
1.59,
0.558,
false,
false
);
// Stand-offs remain visible in the separation joint.
const standoffPositions = [
[-1.25, 0.48],
[-1.25, 2.72],
[1.25, 0.48],
[1.25, 2.72]
];
for (const [x, y] of standoffPositions) {
addBox(
frontWall,
0.13,
0.2,
0.13,
gapMaterial,
x,
y,
0.28,
true,
false
);
}
// Bolted connection: washers and hexagonal heads.
const boltPositions = [
[-1.25, 0.48],
[-1.25, 1.55],
[-1.25, 2.72],
[1.25, 0.48],
[1.25, 1.55],
[1.25, 2.72],
[-0.78, 3.21],
[0, 3.21],
[0.78, 3.21]
];
for (const [x, y] of boltPositions) {
const washer = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, 0.025, 20),
boltMaterial
);
washer.rotation.x = Math.PI / 2;
washer.position.set(x, y, 0.552);
washer.castShadow = true;
frontWall.add(washer);
const hex = new THREE.Mesh(
new THREE.CylinderGeometry(0.043, 0.043, 0.052, 6),
boltMaterial
);
hex.rotation.x = Math.PI / 2;
hex.position.set(x, y, 0.585);
hex.castShadow = true;
frontWall.add(hex);
}
// ------------------------------------------------------------
// New inhabitable rooftop volume
// ------------------------------------------------------------
const addition = new THREE.Group();
addition.position.set(0.55, 4.8, -0.45);
scene.add(addition);
addBox(
addition,
6.6,
2.55,
3.05,
additionMaterial,
0,
1.275,
0
);
// Front glazed strip with pale structural mullions.
const windowXs = [-2.55, -1.28, 0, 1.28, 2.55];
for (const x of windowXs) {
addBox(
addition,
1.12,
1.62,
0.045,
modernGlassMaterial,
x,
1.35,
1.548,
false,
true
);
}
for (const x of [-3.13, -1.92, -0.64, 0.64, 1.92, 3.13]) {
addBox(
addition,
0.075,
1.78,
0.09,
paleFrameMaterial,
x,
1.35,
1.585
);
}
addBox(
addition,
6.35,
0.09,
0.11,
paleFrameMaterial,
0,
0.49,
1.59
);
addBox(
addition,
6.35,
0.09,
0.11,
paleFrameMaterial,
0,
2.21,
1.59
);
// Glazed right side.
addBox(
addition,
0.05,
1.62,
2.42,
modernGlassMaterial,
3.325,
1.35,
0.12,
false,
true
);
addBox(
addition,
0.09,
1.78,
0.08,
paleFrameMaterial,
3.36,
1.35,
0,
false,
false
);
// Roof cap and a projecting slab.
addBox(
addition,
6.82,
0.16,
3.25,
paleFrameMaterial,
0,
2.62,
0
);
addBox(
addition,
6.48,
0.12,
0.68,
additionSideMaterial,
0,
2.43,
1.68
);
// ------------------------------------------------------------
// A second retained building linked to the reused structure
// ------------------------------------------------------------
const secondary = new THREE.Group();
secondary.position.set(7.05, BUILDING_BASE, -0.55);
scene.add(secondary);
const secondaryWindow = {
x1: -0.68,
x2: 0.68,
y1: 2.2,
y2: 3.08
};
const secondaryFront = makeBrickWall(
2.7,
4.4,
[secondaryWindow]
);
secondary.add(secondaryFront);
addOldWindow(secondaryFront, secondaryWindow);
addBox(
secondary,
2.75,
4.4,
2.95,
mortarMaterial,
0,
2.2,
-1.5,
true,
true
);
addBox(
secondary,
3.05,
0.22,
3.3,
concreteMaterial,
0,
4.69,
-0.1,
true,
true
);
// Lightweight rooftop addition on the second retained building.
addBox(
secondary,
1.9,
1.05,
1.55,
paleFrameMaterial,
0,
5.33,
-0.15
);
addBox(
secondary,
1.55,
0.72,
0.04,
modernGlassMaterial,
0,
5.38,
0.65,
false,
true
);
// Slim elevated connector between the two existing buildings.
const bridge = new THREE.Group();
bridge.position.set(5.23, 5.02, -1.1);
scene.add(bridge);
addBox(
bridge,
1.22,
0.18,
1.18,
additionMaterial,
0,
0,
0
);
addBox(
bridge,
1.15,
0.62,
0.035,
modernGlassMaterial,
0,
0.37,
0.56,
false,
true
);
addBox(
bridge,
1.15,
0.62,
0.035,
modernGlassMaterial,
0,
0.37,
-0.56,
false,
true
);
// ------------------------------------------------------------
// Planting and street-scale details
// ------------------------------------------------------------
function addTree(parent, x, y, z, scale = 1) {
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.14, 1.45, 7),
trunkMaterial
);
trunk.position.set(x, y + 0.725 * scale, z);
trunk.castShadow = true;
parent.add(trunk);
const crownA = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.72 * scale, 1),
foliageMaterial
);
crownA.position.set(x - 0.17 * scale, y + 1.65 * scale, z);
crownA.rotation.set(0.2, 0.3, -0.1);
crownA.castShadow = true;
parent.add(crownA);
const crownB = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.52 * scale, 1),
foliageLightMaterial
);
crownB.position.set(x + 0.32 * scale, y + 1.48 * scale, z + 0.04);
crownB.rotation.set(-0.15, 0.8, 0.1);
crownB.castShadow = true;
parent.add(crownB);
}
// Roof planter on the retained terrace.
addBox(
scene,
1.0,
0.43,
0.72,
concreteMaterial,
-3.65,
5.02,
1.48
);
addBox(
scene,
0.83,
0.07,
0.55,
soilMaterial,
-3.65,
5.25,
1.48,
false,
true
);
addTree(scene, -3.65, 5.25, 1.48, 0.8);
// Ground planters.
addBox(
scene,
1.1,
0.5,
1.1,
concreteMaterial,
-5.8,
0.25,
2.5
);
addBox(
scene,
0.94,
0.07,
0.94,
soilMaterial,
-5.8,
0.52,
2.5,
false,
true
);
addTree(scene, -5.8, 0.52, 2.5, 1.05);
addBox(
scene,
1.0,
0.46,
1.0,
concreteMaterial,
6.0,
0.23,
2.65
);
addBox(
scene,
0.84,
0.07,
0.84,
soilMaterial,
6.0,
0.49,
2.65,
false,
true
);
addTree(scene, 6.0, 0.49, 2.65, 0.92);
// Simple bench beside the entrance.
const bench = new THREE.Group();
bench.position.set(3.55, 0, 3.03);
scene.add(bench);
addBox(bench, 1.6, 0.12, 0.44, trunkMaterial, 0, 0.48, 0);
addBox(bench, 1.6, 0.42, 0.1, trunkMaterial, 0, 0.78, -0.18);
addBox(
bench,
0.12,
0.48,
0.38,
frameMaterial,
-0.57,
0.24,
0
);
addBox(
bench,
0.12,
0.48,
0.38,
frameMaterial,
0.57,
0.24,
0
);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xfff7e8,
0x817568,
2.25
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(
0xfff0d7,
4.1
);
sun.position.set(7.5, 12, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(
0xb8d4dc,
1.05
);
fill.position.set(-9, 6, 3);
scene.add(fill);
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom and keyboard access
// ------------------------------------------------------------
const target = new THREE.Vector3(0.85, 2.65, -0.1);
const defaultView = {
theta: 0.56,
phi: 1.08,
radius: 17.0
};
let theta = defaultView.theta;
let phi = defaultView.phi;
let radius = defaultView.radius;
let dragging = false;
let lastX = 0;
let lastY = 0;
function updateCamera() {
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
function resetView() {
theta = defaultView.theta;
phi = defaultView.phi;
radius = defaultView.radius;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastX;
const deltaY = event.clientY - lastY;
theta -= deltaX * 0.006;
phi -= deltaY * 0.005;
phi = THREE.MathUtils.clamp(phi, 0.38, 1.43);
lastX = event.clientX;
lastY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius *= Math.exp(event.deltaY * 0.001);
radius = THREE.MathUtils.clamp(radius, 9.5, 25);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.style.cursor = "grab";
renderer.domElement.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") theta -= 0.08;
if (event.key === "ArrowRight") theta += 0.08;
if (event.key === "ArrowUp") phi -= 0.06;
if (event.key === "ArrowDown") phi += 0.06;
if (event.key === "+" || event.key === "=") radius -= 0.7;
if (event.key === "-" || event.key === "_") radius += 0.7;
if (event.key.toLowerCase() === "r") resetView();
phi = THREE.MathUtils.clamp(phi, 0.38, 1.43);
radius = THREE.MathUtils.clamp(radius, 9.5, 25);
updateCamera();
});
document.getElementById("reset").addEventListener("click", resetView);
// ------------------------------------------------------------
// Screen-space callouts
// ------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabel(element, anchor, offsetX, offsetY) {
projected.copy(anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * innerWidth + offsetX;
const y = (-projected.y * 0.5 + 0.5) * innerHeight + offsetY;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const masonryAnchor = new THREE.Vector3(-3.65, 3.35, 2.25);
const frameAnchor = new THREE.Vector3(1.25, 2.15, 2.57);
const additionAnchor = new THREE.Vector3(0.6, 6.25, 1.12);
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
updateCamera();
renderer.setAnimationLoop(() => {
updateLabel(
document.getElementById("label-masonry"),
masonryAnchor,
-12,
-14
);
updateLabel(
document.getElementById("label-frame"),
frameAnchor,
62,
-4
);
updateLabel(
document.getElementById("label-addition"),
additionAnchor,
42,
-18
);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```