Prompt specification
Build or customize the Three.js 3D scene "Supply a multistory block through one entrance" 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: Supply a multistory block through one entrance
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/supply-a-multistory-block-through-one-entrance-x2316
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts deliveries through a fictional Roman insula in low-poly form. Cut away the front of a multistory block so the street entrance, shared staircase, landings, and several small rooms remain visible. Place water vessels and bundled goods at the entrance, then let me choose an upstairs destination and watch a carrier follow the connected route. Count the actual path distance, including stairs, instead of comparing only vertical height. A second delivery to a lower room should reveal the difference in carrying distance. Keep walls and doorways fixed while destinations change. Include a narrow landing where the carrier must turn before entering a room, making the shared access geometry part of every delivery.
Working Three.js Starter (supply-a-multistory-block-through-one-entrance-x2316):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Insula Caelia — Delivery Routes</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(27, 23, 19, 0.92);
--line: rgba(255, 229, 185, 0.2);
--cream: #f7e8ca;
--muted: #c9b99e;
--accent: #f0a44b;
--cyan: #65d9e7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d6c4a5;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
width: min(390px, calc(100vw - 28px));
border: 1px solid var(--line);
border-radius: 16px;
color: var(--cream);
background: var(--panel);
box-shadow: 0 18px 50px rgba(31, 21, 10, 0.25);
backdrop-filter: blur(12px);
}
#controls {
left: 14px;
top: 14px;
padding: 17px;
}
h1 {
margin: 0;
color: #ffe0a7;
font-family: Georgia, "Times New Roman", serif;
font-size: 26px;
font-weight: 600;
letter-spacing: 0.02em;
}
.subtitle {
margin: 5px 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
label {
display: block;
margin-bottom: 6px;
color: #ead9ba;
font-size: 12px;
font-weight: 650;
letter-spacing: 0.04em;
text-transform: uppercase;
}
select,
button {
width: 100%;
min-height: 40px;
border-radius: 9px;
font: inherit;
}
select {
padding: 8px 10px;
border: 1px solid #75634c;
color: var(--cream);
background: #342b22;
}
button {
margin-top: 9px;
padding: 9px 12px;
border: 1px solid #c67c39;
color: #241a10;
background: linear-gradient(#f3b263, #dc8738);
font-weight: 750;
cursor: pointer;
transition: filter 120ms ease, transform 120ms ease;
}
button:hover {
filter: brightness(1.08);
}
button:active {
transform: translateY(1px);
}
button.secondary {
border-color: #526f72;
color: #d9f7f8;
background: #294448;
}
.hint {
margin: 12px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
#stats {
right: 14px;
top: 14px;
padding: 16px;
}
.stat-title {
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#distance {
margin: 3px 0 0;
color: #ffd18a;
font-size: 34px;
font-weight: 750;
line-height: 1.05;
}
#distance small {
color: var(--muted);
font-size: 13px;
font-weight: 500;
}
#routeDetail {
min-height: 36px;
margin-top: 8px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.progress {
height: 7px;
margin: 12px 0;
overflow: hidden;
border-radius: 999px;
background: #514538;
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #ef9d43, #78dce3);
transition: width 80ms linear;
}
#comparison {
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #d8e6df;
font-size: 12px;
line-height: 1.48;
}
#records {
width: 100%;
margin-top: 11px;
border-collapse: collapse;
font-size: 11px;
}
#records th,
#records td {
padding: 6px 4px;
border-bottom: 1px solid rgba(255, 255, 255, 0.09);
text-align: left;
}
#records th {
color: #a99a82;
font-weight: 600;
}
#records td:last-child,
#records th:last-child {
text-align: right;
}
#cameraHelp {
position: fixed;
z-index: 8;
left: 50%;
bottom: 12px;
transform: translateX(-50%);
padding: 8px 13px;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 999px;
color: #fff4df;
background: rgba(30, 24, 18, 0.72);
font-size: 11px;
white-space: nowrap;
pointer-events: none;
}
#reset {
position: fixed;
z-index: 9;
right: 14px;
bottom: 14px;
width: auto;
min-height: 34px;
margin: 0;
padding: 7px 12px;
font-size: 12px;
}
@media (max-width: 720px) {
#controls {
top: 8px;
left: 8px;
padding: 12px;
}
#stats {
top: auto;
right: 8px;
bottom: 50px;
padding: 12px;
}
h1 {
font-size: 21px;
}
.subtitle,
#cameraHelp {
display: none;
}
#distance {
font-size: 27px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="controls" class="panel">
<h1>Insula Caelia</h1>
<p class="subtitle">
A cutaway Roman apartment block. Walls and doorways remain fixed;
only the carrier and its route change.
</p>
<label for="destination">Delivery destination</label>
<select id="destination">
<option value="upper-weaver">Upper room — Weaver’s Cubiculum</option>
<option value="upper-store">Upper room — Blue Storeroom</option>
<option value="lower-cellar">Lower room — Cool Cellar</option>
</select>
<button id="deliver">Deliver selected</button>
<button id="compare" class="secondary">Run Upper → Lower comparison</button>
<p class="hint">
Every route begins at the street entrance and crosses the narrow common
landing. Upstairs deliveries then use the shared staircase and its
turning landing.
</p>
</section>
<section id="stats" class="panel">
<div class="stat-title">Full carrying distance</div>
<div id="distance">0.00 <small>m</small></div>
<div id="routeDetail">Choose a destination, then send the carrier.</div>
<div class="progress"><div id="progressFill"></div></div>
<div id="comparison">
Run the upper room first and the lower room second to compare their
actual routes.
</div>
<table id="records">
<thead>
<tr>
<th>Delivery</th>
<th>Distance</th>
</tr>
</thead>
<tbody></tbody>
</table>
</section>
<div id="cameraHelp">Drag to orbit · Scroll to zoom · Right-drag to pan</div>
<button id="reset" class="secondary">Reset view</button>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera, and direct (non-addon) camera controls
// -------------------------------------------------------------------------
const host = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.setClearColor(0xd6c4a5);
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xd6c4a5, 25, 50);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(-0.2, 3.7, -0.45);
const defaultCamera = {
radius: 21.5,
theta: 0.23,
phi: 1.17,
target: cameraTarget.clone()
};
const orbit = {
radius: defaultCamera.radius,
theta: defaultCamera.theta,
phi: defaultCamera.phi
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const pointerState = {
pointers: new Map(),
dragging: false,
panning: false,
lastX: 0,
lastY: 0,
pinchDistance: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointerState.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerState.pointers.size === 1) {
pointerState.dragging = true;
pointerState.panning = event.button === 2 || event.shiftKey;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
} else if (pointerState.pointers.size === 2) {
const [a, b] = [...pointerState.pointers.values()];
pointerState.pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerState.pointers.has(event.pointerId)) return;
pointerState.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerState.pointers.size >= 2) {
const [a, b] = [...pointerState.pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pointerState.pinchDistance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * pointerState.pinchDistance / Math.max(distance, 1),
10,
38
);
}
pointerState.pinchDistance = distance;
updateCamera();
return;
}
if (!pointerState.dragging) return;
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
if (pointerState.panning) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, up, new THREE.Vector3());
cameraTarget.addScaledVector(right, -dx * 0.012);
cameraTarget.addScaledVector(up, dy * 0.012);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -8, 8);
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, 1, 9);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -6, 5);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.48, 1.48);
}
updateCamera();
});
function releasePointer(event) {
pointerState.pointers.delete(event.pointerId);
if (pointerState.pointers.size === 0) {
pointerState.dragging = false;
pointerState.panning = false;
}
if (pointerState.pointers.size < 2) {
pointerState.pinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
10,
38
);
updateCamera();
}, { passive: false });
document.getElementById("reset").addEventListener("click", () => {
orbit.radius = defaultCamera.radius;
orbit.theta = defaultCamera.theta;
orbit.phi = defaultCamera.phi;
cameraTarget.copy(defaultCamera.target);
updateCamera();
});
// -------------------------------------------------------------------------
// Lighting and reusable geometry helpers
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xffefd3, 0x79634d, 2.25));
const sun = new THREE.DirectionalLight(0xffe0ae, 3.1);
sun.position.set(8, 16, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0005;
scene.add(sun);
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
flatShading: true,
...extra
});
const MAT = {
plaster: material(0xd9c39c),
plasterLight: material(0xead8b4),
plasterPink: material(0xcfaa88),
floor: material(0xa88761),
floorDark: material(0x816246),
stair: material(0xb89b74),
trim: material(0xa95732),
roof: material(0x8f3f27),
wood: material(0x63402a),
woodLight: material(0x9a6b42),
iron: material(0x3e3832, { metalness: 0.45, roughness: 0.58 }),
blue: material(0x315b69),
green: material(0x5c6c43),
cloth: material(0xc3a36c),
rope: material(0xb79b62),
water: material(0x4b9bad, { roughness: 0.25, metalness: 0.05 }),
skin: material(0xb87e55),
hair: material(0x34261d),
carrier: material(0xd6bd82),
carrierDark: material(0x6d3527),
sack: material(0x9c7546),
route: new THREE.LineBasicMaterial({ color: 0x64e0ed })
};
function box(w, h, d, mat, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rt, rb, h, mat, x, y, z, segments = 10, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(a, b, width, depth, mat, parent = scene) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, length, depth),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeSign(text, x, y, z, width = 2.3, color = "#f5dfb4") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(59, 39, 24, 0.92)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = color;
context.lineWidth = 5;
context.strokeRect(8, 8, canvas.width - 16, canvas.height - 16);
context.fillStyle = color;
context.font = "600 37px Georgia";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, width * 0.2),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide
})
);
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Street and fixed Roman insula architecture
// -------------------------------------------------------------------------
box(30, 0.35, 25, material(0x9b8d72), 0, -0.42, 3);
box(12.6, 0.32, 9.0, MAT.floorDark, 0, -0.16, -0.85);
// Instanced cobbles in the street.
const cobbleGeometry = new THREE.BoxGeometry(0.78, 0.09, 0.5);
const cobbleMaterial = material(0xb4a78e);
const cobbles = new THREE.InstancedMesh(cobbleGeometry, cobbleMaterial, 150);
const matrix = new THREE.Matrix4();
let cobbleIndex = 0;
for (let row = 0; row < 10 && cobbleIndex < 150; row++) {
for (let col = 0; col < 15 && cobbleIndex < 150; col++) {
const x = -10.5 + col * 1.5 + (row % 2) * 0.35;
const z = 3.85 + row * 0.72;
matrix.makeTranslation(x, -0.19 + Math.random() * 0.018, z);
cobbles.setMatrixAt(cobbleIndex++, matrix);
}
}
cobbles.receiveShadow = true;
scene.add(cobbles);
// Main shell: back and side walls are tall; the front is intentionally cut away.
box(12.0, 11.8, 0.28, MAT.plaster, 0, 5.9, -5.25);
box(0.28, 11.8, 8.85, MAT.plaster, -6.0, 5.9, -0.85);
box(0.28, 11.8, 3.0, MAT.plaster, 6.0, 5.9, -3.75);
// Upper floors leave the front atrium open.
function addFloorLevel(y) {
box(12.0, 0.16, 1.55, MAT.floor, 0, y - 0.08, -4.45);
box(12.0, 0.16, 1.40, MAT.floor, 0, y - 0.08, -3.0);
box(1.30, 0.18, 4.95, MAT.stair, -5.05, y - 0.09, -0.75);
}
addFloorLevel(4.0);
addFloorLevel(8.0);
// Rear roof cornice and Roman red tiles.
box(12.5, 0.35, 0.55, MAT.trim, 0, 11.85, -5.03);
for (let i = 0; i < 12; i++) {
box(0.94, 0.16, 1.05, MAT.roof, -5.5 + i, 12.08, -4.75);
}
// Rear structural columns.
for (const x of [-5.55, 5.55]) {
for (const y of [0, 4, 8]) {
cylinder(0.24, 0.29, 3.65, MAT.plasterLight, x, y + 1.825, -4.96, 10);
box(0.68, 0.18, 0.68, MAT.trim, x, y + 3.68, -4.96);
}
}
// Cut facade remnants, indicating the removed front wall.
for (const x of [-5.72, 5.72]) {
box(0.42, 11.8, 0.42, MAT.trim, x, 5.9, 3.36);
}
box(1.65, 0.32, 0.44, MAT.trim, -4.9, 3.95, 3.36);
box(1.65, 0.32, 0.44, MAT.trim, 4.9, 3.95, 3.36);
// Street entrance, centered on the common lower landing.
box(0.28, 2.45, 0.40, MAT.trim, 1.55, 1.225, 3.34);
box(0.28, 2.45, 0.40, MAT.trim, 3.25, 1.225, 3.34);
// Low-poly semicircular arch over the entrance.
for (let i = 0; i <= 10; i++) {
const angle = Math.PI - (i / 10) * Math.PI;
const arch = box(
0.30, 0.28, 0.42, MAT.trim,
2.4 + Math.cos(angle) * 0.88,
2.40 + Math.sin(angle) * 0.88,
3.34
);
arch.rotation.z = angle - Math.PI / 2;
}
makeSign("INSULA CAELIA", 2.4, 3.05, 3.58, 2.55);
// -------------------------------------------------------------------------
// Shared staircase and narrow turning landings
// -------------------------------------------------------------------------
const STEPS = 24;
const STAIR_RUN = 5.0;
const STAIR_RISE = 4.0;
const STAIR_Z = 1.30;
const SECOND_STAIR_Z = 0.10;
// First flight: solid Roman masonry steps.
for (let i = 0; i < STEPS; i++) {
const stepWidth = STAIR_RUN / STEPS + 0.025;
const height = STAIR_RISE * (i + 1) / STEPS;
const x = -STAIR_RUN * (i + 0.5) / STEPS;
box(stepWidth, height, 1.38, MAT.stair, x, height / 2, STAIR_Z);
}
// The continuation to the third storey, parallel but offset.
for (let i = 0; i < STEPS; i++) {
const stepWidth = STAIR_RUN / STEPS + 0.025;
const height = STAIR_RISE * (i + 1) / STEPS;
const x = -STAIR_RUN + STAIR_RUN * (i + 0.5) / STEPS;
box(
stepWidth, height, 1.15, MAT.stair,
x, 4 + height / 2, SECOND_STAIR_Z
);
}
// Third-floor landing for the second flight.
box(1.55, 0.18, 2.15, MAT.stair, 0.45, 3.91, -0.05);
// Narrow first-floor landing: the carrier reaches it moving west,
// turns north, then turns east into the shared corridor.
box(1.35, 0.18, 5.00, MAT.stair, -5.05, 3.91, -0.68);
// Common ground-floor landing and narrow lower passage.
box(1.45, 0.13, 1.35, MAT.stair, 1.40, -0.065, 1.30);
box(1.15, 0.13, 4.15, MAT.floorDark, 1.40, -0.065, -1.25);
// Simple rails on the open side of the first flight.
beamBetween(
[0.05, 0.72, 2.05],
[-5.0, 4.72, 2.05],
0.10, 0.10, MAT.wood
);
for (let i = 0; i <= 6; i++) {
const t = i / 6;
cylinder(
0.045, 0.055, 0.68, MAT.wood,
-5 * t, 0.34 + 4 * t, 2.05, 7
);
}
// -------------------------------------------------------------------------
// Fixed rooms and doorways
// -------------------------------------------------------------------------
function doorwayFrame(x, floorY, z, width = 1.2, height = 2.28) {
box(0.17, height, 0.24, MAT.trim, x - width / 2, floorY + height / 2, z);
box(0.17, height, 0.24, MAT.trim, x + width / 2, floorY + height / 2, z);
box(width + 0.34, 0.18, 0.26, MAT.trim, x, floorY + height, z);
}
function cutawayWallWithDoors(x1, x2, z, floorY, doors, wallHeight = 1.12) {
let cursor = x1;
for (const doorX of doors) {
const half = 0.62;
if (doorX - half > cursor) {
const width = doorX - half - cursor;
box(
width, wallHeight, 0.20, MAT.plaster,
cursor + width / 2, floorY + wallHeight / 2, z
);
}
doorwayFrame(doorX, floorY, z, 1.18);
cursor = doorX + half;
}
if (cursor < x2) {
const width = x2 - cursor;
box(
width, wallHeight, 0.20, MAT.plaster,
cursor + width / 2, floorY + wallHeight / 2, z
);
}
}
// Ground-floor lower room, visible through the open atrium.
cutawayWallWithDoors(0.10, 2.70, -0.80, 0, [1.40]);
box(0.20, 1.15, 1.55, MAT.plasterPink, 0.10, 0.575, -1.575);
box(0.20, 1.15, 1.55, MAT.plasterPink, 2.70, 0.575, -1.575);
box(2.80, 1.15, 0.20, MAT.plasterPink, 1.40, 0.575, -2.35);
makeSign("CELLAR", 1.40, 1.55, -0.66, 1.45, "#cce9dd");
// Small ground-floor rooms along the rear.
cutawayWallWithDoors(-5.80, 5.80, -3.70, 0, [-2.35, 3.55]);
box(0.18, 1.15, 1.48, MAT.plaster, -2.30, 0.575, -4.44);
box(0.18, 1.15, 1.48, MAT.plaster, 2.05, 0.575, -4.44);
makeSign("HORREUM", -2.35, 1.48, -3.56, 1.55);
// First-floor rooms.
cutawayWallWithDoors(-5.80, 5.80, -3.70, 4.0, [0.40, 3.60]);
box(0.18, 1.12, 1.48, MAT.plaster, -1.45, 4.56, -4.44);
box(0.18, 1.12, 1.48, MAT.plaster, 2.25, 4.56, -4.44);
makeSign("TEXTOR", 0.40, 5.55, -3.56, 1.55, "#f5d3a7");
makeSign("ARMARIUM", 3.60, 5.55, -3.56, 1.75, "#b9e1e6");
makeSign("COMMUNE", -4.82, 5.18, -2.34, 1.55, "#f0d28f");
// Third-floor rooms.
cutawayWallWithDoors(-5.80, 5.80, -3.70, 8.0, [-1.20, 2.80]);
box(0.18, 1.12, 1.48, MAT.plaster, 0.15, 8.56, -4.44);
box(0.18, 1.12, 1.48, MAT.plaster, 3.75, 8.56, -4.44);
makeSign("CUBICULA", -1.20, 9.55, -3.56, 1.70, "#edd0aa");
makeSign("TABERNA", 2.80, 9.55, -3.56, 1.60, "#d9c5e6");
// -------------------------------------------------------------------------
// Roman props: beds, tables, storage, pottery, bundles
// -------------------------------------------------------------------------
function bed(x, y, z, width = 1.35) {
box(width, 0.18, 2.0, MAT.woodLight, x, y + 0.09, z);
box(width * 0.92, 0.15, 1.88, MAT.cloth, x, y + 0.25, z);
box(width * 0.78, 0.18, 0.44, MAT.linen || material(0xd8c9a6), x, y + 0.38, z + 0.62);
}
// Upper left room.
bed(-0.55, 4.0, -4.30, 1.45);
box(0.75, 0.55, 0.55, MAT.wood, -0.75, 4.27, -3.98);
// Upper storeroom.
for (let i = 0; i < 3; i++) {
box(0.68, 0.52, 0.65, MAT.woodLight, 4.55, 4.26 + i * 0.52, -4.35);
box(0.72, 0.08, 0.68, MAT.iron, 4.55, 4.47 + i * 0.52, -4.35);
}
// Lower room storage.
box(0.75, 0.65, 0.75, MAT.wood, 2.22, 0.325, -1.65);
box(0.78, 0.08, 0.78, MAT.iron, 2.22, 0.60, -1.65);
function amphora(x, y, z, scale = 1, mat = MAT.trim) {
const points = [
new THREE.Vector2(0.14, 0.00),
new THREE.Vector2(0.27, 0.06),
new THREE.Vector2(0.39, 0.42),
new THREE.Vector2(0.34, 0.82),
new THREE.Vector2(0.18, 1.08),
new THREE.Vector2(0.14, 1.31),
new THREE.Vector2(0.21, 1.39),
new THREE.Vector2(0.11, 1.48)
];
const mesh = new THREE.Mesh(new THREE.LatheGeometry(points, 10), mat);
mesh.position.set(x, y, z);
mesh.scale.setScalar(scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Explicit water vessels at the street entrance.
amphora(3.55, 0.0, 3.55, 1.08);
amphora(4.15, 0.0, 3.42, 0.78, MAT.plasterPink);
cylinder(0.42, 0.34, 0.65, MAT.blue, 4.65, 0.325, 3.65, 12);
cylinder(0.35, 0.35, 0.035, MAT.water, 4.65, 0.67, 3.65, 12);
// Bundled goods beside the vessels.
function bundle(x, y, z, w = 0.9, h = 0.58, d = 0.7) {
box(w, h, d, MAT.sack, x, y + h / 2, z);
box(w + 0.04, 0.055, d + 0.04, MAT.rope, x, y + h * 0.52, z);
box(0.055, h + 0.03, d + 0.04, MAT.rope, x, y + h / 2, z);
}
bundle(1.00, 0.0, 3.70);
bundle(1.15, 0.0, 4.35, 0.75, 0.45, 0.65);
bundle(5.15, 0.0, 3.55, 0.8, 0.55, 0.65);
// A few pots in the visible rooms.
amphora(-3.0, 4.0, -4.25, 0.72, MAT.trim);
amphora(-2.35, 4.0, -4.35, 0.62, MAT.plasterPink);
amphora(4.9, 8.0, -4.15, 0.74, MAT.blue);
amphora(-4.9, 8.0, -4.3, 0.62, MAT.trim);
// -------------------------------------------------------------------------
// Carrier
// -------------------------------------------------------------------------
const carrier = new THREE.Group();
scene.add(carrier);
const body = new THREE.Group();
carrier.add(body);
box(0.52, 0.66, 0.34, MAT.carrier, 0, 1.02, 0, body);
box(0.55, 0.10, 0.37, MAT.carrierDark, 0, 0.76, 0, body);
const head = new THREE.Mesh(new THREE.DodecahedronGeometry(0.23, 0), MAT.skin);
head.position.set(0, 1.58, 0);
head.castShadow = true;
body.add(head);
box(0.35, 0.11, 0.32, MAT.hair, 0, 1.72, -0.015, body);
box(0.10, 0.10, 0.10, MAT.skin, 0, 1.56, 0.21, body);
function limb(x, y, length, mat, isLeg) {
const pivot = new THREE.Group();
pivot.position.set(x, y, 0);
body.add(pivot);
box(
isLeg ? 0.17 : 0.14,
length,
isLeg ? 0.19 : 0.15,
mat,
0,
-length / 2,
0,
pivot
);
if (isLeg) {
box(0.20, 0.12, 0.31, MAT.wood, 0, -length - 0.01, 0.07, pivot);
}
return pivot;
}
const leftLeg = limb(-0.14, 0.73, 0.56, MAT.carrierDark, true);
const rightLeg = limb(0.14, 0.73, 0.56, MAT.carrierDark, true);
const leftArm = limb(-0.35, 1.27, 0.47, MAT.skin, false);
const rightArm = limb(0.35, 1.27, 0.47, MAT.skin, false);
const sack = new THREE.Mesh(new THREE.DodecahedronGeometry(0.31, 0), MAT.sack);
sack.position.set(0, 1.00, -0.29);
sack.scale.set(0.9, 1.1, 0.65);
sack.castShadow = true;
body.add(sack);
// -------------------------------------------------------------------------
// Route construction and true 3-D distance counting
// -------------------------------------------------------------------------
const destinations = {
"upper-weaver": {
label: "Upper — Weaver’s Cubiculum",
shortLabel: "Upper: Weaver",
floor: "upper",
doorX: 0.40,
doorZ: -3.70,
targetZ: -4.35,
targetY: 4.06,
color: 0x65d9e7
},
"upper-store": {
label: "Upper — Blue Storeroom",
shortLabel: "Upper: Storeroom",
floor: "upper",
doorX: 3.60,
doorZ: -3.70,
targetZ: -4.35,
targetY: 4.06,
color: 0x65d9e7
},
"lower-cellar": {
label: "Lower — Cool Cellar",
shortLabel: "Lower: Cellar",
floor: "lower",
doorX: 1.40,
doorZ: -0.80,
targetZ: -1.65,
targetY: 0.06,
color: 0xf0a44b
}
};
const V = (x, y, z) => new THREE.Vector3(x, y, z);
function buildRoute(destination) {
const points = [];
// Shared street entrance, doorway, foyer, and common narrow landing.
points.push(V(2.40, 0.06, 4.15));
points.push(V(2.40, 0.06, 2.85));
points.push(V(2.40, 0.06, 1.80));
points.push(V(1.40, 0.06, 1.30));
let stairDistance = 0;
if (destination.floor === "upper") {
// Continue past the common landing to the foot of the shared stairs.
points.push(V(0.0, 0.06, STAIR_Z));
// Each point lies on the top nose of an actual stair.
// Summing full 3-D segment lengths counts the sloped stair run.
for (let i = 1; i <= STEPS; i++) {
const x = -STAIR_RUN * i / STEPS;
const y = 0.06 + STAIR_RISE * i / STEPS;
points.push(V(x, y, STAIR_Z));
}
// Measure the stairs independently for the HUD.
for (let i = 1; i < points.length; i++) {
stairDistance += points[i].distanceTo(points[i - 1]);
}
// Narrow upper landing: turn north, then east into the common corridor.
points.push(V(-5.0, 4.06, -2.85));
points.push(V(destination.doorX, 4.06, -2.85));
// Pass through the fixed doorway into the selected room.
points.push(V(destination.doorX, 4.06, destination.doorZ));
points.push(V(destination.doorX, destination.targetY, destination.targetZ));
} else {
// At the same common landing, turn north through the lower doorway.
points.push(V(destination.doorX, 0.06, destination.doorZ));
points.push(V(destination.doorX, destination.targetY, destination.targetZ));
}
let distance = 0;
let horizontalDistance = 0;
for (let i = 1; i < points.length; i++) {
distance += points[i].distanceTo(points[i - 1]);
horizontalDistance += Math.hypot(
points[i].x - points[i - 1].x,
points[i].z - points[i - 1].z
);
}
const ys = points.map((point) => point.y);
const verticalRise = Math.max(...ys) - Math.min(...ys);
return {
points,
distance,
stairDistance,
horizontalDistance,
verticalRise
};
}
let routeLine = null;
let routeDots = new THREE.Group();
scene.add(routeDots);
const destinationMarker = new THREE.Mesh(
new THREE.TorusGeometry(0.31, 0.045, 6, 28),
new THREE.MeshBasicMaterial({ color: 0xffc05f })
);
destinationMarker.rotation.x = Math.PI / 2;
destinationMarker.visible = false;
scene.add(destinationMarker);
function clearRouteVisuals() {
if (routeLine) {
scene.remove(routeLine);
routeLine.geometry.dispose();
routeLine.material.dispose();
routeLine = null;
}
while (routeDots.children.length) {
const dot = routeDots.children[0];
routeDots.remove(dot);
dot.geometry.dispose();
dot.material.dispose();
}
}
function showRoute(route, destination) {
clearRouteVisuals();
routeLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(route.points),
new THREE.LineBasicMaterial({
color: destination.color,
transparent: true,
opacity: 0.95
})
);
scene.add(routeLine);
// Mark important turns, not every stair nose.
const importantIndices = new Set([
0, 1, 2, 3,
route.points.length - 4,
route.points.length - 3,
route.points.length - 2,
route.points.length - 1
]);
if (destination.floor === "upper") {
importantIndices.add(4);
importantIndices.add(4 + STEPS);
importantIndices.add(5 + STEPS);
} else {
importantIndices.add(4);
}
for (const index of importantIndices) {
if (index < 0 || index >= route.points.length) continue;
const point = route.points[index];
const dot = new THREE.Mesh(
new THREE.SphereGeometry(0.085, 8, 6),
new THREE.MeshBasicMaterial({ color: destination.color })
);
dot.position.copy(point);
routeDots.add(dot);
}
destinationMarker.visible = true;
destinationMarker.position.set(
destination.doorX,
destination.targetY + 0.025,
destination.targetZ
);
}
// -------------------------------------------------------------------------
// Delivery animation and comparison bookkeeping
// -------------------------------------------------------------------------
const records = [];
let currentRun = null;
let comparisonQueue = [];
let comparisonTimer = null;
const distanceElement = document.getElementById("distance");
const routeDetailElement = document.getElementById("routeDetail");
const comparisonElement = document.getElementById("comparison");
const progressFill = document.getElementById("progressFill");
const recordsBody = document.querySelector("#records tbody");
function formatDistance(value) {
return `${value.toFixed(2)} m`;
}
function updateRecords() {
recordsBody.replaceChildren();
for (const record of [...records].reverse()) {
const row = document.createElement("tr");
const name = document.createElement("td");
const distance = document.createElement("td");
name.textContent = record.shortLabel;
distance.textContent = formatDistance(record.distance);
row.append(name, distance);
recordsBody.appendChild(row);
}
const upper = records.find((record) => record.id === "upper-weaver");
const lower = records.find((record) => record.id === "lower-cellar");
if (upper && lower) {
const difference = upper.distance - lower.distance;
comparisonElement.innerHTML =
`<strong>${difference.toFixed(2)} m shorter downstairs.</strong><br>` +
`The upper route is ${formatDistance(upper.distance)}; the lower route is ` +
`${formatDistance(lower.distance)}. Distances are full 3-D carrying paths, ` +
`including the ${formatDistance(upper.stairDistance)} stair run—not simply floor height.`;
} else if (upper) {
comparisonElement.innerHTML =
"Upper delivery recorded. Now choose the lower room to reveal the route difference.";
} else if (lower) {
comparisonElement.innerHTML =
"Lower delivery recorded. Choose an upper room to compare the longer shared-stair route.";
} else {
comparisonElement.innerHTML =
"Run the upper room first and the lower room second to compare their actual routes.";
}
}
function startDelivery(id, partOfComparison = false) {
if (!partOfComparison) {
comparisonQueue = [];
clearTimeout(comparisonTimer);
}
const destination = destinations[id];
const route = buildRoute(destination);
showRoute(route, destination);
currentRun = {
id,
destination,
route,
elapsed: 0,
speed: 2.05,
completed: false
};
carrier.position.copy(route.points[0]);
carrier.rotation.y = 0;
distanceElement.innerHTML = `${route.distance.toFixed(2)} <small>m</small>`;
routeDetailElement.textContent =
`Route ready: ${formatDistance(route.stairDistance)} on stairs · ` +
`${route.verticalRise.toFixed(2)} m vertical rise`;
progressFill.style.width = "0%";
}
function finishDelivery(run) {
records.push({
id: run.id,
shortLabel: run.destination.shortLabel,
distance: run.route.distance,
stairDistance: run.route.stairDistance,
verticalRise: run.route.verticalRise
});
routeDetailElement.textContent =
`Delivered to ${run.destination.label}. ` +
`${formatDistance(run.route.distance)} total.`;
progressFill.style.width = "100%";
updateRecords();
currentRun = null;
if (comparisonQueue.length) {
const nextId = comparisonQueue.shift();
comparisonTimer = setTimeout(() => {
startDelivery(nextId, true);
}, 1050);
}
}
function advanceCarrier(dt) {
const run = currentRun;
if (!run || run.completed) return;
run.elapsed += dt;
const traveled = Math.min(
run.elapsed * run.speed,
run.route.distance
);
const points = run.route.points;
let segmentIndex = 0;
let accumulated = 0;
for (let i = 1; i < points.length; i++) {
const segmentLength = points[i].distanceTo(points[i - 1]);
if (traveled <= accumulated + segmentLength || i === points.length - 1) {
segmentIndex = i - 1;
break;
}
accumulated += segmentLength;
}
const a = points[segmentIndex];
const b = points[segmentIndex + 1];
const segmentLength = a.distanceTo(b);
const localT = segmentLength > 0
? THREE.MathUtils.clamp((traveled - accumulated) / segmentLength, 0, 1)
: 0;
carrier.position.lerpVectors(a, b, localT);
const dx = b.x - a.x;
const dz = b.z - a.z;
if (Math.abs(dx) + Math.abs(dz) > 0.0001) {
const desiredYaw = Math.atan2(dx, dz);
carrier.rotation.y = desiredYaw;
}
const walkPhase = traveled * 5.2;
const swing = Math.sin(walkPhase) * 0.58;
leftLeg.rotation.x = swing;
rightLeg.rotation.x = -swing;
leftArm.rotation.x = -swing * 0.72;
rightArm.rotation.x = swing * 0.72;
body.position.y = Math.abs(Math.sin(walkPhase)) * 0.035;
const progress = run.route.distance > 0
? traveled / run.route.distance
: 1;
progressFill.style.width = `${(progress * 100).toFixed(1)}%`;
routeDetailElement.textContent =
`Carrying to ${run.destination.label} · ` +
`${(traveled).toFixed(1)} / ${run.route.distance.toFixed(1)} m`;
if (traveled >= run.route.distance - 0.0001) {
run.completed = true;
finishDelivery(run);
}
}
document.getElementById("deliver").addEventListener("click", () => {
const id = document.getElementById("destination").value;
startDelivery(id, false);
});
document.getElementById("compare").addEventListener("click", () => {
clearTimeout(comparisonTimer);
comparisonQueue = ["upper-weaver", "lower-cellar"];
startDelivery(comparisonQueue.shift(), true);
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
advanceCarrier(dt);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateRecords();
animate();
</script>
</body>
</html>
```