Prompt specification
Build or customize the Three.js 3D scene "Archipelago supply route scene" 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: Archipelago supply route scene
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/archipelago-supply-route-scene-x1307
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring islands, straits, and access routes. Arrange five islands with harbors, shallow areas, and marked shipping lanes. Show one supply boat visiting accessible ports while respecting shallow-water exclusions in the simplified model. Low-poly.
Working Three.js Starter (archipelago-supply-route-scene-x1307):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Archipelago Freight — Supply Route Planner</title>
<style>
:root{
--ink:#e7f4fb; --dim:#9fc0d4; --line:rgba(120,200,220,.22);
--panel:rgba(7,22,33,.80); --accent:#5fe3c8; --warn:#ffb454; --bad:#ff6b6b;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:#05121c;
font-family:ui-sans-serif,system-ui,"Segoe UI",Roboto,sans-serif;color:var(--ink)}
canvas{display:block;width:100%;height:100%;touch-action:none}
.panel,#status,#controls,#hint{position:fixed;z-index:5}
.panel{top:14px;left:14px;width:290px;max-height:calc(100% - 28px);overflow:auto;
background:var(--panel);backdrop-filter:blur(7px);border:1px solid var(--line);
border-radius:12px;padding:14px 15px;font-size:12.5px;line-height:1.45}
.panel h1{margin:0;font-size:16px;letter-spacing:.4px}
.panel h2{margin:14px 0 6px;font-size:11px;letter-spacing:1.4px;text-transform:uppercase;color:var(--dim)}
.sub{margin:3px 0 11px;color:var(--dim);font-size:11.5px}
.legend div{display:flex;align-items:center;gap:8px;margin:4px 0;color:var(--dim)}
.sw{width:15px;height:9px;border-radius:3px;flex:0 0 auto}
.sw.dash{background:repeating-linear-gradient(90deg,#9fe8ff 0 5px,transparent 5px 9px)}
.sw.buoyR{background:#e2453f}.sw.buoyG{background:#39c46b}
.sw.shoal{background:#c9b47c;box-shadow:0 0 0 2px rgba(255,180,84,.55)}
.sw.excl{background:repeating-linear-gradient(90deg,#ff6b6b 0 4px,transparent 4px 8px)}
ul{list-style:none;margin:0;padding:0}
li.port{padding:6px 0;border-bottom:1px dashed var(--line)}
li.port:last-child{border-bottom:0}
.dot{display:inline-block;width:8px;height:8px;border-radius:50%;margin-right:7px;vertical-align:1px}
.dot.ok{background:var(--accent);box-shadow:0 0 8px var(--accent)}
.dot.no{background:var(--bad)}
.tag{float:right;font-size:9.5px;letter-spacing:.8px;padding:1px 6px;border-radius:20px;margin-left:6px}
.tag.ok{background:rgba(95,227,200,.16);color:var(--accent);border:1px solid rgba(95,227,200,.35)}
.tag.no{background:rgba(255,107,107,.16);color:var(--bad);border:1px solid rgba(255,107,107,.35)}
.meta{color:var(--dim);font-size:10.5px;margin-top:2px}
.note{margin-top:10px;color:var(--dim);font-size:10.5px;border-top:1px solid var(--line);padding-top:8px}
#status{bottom:14px;left:50%;transform:translateX(-50%);display:flex;gap:18px;align-items:center;
background:var(--panel);backdrop-filter:blur(7px);border:1px solid var(--line);border-radius:10px;
padding:9px 16px;font-size:12px;white-space:nowrap}
#status b{color:var(--accent);font-weight:600}
#status .sep{width:1px;height:16px;background:var(--line)}
#st-depth.warn{color:var(--warn)}
#controls{top:14px;right:14px;display:flex;flex-direction:column;gap:7px;align-items:flex-end}
button{background:rgba(9,28,42,.85);border:1px solid var(--line);color:var(--ink);border-radius:8px;
padding:7px 11px;font-size:11.5px;cursor:pointer;letter-spacing:.3px;min-width:132px;text-align:left}
button:hover{border-color:var(--accent);color:#fff}
button.on{border-color:var(--accent);color:var(--accent)}
#hint{bottom:14px;right:14px;color:var(--dim);font-size:10.5px;text-align:right;line-height:1.5}
@media (max-width:820px){.panel{width:230px;font-size:11.5px}.panel .legend,#hint{display:none}}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div class="panel" id="panel">
<h1>Archipelago Freight</h1>
<p class="sub">Supply route planner · simplified bathymetry · draft 2.0 m</p>
<h2>Chart legend</h2>
<div class="legend">
<div><i class="sw" style="background:linear-gradient(90deg,#d9c894,#79c9bd,#16607f)"></i>depth ramp (shallow → deep)</div>
<div><i class="sw dash"></i>marked shipping lane centreline</div>
<div><i class="sw buoyR"></i>port-hand buoy <i class="sw buoyG" style="margin-left:8px"></i>starboard-hand buoy</div>
<div><i class="sw shoal"></i>shoal / foul ground (exclusion)</div>
<div><i class="sw excl"></i>rejected access route</div>
</div>
<h2>Ports</h2>
<ul id="portlist"></ul>
<div class="note" id="routeNote"></div>
</div>
<div id="status">
<span id="st-state">Boat <b>MV Tern</b> underway</span>
<span class="sep"></span>
<span id="st-next">Next: —</span>
<span class="sep"></span>
<span id="st-depth">Depth under keel: —</span>
</div>
<div id="controls">
<button id="btnFollow">Follow boat: off</button>
<button id="btnTop">Top-down view</button>
<button id="btnLanes">Lane marks: on</button>
<button id="btnRestart">Restart tour</button>
<button id="btnReset">Reset camera</button>
</div>
<div id="hint">drag = orbit · wheel = zoom · shift/right-drag = pan</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ------------------------------------------------------------------ *
* Model constants
* ------------------------------------------------------------------ */
const DRAFT = 2.0; // vessel draft (m)
const SEA_MAX = 12.0; // deepest water in the model (m)
const HALO_K = 0.28; // depth gain per metre of distance from a shore
const SHOAL_CORE = 0.5; // depth at the centre of a shoal
const SHOAL_EDGE = 7.5; // depth at the rim of a shoal
const WORLD = 460;
/* deterministic RNG */
function mulberry32(a){return function(){a|=0;a=a+0x6D2B79F5|0;let t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296;};}
const clamp=(v,a,b)=>v<a?a:v>b?b:v;
const lerp=(a,b,t)=>a+(b-a)*t;
function angLerp(a,b,t){let d=((b-a+Math.PI)%(Math.PI*2)+Math.PI*2)%(Math.PI*2)-Math.PI;return a+d*t;}
/* ------------------------------------------------------------------ *
* Geography
* ------------------------------------------------------------------ */
const ISLAND_DEFS=[
{id:'halcyon',name:'Halcyon Island',port:'Halcyon Port',c:[-100,-80],r:28,seed:11,h1:5.5,h2:10.5,h3:13.5,rocky:false},
{id:'rook', name:'Rook Island', port:'Rook Port', c:[0,-110], r:26,seed:23,h1:4.5,h2:8.5, h3:11.0,rocky:false},
{id:'mistral',name:'Mistral Rock', port:'Mistral Port', c:[115,-35], r:20,seed:37,h1:7.5,h2:13.0,h3:17.0,rocky:true },
{id:'cobalt', name:'Cobalt Cay', port:'Cobalt Port', c:[-65,50], r:24,seed:51,h1:4.0,h2:7.5, h3:10.0,rocky:false},
{id:'beacon', name:'Beacon Island',port:'Beacon Port', c:[60,100], r:22,seed:67,h1:5.0,h2:9.0, h3:12.5,rocky:false}
];
const SHOAL_DEFS=[
{id:'mistral-bar',name:'Mistral Bar',c:[72,-58], rx:13, rz:11, rot:0.30,seed:5 },
{id:'grey-flats', name:'Grey Flats', c:[-130,-40],rx:16, rz:12, rot:-0.40,seed:9 },
{id:'tern-shoal', name:'Tern Shoal', c:[120,10], rx:14, rz:12, rot:0.20,seed:15}
];
const S1=[-50,-95], S2=[57,-72], S3=[-2,75]; // strait lane nodes
function makePolygon(cx,cz,R,n,seed,jit){
const rnd=mulberry32(seed), pts=[];
for(let i=0;i<n;i++){
const a=i/n*Math.PI*2;
const rr=R*(1+jit*(rnd()*2-1)+0.07*Math.sin(3*a+seed*0.3));
pts.push(new THREE.Vector2(cx+Math.cos(a)*rr,cz+Math.sin(a)*rr));
}
return pts;
}
const islands=ISLAND_DEFS.map(d=>{
const poly=makePolygon(d.c[0],d.c[1],d.r,26,d.seed,0.13);
const rmax=Math.max(...poly.map(p=>Math.hypot(p.x-d.c[0],p.y-d.c[1])));
return {...d,poly,rmax};
});
const shoals=SHOAL_DEFS.map(s=>({...s}));
/* signed distance to a polygon (negative = inside) */
function polySD(px,pz,poly){
let inside=false,min=Infinity;
for(let i=0;i<poly.length;i++){
const a=poly[i],b=poly[(i+1)%poly.length];
const dx=b.x-a.x,dz=b.y-a.y,l2=dx*dx+dz*dz;
let t=((px-a.x)*dx+(pz-a.y)*dz)/l2; t=clamp(t,0,1);
const cx=a.x+t*dx,cz=a.y+t*dz,d=Math.hypot(px-cx,pz-cz);
if(d<min)min=d;
if((a.y>pz)!==(b.y>pz)){const xi=a.x+(pz-a.y)*(b.x-a.x)/(b.y-a.y);if(px<xi)inside=!inside;}
}
return inside?-min:min;
}
function shoalS(sh,x,z){
const dx=x-sh.c[0],dz=z-sh.c[1],c=Math.cos(-sh.rot),s=Math.sin(-sh.rot);
return Math.hypot((dx*c-dz*s)/sh.rx,(dx*s+dz*c)/sh.rz);
}
/* the depth field used for both rendering and navigation */
function depthAt(x,z){
let d=SEA_MAX;
for(const isl of islands){
const sd=polySD(x,z,isl.poly);
if(sd<0) return 0;
d=Math.min(d,HALO_K*sd);
}
for(const sh of shoals){
const s=shoalS(sh,x,z);
if(s<1) d=Math.min(d,SHOAL_CORE+(SHOAL_EDGE-SHOAL_CORE)*s*s);
else if(s<1.45) d=Math.min(d,SHOAL_EDGE+(SEA_MAX-SHOAL_EDGE)*(s-1)/0.45);
}
return d;
}
/* distance from island centre to its shoreline along a bearing */
function radiusAlong(isl,ang){
const dx=Math.cos(ang),dz=Math.sin(ang);let best=0;
for(let t=1;t<isl.rmax*1.8;t+=0.4){
if(polySD(isl.c[0]+dx*t,isl.c[1]+dz*t,isl.poly)<=0)best=t;else break;
}
return best;
}
/* ------------------------------------------------------------------ *
* Ports: berth is always 12 m off the shoreline (≈3.4 m of water)
* ------------------------------------------------------------------ */
const PORTS=[
{id:'halcyon',name:'Halcyon Port',isl:'halcyon',node:S1,mid:null,dirTo:S1, spur:null},
{id:'rook', name:'Rook Port', isl:'rook', node:S1,mid:[-30,-78],dirTo:[-30,-78],spur:null},
{id:'mistral',name:'Mistral Port',isl:'mistral',node:S2,mid:[68,-60], dirTo:[-1,0], spur:[[68,-60],[76,-48]]},
{id:'cobalt', name:'Cobalt Port', isl:'cobalt', node:S3,mid:[-16,70], dirTo:S3, spur:null},
{id:'beacon', name:'Beacon Port', isl:'beacon', node:S3,mid:[12,82], dirTo:S3, spur:null}
];
PORTS.forEach(p=>{
const isl=islands.find(i=>i.id===p.isl);
const ang=Math.atan2(p.dirTo[1]-isl.c[1],p.dirTo[0]-isl.c[0]);
const tShore=radiusAlong(isl,ang);
const tBerth=tShore+12;
const d=[Math.cos(ang),Math.sin(ang)];
p.island=isl; p.tShore=tShore;
p.shore=[isl.c[0]+d[0]*tShore, isl.c[1]+d[1]*tShore];
p.berth=[isl.c[0]+d[0]*tBerth, isl.c[1]+d[1]*tBerth];
p.dir=d;
p.approach=p.spur?[p.node,...p.spur,p.berth]:(p.mid?[p.node,p.mid,p.berth]:[p.node,p.berth]);
});
/* analyse every planned access route against the depth model */
function analyseRoute(pts){
let minD=Infinity,minP=null,shoal=null;
for(let i=0;i<pts.length-1;i++){
const a=pts[i],b=pts[i+1],len=Math.hypot(b[0]-a[0],b[1]-a[1]);
const steps=Math.max(2,Math.ceil(len/0.5));
for(let s=0;s<=steps;s++){
const x=lerp(a[0],b[0],s/steps),z=lerp(a[1],b[1],s/steps);
const d=depthAt(x,z);
if(d<minD){minD=d;minP=[x,z];
for(const sh of shoals) if(shoalS(sh,x,z)<1){shoal=sh;break;}
}
}
}
return {minD,minP,shoal,blocked:minD<DRAFT};
}
PORTS.forEach(p=>{p.analysis=analyseRoute(p.approach);});
/* shipping lane network */
const LANES=[
{name:'Outer Sea – NW approach',pts:[[-170,-60],[-135,-105],[-95,-140],S1]},
{name:'Halcyon–Rook Strait', pts:[S1,[-30,-78],[0,-74],S2]},
{name:'Rook–Mistral Strait', pts:[S2,[110,-95],[140,-60],[150,20]]},
{name:'Outer Sea – East', pts:[[150,20],[150,80],[120,130]]},
{name:'Cobalt–Beacon Strait', pts:[[120,130],[65,140],[20,115],S3]},
{name:'Outer Sea – West', pts:[S3,[-45,95],[-100,100],[-140,80],[-155,30],[-150,-10]]},
{name:'Halcyon–Cobalt Strait', pts:[[-150,-10],[-70,-45],S1]}
];
/* the supply boat's tour (cyclic): ports it may legally enter + the lane legs */
const TOUR=[
{p:[-170,-60]},{p:[-135,-105]},{p:[-95,-140]},
{p:S1,dest:'Halcyon Port'},
{p:PORTS[0].berth,stop:5,port:'Halcyon Port'},
{p:S1,dest:'Halcyon–Rook Strait'},{p:[-30,-78],dest:'Rook Port'},
{p:PORTS[1].berth,stop:5,port:'Rook Port'},
{p:[-30,-78],dest:'Rook–Mistral Strait'},{p:[0,-74],dest:'Rook–Mistral Strait'},
{p:S2,dest:'Rook–Mistral Strait'},{p:[110,-95],dest:'Outer Sea'},{p:[140,-60],dest:'Outer Sea'},
{p:[150,20],dest:'Outer Sea'},{p:[150,80],dest:'Outer Sea'},{p:[120,130],dest:'Beacon Strait'},
{p:[65,140],dest:'Cobalt–Beacon Strait'},{p:[20,115],dest:'Cobalt–Beacon Strait'},
{p:S3,dest:'Beacon Port'},{p:[12,82],dest:'Beacon Port'},
{p:PORTS[4].berth,stop:5,port:'Beacon Port'},
{p:[12,82],dest:'Cobalt Port'},{p:S3,dest:'Cobalt Port'},{p:[-16,70],dest:'Cobalt Port'},
{p:PORTS[3].berth,stop:5,port:'Cobalt Port'},
{p:[-16,70],dest:'Outer Sea (west)'},{p:S3,dest:'Outer Sea (west)'},{p:[-45,95],dest:'Outer Sea (west)'},
{p:[-100,100],dest:'Outer Sea (west)'},{p:[-140,80],dest:'Halcyon–Cobalt Strait'},
{p:[-155,30],dest:'Halcyon–Cobalt Strait'},{p:[-150,-10],dest:'Halcyon–Cobalt Strait'},
{p:[-70,-45],dest:'Halcyon–Rook Strait'},{p:S1,dest:'Halcyon–Rook Strait'}
];
/* ------------------------------------------------------------------ *
* Scene
* ------------------------------------------------------------------ */
const canvas=document.getElementById('scene');
const renderer=new THREE.WebGLRenderer({canvas,antialias:true});
renderer.setPixelRatio(Math.min(devicePixelRatio,2));
renderer.shadowMap.enabled=true;
renderer.shadowMap.type=THREE.PCFSoftShadowMap;
const scene=new THREE.Scene();
scene.background=new THREE.Color(0x0a1c2b);
scene.fog=new THREE.Fog(0x0b2b40,420,980);
const camera=new THREE.PerspectiveCamera(48,innerWidth/innerHeight,1,2200);
const cam={theta:0.55,phi:1.0,r:340,target:new THREE.Vector3(0,0,10)};
scene.add(new THREE.HemisphereLight(0xbfe4ff,0x1d3242,0.85));
const sun=new THREE.DirectionalLight(0xfff0d0,1.05);
sun.position.set(-160,220,-120); sun.castShadow=true;
sun.shadow.mapSize.set(2048,2048);
const sc=sun.shadow.camera; sc.left=-260;sc.right=260;sc.top=260;sc.bottom=-260;sc.near=1;sc.far=700;
sun.shadow.bias=-0.0009; scene.add(sun);
const mat=(c,o={})=>new THREE.MeshLambertMaterial({color:c,flatShading:true,...o});
const box=(w,h,d,color,x=0,y=0,z=0,ry=0)=>{
const m=new THREE.Mesh(new THREE.BoxGeometry(w,h,d),mat(color));
m.position.set(x,y,z); m.rotation.y=ry; m.castShadow=true; m.receiveShadow=true; scene.add(m); return m;
};
const cyl=(rt,rb,h,color,x=0,y=0,z=0,seg=8)=>{
const m=new THREE.Mesh(new THREE.CylinderGeometry(rt,rb,h,seg),mat(color));
m.position.set(x,y,z); m.castShadow=true; m.receiveShadow=true; scene.add(m); return m;
};
/* ---------- sea ---------- */
const RAMP=[[0,0xe9d9a3],[1.0,0x9adfc9],[2.2,0x4cbcc0],[4.5,0x1e7fa0],[8,0x12587c],[12,0x0c3c5c]];
const _c1=new THREE.Color(),_c2=new THREE.Color();
function depthColor(d,out){
for(let i=0;i<RAMP.length-1;i++){
if(d<=RAMP[i+1][0]){
_c1.setHex(RAMP[i][1]); _c2.setHex(RAMP[i+1][1]);
return out.copy(_c1).lerp(_c2,(d-RAMP[i][0])/(RAMP[i+1][0]-RAMP[i][0]));
}
}
return out.setHex(RAMP[RAMP.length-1][1]);
}
{
const g=new THREE.PlaneGeometry(WORLD,WORLD,80,80); g.rotateX(-Math.PI/2);
const p=g.attributes.position,cols=[],rnd=mulberry32(7),col=new THREE.Color();
for(let i=0;i<p.count;i++){
depthColor(depthAt(p.getX(i),p.getZ(i)),col);
const j=1+(rnd()-0.5)*0.09;
cols.push(col.r*j,col.g*j,col.b*j);
}
g.setAttribute('color',new THREE.Float32BufferAttribute(cols,3));
const sea=new THREE.Mesh(g,new THREE.MeshLambertMaterial({vertexColors:true,flatShading:true}));
sea.receiveShadow=true; scene.add(sea);
const outer=new THREE.Mesh(new THREE.PlaneGeometry(1700,1700),new THREE.MeshBasicMaterial({color:0x0c3c5c}));
outer.rotation.x=-Math.PI/2; outer.position.y=-0.02; scene.add(outer);
}
/* ---------- labels ---------- */
const labels=[];
function roundRect(ctx,x,y,w,h,r){
ctx.beginPath();ctx.moveTo(x+r,y);ctx.arcTo(x+w,y,x+w,y+h,r);ctx.arcTo(x+w,y+h,x,y+h,r);
ctx.arcTo(x,y+h,x,y,r);ctx.arcTo(x,y,x+w,y,r);ctx.closePath();
}
function makeLabel(text,{color='#e7f4fb',bg='rgba(6,20,31,.78)',border='rgba(95,227,200,.75)',scale=1}={}){
const fs=42,pad=16;
let c=document.createElement('canvas'),x=c.getContext('2d');
x.font=`600 ${fs}px system-ui, sans-serif`;
const w=Math.ceil(x.measureText(text).width)+pad*2,h=fs+pad*2;
c.width=w;c.height=h;const g=c.getContext('2d');
g.font=`600 ${fs}px system-ui, sans-serif`;
g.fillStyle=bg;roundRect(g,0,0,w,h,12);g.fill();
g.strokeStyle=border;g.lineWidth=3;roundRect(g,1.5,1.5,w-3,h-3,12);g.stroke();
g.fillStyle=color;g.textAlign='center';g.textBaseline='middle';g.fillText(text,w/2,h/2+2);
const tex=new THREE.CanvasTexture(c); tex.colorSpace=THREE.SRGBColorSpace;
const sp=new THREE.Sprite(new THREE.SpriteMaterial({map:tex,transparent:true,depthTest:false}));
sp.renderOrder=20; sp.userData={aspect:w/h,scale};
scene.add(sp); labels.push(sp); return sp;
}
function placeLabel(sp,x,y,z){sp.position.set(x,y,z);return sp;}
/* ---------- islands ---------- */
function buildIsland(isl){
const n=isl.poly.length,rnd=mulberry32(isl.seed*7+3);
const sand=isl.rocky?0xd6cbb2:0xe2cf9c;
const grass=isl.rocky?0x9b9483:0x79a35e;
const grass2=isl.rocky?0x8b8577:0x5f8c4c;
const top=isl.rocky?0xb0a894:0x6f9c56;
const rings=[
{s:1.00,y:0.35,c:sand,jit:0},
{s:0.62,y:isl.h1,c:grass,jit:1},
{s:0.30,y:isl.h2,c:grass2,jit:1}
];
const ringPts=rings.map((r,ri)=>isl.poly.map(p=>{
const j=ri===0?1:(0.84+0.30*rnd());
const x=isl.c[0]+(p.x-isl.c[0])*r.s*j, z=isl.c[1]+(p.y-isl.c[1])*r.s*j;
const y=r.y*(ri===0?1:(0.72+0.52*rnd()));
return new THREE.Vector3(x,y,z);
}));
const V=[],C=[],push=(v,c)=>{V.push(v.x,v.y,v.z);C.push(c.r,c.g,c.b);};
const c0=new THREE.Color(sand),c1=new THREE.Color(grass),c2=new THREE.Color(grass2),ct=new THREE.Color(top);
for(let ri=0;ri<rings.length-1;ri++){
for(let i=0;i<n;i++){
const i2=(i+1)%n,A=ringPts[ri][i],B=ringPts[ri][i2],C2=ringPts[ri+1][i2],D=ringPts[ri+1][i];
const ca=ri===0?c0:c1, cb=ri===0?c0:c2;
push(A,ca);push(B,ca);push(C2,cb); push(A,ca);push(C2,cb);push(D,cb);
}
}
const topV=new THREE.Vector3(isl.c[0],isl.h3,isl.c[1]);
for(let i=0;i<n;i++){
const i2=(i+1)%n;
push(ringPts[2][i],c2);push(ringPts[2][i2],c2);push(topV,ct);
}
const g=new THREE.BufferGeometry();
g.setAttribute('position',new THREE.Float32BufferAttribute(V,3));
g.setAttribute('color',new THREE.Float32BufferAttribute(C,3));
g.computeVertexNormals();
const m=new THREE.Mesh(g,new THREE.MeshLambertMaterial({vertexColors:true,flatShading:true,side:THREE.DoubleSide}));
m.castShadow=true;m.receiveShadow=true;scene.add(m);
/* trees on the green islands */
if(!isl.rocky){
const tr=mulberry32(isl.seed*13+1);
const count=5+Math.floor(tr()*4);
for(let i=0;i<count;i++){
const a=tr()*Math.PI*2,rr=isl.r*(0.18+tr()*0.36);
const x=isl.c[0]+Math.cos(a)*rr,z=isl.c[1]+Math.sin(a)*rr;
const y=isl.h1*0.9;
cyl(0.32,0.4,2.6,0x5b4632,x,y+1.3,z,5);
const tree=new THREE.Mesh(new THREE.ConeGeometry(2.2,5.4,6),mat(0x3f7a45));
tree.position.set(x,y+4.2,z);tree.castShadow=true;scene.add(tree);
}
}else{
for(let i=0;i<5;i++){
const a=i/5*Math.PI*2+0.4,rr=isl.r*0.45;
const rock=new THREE.Mesh(new THREE.DodecahedronGeometry(3.4,0),mat(0x8d8878));
rock.position.set(isl.c[0]+Math.cos(a)*rr,isl.h1*0.8,isl.c[1]+Math.sin(a)*rr);
rock.rotation.set(i, i*1.7, 0.3); rock.castShadow=true; scene.add(rock);
}
}
placeLabel(makeLabel(isl.name,{scale:1.15,border:'rgba(120,200,220,.6)'}),isl.c[0],isl.h3+9,isl.c[1]);
}
islands.forEach(buildIsland);
/* ---------- shoals ---------- */
function buildShoal(sh){
const rnd=mulberry32(sh.seed*31+5),pts=[];
for(let i=0;i<18;i++){
const a=i/18*Math.PI*2,rr=1+(rnd()-0.5)*0.30;
const x=sh.c[0]+Math.cos(a)*sh.rx*rr,z=sh.c[1]+Math.sin(a)*sh.rz*rr;
pts.push(new THREE.Vector2(x,z));
}
const shape=new THREE.Shape(pts);
const g=new THREE.ShapeGeometry(shape); g.rotateX(-Math.PI/2);
const m=new THREE.Mesh(g,new THREE.MeshLambertMaterial({color:0xcbb684,flatShading:true,side:THREE.DoubleSide}));
m.position.y=0.07;m.receiveShadow=true;scene.add(m);
/* a few reef heads */
for(let i=0;i<4;i++){
const a=rnd()*Math.PI*2,rr=0.55+rnd()*0.35;
const rock=new THREE.Mesh(new THREE.DodecahedronGeometry(1.4,0),mat(0x9d9478));
rock.position.set(sh.c[0]+Math.cos(a)*sh.rx*rr,0.25,sh.c[1]+Math.sin(a)*sh.rz*rr);
rock.rotation.set(rnd()*3,rnd()*3,0);rock.castShadow=true;scene.add(rock);
}
/* shoal perimeter markers */
for(let i=0;i<7;i++){
const a=i/7*Math.PI*2;
const x=sh.c[0]+Math.cos(a)*sh.rx*1.05,z=sh.c[1]+Math.sin(a)*sh.rz*1.05;
if(depthAt(x,z)<0.2)continue;
const g2=new THREE.Group();
const body=new THREE.Mesh(new THREE.CylinderGeometry(0.7,0.9,1.7,6),mat(0xffc247));
body.position.y=0.85; body.castShadow=true; g2.add(body);
const top=new THREE.Mesh(new THREE.ConeGeometry(0.75,1.3,6),mat(0x1d1d1d));
top.position.y=2.3;g2.add(top);
g2.position.set(x,0,z);scene.add(g2);
}
placeLabel(makeLabel(sh.name.toUpperCase()+' · SHALLOW',{color:'#ffd9a0',bg:'rgba(46,28,4,.78)',border:'rgba(255,180,84,.85)',scale:0.8}),
sh.c[0],5,sh.c[1]);
}
shoals.forEach(buildShoal);
/* ---------- lane markings ---------- */
const laneGroup=new THREE.Group(); scene.add(laneGroup);
function dashedLine(pts,color,dash=6,gap=5,opacity=0.85,y=0.24){
const v=pts.map(p=>new THREE.Vector3(p[0],y,p[1]));
const l=new THREE.Line(new THREE.BufferGeometry().setFromPoints(v),
new THREE.LineDashedMaterial({color,dashSize:dash,gapSize:gap,transparent:true,opacity}));
l.computeLineDistances(); return l;
}
function buoy(color,x,z,s=1){
const g=new THREE.Group();
const b=new THREE.Mesh(new THREE.CylinderGeometry(0.75*s,0.95*s,1.8*s,6),mat(color));
b.position.y=0.9*s;b.castShadow=true;g.add(b);
const t=new THREE.Mesh(new THREE.ConeGeometry(0.8*s,1.4*s,6),mat(color));
t.position.y=2.5*s;g.add(t);
g.position.set(x,0,z);return g;
}
function markLane(pts,{half=8,spacing=17}={}){
let acc=0;
for(let i=0;i<pts.length-1;i++){
const a=pts[i],b=pts[i+1];
const dx=b[0]-a[0],dz=b[1]-a[1],len=Math.hypot(dx,dz);
const ux=dx/len,uz=dz/len,px=-uz,pz=ux;
let t=spacing*0.5;
while(t<len){
const x=a[0]+ux*t,z=a[1]+uz*t;
for(const side of [-1,1]){
const bx=x+px*half*side,bz=z+pz*half*side;
if(depthAt(bx,bz)<0.25)continue;
laneGroup.add(buoy(side<0?0xe2453f:0x39c46b,bx,bz));
}
t+=spacing;
}
acc+=len;
}
}
LANES.forEach(l=>{
laneGroup.add(dashedLine(l.pts,0x9fe8ff,7,6,0.8));
markLane(l.pts);
const mid=l.pts[Math.floor(l.pts.length/2)];
placeLabel(makeLabel(l.name,{color:'#bfe6f7',bg:'rgba(6,22,34,.55)',border:'rgba(120,200,220,.35)',scale:0.62}),mid[0],3.2,mid[1]);
});
/* chevrons showing the direction of traffic */
for(let i=0;i<TOUR.length-1;i++){
const a=TOUR[i].p,b=TOUR[i+1].p;
const ang=Math.atan2(b[0]-a[0],b[1]-a[1]);
const m=new THREE.Mesh(new THREE.ConeGeometry(1.5,3.4,3),new THREE.MeshBasicMaterial({color:0xbfefff,transparent:true,opacity:0.28}));
m.position.set((a[0]+b[0])/2,0.3,(a[1]+b[1])/2);
m.rotation.set(Math.PI/2,0,-ang+Math.PI/2);
laneGroup.add(m);
}
/* ---------- ports ---------- */
function buildPort(p){
const blocked=p.analysis.blocked;
const pal=blocked?{quay:0x6c7176,house:0x868c8f,crane:0x9aa0a4,tank:0x7d8488}
:{quay:0x9a8c74,house:0xd9d2c4,crane:0xe4a13c,tank:0xb9b2a4};
const dx=p.dir[0],dz=p.dir[1],len=15;
const cx=p.shore[0]+dx*6,cz=p.shore[1]+dz*6;
const ry=Math.atan2(dx,dz);
/* quay platform + pier */
box(12,1.8,10,pal.quay,p.shore[0]-dx*4,0.7,p.shore[1]-dz*4,ry);
const pier=box(4.4,1.4,len,pal.quay,cx,0.85,cz,ry);
pier.castShadow=true;
/* bollards + lamps */
for(let i=0;i<6;i++){
const t=-6+i*2.4;
const x=cx+dx*t,z=cz+dz*t;
cyl(0.35,0.4,1.1,0x2f3b44,x,1.6,z,6);
}
for(let i=0;i<3;i++){
const t=-5+i*5,x=cx+dx*t,z=cz+dz*t;
cyl(0.16,0.16,4.2,0x59636b,x,3.0,z,5);
const bulb=new THREE.Mesh(new THREE.SphereGeometry(0.55,6,5),new THREE.MeshBasicMaterial({color:0xffe9b0}));
bulb.position.set(x,5.2,z);scene.add(bulb);
}
/* warehouse */
box(11,5.5,9,pal.house,p.shore[0]-dx*13,2.8,p.shore[1]-dz*13,ry);
const roof=new THREE.Mesh(new THREE.ConeGeometry(7.6,2.6,4),mat(blocked?0x5f6467:0x8a4b3a));
roof.position.set(p.shore[0]-dx*13,6.6,p.shore[1]-dz*13);roof.rotation.y=Math.PI/4;roof.castShadow=true;scene.add(roof);
/* tanks */
if(p.id==='halcyon'||p.id==='beacon'){
for(const s of [-1,1]){
const x=p.shore[0]-dx*19+(-dz)*s*6,z=p.shore[1]-dz*19+(dx)*s*6;
cyl(3.1,3.1,6.5,pal.tank,x,3.4,z,10);
cyl(3.2,3.2,0.5,0x6e6a60,x,5.2,z,10);
}
}
/* crane at the berth */
const bx=p.berth[0]-dx*3.5,bz=p.berth[1]-dz*3.5;
box(1.0,9,1.0,pal.crane,bx-(-dz)*2.2,4.5,bz-(dx)*2.2);
box(1.0,9,1.0,pal.crane,bx+(-dz)*2.2,4.5,bz+(dx)*2.2);
const arm=box(1.1,1.0,10,pal.crane,bx-dx*3.4,8.6,bz-dz*3.4,ry);
arm.castShadow=true;
box(1.6,1.4,1.6,0x39424a,bx-dx*7.6,7.4,bz-dz*7.6);
/* small settlement */
for(let i=0;i<4;i++){
const a=0.6+i*1.4,rr=p.island.r*0.42;
const hx=p.island.c[0]+Math.cos(a)*rr, hz=p.island.c[1]+Math.sin(a)*rr;
const w=3.4+ (i%2)*1.4;
box(w,2.8,3.2,blocked?0x8a8f92:0xe7e0d2,hx,1.5,hz);
const r2=new THREE.Mesh(new THREE.ConeGeometry(2.8,1.8,4),mat(blocked?0x60656a:0x9c5040));
r2.position.set(hx,3.6,hz);r2.rotation.y=Math.PI/4;scene.add(r2);
}
/* berth marker + status label */
const m=new THREE.Mesh(new THREE.CylinderGeometry(0.8,0.8,1.6,6),mat(blocked?0xff6b6b:0x39c46b));
m.position.set(p.berth[0],1.0,p.berth[1]);scene.add(m);
placeLabel(makeLabel(p.name.toUpperCase(),{
color:blocked?'#ffb9b9':'#d7fff5',
bg:blocked?'rgba(48,10,10,.8)':'rgba(6,28,26,.8)',
border:blocked?'rgba(255,107,107,.85)':'rgba(95,227,200,.85)',scale:0.85}),
p.berth[0]+ (blocked?0:dx*6), blocked?7:5.5, p.berth[1]+ (blocked?0:dz*6));
/* access route: solid for reachable ports, rejected dashed for the barred one */
const line=dashedLine(p.approach, blocked?0xff6b6b:0x9fe8ff, blocked?4:3, blocked?4:4, blocked?0.95:0.5, 0.26);
(blocked?scene:laneGroup).add(line);
if(blocked){
const [mx,mz]=p.analysis.minP;
const x=new THREE.Group();
const b1=box(9,0.7,1.1,0xff6b6b,mx,1.2,mz,0.9);
const b2=box(9,0.7,1.1,0xff6b6b,mx,1.2,mz,-0.9);
scene.add(x);
placeLabel(makeLabel('NO ENTRY · '+p.analysis.minD.toFixed(1)+' m',{
color:'#ffd4d4',bg:'rgba(56,8,8,.85)',border:'rgba(255,107,107,.9)',scale:0.7}),mx,7,mz);
}
}
PORTS.forEach(buildPort);
/* lighthouse on Beacon Island */
{
const isl=islands.find(i=>i.id==='beacon');
const x=isl.c[0]-isl.r*0.42,z=isl.c[1]-isl.r*0.42;
cyl(2.0,2.6,10,0xe6e2d6,x,isl.h1*0.9+5,z,10);
cyl(2.15,2.15,2.0,0xc04a3a,x,isl.h1*0.9+7.6,z,10);
const lh=new THREE.Mesh(new THREE.ConeGeometry(2.5,2.4,10),mat(0x39424a));
lh.position.set(x,isl.h1*0.9+11,z);scene.add(lh);
const lamp=new THREE.Mesh(new THREE.SphereGeometry(1.1,8,6),new THREE.MeshBasicMaterial({color:0xfff2c0}));
lamp.position.set(x,isl.h1*0.9+9.8,z);scene.add(lamp);
const beam=new THREE.PointLight(0xffe6a8,1.6,60);beam.position.copy(lamp.position);scene.add(beam);
}
/* ------------------------------------------------------------------ *
* The supply boat
* ------------------------------------------------------------------ */
function buildBoat(){
const g=new THREE.Group();
const shape=new THREE.Shape();
const pts=[[0,10],[3.0,2.0],[3.4,-4.0],[2.6,-6.6],[-2.6,-6.6],[-3.4,-4.0],[-3.0,2.0]];
shape.moveTo(pts[0][0],pts[0][1]);
for(let i=1;i<pts.length;i++)shape.lineTo(pts[i][0],pts[i][1]);
shape.closePath();
const hull=new THREE.Mesh(new THREE.ExtrudeGeometry(shape,{depth:2.2,bevelEnabled:false}),
new THREE.MeshLambertMaterial({color:0x24415c,flatShading:true}));
hull.rotation.x=-Math.PI/2; hull.castShadow=true; g.add(hull);
const waterline=new THREE.Mesh(new THREE.ExtrudeGeometry(shape,{depth:0.55,bevelEnabled:false}),
new THREE.MeshLambertMaterial({color:0x8f2f2a,flatShading:true}));
waterline.rotation.x=-Math.PI/2; waterline.position.y=-0.55; g.add(waterline);
const deck=boxMesh(5.6,0.45,10.5,0xc9d3d6,0,2.25,-1.2); g.add(deck);
const house=boxMesh(3.7,2.4,3.4,0xe8eef0,0,3.4,1.0); g.add(house);
const roof=boxMesh(3.1,0.8,2.9,0xb9c6cc,0,4.9,1.1); g.add(roof);
const win=boxMesh(3.75,0.6,0.15,0x18303f,0,3.9,2.75); g.add(win);
const funnel=cylMesh(0.85,1.0,2.4,0x37474f,0,4.0,-2.6,8); g.add(funnel);
const mast=cylMesh(0.16,0.2,7.5,0xd8d2c4,0,7.0,0.4,6); g.add(mast);
const boom=boxMesh(0.22,0.22,4.2,0xd8d2c4,0,8.6,-1.4); g.add(boom);
const c1=boxMesh(2.3,1.7,3.0,0xe07a3c,-1.4,3.1,-3.4); g.add(c1);
const c2=boxMesh(2.3,1.7,3.0,0x3f9d8f,1.4,3.1,-3.4); g.add(c2);
const c3=boxMesh(2.3,1.7,3.0,0xd8c04a,0,3.1,-5.0); g.add(c3);
const nav=new THREE.Mesh(new THREE.SphereGeometry(0.42,6,5),new THREE.MeshBasicMaterial({color:0xffd27a}));
nav.position.set(0,9.2,0.4); g.add(nav);
return g;
}
function boxMesh(w,h,d,c,x,y,z){const m=new THREE.Mesh(new THREE.BoxGeometry(w,h,d),mat(c));m.position.set(x,y,z);m.castShadow=true;return m;}
function cylMesh(rt,rb,h,c,x,y,z,s){const m=new THREE.Mesh(new THREE.CylinderGeometry(rt,rb,h,s),mat(c));m.position.set(x,y,z);m.castShadow=true;return m;}
const boat=buildBoat(); boat.position.set(-170,0, -60); scene.add(boat);
/* wake */
const wake=[];
const wakeGeo=new THREE.PlaneGeometry(2.2,2.2); wakeGeo.rotateX(-Math.PI/2);
for(let i=0;i<48;i++){
const m=new THREE.Mesh(wakeGeo,new THREE.MeshBasicMaterial({color:0xdff4ff,transparent:true,opacity:0,depthWrite:false}));
m.visible=false; scene.add(m); wake.push({m,age:1e9});
}
let wakeTimer=0;
/* ------------------------------------------------------------------ *
* Tour state
* ------------------------------------------------------------------ */
const tourPts=TOUR.map(t=>({p:new THREE.Vector3(t.p[0],0,t.p[1]),stop:t.stop||0,port:t.port,dest:t.dest||''}));
const segs=[];
for(let i=0;i<tourPts.length;i++){
const a=tourPts[i],b=tourPts[(i+1)%tourPts.length];
segs.push({a,b,len:a.p.distanceTo(b.p)});
}
const state={idx:0,u:0,dwell:0,cycle:0,visited:new Map(),yaw:0,speed:0};
const SPEED=9.0;
function tourStart(){state.idx=0;state.u=0;state.dwell=0;state.cycle++;state.visited.clear();
boat.position.copy(tourPts[0].p);boat.position.y=0;}
function advance(dt){
if(state.dwell>0){state.dwell-=dt;return;}
let rem=SPEED*dt,moved=0;
while(rem>0){
const sg=segs[state.idx];
if(state.u+rem<sg.len){state.u+=rem;moved+=rem;rem=0;}
else{
rem-=(sg.len-state.u);moved+=(sg.len-state.u);state.u=0;
state.idx=(state.idx+1)%segs.length;
const node=tourPts[state.idx];
if(node.stop&&!state.visited.get(state.idx+':'+state.cycle)){
state.visited.set(state.idx+':'+state.cycle,true);
state.dwell=node.stop;state.docking=node.port;
}
}
}
const sg=segs[state.idx];
const t=sg.len>0?state.u/sg.len:0;
boat.position.lerpVectors(sg.a.p,sg.b.p,t);
const dir=new THREE.Vector3().subVectors(sg.b.p,sg.a.p).normalize();
const targetYaw=Math.atan2(-dir.x,-dir.z);
state.yaw=angLerp(state.yaw,targetYaw,1-Math.exp(-6*dt));
state.speed=moved/dt;
}
function currentInfo(){
if(state.dwell>0) return {mode:'docked',text:'Docked at '+state.docking+' — cargo working',next:nextDest()};
const sg=segs[state.idx];
const node=tourPts[(state.idx+1)%tourPts.length];
return {mode:'underway',text:'Underway',next:(node.dest||'open water')};
}
function nextDest(){
for(let k=1;k<segs.length;k++){
const i=(state.idx+k)%segs.length;
const node=tourPts[(i+1)%tourPts.length];
if(node.dest&&node.dest!==tourPts[(state.idx+1)%tourPts.length].dest) return node.dest;
if(node.dest) return node.dest;
}
return 'open water';
}
/* ------------------------------------------------------------------ *
* Custom camera controls (no addons)
* ------------------------------------------------------------------ */
let follow=false;
const pointers=new Map();
let lastMid=null,pinchDist=0;
canvas.addEventListener('pointerdown',e=>{
canvas.setPointerCapture(e.pointerId);
pointers.set(e.pointerId,{x:e.clientX,y:e.clientY});
if(pointers.size===2){
const [a,b]=[...pointers.values()];
pinchDist=Math.hypot(a.x-b.x,a.y-b.y);
lastMid={x:(a.x+b.x)/2,y:(a.y+b.y)/2};
}
});
canvas.addEventListener('pointermove',e=>{
if(!pointers.has(e.pointerId))return;
const p=pointers.get(e.pointerId);
const dx=e.clientX-p.x,dy=e.clientY-p.y;
p.x=e.clientX;p.y=e.clientY;
if(pointers.size===1){
if(e.shiftKey||e.buttons===2) pan(dx,dy); else {cam.theta-=dx*0.005;cam.phi=clamp(cam.phi-dy*0.005,0.04,1.45);}
}else if(pointers.size===2){
const [a,b]=[...pointers.values()];
const d=Math.hypot(a.x-b.x,a.y-b.y);
if(pinchDist>0)cam.r=clamp(cam.r*(pinchDist/Math.max(d,1)),60,760);
pinchDist=d;
const mid={x:(a.x+b.x)/2,y:(a.y+b.y)/2};
if(lastMid)pan(mid.x-lastMid.x,mid.y-lastMid.y);
lastMid=mid;
}
});
const endPointer=e=>{pointers.delete(e.pointerId);if(pointers.size<2){lastMid=null;pinchDist=0;}};
canvas.addEventListener('pointerup',endPointer);
canvas.addEventListener('pointercancel',endPointer);
canvas.addEventListener('contextmenu',e=>e.preventDefault());
canvas.addEventListener('wheel',e=>{e.preventDefault();cam.r=clamp(cam.r*(1+Math.sign(e.deltaY)*0.09),60,760);},{passive:false});
function pan(dx,dy){
const s=cam.r*0.0016;
const right=new THREE.Vector3(Math.cos(cam.theta),0,-Math.sin(cam.theta));
const fwd=new THREE.Vector3(-Math.sin(cam.theta),0,-Math.cos(cam.theta));
cam.target.addScaledVector(right,-dx*s).addScaledVector(fwd,-dy*s);
cam.target.x=clamp(cam.target.x,-320,320);cam.target.z=clamp(cam.target.z,-320,320);
}
function updateCamera(dt){
if(follow){
cam.target.lerp(new THREE.Vector3(boat.position.x,0,boat.position.z),1-Math.exp(-2.2*dt));
}
const sp=Math.sin(cam.phi),cp=Math.cos(cam.phi);
camera.position.set(
cam.target.x+cam.r*sp*Math.sin(cam.theta),
cam.target.y+cam.r*cp,
cam.target.z+cam.r*sp*Math.cos(cam.theta));
camera.lookAt(cam.target);
}
/* ------------------------------------------------------------------ *
* HUD
* ------------------------------------------------------------------ */
const portList=document.getElementById('portlist');
PORTS.forEach(p=>{
const li=document.createElement('li'); li.className='port';
const a=p.analysis;
const detail=a.blocked
? `approach barred by ${a.shoal?a.shoal.name:'shoal'} — min depth ${a.minD.toFixed(1)} m < draft ${DRAFT.toFixed(1)} m`
: `clear approach — min depth ${a.minD.toFixed(1)} m · berth ${depthAt(p.berth[0],p.berth[1]).toFixed(1)} m`;
li.innerHTML=`<span class="dot ${a.blocked?'no':'ok'}"></span><b>${p.name}</b>
<span class="tag ${a.blocked?'no':'ok'}">${a.blocked?'EXCLUDED':'ACCESSIBLE'}</span>
<div class="meta">${p.island.name} · ${detail}</div>`;
portList.appendChild(li);
});
const tourMin=analyseRoute(TOUR.map(t=>t.p)).minD;
document.getElementById('routeNote').innerHTML=
`Boat tour validated against the depth model: minimum keel depth on route
<b>${tourMin.toFixed(1)} m</b> ≥ draft ${DRAFT.toFixed(1)} m.
<b>${PORTS.filter(p=>!p.analysis.blocked).length}</b> of ${PORTS.length} ports reachable —
Mistral Port is excluded by the shallow bar on its approach.`;
const stState=document.getElementById('st-state'),stNext=document.getElementById('st-next'),stDepth=document.getElementById('st-depth');
let hudT=0;
/* buttons */
document.getElementById('btnFollow').onclick=e=>{follow=!follow;e.target.textContent='Follow boat: '+(follow?'on':'off');e.target.classList.toggle('on',follow);};
document.getElementById('btnTop').onclick=()=>{cam.phi=0.05;cam.r=430;cam.theta=0.0;};
document.getElementById('btnReset').onclick=()=>{cam.theta=0.55;cam.phi=1.0;cam.r=340;cam.target.set(0,0,10);};
document.getElementById('btnRestart').onclick=tourStart;
let lanesOn=true;
document.getElementById('btnLanes').onclick=e=>{lanesOn=!lanesOn;laneGroup.visible=lanesOn;e.target.textContent='Lane marks: '+(lanesOn?'on':'off');e.target.classList.toggle('on',lanesOn);};
addEventListener('resize',()=>{
camera.aspect=innerWidth/innerHeight;camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
});
renderer.setSize(innerWidth,innerHeight);
/* ------------------------------------------------------------------ *
* Loop
* ------------------------------------------------------------------ */
const clock=new THREE.Clock();
let time=0;
function animate(){
const dt=Math.min(clock.getDelta(),0.05); time+=dt;
advance(dt);
boat.rotation.y=state.yaw;
boat.position.y=-0.95+Math.sin(time*1.6)*0.16;
boat.rotation.z=Math.sin(time*1.1)*0.025;
/* wake */
if(state.speed>0.5){
wakeTimer-=dt;
if(wakeTimer<=0){
wakeTimer=0.28;
const back=new THREE.Vector3(Math.sin(state.yaw),0,Math.cos(state.yaw)).multiplyScalar(-7.4);
const side=new THREE.Vector3(Math.cos(state.yaw),0,-Math.sin(state.yaw));
const w=wake.find(x=>!x.m.visible)||wake[0];
w.m.visible=true;w.age=0;
w.m.position.set(boat.position.x+back.x+side.x*(Math.random()-0.5)*1.4,
0.08, boat.position.z+back.z+side.z*(Math.random()-0.5)*1.4);
}
}
for(const w of wake){
if(!w.m.visible)continue;
w.age+=dt;
const k=w.age/2.4;
if(k>=1){w.m.visible=false;continue;}
w.m.scale.setScalar(0.5+k*2.0);
w.m.material.opacity=0.55*(1-k);
w.m.position.y=0.07;
}
updateCamera(dt);
/* labels keep a readable screen size */
for(const sp of labels){
const d=camera.position.distanceTo(sp.position);
const k=clamp(d*0.030,0.35,3.2)*sp.userData.scale;
sp.scale.set(k*sp.userData.aspect,k,1);
}
hudT-=dt;
if(hudT<=0){
hudT=0.15;
const info=currentInfo();
stState.innerHTML=info.mode==='docked'
? `<b>MV Tern</b> — ${info.text}`
: `<b>MV Tern</b> — underway on the marked lane`;
stNext.textContent='Next: '+info.next;
const d=depthAt(boat.position.x,boat.position.z);
stDepth.textContent=`Depth under keel: ${d.toFixed(1)} m (draft ${DRAFT.toFixed(1)} m)`;
stDepth.classList.toggle('warn',d<DRAFT+1.2);
}
renderer.render(scene,camera);
}
renderer.setAnimationLoop(animate);
tourStart();
</script>
</body>
</html>
```