Prompt specification
Build or customize the Three.js 3D scene "Food-stall setup in a Marrakech square" 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: Food-stall setup in a Marrakech square
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/food-stall-setup-in-a-marrakech-square-x2938
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring Jemaa el-Fna in Marrakech. Create a compact referenced vignette with an original food stall being assembled and pedestrians passing. Show preparation as organized work and keep the main passage unobstructed. Voxel style.
Working Three.js Starter (food-stall-setup-in-a-marrakech-square-x2938):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#d9a66f">
<title>Jemaa el-Fna — Zaatar + Ember</title>
<style>
:root {
--ink: #38271d;
--cream: #fff4dc;
--saffron: #e69a32;
--green: #536849;
--panel: rgba(48, 34, 25, 0.84);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9a66f;
color: var(--cream);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#app,
#app canvas {
width: 100%;
height: 100%;
display: block;
}
#app canvas {
cursor: grab;
touch-action: none;
}
#app canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
text-shadow: 0 2px 18px rgba(61, 34, 18, 0.35);
}
.kicker {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.kicker::before {
content: "";
width: 25px;
height: 3px;
background: var(--saffron);
box-shadow: 0 0 0 1px rgba(255, 244, 220, 0.35);
}
.brand h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3.2vw, 48px);
font-weight: 500;
letter-spacing: -0.035em;
}
.brand p {
margin: 5px 0 0;
font-size: 10px;
letter-spacing: 0.13em;
text-transform: uppercase;
opacity: 0.82;
}
.actions {
position: absolute;
top: 24px;
right: 26px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid rgba(255, 244, 220, 0.34);
border-radius: 3px;
padding: 10px 13px;
color: var(--cream);
background: rgba(55, 38, 27, 0.82);
font: 700 10px/1 ui-monospace, monospace;
letter-spacing: 0.09em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
background 160ms ease,
transform 160ms ease,
border-color 160ms ease;
}
button:hover {
background: rgba(75, 50, 33, 0.96);
border-color: var(--saffron);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--saffron);
outline-offset: 3px;
}
.story {
position: absolute;
left: 26px;
bottom: 25px;
width: min(405px, calc(100vw - 52px));
padding: 18px 19px 16px;
border: 1px solid rgba(255, 244, 220, 0.2);
border-left: 4px solid var(--saffron);
border-radius: 4px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(56, 33, 19, 0.24);
backdrop-filter: blur(14px);
}
.story .eyebrow {
margin-bottom: 8px;
color: #efc77f;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.story h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 26px;
font-weight: 500;
letter-spacing: -0.02em;
}
.story h2 span {
color: #efb75d;
}
.story p {
margin: 8px 0 13px;
color: rgba(255, 244, 220, 0.76);
font: 12px/1.55 system-ui, sans-serif;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 15px;
}
.chip {
padding: 5px 7px;
border: 1px solid rgba(255, 244, 220, 0.16);
border-radius: 2px;
color: rgba(255, 244, 220, 0.76);
background: rgba(255, 255, 255, 0.05);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.status {
display: flex;
align-items: center;
gap: 9px;
padding-top: 12px;
border-top: 1px solid rgba(255, 244, 220, 0.13);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--saffron);
box-shadow: 0 0 0 4px rgba(230, 154, 50, 0.15);
}
.progress {
height: 2px;
margin-top: 10px;
overflow: hidden;
background: rgba(255, 255, 255, 0.12);
}
.progress div {
width: 0;
height: 100%;
background: linear-gradient(90deg, #efb75d, #fff0c6);
}
.hint {
position: absolute;
right: 26px;
bottom: 26px;
padding: 9px 11px;
border: 1px solid rgba(255, 244, 220, 0.22);
border-radius: 3px;
background: rgba(55, 38, 27, 0.68);
color: rgba(255, 244, 220, 0.78);
font-size: 9px;
letter-spacing: 0.07em;
text-align: right;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
#loader {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #d9a66f;
color: #493225;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loader.hidden {
opacity: 0;
visibility: hidden;
}
.loader-card {
text-align: center;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.loader-card::after {
content: "";
display: block;
width: 120px;
height: 3px;
margin: 15px auto 0;
background: rgba(73, 50, 37, 0.18);
overflow: hidden;
}
.loader-card::before {
content: "";
display: block;
width: 120px;
height: 3px;
margin: 15px auto 0;
background: #73503a;
animation: load 1s ease-in-out infinite alternate;
}
@keyframes load {
from { transform: translateX(-78px); }
to { transform: translateX(78px); }
}
@media (max-width: 700px) {
.brand {
top: 17px;
left: 17px;
}
.brand h1 {
font-size: 29px;
}
.brand p {
display: none;
}
.actions {
top: 16px;
right: 16px;
}
button {
padding: 9px 10px;
font-size: 8px;
}
.story {
left: 16px;
bottom: 16px;
width: calc(100vw - 32px);
padding: 14px 15px;
}
.story h2 {
font-size: 23px;
}
.story p {
display: none;
}
.chips {
margin-bottom: 10px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="hud">
<header class="brand">
<div class="kicker">Marrakech · Scene 01</div>
<h1>Jemaa el-Fna</h1>
<p>Adobe · saffron · evening trade</p>
</header>
<div class="actions">
<button id="reassemble" type="button">Reassemble</button>
<button id="pause" type="button">Pause</button>
</div>
<section class="story" aria-label="Scene description">
<div class="eyebrow">Original food stall / compact vignette</div>
<h2>ZAATAR <span>+ EMBER</span></h2>
<p>
An open-kitchen stall assembles in the square while the main promenade
remains clear. Ingredients, spice, prep, and fire are arranged as a
visible production line.
</p>
<div class="chips">
<span class="chip">Mise en place</span>
<span class="chip">Two work zones</span>
<span class="chip">Open passage</span>
</div>
<div class="status">
<span class="status-dot"></span>
<span id="phase">Preparing the square</span>
</div>
<div class="progress"><div id="progress-fill"></div></div>
</section>
<div class="hint">
Drag: orbit · wheel: zoom<br>
Shift + drag: pan · double click: reset
</div>
</div>
<div id="loader">
<div class="loader-card">Setting the square</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 and scene
// ---------------------------------------------------------------------
const app = document.querySelector("#app");
const loader = document.querySelector("#loader");
const phaseLabel = document.querySelector("#phase");
const progressFill = document.querySelector("#progress-fill");
const pauseButton = document.querySelector("#pause");
const reassembleButton = document.querySelector("#reassemble");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xedc89a);
scene.fog = new THREE.Fog(0xedc89a, 16, 34);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
app.appendChild(renderer.domElement);
const world = new THREE.Group();
scene.add(world);
const hemisphere = new THREE.HemisphereLight(0xffe8bd, 0x72503a, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffd59b, 3.4);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00025;
scene.add(sun);
const warmFill = new THREE.DirectionalLight(0xf28d52, 0.75);
warmFill.position.set(9, 5, -8);
scene.add(warmFill);
// ---------------------------------------------------------------------
// Palette and geometry helpers
// ---------------------------------------------------------------------
const C = {
sand: 0xd4a46e,
sandLight: 0xe1b985,
sandDark: 0xb98252,
adobe: 0xc88f60,
adobeLight: 0xdba473,
adobePale: 0xe6bc83,
terracotta: 0xa95336,
wood: 0x58392a,
woodLight: 0x775039,
darkWood: 0x35251e,
cream: 0xf5dfb4,
saffron: 0xe79a2e,
paprika: 0xb9412b,
herb: 0x536b3f,
herbLight: 0x78904d,
charcoal: 0x292421,
black: 0x171514,
metal: 0x817468,
brass: 0xc29343,
white: 0xfff0cf,
pink: 0xcf8a70,
blue: 0x536c78
};
const materialCache = new Map();
function material(color) {
if (color && color.isMaterial) return color;
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0
})
);
}
return materialCache.get(color);
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
return function () {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
const random = seededRandom(1471);
function textTexture(title, subtitle = "", background = "#3b2a20", foreground = "#fff0c9") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = foreground;
ctx.globalAlpha = 0.32;
ctx.lineWidth = 5;
ctx.strokeRect(15, 15, canvas.width - 30, canvas.height - 30);
ctx.globalAlpha = 1;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.font = "700 86px monospace";
ctx.fillText(title, 512, subtitle ? 102 : 130, 930);
if (subtitle) {
ctx.font = "700 25px monospace";
ctx.fillText(subtitle, 512, 187, 920);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function labelPlane(
parent,
title,
subtitle,
width,
height,
x,
y,
z,
background = "#3b2a20",
foreground = "#fff0c9"
) {
const texture = textTexture(title, subtitle, background, foreground);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({ map: texture })
);
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Paved square
// ---------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.BoxGeometry(17.8, 0.42, 12.4),
material(C.sandDark)
);
ground.position.y = -0.24;
ground.receiveShadow = true;
world.add(ground);
const tileGeometry = new THREE.BoxGeometry(0.64, 0.065, 0.64);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
25 * 15
);
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let ix = 0; ix < 25; ix++) {
for (let iz = 0; iz < 15; iz++) {
const x = -8.4 + ix * 0.7;
const z = -4.9 + iz * 0.7;
dummy.position.set(x, 0.025, z);
dummy.rotation.y = 0;
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const passage = z > 1.05;
const baseColors = passage
? [0xe1ba82, 0xd8ad75, 0xe6c18b, 0xd9b17b]
: [0xd4a46e, 0xc99562, 0xdcb078, 0xc9905e];
tileColor.setHex(baseColors[Math.floor(random() * baseColors.length)]);
tileColor.offsetHSL(0, 0, (random() - 0.5) * 0.035);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.receiveShadow = true;
world.add(tiles);
// ---------------------------------------------------------------------
// Background architecture
// ---------------------------------------------------------------------
function makeBuilding(x, z, w, h, d, color, variant = 0, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
world.add(group);
box(group, w, h, d, color, 0, h / 2, 0);
box(group, w + 0.12, 0.15, d + 0.12, C.adobeLight, 0, h + 0.075, 0);
for (let px = -w / 2 + 0.22; px < w / 2 - 0.12; px += 0.48) {
box(group, 0.25, 0.25, 0.18, color, px, h + 0.23, d / 2 + 0.02);
}
const rows = h > 4.2 ? [1.2, 2.35, 3.5] : [1.25, 2.45];
const columns = [-w * 0.3, 0, w * 0.3];
for (const yy of rows) {
for (const xx of columns) {
if (yy < 1.7 && xx === 0) continue;
box(group, 0.58, 0.78, 0.065, C.woodLight, xx, yy, d / 2 + 0.04);
box(group, 0.43, 0.61, 0.075, C.darkWood, xx, yy, d / 2 + 0.085);
box(group, 0.035, 0.61, 0.025, C.wood, xx, yy, d / 2 + 0.13);
box(group, 0.43, 0.035, 0.025, C.wood, xx, yy, d / 2 + 0.13);
}
}
box(group, 0.72, 1.25, 0.09, C.darkWood, 0, 0.66, d / 2 + 0.055);
box(group, 0.79, 0.09, 0.15, C.woodLight, 0, 1.31, d / 2 + 0.08);
if (variant % 2 === 0) {
for (let i = 0; i < 5; i++) {
box(
group,
0.26,
0.08,
0.82,
i % 2 ? C.cream : C.terracotta,
-w * 0.36 + i * 0.26,
1.85,
d / 2 + 0.39
);
}
}
if (variant === 1) {
box(group, w * 0.64, 0.12, 0.72, C.terracotta, 0, 1.77, d / 2 + 0.3);
box(group, w * 0.64, 0.36, 0.1, C.cream, 0, 1.59, d / 2 + 0.64);
}
return group;
}
makeBuilding(-7.1, -5.35, 3.15, 4.1, 1.25, C.adobe, 0);
makeBuilding(-3.85, -5.45, 3.15, 5.0, 1.35, C.adobeLight, 1);
makeBuilding(-0.55, -5.45, 3.1, 3.75, 1.3, C.adobePale, 2);
makeBuilding(2.0, -5.45, 2.65, 4.55, 1.35, C.adobe, 3);
makeBuilding(-8.0, -1.65, 3.5, 4.2, 1.3, C.adobeLight, 2, Math.PI / 2);
makeBuilding(8.0, -1.15, 3.5, 4.8, 1.3, C.adobe, 1, -Math.PI / 2);
// A compact Koutoubia-inspired landmark anchors the square.
const minaret = new THREE.Group();
minaret.position.set(5.55, 0, -5.25);
world.add(minaret);
box(minaret, 2.45, 0.38, 2.45, C.adobeLight, 0, 0.19, 0);
box(minaret, 1.72, 4.7, 1.72, C.sandLight, 0, 2.72, 0);
box(minaret, 1.95, 0.22, 1.95, C.adobePale, 0, 5.16, 0);
box(minaret, 1.26, 1.02, 1.26, C.sandLight, 0, 5.76, 0);
box(minaret, 1.52, 0.18, 1.52, C.adobeLight, 0, 6.36, 0);
box(minaret, 0.74, 0.64, 0.74, C.herb, 0, 6.77, 0);
box(minaret, 0.16, 0.52, 0.16, C.brass, 0, 7.31, 0);
box(minaret, 0.32, 0.14, 0.32, C.brass, 0, 7.58, 0);
for (const side of [-1, 1]) {
for (const yy of [1.2, 2.45, 3.7]) {
box(minaret, 0.32, 0.58, 0.05, C.darkWood, side * 0.48, yy, 0.885);
}
}
// Distant market canopies.
function makeMiniStall(x, z, a, b) {
const group = new THREE.Group();
group.position.set(x, 0, z);
world.add(group);
box(group, 2.55, 0.86, 1.1, C.wood, 0, 0.46, 0);
box(group, 2.7, 0.12, 1.2, C.cream, 0, 0.94, 0);
for (const px of [-1.22, 1.22]) {
box(group, 0.09, 2.15, 0.09, C.darkWood, px, 1.08, 0.48);
}
for (let i = 0; i < 4; i++) {
box(
group,
0.64,
0.14,
1.35,
i % 2 ? a : b,
-0.96 + i * 0.64,
2.16,
0
);
}
box(group, 0.78, 0.08, 0.48, C.charcoal, 0.58, 1.04, 0.04);
return group;
}
makeMiniStall(-5.9, -4.05, C.saffron, C.cream);
makeMiniStall(3.3, -4.0, C.terracotta, C.cream);
// String lights.
const lightWire = box(world, 15.2, 0.025, 0.025, C.darkWood, 0, 4.15, -3.25);
lightWire.rotation.z = -0.006;
const bulbMaterial = new THREE.MeshStandardMaterial({
color: 0xffd67d,
emissive: 0xff8e2d,
emissiveIntensity: 1.3,
roughness: 0.6
});
for (let i = 0; i < 19; i++) {
const x = -7.2 + i * 0.8;
const y = 4.15 - Math.sin((i / 18) * Math.PI) * 0.25;
box(world, 0.035, 0.23, 0.035, C.darkWood, x, y + 0.11, -3.25);
box(world, 0.12, 0.15, 0.12, bulbMaterial, x, y - 0.05, -3.25);
}
// ---------------------------------------------------------------------
// Original stall: assembly parts
// ---------------------------------------------------------------------
const stall = new THREE.Group();
stall.position.set(-1.25, 0, -1.68);
world.add(stall);
const assemblyParts = [];
function part(delay, label, anchor) {
const group = new THREE.Group();
group.position.copy(anchor);
group.visible = false;
stall.add(group);
assemblyParts.push({
group,
delay,
label,
finalPosition: anchor.clone()
});
return group;
}
const platform = part(0.0, "Laying the platform", new THREE.Vector3(0, 0.09, 0));
box(platform, 5.85, 0.18, 2.55, C.woodLight, 0, 0, 0);
box(platform, 5.45, 0.06, 2.2, C.sandDark, 0, 0.12, 0);
const frame = part(0.42, "Raising the timber frame", new THREE.Vector3(0, 1.57, 0));
for (const px of [-2.65, 2.65]) {
for (const pz of [-0.98, 0.98]) {
box(frame, 0.14, 2.84, 0.14, C.darkWood, px, 0, pz);
box(frame, 0.25, 0.13, 0.25, C.brass, px, -1.37, pz);
}
}
box(frame, 5.45, 0.13, 0.13, C.wood, 0, 1.39, -0.98);
box(frame, 5.45, 0.13, 0.13, C.wood, 0, 1.39, 0.98);
const counter = part(0.83, "Setting the service counter", new THREE.Vector3(0, 0.86, 0.72));
box(counter, 5.45, 1.03, 0.34, C.wood, 0, 0, 0);
box(counter, 5.62, 0.13, 0.56, C.cream, 0, 0.58, -0.02);
for (let i = 0; i < 7; i++) {
box(
counter,
0.67,
0.63,
0.035,
i % 2 ? C.terracotta : C.saffron,
-2.1 + i * 0.7,
0,
0.19
);
box(
counter,
0.18,
0.18,
0.04,
C.brass,
-2.1 + i * 0.7,
0,
0.22
);
}
const shelves = part(1.25, "Mounting the prep shelves", new THREE.Vector3(0, 1.76, -0.91));
box(shelves, 5.05, 0.12, 0.43, C.woodLight, 0, -0.44, 0);
box(shelves, 5.05, 0.12, 0.43, C.woodLight, 0, 0.4, 0);
box(shelves, 0.12, 1.04, 0.35, C.wood, -2.43, 0, 0);
box(shelves, 0.12, 1.04, 0.35, C.wood, 2.43, 0, 0);
const canopy = part(1.68, "Stitching the saffron canopy", new THREE.Vector3(0, 3.12, 0));
for (let i = 0; i < 9; i++) {
const x = -2.56 + i * 0.64;
const color = i % 2 ? C.cream : C.saffron;
box(canopy, 0.63, 0.17, 2.68, color, x, 0, 0);
box(canopy, 0.63, 0.37, 0.13, color, x, -0.22, 1.29);
box(canopy, 0.22, 0.16, 0.13, color, x, -0.46, 1.29);
}
box(canopy, 5.86, 0.12, 0.13, C.darkWood, 0, 0.05, 1.32);
const sign = part(2.12, "Hanging the original sign", new THREE.Vector3(0, 2.61, 1.37));
labelPlane(
sign,
"ZAATAR + EMBER",
"MUSHROOMS / SPICE / FIRE",
3.85,
0.73,
0,
0,
0,
"#3a2a21",
"#ffe1a0"
);
const lanterns = part(2.43, "Lighting the service lamps", new THREE.Vector3(0, 2.52, 1.02));
for (const x of [-1.85, 0, 1.85]) {
box(lanterns, 0.025, 0.35, 0.025, C.darkWood, x, 0.18, 0);
box(lanterns, 0.25, 0.29, 0.25, bulbMaterial, x, -0.1, 0);
box(lanterns, 0.31, 0.06, 0.31, C.brass, x, 0.075, 0);
box(lanterns, 0.31, 0.06, 0.31, C.brass, x, -0.275, 0);
}
const mise = part(2.68, "Arranging mise en place", new THREE.Vector3(0, 1.49, 0.39));
box(mise, 0.9, 0.055, 0.56, C.woodLight, -1.52, 0, 0);
box(mise, 0.62, 0.045, 0.42, C.cream, -1.52, 0.05, 0);
box(mise, 0.18, 0.08, 0.12, C.herb, -1.69, 0.11, 0.04);
box(mise, 0.14, 0.08, 0.12, C.herbLight, -1.5, 0.11, 0.06);
box(mise, 0.16, 0.08, 0.12, C.paprika, -1.35, 0.11, -0.03);
box(mise, 0.035, 0.28, 0.035, C.wood, -1.26, 0.14, 0.12);
for (let i = 0; i < 5; i++) {
box(mise, 0.47, 0.035, 0.47, C.white, -0.62, 0.02 + i * 0.04, 0);
}
box(mise, 1.03, 0.13, 0.57, C.charcoal, 1.45, 0.05, 0);
const emberMaterial = new THREE.MeshStandardMaterial({
color: 0xdb4b24,
emissive: 0xff3b0d,
emissiveIntensity: 1.65,
roughness: 0.7
});
box(mise, 0.82, 0.045, 0.38, emberMaterial, 1.45, 0.13, 0);
for (let i = 0; i < 5; i++) {
box(mise, 0.032, 0.035, 0.67, C.woodLight, 1.13 + i * 0.16, 0.19, 0);
for (let j = 0; j < 2; j++) {
box(
mise,
0.105,
0.105,
0.105,
j ? C.sandLight : C.wood,
1.13 + i * 0.16,
0.25,
-0.16 + j * 0.32
);
}
}
const tools = part(2.98, "Labeling prep, spice, and fire", new THREE.Vector3(0, 1.76, -0.86));
const binColors = [
C.herbLight,
C.paprika,
C.saffron,
0x4b342a,
C.herb,
0xd4a35f
];
for (let i = 0; i < 6; i++) {
const x = -1.92 + i * 0.57;
box(tools, 0.43, 0.28, 0.34, C.cream, x, -0.22, 0);
box(tools, 0.34, 0.07, 0.27, binColors[i], x, -0.045, 0);
}
for (let i = 0; i < 4; i++) {
box(tools, 0.39, 0.035, 0.39, C.white, 1.18 + (i % 2) * 0.48, 0.5 + Math.floor(i / 2) * 0.06, 0);
}
labelPlane(tools, "PREP", "", 0.78, 0.28, -1.55, 0.73, 0.23, "#43583b", "#fff0c9");
labelPlane(tools, "SPICE", "", 0.78, 0.28, 0, 0.73, 0.23, "#9b6730", "#fff0c9");
labelPlane(tools, "FIRE", "", 0.78, 0.28, 1.55, 0.73, 0.23, "#8b3828", "#fff0c9");
// The two workers reinforce distinct preparation stations.
const workerPart = part(3.27, "Opening the two work stations", new THREE.Vector3(0, 0, 0));
const workerArms = [];
function makeWorker(x, z, apron, armSide) {
const group = new THREE.Group();
group.position.set(x, 0, z);
workerPart.add(group);
box(group, 0.47, 0.63, 0.31, C.cream, 0, 1.27, 0);
box(group, 0.39, 0.48, 0.035, apron, 0, 1.22, 0.175);
box(group, 0.28, 0.29, 0.27, 0xb97d58, 0, 1.73, 0);
box(group, 0.35, 0.12, 0.31, C.white, 0, 1.9, 0);
box(group, 0.13, 0.09, 0.02, C.charcoal, -0.06, 1.75, 0.145);
box(group, 0.13, 0.09, 0.02, C.charcoal, 0.06, 1.75, 0.145);
const arm = new THREE.Group();
arm.position.set(armSide * 0.28, 1.47, 0.04);
group.add(arm);
box(arm, 0.13, 0.42, 0.14, C.cream, 0, -0.17, 0);
box(arm, 0.13, 0.13, 0.14, 0xb97d58, 0, -0.41, 0);
workerArms.push(arm);
}
makeWorker(-1.5, -0.27, C.herb, 1);
makeWorker(1.45, -0.25, C.terracotta, -1);
// ---------------------------------------------------------------------
// Passing pedestrians
// ---------------------------------------------------------------------
const people = [];
const clothing = [
0x5f7b82,
0x9f4f38,
0x6e6c46,
0x8d6380,
0x4f6870,
0xc08a55,
0x59664b,
0xa65e44
];
function makePerson(color, variant = 0, scale = 1) {
const group = new THREE.Group();
group.scale.setScalar(scale);
const legs = [];
const arms = [];
for (const side of [-1, 1]) {
const legPivot = new THREE.Group();
legPivot.position.set(side * 0.12, 0.65, 0);
group.add(legPivot);
box(legPivot, 0.15, 0.48, 0.16, C.darkWood, 0, -0.22, 0);
box(legPivot, 0.18, 0.1, 0.25, C.charcoal, 0, -0.47, 0.04);
legs.push(legPivot);
}
if (variant === 1) {
box(group, 0.47, 0.79, 0.31, color, 0, 0.87, 0);
box(group, 0.31, 0.17, 0.32, color, 0, 1.51, 0);
} else {
box(group, 0.43, 0.61, 0.29, color, 0, 0.93, 0);
box(group, 0.29, 0.29, 0.28, 0xb77d59, 0, 1.43, 0);
box(group, 0.3, 0.1, 0.29, C.darkWood, 0, 1.58, 0);
}
for (const side of [-1, 1]) {
const armPivot = new THREE.Group();
armPivot.position.set(side * 0.29, 1.13, 0);
group.add(armPivot);
box(armPivot, 0.12, 0.43, 0.14, color, 0, -0.17, 0);
box(armPivot, 0.12, 0.12, 0.13, 0xb77d59, 0, -0.41, 0);
arms.push(armPivot);
}
group.userData.legs = legs;
group.userData.arms = arms;
return group;
}
for (let i = 0; i < 8; i++) {
const direction = i % 2 === 0 ? 1 : -1;
const person = makePerson(
clothing[i % clothing.length],
i % 3 === 0 ? 1 : 0,
0.87 + random() * 0.23
);
person.rotation.y = direction > 0 ? Math.PI / 2 : -Math.PI / 2;
person.position.set(
-8.8 + random() * 17.6,
0.08,
1.38 + random() * 1.75
);
if (i === 2) {
box(person, 0.62, 0.06, 0.42, C.woodLight, 0, 1.84, 0);
for (let j = 0; j < 3; j++) {
box(person, 0.13, 0.13, 0.13, C.saffron, -0.19 + j * 0.19, 1.94, 0);
}
}
world.add(person);
people.push({
group: person,
direction,
speed: 0.52 + random() * 0.38,
phase: random() * Math.PI * 2,
baseZ: person.position.z
});
}
// A few quiet figures farther back keep the square inhabited without
// occupying the foreground passage.
for (const [x, z, color, variant] of [
[-6.4, -2.95, C.blue, 0],
[-5.8, -3.0, C.cream, 1],
[3.9, -3.05, C.herb, 0],
[4.7, -2.8, C.pink, 1]
]) {
const person = makePerson(color, variant, 0.9);
person.position.set(x, 0.08, z);
person.rotation.y = 0.3;
world.add(person);
}
// ---------------------------------------------------------------------
// Assembly animation
// ---------------------------------------------------------------------
let assemblyTime = 0;
const assemblyDuration = 4.35;
let paused = false;
function easeOutBack(value) {
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(value - 1, 3) + c1 * Math.pow(value - 1, 2);
}
function updateAssembly() {
let activeLabel = "Preparing the square";
let highest = 0;
for (const item of assemblyParts) {
const raw = (assemblyTime - item.delay) / 0.72;
const progress = THREE.MathUtils.clamp(raw, 0, 1);
highest = Math.max(highest, progress);
if (progress <= 0) {
item.group.visible = false;
continue;
}
item.group.visible = true;
const eased = easeOutBack(progress);
item.group.scale.setScalar(Math.max(0.001, eased));
item.group.position.copy(item.finalPosition);
item.group.position.y -= (1 - progress) * 0.72;
if (progress < 1) activeLabel = item.label;
}
if (assemblyTime >= assemblyDuration) {
phaseLabel.textContent = "Open for service · passage clear";
} else {
phaseLabel.textContent = activeLabel;
}
progressFill.style.width =
`${Math.min(100, (assemblyTime / assemblyDuration) * 100)}%`;
}
reassembleButton.addEventListener("click", () => {
assemblyTime = 0;
paused = false;
pauseButton.textContent = "Pause";
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
// ---------------------------------------------------------------------
// Custom camera controls — no examples or addons
// ---------------------------------------------------------------------
const orbit = {
yaw: 0.43,
pitch: 0.51,
radius: 17.2,
target: new THREE.Vector3(0, 1.1, 0)
};
const defaultOrbit = {
yaw: 0.43,
pitch: 0.51,
radius: 17.2,
target: new THREE.Vector3(0, 1.1, 0)
};
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (event.shiftKey) {
const panScale = orbit.radius * 0.0011;
orbit.target.x += Math.cos(orbit.yaw) * dx * panScale;
orbit.target.z -= Math.sin(orbit.yaw) * dx * panScale;
orbit.target.y += dy * panScale * 0.7;
orbit.target.y = THREE.MathUtils.clamp(orbit.target.y, 0.2, 4.5);
} else {
orbit.yaw -= dx * 0.006;
orbit.pitch += dy * 0.0045;
orbit.pitch = THREE.MathUtils.clamp(orbit.pitch, 0.18, 1.15);
}
});
function stopDragging(event) {
dragging = false;
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();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
10.5,
25
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.yaw = defaultOrbit.yaw;
orbit.pitch = defaultOrbit.pitch;
orbit.radius = defaultOrbit.radius;
orbit.target.copy(defaultOrbit.target);
});
function updateCamera() {
const horizontal = Math.cos(orbit.pitch) * orbit.radius;
camera.position.set(
orbit.target.x + Math.sin(orbit.yaw) * horizontal,
orbit.target.y + Math.sin(orbit.pitch) * orbit.radius,
orbit.target.z + Math.cos(orbit.yaw) * horizontal
);
camera.lookAt(orbit.target);
}
// ---------------------------------------------------------------------
// Animation loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
assemblyTime += delta;
updateAssembly();
for (const person of people) {
person.phase += delta * person.speed * 5.4;
person.group.position.x += person.direction * person.speed * delta;
if (person.group.position.x > 9.6) {
person.group.position.x = -9.6;
} else if (person.group.position.x < -9.6) {
person.group.position.x = 9.6;
}
person.group.position.z =
person.baseZ + Math.sin(person.phase * 0.45) * 0.055;
const swing = Math.sin(person.phase) * 0.48;
person.group.userData.legs[0].rotation.x = swing;
person.group.userData.legs[1].rotation.x = -swing;
person.group.userData.arms[0].rotation.x = -swing * 0.7;
person.group.userData.arms[1].rotation.x = swing * 0.7;
}
for (let i = 0; i < workerArms.length; i++) {
workerArms[i].rotation.x =
Math.sin(assemblyTime * 3.4 + i * 1.9) * 0.28;
}
}
updateCamera();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateAssembly();
updateCamera();
renderer.render(scene, camera);
animate();
requestAnimationFrame(() => {
loader.classList.add("hidden");
});
</script>
</body>
</html>
```