Prompt specification
Build or customize the Three.js 3D scene "Petit-Champlain stair and stone facade fragment" 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: Petit-Champlain stair and stone facade fragment
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/petit-champlain-stair-and-stone-facade-fragment-x2777
Scene Description Prompt:
Using Three.js from cdnjs, build one HTML scene of a voxel Petit-Champlain staircase beside a Québec stone shopfront with a separate entrance threshold.
Working Three.js Starter (petit-champlain-stair-and-stone-facade-fragment-x2777):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Petit-Champlain — Voxel Québec</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b8d0d9;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#title-card {
position: fixed;
top: 22px;
left: 24px;
z-index: 10;
max-width: min(390px, calc(100vw - 48px));
padding: 16px 18px;
color: #f8eed9;
background: rgba(29, 49, 52, 0.9);
border: 1px solid rgba(248, 238, 217, 0.25);
border-radius: 4px;
box-shadow: 0 12px 32px rgba(25, 39, 42, 0.2);
backdrop-filter: blur(10px);
pointer-events: none;
}
#title-card .eyebrow {
margin-bottom: 5px;
color: #d6b978;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
#title-card h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(22px, 4vw, 32px);
font-weight: 600;
line-height: 1.05;
}
#title-card p {
margin: 8px 0 0;
color: rgba(248, 238, 217, 0.78);
font-size: 12px;
line-height: 1.45;
}
#controls-hint {
position: fixed;
right: 20px;
bottom: 18px;
z-index: 10;
padding: 9px 12px;
color: #294347;
background: rgba(249, 241, 220, 0.86);
border: 1px solid rgba(41, 67, 71, 0.14);
border-radius: 4px;
font-size: 11px;
letter-spacing: 0.02em;
pointer-events: none;
}
#reset-view {
position: fixed;
left: 24px;
bottom: 18px;
z-index: 11;
padding: 9px 13px;
color: #f8eed9;
background: rgba(29, 49, 52, 0.88);
border: 1px solid rgba(248, 238, 217, 0.25);
border-radius: 4px;
cursor: pointer;
font: inherit;
font-size: 11px;
letter-spacing: 0.04em;
}
#reset-view:hover {
background: rgba(29, 49, 52, 0.98);
}
.pin {
position: fixed;
z-index: 8;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 8px;
color: #263f43;
background: rgba(250, 243, 224, 0.92);
border: 1px solid rgba(38, 63, 67, 0.2);
border-radius: 3px;
box-shadow: 0 5px 15px rgba(29, 49, 52, 0.14);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -115%);
}
.pin::after {
content: "";
position: absolute;
left: 50%;
bottom: -10px;
width: 1px;
height: 9px;
background: rgba(38, 63, 67, 0.5);
}
.pin i {
width: 7px;
height: 7px;
background: #c5994b;
border: 1px solid rgba(38, 63, 67, 0.45);
border-radius: 50%;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
color: #294347;
background: #b8d0d9;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
transition: opacity 0.4s ease;
}
@media (max-width: 650px) {
#title-card {
top: 12px;
left: 12px;
padding: 12px 14px;
}
#title-card p {
display: none;
}
#controls-hint {
right: 10px;
bottom: 10px;
max-width: 210px;
text-align: right;
}
#reset-view {
left: 10px;
bottom: 10px;
}
.pin {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="loading">Construction du Vieux-Québec…</div>
<header id="title-card">
<div class="eyebrow">Québec · Vieux-Québec</div>
<h1>Petit-Champlain</h1>
<p>A voxel limestone shopfront, its grand exterior stair, and a distinct upper entrance threshold.</p>
</header>
<div class="pin" id="pin-shop"><i></i>Boutique</div>
<div class="pin" id="pin-stair"><i></i>Escalier Petit-Champlain</div>
<div class="pin" id="pin-threshold"><i></i>Seuil d’entrée séparé</div>
<div id="controls-hint">Drag to orbit · Wheel or pinch to zoom · Double-click to reset</div>
<button id="reset-view" type="button">Reset view</button>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8d0d9);
scene.fog = new THREE.Fog(0xb8d0d9, 27, 48);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel scene of the Petit-Champlain staircase and Québec stone shopfront"
);
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const orbit = {
yaw: 0.68,
pitch: 0.57,
distance: 20,
target: new THREE.Vector3(0, 1.9, 0)
};
const defaultOrbit = { ...orbit, target: orbit.target.clone() };
function updateCamera() {
const horizontalDistance = Math.cos(orbit.pitch) * orbit.distance;
camera.position.set(
orbit.target.x + Math.sin(orbit.yaw) * horizontalDistance,
orbit.target.y + Math.sin(orbit.pitch) * orbit.distance,
orbit.target.z + Math.cos(orbit.yaw) * horizontalDistance
);
camera.lookAt(orbit.target);
camera.zoom = 18 / orbit.distance;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(11.8, 18 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
updateCamera();
resize();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfff3d9, 0x78929d, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc7, 3.8);
sun.position.set(-8, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
sun.shadow.bias = -0.00015;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0xb8dcff, 0.65);
coolFill.position.set(10, 7, -8);
scene.add(coolFill);
// -------------------------------------------------------------------------
// Shared geometry and materials
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function standard(color, roughness = 0.8, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
const stoneMaterials = [
standard(0xc8bda4),
standard(0xd5cbb3),
standard(0xbeb39c),
standard(0xc2b79f),
standard(0xd9cfb8),
standard(0xb7ad98)
];
const materials = {
base: standard(0x8e8170),
pavement: standard(0xa39b8b),
pavementDark: standard(0x8f887b),
pavementLight: standard(0xb2aa99),
curb: standard(0xc1b8a4),
road: standard(0x5e6667),
darkWood: standard(0x263f3e),
greenWood: standard(0x31534d),
redWood: standard(0x823e35),
brass: standard(0xc8a65b, 0.28, 0.68),
iron: standard(0x294441, 0.42, 0.45),
roof: standard(0x4d5555),
roofLight: standard(0x626968),
interior: standard(0x202b2b),
soil: standard(0x493d32),
leaf: standard(0x486b4d),
leafLight: standard(0x5e8056),
leafDark: standard(0x355641),
trunk: standard(0x6b4e36),
awning: standard(0x914a3c),
awningCream: standard(0xe6d8b5),
glass: new THREE.MeshStandardMaterial({
color: 0x71949b,
roughness: 0.16,
metalness: 0.05,
transparent: true,
opacity: 0.38
}),
lamp: new THREE.MeshStandardMaterial({
color: 0xffe1a0,
emissive: 0xffb84e,
emissiveIntensity: 1.3,
roughness: 0.4
})
};
function box(
width,
height,
depth,
x,
y,
z,
material,
parent = scene,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
let seed = 731942;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function range(min, max) {
return min + (max - min) * random();
}
function chooseStone() {
return stoneMaterials[Math.floor(random() * stoneMaterials.length)];
}
// -------------------------------------------------------------------------
// Text labels made locally with CanvasTexture
// -------------------------------------------------------------------------
function makeTextTexture(lines, color = "#f7e9c4") {
const textLines = Array.isArray(lines) ? lines : [lines];
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = Math.max(128, Math.round(canvas.width / 6.4));
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
const maxCharacters = Math.max(...textLines.map((line) => line.length));
let fontSize = canvas.height * (textLines.length > 1 ? 0.31 : 0.52);
ctx.font = `700 ${fontSize}px Georgia, serif`;
while (
ctx.measureText(textLines[0]).width > canvas.width * 0.9 ||
(textLines.length > 1 &&
ctx.measureText(textLines[textLines.length - 1]).width >
canvas.width * 0.9)
) {
fontSize *= 0.92;
ctx.font = `700 ${fontSize}px Georgia, serif`;
}
const lineHeight = fontSize * 1.12;
const startY =
canvas.height / 2 - ((textLines.length - 1) * lineHeight) / 2;
textLines.forEach((line, index) => {
ctx.fillText(line, canvas.width / 2, startY + index * lineHeight);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function textPlane(lines, width, height, color = "#f7e9c4") {
const material = new THREE.MeshBasicMaterial({
map: makeTextTexture(lines, color),
transparent: true,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
return new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
}
// -------------------------------------------------------------------------
// Masonry construction
// -------------------------------------------------------------------------
function subtractIntervals(min, max, cuts) {
let intervals = [{ min, max }];
for (const cut of cuts) {
const next = [];
for (const interval of intervals) {
if (cut.max <= interval.min || cut.min >= interval.max) {
next.push(interval);
continue;
}
if (cut.min > interval.min) {
next.push({ min: interval.min, max: cut.min });
}
if (cut.max < interval.max) {
next.push({ min: cut.max, max: interval.max });
}
}
intervals = next;
}
return intervals;
}
function buildCourseWall(axis, fixed, min, max, yMin, yMax, openings) {
const rowHeight = 0.44;
const wallDepth = 0.36;
const rowCount = Math.ceil((yMax - yMin) / rowHeight);
for (let row = 0; row < rowCount; row++) {
const rowBottom = yMin + row * rowHeight;
const rowTop = Math.min(yMin + (row + 1) * rowHeight, yMax);
if (rowTop <= rowBottom) continue;
const activeCuts = openings
.filter(
(opening) =>
rowTop > opening.y0 && rowBottom < opening.y1
)
.map((opening) => ({ min: opening.min, max: opening.max }));
const intervals = subtractIntervals(min, max, activeCuts);
for (const interval of intervals) {
let cursor = interval.min;
while (cursor < interval.max - 0.02) {
let length = Math.min(
range(0.72, 1.18),
interval.max - cursor
);
if (interval.max - cursor - length < 0.28) {
length = interval.max - cursor;
}
const center = cursor + length / 2;
if (axis === "x") {
box(
length - 0.026,
rowTop - rowBottom - 0.026,
wallDepth,
center,
(rowBottom + rowTop) / 2,
fixed,
chooseStone()
);
} else {
box(
wallDepth,
rowTop - rowBottom - 0.026,
length - 0.026,
fixed,
(rowBottom + rowTop) / 2,
center,
chooseStone()
);
}
cursor += length;
}
}
}
}
// -------------------------------------------------------------------------
// Ground, pavement, and street
// -------------------------------------------------------------------------
box(18, 0.48, 13, 0, -0.28, 0, materials.base);
box(18, 0.08, 13, 0, 0.01, 0, materials.pavement);
const paverMaterials = [
materials.pavement,
materials.pavementDark,
materials.pavementLight
];
for (let x = -8.0; x <= 8.0; x += 0.72) {
for (let z = -3.8; z <= 3.8; z += 0.72) {
const insideBuilding =
x > -6.35 && x < 3.35 && z < 0.08 && z > -3.65;
const insideStairs = x > 3.1 && x < 6.0 && z < 3.35 && z > -3.65;
if (insideBuilding || insideStairs) continue;
const material = paverMaterials[
Math.floor(random() * paverMaterials.length)
];
box(
0.68,
0.055,
0.68,
x,
0.075,
z,
material,
scene,
false,
true
);
}
}
box(18, 0.13, 0.22, 0, 0.12, 4.08, materials.curb);
box(18, 0.08, 2.25, 0, -0.015, 5.18, materials.road);
for (let x = -8; x <= 8; x += 1.35) {
box(
0.66,
0.025,
0.07,
x,
0.035,
5.2,
standard(0xc8b982),
scene,
false,
true
);
}
// -------------------------------------------------------------------------
// Limestone shopfront
// -------------------------------------------------------------------------
const building = new THREE.Group();
scene.add(building);
const frontOpenings = [
{ min: -5.36, max: -3.84, y0: 0.08, y1: 3.62 },
{ min: -3.0, max: 0.9, y0: 1.03, y1: 3.53 }
];
buildCourseWall(
"x",
-0.2,
-6.0,
3.2,
0.0,
5.35,
frontOpenings
);
buildCourseWall("x", -3.4, -6.0, 3.2, 0.0, 5.35, []);
buildCourseWall("z", -6.0, -3.4, -0.2, 0.0, 5.35, []);
buildCourseWall(
"z",
3.2,
-3.4,
-0.2,
0.0,
5.35,
[
{
min: -3.35,
max: -2.15,
y0: 2.31,
y1: 4.61
}
]
);
// Interior floor and rear recess.
box(9.0, 0.12, 3.0, -1.4, 0.07, -1.8, materials.interior, building);
box(4.05, 2.65, 0.12, -1.05, 2.28, -0.38, materials.interior, building);
// Stone plinth and cornice.
box(9.55, 0.32, 3.62, -1.4, 0.16, -1.8, stoneMaterials[1], building);
box(9.72, 0.27, 3.75, -1.4, 5.49, -1.8, stoneMaterials[3], building);
// Corner quoins.
for (let y = 0.45; y < 5.2; y += 0.64) {
const blockHeight = 0.48;
box(0.72, blockHeight, 0.52, -5.88, y, -0.02, chooseStone(), building);
box(0.72, blockHeight, 0.52, 3.06, y + 0.18, -0.02, chooseStone(), building);
}
// Flat, blocky slate roof.
box(9.9, 0.25, 3.85, -1.4, 5.73, -1.8, materials.roof, building);
box(9.45, 0.10, 3.45, -1.4, 5.90, -1.8, materials.roofLight, building);
box(0.65, 1.0, 0.72, -4.25, 6.26, -2.55, materials.roof, building);
box(0.78, 0.16, 0.84, -4.25, 6.83, -2.55, stoneMaterials[2], building);
// -------------------------------------------------------------------------
// Main shop door and its separate ground-level threshold
// -------------------------------------------------------------------------
box(1.36, 3.45, 0.12, -4.6, 1.81, -0.19, materials.darkWood, building);
box(1.08, 1.22, 0.045, -4.6, 2.63, -0.105, materials.glass, building, false);
box(1.12, 0.72, 0.045, -4.6, 0.78, -0.09, materials.greenWood, building);
box(0.055, 3.45, 0.055, -4.6, 1.81, -0.07, materials.darkWood, building);
box(0.20, 0.12, 0.15, -4.18, 1.65, 0.03, materials.brass, building);
// Door surround.
box(0.18, 3.73, 0.18, -5.44, 1.86, 0.08, stoneMaterials[2], building);
box(0.18, 3.73, 0.18, -3.76, 1.86, 0.08, stoneMaterials[2], building);
box(1.86, 0.20, 0.18, -4.6, 3.69, 0.08, stoneMaterials[1], building);
// This threshold belongs only to the street-level boutique.
box(1.82, 0.16, 0.78, -4.6, 0.12, 0.22, stoneMaterials[0], building);
box(1.54, 0.035, 0.48, -4.6, 0.218, 0.25, materials.darkWood, building);
// -------------------------------------------------------------------------
// Display window
// -------------------------------------------------------------------------
// Recess, sill, and wooden mullions.
box(4.02, 0.16, 0.34, -1.05, 0.98, 0.02, stoneMaterials[1], building);
box(0.18, 2.66, 0.20, -3.09, 2.29, 0.08, stoneMaterials[2], building);
box(0.18, 2.66, 0.20, 0.99, 2.29, 0.08, stoneMaterials[2], building);
box(4.26, 0.18, 0.20, -1.05, 3.61, 0.08, stoneMaterials[1], building);
box(0.10, 2.45, 0.11, -2.20, 2.27, 0.12, materials.darkWood, building);
box(0.10, 2.45, 0.11, 0.08, 2.27, 0.12, materials.darkWood, building);
box(4.02, 0.10, 0.11, -1.05, 2.25, 0.12, materials.darkWood, building);
// Products behind the glazing.
for (let shelf = 0; shelf < 3; shelf++) {
const shelfY = 1.42 + shelf * 0.69;
box(3.55, 0.075, 0.23, -1.05, shelfY, -0.14, materials.darkWood, building);
for (let item = 0; item < 8; item++) {
const itemX = -2.58 + item * 0.43;
const itemHeight = 0.22 + random() * 0.23;
const itemMaterial = [
standard(0xa95d45),
standard(0x537b6b),
standard(0xc09a50),
standard(0xd2c4a0)
][Math.floor(random() * 4)];
box(
0.17,
itemHeight,
0.13,
itemX,
shelfY + itemHeight / 2 + 0.04,
-0.08,
itemMaterial,
building
);
}
}
box(3.91, 2.42, 0.025, -1.05, 2.28, 0.155, materials.glass, building, false);
// -------------------------------------------------------------------------
// Awning and shop signs
// -------------------------------------------------------------------------
for (let stripe = 0; stripe < 12; stripe++) {
const x = -3.48 + stripe * 0.43;
const material = stripe % 2 === 0 ? materials.awning : materials.awningCream;
box(0.43, 0.12, 1.02, x, 4.01, 0.48, material, building);
box(0.43, 0.30, 0.10, x, 3.86, 0.96, material, building);
}
box(4.95, 0.78, 0.16, -1.08, 4.76, 0.18, materials.darkWood, building);
const shopSign = textPlane(
"ÉPICERIE DU VIEUX QUÉBEC",
4.65,
0.48
);
shopSign.position.set(-1.08, 4.76, 0.272);
building.add(shopSign);
// Small hanging bracket sign.
box(0.08, 0.08, 0.82, -5.80, 3.75, 0.37, materials.iron, building);
box(0.92, 1.18, 0.14, -5.80, 3.15, 0.77, materials.darkWood, building);
const hangingSign = textPlane(["ÉPICERIE", "DU QUÉBEC"], 0.78, 0.84);
hangingSign.position.set(-5.80, 3.15, 0.85);
building.add(hangingSign);
// -------------------------------------------------------------------------
// Petit-Champlain staircase
// -------------------------------------------------------------------------
const stairs = new THREE.Group();
scene.add(stairs);
const stepCount = 11;
const stepDepth = 0.48;
const stepRise = 0.21;
const stairWidth = 2.65;
const stairCenterX = 4.62;
const topHeight = stepCount * stepRise;
for (let index = 0; index < stepCount; index++) {
const stepTop = (index + 1) * stepRise;
const stepCenterZ = 3.1 - (index + 0.5) * stepDepth;
box(
stairWidth,
stepTop,
stepDepth - 0.012,
stairCenterX,
stepTop / 2,
stepCenterZ,
stoneMaterials[(index + 1) % stoneMaterials.length],
stairs
);
box(
stairWidth + 0.025,
0.055,
stepDepth + 0.018,
stairCenterX,
stepTop + 0.027,
stepCenterZ,
stoneMaterials[(index + 3) % stoneMaterials.length],
stairs
);
}
// Upper landing.
box(
stairWidth,
topHeight,
1.55,
stairCenterX,
topHeight / 2,
-2.86,
stoneMaterials[1],
stairs
);
box(
stairWidth + 0.03,
0.055,
1.55,
stairCenterX,
topHeight + 0.027,
-2.86,
stoneMaterials[0],
stairs
);
// -------------------------------------------------------------------------
// Separate upper side entrance and its visibly distinct threshold
// -------------------------------------------------------------------------
const sideDoorZ = -2.75;
box(
0.14,
2.20,
1.13,
3.26,
topHeight + 1.10,
sideDoorZ,
materials.greenWood,
building
);
box(
0.04,
0.78,
0.75,
3.35,
topHeight + 1.54,
sideDoorZ,
materials.glass,
building,
false
);
// Door panels and brass hardware.
box(
0.035,
0.58,
0.77,
3.35,
topHeight + 0.43,
sideDoorZ,
materials.darkWood,
building
);
box(
0.16,
2.48,
0.16,
3.41,
topHeight + 1.18,
sideDoorZ - 0.64,
stoneMaterials[2],
building
);
box(
0.16,
2.48,
0.16,
3.41,
topHeight + 1.18,
sideDoorZ + 0.64,
stoneMaterials[2],
building
);
box(
0.16,
0.17,
1.44,
3.41,
topHeight + 2.38,
sideDoorZ,
stoneMaterials[1],
building
);
box(
0.17,
0.13,
0.10,
3.43,
topHeight + 0.93,
sideDoorZ + 0.36,
materials.brass,
building
);
// The threshold is distinct in color, shape, and position from the shop door.
box(
0.58,
0.12,
1.36,
3.48,
topHeight + 0.08,
sideDoorZ,
stoneMaterials[4],
building
);
box(
0.055,
0.035,
1.34,
3.76,
topHeight + 0.158,
sideDoorZ,
materials.brass,
building
);
// Side entrance plaque.
box(
0.08,
0.42,
1.18,
3.43,
topHeight + 1.94,
sideDoorZ,
materials.darkWood,
building
);
const entrancePlaque = textPlane("ENTRÉE 18", 1.04, 0.28);
entrancePlaque.rotation.y = Math.PI / 2;
entrancePlaque.position.set(3.48, topHeight + 1.94, sideDoorZ);
building.add(entrancePlaque);
// Small lamp over the separate entrance.
box(
0.30,
0.32,
0.30,
3.56,
topHeight + 2.66,
sideDoorZ,
materials.lamp,
building,
false
);
// -------------------------------------------------------------------------
// Square iron stair rails
// -------------------------------------------------------------------------
function beamBetween(start, end, width, material, parent = scene) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(start, end)
.multiplyScalar(0.5);
const mesh = box(
width,
length,
width,
midpoint.x,
midpoint.y,
midpoint.z,
material,
parent
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
for (const railX of [3.18, 6.06]) {
const railStart = new THREE.Vector3(railX, 1.02, 3.02);
const railEnd = new THREE.Vector3(railX, 3.12, -2.38);
beamBetween(railStart, railEnd, 0.075, materials.iron, stairs);
beamBetween(
railStart.clone().add(new THREE.Vector3(0, -0.36, 0)),
railEnd.clone().add(new THREE.Vector3(0, -0.36, 0)),
0.045,
materials.iron,
stairs
);
for (let index = 0; index < stepCount; index += 2) {
const stepTop = (index + 1) * stepRise;
const postZ = 3.1 - (index + 0.5) * stepDepth;
box(
0.075,
0.92,
0.075,
railX,
stepTop + 0.46,
postZ,
materials.iron,
stairs
);
}
}
// Street-level stair sign.
box(0.09, 1.9, 0.09, 6.55, 0.95, 2.45, materials.iron);
box(1.78, 1.08, 0.15, 6.55, 1.76, 2.45, materials.darkWood);
const stairSign = textPlane(
["ESCALIER", "PETIT-CHAMPLAIN"],
1.56,
0.76
);
stairSign.position.set(6.55, 1.76, 2.535);
scene.add(stairSign);
// -------------------------------------------------------------------------
// Street furniture, planters, and trees
// -------------------------------------------------------------------------
function voxelTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
box(1.05, 0.44, 1.05, 0, 0.22, 0, materials.curb, tree);
box(0.88, 0.06, 0.88, 0, 0.47, 0, materials.soil, tree);
box(0.18, 1.55, 0.18, 0, 1.16, 0, materials.trunk, tree);
box(1.12, 0.86, 1.02, 0, 2.08, 0, materials.leaf, tree);
box(0.78, 0.74, 0.86, -0.36, 2.61, 0.03, materials.leafLight, tree);
box(0.84, 0.68, 0.76, 0.37, 2.49, -0.05, materials.leafDark, tree);
box(0.66, 0.56, 0.63, 0.08, 3.03, 0.05, materials.leafLight, tree);
}
voxelTree(-7.08, -0.9, 0.95);
voxelTree(6.92, -2.82, 0.82);
// Street lamp.
box(0.48, 0.16, 0.48, -6.88, 0.12, 2.55, materials.iron);
box(0.13, 3.55, 0.13, -6.88, 1.91, 2.55, materials.iron);
box(0.58, 0.13, 0.58, -6.88, 3.68, 2.55, materials.iron);
box(0.42, 0.48, 0.42, -6.88, 3.40, 2.55, materials.lamp, scene, false);
box(0.08, 0.70, 0.08, -6.88, 4.06, 2.55, materials.iron);
// Crates and sacks near the storefront.
box(0.62, 0.54, 0.62, -0.05, 0.30, 0.64, materials.trunk);
box(0.55, 0.46, 0.55, 0.34, 0.28, 0.83, materials.trunk);
box(0.66, 0.06, 0.66, -0.05, 0.60, 0.64, materials.roofLight);
// -------------------------------------------------------------------------
// Small voxel pedestrians for scale
// -------------------------------------------------------------------------
function pedestrian(x, groundY, z, coatColor, hatColor, facing = 0) {
const person = new THREE.Group();
person.position.set(x, groundY, z);
person.rotation.y = facing;
scene.add(person);
const coat = standard(coatColor);
const trousers = standard(0x344149);
const hat = standard(hatColor);
const skin = standard(0xc68f69);
box(0.16, 0.58, 0.19, -0.13, 0.29, 0, trousers, person);
box(0.16, 0.58, 0.19, 0.13, 0.29, 0, trousers, person);
box(0.20, 0.12, 0.31, -0.13, 0.06, 0.05, materials.darkWood, person);
box(0.20, 0.12, 0.31, 0.13, 0.06, 0.05, materials.darkWood, person);
box(0.48, 0.73, 0.31, 0, 0.95, 0, coat, person);
box(0.15, 0.54, 0.17, -0.31, 0.93, 0, coat, person);
box(0.15, 0.54, 0.17, 0.31, 0.93, 0, coat, person);
box(0.32, 0.34, 0.31, 0, 1.49, 0, skin, person);
box(0.40, 0.16, 0.39, 0, 1.73, 0, hat, person);
box(0.34, 0.12, 0.15, 0, 1.66, 0.23, hat, person);
}
pedestrian(-2.25, 0.12, 1.10, 0x9e5345, 0x33454b, 0.2);
pedestrian(4.66, 1.48, -0.15, 0x416879, 0x7b5942, -0.15);
// -------------------------------------------------------------------------
// HTML annotation pins
// -------------------------------------------------------------------------
const pins = [
{
element: document.getElementById("pin-shop"),
position: new THREE.Vector3(-4.6, 0.55, 0.70)
},
{
element: document.getElementById("pin-stair"),
position: new THREE.Vector3(4.65, 0.78, 0.65)
},
{
element: document.getElementById("pin-threshold"),
position: new THREE.Vector3(3.72, topHeight + 0.60, sideDoorZ)
}
];
const projected = new THREE.Vector3();
function updatePins() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const pin of pins) {
projected.copy(pin.position).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -50 &&
x < width + 50 &&
y > -50 &&
y < height + 50;
pin.element.style.display = visible ? "flex" : "none";
pin.element.style.left = `${x}px`;
pin.element.style.top = `${y}px`;
}
}
// -------------------------------------------------------------------------
// Custom orbit, zoom, and touch controls
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
const pointers = new Map();
let previousPinchDistance = 0;
function pointerDistance() {
const points = [...pointers.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const current = { x: event.clientX, y: event.clientY };
pointers.set(event.pointerId, current);
if (pointers.size === 1) {
const dx = current.x - previous.x;
const dy = current.y - previous.y;
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.0045,
0.22,
1.18
);
updateCamera();
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
orbit.distance = THREE.MathUtils.clamp(
orbit.distance * (previousPinchDistance / distance),
10,
31
);
updateCamera();
}
previousPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointers.size === 2 ? pointerDistance() : 0;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("pointerleave", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.distance = THREE.MathUtils.clamp(
orbit.distance * Math.exp(event.deltaY * 0.001),
10,
31
);
updateCamera();
},
{ passive: false }
);
function resetView() {
orbit.yaw = defaultOrbit.yaw;
orbit.pitch = defaultOrbit.pitch;
orbit.distance = defaultOrbit.distance;
orbit.target.copy(defaultOrbit.target);
updateCamera();
}
document.getElementById("reset-view").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
renderer.setAnimationLoop(() => {
updatePins();
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
const loading = document.getElementById("loading");
loading.style.opacity = "0";
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```