Prompt specification
Build or customize the Three.js 3D scene "Inspect a raised threshold under changing water levels" 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: Inspect a raised threshold under changing water levels
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/inspect-a-raised-threshold-under-changing-water-levels-x2984
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Hội An's riverside streets. Let users vary a clearly schematic river level around the modeled quay. Show access changes and dry interior thresholds without claiming a real flood prediction. Voxel style.
Working Three.js Starter (inspect-a-raised-threshold-under-changing-water-levels-x2984):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hội An — Schematic Riverside</title>
<style>
:root {
--ink: #183238;
--muted: #61777a;
--paper: #f6f0df;
--panel: #fffaf0;
--line: #d9cfb8;
--green: #288b65;
--amber: #c77b20;
--red: #bc4840;
--blue: #327f95;
--cyan: #49c6c2;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background: #b9d7d7;
}
button, input { font: inherit; }
#app {
display: grid;
grid-template-columns: 350px minmax(0, 1fr);
grid-template-rows: 100%;
width: 100%;
height: 100%;
}
#panel {
grid-column: 1;
grid-row: 1;
z-index: 10;
overflow-y: auto;
padding: 24px 22px 26px;
background:
linear-gradient(rgba(255, 250, 240, .97), rgba(255, 250, 240, .97)),
repeating-linear-gradient(0deg, transparent 0 12px, #eadfc8 13px);
border-right: 1px solid rgba(80, 65, 40, .2);
box-shadow: 5px 0 24px rgba(37, 48, 44, .14);
}
#viewport {
grid-column: 2;
grid-row: 1;
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #b9d7d7;
}
canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
z-index: 0;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: #a45135;
font-size: 11px;
font-weight: 800;
letter-spacing: .15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 2px;
background: #a45135;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 37px;
line-height: .98;
font-weight: 600;
letter-spacing: -.035em;
}
.subtitle {
margin: 11px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.warning {
margin: 0 0 20px;
padding: 12px 13px;
border: 1px solid #e4b66b;
border-radius: 10px;
background: #fff3d4;
color: #684b24;
font-size: 11px;
line-height: 1.45;
}
.warning strong {
display: block;
margin-bottom: 4px;
color: #8a4d23;
font-size: 10px;
letter-spacing: .09em;
text-transform: uppercase;
}
.section-title {
display: flex;
justify-content: space-between;
align-items: baseline;
margin: 20px 0 10px;
font-size: 11px;
font-weight: 800;
letter-spacing: .11em;
text-transform: uppercase;
}
.section-title span {
color: var(--muted);
font-weight: 600;
letter-spacing: 0;
text-transform: none;
}
.level-card {
padding: 15px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, .65);
box-shadow: 0 5px 16px rgba(73, 60, 38, .06);
}
.level-readout {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.level-number {
font-size: 29px;
font-weight: 750;
letter-spacing: -.04em;
font-variant-numeric: tabular-nums;
}
.level-number small {
margin-left: 3px;
font-size: 14px;
font-weight: 650;
color: var(--muted);
letter-spacing: 0;
}
.datum {
color: var(--muted);
font-size: 10px;
text-align: right;
line-height: 1.35;
}
input[type="range"] {
width: 100%;
height: 24px;
margin: 0;
accent-color: var(--blue);
cursor: ew-resize;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 2px;
color: #829294;
font-size: 10px;
}
.presets {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 13px;
}
.presets button,
.toolbar button {
border: 1px solid #cfc4ad;
border-radius: 7px;
background: #fffaf0;
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 700;
padding: 8px 10px;
transition: background .15s, border-color .15s, transform .15s;
}
.presets button:hover,
.toolbar button:hover {
border-color: #8fa9a4;
background: #edf4ed;
}
.presets button:active,
.toolbar button:active { transform: translateY(1px); }
.profile {
overflow: hidden;
margin-top: 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: #f7f4e9;
}
.profile svg {
display: block;
width: 100%;
height: auto;
}
.profile-caption {
padding: 7px 10px 9px;
border-top: 1px solid #e4ddcb;
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.route-summary {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 15px 0 8px;
padding: 12px 13px;
border-radius: 10px;
background: #e7f0e6;
border-left: 4px solid var(--green);
transition: background .2s, border-color .2s;
}
.route-summary.reduced {
background: #fff0d2;
border-left-color: var(--amber);
}
.route-summary.restricted {
background: #f8dfda;
border-left-color: var(--red);
}
.route-summary strong {
display: block;
font-size: 13px;
}
.route-summary small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.route-badge {
flex: 0 0 auto;
padding: 5px 8px;
border-radius: 999px;
background: rgba(255, 255, 255, .72);
color: var(--green);
font-size: 9px;
font-weight: 850;
letter-spacing: .08em;
text-transform: uppercase;
}
.reduced .route-badge { color: var(--amber); }
.restricted .route-badge { color: var(--red); }
.status-list {
display: grid;
gap: 7px;
margin-top: 13px;
}
.status-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 10px;
align-items: center;
padding: 10px 11px;
border: 1px solid #e1d8c4;
border-radius: 9px;
background: rgba(255, 255, 255, .5);
}
.status-label {
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: .08em;
text-transform: uppercase;
}
.status-value {
margin-top: 2px;
font-size: 12px;
font-weight: 700;
}
.status-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(40, 139, 101, .12);
}
.status-dot.wet {
background: var(--amber);
box-shadow: 0 0 0 4px rgba(199, 123, 32, .13);
}
.status-dot.edge {
background: var(--red);
box-shadow: 0 0 0 4px rgba(188, 72, 64, .13);
}
.status-dot.dry {
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(73, 198, 194, .14);
}
.disclaimer {
margin-top: 18px;
padding-top: 15px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.disclaimer strong { color: #445e60; }
.toolbar {
position: absolute;
z-index: 5;
top: 15px;
right: 15px;
display: flex;
gap: 6px;
padding: 6px;
border: 1px solid rgba(255, 255, 255, .55);
border-radius: 10px;
background: rgba(255, 250, 240, .82);
backdrop-filter: blur(8px);
box-shadow: 0 5px 20px rgba(39, 54, 50, .12);
}
.toolbar button {
padding: 7px 9px;
background: rgba(255, 255, 255, .75);
}
#labels {
position: absolute;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
#labels.hidden { display: none; }
.pin {
position: absolute;
display: flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, .7);
border-radius: 7px;
background: rgba(26, 48, 52, .84);
color: white;
box-shadow: 0 4px 12px rgba(15, 33, 36, .18);
font-size: 10px;
font-weight: 750;
white-space: nowrap;
transform: translate(-50%, -100%);
backdrop-filter: blur(5px);
}
.pin::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 17px;
background: rgba(26, 48, 52, .8);
}
.pin i {
width: 7px;
height: 7px;
border-radius: 50%;
background: #f0b24d;
}
.pin.sill i { background: var(--cyan); }
.pin.gauge i { background: #ef6a58; }
.pin.bridge i { background: #d98d55; }
.hint {
position: absolute;
z-index: 4;
left: 15px;
bottom: 14px;
padding: 7px 10px;
border-radius: 8px;
background: rgba(25, 47, 50, .72);
color: rgba(255, 255, 255, .9);
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(6px);
}
.scene-title {
position: absolute;
z-index: 4;
left: 18px;
top: 16px;
pointer-events: none;
color: rgba(24, 50, 56, .76);
text-shadow: 0 1px 0 rgba(255, 255, 255, .45);
}
.scene-title strong {
display: block;
font-family: Georgia, serif;
font-size: 20px;
font-weight: 500;
letter-spacing: .02em;
}
.scene-title span {
font-size: 9px;
font-weight: 800;
letter-spacing: .13em;
text-transform: uppercase;
}
@media (max-width: 850px) {
#app {
grid-template-columns: 1fr;
grid-template-rows: 58vh 42vh;
}
#viewport {
grid-column: 1;
grid-row: 1;
}
#panel {
grid-column: 1;
grid-row: 2;
border-right: 0;
border-top: 1px solid rgba(80, 65, 40, .2);
box-shadow: 0 -5px 24px rgba(37, 48, 44, .12);
}
h1 { font-size: 31px; }
.scene-title { display: none; }
.hint { display: none; }
}
</style>
</head>
<body>
<div id="app">
<aside id="panel">
<div class="eyebrow">Riverside scenario</div>
<h1>Hội An</h1>
<p class="subtitle">
A voxel riverside study with a movable, schematic river level around the
modeled quay, landing steps, and raised shop thresholds.
</p>
<div class="warning">
<strong>Schematic · not a flood prediction</strong>
The slider uses an illustrative relative level. It is not a surveyed
elevation, hydraulic model, or forecast, and does not simulate flow,
defenses, drainage, or inland flooding.
</div>
<div class="section-title">
Schematic river level
<span>relative units</span>
</div>
<div class="level-card">
<div class="level-readout">
<div class="level-number">
<span id="levelValue">+0.30</span><small>m</small>
</div>
<div class="datum">
arbitrary vertical datum<br />
shown range −0.15 to +1.55
</div>
</div>
<input
id="level"
type="range"
min="-0.15"
max="1.55"
step="0.01"
value="0.30"
aria-label="Schematic river level"
/>
<div class="range-ends">
<span>Lower</span>
<span>Upper</span>
</div>
<div class="presets">
<button type="button" data-level="0.05">Lower</button>
<button type="button" data-level="0.48">Middle</button>
<button type="button" data-level="1.38">Upper</button>
</div>
</div>
<div class="profile" aria-label="Schematic cross-section">
<svg viewBox="0 0 300 130" role="img">
<rect width="300" height="130" fill="#f5f1e5" />
<g opacity=".5" stroke="#d7d0bd" stroke-width="1">
<path d="M0 24H300M0 49H300M0 74H300M0 99H300" />
</g>
<rect id="profileWater" x="0" y="67" width="182" height="63"
fill="#4aa5ba" fill-opacity=".26" />
<line id="profileWaterLine" x1="0" y1="67" x2="182" y2="67"
stroke="#328ba0" stroke-width="2" />
<g id="profileSteps" fill="#cdbb94" stroke="#9f8d6b" stroke-width="1"></g>
<rect x="145" y="42" width="8" height="88"
fill="#bba984" stroke="#8f7c5d" />
<path d="M153 42H190" stroke="#8f7c5d" stroke-width="3" />
<rect x="195" y="29" width="76" height="101"
fill="#e8c86e" stroke="#9e8250" stroke-width="1" />
<rect x="190" y="29" width="86" height="10"
fill="#465653" stroke="#364441" />
<line x1="222" y1="24" x2="222" y2="39"
stroke="#26aaa7" stroke-width="3" />
<circle cx="222" cy="24" r="3" fill="#26aaa7" />
<text x="225" y="19" font-family="system-ui" font-size="8"
font-weight="700" fill="#227d7b">raised sill</text>
<text x="7" y="121" font-family="system-ui" font-size="8"
fill="#537176">RIVER</text>
<text x="202" y="121" font-family="system-ui" font-size="8"
fill="#725f43">INTERIOR · DRY</text>
</svg>
<div class="profile-caption">
Cross-section is a visual aid only. The interior floor and sill remain
raised reference geometry; no inland inundation is simulated.
</div>
</div>
<div id="routeSummary" class="route-summary" aria-live="polite">
<div>
<strong id="routeTitle">Reduced stepped access</strong>
<small id="routeDetail">The low landing is wet in this scenario.</small>
</div>
<span id="routeBadge" class="route-badge">Reduced</span>
</div>
<div class="section-title">
Modeled access and thresholds
<span>updates with slider</span>
</div>
<div class="status-list">
<div class="status-row">
<div>
<div class="status-label">Stepped landing</div>
<div id="landingValue" class="status-value">Lower landing wet</div>
</div>
<span id="landingDot" class="status-dot wet"></span>
</div>
<div class="status-row">
<div>
<div class="status-label">Modeled quay edge</div>
<div id="quayValue" class="status-value">Dry</div>
</div>
<span id="quayDot" class="status-dot"></span>
</div>
<div class="status-row">
<div>
<div class="status-label">Lowest raised interior sill</div>
<div id="interiorValue" class="status-value">Dry · +1.35 m clearance</div>
</div>
<span class="status-dot dry"></span>
</div>
</div>
<p class="disclaimer">
<strong>Interpretation:</strong> visible wetting and access changes occur
only in the modeled river and stepped landing. “Clearance” is a vertical
comparison to the selected schematic sill, not a safety assessment or
statement about actual flood behavior.
</p>
</aside>
<main id="viewport">
<div class="scene-title">
<strong>Thu Bồn · Hoi An</strong>
<span>Voxel waterfront / illustrative section</span>
</div>
<div class="toolbar">
<button id="toggleLabels" type="button">Labels</button>
<button id="resetView" type="button">Reset view</button>
</div>
<div id="labels">
<div class="pin" id="pinSteps"><i></i>Stepped landing</div>
<div class="pin sill" id="pinSill"><i></i>Raised interior sill</div>
<div class="pin gauge" id="pinGauge"><i></i>Level gauge</div>
<div class="pin bridge" id="pinBridge"><i></i>Covered bridge</div>
</div>
<div class="hint">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom · R resets view
</div>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* ------------------------------------------------------------------
DOM and constants
------------------------------------------------------------------ */
const viewport = document.getElementById("viewport");
const labels = document.getElementById("labels");
const levelInput = document.getElementById("level");
const levelValue = document.getElementById("levelValue");
const routeSummary = document.getElementById("routeSummary");
const routeTitle = document.getElementById("routeTitle");
const routeDetail = document.getElementById("routeDetail");
const routeBadge = document.getElementById("routeBadge");
const landingValue = document.getElementById("landingValue");
const landingDot = document.getElementById("landingDot");
const quayValue = document.getElementById("quayValue");
const quayDot = document.getElementById("quayDot");
const interiorValue = document.getElementById("interiorValue");
const profileWater = document.getElementById("profileWater");
const profileWaterLine = document.getElementById("profileWaterLine");
const profileSteps = document.getElementById("profileSteps");
const QUAY_TOP = 1.20;
const INTERIOR_SILL = 1.65;
const STEP_TOPS = [0.96, 0.72, 0.48, 0.24, 0.00];
const STEP_WIDTH = 4.2;
const STEP_CENTER_X = 2.1;
let riverLevel = Number(levelInput.value);
/* ------------------------------------------------------------------
Renderer, scene, and camera
------------------------------------------------------------------ */
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8d6d5);
scene.fog = new THREE.Fog(0xb8d6d5, 27, 65);
const camera = new THREE.PerspectiveCamera(
42,
viewport.clientWidth / viewport.clientHeight,
0.1,
120
);
const target = new THREE.Vector3(1.0, 1.1, 1.2);
const defaultView = {
yaw: 2.25,
polar: 1.02,
radius: 33
};
let yaw = defaultView.yaw;
let polar = defaultView.polar;
let radius = defaultView.radius;
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.sin(yaw),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.cos(yaw)
);
camera.lookAt(target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xd8f1ef, 0x806c50, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe0b4, 3.0);
sun.position.set(-12, 22, -9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.0006;
scene.add(sun);
/* ------------------------------------------------------------------
Materials and helpers
------------------------------------------------------------------ */
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
}
function box(w, h, d, x, y, z, material, parent = scene, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function signMaterial(text, background = "#754735", foreground = "#ffe4a3") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "rgba(255,235,185,.7)";
ctx.lineWidth = 8;
ctx.strokeRect(9, 9, canvas.width - 18, canvas.height - 18);
ctx.fillStyle = foreground;
ctx.font = "700 48px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return new THREE.MeshBasicMaterial({ map: texture });
}
function addSign(text, x, y, z, w, h, parent = scene, bg, fg) {
const material = signMaterial(text, bg, fg);
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(w, h), material);
mesh.position.set(x, y, z);
mesh.rotation.y = Math.PI;
parent.add(mesh);
return mesh;
}
const landMat = standard(0xb9ad8b);
const wallMat = standard(0xc7b590);
const pavingMat = standard(0x8f9184);
const curbMat = standard(0xb9ac8d);
const woodMat = standard(0x704738);
const darkWoodMat = standard(0x40352f);
const trimMat = standard(0xf0d8a0);
const roofMats = [
standard(0x3f504e),
standard(0x465957),
standard(0x374846)
];
const palette = [
0xd9a434, 0xd97652, 0xe1c273, 0xc89056,
0x93a68b, 0xd4ba91, 0xb76c4d, 0xe6b95c
];
/* ------------------------------------------------------------------
Land, river bed, water, and quay
------------------------------------------------------------------ */
box(44, 1.2, 18, 0, 0.60, 9.0, landMat);
box(46, 0.5, 32, 0, -0.80, -6.5, standard(0x567d77), scene, false);
box(46, 1.2, 2.5, 0, 0.60, -14.4, landMat);
const quayWallMat = standard(0xa89a79);
box(44, 1.2, 0.42, 0, 0.60, 0.18, quayWallMat);
box(44, 0.12, 2.5, 0, 1.26, 1.45, pavingMat);
const waterGroup = new THREE.Group();
scene.add(waterGroup);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x3f94a6,
roughness: 0.28,
metalness: 0.03,
transparent: true,
opacity: 0.82,
depthWrite: false,
side: THREE.DoubleSide
});
const waterPlane = new THREE.Mesh(
new THREE.PlaneGeometry(46, 14.2),
waterMaterial
);
waterPlane.rotation.x = -Math.PI / 2;
waterPlane.position.set(0, 0, -6.35);
waterPlane.receiveShadow = true;
waterPlane.renderOrder = 2;
waterGroup.add(waterPlane);
const waveMaterial = new THREE.MeshBasicMaterial({
color: 0x8bc8cd,
transparent: true,
opacity: 0.48,
depthWrite: false
});
const waves = [];
for (let i = 0; i < 55; i++) {
const x = -22 + (i * 7.31 % 44);
const z = -12.7 + (i * 3.17 % 12.1);
const wave = box(
0.5 + (i % 4) * 0.22,
0.018,
0.075,
x,
0.022,
z,
waveMaterial,
waterGroup,
false
);
wave.userData.baseX = x;
wave.userData.phase = i * 0.73;
waves.push(wave);
}
const foam = box(
46, 0.018, 0.08, 0, 0.025, 0.03,
new THREE.MeshBasicMaterial({
color: 0xd7eeee,
transparent: true,
opacity: 0.65,
depthWrite: false
}),
waterGroup,
false
);
const stepMeshes = [];
const stepMaterials = [];
const routeMaterial = standard(0x43a874, {
emissive: 0x143d2c,
emissiveIntensity: 0.35
});
for (let i = 0; i < STEP_TOPS.length; i++) {
const top = STEP_TOPS[i];
const bottom = -0.45;
const z = -0.22 - i * 0.42;
const material = standard(0xcbb58b);
const step = box(
STEP_WIDTH,
top - bottom,
0.42,
STEP_CENTER_X,
(top + bottom) / 2,
z,
material
);
stepMeshes.push(step);
stepMaterials.push(material);
box(
0.17,
0.025,
0.32,
STEP_CENTER_X,
top + 0.025,
z,
routeMaterial,
scene,
false
);
}
box(
0.17, 0.025, 1.05,
STEP_CENTER_X, QUAY_TOP + 0.026, 0.33,
routeMaterial, scene, false
);
const edgeMaterial = standard(0x49a978, {
emissive: 0x153c2c,
emissiveIntensity: 0.2
});
box(
8.4, 0.035, 0.11,
STEP_CENTER_X, QUAY_TOP + 0.04, 0.18,
edgeMaterial, scene, false
);
const barrier = new THREE.Group();
scene.add(barrier);
box(0.12, 1.0, 0.12, 4.35, 1.72, -0.62, darkWoodMat, barrier);
box(0.12, 1.0, 0.12, 2.85, 1.72, -0.62, darkWoodMat, barrier);
box(
1.8, 0.14, 0.12,
3.60, 2.08, -0.62,
standard(0xd94f43), barrier
);
barrier.visible = false;
/* ------------------------------------------------------------------
Street, shop houses, doors, windows, roofs
------------------------------------------------------------------ */
box(39, 0.055, 3.1, 0, 1.235, 8.05, pavingMat, scene, false);
box(39, 0.14, 0.25, 0, 1.29, 6.48, curbMat);
box(39, 0.14, 0.25, 0, 1.29, 9.66, curbMat);
function makeBuilding(x, z, width, depth, height, color, signText, variant = 0) {
const base = QUAY_TOP;
const front = z - depth / 2;
const wall = standard(color);
const trim = standard(variant % 2 ? 0xf1dca5 : 0xe5c27e);
box(width, height, depth, x, base + height / 2, z, wall);
box(width + 0.10, 0.14, depth + 0.10, x, base + 0.07, z, trim);
// Raised doorway and threshold.
const doorWidth = Math.min(0.95, width * 0.27);
box(
doorWidth, 1.32, 0.10,
x, 2.21, front - 0.075,
standard(variant % 3 === 0 ? 0x5f4032 : 0x42665d)
);
box(
doorWidth + 0.26, 0.12, 0.30,
x, 1.56, front - 0.16,
standard(0xb9aa87)
);
// First-floor windows.
const windowMaterial = standard(0x42676b, {
roughness: 0.35,
emissive: 0x173638,
emissiveIntensity: 0.18
});
const windowCount = Math.max(2, Math.floor(width / 1.15));
for (let i = 0; i < windowCount; i++) {
const wx = x + (i - (windowCount - 1) / 2) * (width / (windowCount + 0.15));
if (Math.abs(wx - x) < doorWidth * 0.85) continue;
box(0.48, 0.72, 0.10, wx, 2.12, front - 0.085, windowMaterial);
box(0.62, 0.09, 0.13, wx, 1.76, front - 0.10, trim);
if (variant % 2 === 0) {
box(0.10, 0.78, 0.12, wx - 0.34, 2.12, front - 0.09, trim);
box(0.10, 0.78, 0.12, wx + 0.34, 2.12, front - 0.09, trim);
}
}
// Upper windows.
if (height > 3.1) {
const upperY = base + height * 0.72;
for (let i = 0; i < windowCount; i++) {
const wx = x + (i - (windowCount - 1) / 2) * (width / (windowCount + 0.15));
box(0.40, 0.62, 0.09, wx, upperY, front - 0.08, windowMaterial);
box(0.53, 0.08, 0.12, wx, upperY - 0.36, front - 0.10, trim);
}
}
// Voxel gable roof: stepped slabs on both sides of a central ridge.
const roofBase = base + height + 0.08;
const half = depth / 2;
const layers = 3;
const segment = half / layers;
for (const side of [-1, 1]) {
for (let j = 0; j < layers; j++) {
const distance = (j + 0.5) * segment;
const roofY = roofBase + 0.13 + (layers - j) * 0.15;
box(
width + 0.48,
0.18,
segment + 0.13,
x,
roofY,
z + side * distance,
roofMats[(j + variant) % roofMats.length]
);
}
}
box(
width + 0.52,
0.20,
0.35,
x,
roofBase + 0.68,
z,
roofMats[0]
);
// Shop sign.
addSign(
signText,
x,
base + Math.min(height - 0.35, 2.85),
front - 0.105,
Math.min(width - 0.35, 2.35),
0.52
);
// Small balcony on some façades.
if (variant % 3 === 1) {
box(width * 0.55, 0.10, 0.45, x, 3.10, front - 0.30, woodMat);
for (let i = 0; i < 4; i++) {
box(
0.05, 0.42, 0.05,
x - width * 0.23 + i * width * 0.15,
3.33,
front - 0.50,
darkWoodMat
);
}
}
// Awning.
if (variant % 3 === 2) {
box(
width * 0.72, 0.10, 0.65,
x, 2.78, front - 0.42,
standard(variant % 2 ? 0xaa5e43 : 0x567d72)
);
}
}
const riverRow = [
[-14.5, 4.1, 3.2, "NƯỚC"],
[-10.7, 4.4, 3.3, "SILK"],
[-6.7, 3.8, 3.1, "HỘI AN"],
[-2.6, 4.5, 4.0, "LAN TẤM"],
[1.6, 4.2, 3.7, "CAFÉ"],
[5.9, 3.5, 3.0, "MĂNG"],
[9.6, 4.2, 3.4, "ĐÈO"],
[13.6, 3.8, 3.2, "GHE"]
];
riverRow.forEach((b, i) => {
makeBuilding(
b[0], 4.35, b[1], b[2],
2.8 + (i % 4) * 0.35,
palette[i % palette.length],
b[3],
i
);
});
const backRow = [
[-13.8, 3.4, 2.9, "BỌC"],
[-10.1, 3.8, 3.2, "NEM"],
[-6.3, 3.5, 3.0, "GỖ"],
[-2.5, 3.8, 3.4, "HOA"],
[1.3, 3.4, 3.1, "TÂM"],
[5.0, 3.7, 3.3, "MẬU"],
[8.8, 3.3, 2.9, "LỤA"]
];
backRow.forEach((b, i) => {
makeBuilding(
b[0], 11.8, b[1], b[2],
3.0 + (i % 3) * 0.35,
palette[(i + 3) % palette.length],
b[3],
i + 1
);
});
/* ------------------------------------------------------------------
Raised sill marker and vertical gauge
------------------------------------------------------------------ */
const thresholdMaterial = standard(0x43c9c4, {
emissive: 0x136b69,
emissiveIntensity: 0.75
});
const thresholdMarker = box(
1.5, 0.13, 0.34,
-2.6, INTERIOR_SILL, 1.90,
thresholdMaterial
);
const thresholdStem = box(
0.035, 0.75, 0.035,
-2.6, INTERIOR_SILL + 0.36, 1.83,
thresholdMaterial,
scene,
false
);
const gauge = new THREE.Group();
gauge.position.set(-8.4, 0, -0.28);
scene.add(gauge);
box(0.75, 2.18, 0.16, 0, 0.75, 0, standard(0xf0e4c7), gauge);
for (let i = 0; i < 10; i++) {
const y = -0.15 + i * 0.18;
const width = i % 2 === 0 ? 0.52 : 0.35;
box(
width, 0.035, 0.025,
-0.04, y, -0.095,
standard(0x43585a),
gauge,
false
);
}
const gaugeMarker = box(
1.12, 0.08, 0.20,
0, riverLevel, -0.13,
standard(0xe65b4f, {
emissive: 0x681d16,
emissiveIntensity: 0.35
}),
gauge
);
/* ------------------------------------------------------------------
Lanterns, trees, boats, and street details
------------------------------------------------------------------ */
const lanternMaterials = [
standard(0xe74e3f, { emissive: 0xa51c14, emissiveIntensity: 0.8 }),
standard(0xf0a52f, { emissive: 0x9f5b0b, emissiveIntensity: 0.75 }),
standard(0xe9d16e, { emissive: 0x8c691c, emissiveIntensity: 0.6 })
];
const lanternPositions = [];
for (let i = 0; i <= 24; i++) {
const x = -12 + i;
const t = x / 12;
const y = 3.72 - 0.42 * (1 - t * t);
lanternPositions.push(new THREE.Vector3(x, y, 1.62));
}
const stringGeometry = new THREE.BufferGeometry().setFromPoints(lanternPositions);
const stringLine = new THREE.Line(
stringGeometry,
new THREE.LineBasicMaterial({ color: 0x3f4039 })
);
scene.add(stringLine);
lanternPositions.forEach((p, i) => {
if (i % 2 !== 0) return;
const material = lanternMaterials[i % lanternMaterials.length];
box(0.34, 0.48, 0.34, p.x, p.y - 0.35, p.z, material);
box(0.38, 0.06, 0.38, p.x, p.y - 0.08, p.z, darkWoodMat);
box(0.38, 0.06, 0.38, p.x, p.y - 0.62, p.z, darkWoodMat);
box(0.035, 0.24, 0.035, p.x, p.y - 0.77, p.z, material);
});
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, QUAY_TOP, z);
group.scale.setScalar(scale);
scene.add(group);
box(0.45, 2.2, 0.45, 0, 1.1, 0, standard(0x73533c), group);
box(0.22, 0.22, 1.1, 0, 1.8, -0.25, standard(0x73533c), group);
const foliage = standard(0x668454);
box(2.0, 1.2, 1.7, 0, 2.55, 0, foliage, group);
box(1.35, 1.05, 1.4, -0.65, 3.2, 0.12, standard(0x78915b), group);
box(1.25, 0.9, 1.25, 0.72, 3.25, -0.08, standard(0x57754c), group);
box(1.0, 0.8, 1.0, 0.05, 3.85, 0.08, standard(0x82975e), group);
}
makeTree(-17.2, 2.3, 1.15);
makeTree(-17.0, 6.3, 0.9);
makeTree(7.7, 6.25, 0.85);
makeTree(16.8, 6.4, 1.0);
function makePlanter(x, z, color) {
box(1.0, 0.45, 0.75, x, 1.48, z, standard(0xa97852));
box(0.9, 0.4, 0.65, x, 1.78, z, standard(color));
box(0.65, 0.32, 0.5, x + 0.12, 2.08, z, standard(0x63805a));
}
makePlanter(-7.6, 7.35, 0xc56045);
makePlanter(-5.8, 7.35, 0x4f866f);
makePlanter(4.9, 7.35, 0xc78b45);
function makeBoat(x, z, rotation, scale = 1) {
const group = new THREE.Group();
group.position.set(x, riverLevel + 0.10, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
scene.add(group);
const hull = standard(0x6e4935);
box(2.8, 0.36, 1.05, 0, 0, 0, hull, group);
box(0.58, 0.42, 0.78, -1.42, 0.03, 0, hull, group);
box(0.58, 0.42, 0.78, 1.42, 0.03, 0, hull, group);
box(2.25, 0.10, 0.88, 0, 0.23, 0, standard(0xa9784f), group);
box(0.72, 0.60, 0.72, 0.25, 0.55, 0, standard(0xcf9e4f), group);
box(0.90, 0.10, 0.92, 0.25, 0.89, 0, standard(0x405654), group);
box(0.08, 1.35, 0.08, -0.75, 1.0, 0, darkWoodMat, group);
group.userData.phase = x * 0.12 + z * 0.07;
return group;
}
const boats = [
makeBoat(-8.5, -6.3, 0.12, 1.0),
makeBoat(-1.2, -8.3, -0.18, 0.85),
makeBoat(6.6, -4.6, 0.24, 1.1),
makeBoat(17.6, -9.3, 0.35, 0.8)
];
/* ------------------------------------------------------------------
Covered bridge landmark
------------------------------------------------------------------ */
const bridge = new THREE.Group();
bridge.position.set(13.1, 0, -6.1);
scene.add(bridge);
const bridgeCream = standard(0xe7d6a1);
const bridgeRoof = standard(0x965342);
box(2.65, 0.24, 14.1, 0, 1.48, 0, standard(0x8d6848), bridge);
box(2.35, 0.12, 14.0, 0, 1.65, 0, standard(0xb28a5e), bridge);
for (let i = 0; i < 8; i++) {
const z = -6.4 + i * 1.82;
box(0.14, 1.12, 0.14, -1.12, 2.20, z, bridgeCream, bridge);
box(0.14, 1.12, 0.14, 1.12, 2.20, z, bridgeCream, bridge);
}
for (const side of [-1, 1]) {
box(0.12, 0.12, 13.6, side * 1.15, 2.63, 0, bridgeCream, bridge);
box(0.10, 0.10, 13.5, side * 1.15, 2.14, 0, standard(0xb07b4d), bridge);
}
// Stepped roof, ridge running along the bridge.
for (const side of [-1, 1]) {
for (let j = 0; j < 3; j++) {
box(
0.72,
0.20,
13.6,
side * (0.50 + j * 0.58),
3.05 + (2 - j) * 0.16,
0,
j % 2 ? standard(0xa35d48) : bridgeRoof,
bridge
);
}
}
box(0.50, 0.24, 13.8, 0, 3.52, 0, standard(0x854a3d), bridge);
// Bridge end frames.
for (const z of [-5.1, 5.1]) {
box(2.45, 0.18, 0.18, 0, 2.55, z, bridgeCream, bridge);
box(0.16, 1.0, 0.16, -1.08, 2.12, z, bridgeCream, bridge);
box(0.16, 1.0, 0.16, 1.08, 2.12, z, bridgeCream, bridge);
}
/* ------------------------------------------------------------------
Additional far-bank silhouettes
------------------------------------------------------------------ */
for (let i = 0; i < 6; i++) {
const x = -18 + i * 7.2;
const h = 1.4 + (i % 3) * 0.5;
box(
3.4, h, 2.3,
x, QUAY_TOP + h / 2, -14.7,
standard(i % 2 ? 0xc5b586 : 0xd2bd8e)
);
}
/* ------------------------------------------------------------------
Scenario updates
------------------------------------------------------------------ */
const green = new THREE.Color(0x43a874);
const amber = new THREE.Color(0xe0a43c);
const red = new THREE.Color(0xdb574c);
const dryStone = new THREE.Color(0xcbb58b);
const wetStone = new THREE.Color(0x718783);
function setRouteColor(color) {
routeMaterial.color.copy(color);
routeMaterial.emissive.copy(color).multiplyScalar(0.18);
}
function updateScenario() {
riverLevel = Number(levelInput.value);
levelValue.textContent = `${riverLevel >= 0 ? "+" : ""}${riverLevel.toFixed(2)}`;
levelInput.setAttribute(
"aria-valuetext",
`${riverLevel.toFixed(2)} schematic relative units`
);
waterGroup.position.y = riverLevel;
gaugeMarker.position.y = riverLevel;
boats.forEach((boat) => {
boat.position.y = riverLevel + 0.10;
});
stepMaterials.forEach((material, i) => {
material.color.copy(
riverLevel >= STEP_TOPS[i] - 0.01 ? wetStone : dryStone
);
});
let routeState;
let title;
let detail;
let badge;
let badgeClass;
if (riverLevel < 0.26) {
routeState = "open";
title = "Stepped access shown open";
detail = "The lower landing remains dry in this schematic scenario.";
badge = "Open";
badgeClass = "";
setRouteColor(green);
edgeMaterial.color.copy(green);
} else if (riverLevel < 0.73) {
routeState = "reduced";
title = "Reduced stepped access";
detail = "The low landing and lower steps are wet.";
badge = "Reduced";
badgeClass = "reduced";
setRouteColor(amber);
edgeMaterial.color.copy(amber);
} else if (riverLevel < QUAY_TOP + 0.02) {
routeState = "restricted";
title = "Restricted stepped access";
detail = "Most lower steps are submerged; the upper landing remains above water.";
badge = "Restricted";
badgeClass = "restricted";
setRouteColor(red);
edgeMaterial.color.copy(red);
} else {
routeState = "restricted";
title = "Modeled quay edge reached";
detail = "The river reaches the modeled quay elevation; access is restricted.";
badge = "Edge reached";
badgeClass = "restricted";
setRouteColor(red);
edgeMaterial.color.copy(red);
}
routeSummary.className = `route-summary ${badgeClass}`;
routeTitle.textContent = title;
routeDetail.textContent = detail;
routeBadge.textContent = badge;
barrier.visible = riverLevel >= 0.73;
if (riverLevel < 0.02) {
landingValue.textContent = "Dry";
landingDot.className = "status-dot";
} else if (riverLevel < 0.38) {
landingValue.textContent = "Lower landing wet";
landingDot.className = "status-dot wet";
} else if (riverLevel < 0.78) {
landingValue.textContent = "Lower steps submerged";
landingDot.className = "status-dot wet";
} else if (riverLevel < 1.22) {
landingValue.textContent = "Upper landing wet";
landingDot.className = "status-dot edge";
} else {
landingValue.textContent = "Steps submerged";
landingDot.className = "status-dot edge";
}
if (riverLevel < QUAY_TOP) {
quayValue.textContent = "Dry";
quayDot.className = "status-dot";
} else {
quayValue.textContent = "At modeled elevation";
quayDot.className = "status-dot edge";
}
const clearance = INTERIOR_SILL - riverLevel;
interiorValue.textContent = `Dry · +${clearance.toFixed(2)} m clearance`;
updateProfile();
}
function svgY(level) {
const min = -0.15;
const max = 1.55;
return 112 - ((level - min) / (max - min)) * 92;
}
function updateProfile() {
const y = svgY(riverLevel);
profileWater.setAttribute("y", y);
profileWater.setAttribute("height", 120 - y);
profileWaterLine.setAttribute("y1", y);
profileWaterLine.setAttribute("y2", y);
}
// Draw the schematic steps in the SVG profile.
STEP_TOPS.forEach((top, i) => {
const x = 145 - (i + 1) * 8;
const y = svgY(top);
const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
rect.setAttribute("x", x);
rect.setAttribute("y", y);
rect.setAttribute("width", "8");
rect.setAttribute("height", 120 - y);
profileSteps.appendChild(rect);
});
/* ------------------------------------------------------------------
Direct HTML camera controls — no addons
------------------------------------------------------------------ */
const canvas = renderer.domElement;
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const scale = radius * 0.0012;
target.x = THREE.MathUtils.clamp(target.x - dx * scale, -18, 18);
target.z = THREE.MathUtils.clamp(target.z - dy * scale, -14, 14);
} else {
yaw -= dx * 0.005;
polar = THREE.MathUtils.clamp(polar + dy * 0.004, 0.40, 1.30);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
panning = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
14,
52
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
function resetView() {
yaw = defaultView.yaw;
polar = defaultView.polar;
radius = defaultView.radius;
target.set(1.0, 1.1, 1.2);
updateCamera();
}
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
resetView();
return;
}
if (key === "arrowleft") target.x -= 0.7;
else if (key === "arrowright") target.x += 0.7;
else if (key === "arrowup") target.z -= 0.7;
else if (key === "arrowdown") target.z += 0.7;
else if (key === "+" || key === "=") radius = Math.max(14, radius - 1.5);
else if (key === "-") radius = Math.min(52, radius + 1.5);
else return;
event.preventDefault();
updateCamera();
});
/* ------------------------------------------------------------------
UI events
------------------------------------------------------------------ */
levelInput.addEventListener("input", updateScenario);
document.querySelectorAll("[data-level]").forEach((button) => {
button.addEventListener("click", () => {
levelInput.value = button.dataset.level;
updateScenario();
});
});
document.getElementById("resetView").addEventListener("click", resetView);
document.getElementById("toggleLabels").addEventListener("click", (event) => {
labels.classList.toggle("hidden");
event.currentTarget.textContent =
labels.classList.contains("hidden") ? "Show labels" : "Labels";
});
/* ------------------------------------------------------------------
Screen-space labels
------------------------------------------------------------------ */
const pinDefinitions = [
{
element: document.getElementById("pinSteps"),
position: new THREE.Vector3(2.1, 0.80, -1.25)
},
{
element: document.getElementById("pinSill"),
position: new THREE.Vector3(-2.6, 2.22, 1.83)
},
{
element: document.getElementById("pinGauge"),
position: new THREE.Vector3(-8.4, 2.12, -0.28)
},
{
element: document.getElementById("pinBridge"),
position: new THREE.Vector3(13.1, 4.10, -6.1)
}
];
function updatePins() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
pinDefinitions.forEach((pin) => {
const projected = pin.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
pin.element.style.display = visible ? "flex" : "none";
if (visible) {
pin.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
pin.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
});
}
/* ------------------------------------------------------------------
Resize and animation
------------------------------------------------------------------ */
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / Math.max(1, height);
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
new ResizeObserver(resize).observe(viewport);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
waves.forEach((wave) => {
wave.position.x =
wave.userData.baseX + Math.sin(time * 0.42 + wave.userData.phase) * 0.11;
});
boats.forEach((boat) => {
boat.position.y =
riverLevel + 0.10 + Math.sin(time * 1.1 + boat.userData.phase) * 0.025;
boat.rotation.z =
Math.sin(time * 0.72 + boat.userData.phase) * 0.015;
});
thresholdMaterial.emissiveIntensity =
0.62 + Math.sin(time * 2.0) * 0.14;
updatePins();
renderer.render(scene, camera);
}
updateScenario();
animate();
</script>
</body>
</html>
```