Prompt specification
Build or customize the Three.js 3D scene "Train ticket and packed household suitcase" 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: Train ticket and packed household suitcase
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/train-ticket-and-packed-household-suitcase-x2585
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Model a period suitcase and fictional train ticket beside a schematic southern-to-northern route. Label the Great Migration context without inventing a real traveler's identity.
Working Three.js Starter (train-ticket-and-packed-household-suitcase-x2585):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#0b1116">
<title>Northbound — The Great Migration</title>
<style>
:root {
color-scheme: dark;
--ink: #edf2ef;
--muted: #aebbb8;
--panel: rgba(10, 17, 22, 0.88);
--line: rgba(225, 238, 233, 0.16);
--south: #ff8064;
--route: #efc064;
--north: #63d7d2;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0b1116;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
top: 24px;
left: 24px;
z-index: 5;
width: min(390px, calc(100vw - 48px));
padding: 21px 22px 20px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(14px);
pointer-events: none;
}
.kicker {
margin-bottom: 9px;
color: var(--route);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 46px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: 8px;
margin: 13px 0 10px;
}
.subtitle strong {
font-size: 15px;
}
.subtitle span {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
}
.panel p {
margin: 0;
color: #c5d0cd;
font-size: 13px;
line-height: 1.55;
}
.note {
margin-top: 13px !important;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #93a3a0 !important;
font-size: 11px !important;
}
.legend {
position: fixed;
top: 24px;
right: 24px;
z-index: 5;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
width: min(350px, calc(100vw - 48px));
pointer-events: none;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(10, 17, 22, 0.8);
color: #cbd5d2;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.02em;
backdrop-filter: blur(10px);
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: 0 0 12px currentColor;
}
.swatch.south {
color: var(--south);
background: var(--south);
}
.swatch.route {
color: var(--route);
background: var(--route);
}
.swatch.north {
color: var(--north);
background: var(--north);
}
.controls {
position: fixed;
right: 24px;
bottom: 22px;
z-index: 6;
display: flex;
align-items: center;
gap: 12px;
color: #aab7b4;
font-size: 11px;
pointer-events: none;
}
.controls kbd {
display: inline-block;
min-width: 20px;
padding: 3px 5px;
border: 1px solid rgba(255, 255, 255, 0.22);
border-bottom-width: 2px;
border-radius: 4px;
background: rgba(255, 255, 255, 0.06);
color: #e7eeeb;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
button {
pointer-events: auto;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(15, 25, 31, 0.92);
color: #e9efed;
font: 700 11px ui-sans-serif, system-ui, sans-serif;
cursor: pointer;
}
button:hover {
border-color: rgba(239, 192, 100, 0.65);
color: var(--route);
}
button:focus-visible,
canvas:focus-visible {
outline: 2px solid var(--route);
outline-offset: 3px;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
#fallback {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
padding: 30px;
background: #0b1116;
color: #e6eeeb;
text-align: center;
}
#fallback[hidden] {
display: none;
}
@media (max-width: 760px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px;
}
.panel p {
font-size: 12px;
}
.note {
font-size: 10px !important;
}
.legend {
top: auto;
right: 12px;
bottom: 66px;
left: 12px;
width: auto;
justify-content: center;
}
.legend-item {
padding: 7px 8px;
font-size: 9px;
}
.controls {
right: 12px;
bottom: 16px;
}
.controls .hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<aside class="panel" aria-label="Great Migration context">
<div class="kicker">Voxel history · composite view</div>
<h1>Northbound</h1>
<div class="subtitle">
<strong>The Great Migration</strong>
<span>c. 1916–1970</span>
</div>
<p>
Millions of Black Southerners moved northward and westward, seeking
work, housing, and greater freedom from Jim Crow. Rail travel was
one part of a much broader movement.
</p>
<p class="note">
Interpretive display: no real traveler is named or depicted. The
period suitcase is generic, the train ticket is fictional, and the
route combines several origin–destination patterns rather than
representing one documented journey.
</p>
</aside>
<div class="legend" aria-label="Route legend">
<div class="legend-item">
<span class="swatch south"></span>
Southern origins
</div>
<div class="legend-item">
<span class="swatch route"></span>
Composite route
</div>
<div class="legend-item">
<span class="swatch north"></span>
Northern cities
</div>
</div>
<div class="controls">
<span class="hint"><kbd>drag</kbd> orbit · <kbd>scroll</kbd> zoom</span>
<button id="reset" type="button">Reset view</button>
</div>
<p id="scene-description" class="sr-only">
A voxel-style museum display showing a generic mid-century suitcase,
an explicitly fictional train ticket, and a schematic route from
southern communities to northern and Midwestern cities. The display
provides context for the Great Migration without representing or
identifying a particular historical traveler.
</p>
<div id="fallback" hidden>
This scene requires WebGL. Please try a browser with hardware
acceleration enabled.
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.querySelector("#scene");
const fallback = document.querySelector("#fallback");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
fallback.hidden = false;
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute("role", "img");
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel exhibit about the Great Migration"
);
renderer.domElement.setAttribute("aria-describedby", "scene-description");
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1116);
scene.fog = new THREE.Fog(0x0b1116, 20, 38);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
70
);
// Custom camera controls — no Three.js examples/addons are imported.
const target = new THREE.Vector3(0.45, 0.72, 0.05);
let theta = 0.69;
let phi = 0.92;
let radius = window.innerWidth < 760 ? 26 : 19;
function updateCamera() {
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);
}
updateCamera();
function resetCamera() {
theta = 0.69;
phi = 0.92;
radius = window.innerWidth < 760 ? 26 : 19;
target.set(0.45, 0.72, 0.05);
updateCamera();
}
document.querySelector("#reset").addEventListener("click", resetCamera);
const pointers = new Map();
let gesture = null;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function beginGesture() {
if (pointers.size === 1) {
const point = [...pointers.values()][0];
gesture = {
type: "rotate",
x: point.x,
y: point.y
};
} else if (pointers.size === 2) {
gesture = {
type: "pinch",
distance: pointerDistance(),
radius
};
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.focus();
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
beginGesture();
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId) || !gesture) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (gesture.type === "rotate" && pointers.size === 1) {
const dx = event.clientX - gesture.x;
const dy = event.clientY - gesture.y;
theta -= dx * 0.006;
phi = THREE.MathUtils.clamp(phi + dy * 0.005, 0.35, 1.28);
gesture.x = event.clientX;
gesture.y = event.clientY;
} else if (gesture.type === "pinch" && pointers.size === 2) {
const distance = pointerDistance();
if (distance > 0) {
radius = THREE.MathUtils.clamp(
gesture.radius * gesture.distance / distance,
10,
34
);
}
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
beginGesture();
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
10,
34
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
resetCamera();
return;
}
if (key === "arrowleft") theta -= 0.08;
if (key === "arrowright") theta += 0.08;
if (key === "arrowup") phi -= 0.06;
if (key === "arrowdown") phi += 0.06;
if (key === "+" || key === "=") radius -= 0.8;
if (key === "-") radius += 0.8;
phi = THREE.MathUtils.clamp(phi, 0.35, 1.28);
radius = THREE.MathUtils.clamp(radius, 10, 34);
updateCamera();
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
// Lighting
scene.add(new THREE.HemisphereLight(0xb9d8ef, 0x4a3424, 1.8));
const keyLight = new THREE.DirectionalLight(0xffe1b5, 3.2);
keyLight.position.set(-5, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 32;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const warmFill = new THREE.PointLight(0xff9a63, 42, 18, 2);
warmFill.position.set(-6, 5, 5);
scene.add(warmFill);
const coolFill = new THREE.PointLight(0x5fd8d1, 50, 20, 2);
coolFill.position.set(8, 5, -5);
scene.add(coolFill);
function standardMaterial(color, roughness = 0.8, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
function addBox(parent, size, position, material, shadows = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = shadows;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Floor and exhibition plinths
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 24),
standardMaterial(0x11191e, 0.98)
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.055;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(
28,
28,
0x3a4b53,
0x243139
);
grid.position.y = -0.035;
grid.material.transparent = true;
grid.material.opacity = 0.27;
scene.add(grid);
addBox(
scene,
[8.6, 0.14, 9.6],
[3.45, 0.02, -0.05],
standardMaterial(0x182329, 0.94)
);
addBox(
scene,
[4.7, 0.08, 2.55],
[-4.55, 0.0, 1.0],
standardMaterial(0x202b30, 0.94)
);
// Raised border around the schematic
const borderMaterial = standardMaterial(0x3a4a51, 0.82);
addBox(scene, [8.45, 0.08, 0.08], [3.45, 0.14, 4.70], borderMaterial);
addBox(scene, [8.45, 0.08, 0.08], [3.45, 0.14, -4.80], borderMaterial);
addBox(scene, [0.08, 0.08, 9.42], [-0.73, 0.14, -0.05], borderMaterial);
addBox(scene, [0.08, 0.08, 9.42], [7.63, 0.14, -0.05], borderMaterial);
// Generic period suitcase, built as individual voxel-like blocks.
const suitcase = new THREE.Group();
suitcase.position.set(-4.55, 0, 1.0);
suitcase.rotation.y = -0.12;
scene.add(suitcase);
const leatherMaterial = standardMaterial(0xffffff, 0.88);
const strapMaterial = standardMaterial(0x4a291f, 0.82);
const stitchMaterial = standardMaterial(0x3a211b, 0.92);
const brassMaterial = standardMaterial(0xc99a49, 0.36, 0.58);
const darkMetalMaterial = standardMaterial(0x302820, 0.58, 0.38);
const bodyGeometry = new THREE.BoxGeometry(0.442, 0.442, 0.442);
const body = new THREE.InstancedMesh(
bodyGeometry,
leatherMaterial,
8 * 6 * 3
);
const dummy = new THREE.Object3D();
const leatherColor = new THREE.Color(0x8b4b2f);
let instance = 0;
for (let z = 0; z < 3; z++) {
for (let y = 0; y < 6; y++) {
for (let x = 0; x < 8; x++) {
dummy.position.set(
(x - (8 - 1) / 2) * 0.45,
0.12 + (y + 0.5) * 0.45,
(z - (3 - 1) / 2) * 0.45
);
dummy.updateMatrix();
body.setMatrixAt(instance, dummy.matrix);
const color = leatherColor.clone();
color.offsetHSL(
0,
((x + y + z) % 2) * 0.015,
(((x + y * 2 + z) % 3) - 1) * 0.025
);
body.setColorAt(instance, color);
instance++;
}
}
}
body.instanceMatrix.needsUpdate = true;
body.instanceColor.needsUpdate = true;
body.castShadow = true;
body.receiveShadow = true;
suitcase.add(body);
// Two leather straps wrapping over the body.
for (const x of [-1.08, 1.08]) {
addBox(
suitcase,
[0.17, 2.72, 0.09],
[x, 1.47, 0.72],
strapMaterial
);
addBox(
suitcase,
[0.17, 0.09, 1.40],
[x, 2.84, 0],
strapMaterial
);
}
// Decorative stitching.
for (const x of [-1.64, -0.54, 0.54, 1.64]) {
addBox(
suitcase,
[0.025, 2.30, 0.025],
[x, 1.46, 0.688],
stitchMaterial,
false
);
}
addBox(
suitcase,
[3.25, 0.025, 0.025],
[0, 0.54, 0.688],
stitchMaterial,
false
);
// Brass buckles and latches.
for (const x of [-1.08, 1.08]) {
addBox(
suitcase,
[0.34, 0.34, 0.12],
[x, 1.24, 0.80],
brassMaterial
);
addBox(
suitcase,
[0.18, 0.13, 0.14],
[x, 1.24, 0.88],
darkMetalMaterial,
false
);
addBox(
suitcase,
[0.28, 0.20, 0.10],
[x, 2.18, 0.80],
brassMaterial
);
}
// Block-built handle.
addBox(
suitcase,
[0.18, 0.43, 0.20],
[-0.55, 2.98, 0],
darkMetalMaterial
);
addBox(
suitcase,
[0.18, 0.43, 0.20],
[0.55, 2.98, 0],
darkMetalMaterial
);
addBox(
suitcase,
[1.30, 0.18, 0.22],
[0, 3.21, 0],
strapMaterial
);
// Corner protectors and feet.
for (const x of [-1.68, 1.68]) {
for (const y of [0.23, 2.69]) {
for (const z of [-0.57, 0.57]) {
addBox(
suitcase,
[0.28, 0.27, 0.28],
[x, y, z],
darkMetalMaterial
);
}
}
}
for (const x of [-1.30, 1.30]) {
for (const z of [-0.42, 0.42]) {
addBox(
suitcase,
[0.24, 0.14, 0.22],
[x, 0.07, z],
darkMetalMaterial
);
}
}
// Fictional ticket: each visible cell is rendered as a tiny 3D block.
function createTicketTexture() {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 320;
const context = canvas.getContext("2d", { willReadFrequently: true });
const cream = "#e8d5a8";
const red = "#9e3728";
const ink = "#23221f";
context.fillStyle = cream;
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = red;
context.fillRect(0, 0, 18, canvas.height);
context.fillRect(18, 0, 622, 5);
context.fillStyle = ink;
context.font = "bold 29px monospace";
context.fillText("FICTIONAL EXHIBIT TICKET", 29, 43);
context.fillStyle = red;
context.fillRect(29, 53, 580, 3);
context.fillStyle = ink;
context.font = "bold 43px monospace";
context.fillText("TRAIN 00", 29, 102);
context.font = "bold 31px monospace";
context.fillText("SOUTH > NORTH", 29, 145);
context.font = "bold 23px monospace";
context.fillText("COMPOSITE ROUTE", 29, 180);
context.font = "bold 20px monospace";
context.fillText("NO HISTORICAL TRAVELER", 29, 208);
context.fillStyle = red;
context.fillRect(29, 224, 580, 3);
context.fillStyle = ink;
context.font = "bold 27px monospace";
context.fillText("NOT VALID FOR TRAVEL", 29, 271);
context.fillStyle = red;
context.fillRect(29, 288, 580, 8);
return canvas;
}
function createVoxelTicket() {
const canvas = createTicketTexture();
const context = canvas.getContext("2d");
const image = context.getImageData(0, 0, canvas.width, canvas.height).data;
const columns = 64;
const rows = 32;
const cellPixels = 10;
const cellSize = 0.055;
const palette = [
[232, 213, 168],
[158, 55, 40],
[35, 34, 31],
[195, 145, 58],
[245, 231, 190],
[100, 36, 28]
];
function nearestPalette(r, g, b) {
let best = palette[0];
let bestDistance = Infinity;
for (const color of palette) {
const distance =
(r - color[0]) ** 2 +
(g - color[1]) ** 2 +
(b - color[2]) ** 2;
if (distance < bestDistance) {
bestDistance = distance;
best = color;
}
}
return best;
}
const pixels = [];
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
let r = 0;
let g = 0;
let b = 0;
let a = 0;
for (let y = 0; y < cellPixels; y++) {
for (let x = 0; x < cellPixels; x++) {
const px = column * cellPixels + x;
const py = row * cellPixels + y;
const index = (py * canvas.width + px) * 4;
r += image[index];
g += image[index + 1];
b += image[index + 2];
a += image[index + 3];
}
}
const samples = cellPixels * cellPixels;
r /= samples;
g /= samples;
b /= samples;
a /= samples;
if (a < 90) continue;
pixels.push({
column,
row,
color: nearestPalette(r, g, b)
});
}
}
const geometry = new THREE.BoxGeometry(0.052, 0.05, 0.052);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.77,
metalness: 0
});
const ticketMesh = new THREE.InstancedMesh(
geometry,
material,
pixels.length
);
const transform = new THREE.Object3D();
const color = new THREE.Color();
pixels.forEach((pixel, index) => {
transform.position.set(
(pixel.column - (columns - 1) / 2) * cellSize,
0.025,
(pixel.row - (rows - 1) / 2) * cellSize
);
transform.updateMatrix();
ticketMesh.setMatrixAt(index, transform.matrix);
color.setRGB(
pixel.color[0] / 255,
pixel.color[1] / 255,
pixel.color[2] / 255
);
ticketMesh.setColorAt(index, color);
});
ticketMesh.instanceMatrix.needsUpdate = true;
ticketMesh.instanceColor.needsUpdate = true;
ticketMesh.castShadow = true;
ticketMesh.receiveShadow = true;
return ticketMesh;
}
const ticketGroup = new THREE.Group();
ticketGroup.position.set(-2.35, 0.10, 3.58);
ticketGroup.rotation.y = -0.16;
scene.add(ticketGroup);
addBox(
ticketGroup,
[3.58, 0.05, 1.82],
[0, -0.035, 0],
standardMaterial(0x6b563e, 0.9)
);
ticketGroup.add(createVoxelTicket());
// Schematic route made from raised square blocks.
const routeMaterial = standardMaterial(0xefc064, 0.7);
const southMaterial = standardMaterial(0xff8064, 0.65);
const northMaterial = standardMaterial(0x63d7d2, 0.6);
const stopMaterial = standardMaterial(0xf4d998, 0.48, 0.16);
const routeGeometry = new THREE.BoxGeometry(0.16, 0.14, 0.16);
function addRouteSegment(start, end) {
const length = Math.hypot(end[0] - start[0], end[1] - start[1]);
const steps = Math.max(1, Math.ceil(length / 0.18));
for (let i = 0; i <= steps; i++) {
const t = i / steps;
const x = THREE.MathUtils.lerp(start[0], end[0], t);
const z = THREE.MathUtils.lerp(start[1], end[1], t);
const block = new THREE.Mesh(routeGeometry, routeMaterial);
block.position.set(x, 0.19, z);
block.castShadow = true;
block.receiveShadow = true;
scene.add(block);
}
}
function addRoutePath(points) {
for (let i = 0; i < points.length - 1; i++) {
addRouteSegment(points[i], points[i + 1]);
}
}
// Several southern origins merge into one schematic route.
addRoutePath([
[0.60, 3.15],
[0.60, 2.45],
[2.00, 2.45]
]);
addRoutePath([
[2.00, 3.15],
[2.00, 2.45]
]);
addRoutePath([
[3.35, 3.15],
[3.35, 2.75],
[2.00, 2.75],
[2.00, 2.45]
]);
addRoutePath([
[2.00, 2.45],
[2.80, 2.45],
[2.80, 1.45],
[3.60, 1.45],
[3.60, 0.35],
[4.45, 0.35],
[4.45, -0.80],
[5.35, -0.80],
[5.35, -2.00],
[4.80, -2.00],
[4.80, -3.65]
]);
// Representative destination branches.
addRoutePath([
[5.35, -2.00],
[5.35, -3.65]
]);
addRoutePath([
[4.80, -3.65],
[3.45, -3.65]
]);
addRoutePath([
[4.80, -3.65],
[6.25, -3.65]
]);
for (const [x, z] of [
[0.60, 3.15],
[2.00, 3.15],
[3.35, 3.15]
]) {
addBox(
scene,
[0.48, 0.16, 0.48],
[x, 0.20, z],
southMaterial
);
}
for (const [x, z] of [
[3.45, -3.65],
[4.80, -3.65],
[6.25, -3.65]
]) {
addBox(
scene,
[0.48, 0.16, 0.48],
[x, 0.20, z],
northMaterial
);
}
for (const [x, z] of [
[2.00, 2.45],
[3.60, 1.45],
[4.45, -0.80],
[4.80, -2.00]
]) {
addBox(
scene,
[0.24, 0.18, 0.24],
[x, 0.23, z],
stopMaterial
);
}
// Direction arrow pointing north.
addBox(scene, [0.17, 0.15, 0.17], [5.35, 0.22, -1.18], northMaterial);
addBox(scene, [0.17, 0.15, 0.17], [5.20, 0.22, -1.02], northMaterial);
addBox(scene, [0.17, 0.15, 0.17], [5.50, 0.22, -1.02], northMaterial);
// Text labels placed directly on the schematic board.
function roundedRectPath(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
}
function addFloorLabel(lines, width, height, position, accent) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRectPath(context, 8, 8, 1008, 240, 24);
context.fillStyle = "rgba(8, 15, 19, 0.90)";
context.fill();
context.lineWidth = 5;
context.strokeStyle = accent;
context.stroke();
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = accent;
const lineHeight = lines.length > 1 ? 72 : 92;
const firstY = 128 - ((lines.length - 1) * lineHeight) / 2;
lines.forEach((line, index) => {
context.font =
index === 0
? "bold 55px ui-sans-serif, system-ui, sans-serif"
: "bold 36px ui-monospace, monospace";
context.fillText(line, 512, firstY + index * lineHeight);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const label = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
label.rotation.x = -Math.PI / 2;
label.position.set(position[0], position[1], position[2]);
scene.add(label);
}
addFloorLabel(
["SCHEMATIC NORTHWARD ROUTES"],
5.6,
0.68,
[4.35, 0.25, 4.28],
"#efc064"
);
addFloorLabel(
["SOUTH", "SOUTHERN COMMUNITIES"],
3.85,
0.82,
[1.85, 0.25, 3.72],
"#ff8064"
);
addFloorLabel(
["NORTH", "MIDWESTERN & NORTHEASTERN CITIES"],
4.7,
0.86,
[4.95, 0.25, -4.22],
"#63d7d2"
);
addFloorLabel(
["PULLS OF MOVEMENT", "WORK / HOUSING", "FREEDOM FROM JIM CROW"],
2.75,
1.22,
[6.38, 0.25, 0.85],
"#c7d3d0"
);
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```