Prompt specification
Build or customize the Three.js 3D scene "Shared square during market and assembly" 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: Shared square during market and assembly
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/shared-square-during-market-and-assembly-x2272
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring an ancient Greek agora and its shared uses. Let users switch between market and meeting arrangements on the same ground plan. Move temporary furniture while keeping permanent buildings fixed and labeling the scenario as illustrative. Voxel style.
Working Three.js Starter (shared-square-during-market-and-assembly-x2272):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Shared Agora — Interactive Voxel Scene</title>
<style>
:root {
--ink: #27332e;
--muted: #687169;
--paper: #fffaf0;
--paper-strong: rgba(255, 250, 240, 0.94);
--line: rgba(64, 74, 65, 0.18);
--fixed: #b65f3d;
--fixed-soft: #ead0bd;
--movable: #167f78;
--movable-soft: #c9e3dc;
--shadow: 0 18px 50px rgba(48, 43, 31, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8c8a7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene,
#scene canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene canvas {
display: block;
touch-action: none;
outline: none;
}
.wash {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(255, 250, 235, 0.18), transparent 28%),
radial-gradient(circle at 50% 45%, transparent 48%, rgba(62, 53, 39, 0.14));
z-index: 2;
}
.intro {
position: fixed;
z-index: 5;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px 18px;
border: 1px solid rgba(255, 255, 255, 0.52);
border-radius: 18px;
background: var(--paper-strong);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--movable);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--movable);
box-shadow: 0 0 0 4px rgba(22, 127, 120, 0.12);
}
h1 {
margin: 0;
max-width: 340px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(32px, 4vw, 48px);
font-weight: 500;
line-height: 0.99;
letter-spacing: -0.035em;
}
.intro p {
margin: 13px 0 15px;
max-width: 345px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.illustrative {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(182, 95, 61, 0.35);
border-radius: 7px;
background: rgba(182, 95, 61, 0.08);
color: #8c462b;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
line-height: 1.35;
text-transform: uppercase;
}
.illustrative::before {
content: "";
width: 6px;
height: 6px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--fixed);
}
.status-panel {
position: fixed;
z-index: 5;
top: 24px;
right: 24px;
width: 238px;
padding: 15px 16px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 15px;
background: rgba(255, 250, 240, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
pointer-events: none;
}
.status-kicker {
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.status-mode {
margin-top: 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
line-height: 1.05;
}
.status-description {
min-height: 34px;
margin: 7px 0 12px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.status-rule {
height: 1px;
margin: 0 0 10px;
background: var(--line);
}
.status-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.status-stat {
padding: 8px 9px;
border-radius: 9px;
background: rgba(39, 51, 46, 0.045);
}
.status-stat strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
}
.status-stat span {
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
display: flex;
align-items: center;
gap: 6px;
max-width: 180px;
padding: 5px 8px 5px 5px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 6px;
background: rgba(255, 250, 240, 0.9);
box-shadow: 0 5px 16px rgba(52, 46, 36, 0.14);
color: var(--ink);
opacity: 0;
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
white-space: nowrap;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 10px;
background: rgba(39, 51, 46, 0.32);
}
.world-label .label-tag {
padding: 3px 4px;
border-radius: 4px;
font-size: 7px;
font-weight: 900;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.world-label strong {
overflow: hidden;
font-size: 10px;
font-weight: 750;
text-overflow: ellipsis;
}
.world-label.fixed .label-tag {
background: var(--fixed-soft);
color: #8c462b;
}
.world-label.movable .label-tag {
background: var(--movable-soft);
color: #0d6862;
}
.dock {
position: fixed;
z-index: 8;
left: 50%;
bottom: 20px;
width: min(960px, calc(100vw - 32px));
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 17px;
background: rgba(255, 250, 240, 0.94);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
transform: translateX(-50%);
}
.dock-main {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 16px;
}
.control-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.segmented {
display: flex;
gap: 4px;
padding: 4px;
border-radius: 11px;
background: rgba(39, 51, 46, 0.075);
}
.segmented button,
.action-button {
border: 0;
border-radius: 8px;
cursor: pointer;
transition:
color 150ms ease,
background 150ms ease,
transform 150ms ease,
box-shadow 150ms ease;
}
.segmented button {
min-width: 104px;
padding: 9px 12px;
background: transparent;
color: var(--muted);
font-size: 11px;
font-weight: 800;
}
.segmented button:hover {
color: var(--ink);
}
.segmented button.active {
background: var(--ink);
color: #fffaf0;
box-shadow: 0 4px 11px rgba(39, 51, 46, 0.18);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 10px 18px;
justify-content: center;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
}
.swatch.fixed {
background: var(--fixed);
}
.swatch.movable {
background: var(--movable);
}
.actions {
display: flex;
gap: 6px;
}
.action-button {
padding: 9px 11px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.52);
color: var(--ink);
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
.action-button:hover {
background: white;
transform: translateY(-1px);
}
.action-button:active {
transform: translateY(0);
}
.instruction-row {
display: flex;
justify-content: space-between;
gap: 18px;
margin-top: 9px;
padding: 8px 4px 0;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
#liveStatus {
color: var(--ink);
font-weight: 650;
}
#liveStatus[data-tone="blocked"] {
color: #a1472b;
}
#liveStatus[data-tone="movable"] {
color: #0d6862;
}
.key-help {
flex: 0 0 auto;
text-align: right;
}
kbd {
padding: 2px 4px;
border: 1px solid var(--line);
border-bottom-width: 2px;
border-radius: 4px;
background: rgba(255, 255, 255, 0.55);
color: var(--ink);
font: inherit;
font-size: 8px;
font-weight: 800;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #e8dbc0;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
.intro {
top: 12px;
left: 12px;
width: min(340px, calc(100vw - 24px));
padding: 15px 17px;
}
h1 {
font-size: 34px;
}
.intro p {
margin: 10px 0 12px;
font-size: 11px;
}
.status-panel {
display: none;
}
.dock {
bottom: 10px;
width: calc(100vw - 20px);
padding: 10px;
}
.dock-main {
grid-template-columns: 1fr auto;
gap: 9px;
}
.legend {
grid-column: 1 / -1;
grid-row: 2;
justify-content: flex-start;
}
.actions {
align-self: end;
}
.segmented button {
min-width: 92px;
padding: 8px 9px;
}
.instruction-row {
font-size: 9px;
}
.key-help {
display: none;
}
}
@media (max-width: 460px) {
.illustrative {
font-size: 8px;
}
.intro p {
display: none;
}
.world-label strong {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="wash"></div>
<header class="intro">
<div class="eyebrow">Agora / Shared Ground</div>
<h1>One place.<br>Many civic lives.</h1>
<p>
A permanent stone framework supports changing layers of trade, debate,
ritual, and everyday encounter. Switch the temporary arrangement to
reveal the same ground serving different communities.
</p>
<div class="illustrative">
Illustrative scenario · not an archaeological reconstruction
</div>
</header>
<aside class="status-panel">
<div class="status-kicker">Active arrangement</div>
<div id="modeName" class="status-mode">Market day</div>
<div id="modeDescription" class="status-description">
Goods, exchange, food, and practical conversation.
</div>
<div class="status-rule"></div>
<div class="status-grid">
<div class="status-stat">
<strong>7</strong>
<span>Fixed elements</span>
</div>
<div class="status-stat">
<strong>4</strong>
<span>Movable modules</span>
</div>
</div>
</aside>
<div id="labels"></div>
<section class="dock" aria-label="Scene controls">
<div class="dock-main">
<div>
<span class="control-label">Illustrative scenario</span>
<div class="segmented" role="group" aria-label="Choose an agora arrangement">
<button class="active" data-mode="market" aria-pressed="true">
Market day
</button>
<button data-mode="meeting" aria-pressed="false">
Civic assembly
</button>
</div>
</div>
<div class="legend" aria-label="Scene legend">
<span><i class="swatch fixed"></i> Permanent · locked</span>
<span><i class="swatch movable"></i> Temporary · draggable</span>
</div>
<div class="actions">
<button class="action-button" data-action="reset">Reset layout</button>
<button class="action-button" data-action="view" id="viewButton">
Plan view
</button>
</div>
</div>
<div class="instruction-row">
<span id="liveStatus" aria-live="polite">
Drag teal temporary furniture. Permanent architecture remains fixed.
</span>
<span class="key-help">
Drag ground to orbit · right-drag to pan · wheel to zoom · arrow keys to nudge
</span>
</div>
</section>
<div id="loading">Building the agora…</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 container = document.getElementById("scene");
const labelLayer = document.getElementById("labels");
const liveStatus = document.getElementById("liveStatus");
const modeName = document.getElementById("modeName");
const modeDescription = document.getElementById("modeDescription");
const viewButton = document.getElementById("viewButton");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8c8a7);
scene.fog = new THREE.Fog(0xd8c8a7, 63, 110);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
container.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel-style ancient Greek agora. Drag temporary furniture, " +
"drag empty ground to orbit, and use arrow keys to move selected furniture."
);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
180
);
const cameraState = {
target: new THREE.Vector3(0, 0, 0),
radius: 45,
theta: 0.72,
phi: 0.92,
topView: false
};
const hemisphere = new THREE.HemisphereLight(0xffefcf, 0x756b58, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d0, 3.15);
sun.position.set(-19, 34, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -31;
sun.shadow.camera.right = 31;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 85;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d4d0, 0.55);
fill.position.set(22, 14, -18);
scene.add(fill);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
const MAT = {
ground: material(0xc9b58d),
plaza: material(0xd7c39c),
limestone: material(0xd9c9a4),
limestoneLight: material(0xeadcba),
limestoneDark: material(0xbdaa83),
shadowStone: material(0xa99776),
terracotta: material(0xa95538),
terracottaLight: material(0xc87550),
roof: material(0x8e4634),
wood: material(0x75503a),
woodLight: material(0x9a7048),
teal: material(0x177f78),
tealLight: material(0x4fa79c),
cream: material(0xf0dfb8),
water: material(0x5b9e9a, {
roughness: 0.24,
metalness: 0.05
}),
olive: material(0x627a54),
oliveLight: material(0x829263),
trunk: material(0x6a4b35),
dark: material(0x3d443d),
basket: material(0xb58a51),
produce: material(0xc87932),
produceLight: material(0x78934c)
};
function addBox(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
mat,
segments = 8
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addColumn(parent, x, z, height = 2.45, mat = MAT.limestone) {
addBox(parent, [0.66, 0.24, 0.66], [x, 0.12, z], MAT.limestoneDark);
addBox(
parent,
[0.36, height, 0.36],
[x, 0.24 + height / 2, z],
mat
);
addBox(
parent,
[0.67, 0.25, 0.67],
[x, 0.36 + height, z],
MAT.limestoneLight
);
}
// ------------------------------------------------------------
// Ground and plaza tiles
// ------------------------------------------------------------
addBox(
scene,
[49, 0.8, 35],
[0, -0.72, 0],
MAT.ground,
false
);
addBox(
scene,
[36.5, 0.38, 25.5],
[0, -0.27, 0],
MAT.plaza,
false
);
const tileColumns = 35;
const tileRows = 24;
const tileGeometry = new THREE.BoxGeometry(0.96, 0.08, 0.96);
const tileMaterial = material(0xffffff);
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileColumns * tileRows
);
const tileTransform = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < tileRows; row++) {
for (let column = 0; column < tileColumns; column++) {
const x = column - (tileColumns - 1) / 2;
const z = row - (tileRows - 1) / 2;
tileTransform.position.set(x, -0.025, z);
tileTransform.updateMatrix();
tiles.setMatrixAt(tileIndex, tileTransform.matrix);
tileColor.set(0xd9c8a2);
tileColor.offsetHSL(
0,
(Math.random() - 0.5) * 0.025,
(Math.random() - 0.5) * 0.075
);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
// A subtle central paving cross.
addBox(
scene,
[2.1, 0.025, 18.8],
[0, 0.035, 0],
MAT.limestoneDark,
false
);
addBox(
scene,
[25.8, 0.027, 1.9],
[0, 0.037, 0],
MAT.limestoneDark,
false
);
// ------------------------------------------------------------
// Permanent architecture
// ------------------------------------------------------------
const architectureRoot = new THREE.Group();
architectureRoot.name = "Permanent architecture";
architectureRoot.userData.permanent = true;
scene.add(architectureRoot);
// North stoa.
addBox(
architectureRoot,
[15.6, 0.34, 3.0],
[-7, 0.13, -11.35],
MAT.limestoneDark
);
addBox(
architectureRoot,
[15.6, 2.55, 0.55],
[-7, 1.48, -12.35],
MAT.limestone
);
addBox(
architectureRoot,
[16.2, 0.46, 3.2],
[-7, 3.04, -11.38],
MAT.roof
);
for (let i = 0; i < 8; i++) {
addColumn(architectureRoot, -14 + i * 2, -10.25);
}
// West stoa.
addBox(
architectureRoot,
[3.0, 0.32, 19.2],
[-16.5, 0.13, 0],
MAT.limestoneDark
);
addBox(
architectureRoot,
[0.55, 2.55, 19.2],
[-17.65, 1.48, 0],
MAT.limestone
);
addBox(
architectureRoot,
[3.2, 0.46, 20.0],
[-16.5, 3.04, 0],
MAT.roof
);
for (let i = 0; i < 9; i++) {
addColumn(architectureRoot, -15.35, -8.5 + i * 2.1);
}
// East stoa.
addBox(
architectureRoot,
[3.0, 0.32, 19.2],
[16.5, 0.13, 0],
MAT.limestoneDark
);
addBox(
architectureRoot,
[0.55, 2.55, 19.2],
[17.65, 1.48, 0],
MAT.limestone
);
addBox(
architectureRoot,
[3.2, 0.46, 20.0],
[16.5, 3.04, 0],
MAT.roof
);
for (let i = 0; i < 9; i++) {
addColumn(architectureRoot, 15.35, -8.5 + i * 2.1);
}
// Temple on a raised podium.
const temple = new THREE.Group();
temple.position.set(8, 0.55, -9.55);
architectureRoot.add(temple);
addBox(
architectureRoot,
[8.2, 0.55, 5.7],
[8, 0.23, -9.55],
MAT.limestoneDark
);
addBox(
architectureRoot,
[7.3, 0.22, 1.1],
[8, 0.18, -6.25],
MAT.limestoneLight
);
addBox(
architectureRoot,
[6.6, 0.16, 0.9],
[8, 0.07, -5.85],
MAT.limestoneLight
);
const templeXs = [4.75, 6.05, 7.35, 8.65, 9.95, 11.25];
for (const x of templeXs) {
addColumn(temple, x - 8, 2.05, 2.3);
}
for (const x of [-3.25, 3.25]) {
addColumn(temple, x, 0.55, 2.3);
addColumn(temple, x, -1.15, 2.3);
}
addBox(temple, [8.3, 0.52, 5.2], [0, 2.95, 0], MAT.limestoneLight);
addBox(temple, [7.8, 0.42, 4.8], [0, 3.38, 0], MAT.roof);
addBox(temple, [6.7, 0.38, 4.0], [0, 3.77, 0], MAT.terracotta);
addBox(temple, [5.4, 0.34, 3.2], [0, 4.11, 0], MAT.roof);
addBox(temple, [3.9, 0.30, 2.45], [0, 4.42, 0], MAT.terracotta);
// Low-poly, block-built tholos.
const tholos = new THREE.Group();
tholos.position.set(-8, 0, -2);
architectureRoot.add(tholos);
addCylinder(tholos, 2.9, 2.9, 0.3, [0, 0.14, 0], MAT.limestoneDark);
addCylinder(tholos, 2.55, 2.65, 0.28, [0, 0.42, 0], MAT.limestone);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const x = Math.cos(angle) * 2.05;
const z = Math.sin(angle) * 2.05;
addBox(tholos, [0.34, 2.1, 0.34], [x, 1.56, z], MAT.limestone);
addBox(tholos, [0.57, 0.2, 0.57], [x, 2.73, z], MAT.limestoneLight);
}
addCylinder(tholos, 2.75, 2.75, 0.34, [0, 2.95, 0], MAT.roof);
addCylinder(tholos, 2.15, 2.55, 0.55, [0, 3.38, 0], MAT.terracotta);
// Central fountain.
const fountain = new THREE.Group();
architectureRoot.add(fountain);
addCylinder(fountain, 2.1, 2.25, 0.42, [0, 0.2, 0], MAT.limestoneDark);
addCylinder(fountain, 1.82, 1.82, 0.22, [0, 0.48, 0], MAT.limestone);
addCylinder(fountain, 1.55, 1.55, 0.07, [0, 0.62, 0], MAT.water, 16);
addBox(fountain, [0.55, 1.0, 0.55], [0, 1.02, 0], MAT.limestoneLight);
addBox(fountain, [1.25, 0.18, 0.42], [0, 1.52, 0], MAT.limestone);
// South propylon / gateway.
addBox(
architectureRoot,
[7.4, 0.34, 2.5],
[0, 0.14, 11.1],
MAT.limestoneDark
);
addColumn(architectureRoot, -2.75, 10.65, 2.45);
addColumn(architectureRoot, 2.75, 10.65, 2.45);
addBox(
architectureRoot,
[6.5, 0.52, 1.05],
[0, 3.0, 10.8],
MAT.limestoneLight
);
addBox(
architectureRoot,
[7.2, 0.4, 2.2],
[0, 3.46, 10.95],
MAT.roof
);
// Blocky olive trees outside the civic enclosure.
function addOliveTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
addBox(tree, [1.9, 0.5, 1.9], [0, 0.05, 0], MAT.limestoneDark);
addBox(tree, [0.45, 2.1, 0.45], [0, 1.05, 0], MAT.trunk);
addBox(tree, [2.3, 1.2, 1.8], [0, 2.65, 0], MAT.olive);
addBox(tree, [1.8, 1.2, 2.2], [0.25, 3.2, 0.15], MAT.oliveLight);
addBox(tree, [1.15, 0.9, 1.1], [-0.65, 3.55, -0.25], MAT.olive);
}
addOliveTree(-21, -9, 1.05);
addOliveTree(-20.5, 7.5, 0.9);
addOliveTree(21, 8.5, 1.0);
addOliveTree(20.8, -9.5, 0.88);
// ------------------------------------------------------------
// World labels
// ------------------------------------------------------------
const fixedLabels = [];
const movableLabels = [];
function addFixedLabel(text, position, tag = "Fixed") {
const element = document.createElement("div");
element.className = "world-label fixed";
element.innerHTML =
`<span class="label-tag">${tag}</span><strong>${text}</strong>`;
labelLayer.appendChild(element);
fixedLabels.push({
element,
position: new THREE.Vector3(...position)
});
}
addFixedLabel("North stoa", [-7.2, 4.0, -11.2]);
addFixedLabel("West stoa", [-16.1, 4.0, 1.6]);
addFixedLabel("East stoa", [16.1, 4.0, -1.0]);
addFixedLabel("Temple", [8.0, 5.2, -9.2]);
addFixedLabel("Tholos", [-8.0, 4.55, -2.0]);
addFixedLabel("Central fountain", [0, 2.05, 0]);
addFixedLabel("South propylon", [0, 4.05, 10.9]);
// ------------------------------------------------------------
// Temporary furniture
// ------------------------------------------------------------
function createMarketStall(variant) {
const group = new THREE.Group();
// Teal woven ground cloth identifies the module as temporary.
addBox(group, [3.45, 0.07, 2.15], [0, 0.09, 0], MAT.tealLight);
// Counter.
addBox(group, [2.65, 0.78, 0.92], [0, 0.49, 0.18], MAT.wood);
addBox(group, [2.5, 0.5, 0.08], [0, 0.49, 0.68], MAT.teal);
addBox(group, [2.85, 0.13, 1.1], [0, 0.92, 0.18], MAT.woodLight);
// Four posts.
for (const x of [-1.36, 1.36]) {
for (const z of [-0.78, 0.82]) {
addBox(group, [0.16, 2.25, 0.16], [x, 1.2, z], MAT.wood);
}
}
// Striped awning.
for (let i = 0; i < 7; i++) {
const x = -1.62 + i * 0.54;
addBox(
group,
[0.54, 0.13, 2.12],
[x, 2.43, 0],
i % 2 === 0 ? MAT.cream : MAT.terracottaLight
);
addBox(
group,
[0.54, 0.32, 0.08],
[x, 2.2, 1.06],
i % 2 === 0 ? MAT.cream : MAT.terracottaLight
);
}
// Baskets and produce.
addBox(group, [0.56, 0.28, 0.48], [-0.78, 1.13, 0.2], MAT.basket);
addBox(group, [0.48, 0.24, 0.44], [0.03, 1.1, 0.26], MAT.basket);
addBox(group, [0.5, 0.23, 0.42], [0.77, 1.1, 0.2], MAT.basket);
const goods =
variant % 2 === 0 ? MAT.produce : MAT.produceLight;
for (let i = 0; i < 4; i++) {
addBox(
group,
[0.16, 0.15, 0.16],
[-0.91 + i * 0.16, 1.35, 0.18],
goods
);
}
// Crates and stacked amphora-like blocks.
addBox(group, [0.63, 0.48, 0.62], [-1.02, 0.32, 0.92], MAT.woodLight);
addBox(group, [0.52, 0.4, 0.52], [-0.95, 0.75, 0.91], MAT.basket);
addBox(group, [0.23, 0.5, 0.23], [1.02, 0.34, 0.96], MAT.terracotta);
addBox(group, [0.31, 0.18, 0.31], [1.02, 0.65, 0.96], MAT.terracottaLight);
return group;
}
function createMeetingModule(variant) {
const group = new THREE.Group();
addBox(group, [3.4, 0.06, 1.82], [0, 0.09, 0], MAT.tealLight);
if (variant === 0) {
// Low speaker's dais.
addBox(group, [2.75, 0.24, 1.12], [0, 0.23, 0], MAT.limestoneLight);
addBox(group, [2.5, 0.16, 0.58], [0, 0.58, 0.08], MAT.wood);
addBox(group, [2.5, 0.45, 0.12], [0, 0.82, -0.23], MAT.woodLight);
addBox(group, [0.52, 0.48, 0.44], [1.02, 0.77, 0.55], MAT.wood);
addBox(group, [0.58, 0.08, 0.42], [1.02, 1.04, 0.53], MAT.cream);
} else {
// Assembly bench.
addBox(group, [2.55, 0.18, 0.58], [0, 0.53, 0], MAT.wood);
addBox(group, [2.55, 0.47, 0.12], [0, 0.78, -0.31], MAT.woodLight);
addBox(group, [2.45, 0.06, 0.53], [0, 0.65, 0.02], MAT.teal);
for (const x of [-1.0, 1.0]) {
addBox(group, [0.16, 0.48, 0.45], [x, 0.26, 0], MAT.dark);
}
// Stools and a writing table.
addBox(group, [0.54, 0.12, 0.54], [-1.47, 0.47, 0.34], MAT.wood);
addBox(group, [0.13, 0.4, 0.13], [-1.47, 0.23, 0.34], MAT.dark);
addBox(group, [0.54, 0.12, 0.54], [1.46, 0.47, 0.31], MAT.wood);
addBox(group, [0.13, 0.4, 0.13], [1.46, 0.23, 0.31], MAT.dark);
if (variant === 1) {
addBox(group, [0.68, 0.12, 0.48], [0.86, 0.8, 0.64], MAT.wood);
addBox(group, [0.1, 0.68, 0.1], [0.86, 0.42, 0.64], MAT.dark);
addBox(group, [0.35, 0.06, 0.28], [0.86, 0.89, 0.63], MAT.cream);
}
}
return group;
}
const furnitureRoots = [];
const marketNames = [
"Produce stall",
"Textile stall",
"Olive-oil stall",
"Pottery stall"
];
const meetingNames = [
"Speaker's dais",
"Clerk's bench",
"Citizens' bench",
"Council bench"
];
for (let i = 0; i < 4; i++) {
const root = new THREE.Group();
root.userData.movableRoot = true;
root.userData.index = i;
const market = createMarketStall(i);
const meeting = createMeetingModule(i);
root.add(market, meeting);
root.userData.market = market;
root.userData.meeting = meeting;
const padMaterial = new THREE.MeshBasicMaterial({
color: 0x0e8178,
transparent: true,
opacity: 0.09,
depthWrite: false
});
const pad = new THREE.Mesh(
new THREE.BoxGeometry(3.65, 0.045, 2.35),
padMaterial
);
pad.position.y = 0.055;
root.add(pad);
root.userData.pad = pad;
scene.add(root);
furnitureRoots.push(root);
const labelElement = document.createElement("div");
labelElement.className = "world-label movable";
labelElement.innerHTML =
`<span class="label-tag">Move</span><strong>${marketNames[i]}</strong>`;
labelLayer.appendChild(labelElement);
movableLabels.push({
element: labelElement,
root,
marketText: marketNames[i],
meetingText: meetingNames[i]
});
}
// ------------------------------------------------------------
// Scenario arrangements and placement constraints
// ------------------------------------------------------------
const arrangements = {
market: [
[-3.2, -4.4],
[4.8, -3.8],
[-4.0, 4.2],
[5.5, 3.8]
],
meeting: [
[-2.5, -5.8],
[4.3, -5.0],
[-2.5, 5.5],
[4.3, 5.5]
]
};
const marketRotations = [0.02, -0.06, 0.08, -0.03];
// Axis-aligned zones occupied by permanent elements.
const fixedZones = [
{ minX: -15, maxX: 1, minZ: -13.1, maxZ: -9.7 }, // North stoa
{ minX: 3.7, maxX: 12.3, minZ: -12.5, maxZ: -6.1 }, // Temple
{ minX: 14.5, maxX: 18.2, minZ: -10, maxZ: 10 }, // East stoa
{ minX: -18.2, maxX: -14.5, minZ: -10, maxZ: 10 }, // West stoa
{ minX: -3.8, maxX: 3.8, minZ: 9.6, maxZ: 12.6 }, // Propylon
{ minX: -11.1, maxX: -4.9, minZ: -5.1, maxZ: 1.1 }, // Tholos
{ minX: -2.1, maxX: 2.1, minZ: -2.1, maxZ: 2.1 } // Fountain
];
let mode = "market";
let selectedRoot = null;
let hoveredRoot = null;
function placementIsValid(root, x, z) {
const halfWidth = 1.75;
const halfDepth = 1.08;
const minX = x - halfWidth;
const maxX = x + halfWidth;
const minZ = z - halfDepth;
const maxZ = z + halfDepth;
for (const zone of fixedZones) {
const overlaps =
minX < zone.maxX &&
maxX > zone.minX &&
minZ < zone.maxZ &&
maxZ > zone.minZ;
if (overlaps) return false;
}
for (const other of furnitureRoots) {
if (other === root) continue;
const overlaps =
Math.abs(x - other.position.x) < 3.25 &&
Math.abs(z - other.position.z) < 1.95;
if (overlaps) return false;
}
return true;
}
function setStatus(message, tone = "") {
liveStatus.textContent = message;
liveStatus.dataset.tone = tone;
}
function updatePadStates() {
for (const root of furnitureRoots) {
const opacity =
root === hoveredRoot ? 0.38 :
root === selectedRoot ? 0.25 :
0.09;
root.userData.pad.material.opacity = opacity;
}
}
function applyMode(nextMode, announce = true) {
mode = nextMode;
document.querySelectorAll("[data-mode]").forEach((button) => {
const active = button.dataset.mode === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
if (mode === "market") {
modeName.textContent = "Market day";
modeDescription.textContent =
"Goods, exchange, food, and practical conversation.";
} else {
modeName.textContent = "Civic assembly";
modeDescription.textContent =
"Public speaking, deliberation, voting, and civic memory.";
}
furnitureRoots.forEach((root, index) => {
const [x, z] = arrangements[mode][index];
root.position.set(x, 0, z);
root.userData.market.visible = mode === "market";
root.userData.meeting.visible = mode === "meeting";
if (mode === "meeting") {
// Rotate benches to face the open civic center.
root.rotation.y = Math.atan2(-x, -z);
} else {
root.rotation.y = marketRotations[index];
}
root.scale.setScalar(0.86);
});
movableLabels.forEach((label, index) => {
const text =
mode === "market" ? label.marketText : label.meetingText;
label.element.querySelector("strong").textContent = text;
});
selectedRoot = null;
hoveredRoot = null;
updatePadStates();
if (announce) {
setStatus(
mode === "market"
? "Market arrangement loaded. The four teal stalls are temporary and movable."
: "Assembly arrangement loaded. The four teal seating modules are temporary and movable."
);
}
}
function resetArrangement(announce = true) {
applyMode(mode, false);
if (announce) {
setStatus("Temporary furniture returned to the current scenario’s starting layout.");
}
}
// ------------------------------------------------------------
// Labels
// ------------------------------------------------------------
const projected = new THREE.Vector3();
const worldPosition = new THREE.Vector3();
function updateLabels() {
const width = renderer.domElement.clientWidth;
const height = renderer.domElement.clientHeight;
function positionLabel(element, position) {
projected.copy(position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
if (!visible) {
element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = "1";
}
for (const label of fixedLabels) {
positionLabel(label.element, label.position);
}
for (const label of movableLabels) {
const localY = mode === "market" ? 3.15 : 1.42;
worldPosition.set(0, localY, 0);
label.root.localToWorld(worldPosition);
positionLabel(label.element, worldPosition);
}
}
// ------------------------------------------------------------
// Picking and dragging
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.08);
const intersectionPoint = new THREE.Vector3();
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function isActuallyVisible(object) {
let current = object;
while (current) {
if (!current.visible) return false;
current = current.parent;
}
return true;
}
function findMovableRoot(object) {
let current = object;
while (current && current !== scene) {
if (current.userData.movableRoot) return current;
current = current.parent;
}
return null;
}
function pickMovable(event) {
updatePointer(event);
const intersections = raycaster.intersectObjects(furnitureRoots, true);
for (const intersection of intersections) {
if (!isActuallyVisible(intersection.object)) continue;
const root = findMovableRoot(intersection.object);
if (root) return root;
}
return null;
}
function pickPermanent(event) {
updatePointer(event);
const intersections = raycaster.intersectObject(architectureRoot, true);
for (const intersection of intersections) {
if (isActuallyVisible(intersection.object)) return true;
}
return false;
}
function getGroundPoint(event) {
updatePointer(event);
return raycaster.ray.intersectPlane(dragPlane, intersectionPoint);
}
function setCameraView(top) {
cameraState.topView = top;
if (top) {
cameraState.theta = 0;
cameraState.phi = 0.075;
cameraState.radius = 48;
viewButton.textContent = "3D view";
setStatus("Plan view selected. Temporary modules remain draggable.");
} else {
cameraState.theta = 0.72;
cameraState.phi = 0.92;
cameraState.radius = 45;
viewButton.textContent = "Plan view";
setStatus("Three-quarter view selected.");
}
}
// ------------------------------------------------------------
// Direct camera controls
// ------------------------------------------------------------
const activePointers = new Map();
let dragging = null;
let orbiting = false;
let panning = false;
let pinchDistance = 0;
function updateCamera() {
const { target, radius, theta, phi } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function clampTarget() {
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-9,
9
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-7,
7
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.focus({ preventScroll: true });
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size >= 2) {
dragging = null;
orbiting = false;
panning = false;
const pointers = [...activePointers.values()];
pinchDistance = Math.hypot(
pointers[0].x - pointers[1].x,
pointers[0].y - pointers[1].y
);
return;
}
if (event.button === 0) {
const root = pickMovable(event);
if (root) {
selectedRoot = root;
hoveredRoot = root;
updatePadStates();
const point = getGroundPoint(event);
if (point) {
dragging = {
root,
offsetX: root.position.x - point.x,
offsetZ: root.position.z - point.z
};
renderer.domElement.style.cursor = "grabbing";
setStatus(
`Moving ${mode === "market" ? "stall" : "assembly module"}. ` +
"Permanent architecture cannot be moved.",
"movable"
);
}
renderer.domElement.setPointerCapture(event.pointerId);
event.preventDefault();
return;
}
}
if (event.button === 2) {
panning = true;
} else {
orbiting = true;
}
renderer.domElement.setPointerCapture(event.pointerId);
event.preventDefault();
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (activePointers.has(event.pointerId)) {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
}
if (activePointers.size >= 2) {
const pointers = [...activePointers.values()];
const distance = Math.hypot(
pointers[0].x - pointers[1].x,
pointers[0].y - pointers[1].y
);
if (pinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / distance),
20,
78
);
}
pinchDistance = distance;
return;
}
if (dragging) {
const point = getGroundPoint(event);
if (!point) return;
const nextX = THREE.MathUtils.clamp(
point.x + dragging.offsetX,
-14.5,
14.5
);
const nextZ = THREE.MathUtils.clamp(
point.z + dragging.offsetZ,
-9.1,
8.7
);
if (placementIsValid(dragging.root, nextX, nextZ)) {
dragging.root.position.x = nextX;
dragging.root.position.z = nextZ;
setStatus(
"Temporary furniture repositioned. The permanent ground plan stays locked.",
"movable"
);
} else {
setStatus(
"That position overlaps fixed architecture or another temporary module.",
"blocked"
);
}
return;
}
if (orbiting) {
const previous = activePointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.004,
0.075,
1.34
);
previous.x = event.clientX;
previous.y = event.clientY;
return;
}
if (panning) {
const previous = activePointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
const scale = cameraState.radius * 0.0016;
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(
camera.quaternion
);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3(0, 0, -1).applyQuaternion(
camera.quaternion
);
forward.y = 0;
forward.normalize();
cameraState.target
.addScaledVector(right, -dx * scale)
.addScaledVector(forward, -dy * scale);
clampTarget();
previous.x = event.clientX;
previous.y = event.clientY;
return;
}
const root = pickMovable(event);
if (root !== hoveredRoot) {
hoveredRoot = root;
updatePadStates();
}
renderer.domElement.style.cursor = root ? "grab" : "default";
if (root) {
const label =
mode === "market" ? marketNames[root.userData.index] :
meetingNames[root.userData.index];
setStatus(
`${label} · temporary module. Drag to reposition.`,
"movable"
);
} else if (pickPermanent(event)) {
setStatus("Permanent architecture · fixed in the ground plan.");
} else {
setStatus(
"Drag empty ground to orbit, right-drag to pan, and use the wheel to zoom."
);
}
});
function finishPointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) pinchDistance = 0;
dragging = null;
orbiting = false;
panning = false;
renderer.domElement.style.cursor = "default";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", finishPointer);
renderer.domElement.addEventListener("pointercancel", finishPointer);
renderer.domElement.addEventListener("pointerleave", (event) => {
if (!dragging && !orbiting && !panning) {
hoveredRoot = null;
updatePadStates();
}
if (event.pointerType === "mouse") {
setStatus(
"Drag teal temporary furniture. Permanent architecture remains fixed."
);
}
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
20,
78
);
},
{ passive: false }
);
// Keyboard nudging for a selected temporary module.
renderer.domElement.addEventListener("keydown", (event) => {
if (!selectedRoot) return;
const step = event.shiftKey ? 1.5 : 0.5;
let dx = 0;
let dz = 0;
if (event.key === "ArrowLeft") dx = -step;
else if (event.key === "ArrowRight") dx = step;
else if (event.key === "ArrowUp") dz = -step;
else if (event.key === "ArrowDown") dz = step;
else return;
event.preventDefault();
const x = selectedRoot.position.x + dx;
const z = selectedRoot.position.z + dz;
if (placementIsValid(selectedRoot, x, z)) {
selectedRoot.position.x = x;
selectedRoot.position.z = z;
setStatus(
`Temporary module nudged ${step} units. Permanent elements remain fixed.`,
"movable"
);
} else {
setStatus(
"That move would overlap a fixed or temporary element.",
"blocked"
);
}
});
// ------------------------------------------------------------
// UI controls
// ------------------------------------------------------------
document.querySelectorAll("[data-mode]").forEach((button) => {
button.addEventListener("click", () => {
applyMode(button.dataset.mode);
});
});
document.querySelector('[data-action="reset"]').addEventListener("click", () => {
resetArrangement();
});
viewButton.addEventListener("click", () => {
setCameraView(!cameraState.topView);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
for (const root of furnitureRoots) {
const scale = root.scale.x;
const nextScale = THREE.MathUtils.lerp(scale, 1, 0.13);
root.scale.setScalar(nextScale);
}
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
applyMode("market", false);
updateCamera();
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```