Prompt specification
Build or customize the Three.js 3D scene "Offset street rail and pavement segment" 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: Offset street rail and pavement segment
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/offset-street-rail-and-pavement-segment-x2465
Scene Description Prompt:
Model a small 1906 San Francisco street fragment with displaced pavement and streetcar rail. Keep damage non-graphic and source the type of deformation shown. Build this with Three.js from cdnjs as a stylized scene in one self-contained HTML file.
Working Three.js Starter (offset-street-rail-and-pavement-segment-x2465):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Faulted Street — 1906 San Francisco</title>
<style>
:root {
color-scheme: light;
--ink: #27231f;
--muted: #6d6459;
--paper: rgba(246, 240, 226, 0.91);
--paper-strong: #f4eddd;
--line: rgba(65, 55, 43, 0.2);
--accent: #8c3d32;
--teal: #246f73;
--shadow: 0 14px 42px rgba(54, 42, 28, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cec6b8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
touch-action: none;
cursor: grab;
}
#app canvas.dragging {
cursor: grabbing;
}
#interface {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.58);
box-shadow: var(--shadow);
backdrop-filter: blur(15px) saturate(0.82);
-webkit-backdrop-filter: blur(15px) saturate(0.82);
}
#title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px 18px;
border-radius: 5px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin: 0 0 8px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 2px;
background: var(--accent);
content: "";
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 3.2vw, 44px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 330px;
margin: 12px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.source-chip {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
border: 1px solid rgba(140, 61, 50, 0.22);
border-radius: 3px;
background: rgba(140, 61, 50, 0.06);
color: #73352e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.source-chip::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
content: "";
}
#tools {
position: absolute;
right: 24px;
bottom: 24px;
left: 24px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
width: fit-content;
max-width: calc(100vw - 48px);
padding: 12px 14px;
border-radius: 5px;
}
.tool-group {
display: flex;
align-items: center;
gap: 7px;
}
.tool-label {
margin-right: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.tool-button,
.view-button {
min-height: 34px;
padding: 7px 11px;
border: 1px solid var(--line);
border-radius: 3px;
background: rgba(255, 255, 255, 0.4);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.tool-button:hover,
.view-button:hover {
border-color: rgba(91, 73, 54, 0.42);
background: rgba(255, 255, 255, 0.76);
transform: translateY(-1px);
}
.view-button.active,
.tool-button[aria-pressed="true"] {
border-color: rgba(140, 61, 50, 0.35);
background: rgba(140, 61, 50, 0.1);
color: #71342d;
}
#offset-control {
display: grid;
grid-template-columns: auto 125px 54px;
align-items: center;
gap: 9px;
min-width: 255px;
}
#offset-control output {
color: var(--accent);
font-variant-numeric: tabular-nums;
font-size: 11px;
font-weight: 800;
text-align: right;
}
input[type="range"] {
width: 125px;
height: 4px;
margin: 0;
appearance: none;
border-radius: 4px;
background:
linear-gradient(
90deg,
var(--accent) 0 var(--range-fill, 100%),
rgba(67, 59, 49, 0.2) var(--range-fill, 100%) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 2px solid var(--paper-strong);
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(91, 58, 47, 0.3);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 2px solid var(--paper-strong);
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(91, 58, 47, 0.3);
}
#hint {
position: absolute;
bottom: 25px;
left: 26px;
color: rgba(45, 39, 32, 0.72);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-shadow: 0 1px 2px rgba(255, 255, 255, 0.65);
}
#world-labels {
position: fixed;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 7px;
width: max-content;
max-width: 230px;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 3px;
background: rgba(245, 238, 222, 0.9);
box-shadow: 0 5px 18px rgba(47, 38, 28, 0.14);
color: #3d342c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.045em;
line-height: 1.25;
text-transform: uppercase;
transform: translate(-50%, -115%);
transition: opacity 100ms ease;
white-space: nowrap;
}
.world-label::before {
width: 7px;
height: 7px;
flex: 0 0 auto;
border: 2px solid #f4ecdc;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent);
content: "";
}
.world-label.teal::before {
background: var(--teal);
box-shadow: 0 0 0 1px var(--teal);
}
#source-drawer {
position: fixed;
top: 0;
right: 0;
bottom: 0;
z-index: 20;
width: min(430px, 100vw);
padding: 28px 28px 36px;
overflow-y: auto;
border-left: 1px solid rgba(255, 255, 255, 0.65);
background: rgba(246, 239, 224, 0.97);
box-shadow: -18px 0 50px rgba(45, 36, 26, 0.17);
transform: translateX(105%);
transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
}
#source-drawer.open {
transform: translateX(0);
}
#drawer-close {
position: absolute;
top: 18px;
right: 18px;
width: 34px;
height: 34px;
border: 1px solid var(--line);
border-radius: 50%;
background: transparent;
cursor: pointer;
font-size: 20px;
line-height: 1;
}
#source-drawer h2 {
max-width: 300px;
margin: 7px 42px 18px 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 33px;
font-weight: 500;
line-height: 1.05;
letter-spacing: -0.03em;
}
#source-drawer h3 {
margin: 25px 0 9px;
color: var(--accent);
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#source-drawer p,
#source-drawer li {
color: #5f554b;
font-size: 13px;
line-height: 1.65;
}
#source-drawer a {
color: #713a32;
text-decoration-color: rgba(113, 58, 50, 0.35);
text-underline-offset: 3px;
}
#source-drawer ul {
padding-left: 18px;
}
.model-note {
padding: 14px 15px;
border-left: 3px solid var(--teal);
background: rgba(36, 111, 115, 0.07);
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #d5cdbf;
color: #5d5146;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
#title-card {
top: 14px;
left: 14px;
width: min(355px, calc(100vw - 28px));
padding: 16px 18px;
}
.subtitle {
display: none;
}
#tools {
right: 14px;
bottom: 14px;
left: 14px;
flex-wrap: wrap;
justify-content: flex-start;
max-width: calc(100vw - 28px);
}
#offset-control {
order: -1;
width: 100%;
grid-template-columns: auto 1fr 58px;
}
#offset-control input {
width: 100%;
}
#hint {
display: none;
}
.tool-label {
display: none;
}
}
@media (max-width: 520px) {
#title-card {
width: calc(100vw - 28px);
}
h1 {
font-size: 29px;
}
#tools {
gap: 8px;
}
.tool-button,
.view-button {
padding: 7px 9px;
font-size: 10px;
}
.world-label {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="app" aria-label="Interactive stylized reconstruction of a fault-displaced 1906 San Francisco street"></div>
<div id="world-labels" aria-hidden="true">
<div class="world-label" id="label-rupture">Surface rupture</div>
<div class="world-label teal" id="label-offset">Modeled lateral offset</div>
</div>
<main id="interface">
<section id="title-card" class="panel">
<p class="eyebrow">San Francisco · 1906</p>
<h1>Faulted Street</h1>
<p class="subtitle">
A generalized interpretive fragment showing laterally displaced paving,
broken curbs, and an interrupted streetcar track.
</p>
<div class="source-chip">Right-lateral surface faulting</div>
</section>
<section id="tools" class="panel" aria-label="Scene controls">
<div class="tool-group">
<span class="tool-label">View</span>
<button class="view-button active" data-view="oblique" type="button">Oblique</button>
<button class="view-button" data-view="street" type="button">Street</button>
<button class="view-button" data-view="plan" type="button">Plan</button>
<button class="view-button" data-view="fault" type="button">Fault</button>
</div>
<div id="offset-control">
<span class="tool-label">Offset</span>
<input
id="offset"
type="range"
min="0"
max="100"
value="100"
aria-label="Modeled lateral displacement"
>
<output id="offset-value" for="offset">1.05 m</output>
</div>
<div class="tool-group">
<button
class="tool-button"
id="guide-toggle"
type="button"
aria-pressed="false"
>Reference</button>
<button
class="tool-button"
id="annotation-toggle"
type="button"
aria-pressed="true"
>Labels</button>
<button class="tool-button" id="sources-toggle" type="button">Sources</button>
</div>
</section>
<div id="hint">Drag to orbit · wheel/pinch to zoom · shift-drag to pan</div>
</main>
<aside id="source-drawer" aria-label="Historical sources and model notes">
<button id="drawer-close" type="button" aria-label="Close source panel">×</button>
<p class="eyebrow">Deformation source</p>
<h2>Surface faulting, not an impact crater.</h2>
<p>
The scene models the kind of permanent ground deformation documented during
the 1906 San Francisco earthquake: a lateral fault trace across the street,
with opposite ground blocks shifted horizontally and a small vertical step.
The principal San Andreas rupture in the region is described as
right-lateral.
</p>
<h3>Historical references</h3>
<ul>
<li>
<a
href="https://www.usgs.gov/programs/earthquake-hazards/science/1906-great-san-francisco-earthquake"
target="_blank"
rel="noopener noreferrer"
>U.S. Geological Survey — The Great 1906 San Francisco Earthquake</a>
</li>
<li>
<a
href="https://www.nps.gov/goga/learn/historyculture/1906-earthquake.htm"
target="_blank"
rel="noopener noreferrer"
>National Park Service — 1906 Earthquake and Fire</a>
</li>
</ul>
<h3>What the model represents</h3>
<p>
Paving stones and curbs terminate at a jagged surface trace. The two street
sections are translated along the rupture, so the rails kink and their
gauge is briefly interrupted. A generic period streetcar remains on the
displaced rail bed.
</p>
<div class="model-note">
<strong>Interpretive, not forensic.</strong>
<p style="margin: 6px 0 0">
This is a generalized educational reconstruction, not a reconstruction of
a surveyed parcel or a claim about a specific address. Building forms,
street width, streetcar hardware, the 1.05 m offset, and the minor
vertical step are diagrammatic. Actual displacement and urban damage
varied substantially by location.
</p>
</div>
</aside>
<div id="loading">Preparing the street fragment…</div>
<script type="module">
// Only the Three.js core ES module is used.
// Camera controls are implemented directly below; no addons are imported.
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.04;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional reconstruction of a displaced 1906 street"
);
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcfc7b9);
scene.fog = new THREE.Fog(0xcfc7b9, 28, 56);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemi = new THREE.HemisphereLight(0xf8ead1, 0x6a6258, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffdfb0, 3.5);
sun.position.set(-11, 18, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -19;
sun.shadow.camera.right = 19;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaec5d0, 0.75);
fill.position.set(12, 8, -14);
scene.add(fill);
const world = new THREE.Group();
scene.add(world);
const palette = {
ground: new THREE.MeshStandardMaterial({
color: 0x827665,
roughness: 1
}),
earth: new THREE.MeshStandardMaterial({
color: 0x665547,
roughness: 1
}),
road: new THREE.MeshStandardMaterial({
color: 0x514d47,
roughness: 0.95
}),
curb: new THREE.MeshStandardMaterial({
color: 0xb4aa96,
roughness: 0.9
}),
sidewalk: new THREE.MeshStandardMaterial({
color: 0xc0b39d,
roughness: 0.94
}),
rail: new THREE.MeshStandardMaterial({
color: 0x696c69,
metalness: 0.68,
roughness: 0.48
}),
cable: new THREE.MeshStandardMaterial({
color: 0x252a29,
roughness: 0.74,
metalness: 0.25
}),
tie: new THREE.MeshStandardMaterial({
color: 0x504238,
roughness: 1
}),
iron: new THREE.MeshStandardMaterial({
color: 0x343737,
metalness: 0.65,
roughness: 0.55
}),
glass: new THREE.MeshStandardMaterial({
color: 0x667b7b,
metalness: 0.18,
roughness: 0.3
}),
trolleyRed: new THREE.MeshStandardMaterial({
color: 0x843a31,
roughness: 0.64,
metalness: 0.06
}),
trolleyCream: new THREE.MeshStandardMaterial({
color: 0xd8c7a0,
roughness: 0.68
}),
wood: new THREE.MeshStandardMaterial({
color: 0x70513a,
roughness: 0.86
}),
rubble: new THREE.MeshStandardMaterial({
color: 0x898074,
roughness: 1
})
};
const buildingMaterials = [
new THREE.MeshStandardMaterial({ color: 0xa16c50, roughness: 0.92 }),
new THREE.MeshStandardMaterial({ color: 0x777e69, roughness: 0.93 }),
new THREE.MeshStandardMaterial({ color: 0x9a8568, roughness: 0.91 }),
new THREE.MeshStandardMaterial({ color: 0x806151, roughness: 0.94 })
];
const trimMaterials = [
new THREE.MeshStandardMaterial({ color: 0xd0bfa1, roughness: 0.88 }),
new THREE.MeshStandardMaterial({ color: 0xb8ad94, roughness: 0.9 })
];
function addBox(parent, size, position, material, options = {}) {
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 = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radius,
height,
position,
material,
radialSegments = 12
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, radialSegments),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBeam(parent, start, end, radius, material) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(b, a);
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const beam = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), 8),
material
);
beam.position.copy(midpoint);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
beam.castShadow = true;
beam.receiveShadow = true;
parent.add(beam);
return beam;
}
function addAnchor(parent, x, y, z) {
const anchor = new THREE.Object3D();
anchor.position.set(x, y, z);
parent.add(anchor);
return anchor;
}
// A broad ground and foundation mass remain in place while the two
// reconstructed street blocks move relative to one another.
addBox(
world,
[26, 1.25, 39],
[0, -0.82, 0],
palette.ground,
{ castShadow: false }
);
addBox(
world,
[18.5, 0.55, 31],
[0, -0.34, 0],
palette.earth,
{ castShadow: false }
);
const northBlock = new THREE.Group();
const southBlock = new THREE.Group();
world.add(northBlock, southBlock);
function addStreetSegment(parent, centerZ, side) {
const segmentLength = 11.75;
// Street bed.
addBox(
parent,
[11.45, 0.36, segmentLength],
[0, -0.18, centerZ],
palette.road,
{ castShadow: false }
);
// Raised sidewalks.
for (const x of [-5.75, 5.75]) {
addBox(
parent,
[1.45, 0.3, segmentLength],
[x, 0.15, centerZ],
palette.sidewalk
);
}
// Broken stone paving, built as instanced low blocks for performance.
const columns = 21;
const rows = 29;
const count = columns * rows;
const cobbleGeometry = new THREE.BoxGeometry(0.46, 0.09, 0.37);
const cobbleMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.98
});
const cobbles = new THREE.InstancedMesh(
cobbleGeometry,
cobbleMaterial,
count
);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
const paletteColors = [
new THREE.Color(0x625d56),
new THREE.Color(0x70695f),
new THREE.Color(0x777067),
new THREE.Color(0x57534d),
new THREE.Color(0x81786b)
];
let instance = 0;
for (let column = 0; column < columns; column++) {
for (let row = 0; row < rows; row++) {
const jitterX = (Math.random() - 0.5) * 0.075;
const jitterZ = (Math.random() - 0.5) * 0.065;
const x = -5 + column * 0.5 + jitterX;
const z =
side < 0
? -11.55 + row * 0.405 + jitterZ
: 0.08 + row * 0.405 + jitterZ;
dummy.position.set(x, 0.04 + Math.random() * 0.012, z);
dummy.rotation.set(
(Math.random() - 0.5) * 0.025,
(Math.random() - 0.5) * 0.16,
(Math.random() - 0.5) * 0.018
);
dummy.scale.set(
0.88 + Math.random() * 0.16,
0.8 + Math.random() * 0.22,
0.88 + Math.random() * 0.15
);
dummy.updateMatrix();
cobbles.setMatrixAt(instance, dummy.matrix);
color.copy(
paletteColors[
Math.floor(Math.random() * paletteColors.length)
]
);
color.offsetHSL(
(Math.random() - 0.5) * 0.018,
(Math.random() - 0.5) * 0.035,
(Math.random() - 0.5) * 0.055
);
cobbles.setColorAt(instance, color);
instance++;
}
}
cobbles.instanceMatrix.needsUpdate = true;
if (cobbles.instanceColor) {
cobbles.instanceColor.needsUpdate = true;
}
cobbles.castShadow = false;
cobbles.receiveShadow = true;
parent.add(cobbles);
// Segmented curbs preserve the broken masonry character.
const curbStart = side < 0 ? -11.72 : 0.18;
const curbEnd = side < 0 ? -0.08 : 11.78;
for (const x of [-5.08, 5.08]) {
for (let z = curbStart; z < curbEnd; z += 0.73) {
const length = Math.min(0.67, curbEnd - z);
const block = addBox(
parent,
[0.24, 0.28, length],
[x, 0.12, z + length * 0.5],
palette.curb
);
block.rotation.y = (Math.random() - 0.5) * 0.018;
}
}
// Two streetcar tracks, each with running rails and a central cable slot.
for (const trackCenter of [-1.68, 1.68]) {
for (const railOffset of [-0.72, 0.72]) {
addBox(
parent,
[0.09, 0.12, segmentLength - 0.12],
[trackCenter + railOffset, 0.135, centerZ],
palette.rail
);
}
addBox(
parent,
[0.038, 0.035, segmentLength - 0.08],
[trackCenter, 0.093, centerZ],
palette.cable,
{ castShadow: false }
);
for (let z = centerZ - 5.65; z < centerZ + 5.7; z += 0.62) {
addBox(
parent,
[1.76, 0.065, 0.13],
[trackCenter, 0.095, z],
palette.tie,
{ castShadow: false }
);
}
}
// Sparse, non-graphic rubble close to the rupture.
for (let i = 0; i < 14; i++) {
const rubble = addBox(
parent,
[
0.12 + Math.random() * 0.25,
0.07 + Math.random() * 0.13,
0.12 + Math.random() * 0.27
],
[
-4.7 + Math.random() * 9.4,
0.1 + Math.random() * 0.07,
side < 0
? -0.85 + Math.random() * 0.85
: 0.02 + Math.random() * 0.85
],
palette.rubble
);
rubble.rotation.set(
Math.random() * 0.4,
Math.random() * Math.PI,
Math.random() * 0.3
);
}
}
addStreetSegment(northBlock, -6, -1);
addStreetSegment(southBlock, 6, 1);
function addBuilding(parent, side, z, height, materialIndex) {
const bodyMaterial = buildingMaterials[materialIndex % buildingMaterials.length];
const trimMaterial = trimMaterials[materialIndex % trimMaterials.length];
const centerX = side * 7.35;
const baseY = 0.3;
const depth = 4.15;
const width = 3.0;
const innerFaceX = side * 5.82;
addBox(
parent,
[width, height, depth],
[centerX, baseY + height * 0.5, z],
bodyMaterial
);
addBox(
parent,
[3.22, 0.19, depth + 0.22],
[centerX, baseY + height + 0.06, z],
trimMaterial
);
addBox(
parent,
[3.05, 0.17, depth - 0.15],
[centerX, baseY + height + 0.2, z],
palette.wood
);
// Street-level storefront.
addBox(
parent,
[0.08, 1.2, 2.8],
[innerFaceX, baseY + 0.77, z],
palette.glass,
{ castShadow: false }
);
addBox(
parent,
[0.11, 0.13, 2.95],
[innerFaceX, baseY + 1.45, z],
trimMaterial
);
// Upper-floor windows.
const floors = Math.max(2, Math.floor(height / 1.35));
for (let floor = 0; floor < floors; floor++) {
const y = baseY + 2.05 + floor * 1.25;
for (const windowZ of [z - 1.02, z + 1.02]) {
addBox(
parent,
[0.065, 0.72, 0.63],
[innerFaceX, y, windowZ],
palette.glass,
{ castShadow: false }
);
addBox(
parent,
[0.085, 0.055, 0.72],
[innerFaceX, y - 0.39, windowZ],
trimMaterial,
{ castShadow: false }
);
}
}
// A simple facade sign band without modern lettering.
addBox(
parent,
[0.09, 0.22, 2.25],
[innerFaceX, baseY + 1.72, z],
trimMaterial,
{ castShadow: false }
);
}
// Eight stylized period facades, two on each side of each displaced block.
const buildingPlan = [
[-1, -9.1, 4.7, 0],
[-1, -2.9, 5.8, 1],
[1, -9.1, 5.4, 2],
[1, -2.9, 4.6, 3]
];
for (const [side, z, height, materialIndex] of buildingPlan) {
addBuilding(northBlock, side, z, height, materialIndex);
}
const southBuildingPlan = [
[-1, 2.9, 5.5, 1],
[-1, 9.1, 4.6, 2],
[1, 2.9, 4.9, 3],
[1, 9.1, 5.9, 0]
];
for (const [side, z, height, materialIndex] of southBuildingPlan) {
addBuilding(southBlock, side, z, height, materialIndex);
}
function addStreetLamp(parent, x, z) {
addCylinder(parent, 0.055, 3.2, [x, 1.85, z], palette.iron, 10);
addBox(parent, [0.48, 0.07, 0.07], [x, 3.43, z], palette.iron);
addBox(
parent,
[0.25, 0.34, 0.25],
[x + (x < 0 ? 0.2 : -0.2), 3.25, z],
new THREE.MeshStandardMaterial({
color: 0xe4d4ad,
emissive: 0x5a3a12,
emissiveIntensity: 0.14,
roughness: 0.45
})
);
}
addStreetLamp(northBlock, -5.72, -10.7);
addStreetLamp(northBlock, 5.72, -1.55);
addStreetLamp(southBlock, -5.72, 1.55);
addStreetLamp(southBlock, 5.72, 10.7);
function addStreetcar(parent) {
const car = new THREE.Group();
parent.add(car);
const x = 1.68;
const z = 6.0;
// Underframe and body.
addBox(car, [1.52, 0.22, 3.42], [x, 0.55, z], palette.iron);
addBox(car, [1.48, 1.26, 3.32], [x, 1.25, z], palette.trolleyRed);
addBox(car, [1.52, 0.22, 3.37], [x, 1.73, z], palette.trolleyCream);
addBox(car, [1.62, 0.18, 3.52], [x, 2.03, z], palette.iron);
addBox(car, [1.16, 0.2, 2.25], [x, 2.18, z], palette.trolleyCream);
// Side windows.
for (const side of [-1, 1]) {
for (const windowZ of [z - 0.94, z, z + 0.94]) {
addBox(
car,
[0.045, 0.62, 0.68],
[x + side * 0.755, 1.43, windowZ],
palette.glass,
{ castShadow: false }
);
}
}
// End windows.
addBox(
car,
[1.13, 0.66, 0.045],
[x, 1.43, z + 1.68],
palette.glass,
{ castShadow: false }
);
addBox(
car,
[1.13, 0.66, 0.045],
[x, 1.43, z - 1.68],
palette.glass,
{ castShadow: false }
);
// Wheels aligned to the running rails.
for (const side of [-1, 1]) {
for (const wheelZ of [z - 1.05, z + 1.05]) {
const wheel = addCylinder(
car,
0.29,
0.15,
[x + side * 0.72, 0.32, wheelZ],
palette.iron,
14
);
wheel.rotation.z = Math.PI * 0.5;
}
}
// A small trolley pole, with no overhead wire network.
addBeam(
car,
[x, 2.2, z - 0.35],
[x - 0.18, 4.15, z - 1.6],
0.035,
palette.iron
);
addBox(car, [0.7, 0.19, 0.08], [x, 0.67, z + 1.7], palette.rail);
}
addStreetcar(southBlock);
// The rupture is a subdued dark seam, with a slightly irregular edge.
const faultGroup = new THREE.Group();
world.add(faultGroup);
addBox(
faultGroup,
[18, 0.24, 0.43],
[0, -0.05, 0],
palette.earth,
{ castShadow: false }
);
const crackMaterial = new THREE.MeshStandardMaterial({
color: 0x302d29,
roughness: 1,
transparent: true,
opacity: 0.92
});
for (let i = 0; i < 30; i++) {
const x = -8.8 + i * 0.6;
const crack = addBox(
faultGroup,
[0.48 + Math.random() * 0.26, 0.026, 0.075],
[x, 0.103, (Math.random() - 0.5) * 0.25],
crackMaterial,
{ castShadow: false }
);
crack.rotation.y = (Math.random() - 0.5) * 0.5;
}
// Straight cyan guides show the pre-rupture curb alignment.
const guideMaterial = new THREE.LineDashedMaterial({
color: 0x2b8d91,
dashSize: 0.28,
gapSize: 0.18,
transparent: true,
opacity: 0.85
});
const guideGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-5.08, 0.34, -11.75),
new THREE.Vector3(-5.08, 0.34, 11.75)
]);
const guide = new THREE.Line(guideGeometry, guideMaterial);
guide.computeLineDistances();
guide.visible = false;
world.add(guide);
const offsetInput = document.getElementById("offset");
const offsetValue = document.getElementById("offset-value");
const guideToggle = document.getElementById("guide-toggle");
const annotationToggle = document.getElementById("annotation-toggle");
const sourceDrawer = document.getElementById("source-drawer");
const sourcesToggle = document.getElementById("sources-toggle");
const drawerClose = document.getElementById("drawer-close");
const ruptureAnchor = addAnchor(faultGroup, -2.7, 0.54, -0.1);
const offsetAnchor = addAnchor(southBlock, -4.9, 0.54, 0.08);
const labelDefinitions = [
{
element: document.getElementById("label-rupture"),
anchor: ruptureAnchor
},
{
element: document.getElementById("label-offset"),
anchor: offsetAnchor
}
];
let displacementAmount = 1;
function updateDisplacement(value) {
displacementAmount = THREE.MathUtils.clamp(value / 100, 0, 1);
// The relative modeled lateral offset is 1.05 m at full displacement.
northBlock.position.x = -0.35 * displacementAmount;
southBlock.position.x = 0.70 * displacementAmount;
// A small illustrative vertical step across the rupture.
northBlock.position.y = 0.025 * displacementAmount;
southBlock.position.y = -0.125 * displacementAmount;
crackMaterial.opacity = 0.16 + 0.76 * displacementAmount;
const displayedOffset = 1.05 * displacementAmount;
offsetValue.textContent = `${displayedOffset.toFixed(2)} m`;
offsetInput.style.setProperty(
"--range-fill",
`${displacementAmount * 100}%`
);
}
offsetInput.addEventListener("input", (event) => {
updateDisplacement(Number(event.target.value));
});
guideToggle.addEventListener("click", () => {
guide.visible = !guide.visible;
guideToggle.setAttribute("aria-pressed", String(guide.visible));
});
annotationToggle.addEventListener("click", () => {
const visible = annotationToggle.getAttribute("aria-pressed") !== "true";
annotationToggle.setAttribute("aria-pressed", String(visible));
for (const definition of labelDefinitions) {
definition.element.style.display = visible ? "flex" : "none";
}
});
function setDrawer(open) {
sourceDrawer.classList.toggle("open", open);
sourcesToggle.setAttribute("aria-pressed", String(open));
}
sourcesToggle.addEventListener("click", () => {
setDrawer(!sourceDrawer.classList.contains("open"));
});
drawerClose.addEventListener("click", () => setDrawer(false));
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
setDrawer(false);
}
});
updateDisplacement(100);
// ---------------------------------------------------------------------
// Direct camera controls: spherical orbit, wheel/pinch zoom, shift-pan.
// ---------------------------------------------------------------------
const orbit = {
theta: 0.66,
phi: 0.91,
radius: 25,
target: new THREE.Vector3(0, 0.65, 0)
};
const desired = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius,
target: orbit.target.clone()
};
const canvas = renderer.domElement;
const pointers = new Map();
let activePointer = null;
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
function updateCamera(dt) {
const smoothing = 1 - Math.exp(-dt * 9);
orbit.theta = THREE.MathUtils.lerp(
orbit.theta,
desired.theta,
smoothing
);
orbit.phi = THREE.MathUtils.lerp(
orbit.phi,
desired.phi,
smoothing
);
orbit.radius = THREE.MathUtils.lerp(
orbit.radius,
desired.radius,
smoothing
);
orbit.target.lerp(desired.target, smoothing);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x +
orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z +
orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function panCamera(dx, dy) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(
camera.quaternion
);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(camera.quaternion);
const scale = orbit.radius * 0.00135;
desired.target.addScaledVector(right, -dx * scale);
desired.target.addScaledVector(up, dy * scale);
desired.target.x = THREE.MathUtils.clamp(
desired.target.x,
-8,
8
);
desired.target.y = THREE.MathUtils.clamp(
desired.target.y,
-0.5,
6
);
desired.target.z = THREE.MathUtils.clamp(
desired.target.z,
-10,
10
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
activePointer = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.classList.add("dragging");
} else if (pointers.size === 2) {
activePointer = null;
const values = [...pointers.values()];
previousPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) {
return;
}
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (previousPinchDistance > 0 && distance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius * (previousPinchDistance / distance),
7,
42
);
}
previousPinchDistance = distance;
return;
}
if (event.pointerId !== activePointer) {
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (event.shiftKey || event.buttons === 4) {
panCamera(dx, dy);
} else {
desired.theta -= dx * 0.0055;
desired.phi = THREE.MathUtils.clamp(
desired.phi + dy * 0.0045,
0.1,
1.48
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
previousPinchDistance = 0;
}
if (pointers.size === 1) {
const remaining = [...pointers.entries()][0];
activePointer = remaining[0];
previousX = remaining[1].x;
previousY = remaining[1].y;
} else if (pointers.size === 0) {
activePointer = null;
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
7,
42
);
},
{ passive: false }
);
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
const presets = {
oblique: {
theta: 0.66,
phi: 0.91,
radius: 25,
target: [0, 0.65, 0]
},
street: {
theta: 0.19,
phi: 1.13,
radius: 21.5,
target: [0, 0.9, 2.2]
},
plan: {
theta: 0,
phi: 0.12,
radius: 28,
target: [0, 0, 0]
},
fault: {
theta: 0.05,
phi: 0.62,
radius: 12.5,
target: [-0.8, 0.35, 0]
}
};
const viewButtons = [...document.querySelectorAll(".view-button")];
function applyPreset(name) {
const preset = presets[name];
desired.theta = preset.theta;
desired.phi = preset.phi;
desired.radius = preset.radius;
desired.target.set(...preset.target);
for (const button of viewButtons) {
button.classList.toggle("active", button.dataset.view === name);
}
}
for (const button of viewButtons) {
button.addEventListener("click", () => {
applyPreset(button.dataset.view);
});
}
const projectedPosition = new THREE.Vector3();
function updateLabels() {
for (const definition of labelDefinitions) {
definition.anchor.getWorldPosition(projectedPosition);
projectedPosition.project(camera);
const visible =
projectedPosition.z > -1 &&
projectedPosition.z < 1 &&
Math.abs(projectedPosition.x) < 1.08 &&
Math.abs(projectedPosition.y) < 1.08;
definition.element.style.opacity = visible ? "1" : "0";
if (!visible) {
continue;
}
const x = (projectedPosition.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projectedPosition.y * 0.5 + 0.5) * window.innerHeight;
definition.element.style.transform =
`translate(-50%, -115%) translate(${x}px, ${y}px)`;
}
}
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);
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
updateCamera(dt);
updateLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => loading.classList.add("hidden"));
}
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```