Prompt specification
Build or customize the Three.js 3D scene "Compare daytime and evening spatial arrangements" 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: Compare daytime and evening spatial arrangements
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compare-daytime-and-evening-spatial-arrangements-x2940
Scene Description Prompt:
Rearrange fictional voxel stalls in Marrakech's Jemaa el-Fna between day and evening, changing occupied areas and routes. Three.js from cdnjs; standalone HTML.
Working Three.js Starter (compare-daytime-and-evening-spatial-arrangements-x2940):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jemaa el-Fna — Day to Evening</title>
<style>
:root {
--ink: #241b17;
--paper: rgba(255, 248, 235, 0.9);
--paper-solid: #fff8e9;
--line: rgba(74, 45, 29, 0.16);
--terracotta: #b74e32;
--gold: #d89b35;
--teal: #397f84;
--shadow: 0 16px 45px rgba(45, 25, 15, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7b47c;
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;
outline: none;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 10;
}
.panel {
position: absolute;
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.55);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(1.1);
-webkit-backdrop-filter: blur(16px) saturate(1.1);
}
#phase-panel {
top: 20px;
left: 20px;
width: min(350px, calc(100vw - 40px));
border-radius: 22px;
padding: 20px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: #8a5636;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--terracotta);
box-shadow: 13px 0 0 var(--gold);
margin-right: 13px;
}
h1 {
margin: 0;
max-width: 280px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 3vw, 39px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.intro {
margin: 12px 0 17px;
max-width: 300px;
color: rgba(36, 27, 23, 0.67);
font-size: 12px;
line-height: 1.55;
}
.phase-tabs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
padding: 5px;
border-radius: 14px;
background: rgba(95, 58, 35, 0.08);
}
.phase-tab {
min-height: 40px;
border: 0;
border-radius: 10px;
background: transparent;
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.1em;
transition:
background 180ms ease,
color 180ms ease,
transform 180ms ease;
}
.phase-tab:hover {
background: rgba(255, 255, 255, 0.45);
}
.phase-tab.active {
color: #fffaf0;
background: var(--ink);
box-shadow: 0 5px 14px rgba(36, 27, 23, 0.2);
}
.phase-tab[data-phase="1"].active {
background: var(--terracotta);
}
.timeline {
margin-top: 15px;
}
.timeline input {
width: 100%;
accent-color: var(--terracotta);
cursor: pointer;
}
.timeline-labels {
display: flex;
justify-content: space-between;
margin-top: 5px;
color: rgba(36, 27, 23, 0.55);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
}
.stats {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 15px;
}
.stat {
min-width: 0;
padding: 10px 8px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.3);
}
.stat-label {
display: block;
overflow: hidden;
color: rgba(36, 27, 23, 0.5);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.stat-value {
display: block;
margin-top: 4px;
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
white-space: nowrap;
}
.panel-footer {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.small-button {
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.35);
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
transition:
background 160ms ease,
border-color 160ms ease;
}
.small-button:hover,
.small-button.active {
border-color: rgba(183, 78, 50, 0.42);
background: rgba(183, 78, 50, 0.1);
}
#view-panel {
top: 20px;
right: 20px;
display: flex;
gap: 7px;
padding: 9px;
border-radius: 15px;
}
#view-panel button {
min-height: 36px;
}
#info-panel {
right: 20px;
bottom: 20px;
width: 270px;
padding: 16px;
border-radius: 17px;
}
.info-kicker {
color: var(--terracotta);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#selection-name {
margin-top: 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
}
#selection-detail {
margin-top: 6px;
color: rgba(36, 27, 23, 0.64);
font-size: 11px;
line-height: 1.5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 14px;
color: rgba(36, 27, 23, 0.62);
font-size: 9px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 5px;
}
.swatch {
width: 15px;
height: 4px;
border-radius: 4px;
}
.swatch.day {
background: #4f8992;
}
.swatch.night {
background: #e76f35;
}
.swatch.zone {
border: 1px solid #ce8b42;
background: rgba(231, 164, 73, 0.22);
}
#hint {
position: absolute;
bottom: 20px;
left: 20px;
padding: 9px 12px;
border-radius: 999px;
color: rgba(255, 255, 255, 0.9);
background: rgba(36, 27, 23, 0.62);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
}
.world-label {
position: absolute;
z-index: 4;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.35);
border-radius: 999px;
color: white;
background: rgba(36, 27, 23, 0.64);
box-shadow: 0 7px 20px rgba(0, 0, 0, 0.14);
backdrop-filter: blur(8px);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.12em;
pointer-events: none;
text-transform: uppercase;
transform: translate(-50%, -50%);
white-space: nowrap;
}
#day-label {
border-color: rgba(117, 198, 204, 0.55);
background: rgba(31, 84, 91, 0.72);
}
#night-label {
border-color: rgba(255, 179, 95, 0.55);
background: rgba(125, 54, 31, 0.75);
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
color: #fff7e9;
background: #9d5938;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
letter-spacing: 0.03em;
}
@media (max-width: 720px) {
#phase-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px;
}
h1 {
font-size: 29px;
}
.intro {
display: none;
}
.stats {
margin-top: 10px;
}
.panel-footer {
margin-top: 10px;
padding-top: 10px;
}
#view-panel {
top: auto;
right: 12px;
bottom: 54px;
flex-direction: column;
}
#info-panel {
display: none;
}
#hint {
right: 12px;
bottom: 12px;
left: 12px;
text-align: center;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<div id="loading">Building the voxel square…</div>
<div class="hud">
<section id="phase-panel" class="panel">
<div class="eyebrow">Jemaa el-Fna · fictional study</div>
<h1>A square,<br>two rhythms.</h1>
<p class="intro">
Rearrange the market between a sunlit trading day and a dense evening
food court. Stalls, visitors, occupied ground, and circulation routes
all move into a new arrangement.
</p>
<div class="phase-tabs" role="group" aria-label="Market time">
<button
class="phase-tab active"
data-phase="0"
type="button"
aria-pressed="true"
>
☀ DAY
</button>
<button
class="phase-tab"
data-phase="1"
type="button"
aria-pressed="false"
>
☾ EVENING
</button>
</div>
<div class="timeline">
<input
id="phase-slider"
type="range"
min="0"
max="100"
value="0"
aria-label="Transition from day to evening"
>
<div class="timeline-labels">
<span>16:20 · EDGE TRADE</span>
<span>20:45 · FOOD COURT</span>
</div>
</div>
<div class="stats">
<div class="stat">
<span class="stat-label">Market time</span>
<span id="time-stat" class="stat-value">16:20</span>
</div>
<div class="stat">
<span class="stat-label">Activity</span>
<span id="activity-stat" class="stat-value">38%</span>
</div>
<div class="stat">
<span class="stat-label">Occupied</span>
<span id="zone-stat" class="stat-value">4 edge</span>
</div>
</div>
<div class="panel-footer">
<button id="auto-button" class="small-button" type="button">
Auto cycle
</button>
<button
id="routes-button"
class="small-button active"
type="button"
aria-pressed="true"
>
Routes
</button>
<button
id="zones-button"
class="small-button active"
type="button"
aria-pressed="true"
>
Occupied ground
</button>
</div>
<div class="legend">
<span class="legend-item">
<i class="swatch day"></i> Day circulation
</span>
<span class="legend-item">
<i class="swatch night"></i> Evening circulation
</span>
<span class="legend-item">
<i class="swatch zone"></i> Occupied ground
</span>
</div>
</section>
<section id="view-panel" class="panel" aria-label="View controls">
<button id="reset-view" class="small-button" type="button">
Reset view
</button>
</section>
<section id="info-panel" class="panel">
<div class="info-kicker">Selected stall</div>
<div id="selection-name">Choose a voxel stall</div>
<div id="selection-detail">
Click any stall to inspect its fictional trade and current district.
</div>
</section>
<div id="hint">
Drag to orbit · Wheel/pinch to zoom · Click a stall to inspect
</div>
<div id="day-label" class="world-label">Perimeter trade loop</div>
<div id="night-label" class="world-label">Evening food court</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const ui = {
phaseButtons: [...document.querySelectorAll(".phase-tab")],
slider: $("#phase-slider"),
time: $("#time-stat"),
activity: $("#activity-stat"),
zones: $("#zone-stat"),
auto: $("#auto-button"),
routes: $("#routes-button"),
occupied: $("#zones-button"),
selectionName: $("#selection-name"),
selectionDetail: $("#selection-detail"),
dayLabel: $("#day-label"),
nightLabel: $("#night-label")
};
const state = {
phase: 0,
target: 0,
auto: false,
autoClock: 0,
routesVisible: true,
occupiedVisible: true,
selectedStall: null,
elapsed: 0
};
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
const dayBackground = new THREE.Color(0xe8c996);
const eveningBackground = new THREE.Color(0x241d31);
scene.background = dayBackground.clone();
scene.fog = new THREE.Fog(dayBackground.clone(), 66, 125);
const camera = new THREE.PerspectiveCamera(
43,
innerWidth / innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.8));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.03;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive voxel market");
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff2cf, 0x9c6947, 2.35);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe8b6, 3.25);
sun.position.set(28, 38, 20);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -44;
sun.shadow.camera.right = 44;
sun.shadow.camera.top = 40;
sun.shadow.camera.bottom = -40;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 100;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0x88b9cf, 0.55);
fillLight.position.set(-25, 14, -20);
scene.add(fillLight);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function box(parent, material, x, y, z, sx, sy, sz) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
}
// -------------------------------------------------------------------------
// Plaza and paving
// -------------------------------------------------------------------------
const groundMaterial = standardMaterial(0xd3ae77);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 50),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const gridPositions = [];
for (let x = -34; x <= 34; x += 4) {
gridPositions.push(x, 0.018, -25, x, 0.018, 25);
}
for (let z = -25; z <= 25; z += 4) {
gridPositions.push(-35, 0.018, z, 35, 0.018, z);
}
const pavingGrid = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
),
new THREE.LineBasicMaterial({
color: 0x9e754c,
transparent: true,
opacity: 0.22
})
);
scene.add(pavingGrid);
const plazaBorderMaterial = standardMaterial(0xa87950);
box(scene, plazaBorderMaterial, 0, 0.25, -25.3, 70, 0.5, 0.6);
box(scene, plazaBorderMaterial, 0, 0.25, 25.3, 70, 0.5, 0.6);
box(scene, plazaBorderMaterial, -35.3, 0.25, 0, 0.6, 0.5, 50);
box(scene, plazaBorderMaterial, 35.3, 0.25, 0, 0.6, 0.5, 50);
// -------------------------------------------------------------------------
// Voxel architecture around the square
// -------------------------------------------------------------------------
const architecture = new THREE.Group();
scene.add(architecture);
const wallMaterials = [
standardMaterial(0xc88f5e),
standardMaterial(0xd7a874),
standardMaterial(0xb96f48),
standardMaterial(0xe0b98b),
standardMaterial(0xc99467)
];
const roofMaterial = standardMaterial(0x8b5b3e);
const windowMaterial = standardMaterial(0x433b39, {
roughness: 0.55
});
const trimMaterial = standardMaterial(0xe6c99e);
function addBuilding(x, z, width, depth, height, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
const wall =
wallMaterials[
Math.abs(Math.round(x * 3 + z * 7)) % wallMaterials.length
];
box(group, wall, 0, height / 2, 0, width, height, depth);
box(group, roofMaterial, 0, height + 0.22, 0, width + 0.35, 0.44, depth + 0.35);
box(
group,
trimMaterial,
0,
1.4,
depth / 2 + 0.025,
width * 0.9,
0.22,
0.12
);
const columns = Math.max(2, Math.floor(width / 2));
const windowHeight = Math.min(2.2, height * 0.34);
for (let i = 0; i < columns; i++) {
const wx =
-width / 2 +
(width / (columns - 1 || 1)) * i;
box(
group,
windowMaterial,
wx,
Math.min(height - 1.2, 3.2),
depth / 2 + 0.06,
0.48,
windowHeight,
0.13
);
}
architecture.add(group);
return group;
}
for (const x of [-30, -24, -18, -12, 12, 18, 24, 30]) {
const height = 5.5 + ((x * 7) % 5 + 5) % 5;
addBuilding(x, -27.5, 5.6, 4.5, height);
}
for (const x of [-24, -18, -12, 12, 18, 24]) {
const height = 4.7 + ((x * 5) % 4 + 4) % 4;
addBuilding(x, 27.5, 5.6, 4.5, height);
}
for (const z of [-17, -10, -3, 4, 11, 18]) {
const height = 5 + ((z * 3) % 5 + 5) % 5;
addBuilding(-33.5, z, 4.3, 6, height, Math.PI / 2);
addBuilding(33.5, z, 4.3, 6, height, -Math.PI / 2);
}
// A simplified Koutoubia-inspired minaret.
const minaret = new THREE.Group();
minaret.position.set(0, 0, -29.5);
architecture.add(minaret);
const minaretMaterial = standardMaterial(0xd38b65);
const minaretLight = standardMaterial(0xe5ad82);
const minaretShadow = standardMaterial(0xa96149);
box(minaret, minaretMaterial, 0, 2.4, 0, 8, 4.8, 7);
box(minaret, minaretLight, 0, 5.5, 0, 6.4, 1.5, 6);
box(minaret, minaretMaterial, 0, 12.6, 0, 4.6, 14, 4.6);
box(minaret, minaretShadow, 0, 20, 0, 5.6, 1.2, 5.6);
box(minaret, minaretMaterial, 0, 22.1, 0, 4.8, 3, 4.8);
box(minaret, minaretLight, 0, 24, 0, 3.6, 1, 3.6);
box(minaret, minaretMaterial, 0, 25.1, 0, 2.6, 1.5, 2.6);
for (const x of [-1.65, 1.65]) {
for (const y of [8, 12, 16]) {
box(
minaret,
windowMaterial,
x,
y,
2.34,
0.5,
1.5,
0.12
);
}
}
for (const x of [-1.7, 1.7]) {
for (const z of [-1.7, 1.7]) {
box(minaret, minaretShadow, x, 19.3, z, 0.65, 1.3, 0.65);
}
}
// Voxel palms.
const palmTrunkMaterial = standardMaterial(0x8f633d);
const palmLeafMaterial = standardMaterial(0x537448);
const palmLeafLight = standardMaterial(0x698451);
function addPalm(x, z, scale = 1) {
const palm = new THREE.Group();
palm.position.set(x, 0, z);
palm.scale.setScalar(scale);
for (let i = 0; i < 5; i++) {
box(
palm,
palmTrunkMaterial,
i * 0.08,
1 + i * 1.7,
0,
0.65,
1.75,
0.65
);
}
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const leaf = box(
palm,
i % 2 ? palmLeafMaterial : palmLeafLight,
Math.cos(angle) * 1.6,
9.4,
Math.sin(angle) * 1.6,
3.4,
0.35,
0.9
);
leaf.rotation.y = -angle;
leaf.rotation.z = i % 2 ? 0.12 : -0.12;
}
architecture.add(palm);
}
addPalm(-28, 21, 0.9);
addPalm(28, 21, 0.95);
addPalm(-29, -19, 0.85);
addPalm(29, -19, 0.9);
// -------------------------------------------------------------------------
// Stall layouts: edge trading by day, central food court by evening
// -------------------------------------------------------------------------
const dayLayout = [];
for (const z of [-13, -8, -3, 2, 7, 12]) {
dayLayout.push({
x: -24,
z,
rot: Math.PI / 2,
zone: "West craft row"
});
dayLayout.push({
x: 24,
z,
rot: -Math.PI / 2,
zone: "East spice row"
});
}
for (const x of [-18, -12, 12, 18]) {
dayLayout.push({
x,
z: -15,
rot: 0,
zone: "North arcade"
});
dayLayout.push({
x,
z: 15,
rot: Math.PI,
zone: "South sun row"
});
}
const eveningLayout = [];
const eveningX = [-12, -6, 0, 6, 12];
const eveningZ = [-8, -2, 4, 10];
for (const z of eveningZ) {
for (const x of eveningX) {
eveningLayout.push({
x,
z,
rot: z <= -2 ? 0 : Math.PI,
zone: "Central food court"
});
}
}
const stallNames = [
"Orange & mint",
"Saffron pyramids",
"Amlou bread",
"Olives & dates",
"Tea tins",
"Cumin baskets",
"Rose water",
"Lemon baskets",
"Honey jars",
"Almond trays",
"Pepper pyramids",
"Fig bundles",
"Mint bundles",
"Jasmine baskets",
"Cinnamon rolls",
"Dried limes",
"Apricot cones",
"Sesame jars",
"Orange blossom",
"Market herbs"
];
const dayPalette = [
0xb96542, 0x748b6f, 0xc79b4a, 0x527b84, 0xb95752
];
const eveningPalette = [
0xe45831, 0x2f8b7e, 0xf0b53b, 0x465ba7, 0xd74459
];
const productPalette = [
0xe98b2d,
0xd94b31,
0xf2c34d,
0x759b3c,
0x9b5734,
0xe7d39c
];
const woodMaterial = standardMaterial(0x70442c);
const darkWoodMaterial = standardMaterial(0x432b22);
const counterMaterial = standardMaterial(0xb77a42);
const crateMaterial = standardMaterial(0x966039);
const market = new THREE.Group();
scene.add(market);
const stalls = [];
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(90817);
for (let i = 0; i < dayLayout.length; i++) {
const stall = new THREE.Group();
stall.userData.stallIndex = i;
const dayColor = new THREE.Color(dayPalette[i % dayPalette.length]);
const eveningColor = new THREE.Color(
eveningPalette[i % eveningPalette.length]
);
const canopyMaterial = standardMaterial(dayColor);
const stripeMaterial = standardMaterial(0xe8cfa5);
const lanternMaterial = new THREE.MeshBasicMaterial({
color: 0xffb54c,
transparent: true,
opacity: 0.06
});
// Posts and counter.
for (const x of [-1.48, 1.48]) {
for (const z of [-0.87, 0.87]) {
box(stall, woodMaterial, x, 1.2, z, 0.18, 2.4, 0.18);
}
}
box(stall, counterMaterial, 0, 0.75, 0.18, 2.9, 0.72, 1.35);
box(stall, darkWoodMaterial, 0, 0.33, 0.18, 3.05, 0.2, 1.48);
// Flat voxel awning.
box(stall, canopyMaterial, 0, 2.56, 0, 3.45, 0.3, 2.25);
box(stall, canopyMaterial, 0, 2.27, 1.1, 3.45, 0.42, 0.16);
for (const x of [-1.12, -0.38, 0.38, 1.12]) {
box(stall, stripeMaterial, x, 2.735, 0, 0.22, 0.035, 2.27);
}
// Crates and small voxel produce.
for (let crate = 0; crate < 3; crate++) {
const cx = -0.93 + crate * 0.93;
box(
stall,
crateMaterial,
cx,
1.19,
0.42,
0.72,
0.18,
0.72
);
for (let p = 0; p < 3; p++) {
const productMaterial = standardMaterial(
productPalette[
(i + crate + p + Math.floor(random() * 3)) %
productPalette.length
]
);
box(
stall,
productMaterial,
cx - 0.18 + (p % 2) * 0.34,
1.39,
0.28 + Math.floor(p / 2) * 0.24,
0.25,
0.25,
0.25
);
}
}
// A small lantern that becomes visible in the evening.
box(
stall,
lanternMaterial,
1.25,
2.05,
0.92,
0.23,
0.32,
0.23
);
stall.position.set(dayLayout[i].x, 0, dayLayout[i].z);
stall.rotation.y = dayLayout[i].rot;
stall.userData.day = dayLayout[i];
stall.userData.evening = eveningLayout[i];
stall.userData.dayColor = dayColor;
stall.userData.eveningColor = eveningColor;
stall.userData.canopyMaterial = canopyMaterial;
stall.userData.stripeMaterial = stripeMaterial;
stall.userData.lanternMaterial = lanternMaterial;
market.add(stall);
stalls.push(stall);
}
// -------------------------------------------------------------------------
// Occupied-ground zones
// -------------------------------------------------------------------------
const occupiedGroup = new THREE.Group();
scene.add(occupiedGroup);
const zoneDayColor = new THREE.Color(0x5a9ca2);
const zoneNightColor = new THREE.Color(0xe3a64f);
const zones = [];
function addZone(width, depth, x, z, dayOpacity, eveningOpacity) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const fillMaterial = new THREE.MeshBasicMaterial({
color: zoneDayColor,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
});
const fill = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
fillMaterial
);
fill.rotation.x = -Math.PI / 2;
fill.position.y = 0.04;
group.add(fill);
const borderMaterial = new THREE.LineBasicMaterial({
color: zoneDayColor,
transparent: true,
opacity: 0
});
const points = [
new THREE.Vector3(-width / 2, 0.075, -depth / 2),
new THREE.Vector3(width / 2, 0.075, -depth / 2),
new THREE.Vector3(width / 2, 0.075, depth / 2),
new THREE.Vector3(-width / 2, 0.075, depth / 2)
];
const border = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
borderMaterial
);
group.add(border);
group.userData = {
fillMaterial,
borderMaterial,
dayOpacity,
eveningOpacity
};
occupiedGroup.add(group);
zones.push(group);
}
// Day: four edge-market strips.
addZone(8, 31, -22.5, 0, 0.17, 0.015);
addZone(8, 31, 22.5, 0, 0.17, 0.015);
addZone(29, 6, 0, -14.5, 0.14, 0.01);
addZone(29, 6, 0, 14.5, 0.14, 0.01);
// Evening: one core and two social edges.
addZone(34, 24, 0, 1, 0.015, 0.23);
addZone(7, 16, -18, 2, 0.01, 0.13);
addZone(7, 16, 18, 2, 0.01, 0.13);
// -------------------------------------------------------------------------
// Route networks
// -------------------------------------------------------------------------
const routeGroup = new THREE.Group();
scene.add(routeGroup);
const routes = [];
const routeDayColor = new THREE.Color(0x4d8993);
const routeNightColor = new THREE.Color(0xf39a45);
function addRoute(points, closed, dayOpacity, eveningOpacity, radius = 0.09) {
const curve = new THREE.CatmullRomCurve3(
points.map(([x, z]) => new THREE.Vector3(x, 0.12, z)),
closed,
"catmullrom",
0.15
);
const material = new THREE.MeshBasicMaterial({
color: routeDayColor,
transparent: true,
opacity: 0,
depthWrite: false
});
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 100, radius, 6, closed),
material
);
mesh.userData.dayOpacity = dayOpacity;
mesh.userData.eveningOpacity = eveningOpacity;
routeGroup.add(mesh);
routes.push(mesh);
}
// Day circulation: an outer loop and sparse cross-square lanes.
addRoute(
[
[-20, -17],
[-10, -20],
[10, -20],
[20, -17],
[21, 16],
[10, 19],
[-10, 19],
[-20, 16]
],
true,
0.78,
0.015,
0.1
);
addRoute(
[
[-28, 0],
[-15, -1],
[0, 1],
[15, 0],
[28, -1]
],
false,
0.62,
0.015,
0.075
);
addRoute(
[
[0, 21],
[1, 12],
[-1, 4],
[0, -5],
[1, -19]
],
false,
0.48,
0.015,
0.075
);
// Evening circulation: a compact loop and curved central crossings.
addRoute(
[
[-16, -7],
[-11, -13],
[0, -15],
[12, -12],
[16, -5],
[15, 8],
[9, 14],
[-5, 14],
[-15, 9]
],
true,
0.01,
0.86,
0.115
);
addRoute(
[
[-28, 15],
[-17, 8],
[-8, 2],
[0, 0],
[9, -2],
[20, -10]
],
false,
0.01,
0.66,
0.09
);
addRoute(
[
[27, 17],
[18, 10],
[10, 4],
[1, 0],
[-9, -4],
[-20, -13]
],
false,
0.01,
0.58,
0.08
);
// -------------------------------------------------------------------------
// Voxel crowd
// -------------------------------------------------------------------------
const crowd = new THREE.Group();
scene.add(crowd);
const crowdBodyMaterials = [
standardMaterial(0x557d91),
standardMaterial(0xb85c40),
standardMaterial(0xd4ae52),
standardMaterial(0x60765d),
standardMaterial(0xd5c8ac),
standardMaterial(0x7b5f83)
];
const crowdHeadMaterial = standardMaterial(0x9b6847);
const people = [];
for (let i = 0; i < 48; i++) {
const person = new THREE.Group();
const body = box(
person,
crowdBodyMaterials[i % crowdBodyMaterials.length],
0,
0.56,
0,
0.34,
0.66,
0.28
);
box(
person,
crowdHeadMaterial,
0,
1.05,
0,
0.28,
0.28,
0.28
);
const dayAnchor =
dayLayout[Math.floor(random() * dayLayout.length)];
const eveningAnchor =
eveningLayout[Math.floor(random() * eveningLayout.length)];
const dayAngle = random() * Math.PI * 2;
const eveningAngle = random() * Math.PI * 2;
const dayRadius = 2.2 + random() * 3.8;
const eveningRadius = 1.3 + random() * 2.8;
person.userData = {
day: new THREE.Vector3(
THREE.MathUtils.clamp(
dayAnchor.x + Math.cos(dayAngle) * dayRadius,
-29,
29
),
0,
THREE.MathUtils.clamp(
dayAnchor.z + Math.sin(dayAngle) * dayRadius,
-20,
20
)
),
evening: new THREE.Vector3(
THREE.MathUtils.clamp(
eveningAnchor.x + Math.cos(eveningAngle) * eveningRadius,
-16,
16
),
0,
THREE.MathUtils.clamp(
eveningAnchor.z + Math.sin(eveningAngle) * eveningRadius,
-11,
13
)
),
body,
phase: random() * Math.PI * 2,
scale: 0.82 + random() * 0.3
};
person.scale.setScalar(person.userData.scale);
person.rotation.y = random() * Math.PI * 2;
crowd.add(person);
people.push(person);
}
// -------------------------------------------------------------------------
// Evening lamps and lights
// -------------------------------------------------------------------------
const lampMaterial = standardMaterial(0xffb84f, {
emissive: 0xff741f,
emissiveIntensity: 0.05,
roughness: 0.5
});
const lampPostMaterial = standardMaterial(0x49352d);
const eveningLights = [];
for (const [x, z] of [
[-15, -8],
[15, -8],
[-15, 9],
[15, 9],
[0, -13],
[0, 13]
]) {
box(scene, lampPostMaterial, x, 1.8, z, 0.18, 3.6, 0.18);
box(scene, lampMaterial, x, 3.65, z, 0.48, 0.58, 0.48);
box(scene, lampPostMaterial, x, 4, z, 0.65, 0.14, 0.65);
const light = new THREE.PointLight(0xff8c39, 0, 22, 2);
light.position.set(x, 3.7, z);
scene.add(light);
eveningLights.push(light);
}
// -------------------------------------------------------------------------
// Subtle steam above selected evening food stalls
// -------------------------------------------------------------------------
const steam = [];
for (let i = 0; i < 10; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0xfff1d7,
transparent: true,
opacity: 0,
depthWrite: false
});
const puff = new THREE.Mesh(unitBox, material);
scene.add(puff);
steam.push({
mesh: puff,
material,
stallIndex: 5 + i * 2,
offset: random() * 10
});
}
// -------------------------------------------------------------------------
// Stars for the evening sky
// -------------------------------------------------------------------------
const starPositions = [];
for (let i = 0; i < 160; i++) {
const angle = random() * Math.PI * 2;
const radius = 45 + random() * 50;
starPositions.push(
Math.cos(angle) * radius,
25 + random() * 45,
Math.sin(angle) * radius
);
}
const starMaterial = new THREE.PointsMaterial({
color: 0xffeccd,
size: 0.35,
transparent: true,
opacity: 0,
depthWrite: false
});
const stars = new THREE.Points(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
),
starMaterial
);
scene.add(stars);
// -------------------------------------------------------------------------
// Custom orbit controls, implemented without camera-control addons
// -------------------------------------------------------------------------
const orbit = {
theta: 0.62,
phi: 0.79,
radius: 64,
target: new THREE.Vector3(0, 1, -1)
};
const defaultOrbit = {
theta: 0.62,
phi: 0.79,
radius: 64,
target: new THREE.Vector3(0, 1, -1)
};
function updateCamera() {
orbit.phi = THREE.MathUtils.clamp(orbit.phi, 0.34, 1.27);
orbit.radius = THREE.MathUtils.clamp(orbit.radius, 27, 90);
const horizontal = Math.sin(orbit.phi) * orbit.radius;
camera.position.set(
orbit.target.x + horizontal * Math.sin(orbit.theta),
orbit.target.y + Math.cos(orbit.phi) * orbit.radius,
orbit.target.z + horizontal * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
const pointers = new Map();
let dragDistance = 0;
let previousPinchDistance = 0;
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
function pickStall(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNdc.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNdc, camera);
const hits = raycaster.intersectObjects(stalls, true);
if (!hits.length) return;
let object = hits[0].object;
while (object && object.userData.stallIndex === undefined) {
object = object.parent;
}
if (object) {
state.selectedStall = object.userData.stallIndex;
updateSelection();
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragDistance = 0;
}
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
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 === 1) {
dragDistance += Math.abs(dx) + Math.abs(dy);
orbit.theta -= dx * 0.0055;
orbit.phi -= dy * 0.0045;
updateCamera();
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0) {
orbit.radius *= previousPinchDistance / Math.max(distance, 1);
updateCamera();
}
previousPinchDistance = distance;
}
});
function endPointer(event, cancelled = false) {
const wasSingle = pointers.size === 1;
pointers.delete(event.pointerId);
if (!cancelled && wasSingle && dragDistance < 6) {
pickStall(event.clientX, event.clientY);
}
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", (event) => {
endPointer(event, false);
});
renderer.domElement.addEventListener("pointercancel", (event) => {
endPointer(event, true);
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius += event.deltaY * 0.035;
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
Object.assign(orbit, {
theta: defaultOrbit.theta,
phi: defaultOrbit.phi,
radius: defaultOrbit.radius
});
orbit.target.copy(defaultOrbit.target);
updateCamera();
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
// -------------------------------------------------------------------------
// Interface
// -------------------------------------------------------------------------
function setTarget(value) {
state.target = THREE.MathUtils.clamp(value, 0, 1);
ui.slider.value = String(Math.round(state.target * 100));
ui.phaseButtons.forEach((button) => {
const active =
Number(button.dataset.phase) === (state.target > 0.5 ? 1 : 0);
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
}
function updateAutoButton() {
ui.auto.classList.toggle("active", state.auto);
ui.auto.textContent = state.auto ? "Pause cycle" : "Auto cycle";
}
function updateSelection() {
if (state.selectedStall === null) return;
const index = state.selectedStall;
const stall = stalls[index];
const area =
state.phase < 0.5
? stall.userData.day.zone
: stall.userData.evening.zone;
ui.selectionName.textContent = stallNames[index];
ui.selectionDetail.textContent =
`Fictional ${index + 1 < 10 ? "0" : ""}${index + 1} voxel stall · ` +
`${area}. The canopy and surrounding crowd density shift with the market phase.`;
}
ui.phaseButtons.forEach((button) => {
button.addEventListener("click", () => {
state.auto = false;
state.autoClock = 0;
updateAutoButton();
setTarget(Number(button.dataset.phase));
});
});
ui.slider.addEventListener("input", () => {
state.auto = false;
state.autoClock = 0;
updateAutoButton();
setTarget(Number(ui.slider.value) / 100);
});
ui.auto.addEventListener("click", () => {
state.auto = !state.auto;
state.autoClock = 0;
updateAutoButton();
});
ui.routes.addEventListener("click", () => {
state.routesVisible = !state.routesVisible;
routeGroup.visible = state.routesVisible;
ui.routes.classList.toggle("active", state.routesVisible);
ui.routes.setAttribute("aria-pressed", String(state.routesVisible));
});
ui.occupied.addEventListener("click", () => {
state.occupiedVisible = !state.occupiedVisible;
occupiedGroup.visible = state.occupiedVisible;
ui.occupied.classList.toggle("active", state.occupiedVisible);
ui.occupied.setAttribute("aria-pressed", String(state.occupiedVisible));
});
$("#reset-view").addEventListener("click", () => {
Object.assign(orbit, {
theta: defaultOrbit.theta,
phi: defaultOrbit.phi,
radius: defaultOrbit.radius
});
orbit.target.copy(defaultOrbit.target);
updateCamera();
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const daySunPosition = new THREE.Vector3(28, 38, 20);
const eveningSunPosition = new THREE.Vector3(-20, 19, 8);
const daySunColor = new THREE.Color(0xffe8b6);
const eveningSunColor = new THREE.Color(0xff7650);
const dayHemisphereColor = new THREE.Color(0xfff2cf);
const eveningHemisphereColor = new THREE.Color(0x7776a4);
const dayGroundLight = new THREE.Color(0x9c6947);
const eveningGroundLight = new THREE.Color(0x302536);
const dayPlazaColor = new THREE.Color(0xd3ae77);
const eveningPlazaColor = new THREE.Color(0x8e6c55);
const dayStripeColor = new THREE.Color(0xe8cfa5);
const eveningStripeColor = new THREE.Color(0xffd990);
const dayLabelAnchor = new THREE.Vector3(-19, 0.4, 5);
const eveningLabelAnchor = new THREE.Vector3(8, 0.4, 8);
const projected = new THREE.Vector3();
let uiClock = 0;
function positionWorldLabel(element, worldPosition, opacity) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
opacity > 0.02;
element.style.display = visible ? "block" : "none";
element.style.opacity = String(opacity);
if (!visible) return;
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
state.elapsed += dt;
if (state.auto) {
state.autoClock += dt;
if (state.autoClock > 7) {
state.autoClock = 0;
setTarget(state.target > 0.5 ? 0 : 1);
}
}
// Smooth, non-linear transition between the two layouts.
state.phase +=
(state.target - state.phase) * (1 - Math.exp(-dt * 2.75));
const p = THREE.MathUtils.clamp(state.phase, 0, 1);
// Stalls move from edge rows to a central evening grid.
for (const stall of stalls) {
const { day, evening } = stall.userData;
stall.position.lerpVectors(
new THREE.Vector3(day.x, 0, day.z),
new THREE.Vector3(evening.x, 0, evening.z),
p
);
stall.rotation.y = THREE.MathUtils.lerp(day.rot, evening.rot, p);
stall.userData.canopyMaterial.color.lerpColors(
stall.userData.dayColor,
stall.userData.eveningColor,
p
);
stall.userData.stripeMaterial.color.lerpColors(
dayStripeColor,
eveningStripeColor,
p
);
stall.userData.lanternMaterial.opacity = 0.04 + p * 0.96;
}
// Occupied ground changes from four edge strips to a central cluster.
for (const zone of zones) {
const opacity = THREE.MathUtils.lerp(
zone.userData.dayOpacity,
zone.userData.eveningOpacity,
p
);
zone.userData.fillMaterial.opacity = opacity;
zone.userData.borderMaterial.opacity = Math.min(1, opacity * 1.7);
zone.userData.fillMaterial.color.lerpColors(
zoneDayColor,
zoneNightColor,
p
);
zone.userData.borderMaterial.color.copy(
zone.userData.fillMaterial.color
);
zone.visible = opacity > 0.003;
}
// Route systems cross-fade.
for (const route of routes) {
const opacity = THREE.MathUtils.lerp(
route.userData.dayOpacity,
route.userData.eveningOpacity,
p
);
route.material.opacity = opacity;
route.material.color.lerpColors(
routeDayColor,
routeNightColor,
p
);
}
// Visitors redistribute from edge rows into the evening food court.
for (const person of people) {
person.position.lerpVectors(
person.userData.day,
person.userData.evening,
p
);
const bob =
Math.sin(state.elapsed * 6.2 + person.userData.phase) *
(0.012 + p * 0.025);
person.position.y = bob;
person.rotation.y += dt * (0.08 + p * 0.13);
}
// Lighting and atmosphere.
scene.background.lerpColors(dayBackground, eveningBackground, p);
scene.fog.color.copy(scene.background);
groundMaterial.color.lerpColors(dayPlazaColor, eveningPlazaColor, p);
hemisphere.color.lerpColors(
dayHemisphereColor,
eveningHemisphereColor,
p
);
hemisphere.groundColor.lerpColors(
dayGroundLight,
eveningGroundLight,
p
);
hemisphere.intensity = THREE.MathUtils.lerp(2.35, 0.72, p);
sun.color.lerpColors(daySunColor, eveningSunColor, p);
sun.position.lerpVectors(daySunPosition, eveningSunPosition, p);
sun.intensity = THREE.MathUtils.lerp(3.25, 0.52, p);
fillLight.intensity = THREE.MathUtils.lerp(0.55, 0.28, p);
fillLight.color.lerpColors(
new THREE.Color(0x88b9cf),
new THREE.Color(0x695a9c),
p
);
renderer.toneMappingExposure = THREE.MathUtils.lerp(1.03, 0.9, p);
lampMaterial.emissiveIntensity = THREE.MathUtils.lerp(0.04, 3.1, p);
eveningLights.forEach((light, index) => {
light.intensity =
THREE.MathUtils.lerp(0, 34 + (index % 3) * 5, p);
});
starMaterial.opacity = p * 0.78;
// Steam animation.
for (const puff of steam) {
const stall = stalls[puff.stallIndex];
if (!stall) continue;
const cycle = (state.elapsed * 0.16 + puff.offset) % 1;
puff.mesh.position.set(
stall.position.x + Math.sin(puff.offset * 5) * 0.35,
2.9 + cycle * 2.4,
stall.position.z + Math.cos(puff.offset * 4) * 0.25
);
puff.mesh.scale.setScalar(0.2 + cycle * 0.48);
puff.mesh.rotation.y += dt * 0.35;
puff.material.opacity =
(1 - cycle) * 0.18 * (0.18 + p * 0.82);
}
// World-space labels.
positionWorldLabel(
ui.dayLabel,
dayLabelAnchor,
Math.max(0, 1 - p * 1.8)
);
positionWorldLabel(
ui.nightLabel,
eveningLabelAnchor,
Math.max(0, (p - 0.35) * 1.7)
);
// Lightweight UI refresh.
uiClock += dt;
if (uiClock > 0.08) {
uiClock = 0;
const minutes = Math.round(
THREE.MathUtils.lerp(16 * 60 + 20, 20 * 60 + 45, p)
);
const hours = Math.floor(minutes / 60);
const mins = minutes % 60;
ui.time.textContent =
`${String(hours).padStart(2, "0")}:${String(mins).padStart(2, "0")}`;
ui.activity.textContent =
`${Math.round(THREE.MathUtils.lerp(38, 96, p))}%`;
ui.zones.textContent =
p < 0.5 ? "4 edge" : "3 core";
updateSelection();
}
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.8));
});
$("#loading").remove();
animate();
</script>
</body>
</html>
```