Prompt specification
Build or customize the Three.js 3D scene "Marrakech stall canopy and paving module" 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: Marrakech stall canopy and paving module
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/marrakech-stall-canopy-and-paving-module-x2937
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: Marrakech stall canopy and paving module. Build a referenced simple stall canopy on a Jemaa el-Fna paving tile. Keep the temporary structure distinct from the permanent square surface and surrounding circulation. Return one self-contained HTML file.
Working Three.js Starter (marrakech-stall-canopy-and-paving-module-x2937):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Marrakech Canopy & Paving Module</title>
<style>
:root {
--ink: #342b24;
--muted: #74675b;
--paper: rgba(250, 244, 232, 0.86);
--line: rgba(78, 59, 42, 0.18);
--terracotta: #a9523e;
--sand: #d4b47f;
--sage: #718b82;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9d9bd;
color: var(--ink);
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; }
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.title-card {
position: absolute;
top: 24px;
left: 26px;
max-width: min(390px, calc(100vw - 52px));
padding: 18px 20px 17px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 14px 40px rgba(77, 55, 35, 0.11);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 8px;
color: var(--terracotta);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 39px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.legend {
position: absolute;
left: 26px;
bottom: 25px;
width: 218px;
padding: 14px 16px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 14px 40px rgba(77, 55, 35, 0.1);
backdrop-filter: blur(12px);
}
.legend-title {
margin-bottom: 10px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
color: var(--muted);
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 8px;
font-size: 11px;
color: #51463d;
}
.swatch {
position: relative;
flex: 0 0 22px;
width: 22px;
height: 14px;
border: 1px solid rgba(57, 43, 32, 0.16);
}
.swatch.permanent {
background: #c89c68;
box-shadow: inset 0 0 0 3px #e8cc99;
}
.swatch.temporary {
height: 10px;
background: repeating-linear-gradient(
90deg,
#b55d47 0 5px,
#e7d5b2 5px 10px
);
transform: skewY(-7deg);
}
.swatch.circulation {
background: #d8c7aa;
box-shadow: inset 0 0 0 3px #eee1ca;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
color: var(--muted);
font-size: 10px;
box-shadow: 0 14px 40px rgba(77, 55, 35, 0.1);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.controls strong {
color: var(--ink);
font-weight: 700;
}
button {
border: 1px solid rgba(78, 59, 42, 0.2);
border-radius: 3px;
padding: 7px 9px;
background: rgba(255,255,255,0.58);
color: var(--ink);
font: inherit;
font-size: 10px;
cursor: pointer;
}
button:hover { background: #fffaf0; }
.anchor {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
border: 1px solid rgba(71, 54, 40, 0.17);
border-radius: 3px;
background: rgba(250, 244, 232, 0.91);
box-shadow: 0 5px 16px rgba(68, 47, 31, 0.12);
color: #4d4036;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.075em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
transition: opacity 160ms ease;
}
.anchor::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--terracotta);
box-shadow: 0 0 0 3px rgba(169, 82, 62, 0.14);
}
.anchor.canopy::before { background: #bc654e; }
.anchor.circulation::before { background: var(--sage); }
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #ead9bb;
color: #604d3e;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hide {
opacity: 0;
visibility: hidden;
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
padding: 14px 15px;
}
.subtitle { display: none; }
.legend { left: 14px; bottom: 14px; width: 188px; }
.controls { right: 14px; bottom: 14px; }
.controls .hint { display: none; }
.anchor { font-size: 8px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly Marrakech stall canopy on a patterned paving tile"></canvas>
<div class="ui">
<section class="title-card">
<div class="eyebrow">Jemaa el-Fna · Public Realm Study</div>
<h1>Canopy &<br>Paving Module</h1>
<p class="subtitle">
A removable market stall set within a permanent geometric paving square,
separated from the surrounding pedestrian circulation.
</p>
</section>
<section class="legend" aria-label="Scene legend">
<div class="legend-title">Material & spatial hierarchy</div>
<div class="legend-row"><i class="swatch permanent"></i>Permanent paving module</div>
<div class="legend-row"><i class="swatch temporary"></i>Temporary canopy structure</div>
<div class="legend-row"><i class="swatch circulation"></i>Clear circulation ring</div>
</section>
<div class="controls">
<span class="hint"><strong>Drag</strong> orbit · <strong>Shift-drag</strong> pan · <strong>Scroll</strong> zoom</span>
<button id="reset" type="button">Reset view</button>
</div>
<div id="label-tile" class="anchor">Permanent square</div>
<div id="label-canopy" class="anchor canopy">Temporary canopy</div>
<div id="label-flow" class="anchor circulation">Circulation</div>
</div>
<div id="loading">Assembling the square…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9d9bd);
scene.fog = new THREE.Fog(0xe9d9bd, 24, 46);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const controls = {
target: new THREE.Vector3(0, 0.65, 0),
theta: 0.64,
phi: 0.78,
radius: 18.5
};
const hemi = new THREE.HemisphereLight(0xfff3d8, 0x80674e, 1.75);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe1b0, 3.25);
sun.position.set(-8, 14, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00045;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9cc4cf, 0.75);
fill.position.set(9, 7, -9);
scene.add(fill);
const standard = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...extra
});
const materials = {
ground: standard(0xb89b77),
paver: standard(0xffffff),
tile: standard(0xc79862),
tileBorder: standard(0xe7c892),
tileDark: standard(0x96513f),
tileLight: standard(0xead5ad),
circulation: standard(0xd8c7aa),
circulationInk: standard(0x6e8981),
wood: standard(0x775139),
woodLight: standard(0xa9794d),
woodDark: standard(0x4c382c),
rope: standard(0xbca77d),
coral: standard(0xb95e47, { side: THREE.DoubleSide }),
cream: standard(0xe8d8b7, { side: THREE.DoubleSide }),
sage: standard(0x6f887c),
terracotta: standard(0xb45d43),
basket: standard(0xb18450),
basketDark: standard(0x765535),
fruitOrange: standard(0xd98232),
fruitLemon: standard(0xd9b747),
fruitGreen: standard(0x748e4f),
charcoal: standard(0x3e3831),
plaster: standard(0xc59e72),
plasterLight: standard(0xd4b486),
distantRoof: standard(0x9e604c),
skin: standard(0x9a674b),
white: standard(0xe9dfc7)
};
function addMesh(geometry, material, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(w, h, d, material, parent = scene, x = 0, y = 0, z = 0) {
const mesh = addMesh(new THREE.BoxGeometry(w, h, d), material, parent);
mesh.position.set(x, y, z);
return mesh;
}
function beam(a, b, radius, material, parent = scene, sides = 6) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const mesh = addMesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), sides),
material,
parent
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
return mesh;
}
function surface(points, material, parent = scene) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(points.flat(), 3)
);
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
return addMesh(geometry, material, parent);
}
function starShape(points, outerRadius, innerRadius, rotation = Math.PI / 2) {
const shape = new THREE.Shape();
for (let i = 0; i < points * 2; i++) {
const radius = i % 2 === 0 ? outerRadius : innerRadius;
const angle = rotation + (i / (points * 2)) * Math.PI * 2;
const x = Math.cos(angle) * radius;
const y = Math.sin(angle) * radius;
if (i === 0) shape.moveTo(x, y);
else shape.lineTo(x, y);
}
shape.closePath();
return shape;
}
function shapeMesh(shape, material, x, z, y, parent = scene) {
const mesh = addMesh(new THREE.ShapeGeometry(shape), material, parent);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, y, z);
return mesh;
}
let randomSeed = 1471;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
// The broad permanent plaza and its low-poly paving field.
const plaza = addBox(29.5, 0.28, 29.5, materials.ground);
plaza.position.y = -0.18;
plaza.castShadow = false;
const paverCount = 20;
const cell = 1.5;
const paverGeometry = new THREE.BoxGeometry(cell * 0.965, 0.075, cell * 0.965);
const pavers = new THREE.InstancedMesh(paverGeometry, materials.paver, paverCount * paverCount);
pavers.receiveShadow = true;
const dummy = new THREE.Object3D();
const paverColor = new THREE.Color();
let paverIndex = 0;
for (let ix = 0; ix < paverCount; ix++) {
for (let iz = 0; iz < paverCount; iz++) {
const x = (ix - (paverCount - 1) / 2) * cell;
const z = (iz - (paverCount - 1) / 2) * cell;
dummy.position.set(x, -0.04, z);
dummy.updateMatrix();
pavers.setMatrixAt(paverIndex, dummy.matrix);
const hue = 0.085 + random() * 0.025;
const saturation = 0.23 + random() * 0.12;
const lightness = 0.58 + random() * 0.085;
paverColor.setHSL(hue, saturation, lightness);
pavers.setColorAt(paverIndex, paverColor);
paverIndex++;
}
}
pavers.instanceMatrix.needsUpdate = true;
if (pavers.instanceColor) pavers.instanceColor.needsUpdate = true;
scene.add(pavers);
// A lighter, uninterrupted pedestrian ring around the central module.
const circulationGroup = new THREE.Group();
scene.add(circulationGroup);
addBox(10.4, 0.028, 1.5, materials.circulation, circulationGroup, 0, 0.006, 4.45);
addBox(10.4, 0.028, 1.5, materials.circulation, circulationGroup, 0, 0.006, -4.45);
addBox(1.5, 0.028, 7.4, materials.circulation, circulationGroup, 4.45, 0.006, 0);
addBox(1.5, 0.028, 7.4, materials.circulation, circulationGroup, -4.45, 0.006, 0);
const diamond = new THREE.Shape();
diamond.moveTo(0, 0.18);
diamond.lineTo(0.13, 0);
diamond.lineTo(0, -0.18);
diamond.lineTo(-0.13, 0);
diamond.closePath();
const markerPositions = [
[-4.45, -3.9], [-4.45, -2.0], [-4.45, 0], [-4.45, 2.0], [-4.45, 3.9],
[4.45, -3.9], [4.45, -2.0], [4.45, 0], [4.45, 2.0], [4.45, 3.9],
[-2.0, 4.45], [0, 4.45], [2.0, 4.45],
[-2.0, -4.45], [0, -4.45], [2.0, -4.45]
];
markerPositions.forEach(([x, z]) => {
shapeMesh(diamond, materials.circulationInk, x, z, 0.028, circulationGroup);
});
// Permanent, slightly raised 6 × 6 m square paving module.
const tileGroup = new THREE.Group();
scene.add(tileGroup);
const tileBase = addBox(6, 0.12, 6, materials.tile, tileGroup, 0, 0.06, 0);
tileBase.castShadow = false;
const borderY = 0.133;
addBox(0.17, 0.026, 5.66, materials.tileBorder, tileGroup, -2.915, borderY, 0);
addBox(0.17, 0.026, 5.66, materials.tileBorder, tileGroup, 2.915, borderY, 0);
addBox(5.66, 0.026, 0.17, materials.tileBorder, tileGroup, 0, borderY, -2.915);
addBox(5.66, 0.026, 0.17, materials.tileBorder, tileGroup, 0, borderY, 2.915);
addBox(0.065, 0.019, 5.2, materials.tileDark, tileGroup, -2.69, 0.126, 0);
addBox(0.065, 0.019, 5.2, materials.tileDark, tileGroup, 2.69, 0.126, 0);
addBox(5.2, 0.019, 0.065, materials.tileDark, tileGroup, 0, 0.126, -2.69);
addBox(5.2, 0.019, 0.065, materials.tileDark, tileGroup, 0, 0.126, 2.69);
shapeMesh(
starShape(8, 1.43, 0.7),
materials.tileDark,
0,
-0.06,
0.129,
tileGroup
);
shapeMesh(
starShape(8, 0.69, 0.31, Math.PI / 8),
materials.tileLight,
0,
-0.06,
0.133,
tileGroup
);
const smallRosette = starShape(4, 0.42, 0.16);
const cornerRosettes = [
[-2.08, -2.08], [2.08, -2.08], [-2.08, 2.08], [2.08, 2.08]
];
cornerRosettes.forEach(([x, z]) => {
shapeMesh(smallRosette, materials.tileDark, x, z, 0.129, tileGroup);
});
const sideRosette = starShape(4, 0.34, 0.13);
shapeMesh(sideRosette, materials.tileLight, -1.38, 0, 0.129, tileGroup);
shapeMesh(sideRosette, materials.tileLight, 1.38, 0, 0.129, tileGroup);
shapeMesh(sideRosette, materials.tileLight, 0, -1.38, 0.129, tileGroup);
shapeMesh(sideRosette, materials.tileLight, 0, 1.38, 0.129, tileGroup);
// Temporary canopy: independent poles, timber frame, and striped fabric.
const canopy = new THREE.Group();
canopy.position.set(0, 0.13, -0.12);
scene.add(canopy);
const postX = 1.68;
const postZ = 1.02;
const postBottom = 0;
const postTop = 2.66;
[
[-postX, -postZ], [postX, -postZ],
[-postX, postZ], [postX, postZ]
].forEach(([x, z]) => {
beam([x, postBottom, z], [x, postTop, z], 0.055, materials.wood, canopy, 7);
const foot = addMesh(new THREE.CylinderGeometry(0.12, 0.15, 0.1, 7), materials.woodDark, canopy);
foot.position.set(x, 0.02, z);
});
beam([-1.78, 2.66, -postZ], [1.78, 2.66, -postZ], 0.045, materials.woodDark, canopy);
beam([-1.78, 2.66, postZ], [1.78, 2.66, postZ], 0.045, materials.woodDark, canopy);
beam([-postX, 2.66, -1.12], [-postX, 2.66, 1.12], 0.045, materials.woodDark, canopy);
beam([postX, 2.66, -1.12], [postX, 2.66, 1.12], 0.045, materials.woodDark, canopy);
beam([0, 3.03, -1.16], [0, 3.03, 1.16], 0.04, materials.woodDark, canopy);
beam([-postX, 2.66, -postZ], [0, 3.03, -postZ], 0.032, materials.wood, canopy);
beam([postX, 2.66, -postZ], [0, 3.03, -postZ], 0.032, materials.wood, canopy);
beam([-postX, 2.66, postZ], [0, 3.03, postZ], 0.032, materials.wood, canopy);
beam([postX, 2.66, postZ], [0, 3.03, postZ], 0.032, materials.wood, canopy);
const roofHalfWidth = 1.9;
const roofHalfDepth = 1.22;
const ridgeHeight = 3.08;
const eaveHeight = 2.64;
function roofHeight(x, z) {
const edgeSag = 0.065 * (1 - Math.abs(z) / roofHalfDepth);
return ridgeHeight - (Math.abs(x) / roofHalfWidth) * (ridgeHeight - eaveHeight) - edgeSag;
}
const stripeCount = 12;
const stripeWidth = (roofHalfWidth * 2) / stripeCount;
for (let i = 0; i < stripeCount; i++) {
const x0 = -roofHalfWidth + i * stripeWidth;
const x1 = x0 + stripeWidth;
const fabric = i % 2 === 0 ? materials.coral : materials.cream;
const zSegments = [
[-roofHalfDepth, 0],
[0, roofHalfDepth]
];
zSegments.forEach(([z0, z1]) => {
const y0 = roofHeight(x0, z0);
const y1 = roofHeight(x1, z1);
const ya = roofHeight(x0, z1);
const yb = roofHeight(x1, z1);
surface([
[x0, y0, z0],
[x0, ya, z1],
[x1, yb, z1],
[x1, y1, z0]
], fabric, canopy);
});
// Front and back hanging valances.
[-roofHalfDepth, roofHalfDepth].forEach((z) => {
const topY = roofHeight(x0, z);
const nextTopY = roofHeight(x1, z);
surface([
[x0, topY, z],
[x1, nextTopY, z],
[x1, nextTopY - 0.17, z],
[x0, topY - 0.17, z]
], fabric, canopy);
});
}
// Guy ropes emphasize that the canopy is a lightweight temporary object.
const ropeMaterial = materials.rope;
beam([-postX, 2.62, postZ], [-2.25, 0.12, 1.72], 0.012, ropeMaterial, canopy, 5);
beam([postX, 2.62, postZ], [2.25, 0.12, 1.72], 0.012, ropeMaterial, canopy, 5);
// Market counter and goods.
const stall = new THREE.Group();
canopy.add(stall);
const counterTop = addBox(2.65, 0.12, 0.84, materials.woodLight, stall, 0, 0.96, 0.43);
counterTop.castShadow = true;
[
[-1.08, 0.12, 0.13], [1.08, 0.12, 0.13],
[-1.08, 0.12, 0.72], [1.08, 0.12, 0.72]
].forEach(([x, y, z]) => {
beam([x, y, z], [x, 0.91, z], 0.045, materials.wood, stall);
});
beam([-1.08, 0.25, 0.12], [-1.08, 0.25, 0.72], 0.035, materials.woodDark, stall);
beam([1.08, 0.25, 0.12], [1.08, 0.25, 0.72], 0.035, materials.woodDark, stall);
function addBowl(x, z, fruitMaterial, radius = 0.28) {
const bowl = addMesh(
new THREE.CylinderGeometry(radius, radius * 0.62, 0.16, 10),
materials.terracotta,
stall
);
bowl.position.set(x, 1.09, z);
const rim = addMesh(
new THREE.TorusGeometry(radius * 0.92, 0.025, 5, 10),
materials.cream,
stall
);
rim.rotation.x = Math.PI / 2;
rim.position.set(x, 1.17, z);
const fruitGeometry = new THREE.IcosahedronGeometry(0.075, 0);
for (let i = 0; i < 7; i++) {
const fruit = addMesh(fruitGeometry, fruitMaterial, stall);
const angle = (i / 7) * Math.PI * 2;
const spread = i === 0 ? 0 : radius * 0.43;
fruit.position.set(
x + Math.cos(angle) * spread,
1.2 + (i === 0 ? 0.07 : 0),
z + Math.sin(angle) * spread
);
}
}
addBowl(-0.72, 0.42, materials.fruitOrange);
addBowl(0.02, 0.44, materials.fruitLemon, 0.24);
addBowl(0.72, 0.42, materials.fruitGreen, 0.25);
function addBasket(x, z, scale = 1) {
const basket = addMesh(
new THREE.CylinderGeometry(0.31 * scale, 0.23 * scale, 0.43 * scale, 10),
materials.basket,
stall
);
basket.position.set(x, 0.23 * scale, z);
for (let i = 0; i < 3; i++) {
const band = addMesh(
new THREE.TorusGeometry((0.245 + i * 0.028) * scale, 0.014 * scale, 4, 10),
materials.basketDark,
stall
);
band.rotation.x = Math.PI / 2;
band.position.set(x, (0.09 + i * 0.12) * scale, z);
}
const lemonGeometry = new THREE.IcosahedronGeometry(0.09 * scale, 0);
for (let i = 0; i < 5; i++) {
const lemon = addMesh(lemonGeometry, materials.fruitLemon, stall);
const a = (i / 5) * Math.PI * 2;
lemon.position.set(
x + Math.cos(a) * 0.12 * scale,
0.48 * scale,
z + Math.sin(a) * 0.12 * scale
);
}
}
addBasket(-1.22, -0.62, 0.92);
function addCrate(x, y, z) {
const crate = new THREE.Group();
crate.position.set(x, y, z);
stall.add(crate);
addBox(0.58, 0.08, 0.52, materials.woodLight, crate, 0, 0, 0);
addBox(0.58, 0.08, 0.52, materials.woodLight, crate, 0, 0.42, 0);
[-0.27, 0.27].forEach((px) => {
addBox(0.055, 0.48, 0.52, materials.wood, crate, px, 0.21, 0);
});
[-0.24, 0.24].forEach((pz) => {
addBox(0.58, 0.48, 0.055, materials.wood, crate, 0, 0.21, pz);
});
}
addCrate(1.25, 0.04, -0.58);
addCrate(1.25, 0.5, -0.58);
// Folded textiles distinguish the stall as temporary retail furniture.
const textileColors = [materials.sage, materials.cream, materials.terracotta];
textileColors.forEach((mat, i) => {
const textile = addBox(0.72, 0.065, 0.5, mat, stall, -1.22, 0.06 + i * 0.07, 0.45);
textile.rotation.y = (i - 1) * 0.045;
});
// Small hanging lantern.
const lantern = new THREE.Group();
lantern.position.set(1.08, 0, 0.86);
canopy.add(lantern);
beam([0, 2.72, 0], [0, 2.29, 0], 0.012, materials.woodDark, lantern, 5);
const lanternBody = addMesh(
new THREE.CylinderGeometry(0.13, 0.11, 0.27, 6),
new THREE.MeshStandardMaterial({
color: 0xe7a75c,
emissive: 0xd8792d,
emissiveIntensity: 1.1,
roughness: 0.55,
flatShading: true
}),
lantern
);
lanternBody.position.y = 2.17;
const lanternCap = addMesh(
new THREE.CylinderGeometry(0.07, 0.15, 0.12, 6),
materials.woodDark,
lantern
);
lanternCap.position.y = 2.36;
const lanternLight = new THREE.PointLight(0xffb45e, 7, 3.5, 2);
lanternLight.position.set(1.08, 2.13, 0.86);
canopy.add(lanternLight);
// A small hand-painted-looking sign, generated locally as a texture.
const signCanvas = document.createElement("canvas");
signCanvas.width = 256;
signCanvas.height = 96;
const signContext = signCanvas.getContext("2d");
signContext.fillStyle = "#315c55";
signContext.fillRect(0, 0, 256, 96);
signContext.strokeStyle = "#d9ba72";
signContext.lineWidth = 7;
signContext.strokeRect(7, 7, 242, 82);
signContext.fillStyle = "#f3dfb5";
signContext.font = "bold 52px Georgia";
signContext.textAlign = "center";
signContext.textBaseline = "middle";
signContext.fillText("THÉ", 128, 49);
const signTexture = new THREE.CanvasTexture(signCanvas);
signTexture.colorSpace = THREE.SRGBColorSpace;
const sign = addMesh(
new THREE.PlaneGeometry(0.74, 0.28),
new THREE.MeshBasicMaterial({ map: signTexture, side: THREE.DoubleSide }),
canopy
);
sign.position.set(-0.56, 2.32, 1.245);
beam([-0.85, 2.45, 1.245], [-0.56, 2.58, 1.245], 0.01, materials.rope, canopy, 5);
beam([-0.27, 2.45, 1.245], [-0.56, 2.58, 1.245], 0.01, materials.rope, canopy, 5);
// Sparse low-poly pedestrians remain in the circulation zone.
function addPerson(x, z, robeMaterial, heading = 0, scarf = false) {
const person = new THREE.Group();
person.position.set(x, 0.04, z);
person.rotation.y = heading;
scene.add(person);
const body = addMesh(
new THREE.CylinderGeometry(0.17, 0.27, 0.83, 7),
robeMaterial,
person
);
body.position.y = 0.54;
const head = addMesh(new THREE.DodecahedronGeometry(0.15, 0), materials.skin, person);
head.position.y = 1.11;
if (scarf) {
const wrap = addMesh(
new THREE.CylinderGeometry(0.17, 0.17, 0.12, 7),
materials.white,
person
);
wrap.position.y = 1.19;
}
const legGeometry = new THREE.BoxGeometry(0.11, 0.31, 0.12);
const leftLeg = addMesh(legGeometry, materials.charcoal, person);
const rightLeg = addMesh(legGeometry, materials.charcoal, person);
leftLeg.position.set(-0.1, 0.16, 0);
rightLeg.position.set(0.1, 0.16, 0);
const armGeometry = new THREE.CylinderGeometry(0.045, 0.055, 0.48, 6);
const leftArm = addMesh(armGeometry, robeMaterial, person);
const rightArm = addMesh(armGeometry, robeMaterial, person);
leftArm.position.set(-0.22, 0.57, 0);
rightArm.position.set(0.22, 0.57, 0);
leftArm.rotation.z = 0.14;
rightArm.rotation.z = -0.14;
}
addPerson(4.8, -3.7, materials.sage, 0.5);
addPerson(-4.8, 2.9, materials.cream, -1.8);
addPerson(-3.7, -5.55, materials.terracotta, 2.4);
addPerson(5.15, 4.8, materials.charcoal, 2.9, true);
addPerson(-6.0, -1.3, materials.plasterLight, -0.6);
addPerson(3.75, 5.65, materials.sage, -1.0);
// A subdued market edge gives the module a Jemaa el-Fna context.
const backgroundGroup = new THREE.Group();
scene.add(backgroundGroup);
const backWall = addBox(20, 2.15, 0.38, materials.plaster, backgroundGroup, 0, 1.075, -11.65);
backWall.castShadow = false;
for (let i = -4; i <= 4; i++) {
const column = addBox(0.34, 2.25, 0.56, materials.plasterLight, backgroundGroup, i * 2.35, 1.125, -11.35);
column.castShadow = false;
}
const roofBeam = addBox(20.8, 0.22, 1.2, materials.woodDark, backgroundGroup, 0, 2.18, -11.15);
roofBeam.castShadow = false;
[-7.1, -2.35, 2.35, 7.1].forEach((x, index) => {
const awningMat = index % 2 === 0 ? materials.distantRoof : materials.cream;
const awning = surface([
[x - 1.45, 2.05, -10.72],
[x - 1.45, 1.7, -10.06],
[x + 1.45, 1.7, -10.06],
[x + 1.45, 2.05, -10.72]
], awningMat, backgroundGroup);
awning.castShadow = false;
const counter = addBox(2.2, 0.64, 0.52, materials.plasterLight, backgroundGroup, x, 0.32, -10.85);
counter.castShadow = false;
});
function addPalm(x, z, height = 4.4) {
const palm = new THREE.Group();
palm.position.set(x, 0, z);
palm.rotation.z = (x < 0 ? -1 : 1) * 0.035;
backgroundGroup.add(palm);
const trunk = addMesh(
new THREE.CylinderGeometry(0.12, 0.22, height, 7),
materials.wood,
palm
);
trunk.position.y = height * 0.5;
const crown = new THREE.Group();
crown.position.y = height;
palm.add(crown);
const leafMaterial = standard(0x667c54, { side: THREE.DoubleSide });
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const length = 1.65 + (i % 3) * 0.16;
const width = 0.27;
const dx = Math.cos(angle);
const dz = Math.sin(angle);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, 0, 0,
dx * length * 0.52 - dz * width, 0.06, dz * length * 0.52 + dx * width,
dx * length, -0.34, dz * length,
dx * length * 0.52 + dz * width, 0.06, dz * length * 0.52 - dx * width
], 3)
);
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
const leaf = addMesh(geometry, leafMaterial, crown);
leaf.castShadow = false;
}
}
addPalm(-10.3, -8.6, 4.5);
addPalm(10.2, -8.9, 4.1);
// Screen-space labels anchored to the three spatial systems.
const labels = [
{ element: document.querySelector("#label-tile"), point: new THREE.Vector3(-2.55, 0.18, 2.55) },
{ element: document.querySelector("#label-canopy"), point: new THREE.Vector3(1.35, 3.33, -0.45) },
{ element: document.querySelector("#label-flow"), point: new THREE.Vector3(4.45, 0.08, 2.0) }
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach(({ element, point }) => {
const projected = point.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
});
}
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
const aspect = window.innerWidth / window.innerHeight;
const aspectCompensation = Math.min(1, aspect);
const viewHeight = controls.radius * 0.86 / aspectCompensation;
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
updateLabels();
}
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight, false);
updateCamera();
}
window.addEventListener("resize", resize);
// Camera controls are implemented directly without Three.js addons.
const pointers = new Map();
let lastPinchDistance = 0;
let panning = false;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(values[0].x - values[1].x, values[0].y - values[1].y);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
panning = event.button === 2 || event.shiftKey;
if (pointers.size === 2) {
lastPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2) {
const distance = pointerDistance();
if (distance > 0 && lastPinchDistance > 0) {
controls.radius *= lastPinchDistance / distance;
controls.radius = THREE.MathUtils.clamp(controls.radius, 9, 30);
}
lastPinchDistance = distance;
updateCamera();
return;
}
if (panning) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3().crossVectors(forward, camera.up).normalize();
const scale = controls.radius * 0.0014;
controls.target.addScaledVector(right, -dx * scale);
controls.target.addScaledVector(forward, dy * scale);
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -7, 7);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -7, 7);
} else {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(controls.phi + dy * 0.005, 0.35, 1.34);
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
controls.radius *= Math.exp(event.deltaY * 0.001);
controls.radius = THREE.MathUtils.clamp(controls.radius, 9, 30);
updateCamera();
}, { passive: false });
function resetView() {
controls.target.set(0, 0.65, 0);
controls.theta = 0.64;
controls.phi = 0.78;
controls.radius = 18.5;
updateCamera();
}
document.querySelector("#reset").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
resize();
updateCamera();
const loading = document.querySelector("#loading");
let firstFrame = true;
renderer.setAnimationLoop(() => {
const pulse = 1 + Math.sin(performance.now() * 0.0024) * 0.035;
lanternLight.intensity = 7 * pulse;
renderer.render(scene, camera);
updateLabels();
if (firstFrame) {
firstFrame = false;
loading.classList.add("hide");
}
});
</script>
</body>
</html>
```