Prompt specification
Build or customize the Three.js 3D scene "Canal cross-section and small steamship" 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: Canal cross-section and small steamship
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/canal-cross-section-and-small-steamship-x2477
Scene Description Prompt:
A stylized Suez Canal cutaway with a nineteenth-century steamship, showing bank spacing and vessel clearance using schematic dimensions. Three.js from cdnjs, one HTML file.
Working Three.js Starter (canal-cross-section-and-small-steamship-x2477):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Suez Canal — Nineteenth-Century Engineering Cutaway</title>
<style>
:root {
--ink: #18333c;
--muted: #60777d;
--paper: #f5f1e7;
--amber: #d88925;
--amber-dark: #9c5714;
--blue: #247e98;
--panel: rgba(249, 247, 239, 0.88);
--line: rgba(24, 51, 60, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e7;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
#app,
#app canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
touch-action: none;
outline: none;
}
.heading {
position: absolute;
z-index: 10;
top: 26px;
left: 30px;
max-width: 490px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}
.eyebrow {
margin-bottom: 7px;
color: var(--amber-dark);
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 3.4vw, 52px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 0.98;
}
.subtitle {
margin: 12px 0 0;
max-width: 440px;
color: #4f6870;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
line-height: 1.55;
}
.view-panel {
position: absolute;
z-index: 20;
top: 26px;
right: 28px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 10px 32px rgba(31, 57, 63, 0.12);
backdrop-filter: blur(12px);
}
.view-panel .panel-title {
padding: 2px 4px 8px;
color: var(--muted);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.view-buttons {
display: flex;
gap: 5px;
}
.view-buttons button {
appearance: none;
border: 1px solid rgba(24, 51, 60, 0.14);
border-radius: 7px;
padding: 8px 10px;
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
cursor: pointer;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: 700;
transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}
.view-buttons button:hover,
.view-buttons button.active {
background: var(--ink);
color: #fffdf7;
}
.view-buttons button:active {
transform: translateY(1px);
}
.legend {
position: absolute;
z-index: 10;
left: 30px;
bottom: 28px;
width: 245px;
padding: 15px 17px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 10px 32px rgba(31, 57, 63, 0.1);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-title {
margin-bottom: 10px;
color: var(--muted);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin: 8px 0;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
color: #425c64;
}
.swatch {
width: 23px;
height: 9px;
flex: 0 0 auto;
border-radius: 2px;
}
.swatch.water {
background: #4d9fb1;
}
.swatch.hull {
background: #23343b;
}
.swatch.clearance {
border: 1px dashed var(--amber);
background: rgba(216, 137, 37, 0.08);
}
.swatch.strata {
background: linear-gradient(
to bottom,
#d9bb7d 0 33%,
#b88758 33% 66%,
#796552 66% 100%
);
}
.controls-hint {
position: absolute;
z-index: 10;
right: 29px;
bottom: 29px;
color: rgba(24, 51, 60, 0.72);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
line-height: 1.7;
text-align: right;
pointer-events: none;
}
.controls-hint strong {
color: var(--ink);
}
.caption {
position: absolute;
z-index: 9;
left: 50%;
bottom: 29px;
transform: translateX(-50%);
padding: 7px 12px;
border-radius: 999px;
background: rgba(250, 248, 241, 0.76);
color: #5b6f75;
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
}
.north {
position: absolute;
z-index: 10;
right: 31px;
top: 112px;
display: grid;
place-items: center;
width: 44px;
height: 64px;
color: var(--ink);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
pointer-events: none;
}
.north-arrow {
position: relative;
width: 2px;
height: 39px;
margin-top: 4px;
background: var(--ink);
}
.north-arrow::before {
content: "";
position: absolute;
top: -1px;
left: 50%;
width: 10px;
height: 10px;
transform: translateX(-50%) rotate(45deg);
border-top: 2px solid var(--ink);
border-left: 2px solid var(--ink);
background: #f4f1e8;
}
.world-label {
position: absolute;
z-index: 8;
top: 0;
left: 0;
pointer-events: none;
will-change: transform, opacity;
}
.dim-label {
min-width: 116px;
padding: 8px 10px 7px;
border: 1px solid rgba(156, 87, 20, 0.3);
border-radius: 7px;
background: rgba(255, 250, 237, 0.94);
box-shadow: 0 5px 16px rgba(63, 48, 25, 0.13);
text-align: center;
transform-origin: center;
}
.dim-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 11px;
background: var(--amber);
}
.dim-label b,
.ship-label b,
.flow-label b {
display: block;
color: var(--amber-dark);
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.dim-label span,
.ship-label span,
.flow-label span {
display: block;
margin-top: 2px;
color: #60777d;
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
letter-spacing: 0.03em;
}
.ship-label {
min-width: 165px;
padding: 8px 11px;
border-left: 3px solid var(--ink);
border-radius: 3px;
background: rgba(248, 246, 238, 0.91);
box-shadow: 0 5px 18px rgba(31, 57, 63, 0.12);
text-align: left;
}
.ship-label b {
color: var(--ink);
}
.geo-label {
padding: 3px 7px;
border-radius: 4px;
background: rgba(248, 245, 235, 0.86);
color: #4f5e60;
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
letter-spacing: 0.04em;
white-space: nowrap;
transform: translate(-50%, -50%);
}
.flow-label {
padding: 5px 8px;
border-radius: 4px;
background: rgba(234, 247, 248, 0.88);
color: #23758b;
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
letter-spacing: 0.06em;
text-align: center;
text-transform: uppercase;
}
@media (max-width: 760px) {
.heading {
top: 18px;
left: 18px;
max-width: 55vw;
}
h1 {
font-size: 30px;
}
.subtitle {
display: none;
}
.view-panel {
top: 16px;
right: 16px;
}
.view-buttons {
flex-direction: column;
}
.legend {
left: 16px;
bottom: 16px;
width: 202px;
}
.caption,
.controls-hint,
.north {
display: none;
}
.dim-label {
min-width: 94px;
padding: 6px 8px;
}
.dim-label b,
.ship-label b,
.flow-label b {
font-size: 10px;
}
.dim-label span,
.ship-label span,
.flow-label span {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<header class="heading">
<div class="eyebrow">Engineering illustration · 1869</div>
<h1>Suez Canal<br />Cutaway</h1>
<p class="subtitle">
A schematic study of a nineteenth-century screw steamer within the
engineered channel, showing bank spacing and practical side clearance.
</p>
</header>
<nav class="view-panel" aria-label="Camera views">
<div class="panel-title">Camera views</div>
<div class="view-buttons">
<button class="active" data-view="overview">Overview</button>
<button data-view="plan">Plan</button>
<button data-view="cutaway">Cutaway</button>
</div>
</nav>
<aside class="legend">
<div class="legend-title">Schematic key</div>
<div class="legend-row">
<span class="swatch water"></span>
<span>Canal waterway</span>
</div>
<div class="legend-row">
<span class="swatch hull"></span>
<span>Nineteenth-century steamer</span>
</div>
<div class="legend-row">
<span class="swatch clearance"></span>
<span>Side-clearance envelope</span>
</div>
<div class="legend-row">
<span class="swatch strata"></span>
<span>Exposed canal strata</span>
</div>
</aside>
<div class="north" aria-hidden="true">
N
<span class="north-arrow"></span>
</div>
<div class="controls-hint">
<strong>Drag</strong> orbit · <strong>Shift/right-drag</strong> pan<br />
<strong>Wheel/pinch</strong> zoom · <strong>1–3</strong> views
</div>
<div class="caption">Illustrative section · widths enlarged for legibility · not for navigation</div>
<div id="dim-width" class="world-label dim-label">
<b>160 m</b>
<span>nominal channel width</span>
</div>
<div id="dim-beam" class="world-label dim-label">
<b>12 m</b>
<span>vessel beam</span>
</div>
<div id="dim-clearance" class="world-label dim-label">
<b>74 m</b>
<span>clearance each side</span>
</div>
<div id="ship-label" class="world-label ship-label">
<b>1869 screw steamer</b>
<span>Two funnels · iron hull · twin masts</span>
</div>
<div id="flow-label" class="world-label flow-label">
<b>Mediterranean</b>
<span>to Red Sea</span>
</div>
<div id="geo-sand" class="world-label geo-label">Sand & gravel</div>
<div id="geo-clay" class="world-label geo-label">Compact clay</div>
<div id="geo-rock" class="world-label geo-label">Rock foundation</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.getElementById("app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e7);
scene.fog = new THREE.Fog(0xdce8e7, 820, 1500);
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.08;
container.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.5,
2200
);
const clock = new THREE.Clock();
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const materials = {
foundation: new THREE.MeshStandardMaterial({
color: 0x76634f,
roughness: 0.98
}),
clay: new THREE.MeshStandardMaterial({
color: 0xb27e50,
roughness: 1
}),
sand: new THREE.MeshStandardMaterial({
color: 0xd8b878,
roughness: 0.95
}),
surface: new THREE.MeshStandardMaterial({
color: 0xc8aa72,
roughness: 1
}),
bed: new THREE.MeshStandardMaterial({
color: 0x486d68,
roughness: 1
}),
water: new THREE.MeshStandardMaterial({
color: 0x318da5,
transparent: true,
opacity: 0.43,
roughness: 0.32,
metalness: 0.02,
depthWrite: false
}),
waterTop: new THREE.MeshStandardMaterial({
color: 0x5aa9b8,
transparent: true,
opacity: 0.38,
roughness: 0.28,
depthWrite: false
}),
stone: new THREE.MeshStandardMaterial({
color: 0xa99a7d,
roughness: 0.96
}),
stoneDark: new THREE.MeshStandardMaterial({
color: 0x887c66,
roughness: 0.98
}),
hull: new THREE.MeshStandardMaterial({
color: 0x203039,
roughness: 0.58,
metalness: 0.18,
side: THREE.DoubleSide
}),
hullRed: new THREE.MeshStandardMaterial({
color: 0x8f3e32,
roughness: 0.64,
metalness: 0.08,
side: THREE.DoubleSide
}),
deck: new THREE.MeshStandardMaterial({
color: 0xb89b64,
roughness: 0.82
}),
cream: new THREE.MeshStandardMaterial({
color: 0xe3d4aa,
roughness: 0.7
}),
funnel: new THREE.MeshStandardMaterial({
color: 0xb66e3f,
roughness: 0.67
}),
black: new THREE.MeshStandardMaterial({
color: 0x172126,
roughness: 0.7
}),
brass: new THREE.MeshStandardMaterial({
color: 0xb48a3c,
roughness: 0.38,
metalness: 0.65
}),
glass: new THREE.MeshStandardMaterial({
color: 0x294d57,
roughness: 0.22,
metalness: 0.32
}),
flag: new THREE.MeshStandardMaterial({
color: 0xb74635,
side: THREE.DoubleSide,
roughness: 0.8
})
};
function mesh(geometry, material, position, castShadow = true, receiveShadow = true) {
const object = new THREE.Mesh(geometry, material);
if (position) object.position.set(...position);
object.castShadow = castShadow;
object.receiveShadow = receiveShadow;
scene.add(object);
return object;
}
function cylinderBetween(a, b, radius, material, radialSegments = 10) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const object = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
object.position.copy(start).add(end).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
object.castShadow = true;
object.receiveShadow = true;
scene.add(object);
return object;
}
function lineFromPoints(points, color, opacity = 1, dashed = false) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((p) => new THREE.Vector3(...p))
);
const material = dashed
? new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize: 8,
gapSize: 6
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
const line = new THREE.Line(geometry, material);
if (dashed) line.computeLineDistances();
scene.add(line);
return line;
}
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(
new THREE.HemisphereLight(0xf5f2df, 0x6e6252, 2.25)
);
const sun = new THREE.DirectionalLight(0xfff2d2, 3.4);
sun.position.set(-280, 430, 240);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -440;
sun.shadow.camera.right = 440;
sun.shadow.camera.top = 440;
sun.shadow.camera.bottom = -440;
sun.shadow.camera.near = 20;
sun.shadow.camera.far = 1100;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8dbe2, 1.0);
fill.position.set(260, 180, -330);
scene.add(fill);
// ------------------------------------------------------------
// Terrain and cutaway strata
// ------------------------------------------------------------
const CANAL_WIDTH = 160;
const BANK_WIDTH = 180;
const CANAL_LENGTH = 620;
const HALF_CHANNEL = CANAL_WIDTH / 2;
const HALF_LENGTH = CANAL_LENGTH / 2;
const baseGround = mesh(
new THREE.PlaneGeometry(1400, 1000),
new THREE.MeshStandardMaterial({
color: 0xb9a981,
roughness: 1
}),
[0, -14.25, 0],
false,
true
);
baseGround.rotation.x = -Math.PI / 2;
const strata = [
{ bottom: -14, top: -7, material: materials.foundation },
{ bottom: -7, top: 1, material: materials.clay },
{ bottom: 1, top: 9, material: materials.sand },
{ bottom: 9, top: 12, material: materials.surface }
];
for (const side of [-1, 1]) {
const centerX = side * (HALF_CHANNEL + BANK_WIDTH / 2);
for (const layer of strata) {
const height = layer.top - layer.bottom;
mesh(
new THREE.BoxGeometry(BANK_WIDTH, height, CANAL_LENGTH),
layer.material,
[centerX, (layer.bottom + layer.top) / 2, 0]
);
}
// Segmented masonry revetment along the canal-facing bank.
for (let z = -HALF_LENGTH + 10; z < HALF_LENGTH; z += 20) {
mesh(
new THREE.BoxGeometry(1.7, 12, 18.3),
Math.round(z / 20) % 2 === 0
? materials.stone
: materials.stoneDark,
[side * (HALF_CHANNEL + 0.55), 0, z]
);
}
// Low desert outcrops on the upper bank.
let seed = side > 0 ? 8 : 19;
const random = () => {
seed = (seed * 9301 + 49297) % 233280;
return seed / 233280;
};
for (let i = 0; i < 7; i++) {
const rock = mesh(
new THREE.IcosahedronGeometry(1, 1),
materials.surface,
[
side * (145 + random() * 95),
12.2,
-260 + random() * 520
]
);
rock.scale.set(
8 + random() * 16,
2 + random() * 4,
7 + random() * 14
);
rock.rotation.y = random() * Math.PI;
}
}
// Canal bed and water volume.
mesh(
new THREE.BoxGeometry(CANAL_WIDTH - 2, 2, CANAL_LENGTH),
materials.bed,
[0, -8, 0],
false,
true
);
const waterVolume = mesh(
new THREE.BoxGeometry(CANAL_WIDTH - 2, 13, CANAL_LENGTH - 2),
materials.water,
[0, -6.45, 0],
false,
false
);
waterVolume.renderOrder = 1;
const waterSurface = mesh(
new THREE.PlaneGeometry(CANAL_WIDTH - 2, CANAL_LENGTH - 2),
materials.waterTop,
[0, 0.12, 0],
false,
false
);
waterSurface.rotation.x = -Math.PI / 2;
waterSurface.renderOrder = 2;
// Fine water marks.
for (let i = 0; i < 28; i++) {
const x = -68 + (i * 29.7) % 136;
const z = -285 + (i * 83) % 570;
const length = 8 + (i % 5) * 3;
lineFromPoints(
[
[x - length / 2, 0.28, z],
[x, 0.31, z + 0.7],
[x + length / 2, 0.28, z]
],
0xd9f4f4,
0.28
);
}
// Directional chevrons.
for (const x of [-48, 48]) {
for (const z of [-245, -130, -15, 100, 215]) {
lineFromPoints(
[
[x - 3.2, 0.38, z - 3],
[x, 0.4, z + 1],
[x + 3.2, 0.38, z - 3]
],
0xc5edf1,
0.72
);
}
}
// ------------------------------------------------------------
// Nineteenth-century screw steamer
// ------------------------------------------------------------
function createHullGeometry(stations, levels) {
const positions = [];
const point = (station, level, side) => {
const halfWidth = (BEAM / 2) * station.width;
const [y, factor] = levels[level];
return [
side * halfWidth * factor,
y,
station.z
];
};
const quad = (a, b, c, d) => {
positions.push(...a, ...b, ...c, ...a, ...c, ...d);
};
for (let s = 0; s < stations.length - 1; s++) {
const a = stations[s];
const b = stations[s + 1];
for (let l = 0; l < levels.length - 1; l++) {
const al = point(a, l, -1);
const ar = point(a, l, 1);
const bl = point(b, l, -1);
const br = point(b, l, 1);
const alNext = point(a, l + 1, -1);
const arNext = point(a, l + 1, 1);
const blNext = point(b, l + 1, -1);
const brNext = point(b, l + 1, 1);
quad(al, bl, blNext, alNext);
quad(ar, arNext, brNext, br);
// Bottom and top closure between stations.
if (l === 0) {
quad(al, ar, br, bl);
}
if (l === levels.length - 2) {
quad(alNext, blNext, brNext, arNext);
}
}
}
// Bow and stern caps.
for (const station of [stations[0], stations[stations.length - 1]]) {
for (let l = 0; l < levels.length - 1; l++) {
const left0 = point(station, l, -1);
const right0 = point(station, l, 1);
const left1 = point(station, l + 1, -1);
const right1 = point(station, l + 1, 1);
quad(left0, right0, right1, left1);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
return geometry;
}
const BEAM = 12;
const stations = [
{ z: -44, width: 0.76 },
{ z: -39, width: 0.98 },
{ z: -24, width: 1.0 },
{ z: 28, width: 1.0 },
{ z: 39, width: 0.72 },
{ z: 45, width: 0.08 }
];
const lowerHull = mesh(
createHullGeometry(
stations,
[
[-4, 0.42],
[-0.2, 0.82],
[0.8, 0.86]
]
),
materials.hullRed
);
const upperHull = mesh(
createHullGeometry(
stations,
[
[0.8, 0.86],
[3.7, 1.0],
[4.5, 0.97]
]
),
materials.hull
);
// Main deck.
mesh(
new THREE.BoxGeometry(11.4, 0.55, 76),
materials.deck,
[0, 4.65, -2]
);
// Bulwark rails.
for (const side of [-1, 1]) {
const railPoints = [];
for (let z = -36; z <= 34; z += 5.5) {
railPoints.push([side * 5.45, 4.95, z]);
railPoints.push([side * 5.45, 6.0, z]);
}
lineFromPoints(railPoints, 0xd7c69c, 0.85);
lineFromPoints(
[
[side * 5.45, 6.0, -36],
[side * 5.45, 6.0, 34]
],
0xd7c69c,
0.85
);
}
// Deckhouses.
mesh(
new THREE.BoxGeometry(8.4, 3.2, 28),
materials.cream,
[0, 6.55, -7]
);
mesh(
new THREE.BoxGeometry(6.4, 2.8, 10),
materials.cream,
[0, 9.45, -12]
);
mesh(
new THREE.BoxGeometry(7.1, 0.45, 11),
materials.black,
[0, 11.0, -12]
);
// Bridge windows.
for (const side of [-1, 1]) {
for (let z = -15.2; z <= -9; z += 2.05) {
mesh(
new THREE.BoxGeometry(0.16, 1.2, 1.25),
materials.glass,
[side * 3.25, 9.65, z],
false,
false
);
}
}
mesh(
new THREE.BoxGeometry(5.2, 1.15, 0.16),
materials.glass,
[0, 9.65, -16.85],
false,
false
);
// Deckhouse windows.
for (const side of [-1, 1]) {
for (let z = -18; z <= 2; z += 3.3) {
mesh(
new THREE.BoxGeometry(0.13, 1.0, 1.35),
materials.glass,
[side * 4.25, 6.7, z],
false,
false
);
}
}
// Twin funnels.
const funnelPositions = [
[0, 4.9, 2],
[0, 4.9, 16]
];
for (const [x, y, z] of funnelPositions) {
mesh(
new THREE.CylinderGeometry(2.05, 2.25, 8.4, 18),
materials.funnel,
[x, y + 4.2, z]
);
mesh(
new THREE.CylinderGeometry(2.17, 2.17, 1.25, 18),
materials.black,
[x, y + 8.5, z]
);
mesh(
new THREE.TorusGeometry(2.12, 0.12, 6, 20),
materials.brass,
[x, y + 8.1, z]
).rotation.x = Math.PI / 2;
}
// Masts, yards, bowsprit and rigging.
cylinderBetween([0, 4.8, -29], [0, 21, -29], 0.28, materials.deck);
cylinderBetween([0, 4.8, 31], [0, 19.5, 31], 0.25, materials.deck);
cylinderBetween([0, 5.1, 40], [0, 9.1, 57], 0.28, materials.deck);
cylinderBetween([-7, 16.5, -29], [7, 16.5, -29], 0.18, materials.deck);
cylinderBetween([-6.5, 15.7, 31], [6.5, 15.7, 31], 0.16, materials.deck);
const riggingMaterial = new THREE.LineBasicMaterial({
color: 0x3d4140,
transparent: true,
opacity: 0.8
});
function addRigging(points) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((p) => new THREE.Vector3(...p))
);
scene.add(new THREE.Line(geometry, riggingMaterial));
}
addRigging([[0, 21, -29], [0, 5, -43]]);
addRigging([[0, 21, -29], [0, 6, -5]]);
addRigging([[0, 21, -29], [-5.5, 6, -29]]);
addRigging([[0, 21, -29], [5.5, 6, -29]]);
addRigging([[0, 19.5, 31], [0, 6.1, 43]]);
addRigging([[0, 19.5, 31], [0, 9, 57]]);
addRigging([[0, 19.5, 31], [-5, 5.5, 31]]);
addRigging([[0, 19.5, 31], [5, 5.5, 31]]);
// Flags.
function addFlag(x, y, z) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0, 0, 0,
7, -1.1, 0,
0, -2.3, 0
],
3
)
);
geometry.computeVertexNormals();
const flag = new THREE.Mesh(geometry, materials.flag);
flag.position.set(x, y, z);
flag.castShadow = true;
scene.add(flag);
}
addFlag(0.1, 20.4, -29);
addFlag(0.1, 19, 31);
// Ship's boat.
const boat = mesh(
new THREE.SphereGeometry(1, 14, 8),
materials.deck,
[4.7, 6.2, 24]
);
boat.scale.set(1.2, 0.65, 4.2);
// ------------------------------------------------------------
// Navigation beacons
// ------------------------------------------------------------
function addBeacon(x, z) {
const group = new THREE.Group();
group.position.set(x, 12, z);
const tower = new THREE.Mesh(
new THREE.CylinderGeometry(1.7, 2.4, 12, 10),
materials.cream
);
tower.position.y = 6;
tower.castShadow = true;
tower.receiveShadow = true;
group.add(tower);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(3.1, 3.1, 0.7, 12),
materials.stone
);
platform.position.y = 12;
platform.castShadow = true;
group.add(platform);
const lantern = new THREE.Mesh(
new THREE.CylinderGeometry(1.25, 1.25, 2.5, 8),
materials.glass
);
lantern.position.y = 13.65;
group.add(lantern);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(2.2, 1.7, 8),
materials.black
);
roof.position.y = 15.7;
roof.castShadow = true;
group.add(roof);
scene.add(group);
}
addBeacon(-99, 205);
addBeacon(99, -115);
addBeacon(-99, -275);
// ------------------------------------------------------------
// Schematic dimensions and clearance guides
// ------------------------------------------------------------
const dimensionColor = 0xd88925;
function addHorizontalDimension(x1, x2, y, z, tickSize = 7) {
lineFromPoints(
[
[x1, y, z],
[x2, y, z]
],
dimensionColor,
0.95
);
for (const x of [x1, x2]) {
lineFromPoints(
[
[x, y, z - tickSize],
[x, y, z + tickSize]
],
dimensionColor,
0.95
);
}
}
addHorizontalDimension(-80, 80, 18.5, -195, 10);
addHorizontalDimension(-6, 6, 9.2, 20, 5);
addHorizontalDimension(6, 80, 8.3, 70, 6);
// Dashed envelope showing the available channel around the vessel.
lineFromPoints(
[
[-80, 7.4, 70],
[-6, 7.4, 70]
],
dimensionColor,
0.62,
true
);
lineFromPoints(
[
[6, 7.4, 70],
[80, 7.4, 70]
],
dimensionColor,
0.62,
true
);
lineFromPoints(
[
[-80, 7.4, 70],
[80, 7.4, 70]
],
dimensionColor,
0.28,
true
);
// Small reference stakes at the dimension endpoints.
for (const x of [-80, 80]) {
cylinderBetween(
[x, 12, -195],
[x, 18.5, -195],
0.25,
materials.brass,
8
);
}
// ------------------------------------------------------------
// Steam puffs
// ------------------------------------------------------------
const smokePuffs = [];
for (const [, , funnelZ] of funnelPositions) {
for (let i = 0; i < 6; i++) {
const puffMaterial = new THREE.MeshStandardMaterial({
color: 0xd9d8cd,
transparent: true,
opacity: 0.15,
roughness: 1,
depthWrite: false
});
const puff = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 1),
puffMaterial
);
puff.castShadow = false;
scene.add(puff);
smokePuffs.push({
mesh: puff,
originZ: funnelZ,
phase: i / 6,
drift: i % 2 === 0 ? 1 : -1
});
}
}
// ------------------------------------------------------------
// HTML labels projected from world positions
// ------------------------------------------------------------
const labels = [
{
element: document.getElementById("dim-width"),
position: new THREE.Vector3(0, 19, -195),
offset: new THREE.Vector2(0, -4)
},
{
element: document.getElementById("dim-beam"),
position: new THREE.Vector3(0, 10, 20),
offset: new THREE.Vector2(0, -10)
},
{
element: document.getElementById("dim-clearance"),
position: new THREE.Vector3(43, 9, 70),
offset: new THREE.Vector2(0, 12)
},
{
element: document.getElementById("ship-label"),
position: new THREE.Vector3(0, 23, -5),
offset: new THREE.Vector2(0, -4)
},
{
element: document.getElementById("flow-label"),
position: new THREE.Vector3(48, 2, -237),
offset: new THREE.Vector2(0, 0)
},
{
element: document.getElementById("geo-sand"),
position: new THREE.Vector3(169, 5.5, 311),
offset: new THREE.Vector2(58, 0)
},
{
element: document.getElementById("geo-clay"),
position: new THREE.Vector3(169, -3, 311),
offset: new THREE.Vector2(58, 0)
},
{
element: document.getElementById("geo-rock"),
position: new THREE.Vector3(169, -10.5, 311),
offset: new THREE.Vector2(58, 0)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
label.element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * width + label.offset.x;
const y = (-projected.y * 0.5 + 0.5) * height + label.offset.y;
label.element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -50%)`;
}
}
// ------------------------------------------------------------
// Custom camera controls
// ------------------------------------------------------------
const cameraState = {
theta: 0.72,
phi: 1.02,
radius: 760,
target: new THREE.Vector3(0, 0, 0)
};
let viewTween = null;
const presets = {
overview: {
theta: 0.72,
phi: 1.02,
radius: 760,
target: new THREE.Vector3(0, 0, 0)
},
plan: {
theta: 0.02,
phi: 0.07,
radius: 860,
target: new THREE.Vector3(0, 0, 0)
},
cutaway: {
theta: 1.18,
phi: 1.14,
radius: 515,
target: new THREE.Vector3(0, 0, 105)
}
};
function shortestAngleDifference(a, b) {
return Math.atan2(Math.sin(b - a), Math.cos(b - a));
}
function setView(name) {
const preset = presets[name];
if (!preset) return;
viewTween = {
start: performance.now(),
duration: 950,
from: {
theta: cameraState.theta,
phi: cameraState.phi,
radius: cameraState.radius,
target: cameraState.target.clone()
},
to: {
theta:
cameraState.theta +
shortestAngleDifference(cameraState.theta, preset.theta),
phi: preset.phi,
radius: preset.radius,
target: preset.target.clone()
}
};
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
function applyCamera() {
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(spherical).add(cameraState.target);
camera.lookAt(cameraState.target);
}
const pointers = new Map();
let dragMode = "orbit";
let previousPinchDistance = 0;
const canvas = renderer.domElement;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
viewTween = null;
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragMode =
event.shiftKey || event.altKey || event.button === 2
? "pan"
: "orbit";
}
if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (previousPinchDistance / distance),
230,
1250
);
}
previousPinchDistance = distance;
return;
}
if (dragMode === "orbit") {
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0045,
0.055,
1.48
);
} else {
const scale = cameraState.radius * 0.00145;
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(
camera.quaternion
);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(
camera.quaternion
);
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(up, dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-250,
250
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-300,
300
);
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointers.size === 2 ? pointerDistance() : 0;
if (pointers.size === 0) dragMode = "orbit";
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
viewTween = null;
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
230,
1250
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => setView("overview"));
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
window.addEventListener("keydown", (event) => {
if (event.key === "1") setView("overview");
if (event.key === "2") setView("plan");
if (event.key === "3") setView("cutaway");
if (event.key.toLowerCase() === "r") setView("overview");
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
function easeInOutCubic(t) {
return t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (viewTween) {
const raw = Math.min(
(performance.now() - viewTween.start) / viewTween.duration,
1
);
const t = easeInOutCubic(raw);
cameraState.theta = THREE.MathUtils.lerp(
viewTween.from.theta,
viewTween.to.theta,
t
);
cameraState.phi = THREE.MathUtils.lerp(
viewTween.from.phi,
viewTween.to.phi,
t
);
cameraState.radius = THREE.MathUtils.lerp(
viewTween.from.radius,
viewTween.to.radius,
t
);
cameraState.target.lerpVectors(
viewTween.from.target,
viewTween.to.target,
t
);
if (raw >= 1) viewTween = null;
}
for (const puff of smokePuffs) {
const life = (elapsed * 0.095 + puff.phase) % 1;
puff.mesh.position.set(
Math.sin(life * 5 + puff.phase * 8) * life * 4.2,
14.2 + life * 27,
puff.originZ - life * 7
);
const scale = 0.8 + life * 3.4;
puff.mesh.scale.set(scale, scale * 0.82, scale);
puff.mesh.material.opacity = Math.pow(1 - life, 1.7) * 0.19;
}
applyCamera();
updateLabels();
renderer.render(scene, camera);
}
applyCamera();
animate();
</script>
</body>
</html>
```