Prompt specification
Build or customize the Three.js 3D scene "Small vaulted market hall" 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: Small vaulted market hall
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/small-vaulted-market-hall-x2235
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a low-poly market hall with three vaulted bays. Heavy piers divide the hall, supporting curved roof surfaces above an open central walking aisle. Keep two bays intact and cut away part of the third to expose the vault thickness and its connection to the supports. Place modest produce stalls along the outer edges, leaving the central route unobstructed. Use warm masonry, darker paving, and narrow openings that bring light across the curved ceilings.
Working Three.js Starter (small-vaulted-market-hall-x2235):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Three-Bay Market Hall</title>
<style>
:root {
color-scheme: dark;
--ink: #f1dfc4;
--muted: #baa98f;
--line: rgba(241, 223, 196, 0.22);
--panel: rgba(28, 25, 22, 0.82);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #181817;
}
body {
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.panel {
position: fixed;
z-index: 2;
pointer-events: none;
}
.title {
top: 24px;
left: 28px;
max-width: min(390px, calc(100vw - 56px));
padding: 15px 18px 14px;
border: 1px solid var(--line);
border-left: 3px solid #d7a465;
background: var(--panel);
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(10px);
}
.eyebrow {
margin-bottom: 5px;
color: #d7a465;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(22px, 3vw, 34px);
font-weight: 500;
line-height: 1.08;
}
.subtitle {
margin-top: 8px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.help {
right: 24px;
bottom: 22px;
padding: 10px 13px;
border: 1px solid var(--line);
background: var(--panel);
color: var(--muted);
font-size: 11px;
letter-spacing: 0.02em;
backdrop-filter: blur(10px);
}
.help strong {
color: var(--ink);
font-weight: 600;
}
button {
position: fixed;
z-index: 3;
right: 24px;
top: 24px;
padding: 9px 12px;
border: 1px solid var(--line);
background: var(--panel);
color: var(--ink);
font: inherit;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(10px);
}
button:hover {
border-color: #d7a465;
color: #ffdda7;
}
@media (max-width: 650px) {
.title { top: 14px; left: 14px; }
.subtitle { display: none; }
button { top: 14px; right: 14px; }
.help { right: 14px; bottom: 14px; }
}
</style>
</head>
<body>
<div class="panel title">
<div class="eyebrow">Architectural Section Study</div>
<h1>Three-Bay Market Hall</h1>
<div class="subtitle">
Warm masonry vaults, heavy dividing piers, and a clear central market route.
The near half of the third bay is removed to reveal the vault construction.
</div>
</div>
<button id="reset" type="button">Reset view</button>
<div class="panel help">
<strong>Drag</strong> to orbit · <strong>Wheel</strong> to zoom · <strong>Right-drag</strong> to pan
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.createElement("canvas");
document.body.appendChild(canvas);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x191a19);
scene.fog = new THREE.Fog(0x191a19, 29, 58);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const defaultTarget = new THREE.Vector3(0.25, 2.25, 0);
camera.position.set(17.5, 12.2, 17.8);
camera.lookAt(defaultTarget);
const target = defaultTarget.clone();
const spherical = new THREE.Spherical().setFromVector3(
camera.position.clone().sub(target)
);
// -------------------------------------------------------------------------
// Palette and materials
// -------------------------------------------------------------------------
const materials = {
plinth: new THREE.MeshStandardMaterial({
color: 0x4b3a31, roughness: 0.93, flatShading: true
}),
paving: new THREE.MeshStandardMaterial({
color: 0xffffff, roughness: 0.98, flatShading: true
}),
pavingEdge: new THREE.MeshStandardMaterial({
color: 0x55534d, roughness: 0.92
}),
wall: new THREE.MeshStandardMaterial({
color: 0xa9774f, roughness: 0.94, flatShading: true
}),
wallDark: new THREE.MeshStandardMaterial({
color: 0x8d6041, roughness: 0.95, flatShading: true
}),
pier: new THREE.MeshStandardMaterial({
color: 0x9b6946, roughness: 0.92, flatShading: true
}),
pierLight: new THREE.MeshStandardMaterial({
color: 0xb17b51, roughness: 0.9, flatShading: true
}),
pierDark: new THREE.MeshStandardMaterial({
color: 0x80553c, roughness: 0.96, flatShading: true
}),
vaultA: new THREE.MeshStandardMaterial({
color: 0xc08351, roughness: 0.9, flatShading: true,
side: THREE.DoubleSide,
emissive: 0x2d1308, emissiveIntensity: 0.12
}),
vaultB: new THREE.MeshStandardMaterial({
color: 0xb8784b, roughness: 0.92, flatShading: true,
side: THREE.DoubleSide,
emissive: 0x2d1308, emissiveIntensity: 0.1
}),
vaultOuter: new THREE.MeshStandardMaterial({
color: 0x704b38, roughness: 0.97, flatShading: true,
side: THREE.DoubleSide
}),
cutStone: new THREE.MeshStandardMaterial({
color: 0xd0a16c, roughness: 0.88, flatShading: true,
side: THREE.DoubleSide
}),
rib: new THREE.MeshStandardMaterial({
color: 0x9c6844, roughness: 0.92, flatShading: true
}),
cutEdge: new THREE.MeshStandardMaterial({
color: 0xe0b77c, roughness: 0.82, flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: 0x72503a, roughness: 0.95, flatShading: true
}),
woodLight: new THREE.MeshStandardMaterial({
color: 0x95704a, roughness: 0.94, flatShading: true
}),
woodDark: new THREE.MeshStandardMaterial({
color: 0x49352a, roughness: 1, flatShading: true
}),
crate: new THREE.MeshStandardMaterial({
color: 0x8d6643, roughness: 0.96, flatShading: true
}),
clothRed: new THREE.MeshStandardMaterial({
color: 0x9b4f3d, roughness: 1, flatShading: true
}),
clothGreen: new THREE.MeshStandardMaterial({
color: 0x697253, roughness: 1, flatShading: true
}),
clothOchre: new THREE.MeshStandardMaterial({
color: 0xb18548, roughness: 1, flatShading: true
}),
clothBlue: new THREE.MeshStandardMaterial({
color: 0x536d72, roughness: 1, flatShading: true
}),
glow: new THREE.MeshBasicMaterial({
color: 0xffd58a,
side: THREE.DoubleSide
}),
windowGlow: new THREE.MeshBasicMaterial({
color: 0xffc978,
side: THREE.DoubleSide
}),
ground: new THREE.MeshStandardMaterial({
color: 0x1d2222, roughness: 1
})
};
const fruitMaterials = {
red: new THREE.MeshStandardMaterial({
color: 0xb94f36, roughness: 0.82, flatShading: true
}),
gold: new THREE.MeshStandardMaterial({
color: 0xd29a38, roughness: 0.85, flatShading: true
}),
green: new THREE.MeshStandardMaterial({
color: 0x718149, roughness: 0.9, flatShading: true
}),
plum: new THREE.MeshStandardMaterial({
color: 0x76506b, roughness: 0.86, flatShading: true
})
};
function addBox(w, h, d, x, y, z, material, cast = true, receive = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Floor and surrounding ground
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(new THREE.PlaneGeometry(80, 80), materials.ground);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.52;
ground.receiveShadow = true;
scene.add(ground);
addBox(19.25, 0.42, 12.15, 0.05, -0.24, 0, materials.plinth);
addBox(18.45, 0.12, 10.4, 0.05, -0.02, 0, materials.wallDark);
const tileGeometry = new THREE.BoxGeometry(0.87, 0.065, 0.87);
const tileCountX = 19;
const tileCountZ = 11;
const tiles = new THREE.InstancedMesh(
tileGeometry,
materials.paving,
tileCountX * tileCountZ
);
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let ix = 0; ix < tileCountX; ix++) {
for (let iz = 0; iz < tileCountZ; iz++) {
const x = -8.1 + ix * 0.9;
const z = -4.5 + iz * 0.9;
dummy.position.set(x, 0.055, z);
dummy.rotation.y = ((ix * 7 + iz * 11) % 3 - 1) * 0.004;
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const aisle = Math.abs(z) < 1.35;
const variation = ((ix * 13 + iz * 17) % 7) * 0.009;
if (aisle) {
tileColor.setHSL(0.11, 0.07, 0.22 + variation);
} else {
tileColor.setHSL(0.095, 0.08, 0.18 + variation);
}
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
// Flush paving borders define the unobstructed central route.
addBox(16.55, 0.035, 0.075, 0.05, 0.095, -1.58, materials.pavingEdge, false, true);
addBox(16.55, 0.035, 0.075, 0.05, 0.095, 1.58, materials.pavingEdge, false, true);
// -------------------------------------------------------------------------
// Masonry piers
// -------------------------------------------------------------------------
const pierXs = [-8.2, -2.72, 2.8, 8.32];
const pierZ = 4.62;
function addPier(x, z) {
addBox(1.22, 0.26, 1.22, x, 0.13, z, materials.pierDark);
addBox(1.02, 0.26, 1.02, x, 0.39, z, materials.pierLight);
for (let i = 0; i < 5; i++) {
const mat = i % 2 === 0 ? materials.pier : materials.pierLight;
const jitter = (i % 2 ? 1 : -1) * 0.015;
addBox(
0.82 + jitter,
0.535,
0.86 - jitter,
x + jitter,
0.81 + i * 0.56,
z - jitter,
mat
);
}
addBox(1.08, 0.27, 1.08, x, 3.45, z, materials.pierDark);
addBox(1.18, 0.16, 1.18, x, 3.64, z, materials.pierLight);
}
for (const x of pierXs) {
addPier(x, -pierZ);
addPier(x, pierZ);
}
// -------------------------------------------------------------------------
// Side walls with narrow slit openings
// -------------------------------------------------------------------------
const WALL_HEIGHT = 3.8;
const WINDOW_BOTTOM = 2.08;
const WINDOW_TOP = 3.52;
const WINDOW_WIDTH = 0.46;
function addSlitWall(x0, x1, z, height, centers) {
const length = x1 - x0;
const centerX = (x0 + x1) / 2;
if (height >= WINDOW_BOTTOM) {
addBox(length, WINDOW_BOTTOM, 0.34, centerX, WINDOW_BOTTOM / 2, z, materials.wall);
}
if (height > WINDOW_TOP) {
addBox(length, height - WINDOW_TOP, 0.34, centerX, (height + WINDOW_TOP) / 2, z, materials.wall);
}
let cursor = x0;
const usable = centers.filter(c => c - WINDOW_WIDTH / 2 > x0 && c + WINDOW_WIDTH / 2 < x1);
for (const wx of usable) {
const left = wx - WINDOW_WIDTH / 2;
const right = wx + WINDOW_WIDTH / 2;
if (left > cursor + 0.001) {
const width = left - cursor;
addBox(
width,
Math.max(0.01, WINDOW_TOP - WINDOW_BOTTOM),
0.34,
cursor + width / 2,
(WINDOW_TOP + WINDOW_BOTTOM) / 2,
z,
materials.wall
);
}
cursor = right;
addBox(0.62, 0.11, 0.49, wx, WINDOW_BOTTOM - 0.02, z, materials.pierLight);
addBox(0.62, 0.12, 0.49, wx, WINDOW_TOP + 0.03, z, materials.pierLight);
const glow = new THREE.Mesh(
new THREE.PlaneGeometry(WINDOW_WIDTH * 0.78, WINDOW_TOP - WINDOW_BOTTOM - 0.06),
materials.windowGlow
);
glow.position.set(wx, (WINDOW_TOP + WINDOW_BOTTOM) / 2, z + (z > 0 ? -0.19 : 0.19));
if (z > 0) glow.rotation.y = Math.PI;
scene.add(glow);
}
if (cursor < x1 - 0.001) {
const width = x1 - cursor;
addBox(
width,
Math.max(0.01, WINDOW_TOP - WINDOW_BOTTOM),
0.34,
cursor + width / 2,
(WINDOW_TOP + WINDOW_BOTTOM) / 2,
z,
materials.wall
);
}
}
const farWindows = [-6.72, -3.74, -0.58, 2.76, 6.2];
const nearWindows = [-6.72, -3.74, -0.58];
addSlitWall(-8.2, 8.32, -4.98, WALL_HEIGHT, farWindows);
addSlitWall(-8.2, 2.8, 4.98, WALL_HEIGHT, nearWindows);
// The third bay's near wall is cut down with the roof.
addBox(5.52, 1.08, 0.36, 5.56, 0.54, 4.98, materials.wall);
// Longitudinal wall cornices.
addBox(16.52, 0.22, 0.45, 0.06, 3.68, -4.94, materials.pierDark);
addBox(11.0, 0.22, 0.45, -2.7, 3.68, 4.94, materials.pierDark);
// -------------------------------------------------------------------------
// Far end wall and arched entrance
// -------------------------------------------------------------------------
const gableShape = new THREE.Shape();
gableShape.moveTo(-5.08, 3.72);
for (let i = 0; i <= 24; i++) {
const a = Math.PI - (i / 24) * Math.PI;
gableShape.lineTo(5.08 * Math.cos(a), 3.72 + 3.15 * Math.sin(a));
}
gableShape.lineTo(1.56, 3.72);
gableShape.lineTo(1.56, 2.62);
for (let i = 0; i <= 20; i++) {
const a = (i / 20) * Math.PI;
gableShape.lineTo(1.56 * Math.cos(a), 2.62 + 1.78 * Math.sin(a));
}
gableShape.lineTo(-5.08, 3.72);
gableShape.closePath();
const gableGeometry = new THREE.ExtrudeGeometry(gableShape, {
depth: 0.4,
bevelEnabled: false,
curveSegments: 1
});
gableGeometry.rotateY(Math.PI / 2);
const gable = new THREE.Mesh(gableGeometry, materials.wall);
gable.position.x = -8.45;
gable.castShadow = true;
gable.receiveShadow = true;
scene.add(gable);
addBox(0.4, 3.72, 3.5, -8.25, 1.86, -3.31, materials.wall);
addBox(0.4, 3.72, 3.5, -8.25, 1.86, 3.31, materials.wall);
const portalPoints = [
new THREE.Vector3(-8.0, 0, 1.56),
new THREE.Vector3(-8.0, 2.62, 1.56)
];
for (let i = 0; i <= 20; i++) {
const a = (i / 20) * Math.PI;
portalPoints.push(new THREE.Vector3(
-8.0,
2.62 + 1.78 * Math.sin(a),
1.56 * Math.cos(a)
));
}
portalPoints.push(new THREE.Vector3(-8.0, 0, -1.56));
const portalCurve = new THREE.CatmullRomCurve3(portalPoints, false, "catmullrom", 0.12);
const portal = new THREE.Mesh(
new THREE.TubeGeometry(portalCurve, 36, 0.115, 5, false),
materials.pierLight
);
portal.castShadow = true;
scene.add(portal);
// -------------------------------------------------------------------------
// Faceted barrel-vault shells
// -------------------------------------------------------------------------
const SPRING = 3.72;
const VAULT_R = 4.72;
const VAULT_H = 2.85;
const VAULT_T = 0.30;
function innerPoint(a) {
return new THREE.Vector3(
0,
SPRING + VAULT_H * Math.cos(a),
VAULT_R * Math.sin(a)
);
}
function outerPoint(a) {
return new THREE.Vector3(
0,
SPRING + (VAULT_H + VAULT_T) * Math.cos(a),
(VAULT_R + VAULT_T) * Math.sin(a)
);
}
function makeVaultSurface(x0, x1, angles, outer = false) {
const positions = [];
const indices = [];
for (const a of angles) {
const p = outer ? outerPoint(a) : innerPoint(a);
positions.push(x0, p.y, p.z, x1, p.y, p.z);
}
for (let i = 0; i < angles.length - 1; i++) {
const a = i * 2;
const b = (i + 1) * 2;
indices.push(a, a + 1, b + 1, a, b + 1, b);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeVaultEndCap(x, angles, outer = false) {
const positions = [];
const indices = [];
for (let i = 0; i < angles.length - 1; i++) {
const p0 = outer ? outerPoint(angles[i]) : innerPoint(angles[i]);
const p1 = outer ? outerPoint(angles[i + 1]) : innerPoint(angles[i + 1]);
const offset = positions.length / 3;
positions.push(
x, p0.y, p0.z,
x, p1.y, p1.z,
x, p1.y, p1.z,
x, p0.y, p0.z
);
indices.push(offset, offset + 1, offset + 2, offset, offset + 3, offset + 4);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeAngularCap(x0, x1, a) {
const inner = innerPoint(a);
const outer = outerPoint(a);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute([
x0, inner.y, inner.z,
x1, inner.y, inner.z,
x1, outer.y, outer.z,
x0, outer.y, outer.z
], 3));
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
return geometry;
}
function addVault(x0, x1, a0, a1, segmentCount, innerMaterial) {
const angles = [];
for (let i = 0; i <= segmentCount; i++) {
angles.push(a0 + (a1 - a0) * (i / segmentCount));
}
const inner = new THREE.Mesh(
makeVaultSurface(x0, x1, angles, false),
innerMaterial
);
inner.receiveShadow = true;
scene.add(inner);
const outer = new THREE.Mesh(
makeVaultSurface(x0, x1, angles, true),
materials.vaultOuter
);
outer.castShadow = true;
outer.receiveShadow = true;
scene.add(outer);
for (const x of [x0, x1]) {
const cap = new THREE.Mesh(
makeVaultEndCap(x, angles, false),
materials.cutStone
);
cap.castShadow = true;
cap.receiveShadow = true;
scene.add(cap);
}
for (const a of [a0, a1]) {
const cap = new THREE.Mesh(
makeAngularCap(x0, x1, a),
materials.cutStone
);
cap.castShadow = true;
cap.receiveShadow = true;
scene.add(cap);
}
}
// Two complete bays.
addVault(-8.2, -2.72, -Math.PI / 2, Math.PI / 2, 16, materials.vaultA);
addVault(-2.72, 2.8, -Math.PI / 2, Math.PI / 2, 16, materials.vaultB);
// Third bay: the near half is removed.
const CUT_ANGLE = 0.28;
addVault(2.8, 8.32, -Math.PI / 2, CUT_ANGLE, 10, materials.vaultA);
// Transverse arch ribs.
function addArchRib(x, a0, a1) {
const points = [];
const count = a1 === CUT_ANGLE ? 11 : 20;
for (let i = 0; i <= count; i++) {
const a = a0 + (a1 - a0) * (i / count);
points.push(new THREE.Vector3(
x,
SPRING + (VAULT_H - 0.08) * Math.cos(a),
(VAULT_R - 0.08) * Math.sin(a)
));
}
const curve = new THREE.CatmullRomCurve3(points, false, "catmullrom", 0.1);
const rib = new THREE.Mesh(
new THREE.TubeGeometry(curve, count * 2, 0.135, 5, false),
materials.rib
);
rib.castShadow = true;
rib.receiveShadow = true;
scene.add(rib);
}
addArchRib(-8.2, -Math.PI / 2, Math.PI / 2);
addArchRib(-2.72, -Math.PI / 2, Math.PI / 2);
addArchRib(2.8, -Math.PI / 2, Math.PI / 2);
addArchRib(8.32, -Math.PI / 2, CUT_ANGLE);
// Longitudinal ceiling beams.
addBox(5.48, 0.15, 0.24, -5.46, 6.48, 0, materials.rib);
addBox(5.52, 0.15, 0.24, 0.04, 6.48, 0, materials.rib);
addBox(5.52, 0.15, 0.24, 5.56, 6.48, 0, materials.rib);
// Pale longitudinal edges emphasize the thickness of the cutaway.
function addCutEdge(x0, x1, angle, outer = false) {
const p = outer ? outerPoint(angle) : innerPoint(angle);
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(x0, p.y, p.z),
new THREE.Vector3((x0 + x1) / 2, p.y, p.z),
new THREE.Vector3(x1, p.y, p.z)
]);
const edge = new THREE.Mesh(
new THREE.TubeGeometry(curve, 8, 0.035, 4, false),
materials.cutEdge
);
scene.add(edge);
}
addCutEdge(2.8, 8.32, CUT_ANGLE, false);
addCutEdge(2.8, 8.32, CUT_ANGLE, true);
// -------------------------------------------------------------------------
// Narrow bands of light across the curved ceilings
// -------------------------------------------------------------------------
const ceilingLightMaterial = new THREE.MeshBasicMaterial({
color: 0xffd88d,
transparent: true,
opacity: 0.19,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending
});
function addCeilingLightBand(baseX, slope, a0, a1, width = 0.42) {
const positions = [];
const indices = [];
const steps = 20;
for (let i = 0; i <= steps; i++) {
const a = a0 + (a1 - a0) * (i / steps);
const p = innerPoint(a);
const center = baseX + slope * (a - a0);
positions.push(
center - width / 2, p.y - 0.045, p.z,
center + width / 2, p.y - 0.045, p.z
);
}
for (let i = 0; i < steps; i++) {
const a = i * 2;
const b = (i + 1) * 2;
indices.push(a, a + 1, b + 1, a, b + 1, b);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const band = new THREE.Mesh(geometry, ceilingLightMaterial);
scene.add(band);
}
addCeilingLightBand(-6.6, 0.68, -0.98, 0.52);
addCeilingLightBand(-0.55, 0.72, -0.98, 0.52);
addCeilingLightBand(2.75, 0.64, -1.15, 0.46);
addCeilingLightBand(6.15, 0.62, -1.36, 0.18);
// -------------------------------------------------------------------------
// Modest produce stalls along the outer edges
// -------------------------------------------------------------------------
function addCrate(x, y, z, fruitMaterial, seed) {
const w = 0.6;
const d = 0.52;
const h = 0.22;
addBox(w, 0.055, d, x, y + 0.025, z, materials.woodDark);
addBox(w, h, 0.045, x, y + h / 2, z - d / 2, materials.crate);
addBox(w, h, 0.045, x, y + h / 2, z + d / 2, materials.crate);
addBox(0.045, h, d, x - w / 2, y + h / 2, z, materials.crate);
addBox(0.045, h, d, x + w / 2, y + h / 2, z, materials.crate);
const geometry = new THREE.SphereGeometry(0.105, 6, 4);
for (let i = 0; i < 5; i++) {
const fruit = new THREE.Mesh(geometry, fruitMaterial);
const n = seed + i * 1.73;
fruit.position.set(
x + Math.sin(n * 2.1) * 0.18,
y + 0.19 + (i % 2) * 0.025,
z + Math.cos(n * 1.7) * 0.12
);
fruit.scale.set(
0.9 + Math.abs(Math.sin(n)) * 0.18,
0.85 + Math.abs(Math.cos(n)) * 0.18,
0.9 + Math.abs(Math.sin(n * 0.7)) * 0.15
);
fruit.rotation.set(n * 0.2, n * 0.5, n * 0.13);
fruit.castShadow = true;
scene.add(fruit);
}
}
function addStall(x, z, outwardSide, fruitMaterial, clothMaterial, seed) {
const tableY = 0.93;
addBox(2.12, 0.14, 0.9, x, tableY, z, materials.woodLight);
for (const dx of [-0.91, 0.91]) {
for (const dz of [-0.32, 0.32]) {
addBox(0.12, 0.83, 0.12, x + dx, 0.415, z + dz, materials.woodDark);
}
}
addBox(1.96, 0.035, 0.76, x, tableY + 0.09, z, clothMaterial);
// Small canvas canopy, held mainly from the outer edge.
const canopyZ = z + outwardSide * 0.09;
const canopy = addBox(2.28, 0.065, 1.13, x, 2.05, canopyZ, clothMaterial);
canopy.rotation.x = outwardSide * 0.055;
for (const dx of [-1.02, 1.02]) {
addBox(
0.075,
1.04,
0.075,
x + dx,
1.51,
z + outwardSide * 0.49,
materials.woodDark
);
}
const valanceZ = z - outwardSide * 0.47;
addBox(2.24, 0.25, 0.045, x, 1.94, valanceZ, clothMaterial);
const offsets = [-0.7, 0, 0.7];
offsets.forEach((offset, i) => {
addCrate(x + offset, tableY + 0.12, z, fruitMaterial, seed + i * 3.1);
});
}
addStall(-5.45, 3.58, 1, fruitMaterials.green, materials.clothGreen, 1.2);
addStall(-0.15, -3.57, -1, fruitMaterials.red, materials.clothRed, 4.8);
addStall(-1.4, 3.57, 1, fruitMaterials.gold, materials.clothOchre, 8.4);
addStall(5.35, -3.57, -1, fruitMaterials.plum, materials.clothBlue, 12.1);
addStall(6.15, 3.58, 1, fruitMaterials.gold, materials.clothOchre, 16.7);
// A few empty baskets remain outside the walking route.
function addBasket(x, y, z) {
addBox(0.54, 0.24, 0.42, x, y + 0.12, z, materials.woodDark);
addBox(0.59, 0.055, 0.46, x, y + 0.25, z, materials.woodLight);
}
addBasket(-4.15, 0.09, 3.18);
addBasket(1.25, 0.09, -3.15);
addBasket(4.18, 0.09, -3.18);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemi = new THREE.HemisphereLight(0xf1d6ad, 0x303b3d, 1.55);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffe1b3, 2.45);
keyLight.position.set(-8, 15, 10);
keyLight.target.position.set(0, 1.5, 0);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -16;
keyLight.shadow.camera.right = 16;
keyLight.shadow.camera.top = 16;
keyLight.shadow.camera.bottom = -16;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 42;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight, keyLight.target);
const rimLight = new THREE.DirectionalLight(0x8ba2a7, 0.72);
rimLight.position.set(10, 7, -13);
scene.add(rimLight);
// Warm spotlights correspond to the slit windows on the far wall.
farWindows.forEach((wx, index) => {
const light = new THREE.SpotLight(
0xffc978,
index === 2 ? 62 : 48,
18,
0.29,
0.5,
1.25
);
light.position.set(wx, 3.05, -6.25);
light.target.position.set(wx + 0.45, 6.0, -0.4);
scene.add(light, light.target);
const fill = new THREE.PointLight(0xffb865, 7, 4.8, 1.7);
fill.position.set(wx, 2.85, -4.55);
scene.add(fill);
});
// -------------------------------------------------------------------------
// Floating dust in the warm light
// -------------------------------------------------------------------------
const dustCount = 110;
const dustPositions = new Float32Array(dustCount * 3);
const dustBase = [];
for (let i = 0; i < dustCount; i++) {
const x = -7.8 + ((i * 7.13) % 15.6);
const y = 0.35 + ((i * 2.71) % 5.7);
const z = -4.35 + ((i * 4.37) % 8.7);
dustPositions[i * 3] = x;
dustPositions[i * 3 + 1] = y;
dustPositions[i * 3 + 2] = z;
dustBase.push({ x, y, z, phase: i * 0.57 });
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xffd9a1,
size: 0.035,
transparent: true,
opacity: 0.38,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(dust);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, wheel zoom, and touch pinch
// -------------------------------------------------------------------------
const pointers = new Map();
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.22, 1.48);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 11, 36);
spherical.makeSafe();
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
function panCamera(dx, dy) {
const scale = spherical.radius * 0.00125;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0).normalize();
const direction = camera.getWorldDirection(new THREE.Vector3());
const screenUp = new THREE.Vector3().crossVectors(right, direction).normalize();
target.addScaledVector(right, -dx * scale);
target.addScaledVector(screenUp, dy * scale);
target.x = THREE.MathUtils.clamp(target.x, -8, 8);
target.y = THREE.MathUtils.clamp(target.y, 0.5, 5.5);
target.z = THREE.MathUtils.clamp(target.z, -6, 6);
}
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const oldPositions = [...pointers.values()];
const old = pointers.get(event.pointerId);
const dx = event.clientX - old.x;
const dy = event.clientY - old.y;
if (pointers.size >= 2) {
const oldDistance = Math.hypot(
oldPositions[0].x - oldPositions[1].x,
oldPositions[0].y - oldPositions[1].y
);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
const newPositions = [...pointers.values()];
const newDistance = Math.hypot(
newPositions[0].x - newPositions[1].x,
newPositions[0].y - newPositions[1].y
);
if (oldDistance > 0 && newDistance > 0) {
spherical.radius *= oldDistance / newDistance;
}
} else {
if (event.pointerType === "mouse" && (event.buttons & 2)) {
panCamera(dx, dy);
} else {
spherical.theta -= dx * 0.0052;
spherical.phi -= dy * 0.0045;
}
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
function resetView() {
target.copy(defaultTarget);
camera.position.set(17.5, 12.2, 17.8);
spherical.setFromVector3(camera.position.clone().sub(target));
updateCamera();
}
document.getElementById("reset").addEventListener("click", resetView);
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
const time = clock.getElapsedTime();
const positions = dust.geometry.attributes.position;
for (let i = 0; i < dustCount; i++) {
const base = dustBase[i];
positions.array[i * 3] = base.x + Math.sin(time * 0.18 + base.phase) * 0.12;
positions.array[i * 3 + 1] = base.y + Math.sin(time * 0.25 + base.phase) * 0.16;
positions.array[i * 3 + 2] = base.z + Math.cos(time * 0.16 + base.phase) * 0.1;
}
positions.needsUpdate = true;
ceilingLightMaterial.opacity = 0.17 + Math.sin(time * 0.55) * 0.025;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
animate();
</script>
</body>
</html>
```