Prompt specification
Build or customize the Three.js 3D scene "Norwegian fjord branch with settlement and tunnel approach" 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: Norwegian fjord branch with settlement and tunnel approach
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/norwegian-fjord-branch-with-settlement-and-tunnel-appr-x3103
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: norwegian fjord branch with settlement and tunnel approach. Build a bounded landscape with steep sides, deep water, narrow settlement strip, and a schematic tunnel entrance. Use referenced regional form rather than an exact engineering reconstruction. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (norwegian-fjord-branch-with-settlement-and-tunnel-appr-x3103):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Norwegian Fjord Branch — Low-Poly Study</title>
<style>
:root {
--ink: #18313a;
--paper: rgba(244, 241, 230, 0.92);
--line: rgba(24, 49, 58, 0.22);
--accent: #d97941;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd9dc;
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;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.panel {
position: fixed;
z-index: 10;
pointer-events: none;
}
.title-card {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 17px 19px 16px;
border: 1px solid rgba(255,255,255,0.7);
border-radius: 3px;
background: var(--paper);
box-shadow: 0 14px 38px rgba(30, 55, 63, 0.14);
backdrop-filter: blur(8px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 31px);
font-weight: 720;
line-height: 1.03;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
max-width: 34em;
color: rgba(24, 49, 58, 0.72);
font-size: 12px;
line-height: 1.5;
}
.meta {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 13px;
}
.meta span {
padding: 5px 7px;
border: 1px solid var(--line);
border-radius: 2px;
color: rgba(24, 49, 58, 0.8);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.controls {
top: 22px;
right: 22px;
z-index: 12;
display: flex;
gap: 7px;
pointer-events: auto;
}
button {
border: 1px solid rgba(255,255,255,0.72);
border-radius: 3px;
padding: 9px 11px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 24px rgba(30, 55, 63, 0.12);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(8px);
}
button:hover { background: #fffdf7; }
button[aria-pressed="false"] { opacity: 0.62; }
.legend {
right: 22px;
bottom: 22px;
width: 172px;
padding: 13px 14px;
border: 1px solid rgba(255,255,255,0.65);
border-radius: 3px;
background: rgba(244, 241, 230, 0.88);
box-shadow: 0 10px 28px rgba(30, 55, 63, 0.11);
backdrop-filter: blur(8px);
}
.legend-title {
margin-bottom: 9px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 7px;
color: rgba(24, 49, 58, 0.75);
font-size: 10px;
}
.swatch {
width: 16px;
height: 7px;
border-radius: 1px;
box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}
.hint {
left: 22px;
bottom: 22px;
padding: 9px 11px;
border: 1px solid rgba(255,255,255,0.58);
border-radius: 3px;
background: rgba(244, 241, 230, 0.82);
color: rgba(24, 49, 58, 0.68);
font-size: 10px;
letter-spacing: 0.04em;
backdrop-filter: blur(7px);
}
.compass {
right: 28px;
top: 83px;
width: 40px;
height: 58px;
color: var(--ink);
text-align: center;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
}
.compass::before {
content: "";
display: block;
width: 0;
height: 0;
margin: 0 auto 4px;
border-right: 6px solid transparent;
border-bottom: 23px solid var(--accent);
border-left: 6px solid transparent;
}
.landmark {
position: fixed;
z-index: 8;
min-width: 118px;
padding: 6px 8px;
border-left: 2px solid var(--accent);
background: rgba(250, 247, 238, 0.86);
color: var(--ink);
box-shadow: 0 6px 20px rgba(22, 47, 55, 0.11);
font-size: 9px;
font-weight: 800;
line-height: 1.25;
letter-spacing: 0.11em;
text-transform: uppercase;
transform: translate(-50%, -100%);
pointer-events: none;
backdrop-filter: blur(5px);
transition: opacity 120ms ease;
}
.landmark small {
display: block;
margin-top: 2px;
color: rgba(24, 49, 58, 0.58);
font-size: 8px;
font-weight: 650;
letter-spacing: 0.07em;
}
.landmark::after {
content: "";
position: absolute;
left: -5px;
bottom: -19px;
width: 1px;
height: 19px;
background: var(--accent);
}
.hidden { opacity: 0 !important; }
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #cbd9dc;
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
@media (max-width: 680px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 14px;
}
.subtitle { font-size: 11px; }
.meta { display: none; }
.controls {
top: auto;
right: 12px;
bottom: 54px;
}
.legend { display: none; }
.hint { left: 12px; bottom: 12px; }
.compass { top: 122px; right: 17px; }
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="panel title-card">
<div class="eyebrow">Regional form study · 01</div>
<h1>Norwegian Fjord Branch</h1>
<p class="subtitle">
A bounded low-poly landscape with a branching deep-water fjord,
a compressed waterside settlement, and a schematic mountain-tunnel approach.
The geometry is interpretive rather than navigational or engineering-accurate.
</p>
<div class="meta">
<span>Steep-sided fjord</span>
<span>Narrow shore</span>
<span>Concept tunnel</span>
</div>
</header>
<nav class="controls" aria-label="Scene controls">
<button id="reset" type="button">Reset view</button>
<button id="toggleLabels" type="button" aria-pressed="true">Labels</button>
</nav>
<div class="panel compass" aria-hidden="true">N</div>
<aside class="panel legend" aria-label="Landscape legend">
<div class="legend-title">Landscape key</div>
<div class="legend-row"><i class="swatch" style="background:#347b8d"></i>Deep water</div>
<div class="legend-row"><i class="swatch" style="background:#78876a"></i>Shore / scrub</div>
<div class="legend-row"><i class="swatch" style="background:#78838a"></i>Mountain rock</div>
<div class="legend-row"><i class="swatch" style="background:#d97941"></i>Tunnel portal</div>
</aside>
<div class="panel hint">Drag to orbit · Scroll to zoom · Arrow keys to pan</div>
<div id="loading">Building fjord terrain…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd9dc);
scene.fog = new THREE.Fog(0xcbd9dc, 145, 255);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.2, 500);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe6f1f2, 0x48554e, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d5, 3.2);
sun.position.set(-48, 92, 58);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -75;
sun.shadow.camera.right = 75;
sun.shadow.camera.top = 75;
sun.shadow.camera.bottom = -75;
sun.shadow.camera.near = 10;
sun.shadow.camera.far = 220;
sun.shadow.bias = -0.00035;
scene.add(sun);
const terrainSize = 104;
const terrainHalf = terrainSize / 2;
const baseY = -8.2;
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smoothstep(a, b, x) {
const t = clamp((x - a) / (b - a), 0, 1);
return t * t * (3 - 2 * t);
}
function pointSegmentDistance(x, z, ax, az, bx, bz) {
const dx = bx - ax;
const dz = bz - az;
const lengthSq = dx * dx + dz * dz;
const t = lengthSq ? clamp(((x - ax) * dx + (z - az) * dz) / lengthSq, 0, 1) : 0;
const px = ax + dx * t;
const pz = az + dz * t;
return { distance: Math.hypot(x - px, z - pz), t };
}
const mainFjord = [
{ x: -7, z: 52 },
{ x: -6, z: 38 },
{ x: -5, z: 26 },
{ x: -3, z: 14 },
{ x: 0, z: 4 }
];
const westBranch = [
{ x: 0, z: 4 },
{ x: -8, z: -8 },
{ x: -18, z: -21 },
{ x: -25, z: -40 }
];
const eastBranch = [
{ x: 0, z: 4 },
{ x: 8, z: -8 },
{ x: 15, z: -21 },
{ x: 22, z: -41 }
];
function makeSegments(points, width) {
const segments = [];
for (let i = 0; i < points.length - 1; i++) {
segments.push({
a: points[i],
b: points[i + 1],
width
});
}
return segments;
}
const waterSegments = [
...makeSegments(mainFjord, 7.2),
...makeSegments(westBranch, 4.9),
...makeSegments(eastBranch, 4.5)
];
const settlementShelf = [
{ x: 4.4, z: 41, y: 0.85 },
{ x: 5.5, z: 34, y: 0.85 },
{ x: 6.8, z: 27, y: 0.85 },
{ x: 8.5, z: 20, y: 0.95 }
];
const tunnelRoad = [
{ x: 4.1, z: 41, y: 1.02 },
{ x: 5.1, z: 34, y: 1.00 },
{ x: 6.6, z: 27, y: 1.00 },
{ x: 8.8, z: 21, y: 1.08 },
{ x: 13.0, z: 14, y: 1.45 },
{ x: 18.0, z: 7, y: 2.35 },
{ x: 23.0, z: 1, y: 4.8 },
{ x: 27.0, z: -2, y: 8.0 }
];
function nearestOnPath(x, z, path) {
let best = { distance: Infinity, y: 0 };
for (let i = 0; i < path.length - 1; i++) {
const a = path[i];
const b = path[i + 1];
const hit = pointSegmentDistance(x, z, a.x, a.z, b.x, b.z);
if (hit.distance < best.distance) {
best.distance = hit.distance;
best.y = lerp(a.y, b.y, hit.t);
}
}
return best;
}
function nearestWater(x, z) {
let best = { distance: Infinity, width: 5 };
for (const segment of waterSegments) {
const hit = pointSegmentDistance(
x, z,
segment.a.x, segment.a.z,
segment.b.x, segment.b.z
);
if (hit.distance < best.distance) {
best.distance = hit.distance;
best.width = segment.width;
}
}
return best;
}
function terrainHeight(x, z) {
const water = nearestWater(x, z);
const q = water.distance - water.width;
let height;
if (q < 0) {
height = -6.1;
} else if (q < 2.15) {
height = -6.1 + 6.35 * smoothstep(0, 2.15, q);
} else {
const inland = q - 2.15;
const edgeRise = Math.max(0, Math.abs(x) - 27) * 0.62;
const rearRise = Math.max(0, -z - 39) * 0.62;
const foldedRock =
Math.sin(x * 0.13 + z * 0.055) * 1.3 +
Math.sin(z * 0.17 - x * 0.04) * 0.95 +
Math.sin((x + z) * 0.085) * 0.8;
height = 0.25 + Math.min(inland, 23) * 0.76;
height += edgeRise + rearRise + foldedRock;
height += Math.max(0, 1 - Math.abs(x) / 17) * 0.6;
}
const shelf = nearestOnPath(x, z, settlementShelf);
const shelfWeight = 1 - smoothstep(3.2, 8.0, shelf.distance);
height = lerp(height, shelf.y, shelfWeight * 0.94);
const road = nearestOnPath(x, z, tunnelRoad);
const roadWeight = 1 - smoothstep(2.15, 8.5, road.distance);
height = lerp(height, road.y + 0.06, roadWeight);
return height;
}
function terrainColor(height, variation) {
const color = new THREE.Color();
if (height < -0.5) {
color.setHex(0x294d53);
} else if (height < 1.15) {
color.setHex(0x9b9a7f);
} else if (height < 7.5) {
color.setHex(0x6f8067);
} else if (height < 14) {
color.setHex(0x65746a);
} else if (height < 22) {
color.setHex(0x737b7b);
} else {
color.setHex(0xa5aaa5);
}
color.multiplyScalar(variation);
return color;
}
function createTerrain() {
const nx = 72;
const nz = 72;
const positions = [];
const indices = [];
for (let j = 0; j <= nz; j++) {
const z = -terrainHalf + (j / nz) * terrainSize;
for (let i = 0; i <= nx; i++) {
const x = -terrainHalf + (i / nx) * terrainSize;
positions.push(x, terrainHeight(x, z), z);
}
}
for (let j = 0; j < nz; j++) {
for (let i = 0; i < nx; i++) {
const a = j * (nx + 1) + i;
const b = a + 1;
const c = a + nx + 1;
const d = c + 1;
if ((i + j) % 2 === 0) {
indices.push(a, c, b, b, c, d);
} else {
indices.push(a, c, d, a, d, b);
}
}
}
const indexed = new THREE.BufferGeometry();
indexed.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
indexed.setIndex(indices);
const geometry = indexed.toNonIndexed();
indexed.dispose();
const pos = geometry.getAttribute("position");
const colors = new Float32Array(pos.count * 3);
const color = new THREE.Color();
for (let i = 0; i < pos.count; i += 3) {
const h = (pos.getY(i) + pos.getY(i + 1) + pos.getY(i + 2)) / 3;
const variation = 0.87 + Math.random() * 0.24;
color.copy(terrainColor(h, variation));
for (let j = 0; j < 3; j++) {
colors[(i + j) * 3] = color.r;
colors[(i + j) * 3 + 1] = color.g;
colors[(i + j) * 3 + 2] = color.b;
}
}
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.98,
metalness: 0,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function createSkirt() {
const perimeter = [];
const samples = 72;
for (let i = 0; i <= samples; i++) {
perimeter.push([-terrainHalf + (i / samples) * terrainSize, terrainHalf]);
}
for (let i = 1; i <= samples; i++) {
perimeter.push([terrainHalf, terrainHalf - (i / samples) * terrainSize]);
}
for (let i = 1; i <= samples; i++) {
perimeter.push([terrainHalf - (i / samples) * terrainSize, -terrainHalf]);
}
for (let i = 1; i < samples; i++) {
perimeter.push([-terrainHalf, -terrainHalf + (i / samples) * terrainSize]);
}
const positions = [];
const colors = [];
for (let i = 0; i < perimeter.length - 1; i++) {
const [ax, az] = perimeter[i];
const [bx, bz] = perimeter[i + 1];
const ay = terrainHeight(ax, az);
const by = terrainHeight(bx, bz);
positions.push(
ax, ay, az,
bx, by, bz,
ax, baseY, az,
bx, by, bz,
bx, baseY, bz,
ax, baseY, az
);
const strata = [0x566267, 0x667074, 0x454f54];
for (let layer = 0; layer < 6; layer++) {
const c = new THREE.Color(strata[(layer + i) % strata.length]);
c.multiplyScalar(0.88 + Math.random() * 0.2);
colors.push(c.r, c.g, c.b);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
})
);
scene.add(mesh);
}
function createBase() {
const base = new THREE.Mesh(
new THREE.BoxGeometry(terrainSize + 0.5, 2.2, terrainSize + 0.5),
new THREE.MeshStandardMaterial({
color: 0x35474d,
roughness: 0.96,
flatShading: true
})
);
base.position.y = -9.25;
base.receiveShadow = true;
scene.add(base);
}
function createWater() {
const geometry = new THREE.PlaneGeometry(terrainSize - 0.15, terrainSize - 0.15, 1, 1);
geometry.rotateX(-Math.PI / 2);
const water = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0x347b8d,
roughness: 0.28,
metalness: 0.12,
transparent: true,
opacity: 0.94
})
);
water.position.y = 0.02;
water.receiveShadow = true;
scene.add(water);
const positions = [];
const count = 190;
for (let i = 0; i < count; i++) {
const x = (Math.random() - 0.5) * 94;
const z = (Math.random() - 0.5) * 94;
const near = nearestWater(x, z);
if (near.distance > near.width + 0.65) continue;
const length = 0.7 + Math.random() * 1.7;
const angle = Math.random() * Math.PI * 2;
const dx = Math.cos(angle) * length * 0.5;
const dz = Math.sin(angle) * length * 0.5;
const width = 0.035 + Math.random() * 0.055;
const nx = -Math.sin(angle) * width;
const nz = Math.cos(angle) * width;
const y = 0.055 + Math.random() * 0.018;
positions.push(
x - dx + nx, y, z - dz + nz,
x + dx + nx, y, z + dz + nz,
x - dx - nx, y, z - dz - nz,
x + dx + nx, y, z + dz + nz,
x + dx - nx, y, z + dz - nz,
x - dx - nx, y, z - dz - nz
);
}
const waveGeometry = new THREE.BufferGeometry();
waveGeometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
const waves = new THREE.Mesh(
waveGeometry,
new THREE.MeshBasicMaterial({
color: 0xc6e0df,
transparent: true,
opacity: 0.22,
depthWrite: false,
side: THREE.DoubleSide
})
);
scene.add(waves);
}
function createRibbon(path, width, material, lift = 0.04) {
const positions = [];
const indices = [];
for (let i = 0; i < path.length; i++) {
const previous = path[Math.max(0, i - 1)];
const next = path[Math.min(path.length - 1, i + 1)];
const dx = next.x - previous.x;
const dz = next.z - previous.z;
const length = Math.hypot(dx, dz) || 1;
const nx = -dz / length;
const nz = dx / length;
const point = path[i];
const y = point.y + lift;
positions.push(
point.x + nx * width * 0.5, y, point.z + nz * width * 0.5,
point.x - nx * width * 0.5, y, point.z - nz * width * 0.5
);
if (i < path.length - 1) {
const a = i * 2;
indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function createRoadAndQuay() {
const roadMaterial = new THREE.MeshStandardMaterial({
color: 0x4c5352,
roughness: 0.96,
side: THREE.DoubleSide
});
createRibbon(tunnelRoad, 1.75, roadMaterial);
const quay = [
{ x: 2.3, z: 40, y: 0.42 },
{ x: 2.4, z: 34, y: 0.42 },
{ x: 2.7, z: 28, y: 0.42 },
{ x: 3.0, z: 22, y: 0.42 }
];
createRibbon(
quay,
0.8,
new THREE.MeshStandardMaterial({
color: 0x777b72,
roughness: 0.94,
side: THREE.DoubleSide
}),
0.02
);
const markerGeometry = new THREE.BoxGeometry(0.11, 0.035, 0.5);
const markerMaterial = new THREE.MeshBasicMaterial({ color: 0xe8e1c7 });
for (let i = 2; i < tunnelRoad.length - 1; i++) {
const p = tunnelRoad[i];
const marker = new THREE.Mesh(markerGeometry, markerMaterial);
marker.position.set(p.x, p.y + 0.085, p.z);
marker.rotation.y = Math.atan2(
tunnelRoad[i + 1].x - tunnelRoad[i - 1].x,
tunnelRoad[i + 1].z - tunnelRoad[i - 1].z
);
scene.add(marker);
}
}
function createHouse(x, z, options = {}) {
const group = new THREE.Group();
const width = options.width ?? 2.1;
const depth = options.depth ?? 1.8;
const height = options.height ?? 1.75;
const roofHeight = options.roofHeight ?? 1.05;
const y = terrainHeight(x, z);
const bodyColors = [0xa94f3f, 0xd4ad55, 0xe4dfcf, 0x55707b, 0xb76642];
const roofColors = [0x37464a, 0x535b59, 0x6d3e35];
const bodyMaterial = new THREE.MeshStandardMaterial({
color: bodyColors[Math.floor(Math.random() * bodyColors.length)],
roughness: 0.88,
flatShading: true
});
const roofMaterial = new THREE.MeshStandardMaterial({
color: roofColors[Math.floor(Math.random() * roofColors.length)],
roughness: 0.95,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
bodyMaterial
);
body.position.y = height * 0.5;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const roofGeometry = new THREE.BufferGeometry();
const hw = width * 0.57;
const hd = depth * 0.58;
const rh = roofHeight;
roofGeometry.setAttribute("position", new THREE.Float32BufferAttribute([
-hw, 0, -hd,
hw, 0, -hd,
0, rh, -hd,
-hw, 0, hd,
hw, 0, hd,
0, rh, hd
], 3));
roofGeometry.setIndex([
0, 2, 1,
3, 4, 5,
0, 3, 5, 0, 5, 2,
1, 2, 5, 1, 5, 4
]);
roofGeometry.computeVertexNormals();
const roof = new THREE.Mesh(roofGeometry, roofMaterial);
roof.position.y = height;
roof.castShadow = true;
group.add(roof);
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0xffd58b,
emissive: 0xe7a84d,
emissiveIntensity: 0.55,
roughness: 0.45
});
for (const dz of [-depth * 0.23, depth * 0.23]) {
const window = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.42, 0.30),
windowMaterial
);
window.position.set(-width * 0.505, height * 0.57, dz);
group.add(window);
}
group.position.set(x, y, z);
group.rotation.y = options.rotation ?? (Math.random() - 0.5) * 0.35;
scene.add(group);
return group;
}
function createSettlement() {
const houses = [
[4.8, 38.2], [7.4, 36.8],
[4.7, 33.8], [7.5, 32.5],
[5.0, 29.2], [8.2, 28.1],
[5.3, 24.9], [8.4, 23.8],
[6.0, 21.1], [9.7, 20.0],
[9.4, 34.8], [10.3, 31.5],
[10.3, 27.2], [11.0, 24.0]
];
for (const [x, z] of houses) {
createHouse(x, z, {
width: 1.65 + Math.random() * 0.55,
depth: 1.45 + Math.random() * 0.45,
height: 1.35 + Math.random() * 0.65
});
}
const church = createHouse(10.6, 37.4, {
width: 2.4,
depth: 3.1,
height: 2.4,
roofHeight: 1.3,
rotation: 0.05
});
const tower = new THREE.Mesh(
new THREE.BoxGeometry(1.15, 3.2, 1.15),
new THREE.MeshStandardMaterial({
color: 0xe5dfcf,
roughness: 0.9,
flatShading: true
})
);
tower.position.set(0, 1.6, -0.55);
tower.castShadow = true;
church.add(tower);
const spire = new THREE.Mesh(
new THREE.ConeGeometry(0.87, 1.8, 4),
new THREE.MeshStandardMaterial({
color: 0x37464a,
roughness: 0.9,
flatShading: true
})
);
spire.position.set(0, 4.05, -0.55);
spire.rotation.y = Math.PI * 0.25;
spire.castShadow = true;
church.add(spire);
const plankMaterial = new THREE.MeshStandardMaterial({
color: 0x846a4d,
roughness: 1,
flatShading: true
});
for (const z of [35, 29.5, 23.8]) {
for (let i = 0; i < 6; i++) {
const plank = new THREE.Mesh(
new THREE.BoxGeometry(0.58, 0.12, 1.65),
plankMaterial
);
plank.position.set(2.6 - i * 0.58, 0.38, z);
plank.castShadow = true;
scene.add(plank);
}
for (const x of [2.35, 0.65]) {
for (const dz of [-0.62, 0.62]) {
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.11, 1.25, 5),
plankMaterial
);
post.position.set(x, 0.15, z + dz);
scene.add(post);
}
}
}
}
function createMound() {
const mound = new THREE.Mesh(
new THREE.DodecahedronGeometry(1, 0),
new THREE.MeshStandardMaterial({
color: 0x6d7777,
roughness: 1,
flatShading: true
})
);
mound.position.set(35.2, 11.5, -9.5);
mound.scale.set(12, 16, 12);
mound.rotation.set(0.12, 0.38, -0.08);
mound.castShadow = true;
mound.receiveShadow = true;
scene.add(mound);
const shoulder = new THREE.Mesh(
new THREE.DodecahedronGeometry(1, 0),
new THREE.MeshStandardMaterial({
color: 0x7b817a,
roughness: 1,
flatShading: true
})
);
shoulder.position.set(42, 8.5, -16);
shoulder.scale.set(9, 12, 10);
shoulder.castShadow = true;
scene.add(shoulder);
}
function createPortal() {
const portal = new THREE.Group();
portal.position.set(27, 8.05, -2);
portal.rotation.y = -0.927;
const darkShape = new THREE.Shape();
darkShape.moveTo(-2.58, 0);
darkShape.lineTo(2.58, 0);
darkShape.lineTo(2.58, 3.4);
darkShape.absarc(0, 3.4, 2.58, 0, Math.PI, false);
darkShape.lineTo(-2.58, 0);
const mouth = new THREE.Mesh(
new THREE.ShapeGeometry(darkShape, 10),
new THREE.MeshBasicMaterial({ color: 0x10191b, side: THREE.DoubleSide })
);
mouth.position.z = -0.08;
portal.add(mouth);
const concrete = new THREE.MeshStandardMaterial({
color: 0xb8b5a8,
roughness: 0.96,
flatShading: true
});
for (const x of [-3.18, 3.18]) {
const pillar = new THREE.Mesh(
new THREE.BoxGeometry(1.18, 3.55, 1.45),
concrete
);
pillar.position.set(x, 1.775, 0);
pillar.castShadow = true;
portal.add(pillar);
}
const arch = new THREE.Mesh(
new THREE.TorusGeometry(3.2, 0.62, 4, 12, Math.PI),
concrete
);
arch.position.set(0, 3.4, 0);
arch.castShadow = true;
portal.add(arch);
const retaining = new THREE.Mesh(
new THREE.BoxGeometry(7.2, 0.45, 2.1),
new THREE.MeshStandardMaterial({
color: 0x777b74,
roughness: 1,
flatShading: true
})
);
retaining.position.set(0, 0.12, -0.4);
retaining.receiveShadow = true;
portal.add(retaining);
const lampMaterial = new THREE.MeshStandardMaterial({
color: 0xffbb62,
emissive: 0xff8b32,
emissiveIntensity: 2.0,
roughness: 0.45
});
for (const x of [-2.95, 2.95]) {
const lamp = new THREE.Mesh(
new THREE.SphereGeometry(0.17, 6, 4),
lampMaterial
);
lamp.position.set(x, 2.25, 0.77);
portal.add(lamp);
const light = new THREE.PointLight(0xffa64d, 2.2, 7, 2);
light.position.set(x, 2.25, 1.0);
portal.add(light);
}
const signCanvas = document.createElement("canvas");
signCanvas.width = 512;
signCanvas.height = 128;
const context = signCanvas.getContext("2d");
context.fillStyle = "#d97941";
context.fillRect(0, 0, 512, 128);
context.fillStyle = "#26373c";
context.font = "800 42px sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText("FJORD TUNNEL", 256, 66);
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sign = new THREE.Mesh(
new THREE.BoxGeometry(4.8, 1.2, 0.18),
[
concrete, concrete, concrete, concrete,
new THREE.MeshStandardMaterial({ map: texture, roughness: 0.8 }),
concrete
]
);
sign.position.set(0, 7.15, 0.12);
sign.castShadow = true;
portal.add(sign);
scene.add(portal);
}
function createScatter() {
const rockMatrices = [];
const dummy = new THREE.Object3D();
for (let i = 0; i < 125; i++) {
const x = (Math.random() - 0.5) * 96;
const z = (Math.random() - 0.5) * 96;
const y = terrainHeight(x, z);
const road = nearestOnPath(x, z, tunnelRoad);
const shelf = nearestOnPath(x, z, settlementShelf);
if (y < 1.8 || road.distance < 4.5 || shelf.distance < 4.5) continue;
const scale = 0.45 + Math.random() * 1.7;
dummy.position.set(x, y + scale * 0.22, z);
dummy.rotation.set(Math.random() * 2, Math.random() * 6, Math.random() * 2);
dummy.scale.set(scale, scale * (0.55 + Math.random() * 0.65), scale);
dummy.updateMatrix();
rockMatrices.push(dummy.matrix.clone());
}
const rocks = new THREE.InstancedMesh(
new THREE.DodecahedronGeometry(1, 0),
new THREE.MeshStandardMaterial({
color: 0x727b79,
roughness: 1,
flatShading: true
}),
rockMatrices.length
);
rockMatrices.forEach((matrix, i) => rocks.setMatrixAt(i, matrix));
rocks.castShadow = true;
rocks.receiveShadow = true;
scene.add(rocks);
const treeMatrices = [];
for (let i = 0; i < 220; i++) {
const x = (Math.random() - 0.5) * 92;
const z = (Math.random() - 0.5) * 92;
const y = terrainHeight(x, z);
const road = nearestOnPath(x, z, tunnelRoad);
const shelf = nearestOnPath(x, z, settlementShelf);
if (y < 1.4 || y > 17 || road.distance < 6 || shelf.distance < 6) continue;
if (x > 20 && z < 8 && Math.random() > 0.18) continue;
const scale = 0.65 + Math.random() * 0.75;
dummy.position.set(x, y + 1.45 * scale, z);
dummy.rotation.set(0, Math.random() * Math.PI * 2, 0);
dummy.scale.set(scale, scale, scale);
dummy.updateMatrix();
treeMatrices.push(dummy.matrix.clone());
}
const trees = new THREE.InstancedMesh(
new THREE.ConeGeometry(1, 3.25, 5),
new THREE.MeshStandardMaterial({
color: 0x314f42,
roughness: 1,
flatShading: true
}),
treeMatrices.length
);
treeMatrices.forEach((matrix, i) => trees.setMatrixAt(i, matrix));
trees.castShadow = true;
scene.add(trees);
}
function createBoat() {
const boat = new THREE.Group();
const hull = new THREE.Mesh(
new THREE.ConeGeometry(1.05, 3.8, 4),
new THREE.MeshStandardMaterial({
color: 0xb84e3b,
roughness: 0.82,
flatShading: true
})
);
hull.rotation.x = Math.PI / 2;
hull.rotation.y = Math.PI / 4;
hull.scale.set(0.72, 1, 0.55);
hull.castShadow = true;
boat.add(hull);
const cabin = new THREE.Mesh(
new THREE.BoxGeometry(1.0, 0.65, 1.25),
new THREE.MeshStandardMaterial({
color: 0xe8dfc9,
roughness: 0.85,
flatShading: true
})
);
cabin.position.set(0, 0.55, 0.15);
cabin.castShadow = true;
boat.add(cabin);
const roof = new THREE.Mesh(
new THREE.BoxGeometry(1.15, 0.12, 1.4),
new THREE.MeshStandardMaterial({
color: 0x36505a,
roughness: 0.9,
flatShading: true
})
);
roof.position.set(0, 0.93, 0.15);
boat.add(roof);
scene.add(boat);
return boat;
}
createBase();
createTerrain();
createSkirt();
createWater();
createRoadAndQuay();
createSettlement();
createMound();
createPortal();
createScatter();
const boat = createBoat();
// Camera controls implemented directly without external controls modules.
const orbit = {
target: new THREE.Vector3(0, 3.5, 0),
radius: 145,
theta: -0.90,
phi: 0.96
};
function updateCamera() {
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 resetCamera() {
orbit.target.set(0, 3.5, 0);
orbit.radius = 145;
orbit.theta = -0.90;
orbit.phi = 0.96;
updateCamera();
}
updateCamera();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.theta -= dx * 0.005;
orbit.phi = clamp(orbit.phi + dy * 0.004, 0.35, 1.38);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
orbit.radius = clamp(orbit.radius * Math.exp(event.deltaY * 0.001), 62, 220);
updateCamera();
}, { passive: false });
addEventListener("keydown", (event) => {
const step = 3;
if (event.key === "ArrowLeft") orbit.target.x -= step;
if (event.key === "ArrowRight") orbit.target.x += step;
if (event.key === "ArrowUp") orbit.target.z -= step;
if (event.key === "ArrowDown") orbit.target.z += step;
if (event.key === "+" || event.key === "=") orbit.radius = clamp(orbit.radius - 5, 62, 220);
if (event.key === "-") orbit.radius = clamp(orbit.radius + 5, 62, 220);
updateCamera();
});
document.getElementById("reset").addEventListener("click", resetCamera);
// HTML labels projected from world-space anchor points.
const labelData = [
{
title: "Tunnel approach",
detail: "Schematic portal",
position: new THREE.Vector3(27, 16.5, -2)
},
{
title: "Settlement strip",
detail: "Constrained shoreline",
position: new THREE.Vector3(7.4, 6.2, 29)
},
{
title: "Deep channel",
detail: "Main fjord reach",
position: new THREE.Vector3(-4.8, 1.0, 21)
},
{
title: "Branch reach",
detail: "Secondary inlet",
position: new THREE.Vector3(13.5, 1.0, -18)
}
];
const labelElements = labelData.map((data) => {
const element = document.createElement("div");
element.className = "landmark";
element.innerHTML = `${data.title}<small>${data.detail}</small>`;
document.body.appendChild(element);
return element;
});
let labelsVisible = true;
const labelToggle = document.getElementById("toggleLabels");
labelToggle.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelToggle.setAttribute("aria-pressed", String(labelsVisible));
});
function updateLabels() {
labelData.forEach((data, index) => {
const projected = data.position.clone().project(camera);
const visible =
labelsVisible &&
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.1 &&
Math.abs(projected.y) < 1.1;
const element = labelElements[index];
element.classList.toggle("hidden", !visible);
if (visible) {
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
});
}
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const progress = (elapsed * 0.013) % 1;
const segment = Math.min(3, Math.floor(progress * 4));
const local = progress * 4 - segment;
const a = mainFjord[segment];
const b = mainFjord[segment + 1];
const x = lerp(a.x, b.x, local);
const z = lerp(a.z, b.z, local);
boat.position.set(x, 0.25, z);
boat.rotation.y = Math.atan2(b.x - a.x, b.z - a.z) - Math.PI / 2;
boat.rotation.z = Math.sin(elapsed * 1.2) * 0.018;
boat.rotation.x = Math.cos(elapsed * 0.9) * 0.012;
updateLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.style.opacity = "0";
setTimeout(() => loading.remove(), 420);
}
}
animate();
</script>
</body>
</html>
```