three+webgl实现逼真3a级港口拖船拖运货物游戏代码
代码语言:html
所属分类:游戏
代码描述:
three+webgl实现逼真3a级港口拖船拖运货物游戏代码,在海上货物沉下去之前操控小船拉货物当塔吊下面。
代码标签: three webgl 逼真 3a 级 港口 马头 第一 人称 射击 游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"></head><body><title>Undertow</title>
<meta name="claude:viewport-fit-sides" content="cover">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Big+Shoulders+Display:wght@500;700;900&family=IBM+Plex+Mono:wght@400;500&family=Barlow+Condensed:wght@400;500;600&display=swap">
<style>
:root {
color-scheme: dark;
--ink: #0b0d0f; --ink-2: #14181b; --bone: #e8e4da; --bone-dim: rgba(232, 228, 218, .64); --bone-faint: rgba(232, 228, 218, .24);
--signal: #ffb347; --signal-hot: #ffc977; --rust: #d2622a; --steel: #8d9aa3; --alarm: #ff5a40;
--line: rgba(232, 228, 218, .2); --plate: rgba(11, 13, 15, .6); --plate-solid: rgba(11, 13, 15, .9);
--f-display: 'Big Shoulders Display', 'Impact', 'Haettenschweiler', 'Arial Narrow', sans-serif;
--f-label: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
--f-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
--sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
--sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
--gl: max(16px, env(safe-area-inset-left, 0px)); --gr: max(16px, env(safe-area-inset-right, 0px));
--shadow: 0 0 2px rgba(0, 0, 0, .75), 0 1px 5px rgba(0, 0, 0, .55);
}
html, body { height: 100%; margin: 0; }
body { background: var(--ink); color: var(--bone); overflow: hidden; font-family: var(--f-label); -webkit-text-size-adjust: 100%; }
#app { position: fixed; inset: 0; overflow: hidden; background: var(--ink); -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#app *, #app *::before, #app *::after { box-sizing: border-box; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
#ui { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
/* ---- boot ---- */
#boot { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: var(--ink); transition: opacity .6s ease; z-index: 50;
padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
#boot.done { opacity: 0; pointer-events: none; }
.boot-mark { font-family: var(--f-display); font-weight: 900; font-size: clamp(40px, 9vw, 96px); letter-spacing: .16em; margin-right: -.16em; color: var(--bone); line-height: 1; }
.boot-sub { font-family: var(--f-mono); font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--steel); text-align: center; }
.boot-bar { width: min(320px, 70vw); height: 2px; background: #23282c; }
.boot-bar i { display: block; height: 100%; width: 0%; background: var(--signal); transition: width .25s ease; }
#fatal { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(10px + var(--sab)) max(16px, env(safe-area-inset-left, 0px)); font: 12px/1.4 var(--f-mono); color: #ffb4a8; background: rgba(40, 8, 4, .85); white-space: pre-wrap; z-index: 99; max-height: 40%; overflow: auto; pointer-events: auto; -webkit-user-select: text; user-select: text; }
/* ===================================================================== HUD */
.hud { position: absolute; inset: 0; opacity: 0; transition: opacity .35s ease; pointer-events: none; color: var(--bone); text-shadow: var(--shadow); }
.hud.on { opacity: 1; }
.h-k { font: 600 11px/1 var(--f-label); letter-spacing: .26em; text-transform: uppercase; color: rgba(232, 228, 218, .72); }
/* compass */
.h-compass { position: absolute; top: calc(12px + var(--sat)); left: 50%; width: min(420px, calc(100vw - var(--gl) - var(--gr) - 8px)); height: 60px; transform: translateX(-50%); }
.h-tape-wrap { position: absolute; left: 0; right: 0; top: 0; height: 28px; overflow: hidden;
-webkit-mask-image: linear-gradient(90deg, transparent, #000 16%, #000 84%, transparent); mask-image: linear-gradient(90deg, transparent, #000 16%, #000 84%, transparent); }
.h-tape { position: absolute; left: 0; top: 0; height: 100%; width: 2168px; will-change: transform; }
.h-tape i { position: absolute; bottom: 0; width: 1px; margin-left: -.5px; background: var(--bone); box-shadow: 0 0 2px rgba(0, 0, 0, .6); }
.h-tape i.mn { height: 4px; opacity: .45; } .h-tape i.md { height: 7px; opacity: .8; } .h-tape i.mj { height: 10px; width: 2px; margin-left: -1px; }
.h-tape b { position: absolute; top: 0; transform: translateX(-50%); font-weight: 400; white-space: nowrap; }
.h-tape b.card { font: 700 16px/1 var(--f-display); letter-spacing: .04em; }
.h-tape b.ic { font: 600 11px/1.4 var(--f-label); color: var(--bone-dim); letter-spacing: .08em; }
.h-tape b.num { font: 400 9px/1.7 var(--f-mono); color: var(--bone-dim); }
.h-needle { position: absolute; left: 50%; top: 14px; width: 2px; height: 16px; margin-left: -1px; background: var(--signal); box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); }
.h-heading { position: absolute; left: 100%; top: 9px; margin-left: 6px; font: 500 11px/1 var(--f-mono); color: var(--bone-dim); letter-spacing: .06em; }
.h-cmarks { position: absolute; left: 50%; top: 33px; width: 0; height: 0; }
.h-cm { position: absolute; left: -24px; top: 0; width: 48px; text-align: center; will-change: transform; color: var(--signal); }
.h-cm i { display: block; width: 8px; height: 8px; margin: 0 auto 3px; border: 1.5px solid currentColor; transform: rotate(45deg); background: rgba(11, 13, 15, .5); }
.h-cm b { font: 700 13px/1 var(--f-display); letter-spacing: .06em; margin-right: 4px; }
.h-cm span { font: 400 10px/1 var(--f-mono); color: var(--bone); }
.h-cm.edge { opacity: .55; }
.h-cm.extract { color: var(--bone); } .h-cm.extract i { background: var(--bone); }
/* objective tracker */
.h-obj { position: absolute; top: calc(16px + var(--sat)); left: var(--gl); max-width: min(300px, 42vw); padding-left: 12px; border-left: 2px solid var(--signal); opacity: 0; transition: opacity .3s; }
.h-obj.has { opacity: 1; }
.h-obj-t { font: 600 20px/1.1 var(--f-label); letter-spacing: .05em; text-transform: uppercase; margin: 6px 0 9px; min-height: 22px; }
.h-relays { display: flex; align-items: center; gap: 5px; font: 600 11px/1 var(--f-label); letter-spacing: .22em; text-transform: uppercase; color: rgba(232, 228, 218, .72); }
.h-relays span { margin-right: 4px; }
.h-relays.tally i, .h-relays.tally b { display: none; } .h-relays.tally span { color: var(--bone); letter-spacing: .16em; }
.h-relays i { width: 9px; height: 9px; border: 1.5px solid var(--bone); box-shadow: 0 0 2px rgba(0, 0, 0, .6); }
.h-relays i.cut { background: var(--signal); border-color: var(--signal); }
.h-relays b { font: 500 11px/1 var(--f-mono); letter-spacing: .04em; color: var(--bone); margin-left: 5px; }
@keyframes objflash { 0% { border-left-color: var(--bone); } 100% { border-left-color: var(--signal); } }
.h-obj.flash { animation: objflash .9s ease-out; }
/* wave warning */
.h-warn { position: absolute; left: 50%; top: 21%; transform: translateX(-50%); white-space: nowrap; opacity: 0; color: var(--signal);
font: 700 clamp(20px, 3.6vw, 38px)/1 var(--f-display); letter-spacing: .24em; margin-right: -.24em; text-transform: uppercase; padding: 9px 0 8px; border-top: 1px solid currentColor; border-bottom: 1px solid currentColor; }
@keyframes warn { 0% { opacity: 0; letter-spacing: .5em; } 8% { opacity: 1; letter-spacing: .24em; } 14% { opacity: .35; } 20%, 82% { opacity: 1; } 100% { opacity: 0; } }
.h-warn.on { animation: warn 3.4s linear both; }
/* crosshair + hit marker */
.h-cross { position: absolute; left: 50%; top: 50%; width: 0; height: 0; transition: opacity .1s; }
.h-cross.off { opacity: 0; }
.h-cross i { position: absolute; left: 0; top: 0; background: var(--bone); box-shadow: 0 0 0 1px rgba(0, 0, 0, .4); transition: transform .06s linear; }
.h-cross .c-t, .h-cross .c-b { width: 2px; height: 9px; transform: translate3d(-50%, 0, 0); }
.h-cross .c-l, .h-cross .c-r { width: 9px; height: 2px; transform: translate3d(0, -50%, 0); }
.h-cross .c-dot { width: 2px; height: 2px; margin: -1px 0 0 -1px; opacity: .85; }
.h-hit { position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; transform: translate(-50%, -50%); opacity: 0; }
.h-hit i { position: absolute; width: 2px; height: 11px; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); }
.h-hit i:nth-child(1) { left: 3px; top: 0; transform: rotate(-45deg); } .h-hit i:nth-child(2) { right: 3px; top: 0; transform: rotate(45deg); }
.h-hit i:nth-child(3) { left: 3px; bottom: 0; transform: rotate(45deg); } .h-hit i:nth-child(4) { right: 3px; bottom: 0; transform: rotate(-45deg); }
.h-hit.weak i { background: var(--signal); } .h-hit.kill i { background: var(--alarm); width: 3px; }
/* damage direction */
.h-arcs { position: absolute; inset: 0; }
.h-arc { position: absolute; left: 50%; top: 50%; width: min(72vh, 94vw); aspect-ratio: 1; transform: translate(-50%, -50%); opacity: 0; will-change: transform, opacity; }
.h-arc svg { width: 100%; height: 100%; display: block; overflow: visible; }
.h-arc path { fill: none; stroke: var(--alarm); stroke-width: 4; opacity: .9; }
.h-arc path.tip { stroke-width: 2.5; }
/* interaction prompt */
.h-prompt { position: absolute; left: 50%; top: 61%; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; opacity: 0; transition: opacity .15s; white-space: nowrap; }
.h-prompt.on { opacity: 1; }
.h-prompt svg { width: 48px; height: 48px; flex: none; }
.h-prompt circle { fill: none; stroke-width: 3; }
.h-prompt .bg { stroke: var(--bone-faint); fill: rgba(11, 13, 15, .5); } .h-prompt .fg { stroke: var(--signal); }
.h-key { position: absolute; left: 0; top: 0; width: 48px; line-height: 48px; text-align: center; font: 700 19px/48px var(--f-display); letter-spacing: .04em; }
.h-key.wide { font-size: 12px; letter-spacing: .1em; }
.h-plabel { font: 600 16px/1 var(--f-label); letter-spacing: .14em; text-transform: uppercase; padding: 7px 10px 6px; background: var(--plate); border-left: 2px solid var(--signal); }
.h-prompt.busy .h-plabel { color: var(--signal); }
/* kill feed + transient message */
.h-feed { position: absolute; right: var(--gr); top: 31%; text-align: right; }
.h-fl { font: 500 13px/1.5 var(--f-label); letter-spacing: .18em; text-transform: uppercase; color: var(--bone-dim); transition: opacity .5s; }
.h-fl b { font-weight: 600; color: var(--bone); } .h-fl em { font-style: normal; color: var(--signal); margin-left: 10px; }
.h-fl.out { opacity: 0; }
.h-msg { position: absolute; left: 50%; bottom: calc(23% + var(--sab)); transform: translateX(-50%); max-width: calc(100vw - var(--gl) - var(--gr)); text-align: center; padding: 6px 10px; background: var(--plate);
font: 400 11px/1.4 var(--f-mono); letter-spacing: .08em; text-transform: uppercase; opacity: 0; transition: opacity .3s; }
.h-msg.on { opacity: 1; }
/* health (only while hurt) */
.h-health { position: absolute; left: var(--gl); bottom: calc(22px + var(--sab)); opacity: 0; transition: opacity .6s; }
.h-health.on { opacity: 1; transition-duration: .12s; }
.h-hp-row { display: flex; align-items: flex-end; gap: 10px; margin-top: 6px; }
.h-hp-n { font: 700 34px/.82 var(--f-display); letter-spacing: .02em; min-width: 1.6em; }
.h-hp-bar { display: flex; gap: 3px; padding-bottom: 2px; }
.h-hp-bar i { width: 15px; height: 5px; background: var(--bone); box-shadow: 0 0 2px rgba(0, 0, 0, .6); }
.h-hp-bar i.off { background: transparent; box-shadow: inset 0 0 0 1px var(--bone-faint); }
.h-health.crit .h-hp-n { color: var(--alarm); } .h-health.crit .h-hp-bar i:not(.off) { background: var(--alarm); }
/* ammo */
.h-ammo { position: absolute; right: var(--gr); bottom: calc(20px + var(--sab)); text-align: right; }
.h-cue { height: 16px; font: 600 12px/16px var(--f-label); letter-spacing: .26em; margin-right: -.26em; text-transform: uppercase; color: var(--signal); opacity: 0; }
.h-cue.on { opacity: 1; } .h-cue.urgent { color: var(--alarm); animation: blink .7s steps(2, jump-none) infinite; }
@keyframes blink { 0% { opacity: 1; } 100% { opacity: .35; } }
.h-ammo-row { display: flex; align-items: flex-end; justify-content: flex-end; gap: 8px; }
.h-ammo-n { font: 700 76px/.8 var(--f-display); letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.h-ammo-r { font: 500 15px/1 var(--f-mono); color: var(--bone); padding-bottom: 3px; }
.h-ammo-r::before { content: '/ '; color: var(--bone-dim); }
.h-ammo.low .h-ammo-n { color: var(--signal); }
.h-pips { display: flex; justify-content: flex-end; gap: 2px; margin: 9px 0 7px; }
.h-pips i { width: 3px; height: 11px; background: var(--bone); box-shadow: 0 0 2px rgba(0, 0, 0, .5); }
.h-pips i.off { background: var(--bone-faint); box-shadow: none; }
.h-ammo.low .h-pips i:not(.off) { background: var(--signal); }
.h-wname { font: 600 11px/1 var(--f-label); letter-spacing: .28em; margin-right: -.28em; text-transform: uppercase; color: rgba(232, 228, 218, .82); }
.h-alt { margin-top: 7px; font: 500 11px/1 var(--f-mono); letter-spacing: .06em; color: var(--bone-dim); white-space: nowrap; }
.h-alt b { font-weight: 500; color: rgba(232, 228, 218, .82); } .h-alt kbd { margin-right: 6px; }
.h-alt:empty { display: none; }
/* world-space objective diamonds */
.h-marks { position: absolute; inset: 0; transition: opacity .15s; } .h-marks.off { opacity: 0; }
.h-wm { position: absolute; left: 0; top: 0; width: 0; height: 0; color: var(--signal); will-change: transform; opacity: .78; transition: opacity .25s; }
.h-wm.dim { opacity: .22; }
.h-wm i { position: absolute; left: -5px; top: -5px; width: 10px; height: 10px; border: 1.5px solid currentColor; transform: rotate(45deg); background: rgba(11, 13, 15, .45); box-shadow: 0 0 3px rgba(0, 0, 0, .5); }
.h-wm b { position: absolute; left: -30px; width: 60px; top: -24px; text-align: center; font: 700 12px/1 var(--f-display); letter-spacing: .08em; }
.h-wm span { position: absolute; left: -30px; width: 60px; top: 11px; text-align: center; font: 400 10px/1 var(--f-mono); color: var(--bone); }
.h-wm.offscreen { opacity: .7; } .h-wm.offscreen i { left: -5px; top: -5px; width: 10px; height: 10px; } .h-wm.offscreen b { top: -24px; font-size: 12px; }
.h-wm.near { opacity: 0; }
.h-wm.extract { color: var(--bone); } .h-wm.extract i { background: var(--bone); }
/* ===================================================================== radio subtitles */
.comms { position: absolute; left: 50%; bottom: calc(15% + var(--sab)); transform: translateX(-50%); width: min(620px, calc(100vw - var(--gl) - var(--gr))); text-align: center; opacity: 0; transition: opacity .3s; text-shadow: var(--shadow); }
.comms.on { opacity: 1; }
.comms-who { display: block; font: 600 11px/1 var(--f-label); letter-spacing: .34em; margin-right: -.34em; text-transform: uppercase; color: var(--signal); margin-bottom: 6px; }
.comms-t { display: inline; font: 500 19px/1.3 var(--f-label); letter-spacing: .02em; color: var(--bone); background: var(--plate); box-decoration-break: clone; -webkit-box-decoration-break: clone; padding: 2px 8px; }
/* ===================================================================== touch controls */
.touch { position: absolute; inset: 0; display: none; pointer-events: none; }
.touch.on { display: block; }
.t-stick { position: absolute; left: 0; top: 0; width: 0; height: 0; opacity: 0; transition: opacity .12s; }
.t-stick.on { opacity: 1; }
.t-ring { position: absolute; left: -58px; top: -58px; width: 116px; height: 116px; border-radius: 50%; border: 1.5px solid rgba(232, 228, 218, .5); background: rgba(11, 13, 15, .18); }
.t-nub { position: absolute; left: -24px; top: -24px; width: 48px; height: 48px; border-radius: 50%; background: rgba(232, 228, 218, .3); border: 1.5px solid rgba(232, 228, 218, .7); }
.t-btn { position: absolute; pointer-events: auto; touch-action: none; border-radius: 50%; border: 1.5px solid rgba(232, 228, 218, .55); background: rgba(11, 13, 15, .38); color: var(--bone);
font: 600 12px/1 var(--f-label); letter-spacing: .14em; padding: 0; margin: 0; -webkit-appearance: none; appearance: none; }
.t-btn span { pointer-events: none; margin-right: -.14em; }
.t-btn.active { background: rgba(255, 179, 71, .32); border-color: var(--signal); color: var(--signal); }
.t-fire { width: 86px; height: 86px; right: calc(20px + var(--sar)); bottom: calc(62px + var(--sab)); font-size: 14px; }
.t-ads { width: 60px; height: 60px; right: calc(120px + var(--sar)); bottom: calc(34px + var(--sab)); }
.t-jump { width: 60px; height: 60px; right: calc(20px + var(--sar)); bottom: calc(164px + var(--sab)); }
.t-reload { width: 54px; height: 54px; right: calc(108px + var(--sar)); bottom: calc(126px + var(--sab)); }
.t-swap { width: 54px; height: 54px; right: calc(92px + var(--sar)); bottom: calc(196px + var(--sab)); font-size: 10px; }
.t-interact { width: 68px; height: 68px; right: calc(186px + var(--sar)); bottom: calc(96px + var(--sab)); border-color: var(--signal); color: var(--signal); display: none; }
.t-interact.on { display: block; }
.t-pause { width: 42px; height: 42px; border-radius: 0; right: calc(12px + var(--sar)); top: calc(12px + var(--sat)); letter-spacing: .2em; }
/* touch layout: keep the thumbs' corners clear */
.is-touch .h-ammo { bottom: auto; top: calc(64px + var(--sat)); }
.is-touch .h-ammo-n { font-size: 44px; } .is-touch .h-pips { margin: 6px 0 5px; } .is-touch .h-pips i { height: 7px; width: 2px; }
.is-touch .h-health { bottom: auto; top: calc(128px + var(--sat)); }
.is-touch .h-feed { top: calc(150px + var(--sat)); }
.is-touch .comms { bottom: auto; top: calc(27% + var(--sat)); }
.is-touch .h-compass { width: min(300px, calc(100vw - var(--gl) - var(--gr) - 120px)); }
/* ===================================================================== menus */
.menu { position: absolute; inset: 0; pointer-events: none; color: var(--bone); }
.menu.open { pointer-events: auto; }
.menu h1, .menu h2, .menu h3, .menu p, .menu dl, .menu dd, .menu dt { margin: 0; padding: 0; }
.m-veil { position: absolute; inset: 0; opacity: 0; transition: opacity .5s ease; background: rgba(6, 8, 10, .62); }
.menu.open .m-veil { opacity: 1; }
/* title: a reading scrim on the text side only — the scene stays the picture */
.menu[data-screen="title"] .m-veil { background: linear-gradient(90deg, rgba(6, 8, 10, .82) 0%, rgba(6, 8, 10, .5) 38%, rgba(6, 8, 10, 0) 72%), linear-gradient(0deg, rgba(6, 8, 10, .7) 0%, rgba(6, 8, 10, 0) 46%); }
.menu[data-screen="dead"] .m-veil { background: rgba(6, 8, 10, .35); }
.m-bars i { position: absolute; left: 0; right: 0; height: calc(clamp(14px, 5.5vh, 52px) + var(--sat)); background: #000; top: 0; transform: translateY(-101%); transition: transform .7s cubic-bezier(.2, .7, .2, 1); }
.m-bars i + i { top: auto; bottom: 0; height: calc(clamp(14px, 5.5vh, 52px) + var(--sab)); transform: translateY(101%); }
.menu[data-screen="title"] .m-bars i { transform: none; }
.m-screen { position: absolute; display: none; }
.menu[data-screen="title"] .m-title { display: flex; }
.menu[data-screen="paused"] [data-s="paused"], .menu[data-screen="dead"] [data-s="dead"], .menu[data-screen="complete"] [data-s="complete"] { display: block; }
/* ---- title ---- */
.m-title { inset: 0; align-items: flex-end; justify-content: space-between; gap: 32px;
padding: calc(clamp(14px, 5.5vh, 52px) + var(--sat) + 20px) max(var(--gr), 4.5vw) calc(clamp(14px, 5.5vh, 52px) + var(--sab) + clamp(18px, 5vh, 56px)) max(var(--gl), 5.5vw); }
.m-title-main { min-width: 0; flex: 1 1 auto; }
.m-eyebrow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font: 600 13px/1.2 var(--f-label); letter-spacing: .24em; text-transform: uppercase; }
.m-tag { font: 900 15px/1 var(--f-display); letter-spacing: .06em; color: var(--ink); background: var(--signal); padding: 4px 7px 3px; }
.m-dim { color: var(--bone-dim); }
.m-word { font: 900 clamp(52px, 15.5vw, 208px)/.8 var(--f-display) !important; letter-spacing: .15em !important; margin: clamp(10px, 2vh, 22px) -.15em clamp(12px, 2.2vh, 24px) -.035em !important; color: var(--bone); white-space: nowrap; text-shadow: 0 2px 30px rgba(0, 0, 0, .35); }
.m-premise { position: relative; padding-top: 16px !important; border-top: 1px solid var(--line); font: 500 clamp(17px, 1.55vw, 22px)/1.3 var(--f-label); letter-spacing: .03em; color: rgba(232, 228, 218, .9); max-width: 40em; }
.m-premise::before { content: ''; position: absolute; left: 0; top: -2px; width: 72px; height: 3px; background: var(--signal); }
.m-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: clamp(16px, 3vh, 28px); }
.m-actions.col { flex-direction: column; align-items: stretch; margin-top: 22px; }
.m-pick { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px 14px; margin-top: clamp(12px, 2.2vh, 20px); max-width: 430px; }
.m-pick label { font: 500 11px/1 var(--f-label); letter-spacing: .24em; text-transform: uppercase; color: var(--steel); }
.m-pick .seg button { min-height: 34px; font-size: 12px; background: rgba(11, 13, 15, .45); }
.m-pick .seg button[aria-pressed="true"] { background: var(--bone); }
.m-pick-note { grid-column: 1 / -1; font: 400 11px/1.4 var(--f-mono); color: var(--steel); min-height: 15px; }
.m-dead [data-only] { display: none; } .menu[data-mode="holdout"] .m-dead [data-only="holdout"], .menu[data-mode="mission"] .m-dead [data-only="mission"] { display: flex; }
.m-note { margin-top: clamp(14px, 2.6vh, 26px) !important; font: 400 11px/1.5 var(--f-mono); letter-spacing: .04em; color: var(--steel); max-width: 52ch; }
/* Felix's note about the first, feedback-free build: floats top right, clear of the wordmark; dismissing folds it to a tab */
.m-callout { position: absolute; z-index: 2; top: calc(clamp(14px, 5.5vh, 52px) + var(--sat) + 14px); right: max(var(--gr), 4.5vw); width: min(360px, 22.5vw); text-align: left; display: flex; flex-direction: column;
max-height: calc(100% - clamp(14px, 5.5vh, 52px) * 2 - var(--sat) - var(--sab) - 28px); }
.m-callout[hidden] { display: none; }
.m-callout-tab { display: block; margin-left: auto; font: 500 11px/1 var(--f-label); letter-spacing: .22em; text-transform: uppercase; color: var(--bone); background: rgba(11, 13, 15, .6); border: 1px solid rgba(232, 228, 218, .42); border-radius: 0; min-height: 32px; padding: 1px 12px 0; cursor: pointer; }
.m-callout-tab::after { content: ' +'; color: var(--signal); }
.m-callout-tab:hover { border-color: var(--bone); }
.m-callout.open .m-callout-tab { display: none; }
.m-callout-body { display: none; overflow: auto; padding: 14px 16px 16px; background: rgba(8, 10, 12, .72); border: 1px solid var(--line); border-left: 3px solid var(--signal); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.m-callout.open .m-callout-body { display: block; }
.m-callout-x { float: right; width: 34px; height: 34px; margin: -12px -14px 2px 6px; background: none; border: 0; border-radius: 0; color: var(--bone-dim); font: 400 22px/1 var(--f-mono); cursor: pointer; }
.m-callout-x:hover { color: var(--bone); }
.m-callout-body p { margin: 0 0 10px !important; font: 400 12px/1.55 var(--f-mono); letter-spacing: .01em; color: rgba(232, 228, 218, .9); }
.m-callout-body .btn.small { width: 100%; min-height: 38px; margin-top: 2px; font-size: 13px; letter-spacing: .18em; padding: 2px 10px 0; }
@media (max-width: 1099px), (max-height: 599px) {
.m-callout { width: min(360px, calc(100vw - var(--gl) - var(--gr) - 24px)); top: calc(clamp(14px, 5.5vh, 52px) + var(--sat) + 10px); }
.m-callout-body { background: rgba(8, 10, 12, .93); }
}
.btn { font: 600 15px/1 var(--f-label); letter-spacing: .22em; text-transform: uppercase; color: var(--bone); background: rgba(11, 13, 15, .55); border: 1px solid rgba(232, 228, 218, .42);
border-radius: 0; min-height: 46px; padding: 2px 22px 0; cursor: pointer; text-align: center; -webkit-appearance: none; appearance: none; transition: background .12s, border-color .12s, color .12s; }
.btn:hover { border-color: var(--bone); background: rgba(232, 228, 218, .12); }
.btn:active { background: rgba(232, 228, 218, .22); }
.btn.primary { background: var(--signal); border-color: var(--signal); color: var(--ink); font-size: 18px; font-weight: 600; letter-spacing: .3em; min-height: 52px; padding: 2px 40px 0 44px; }
.btn.primary:hover { background: var(--signal-hot); border-color: var(--signal-hot); }
.btn.small { min-height: 34px; font-size: 12px; padding: 1px 14px 0; }
.m-actions.col .btn { text-align: left; padding-left: 18px; }
.menu button:focus-visible, .menu input:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; }
.menu.pad-nav button:focus, .menu.pad-nav input:focus { outline: 2px solid var(--signal); outline-offset: 3px; }
.menu.pad-nav .btn.primary:focus { outline-color: var(--bone); }
.btn.primary:focus-visible { outline-color: var(--bone); }
/* controls at a glance on the title (wide screens; the Controls button covers the rest) */
.m-legend { display: none; flex: none; text-align: right; text-shadow: var(--shadow); padding-bottom: 2px; }
.m-legend > div { display: flex; justify-content: flex-end; align-items: center; gap: 18px; margin-top: 9px; font: 500 12px/1 var(--f-label); letter-spacing: .16em; text-transform: uppercase; color: rgba(232, 228, 218, .78); white-space: nowrap; }
.m-legend kbd { margin-right: 3px; background: rgba(11, 13, 15, .45); }
.m-legend .lg-touch, .m-legend .lg-pad { margin-top: 13px; padding-top: 11px; border-top: 1px solid var(--line); color: var(--bone-dim); }
.m-legend .lg-pad + .lg-touch { margin-top: 9px; padding-top: 0; border-top: 0; }
.m-legend em { font-style: normal; color: var(--signal); letter-spacing: .26em; }
@media (min-width: 1180px) and (min-height: 600px) { .m-legend { display: block; } }
.keys > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 3px 0; }
.keys dt { font: 500 12px/1.3 var(--f-label); letter-spacing: .16em; text-transform: uppercase; color: var(--steel); white-space: nowrap; }
.keys dd { font: 500 13px/1.3 var(--f-label); letter-spacing: .04em; color: var(--bone); text-align: right; }
kbd { display: inline-block; font: 500 10px/1 var(--f-mono); color: var(--bone); border: 1px solid rgba(232, 228, 218, .45); padding: 3px 4px 2px; margin: 0 1px; min-width: 18px; text-align: center; text-transform: uppercase; }
/* ---- cards: paused / dead / debrief ---- */
.m-card { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(430px, calc(100vw - var(--gl) - var(--gr))); max-height: calc(100vh - 24px - var(--sat) - var(--sab)); overflow: auto;
padding: 26px 26px 24px; background: var(--plate-solid); border: 1px solid var(--line); border-top: 3px solid var(--signal); }
.m-card.m-dead { border-top-color: var(--alarm); }
.m-k { font: 600 12px/1 var(--f-label); letter-spacing: .28em; text-transform: uppercase; color: var(--steel); }
.m-h { font: 900 clamp(40px, 11vw, 62px)/.86 var(--f-display) !important; letter-spacing: .08em; text-transform: uppercase; margin: 10px 0 12px !important; }
.m-dead .m-h { color: var(--alarm); }
.m-debrief .m-h { font-size: clamp(30px, 8.6vw, 44px) !important; white-space: nowrap; }
.m-line { font: 400 11px/1.5 var(--f-mono); letter-spacing: .04em; color: var(--steel); min-height: 1px; }
.m-stats > div { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 9px 0 8px; border-top: 1px solid var(--line); }
.m-stats > div:last-child { border-bottom: 1px solid var(--line); }
.m-stats dt { font: 500 13px/1 var(--f-label); letter-spacing: .18em; text-transform: uppercase; color: var(--steel); }
.m-stats dd { font: 500 16px/1 var(--f-mono); color: var(--bone); }
.m-rating { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; margin: 4px 0 12px; }
.m-rating span { font: 500 13px/1 var(--f-label); letter-spacing: .18em; text-transform: uppercase; color: var(--steel); }
.m-rating b { font: 900 46px/.9 var(--f-display); letter-spacing: .08em; text-transform: uppercase; color: var(--signal); }
/* ---- settings / controls panel ---- */
.panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); display: flex; flex-direction: column; background: rgba(11, 13, 15, .95); border-left: 1px solid var(--line);
padding: calc(10px + var(--sat)) 0 var(--sab); z-index: 5; }
.panel[hidden] { display: none; }
.panel:focus { outline: none; }
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px max(20px, var(--sar)) 0 22px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 22px; }
.tab { font: 600 15px/1 var(--f-label); letter-spacing: .22em; text-transform: uppercase; color: var(--steel); background: none; border: 0; border-bottom: 3px solid transparent; border-radius: 0; padding: 14px 0 12px; cursor: pointer; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--bone); border-bottom-color: var(--signal); }
.tab:hover { color: var(--bone); }
.panel-b { flex: 1 1 auto; overflow-y: auto; padding: 6px max(20px, var(--sar)) 24px 22px; -webkit-overflow-scrolling: touch; }
.panel-b[hidden] { display: none; }
.panel-b h3 { font: 600 11px/1 var(--f-label); letter-spacing: .26em; text-transform: uppercase; color: var(--steel); margin: 20px 0 8px !important; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.panel-note { font: 400 11px/1.6 var(--f-mono); letter-spacing: .02em; color: var(--steel); margin-top: 14px !important; }
.row { padding: 15px 0 16px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.row[hidden] { display: none; }
.row .btn.small { justify-self: start; min-height: 38px; }
.row label { font: 600 13px/1 var(--f-label); letter-spacing: .2em; text-transform: uppercase; color: var(--bone); }
.seg { display: flex; }
.seg button { flex: 1 1 0; min-width: 0; min-height: 40px; font: 600 13px/1 var(--f-label); letter-spacing: .16em; text-transform: uppercase; color: var(--bone-dim); background: transparent; border: 1px solid rgba(232, 228, 218, .35); border-radius: 0; margin-left: -1px; padding: 1px 0 0; cursor: pointer; }
.seg button:first-child { margin-left: 0; }
.seg button:hover { color: var(--bone); }
.seg button[aria-pressed="true"] { background: var(--bone); border-color: var(--bone); color: var(--ink); position: relative; }
.slider { display: flex; align-items: center; gap: 14px; }
.slider output { font: 500 13px/1 var(--f-mono); color: var(--bone); min-width: 5ch; text-align: right; }
.slider input { flex: 1 1 auto; min-width: 0; height: 28px; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
.slider input::-webkit-slider-runnable-track { height: 2px; background: rgba(232, 228, 218, .35); }
.slider input::-moz-range-track { height: 2px; background: rgba(232, 228, 218, .35); }
.slider input::-webkit-slider-thumb { -webkit-appearance: none; width: 10px; height: 22px; margin-top: -10px; background: var(--signal); border: 0; border-radius: 0; }
.slider input::-moz-range-thumb { width: 10px; height: 22px; background: var(--signal); border: 0; border-radius: 0; }
.toggle { display: inline-flex; align-items: center; gap: 12px; justify-self: start; background: none; border: 0; padding: 4px 0; color: var(--bone); cursor: pointer; font: 500 13px/1 var(--f-mono); }
.toggle i { position: relative; width: 44px; height: 22px; border: 1px solid rgba(232, 228, 218, .45); }
.toggle i::after { content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 14px; background: var(--bone-dim); transition: transform .12s, background .12s; }
.toggle[aria-pressed="true"] i { border-color: var(--signal); } .toggle[aria-pressed="true"] i::after { transform: translateX(20px); background: var(--signal); }
/* ---- intro location card ---- */
.loc-card { position: absolute; left: max(var(--gl), 5.5vw); bottom: calc(28vh + var(--sab)); padding-left: 16px; opacity: 0; transition: opacity .5s; text-shadow: var(--shadow); max-width: calc(100vw - var(--gl) - var(--gr) - 16px); }
.loc-card i { position: absolute; left: 0; top: 2px; bottom: 2px; width: 3px; background: var(--signal); }
.loc-card b { display: block; font: 700 clamp(19px, 3vw, 34px)/1.05 var(--f-display); letter-spacing: .16em; text-transform: uppercase; }
.loc-card span { display: block; margin-top: 7px; font: 400 11px/1.4 var(--f-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--bone-dim); }
@keyframes locin { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 -2% 0 0); } }
.loc-card.on { opacity: 1; } .loc-card.on b { animation: locin 1.1s steps(28, end) both; }
/* ---- narrow screens (phones, portrait) ---- */
@media (max-width: 760px) {
.h-obj { top: calc(78px + var(--sat)); max-width: 62vw; } .h-obj-t { font-size: 17px; }
.h-heading { display: none; }
.h-ammo-n { font-size: 56px; }
.is-touch .h-ammo { top: calc(78px + var(--sat)); }
.is-touch .h-health { top: calc(150px + var(--sat)); }
.m-title { padding-left: var(--gl); padding-right: var(--gr); }
.m-word { font-size: clamp(52px, 20vw, 150px) !important; }
.m-eyebrow { font-size: 11px; letter-spacing: .2em; }
.m-actions .btn.primary { flex: 1 1 100%; }
.m-actions:not(.col) .btn:not(.primary) { flex: 1 1 0; padding-left: 8px; padding-right: 8px; }
.m-card { padding: 22px 20px 20px; }
.comms-t { font-size: 17px; }
}
@media (max-height: 520px) {
.m-word { font-size: clamp(40px, 20vh, 120px) !important; margin-top: 8px !important; margin-bottom: 10px !important; }
.m-premise { padding-top: 10px !important; } .m-actions { margin-top: 12px; } .m-note { margin-top: 10px !important; }
.btn.primary { min-height: 44px; } .btn { min-height: 40px; }
.m-card { padding: 16px 20px 16px; } .m-h { font-size: clamp(30px, 11vh, 62px) !important; margin: 6px 0 8px !important; }
.m-actions.col { margin-top: 12px; gap: 6px; } .m-stats > div { padding: 6px 0 5px; } .m-rating b { font-size: 34px; }
.h-prompt { top: 64%; }
}
/* ---- motion preferences ---- */
@media (prefers-reduced-motion: reduce) {
.menu *, .hud *, .comms, .loc-card, .loc-card *, #boot, .m-bars i { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
.h-warn.on { animation: none; opacity: 1; }
.h-cue.urgent { animation: none; }
}
/* UNDERTOW HUD — reuses the Saltline tokens (fonts, bone/signal palette) */
.ut-hide { display: none !important; }
#ut-hud { position: absolute; inset: 0; pointer-events: none; }
.ut-obj { position: absolute; left: var(--gl); top: calc(14px + var(--sat)); text-shadow: var(--shadow); }
.ut-ch { font: 500 11px/1 var(--f-mono); letter-spacing: .2em; color: var(--signal); }
.ut-ot { font: 700 26px/1.1 var(--f-display); letter-spacing: .04em; text-transform: uppercase; margin-top: 6px; }
.ut-os { font: 500 15px/1.2 var(--f-label); color: var(--bone-dim); letter-spacing: .04em; margin-top: 2px; }
.ut-timer { position: absolute; left: 50%; top: calc(12px + var(--sat)); transform: translateX(-50%); font: 900 40px/1 var(--f-display); letter-spacing: .06em; text-shadow: var(--shadow); }
.ut-timer.ut-urgent { color: var(--alarm); animation: utPulse 1s infinite; }
@keyframes utPulse { 50% { opacity: .55; } }
.ut-gauges { position: absolute; left: var(--gl); bottom: calc(16px + var(--sab)); display: grid; grid-template-columns: auto auto; gap: 6px 14px; align-items: end; padding: 10px 12px; background: var(--plate); border-left: 2px solid var(--signal); }
.ut-g { display: flex; align-items: center; gap: 8px; font: 500 10px/1 var(--f-mono); letter-spacing: .16em; color: var(--bone-dim); grid-column: 1; }
.ut-g span { width: 34px; }
.ut-bar { position: relative; display: block; width: 150px; height: 6px; background: rgba(232,228,218,.14); }
.ut-bar b { position: absolute; left: 0; top: 0; bottom: 0; background: var(--bone); transition: width .15s; }
.ut-heat b { background: var(--signal); }
.ut-bar.ut-low b { background: var(--alarm); animation: utPulse .5s infinite; }
.ut-bar em { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--alarm); }
.ut-kn { grid-column: 2; grid-row: 1 / span 2; display: flex; flex-direction: column; align-items: flex-end; }
.ut-kn b { font: 900 38px/0.9 var(--f-display); }
.ut-kn span { font: 500 10px/1 var(--f-mono); letter-spacing: .2em; color: var(--bone-dim); }
.ut-tel { position: absolute; right: -16px; bottom: 6px; width: 4px; height: 76px; background: rgba(232,228,218,.14); }
.ut-tel i { position: absolute; left: -4px; top: 35px; width: 12px; height: 6px; background: var(--signal); }
.ut-tow { position: absolute; left: 50%; bottom: calc(118px + var(--sab)); transform: translateX(-50%); display: flex; align-items: center; gap: 10px; font: 500 11px/1 var(--f-mono); letter-spacing: .2em; color: var(--bone-dim); padding: 9px 12px; background: var(--plate); }
.ut-tow .ut-bar { width: min(300px, 40vw); height: 8px; }
.ut-tow .ut-bar b { background: var(--signal-hot); transition: none; }
#ut-radar { position: absolute; right: var(--gr); bottom: calc(16px + var(--sab)); width: 170px; height: 170px; }
.ut-prompt { position: absolute; left: 50%; bottom: calc(170px + var(--sab)); transform: translateX(-50%); font: 600 18px/1 var(--f-label); letter-spacing: .12em; text-transform: uppercase; padding: 8px 14px; background: var(--plate-solid); border: 1px solid var(--signal); color: var(--signal-hot); }
#ut-marks { position: absolute; inset: 0; }
.ut-mk { position: absolute; left: 0; top: 0; margin: -7px 0 0 -7px; width: 14px; height: 14px; font: 500 10px/1 var(--f-mono); color: var(--bone); text-shadow: var(--shadow); white-space: nowrap; }
.ut-mk::before { content: ''; position: absolute; left: 2px; top: 2px; width: 9px; height: 9px; border: 1.5px solid currentColor; transform: rotate(45deg); }
.ut-mk { text-indent: 18px; }
.ut-mk.tow { color: var(--signal-hot); }
.ut-mk.lane { color: var(--signal); }
.ut-mk.urgent { color: var(--alarm); animation: utPulse .6s infinite; }
.ut-mk.goal { color: #8fe0a0; font-weight: 600; letter-spacing: .14em; }
.ut-mk.goal::before { border-radius: 50%; transform: none; }
.ut-mk.gate { color: var(--signal); }
.ut-mk.ferry { color: var(--bone); letter-spacing: .14em; }
.ut-mk.off { opacity: .7; }
.ut-radio { position: absolute; left: 50%; top: calc(112px + var(--sat)); transform: translate(-50%, -8px); max-width: min(620px, 86vw); padding: 10px 16px 12px; background: var(--plate-solid); border-left: 2px solid var(--signal); opacity: 0; transition: opacity .25s, transform .25s; }
.ut-radio.on { opacity: 1; transform: translate(-50%, 0); }
.ut-who { font: 500 10px/1 var(--f-mono); letter-spacing: .22em; color: var(--signal); margin-bottom: 6px; }
.ut-say { font: 500 18px/1.3 var(--f-label); letter-spacing: .02em; min-height: 1.3em; }
.ut-flash { position: absolute; inset: 0; opacity: 0; }
.ut-flash.ut-hit { animation: utFlash .5s; background: radial-gradient(ellipse at center, transparent 40%, rgba(255,90,64,.45)); }
.ut-flash.ut-warn { animation: utFlash .7s; background: radial-gradient(ellipse at center, transparent 50%, rgba(255,179,71,.4)); }
.ut-flash.ut-good { animation: utFlash 1s; background: radial-gradient(ellipse at center, transparent 45%, rgba(143,224,160,.3)); }
@keyframes utFlash { 0% { opacity: 1; } 100% { opacity: 0; } }
.ut-card { position: absolute; left: 0; right: 0; top: 34%; text-align: center; opacity: 0; text-shadow: var(--shadow); }
.ut-card.on { animation: utCard 4.2s ease forwards; }
@keyframes utCard { 0% { opacity: 0; letter-spacing: .4em; } 15%, 70% { opacity: 1; letter-spacing: .14em; } 100% { opacity: 0; letter-spacing: .14em; } }
.ut-cn { font: 500 14px/1 var(--f-mono); letter-spacing: .4em; color: var(--signal); }
.ut-ct { font: 900 clamp(44px, 8vw, 92px)/1 var(--f-display); text-transform: uppercase; letter-spacing: inherit; margin-top: 10px; }
.ut-screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 26px; padding: 0 calc(var(--gl) + 4vw); pointer-events: auto; background: linear-gradient(90deg, rgba(11,13,15,.86) 0%, rgba(11,13,15,.55) 45%, rgba(11,13,15,0) 75%); }
.ut-mark { font: 900 clamp(56px, 11vw, 132px)/.86 var(--f-display); letter-spacing: .1em; color: var(--bone); text-shadow: 0 4px 30px rgba(0,0,0,.5); }
.ut-mark.ut-sm { font-size: clamp(44px, 7vw, 84px); }
.ut-red { color: var(--alarm); }
.ut-why { font: 500 20px/1.3 var(--f-label); color: var(--bone-dim); max-width: 520px; }
.ut-menu, .ut-chapters { display: flex; flex-direction: column; gap: 8px; width: min(320px, 80vw); }
.ut-screen button { font: 600 15px/1 var(--f-label); letter-spacing: .22em; text-transform: uppercase; text-align: left; color: var(--bone); background: var(--plate-solid); border: 1px solid var(--line); padding: 15px 18px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.ut-screen button:hover, .ut-screen button:focus-visible { border-color: var(--signal); color: var(--signal-hot); outline: none; }
.ut-screen button.ut-primary { background: var(--signal); color: var(--ink); border-color: var(--signal); }
.ut-screen button.ut-primary:hover { background: var(--signal-hot); color: var(--ink); }
.ut-screen button:disabled { opacity: .35; cursor: default; }
.ut-screen small { font: 500 11px/1 var(--f-mono); letter-spacing: .1em; opacity: .8; }
.ut-chapters button { padding: 11px 16px; font-size: 13px; }
.ut-keys { display: grid; grid-template-columns: repeat(4, auto 1fr); gap: 6px 10px; margin: 0; font: 500 11px/1.4 var(--f-mono); letter-spacing: .1em; color: var(--bone-dim); }
.ut-keys dt { color: var(--bone); background: rgba(232,228,218,.1); padding: 2px 6px; text-align: center; }
.ut-keys dd { margin: 0 14px 0 0; }
@media (max-width: 900px) { .ut-keys { grid-template-columns: repeat(2, auto 1fr); } }
@media (pointer: coarse) { .ut-keys { display: none; } }
.ut-stats { display: flex; gap: 34px; }
.ut-stats div { display: flex; flex-direction: column; gap: 4px; }
.ut-stats b { font: 900 54px/1 var(--f-display); }
.ut-stats span { font: 500 11px/1.2 var(--f-mono); letter-spacing: .14em; color: var(--bone-dim); text-transform: uppercase; max-width: 110px; }
#ut-touch { position: absolute; inset: 0; pointer-events: none; }
.ut-stick { position: absolute; left: calc(var(--gl) + 10px); bottom: calc(150px + var(--sab)); width: 120px; height: 120px; border-radius: 50%; border: 1px solid var(--line); background: rgba(11,13,15,.35); pointer-events: auto; touch-action: none; }
.ut-stick i { position: absolute; left: 40px; top: 40px; width: 40px; height: 40px; border-radius: 50%; background: var(--signal); opacity: .85; }
.ut-tb { position: absolute; right: calc(var(--gr) + 190px); width: 76px; height: 54px; pointer-events: auto; touch-action: none; font: 600 13px/1 var(--f-label); letter-spacing: .14em; color: var(--bone); background: var(--plate-solid); border: 1px solid var(--line); }
.ut-tb[data-k=hook] { bottom: calc(110px + var(--sab)); border-color: var(--signal); color: var(--signal-hot); }
.ut-tb[data-k=boost] { bottom: calc(46px + var(--sab)); }
.ut-tb[data-k=horn] { bottom: calc(174px + var(--sab)); }
@media (prefers-reduced-motion: reduce) { .ut-timer.ut-urgent, .ut-mk.urgent, .ut-bar.ut-low b { animation: none; } }
</style>
<div id="app">
<canvas id="view" tabindex="0"></canvas>
<div id="ui"></div>
<div id="boot">
<div class="boot-mark">UNDERTOW</div>
<div class="boot-sub" id="boot-msg">Lighting the harbour</div>
<div class="boot-bar"><i id="boot-fill"></i></div>
</div>
</div>
<script>
/* Harbour tug sound module. Pure Web Audio synthesis. */
window.UTAudio = function createAudio() {
'use strict';
var NAMES = ['resume', 'setMaster', 'setPaused', 'setEngine', 'setStorm', 'setTension', 'setKnock',
'ping', 'horn', 'ferryHorn', 'splash', 'thud', 'hookFire', 'hookLatch', 'ropeSnap', 'release',
'gust', 'shipGroan', 'radio', 'chime', 'success', 'fail'];
function noop() { var o = {}; NAMES.forEach(function (n) { o[n] = function () {}; }); return o; }
var AC = window.AudioContext || window.webkitAudioContext;
if (!AC) return noop();
try {
var ctx = new AC();
var R = Math.random;
function c(v, a, b) { v = +v; if (!isFinite(v)) v = a; return v < a ? a : v > b ? b : v; }
function now() { return ctx.currentTime; }
function gainN(v, dest) { var g = ctx.createGain(); g.gain.value = v; if (dest) g.connect(dest); return g; }
function filt(type, f, q, dest) {
var b = ctx.createBiquadFilter(); b.type = type; b.frequency.value = f;
if (q != null) b.Q.value = q; if (dest) b.connect(dest); return b;
}
function sm(p, v, tc) { p.setTargetAtTime(v, now(), tc || 0.1); }
function ramp(p, a, b, t, d) { p.setValueAtTime(a, t); p.exponentialRampToValueAtTime(Math.max(b, 0.001), t + d); }
/* master chain */
var master = gainN(0.8);
var comp = ctx.createDynamicsCompressor();
comp.threshold.value = -16; comp.knee.value = 12; comp.ratio.value = 5;
comp.attack.value = 0.005; comp.release.value = 0.2;
master.connect(comp); comp.connect(ctx.destination);
var sfx = gainN(1, master); /* one-shots */
var loops = gainN(1, master); /* continuous beds, ducked on pause */
/* noise buffers */
function mkBuf(kind) {
var n = ctx.sampleRate * 3, b = ctx.createBuffer(1, n, ctx.sampleRate), d = b.getChannelData(0), l = 0, i, w;
for (i = 0; i < n; i++) {
w = R() * 2 - 1;
if (kind) { l = (l + 0.02 * w) / 1.02; d[i] = l * 3.5; } else d[i] = w;
}
return b;
}
var white = mkBuf(0), brown = mkBuf(1);
function loopNoise(buf) {
var s = ctx.createBufferSource(); s.buffer = buf; s.loop = true;
s.start(0, R() * 2); return s;
}
function shape(k) {
var n = 256, cv = new Float32Array(n), i, x;
for (i = 0; i < n; i++) { x = i / (n / 2) - 1; cv[i] = Math.tanh(x * k); }
var w = ctx.createWaveShaper(); w.curve = cv; return w;
}
/* one-shot helpers */
function burst(t, dur, type, f0, f1, q, peak, dest, att) {
var s = ctx.createBufferSource(); s.buffer = white;
var f = filt(type, f0, q), g = ctx.createGain();
ramp(f.frequency, f0, f1, t, dur);
att = att || 0.005;
g.gain.setValueAtTime(0.0001, t);
g.gain.linearRampToValueAtTime(peak, t + att);
g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
s.connect(f); f.connect(g); g.connect(dest || sfx);
s.start(t, R() * 2); s.stop(t + dur + 0.05);
}
function tone(type, f0, f1, t, dur, peak, dest, att, lp) {
var o = ctx.createOscillator(), g = ctx.createGain(), out = g;
o.type = type; ramp(o.frequency, f0, f1, t, dur);
att = att || 0.005;
g.gain.setValueAtTime(0.0001, t);
g.gain.linearRampToValueAtTime(peak, t + att);
g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
o.connect(g);
if (lp) { g.connect(filt('lowpass', lp, 0.7, dest || sfx)); } else g.connect(dest || sfx);
o.start(t); o.stop(t + dur + 0.05);
}
/* ---------- engine ---------- */
var eng = gainN(0, loops);
var pulse = gainN(0.6, eng);
var lfo = ctx.createOscillator(); lfo.frequency.value = 6;
var lfoD = gainN(0.4, pulse.gain); lfo.connect(lfoD); lfo.start();
var eo1 = ctx.createOscillator(); eo1.type = 'sawtooth'; eo1.frequency.value = 40;
var eo2 = ctx.createOscillator(); eo2.type = 'triangle'; eo2.frequency.value = 80;
var eLP = filt('lowpass', 180, 0.8, pulse);
var eSh = shape(2.5);
var eo2g = gainN(0.5);
eo1.connect(eSh); eSh.connect(eLP); eo2.connect(eo2g); eo2g.connect(eLP);
var eoGain = gainN(0.9); eLP.disconnect(); eLP.connect(eoGain); eoGain.connect(pulse);
eo1.start(); eo2.start();
var eNoise = loopNoise(brown), eNF = filt('lowpass', 400, 0.7), eNG = gainN(0.05);
eNoise.connect(eNF); eNF.connect(eNG); eNG.connect(pulse);
/* grit + turbo */
var gritSh = shape(12), gritG = gainN(0), gritF = filt('lowpass', 500, 0.7);
eo1.connect(gritSh); gritSh.connect(gritF); gritF.connect(gritG); gritG.connect(pulse);
var turbo = ctx.createOscillator(); turbo.type = 'sine'; turbo.frequency.value = 600;
var turboG = gainN(0), turboF = filt('bandpass', 1200, 1.5);
turbo.connect(turboF); turboF.connect(turboG); turboG.connect(loops); turbo.start();
function setEngine(throttle, speed01, boost) {
var a = Math.abs(c(throttle, -1, 1)), s = c(speed01, 0, 1), b = boost ? 1 : 0;
var p = c(0.6 * a + 0.5 * s, 0, 1);
var f = 36 + 16 * p + 3 * b;
sm(eo1.frequency, f, 0.15); sm(eo2.frequency, f * 2.01, 0.15);
sm(lfo.frequency, 5 + 13 * p, 0.2);
sm(lfoD.gain, 0.4 - 0.12 * p, 0.2);
sm(eLP.frequency, 160 + 450 * p, 0.15);
sm(eNF.frequency, 300 + 1500 * p, 0.2);
sm(eNG.gain, 0.04 + 0.2 * p, 0.2);
sm(eng.gain, 0.16 + 0.4 * p, 0.15);
sm(gritG.gain, b ? 0.35 : 0, 0.25);
sm(turboG.gain, b ? 0.035 + 0.03 * p : 0, b ? 0.6 : 0.2);
sm(turbo.frequency, b ? 900 + 1800 * p : 500, 0.7);
sm(turboF.frequency, b ? 1200 + 1800 * p : 800, 0.7);
}
/* ---------- storm ---------- */
var storm = 0;
var wind = loopNoise(white), windF = filt('bandpass', 500, 0.9), windS = gainN(0.7), windG = gainN(0.05);
wind.connect(windF); windF.connect(windS); windS.connect(windG); windG.connect(loops);
var rain = loopNoise(white), rainF = filt('highpass', 3500, 0.5), rainG = gainN(0.05);
rain.connect(rainF); rainF.connect(rainG); rainG.connect(loops);
var sea = loopNoise(brown), seaF = filt('lowpass', 350, 0.6), seaS = gainN(0.7), seaG = gainN(0.08);
sea.connect(seaF); seaF.connect(seaS); seaS.connect(seaG); seaG.connect(loops);
function setStorm(level) {
storm = c(level, 0, 1); var l = storm;
sm(windG.gain, 0.02 + 0.3 * Math.pow(l, 1.4), 0.4);
sm(rainG.gain, 0.04 + 0.1 * l, 0.4);
sm(rainF.frequency, 3500 - 1500 * l, 0.4);
sm(seaG.gain, 0.06 + 0.2 * l, 0.5);
sm(seaF.frequency, 300 + 350 * l, 0.5);
}
setStorm(0);
/* ---------- tension ---------- */
var tension = 0, nextCreak = 0;
var tBus = gainN(1, loops);
function creak(u) {
var t = now() + 0.02, dur = 0.35 + R() * 0.6 + 0.3 * u, f = 90 + R() * 70 + 60 * u;
var o = ctx.createOscillator(); o.type = 'sawtooth';
o.frequency.setValueAtTime(f, t);
o.frequency.linearRampToValueAtTime(f * (0.7 + R() * 0.6), t + dur);
var fm = ctx.createOscillator(); fm.frequency.value = 18 + R() * 25;
var fmg = gainN(f * 0.25); fm.connect(fmg); fmg.connect(o.frequency);
var bp = filt('bandpass', 220 + R() * 250, 6), g = ctx.createGain();
var pk = 0.12 + 0.5 * u;
g.gain.setValueAtTime(0.0001, t);
g.gain.linearRampToValueAtTime(pk, t + dur * 0.3);
g.gain.linearRampToValueAtTime(pk * 0.6, t + dur * 0.7);
g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
o.connect(bp); bp.connect(g); g.connect(tBus);
o.start(t); fm.start(t); o.stop(t + dur + 0.05); fm.stop(t + dur + 0.05);
}
function setTension(t) { tension = c(t, 0, 1); }
/* ---------- knock SOS ---------- */
var K = [0, 0.2, 0.4, 1.0, 1.6, 2.2, 3.2, 3.4, 3.6], KLEN = 5.6;
var knockVol = 0, knockStart = null, knockIdx = 0, paused = false;
var kPan = ctx.createStereoPanner ? ctx.createStereoPanner() : null;
var kBus = gainN(1);
if (kPan) { kBus.connect(kPan); kPan.connect(loops); } else kBus.connect(loops);
function knock(t, v) {
burst(t, 0.05, 'bandpass', 1200, 500, 1.2, 0.5 * v, kBus, 0.002);
tone('sine', 190, 170, t, 0.28, 0.55 * v, kBus, 0.002);
tone('sine', 410, 380, t, 0.12, 0.15 * v, kBus, 0.002);
}
function setKnock(vol, pan) {
knockVol = c(vol, 0, 1);
if (kPan) sm(kPan.pan, c(pan, -1, 1), 0.05);
}
/* ---------- scheduler ---------- */
var nextSweep = 0;
function tick() {
try {
if (ctx.state !== 'running') return;
var t = now();
if (t >= nextSweep) {
nextSweep = t + 1.5 + R() * 2.5;
var l = storm;
sm(windF.frequency, 250 + 500 * l + R() * (300 + 900 * l), 0.9);
sm(windF.Q, 0.6 + R() * 1.5, 0.9);
sm(windS.gain, 0.35 + R() * 0.65, 1.2);
sm(seaS.gain, 0.3 + R() * 0.7, 1.6);
}
if (tension > 0.35 && t >= nextCreak && !paused) {
var u = (tension - 0.35) / 0.65;
creak(u);
nextCreak = t + (2.8 - 2.2 * u) * (0.5 + R());
}
if (knockVol < 0.003 || paused) { knockStart = null; return; }
if (knockStart === null) { knockStart = t + 0.05; knockIdx = 0; }
for (var n = 0; n < 12; n++) {
var tt = knockStart + K[knockIdx];
if (tt > t + 0.35) break;
if (tt >= t - 0.05) knock(Math.max(tt, t), knockVol);
if (++knockIdx >= K.length) { knockIdx = 0; knockStart += KLEN; }
}
} catch (e) {}
}
setInterval(tick, 100);
/* ---------- one-shots ---------- */
var echo = ctx.createDelay(1), echoFb = gainN(0.4), echoLP = filt('lowpass', 2200, 0.5), echoIn = gainN(1);
echo.delayTime.value = 0.29;
echoIn.connect(echo); echo.connect(echoLP); echoLP.connect(echoFb); echoFb.connect(echo);
echoLP.connect(gainN(0.6, sfx));
function ping(s) {
s = c(s, 0, 1); var t = now() + 0.01, f = 620 + 900 * s, pk = 0.12 + 0.25 * s;
var o = ctx.createOscillator(), g = ctx.createGain();
o.type = 'sine'; o.frequency.setValueAtTime(f * 1.04, t); o.frequency.exponentialRampToValueAtTime(f, t + 0.08);
g.gain.setValueAtTime(0.0001, t); g.gain.linearRampToValueAtTime(pk, t + 0.01);
g.gain.exponentialRampToValueAtTime(0.0001, t + 0.7);
o.connect(g); g.connect(sfx); g.connect(echoIn); o.start(t); o.stop(t + 0.75);
}
var hornG = gainN(0, sfx), hornLP = filt('lowpass', 1100, 0.8, hornG), hornOn = false;
[220, 277.2].forEach(function (f) {
var o = ctx.createOscillator(); o.type = 'sawtooth'; o.frequency.value = f;
var og = gainN(0.35, hornLP); o.connect(og); o.start();
var o2 = ctx.createOscillator(); o2.type = 'sawtooth'; o2.frequency.value = f * 1.004;
var og2 = gainN(0.25, hornLP); o2.connect(og2); o2.start();
});
function horn(on) {
on = !!on; if (on === hornOn) return; hornOn = on;
var t = now(), p = hornG.gain;
p.cancelScheduledValues(t); p.setValueAtTime(p.value, t);
p.linearRampToValueAtTime(on ? 0.5 : 0, t + (on ? 0.06 : 0.25));
}
function ferryHorn(d) {
d = c(d, 0, 1); var t = now() + 0.02, dur = 3, pk = 0.55 * (1 - 0.65 * d);
var g = ctx.createGain(), lp = filt('lowpass', 1400 - 1000 * d, 0.8, g);
g.gain.setValueAtTime(0.0001, t); g.gain.linearRampToValueAtTime(pk, t + 0.35);
g.gain.setValueAtTime(pk, t + 2.2); g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
g.connect(sfx);
[[90, 0.5], [90.7, 0.4], [180, 0.25], [270, 0.14], [135, 0.1]].forEach(function (h) {
var o = ctx.createOscillator(); o.type = 'sawtooth';
o.frequency.setValueAtTime(h[0] * 0.96, t); o.frequency.linearRampToValueAtTime(h[0], t + 0.3);
var og = gainN(h[1], lp); o.connect(og); o.start(t); o.stop(t + dur + 0.05);
});
}
function splash(i) {
i = c(i, 0, 1); var t = now() + 0.005;
burst(t, 0.35 + 0.4 * i, 'bandpass', 3500, 500, 0.8, 0.1 + 0.35 * i, sfx, 0.01);
burst(t, 0.2 + 0.2 * i, 'highpass', 2500, 1500, 0.5, 0.05 + 0.15 * i, sfx, 0.005);
}
function thud(i) {
i = c(i, 0, 1); var t = now() + 0.005;
tone('sine', 90, 32, t, 0.6, 0.3 + 0.6 * i, sfx, 0.004);
burst(t, 0.1, 'lowpass', 800, 200, 0.8, 0.2 + 0.4 * i, sfx, 0.002);
[[310, 0.12], [517, 0.08], [843, 0.05]].forEach(function (h) {
tone('square', h[0], h[0] * 0.98, t, 0.25 + 0.3 * i, h[1] * (0.3 + i), sfx, 0.002, 2500);
});
splash(i * 0.6);
}
function hookFire() {
var t = now() + 0.005;
burst(t, 0.4, 'bandpass', 400, 3200, 1.5, 0.3, sfx, 0.15);
}
function hookLatch() {
var t = now() + 0.005;
[0, 0.09].forEach(function (dt, k) {
burst(t + dt, 0.03, 'highpass', 3000, 3000, 0.5, 0.3, sfx, 0.001);
[[230, 0.3], [377, 0.22], [611, 0.16], [1010, 0.08]].forEach(function (h) {
tone('square', h[0], h[0] * 0.99, t + dt, 0.5 - 0.2 * k, h[1] * (k ? 1 : 0.7), sfx, 0.001, 3000);
});
});
tone('sine', 80, 50, t, 0.3, 0.4, sfx, 0.003);
}
function ropeSnap() {
var t = now() + 0.005;
burst(t, 0.06, 'highpass', 2500, 2500, 0.5, 0.7, sfx, 0.001);
burst(t + 0.02, 0.3, 'bandpass', 6000, 800, 2, 0.35, sfx, 0.002);
tone('sine', 140, 60, t, 0.2, 0.3, sfx, 0.002);
}
function release() {
var t = now() + 0.005;
tone('sine', 130, 65, t, 0.18, 0.4, sfx, 0.003);
burst(t, 0.03, 'lowpass', 1500, 500, 0.8, 0.25, sfx, 0.001);
burst(t + 0.08, 0.6, 'bandpass', 900, 250, 2.5, 0.18, sfx, 0.12);
}
function gust() {
var t = now() + 0.01, s = ctx.createBufferSource(); s.buffer = white;
var f = filt('bandpass', 300, 1.2), g = ctx.createGain();
f.frequency.setValueAtTime(300, t); f.frequency.exponentialRampToValueAtTime(1100, t + 0.9);
f.frequency.exponentialRampToValueAtTime(350, t + 2);
g.gain.setValueAtTime(0.0001, t); g.gain.linearRampToValueAtTime(0.3, t + 0.9);
g.gain.linearRampToValueAtTime(0.0001, t + 2.1);
s.connect(f); f.connect(g); g.connect(sfx); s.start(t, R() * 2); s.stop(t + 2.2);
}
function shipGroan() {
var t = now() + 0.01, dur = 2.5, g = ctx.createGain(), lp = filt('lowpass', 260, 4, g);
g.gain.setValueAtTime(0.0001, t); g.gain.linearRampToValueAtTime(0.5, t + 0.8);
g.gain.linearRampToValueAtTime(0.35, t + 1.6); g.gain.linearRampToValueAtTime(0.0001, t + dur);
g.connect(sfx);
[[46, 28], [62, 38]].forEach(function (h) {
var o = ctx.createOscillator(); o.type = 'sawtooth';
o.frequency.setValueAtTime(h[0], t); o.frequency.linearRampToValueAtTime(h[1], t + dur);
var m = ctx.createOscillator(); m.frequency.value = 7 + R() * 4;
var mg = gainN(3, o.frequency); m.connect(mg);
o.connect(lp); o.start(t); m.start(t); o.stop(t + dur + 0.05); m.stop(t + dur + 0.05);
});
lp.frequency.setValueAtTime(180, t); lp.frequency.linearRampToValueAtTime(320, t + 1.2);
lp.frequency.linearRampToValueAtTime(150, t + dur);
}
function radio() {
var t = now() + 0.005;
[0, 0.09].forEach(function (dt, k) {
burst(t + dt, 0.05, 'bandpass', k ? 2200 : 1600, k ? 1800 : 1400, 2, 0.25, sfx, 0.003);
});
tone('sine', 1100, 1100, t + 0.09, 0.04, 0.05, sfx, 0.003);
}
function chime() {
var t = now() + 0.005;
tone('sine', 1320, 1320, t, 0.14, 0.18, sfx, 0.003);
tone('sine', 2640, 2640, t, 0.08, 0.04, sfx, 0.003);
}
function success() {
var t = now() + 0.01;
[523.25, 659.25, 783.99].forEach(function (f, i) {
var d = i === 2 ? 0.7 : 0.35;
tone('triangle', f, f, t + i * 0.22, d, 0.25, sfx, 0.02, 3000);
tone('sine', f * 2, f * 2, t + i * 0.22, d * 0.8, 0.05, sfx, 0.02);
});
}
function fail() {
var t = now() + 0.01;
tone('triangle', 233, 228, t, 0.55, 0.3, sfx, 0.02, 1200);
tone('triangle', 155.6, 140, t + 0.4, 0.8, 0.32, sfx, 0.02, 900);
tone('sine', 77.8, 70, t + 0.4, 0.8, 0.2, sfx, 0.02);
}
/* ---------- control ---------- */
function resume() { if (ctx.state === 'suspended') { var p = ctx.resume(); if (p && p.catch) p.catch(function () {}); } }
function setMaster(v) { sm(master.gain, c(v, 0, 1) * 0.8, 0.05); }
function setPaused(p) { paused = !!p; sm(loops.gain, paused ? 0 : 1, 0.06); }
var impl = {
resume: resume, setMaster: setMaster, setPaused: setPaused, setEngine: setEngine, setStorm: setStorm,
setTension: setTension, setKnock: setKnock, ping: ping, horn: horn, ferryHorn: ferryHorn, splash: splash,
thud: thud, hookFire: hookFire, hookLatch: hookLatch, ropeSnap: ropeSnap, release: release, gust: gust,
shipGroan: shipGroan, radio: radio, chime: chime, success: success, fail: fail
};
var api = {};
NAMES.forEach(function (n) {
api[n] = function () { try { return impl[n].apply(null, arguments); } catch (e) {} };
});
setEngine(0, 0, false);
return api;
} catch (e) {
return noop();
}
};
</script>
<script>
/* UNDERTOW — a night-storm harbour tug game built on the Saltline engine's surfaces.
Exposes window.__UT = { input(G), game(G, L) } consumed by the patched engine boot. */
(() => {
'use strict';
const clamp = (v, a, b) => v < a ? a : v > b ? b : v;
const lerp = (a, b, t) => a + (b - a) * t;
const damp = (a, b, k, dt) => a + (b - a) * (1 - Math.exp(-k * dt));
const rand = (a, b) => a + Math.random() * (b - a);
const TAU = Math.PI * 2;
const wrapA = a => { while (a > Math.PI) a -= TAU; while (a < -Math.PI) a += TAU; return a; };
/* ------------------------------------------------------------------ input */
const KEYS = new Set(), PRESSED = new Set();
const ptr = { drag: false, dx: 0, dy: 0, wheel: 0, lastX: 0, lastY: 0, idle: 9 };
const touch = { on: false, sx: 0, sy: 0, x: 0, y: 0, id: null, boost: false };
function makeInput(G) {
const canvas = document.getElementById('view');
addEventListener('keydown', e => {
if (e.repeat) { if (!['KeyW','KeyS','KeyA','KeyD','ArrowUp','ArrowDown','ArrowLeft','ArrowRight','ShiftLeft','ShiftRight','KeyH'].includes(e.code)) return; }
if (!KEYS.has(e.code)) PRESSED.add(e.code);
KEYS.add(e.code);
if (['Space','ArrowUp','ArrowDown','ArrowLeft','ArrowRight'].includes(e.code)) e.preventDefault();
});
addEventListener('keyup', e => KEYS.delete(e.code));
addEventListener('blur', () => KEYS.clear());
canvas.addEventListener('pointerdown', e => {
if (e.pointerType === 'touch') return;
ptr.drag = true; ptr.lastX = e.clientX; ptr.lastY = e.clientY; canvas.setPointerCapture && canvas.setPointerCapture(e.pointerId);
});
canvas.addEventListener('pointermove', e => {
if (!ptr.drag) return;
ptr.dx += e.clientX - ptr.lastX; ptr.dy += e.clientY - ptr.lastY; ptr.lastX = e.clientX; ptr.lastY = e.clientY; ptr.idle = 0;
});
const up = () => { ptr.drag = false; };
canvas.addEventListener('pointerup', up); canvas.addEventListener('pointercancel', up);
canvas.addEventListener('wheel', e => { ptr.wheel += Math.sign(e.deltaY); e.preventDefault(); }, { passive: false });
canvas.addEventListener('contextmenu', e => e.preventDefault());
const n = () => {};
return {
move: { x: 0, y: 0 }, look: { dx: 0, dy: 0 }, fire: false, ads: false, sprint: false, crouch: false, locked: false, touch: false,
sensitivity: 1, device: 'kbm',
down: k => KEYS.has(k), pressed: k => PRESSED.has(k),
update: n, endFrame() { PRESSED.clear(); }, requestLock: n, exitLock: n,
};
}
/* ------------------------------------------------------------------ the game */
async function makeGame(G, L) {
const T = G.THREE, scene = G.scene, camera = G.camera;
const MUTE = !!(G.params.noaudio || G.params.mute);
const A = (!MUTE && window.UTAudio ? window.UTAudio() : null) || {};
const snd = (k, ...a) => { try { A[k] && A[k](...a); } catch (e) {} };
const SEA = L.K.seaY;
const seaH = (x, z) => { try { return G.ground.seaHeight(x, z); } catch (e) { return SEA; } };
const M = n => G.mats.get(n);
const EM = (hex, i) => G.mats.emissive(hex, i);
const mesh = (geo, mat, o) => L.mesh(geo, typeof mat === 'string' ? M(mat) : mat, o);
const box = (w, h, d, mat, anchor = 'center', o) => mesh(L.box(w, h, d, anchor), mat, o);
const rbox = (w, h, d, r, mat, anchor = 'center', o) => mesh(L.rbox(w, h, d, r, anchor), mat, o);
const at = (o, x, y, z, ry = 0) => { o.position.set(x, y, z); o.rotation.y = ry; return o; };
function cylGeo(rt, rb, h, seg = 16, open = false) {
const g = new T.CylinderGeometry(rt, rb, h, seg, 1, open);
const uv = g.attributes.uv, c = Math.PI * (rt + rb);
for (let i = 0; i < uv.count; i++) uv.setXY(i, uv.getX(i) * c, uv.getY(i) * h);
return g;
}
const cyl = (rt, rb, h, mat, seg, o) => mesh(cylGeo(rt, rb, h, seg), mat, o);
function torusGeo(R, r, rs = 8, ts = 24) {
const g = new T.TorusGeometry(R, r, rs, ts);
const uv = g.attributes.uv;
for (let i = 0; i < uv.count; i++) uv.setXY(i, uv.getX(i) * TAU * R, uv.getY(i) * TAU * r);
return g;
}
function tubeGeo(pts, r, closed = false, seg) {
const curve = new T.CatmullRomCurve3(pts, closed);
const len = curve.getLength();
const g = new T.TubeGeometry(curve, seg || Math.max(8, Math.round(len * 1.5)), r, 6, closed);
const uv = g.attributes.uv;
for (let i = 0; i < uv.count; i++) uv.setXY(i, uv.getX(i) * len, uv.getY(i) * TAU * r);
return g;
}
function hullGeo(outline, y0, y1, scale = 1) {
const s = new T.Shape();
outline.forEach(([x, z], i) => (i ? s.lineTo(x * scale, -z * scale) : s.moveTo(x * scale, -z * scale)));
const g = new T.ExtrudeGeometry(s, { depth: y1 - y0, bevelEnabled: false, curveSegments: 8 });
g.rotateX(-Math.PI / 2); g.translate(0, y0, 0);
g.computeVertexNormals();
return g;
}
function boatOutline(len, beam, bowLen, sternR = 0.5) {
const h = beam / 2, zs = -len / 2, zb = len / 2, zt = zb - bowLen, pts = [];
pts.push([-h + sternR, zs], [h - sternR, zs]);
for (let i = 1; i <= 4; i++) { const a = -Math.PI / 2 + i / 4 * Math.PI / 2; pts.push([h - sternR + Math.cos(a) * sternR, zs + sternR + Math.sin(a) * sternR]); }
pts.push([h, zt]);
for (let i = 1; i < 10; i++) { const t = i / 10; pts.push([h * Math.cos(t * Math.PI / 2) ** 0.9, zt + bowLen * Math.sin(t * Math.PI / 2)]); }
pts.push([0, zb]);
const n = pts.length; for (let i = n - 2; i >= 0; i--) pts.push([-pts[i][0], pts[i][1]]);
pts.pop();
return pts;
}
const sun = G.render.sun, sun0 = sun && sun.position.clone(), sunT0 = sun && sun.target.position.clone();
const root = new T.Group(); root.name = 'undertow'; scene.add(root);
const dyn = new T.Group(); root.add(dyn);
/* ---------- world layout (x east = seaward, quay at x=30) */
const W = {
berth: { x: 41, z: 34 },
pen: { x: 92, z: 52, r: 12 },
medic: { x: 44, z: 72, r: 8 },
lane: { z0: 88, z1: 118, x0: 58, x1: 270 },
bw: { x: 180, z0: -150, z1: 52 },
bounds: { x0: 33, x1: 290, z0: -150, z1: 190 },
};
/* ---------- lights from the engine's pool */
const pooled = [];
function poolLight(color, intensity, dist) {
const h = G.render.lightPool && G.render.lightPool.acquire && G.render.lightPool.acquire();
if (!h) return null;
h.light.color.set(color); h.light.intensity = intensity; if ('distance' in h.light) h.light.distance = dist || 30;
pooled.push(h); return h.light;
}
/* ---------- the tug Petrel */
function buildTug() {
const g = new T.Group(); g.name = 'petrel';
const ol = boatOutline(12, 4.6, 4.2, 0.9);
g.add(mesh(hullGeo(ol, -1.25, 0.15, 0.97), 'hull_red'));
g.add(mesh(hullGeo(ol, 0.15, 1.3, 1.0), 'hull_paint'));
const deck = mesh(hullGeo(ol, 1.28, 1.36, 0.93), 'diamond_plate'); g.add(deck);
const fpts = ol.filter((_, i) => i % 2 === 0).map(([x, z]) => new T.Vector3(x * 1.03, 1.05, z * 1.03));
g.add(mesh(tubeGeo(fpts, 0.2, true, 80), 'rubber'));
for (let i = -1; i <= 1; i++) { const t = mesh(torusGeo(0.42, 0.2), 'tire'); t.position.set(i * 0.75, 0.85 - Math.abs(i) * 0.1, 6.05 - Math.abs(i) * 0.25); t.rotation.y = i * 0.35; g.add(t); }
for (const s of [-1, 1]) for (let k = 0; k < 3; k++) { const t = mesh(torusGeo(0.38, 0.17), 'tire'); t.position.set(s * 2.42, 0.7, -2.5 + k * 2.4); t.rotation.y = Math.PI / 2; g.add(t); }
const wh = rbox(3.1, 2.2, 3.0, 0.12, 'paint_white', 'bottom'); at(wh, 0, 1.36, 1.0); g.add(wh);
const roof = rbox(3.5, 0.16, 3.4, 0.05, 'steel_dark', 'bottom'); at(roof, 0, 3.56, 1.0); g.add(roof);
const glassF = box(2.7, 0.7, 0.06, 'glass'); at(glassF, 0, 2.95, 2.52); glassF.rotation.x = -0.2; g.add(glassF);
for (const s of [-1, 1]) { const gs = box(0.06, 0.65, 2.2, 'glass'); at(gs, s * 1.56, 2.9, 1.0); g.add(gs); }
const lit = box(2.5, 0.5, 0.04, EM(0xffc27a, 1.6)); at(lit, 0, 2.9, 2.47); g.add(lit);
const mast = cyl(0.07, 0.09, 2.6, 'steel_galv', 8); at(mast, 0, 4.9, 0.6); g.add(mast);
const yard = box(1.6, 0.08, 0.08, 'steel_galv'); at(yard, 0, 5.6, 0.6); g.add(yard);
const nav = (c, x, y, z) => { const m = mesh(new T.SphereGeometry(0.09, 8, 6), EM(c, 6)); m.position.set(x, y, z); g.add(m); return m; };
nav(0xff3020, 1.6, 3.7, 2.4); nav(0x30ff70, -1.6, 3.7, 2.4); nav(0xfff4e0, 0, 6.25, 0.6); nav(0xfff4e0, 0, 1.6, -5.9);
const spot = cyl(0.22, 0.26, 0.4, 'steel_dark', 12); spot.rotation.x = Math.PI / 2; at(spot, 0.9, 3.85, 2.3); spot.rotation.x = Math.PI / 2; g.add(spot);
const lens = mesh(new T.CircleGeometry(0.2, 12), EM(0xfff1d0, 8)); lens.position.set(0.9, 3.85, 2.51); g.add(lens);
const fun = cyl(0.55, 0.65, 2.1, 'paint_orange', 16); at(fun, 0, 2.4, -1.4); fun.scale.set(1, 1, 1.3); g.add(fun);
const funTop = cyl(0.56, 0.56, 0.35, 'steel_dark', 16); at(funTop, 0, 3.6, -1.4); funTop.scale.set(1, 1, 1.3); g.add(funTop);
const band = cyl(0.57, 0.6, 0.3, 'paint_white', 16); at(band, 0, 2.9, -1.4); band.scale.set(1, 1, 1.3); g.add(band);
const drum = cyl(0.45, 0.45, 1.8, 'steel_worn', 14); drum.rotation.z = Math.PI / 2; at(drum, 0, 1.85, -3.3); drum.rotation.z = Math.PI / 2; g.add(drum);
const wrap = cyl(0.5, 0.5, 1.5, 'rope', 14); wrap.rotation.z = Math.PI / 2; at(wrap, 0, 1.85, -3.3); wrap.rotation.z = Math.PI / 2; g.add(wrap);
for (const s of [-1, 1]) { const p = box(0.25, 0.9, 0.25, 'steel_dark', 'bottom'); at(p, s * 0.5, 1.36, -5.0); g.add(p); }
const bar = box(1.4, 0.18, 0.2, 'paint_yellow'); at(bar, 0, 2.15, -5.0); g.add(bar);
const ring = mesh(torusGeo(0.32, 0.08), 'paint_orange'); ring.position.set(1.58, 2.3, 0.2); ring.rotation.y = Math.PI / 2; g.add(ring);
const rail = []; for (let i = 0; i < ol.length; i += 3) { const [x, z] = ol[i]; if (z > -1 && z < 3) continue; rail.push(new T.Vector3(x * 0.9, 2.15, z * 0.9)); }
for (const p of rail) { const post = cyl(0.03, 0.03, 0.8, 'steel_galv', 6); at(post, p.x, 1.75, p.z); g.add(post); }
g.userData.lens = lens;
return g;
}
/* ---------- the ferry Albatross */
function buildFerry() {
const g = new T.Group(); g.name = 'albatross';
const ol = boatOutline(66, 14, 18, 2.5);
g.add(mesh(hullGeo(ol, -3.2, 0.2, 0.98), 'hull_red'));
g.add(mesh(hullGeo(ol, 0.2, 5.2, 1), 'hull_paint'));
const sheer = mesh(hullGeo(ol, 5.2, 5.6, 1.01), 'paint_white'); g.add(sheer);
g.add(mesh(hullGeo(ol, 5.55, 5.65, 0.97), 'steel_worn'));
const win = EM(0xffd29a, 3.2), dark = M('glass_dirty');
const strips = [];
const tiers = [[50, 3.2, 12, 0, 5.6], [40, 2.8, 11, -3, 8.8], [26, 2.6, 10, -2, 11.6]];
for (const [l, h, w, z, y] of tiers) {
const t = rbox(w, h, l, 0.2, 'paint_white', 'bottom'); at(t, 0, y, z); g.add(t);
for (const s of [-1, 1]) { const st = box(0.05, 0.7, l - 4, win); at(st, s * (w / 2 + 0.03), y + h * 0.55, z); g.add(st); strips.push(st); }
}
const bridge = box(10.2, 1.1, 0.05, win); at(bridge, 0, 13.0, 11.03); g.add(bridge); strips.push(bridge);
const fun = rbox(3.2, 5, 5, 0.6, 'paint_blue', 'bottom'); at(fun, 0, 14.2, -10); g.add(fun);
const fb = rbox(3.3, 0.8, 5.1, 0.6, 'paint_white', 'bottom'); at(fb, 0, 17.2, -10); g.add(fb);
for (const s of [-1, 1]) for (let k = 0; k < 4; k++) { const lb = rbox(1.6, 1.4, 6, 0.5, 'paint_orange', 'bottom'); at(lb, s * 6.2, 8.9, -14 + k * 8); g.add(lb); }
const mast = cyl(0.15, 0.2, 7, 'steel_galv', 8); at(mast, 0, 17.7, 8); g.add(mast);
const nav = (c, x, y, z, s = 0.25) => { const m = mesh(new T.SphereGeometry(s, 8, 6), EM(c, 7)); m.position.set(x, y, z); g.add(m); return m; };
const navs = [nav(0xff3020, 5.4, 12.2, 10), nav(0x30ff70, -5.4, 12.2, 10), nav(0xfff4e0, 0, 21.3, 8), nav(0xfff4e0, 0, 6.5, -32.5)];
g.userData = { strips, win, dark, navs };
return g;
}
/* ---------- buoys */
function buildBuoy(color, light) {
const g = new T.Group();
g.add(at(cyl(0.75, 0.75, 1.2, 'paint_' + color, 14), 0, 0.2, 0));
g.add(at(cyl(0.12, 0.5, 1.6, 'paint_' + color, 10), 0, 1.6, 0));
g.add(at(mesh(torusGeo(0.78, 0.1), 'rubber'), 0, 0.5, 0)).rotation.x = Math.PI / 2;
const lm = mesh(new T.SphereGeometry(0.16, 8, 6), EM(light, 8)); lm.position.y = 2.5; g.add(lm);
g.userData.lamp = lm;
return g;
}
/* ---------- static scenery */
const buoys = [];
function addBuoy(color, light, x, z, period = 2, phase = 0) {
const b = buildBuoy(color, light); at(b, x, SEA, z); root.add(b);
buoys.push({ obj: b, x, z, period, phase, ph: Math.random() * TAU }); return b;
}
// channel markers: red on the north (left coming in) edge, green south
for (let x = W.lane.x0 + 12; x <= W.lane.x1; x += 26) {
addBuoy('red', 0xff3020, x, W.lane.z1 + 3, 3, x * 0.1);
addBuoy('green', 0x30ff70, x, W.lane.z0 - 3, 3, x * 0.1 + 1.5);
}
// breakwater
const bwGroup = new T.Group(); root.add(bwGroup);
for (let z = W.bw.z0, i = 0; z <= W.bw.z1 - 2; z += 5.2, i++) {
const b = rbox(rand(5, 6.5), 4.2, rand(4.6, 5.6), 0.35, i % 3 ? 'concrete_dirty' : 'concrete', 'bottom');
at(b, W.bw.x + rand(-0.6, 0.6), SEA - 2.3 + rand(-0.3, 0.3), z, rand(-0.25, 0.25)); b.rotation.z = rand(-0.06, 0.06); bwGroup.add(b);
if (i % 2) { const b2 = rbox(rand(3, 4), 2.6, rand(3, 4), 0.3, 'concrete_dirty', 'bottom'); at(b2, W.bw.x + rand(-3.2, 3.2), SEA - 1.6, z + rand(-1, 1), rand(0, 3)); bwGroup.add(b2); }
}
const lh = new T.Group(); at(lh, W.bw.x, SEA + 1.7, W.bw.z1 + 1); root.add(lh);
lh.add(at(cyl(3.2, 3.6, 2, 'concrete', 20), 0, 0, 0));
for (let k = 0; k < 4; k++) lh.add(at(cyl(1.5 - k * 0.12, 1.62 - k * 0.12, 2.6, k % 2 ? 'paint_white' : 'paint_red', 18), 0, 2.3 + k * 2.6, 0));
lh.add(at(cyl(1.25, 1.25, 1.4, 'glass', 14), 0, 12.4, 0));
lh.add(at(cyl(0.2, 1.4, 1, 'steel_dark', 14), 0, 13.6, 0));
const lhLamp = mesh(new T.SphereGeometry(0.55, 12, 8), EM(0xfff0c8, 10)); lhLamp.position.y = 12.4; lh.add(lhLamp);
const lhLight = poolLight(0xffe7b0, 0, 60); if (lhLight) { lhLight.position.set(W.bw.x, SEA + 15, W.bw.z1 + 1); root.add(lhLight); }
// salvage barge + pen
const barge = new T.Group(); const bargeX = W.pen.x, bargeZ = W.pen.z + W.pen.r + 7;
at(barge, bargeX, SEA, bargeZ, Math.PI / 2); root.add(barge);
const bol = boatOutline(36, 12, 3, 1.2);
barge.add(mesh(hullGeo(bol, -1.6, 1.0), 'hull_paint'));
barge.add(mesh(hullGeo(bol, 1.0, 1.2, 0.98), 'steel_rust'));
barge.add(mesh(hullGeo(bol, 1.18, 1.26, 0.95), 'diamond_plate'));
const crane = new T.Group(); at(crane, 3.5, 1.26, -13); barge.add(crane);
crane.add(at(box(1.6, 1.4, 1.6, 'hazard_stripes', 'bottom'), 0, 0, 0));
const tower = new T.Group(); crane.add(tower);
for (const sx of [-0.5, 0.5]) for (const sz of [-0.5, 0.5]) tower.add(at(box(0.18, 11, 0.18, 'paint_yellow', 'bottom'), sx, 1.4, sz));
for (let y = 2.5; y < 12; y += 1.6) { tower.add(at(box(1.1, 0.1, 0.1, 'paint_yellow'), 0, y, 0.5)); tower.add(at(box(1.1, 0.1, 0.1, 'paint_yellow'), 0, y, -0.5)); tower.add(at(box(0.1, 0.1, 1.1, 'paint_yellow'), 0.5, y, 0)); tower.add(at(box(0.1, 0.1, 1.1, 'paint_yellow'), -0.5, y, 0)); }
const cab = rbox(1.8, 1.6, 1.8, 0.1, 'paint_white', 'bottom'); at(cab, 0, 12.4, 0); tower.add(cab);
const boomPivot = new T.Group(); boomPivot.position.set(0, 13.4, 0); tower.add(boomPivot);
const boomLen = 22;
for (const s of [-0.35, 0.35]) boomPivot.add(at(box(0.16, 0.16, boomLen, 'paint_yellow', 'center'), s, 0, boomLen / 2));
for (let z = 1; z < boomLen; z += 1.8) boomPivot.add(at(box(0.7, 0.08, 0.08, 'paint_yellow'), 0, 0, z));
const boomTip = new T.Object3D(); boomTip.position.set(0, -0.2, boomLen - 0.4); boomPivot.add(boomTip);
boomPivot.rotation.x = -0.32;
const craneLamp = poolLight(0xffd8a0, 30, 40); if (craneLamp) { craneLamp.position.set(0, 13, 0); crane.add(craneLamp); }
barge.add(at(G.props.build('floodlight_stand', { seed: 3 }), -4.5, 1.26, 14));
barge.add(at(G.props.build('generator', { seed: 4 }), -3.8, 1.26, -15));
barge.add(at(G.props.build('cable_reel', { seed: 5 }), -4.3, 1.26, -9));
const penBarrels = [];
for (let i = 0; i < 16; i++) {
const a = i / 16 * TAU; if (Math.abs(wrapA(a - Math.PI)) < 0.45) continue; // open mouth facing west... gap
const b = G.props.build('barrel', { color: i % 2 ? 'red' : 'blue', seed: 10 + i });
const x = W.pen.x + Math.cos(a) * W.pen.r, z = W.pen.z + Math.sin(a) * W.pen.r;
at(b, x, SEA, z, -a);
root.add(b); penBarrels.push({ obj: b, x, z, a });
}
const penRope = mesh(tubeGeo(penBarrels.map(p => new T.Vector3(p.x, SEA + 0.4, p.z)), 0.06, false), 'rope'); root.add(penRope);
// medic pontoon
const pont = new T.Group(); at(pont, W.medic.x - 4, SEA + 0.25, W.medic.z, 0); root.add(pont);
pont.add(at(box(5, 0.5, 14, 'wood_dark', 'bottom'), 0, 0, 0));
for (let k = -1; k <= 1; k++) pont.add(at(box(5.2, 0.6, 0.3, 'rubber'), 0, 0.2, k * 6.8));
pont.add(at(G.props.build('floodlight_stand', { seed: 21 }), -1.5, 0.5, -4));
pont.add(at(G.props.build('toolbox_cart', { seed: 22 }), -1.6, 0.5, 3));
const medicLamps = [];
for (const [c, z] of [[0x3070ff, -1], [0xff3030, 1]]) { const m = mesh(new T.SphereGeometry(0.22, 8, 6), EM(c, 9)); m.position.set(1.8, 1.2, z); pont.add(m); medicLamps.push(m); }
const medicLight = poolLight(0x3070ff, 0, 22); if (medicLight) { medicLight.position.set(W.medic.x - 2, SEA + 2.5, W.medic.z); root.add(medicLight); }
// tug berth
const berth = new T.Group(); at(berth, W.berth.x - 7.5, SEA + 0.25, W.berth.z, 0); root.add(berth);
berth.add(at(box(3, 0.5, 18, 'wood_pallet', 'bottom'), 0, 0, 0));
for (const z of [-7, 0, 7]) berth.add(at(G.props.build('bollard_mooring', { seed: 30 + z }), 0.6, 0.5, z));
berth.add(at(G.props.build('tire_stack', { seed: 33 }), -0.6, 0.5, 4));
// ferry terminal on the quay
const term = new T.Group(); at(term, 30, 0, 103, 0); root.add(term);
term.add(at(box(9, 1.6, 14, 'concrete', 'bottom'), 4.5, SEA - 0.1, 0));
term.add(at(box(6, 0.3, 9, 'diamond_plate', 'bottom'), 7, 1.4, 0)).rotation.z = -0.12;
term.add(at(G.props.build('guard_booth', { seed: 40 }), -4, 0, -9));
term.add(at(G.props.build('floodlight_stand', { seed: 41 }), -2, 0, 9));
term.add(at(G.props.build('floodlight_stand', { seed: 42 }), -2, 0, -6));
for (let k = 0; k < 6; k++) term.add(at(G.props.build('jersey_barrier', { seed: 43 + k }), -6, 0, -10 + k * 3.4, Math.PI / 2));
for (const z of [-5, 5]) term.add(at(G.props.build('bollard_mooring', { seed: 50 + z }), 8.4, 1.5, z));
/* ---------- physics bodies (2D OBBs in x/z) */
const bodies = [];
function body(o) {
const b = Object.assign({ x: 0, z: 0, a: 0, vx: 0, vz: 0, w: 0, m: 1, ex: 1, ez: 1, kind: 'x', dragF: 0.25, dragL: 1.6, dragW: 1.4, fx: 0, fz: 0, tq: 0, alive: true }, o);
b.im = b.static ? 0 : 1 / b.m;
b.I = b.m * ((2 * b.ex) ** 2 + (2 * b.ez) ** 2) / 12; b.iI = b.static ? 0 : 1 / b.I;
if (b.kinematic) { b.im = 0; b.iI = 0; }
bodies.push(b); return b;
}
const axes = b => { const c = Math.cos(b.a), s = Math.sin(b.a); return [c, -s, s, c]; }; // ux(x,z), uz(x,z)
const toWorld = (b, lx, lz) => { const [ux, uxz, uzx, uz] = axes(b); return [b.x + ux * lx + uzx * lz, b.z + uxz * lx + uz * lz]; };
const toLocal = (b, x, z) => { const [ux, uxz, uzx, uz] = axes(b); const dx = x - b.x, dz = z - b.z; return [dx * ux + dz * uxz, dx * uzx + dz * uz]; };
const ptVel = (b, x, z) => { const rx = x - b.x, rz = z - b.z; return [b.vx + b.w * rz, b.vz - b.w * rx]; };
const cross = (rx, rz, nx, nz) => rz * nx - rx * nz;
function applyImpulse(b, jx, jz, px, pz) { if (!b.im && !b.iI) return; b.vx += jx * b.im; b.vz += jz * b.im; b.w += cross(px - b.x, pz - b.z, jx, jz) * b.iI; }
function applyForce(b, fx, fz, px, pz) { b.fx += fx; b.fz += fz; if (px !== undefined) b.tq += cross(px - b.x, pz - b.z, fx, fz); }
function corners(b) { const r = []; for (const [sx, sz] of [[1, 1], [1, -1], [-1, -1], [-1, 1]]) r.push(toWorld(b, sx * b.ex, sz * b.ez)); return r; }
function inside(b, x, z, pad = 0) { const [lx, lz] = toLocal(b, x, z); return Math.abs(lx) <= b.ex + pad && Math.abs(lz) <= b.ez + pad; }
function sat(A, B) {
const aA = axes(A), aB = axes(B);
const ax = [[aA[0], aA[1]], [aA[2], aA[3]], [aB[0], aB[1]], [aB[2], aB[3]]];
const dx = B.x - A.x, dz = B.z - A.z;
let best = 1e9, nx = 0, nz = 0;
for (const [x, z] of ax) {
const ra = A.ex * Math.abs(aA[0] * x + aA[1] * z) + A.ez * Math.abs(aA[2] * x + aA[3] * z);
const rb = B.ex * Math.abs(aB[0] * x + aB[1] * z) + B.ez * Math.abs(aB[2] * x + aB[3] * z);
const d = dx * x + dz * z, o = ra + rb - Math.abs(d);
if (o <= 0) return null;
if (o < best) { best = o; const s = d < 0 ? -1 : 1; nx = x * s; nz = z * s; }
}
// contact point: deepest corner of either box inside the other
let px = 0, pz = 0, n = 0;
for (const [x, z] of corners(B)) if (inside(A, x, z, 0.05)) { px += x; pz += z; n++; }
for (const [x, z] of corners(A)) if (inside(B, x, z, 0.05)) { px += x; pz += z; n++; }
if (n) { px /= n; pz /= n; } else { px = (A.x + B.x) / 2; pz = (A.z + B.z) / 2; }
return { nx, nz, o: best, px, pz };
}
const events = [];
function collide(A, B) {
if (A.im + B.im === 0) return;
if (A.ghost || B.ghost) return;
const dx = B.x - A.x, dz = B.z - A.z, rA = Math.hypot(A.ex, A.ez), rB = Math.hypot(B.ex, B.ez);
if (dx * dx + dz * dz > (rA + rB) ** 2) return;
const c = sat(A, B); if (!c) return;
const { nx, nz, o, px, pz } = c;
const tot = A.im + B.im;
A.x -= nx * o * (A.im / tot); A.z -= nz * o * (A.im / tot);
B.x += nx * o * (B.im / tot); B.z += nz * o * (B.im / tot);
const [vax, vaz] = ptVel(A, px, pz), [vbx, vbz] = ptVel(B, px, pz);
const vn = (vbx - vax) * nx + (vbz - vaz) * nz;
if (vn >= 0) return;
const ra = cross(px - A.x, pz - A.z, nx, nz), rb = cross(px - B.x, pz - B.z, nx, nz);
const e = 0.25;
const j = -(1 + e) * vn / (A.im + B.im + ra * ra * A.iI + rb * rb * B.iI);
applyImpulse(A, -j * nx, -j * nz, px, pz); applyImpulse(B, j * nx, j * nz, px, pz);
// tangential friction
const tx = -nz, tz = nx, vt = (vbx - vax) * tx + (vbz - vaz) * tz;
const jt = clamp(-vt / (A.im + B.im + 1e-6) * 0.3, -Math.abs(j) * 0.4, Math.abs(j) * 0.4);
applyImpulse(A, -jt * tx, -jt * tz, px, pz); applyImpulse(B, jt * tx, jt * tz, px, pz);
events.push({ A, B, vn: -vn, px, pz, nx, nz });
}
/* ---------- tug body */
const tugObj = buildTug(); dyn.add(tugObj);
const tug = body({ kind: 'tug', m: 25, ex: 2.35, ez: 6.0, dragF: 0.18, dragL: 2.4, dragW: 2.2, obj: tugObj });
const tugLight = poolLight(0xfff0d0, 0, 26);
if (tugLight) root.add(tugLight);
/* ---------- static colliders */
const statics = [];
const addStatic = (x, z, ex, ez, a = 0, tag) => { const b = body({ static: true, x, z, ex, ez, a, kind: 'static', tag }); statics.push(b); return b; };
addStatic(W.bw.x, (W.bw.z0 + W.bw.z1) / 2, 3.4, (W.bw.z1 - W.bw.z0) / 2 + 2, 0, 'breakwater');
addStatic(W.bw.x, W.bw.z1 + 1, 3.4, 3.4, 0, 'breakwater');
addStatic(bargeX, bargeZ, 6, 18, Math.PI / 2, 'barge');
addStatic(W.berth.x - 7.5, W.berth.z, 1.6, 9, 0, 'pier');
addStatic(W.medic.x - 4, W.medic.z, 2.6, 7, 0, 'pier');
addStatic(39, -42, 10.5, 40.5, 0, 'ship'); // the moored ship along the quay
addStatic(34.5, 103, 4.6, 7, 0, 'pier');
/* ---------- containers */
const COLORS = ['red', 'blue', 'green', 'yellow', 'orange', 'white', 'grey', 'teal'];
const CARGO = [
'Two thousand rubber ducks. Of course it is.', 'Frozen prawns. Smells like it, too.', 'Somebody ordered a grand piano.',
'Tractor tyres. Forty of them.', 'Office chairs. Four hundred office chairs.', 'Wedding dresses, bound for the islands.',
'Bicycle frames. Somebody will be happy.', 'Coffee beans. Imogen says keep that one dry.', 'Garden gnomes. I am not joking.',
'Medical saline. That one matters.', 'Christmas lights in November.', 'School desks for the north shore.',
];
let cargoIdx = 0;
const boxes = [];
function spawnBox(o) {
const size = o.size || (Math.random() < 0.55 ? 20 : 40);
const name = size === 20 ? 'container20' : 'container40';
const len = size === 20 ? 6.06 : 12.19;
const color = o.color || COLORS[(Math.random() * COLORS.length) | 0];
const obj = G.props.build(name, { color, seed: (Math.random() * 99999) | 0, wear: rand(0.3, 0.9), doors: 0 });
const holder = new T.Group(); holder.add(obj); obj.position.set(0, 0, 0); dyn.add(holder);
const b = body({ kind: 'box', m: size === 20 ? 16 : 28, ex: len / 2, ez: 1.22, x: o.x, z: o.z, a: o.a ?? rand(0, TAU), dragF: 0.5, dragL: 0.9, dragW: 0.9, obj: holder });
b.size = size; b.len = len; b.color = color;
b.float = 1; b.sink = o.sink || rand(1 / 260, 1 / 190); b.tag = o.tag || ''; b.fragile = !!o.fragile;
b.state = 'drift'; b.knock = !!o.knock; b.ph = Math.random() * TAU; b.lane = !!o.lane;
b.vx = o.vx || 0; b.vz = o.vz || 0; b.w = rand(-0.05, 0.05);
boxes.push(b);
return b;
}
function removeBox(b) {
b.alive = false; dyn.remove(b.obj);
const i = boxes.indexOf(b); if (i >= 0) boxes.splice(i, 1);
const j = bodies.indexOf(b); if (j >= 0) bodies.splice(j, 1);
}
/* ---------- ferry body */
const ferryObj = buildFerry(); dyn.add(ferryObj); ferryObj.visible = false;
let FERRY_WIND = 115;
const ferry = body({ kind: 'ferry', m: 700, ex: 7, ez: 33, dragF: 0.08, dragL: 0.12, dragW: 0.6, obj: ferryObj, kinematic: true, ghost: true });
ferry.lightsOn = true; ferry.mode = 'hidden';
const ferryLight = poolLight(0xffd8a0, 0, 50); if (ferryLight) root.add(ferryLight);
function ferryLights(on) {
ferry.lightsOn = on; const u = ferryObj.userData;
for (const s of u.strips) s.material = on ? u.win : u.dark;
for (const n of u.navs) n.visible = on;
}
function ferrySetDynamic(d) {
ferry.kinematic = !d; ferry.im = d ? 1 / ferry.m : 0; ferry.iI = d ? 1 / ferry.I : 0;
}
/* ---------- tow line */
const tow = { b: null, L: 9, F: 0, stress: 0, fire: 0, max: 1, geo: null, mesh: null, snapT: 0 };
const ropeMat = M('rope');
const ropeMesh = new T.Mesh(new T.BufferGeometry(), ropeMat); ropeMesh.castShadow = true; ropeMesh.frustumCulled = false; root.add(ropeMesh);
const craneRope = new T.Mesh(new T.BufferGeometry(), ropeMat); craneRope.frustumCulled = false; root.add(craneRope);
const tmpV = new T.Vector3(), tmpV2 = new T.Vector3();
function hookPoint(b) {
const [lx] = toLocal(b, tug.x, tug.z);
const s = lx >= 0 ? 1 : -1; const [x, z] = toWorld(b, s * b.ex, 0); return { x, z, lx: s * b.ex };
}
function sternPoint() { return toWorld(tug, 0, -5.4); }
function setRope(meshR, p0, p1, slack, segs = 16) {
const pts = [];
for (let i = 0; i <= segs; i++) {
const t = i / segs; tmpV.lerpVectors(p0, p1, t);
tmpV.y -= Math.sin(t * Math.PI) * slack;
const sea = seaH(tmpV.x, tmpV.z) + 0.05; if (tmpV.y < sea && slack > 0) tmpV.y = lerp(tmpV.y, sea, 0.8);
pts.push(tmpV.clone());
}
const g = tubeGeo(pts, 0.06, false, segs * 2);
meshR.geometry.dispose(); meshR.geometry = g; meshR.visible = true;
}
/* ---------- HUD */
const ui = document.getElementById('ui');
ui.innerHTML = `
<div id="ut-hud" class="ut-hide">
<div class="ut-obj"><div class="ut-ch" id="ut-ch"></div><div class="ut-ot" id="ut-ot"></div><div class="ut-os" id="ut-os"></div></div>
<div class="ut-timer ut-hide" id="ut-timer"></div>
<div class="ut-gauges">
<div class="ut-g"><span>HULL</span><i class="ut-bar"><b id="ut-hull"></b></i></div>
<div class="ut-g"><span>HEAT</span><i class="ut-bar ut-heat"><b id="ut-heat"></b></i></div>
<div class="ut-kn"><b id="ut-kn">0</b><span>KN</span></div>
<div class="ut-tel" id="ut-tel"><i id="ut-telv"></i></div>
</div>
<div class="ut-tow ut-hide" id="ut-tow"><span>LINE</span><i class="ut-bar"><b id="ut-tension"></b><em id="ut-lim"></em></i></div>
<canvas id="ut-radar" width="200" height="200"></canvas>
<div class="ut-prompt ut-hide" id="ut-prompt"></div>
<div id="ut-marks"></div>
<div class="ut-radio" id="ut-radio"><div class="ut-who" id="ut-who"></div><div class="ut-say" id="ut-say"></div></div>
<div class="ut-flash" id="ut-flash"></div>
<div class="ut-card" id="ut-card"><div class="ut-cn" id="ut-cn"></div><div class="ut-ct" id="ut-ct"></div></div>
</div>
<div id="ut-touch" class="ut-hide">
<div class="ut-stick" id="ut-stick"><i id="ut-knob"></i></div>
<button class="ut-tb" data-k="hook">HOOK</button><button class="ut-tb" data-k="boost">BOOST</button><button class="ut-tb" data-k="horn">HORN</button>
</div>
<div class="ut-screen" id="ut-title">
<div class="ut-mark">UNDERTOW</div>
<div class="ut-menu">
<button data-a="story" class="ut-primary">Begin</button>
<button data-a="chapters">Chapters</button>
<button data-a="shift">Storm Shift <small id="ut-best"></small></button>
</div>
<div class="ut-chapters ut-hide" id="ut-chapters"></div>
<dl class="ut-keys">
<dt>W S</dt><dd>Throttle</dd><dt>A D</dt><dd>Rudder</dd><dt>Shift</dt><dd>Full ahead</dd>
<dt>E</dt><dd>Hook / release</dd><dt>H</dt><dd>Horn</dd><dt>Drag</dt><dd>Look</dd><dt>Esc</dt><dd>Pause</dd>
</dl>
</div>
<div class="ut-screen ut-hide" id="ut-pause">
<div class="ut-mark ut-sm">PAUSED</div>
<div class="ut-menu">
<button data-a="resume" class="ut-primary">Resume</button>
<button data-a="retry">Restart chapter</button>
<button data-a="title">Quit to title</button>
</div>
</div>
<div class="ut-screen ut-hide" id="ut-fail">
<div class="ut-mark ut-sm ut-red" id="ut-failt">LOST</div>
<div class="ut-why" id="ut-why"></div>
<div class="ut-menu">
<button data-a="retry" class="ut-primary">Try again</button>
<button data-a="title">Quit to title</button>
</div>
</div>
<div class="ut-screen ut-hide" id="ut-end">
<div class="ut-mark ut-sm" id="ut-endt">DAWN</div>
<div class="ut-stats" id="ut-stats"></div>
<div class="ut-menu">
<button data-a="shift" class="ut-primary">Storm Shift</button>
<button data-a="title">Title</button>
</div>
</div>`;
const $ = id => document.getElementById(id);
const show = (id, on) => $(id).classList.toggle('ut-hide', !on);
const radarC = $('ut-radar'), rctx = radarC.getContext('2d');
const isTouch = matchMedia('(pointer: coarse)').matches;
/* radio */
const radioQ = []; let radioCur = null, radioT = 0, radioShown = 0;
function say(who, text, hold) { radioQ.push({ who, text, hold: hold || Math.max(2.6, text.length * 0.055) }); }
function radioUpdate(dt) {
if (!radioCur && radioQ.length) { radioCur = radioQ.shift(); radioT = 0; radioShown = 0; $('ut-who').textContent = radioCur.who; $('ut-say').textContent = ''; $('ut-radio').classList.add('on'); snd('radio'); }
if (!radioCur) return;
radioT += dt;
const n = Math.min(radioCur.text.length, Math.floor(radioT * 60));
if (n !== radioShown) { radioShown = n; $('ut-say').textContent = radioCur.text.slice(0, n); }
if (radioT > radioCur.text.length / 60 + radioCur.hold) { radioCur = null; if (!radioQ.length) $('ut-radio').classList.remove('on'); }
}
function radioClear() { radioQ.length = 0; radioCur = null; $('ut-radio').classList.remove('on'); }
function card(n, t) {
$('ut-cn').textContent = n; $('ut-ct').textContent = t;
const c = $('ut-card'); c.classList.remove('on'); void c.offsetWidth; c.classList.add('on');
clearTimeout(card.t); card.t = setTimeout(() => c.classList.remove('on'), 4300);
}
function flash(cls) { const f = $('ut-flash'); f.className = 'ut-flash'; void f.offsetWidth; f.className = 'ut-flash ' + cls; }
/* markers */
const markPool = [];
let markUsed = 0;
function mark(x, y, z, cls, label) {
tmpV.set(x, y, z).project(camera);
if (tmpV.z > 1) return;
let el = markPool[markUsed];
if (!el) { el = document.createElement('div'); $('ut-marks').appendChild(el); markPool.push(el); }
markUsed++;
const w = innerWidth, h = innerHeight;
let sx = (tmpV.x * 0.5 + 0.5) * w, sy = (-tmpV.y * 0.5 + 0.5) * h;
const off = sx < 20 || sx > w - 20 || sy < 60 || sy > h - 20;
sx = clamp(sx, 24, w - 24); sy = clamp(sy, 70, h - 30);
el.className = 'ut-mk ' + cls + (off ? ' off' : '');
el.style.transform = `translate(${sx}px,${sy}px)`;
if (el._l !== label) { el.textContent = label || ''; el._l = label; }
el.style.display = '';
}
/* ---------- game state */
const S = {
state: 'title', mode: 'story', ch: 0, chT: 0, hull: 100, heat: 0, over: 0, throttle: 0, rudder: 0,
delivered: 0, lost: 0, rescued: false, flags: {}, objective: '', sub: '', timer: -1, score: 0, lives: 3, shiftT: 0, spawnT: 0, ferryT: 0,
totalDelivered: 0, startTime: 0, storm: 0.3, shake: 0, gustT: 8, gust: 0, knockId: null, best: store('undertow.best'),
reached: store('undertow.reached'),
};
const game = { state: 'title', S };
function store(k) { try { return +(localStorage.getItem(k) || 0); } catch (e) { return 0; } }
function setObjective(t, sub) { S.objective = t; S.sub = sub || ''; $('ut-ot').textContent = t; $('ut-os').textContent = sub || ''; }
function setChapterLabel(t) { $('ut-ch').textContent = t; }
function resetWorld() {
S.tok = (S.tok || 0) + 1;
for (const b of boxes.slice()) removeBox(b);
tow.b = null; tow.F = 0; tow.stress = 0; ropeMesh.visible = false; craneRope.visible = false;
lifts.length = 0;
ferry.mode = 'hidden'; ferryObj.visible = false; ferry.ghost = true; ferrySetDynamic(false); ferryLights(true);
S.hull = 100; S.heat = 0; S.over = 0; S.timer = -1; S.flags = {}; S.chT = 0; S.knockId = null; S.shake = 0;
gates.forEach(g => g.objs.forEach(o => o.visible = false)); gates.length = 0;
radioClear(); snd('setKnock', 0, 0); snd('setTension', 0);
show('ut-timer', false);
}
function clearDeck() { deckSlots.forEach(s => { if (s.obj) { barge.remove(s.obj); s.obj = null; } }); }
function placeTug(x, z, a) { tug.x = x; tug.z = z; tug.a = a; tug.vx = tug.vz = tug.w = 0; }
/* gates (chapter 1) */
const gates = [];
function addGate(x, z, a) {
const objs = [];
const [ux, uxz] = axes({ a });
for (const s of [-1, 1]) { const b = addBuoy('yellow', 0xffb347, x + ux * s * 7, z + uxz * s * 7, 1, 0); objs.push(b); }
const g = { x, z, a, objs, done: false }; gates.push(g); return g;
}
/* deck slots on the barge for delivered boxes */
const deckSlots = [];
for (let k = 0; k < 10; k++) deckSlots.push({ lx: k < 5 ? -2.2 : 2.6, lz: -10 + (k % 5) * 6.4, ly: 1.26, obj: null });
const lifts = [];
function deliverToBarge(b) {
if (tow.b === b) dropLine(false);
b.state = 'lift'; b.ghost = true; b.im = 0; b.iI = 0;
const slot = deckSlots.find(s => !s.obj) || deckSlots[(S.delivered + S.totalDelivered) % deckSlots.length];
lifts.push({ b, t: 0, from: new T.Vector3(b.x, b.obj.position.y, b.z), a0: b.a, slot });
snd('hookLatch'); snd('shipGroan');
}
function updateLifts(dt) {
for (let i = lifts.length - 1; i >= 0; i--) {
const l = lifts[i]; l.t += dt / 4.2;
const t = clamp(l.t, 0, 1);
barge.updateMatrixWorld(true);
tmpV2.set(l.slot.lx, l.slot.ly + (l.slot.obj ? 2.6 : 0), l.slot.lz); barge.localToWorld(tmpV2);
const up = Math.sin(Math.min(1, t * 1.4) * Math.PI / 2);
const k = clamp((t - 0.25) / 0.65, 0, 1), s = k * k * (3 - 2 * k);
const o = l.b.obj;
o.position.set(lerp(l.from.x, tmpV2.x, s), lerp(l.from.y, tmpV2.y + 3, s) + up * 9 * (1 - s) + (s * 3) * (1 - Math.max(0, t - 0.9) * 10) - (t > 0.9 ? 3 * (t - 0.9) * 10 : 0), lerp(l.from.z, tmpV2.z, s));
o.rotation.set(0, lerp(l.a0, Math.PI / 2 + barge.rotation.y - Math.PI / 2, s) + Math.sin(t * 9) * 0.04 * (1 - t), 0);
boomPivot.rotation.x = -0.32 + Math.sin(t * Math.PI) * 0.12;
crane.rotation.y = lerp(crane.rotation.y, Math.atan2(o.position.x - bargeX, o.position.z - bargeZ) - barge.rotation.y, 0.1);
boomTip.getWorldPosition(tmpV);
setRope(craneRope, tmpV, tmpV2.set(o.position.x, o.position.y + 2.6, o.position.z), 0, 6);
if (l.t >= 1) {
lifts.splice(i, 1); craneRope.visible = lifts.length > 0;
const o2 = l.b.obj; dyn.remove(o2);
const slot = l.slot; if (slot.obj) barge.remove(slot.obj);
barge.add(o2); o2.position.set(slot.lx, slot.ly, slot.lz); o2.rotation.set(0, Math.PI / 2, 0); slot.obj = o2;
const j = bodies.indexOf(l.b); if (j >= 0) bodies.splice(j, 1);
const ix = boxes.indexOf(l.b); if (ix >= 0) boxes.splice(ix, 1);
snd('thud', 0.35);
}
}
}
/* ---------- tow controls */
function tryHook() {
if (tow.b) { dropLine(true); return; }
const [sx, sz] = sternPoint();
let best = null, bd = 16;
for (const b of boxes) {
if (b.state !== 'drift') continue;
const hp = hookPoint(b); const d = Math.hypot(hp.x - sx, hp.z - sz);
if (d < bd) { bd = d; best = b; }
}
if (!best) { snd('chime'); return; }
tow.b = best; tow.L = clamp(bd, 7, 11); tow.F = 0; tow.stress = 0; tow.fire = 0;
tow.lx = hookPoint(best).lx; best.state = 'tow';
snd('hookFire'); setTimeout(() => snd('hookLatch'), 220);
onHook && onHook(best);
}
function dropLine(manual) {
if (!tow.b) return;
if (tow.b.state === 'tow') tow.b.state = 'drift';
tow.b = null; ropeMesh.visible = false; snd('release'); snd('setTension', 0);
}
function snapLine() {
if (!tow.b) return;
const b = tow.b; b.state = 'drift'; tow.b = null; ropeMesh.visible = false;
snd('ropeSnap'); snd('setTension', 0); S.shake = Math.max(S.shake, 0.5); flash('ut-warn');
say('HARBOUR', pick(['Line’s parted! Ease off and hook her again.', 'You snapped it. Gentler this time.', 'Line gone. Throttle down when it sings.']));
if (b.fragile) { S.hull = Math.max(0, S.hull - 0); b.float = Math.max(0.15, b.float - 0.06); }
}
let onHook = null;
const pick = a => a[(Math.random() * a.length) | 0];
/* ---------- chapters */
const CH = [
{ id: 'castoff', name: 'I', title: 'Cast Off' },
{ id: 'flotsam', name: 'II', title: 'Flotsam' },
{ id: 'knock', name: 'III', title: 'Knocking' },
{ id: 'channel', name: 'IV', title: 'The Channel' },
{ id: 'lee', name: 'V', title: 'Lee Shore' },
];
function startChapter(i) {
resetWorld();
if (i === 0) clearDeck();
S.mode = 'story'; S.ch = i; S.chT = 0; S.delivered = 0;
S.reached = Math.max(S.reached, i); try { localStorage.setItem('undertow.reached', S.reached); } catch (e) {}
const c = CH[i];
setChapterLabel(c.name + ' · ' + c.title.toUpperCase());
card(c.name, c.title);
onHook = null;
setState('play');
SETUP[c.id]();
}
const SETUP = {
castoff() {
placeTug(W.berth.x - 2.5, W.berth.z, 0.0);
S.storm = 0.25;
addGate(58, 46, Math.PI / 2 - 0.4); addGate(80, 26, Math.PI / 2 + 0.6); addGate(108, 40, Math.PI / 2 - 0.2);
gates.forEach(g => g.objs.forEach(o => o.visible = true));
setObjective('Run the gates', '0 / 3');
say('HARBOUR', 'Petrel, Harbour. The Meridian Ash rolled off the breakwater and dropped her deck stack.');
say('HARBOUR', 'Boxes are drifting in on the tide. Slip your lines and run the yellow gates, let me see you still steer.');
},
flotsam() {
placeTug(110, 40, Math.PI / 2);
S.storm = 0.4;
spawnBox({ x: 128, z: 18, size: 20 }); spawnBox({ x: 142, z: 44, size: 40 }); spawnBox({ x: 150, z: 6, size: 20 }); spawnBox({ x: 160, z: 30, size: 40 });
setObjective('Tow boxes into the pen', '0 / 3');
say('HARBOUR', 'Hook gear is live. Get a line on a box and drag it into the barrel pen by the salvage barge.');
say('HARBOUR', 'The crane will do the rest. Mind your speed, a snapped line goes nowhere.');
onHook = () => { if (!S.flags.hooked) { S.flags.hooked = 1; say('HARBOUR', 'That’s a line. Easy on the throttle when it starts to sing.'); } };
},
knock() {
placeTug(104, 34, Math.PI / 2 + 0.3);
S.storm = 0.55;
const spots = [[140, -24], [158, -52], [126, -60], [150, 2]];
const k = (Math.random() * spots.length) | 0;
spots.forEach(([x, z], i) => { const b = spawnBox({ x, z, size: i === k ? 20 : (i % 2 ? 40 : 20), knock: i === k, fragile: i === k, sink: i === k ? 1 / 230 : 1 / 400, color: i === k ? 'orange' : undefined }); if (i === k) S.knockId = b; });
setObjective('Find the knocking box', 'Follow the pings');
say('HARBOUR', 'Petrel, the hydrophone is picking up knocking. Three short, three long, three short.');
say('HARBOUR', 'Someone is inside one of those boxes. Follow the pings, they get louder when you’re close.');
onHook = b => {
if (b === S.knockId && !S.flags.found) {
S.flags.found = 1;
say('NICO', 'Hello? Is someone there? The water’s coming in at the doors—');
say('HARBOUR', 'Easy, easy. That box can’t take a hard pull. Bring it to the medic pontoon by the quay.');
setObjective('Bring the box to the medics', 'Keep the line slack');
} else if (b !== S.knockId && !S.flags.wrong) { S.flags.wrong = 1; say('HARBOUR', 'Not that one. Listen for the knocking.'); }
};
},
channel() {
placeTug(100, 82, Math.PI / 2 + 0.4);
S.storm = 0.7;
const xs = [92, 128, 166, 205, 240];
xs.forEach((x, i) => spawnBox({ x, z: rand(W.lane.z0 + 6, W.lane.z1 - 6), lane: true, size: i % 2 ? 40 : 20, a: rand(-0.5, 0.5), sink: 1 / 900 }));
S.timer = 240;
show('ut-timer', true);
setObjective('Clear the ferry channel', '5 boxes in the lane');
say('ALBATROSS', 'Harbour, Albatross. Inbound with three hundred souls, ETA four minutes.');
say('HARBOUR', 'Petrel, five boxes are sitting in her channel. Drag them out of the lane, anywhere outside the buoys.');
},
lee() {
placeTug(196, 74, -0.2);
S.storm = 0.9;
ferry.mode = 'blackout'; ferryObj.visible = true; ferry.ghost = false; ferrySetDynamic(true);
ferry.x = 214; ferry.z = 104; ferry.a = -Math.PI / 2 - 0.08; ferry.vx = -1.6; ferry.vz = 0; ferry.w = 0;
ferryLights(false);
S.flags.restart = 0;
setObjective('Keep the Albatross off the breakwater', 'Push her north');
say('ALBATROSS', 'Harbour, Albatross! Total blackout. No engines, no steering!');
say('HARBOUR', 'She’s being set onto the breakwater. Petrel, get your bow on her south side and push!');
snd('shipGroan');
},
};
function startShift() {
resetWorld(); clearDeck();
S.mode = 'shift'; S.ch = -1; S.score = 0; S.lives = 3; S.shiftT = 0; S.spawnT = 4; S.ferryT = 100; S.storm = 0.45;
placeTug(W.berth.x - 2.5, W.berth.z, 0);
setChapterLabel('STORM SHIFT');
card('', 'Storm Shift');
for (let i = 0; i < 3; i++) spawnRandomBox();
setObjective('Boxes saved: 0', 'Lives 3');
say('HARBOUR', 'The Ash is still shedding boxes. Pen them, keep the channel clear. Ferry every two minutes.');
setState('play');
}
function spawnRandomBox() {
const x = rand(120, 250), z = rand(-90, 150);
spawnBox({ x, z, sink: 1 / rand(130, 200) * (1 + S.shiftT / 600), lane: z > W.lane.z0 && z < W.lane.z1 });
}
function setState(s) {
S.state = s; game.state = s === 'play' || s === 'cine' ? 'playing' : s;
show('ut-title', s === 'title'); show('ut-pause', s === 'paused'); show('ut-fail', s === 'fail'); show('ut-end', s === 'end');
show('ut-hud', s === 'play' || s === 'paused' || s === 'cine');
show('ut-touch', isTouch && s === 'play');
snd('setPaused', s === 'paused' || s === 'title'); snd('horn', false); if (s !== 'play') { snd('setKnock', 0, 0); snd('setTension', 0); }
}
function fail(why) {
if (S.state !== 'play' && S.state !== 'cine') return;
dropLine(); snd('fail'); S.failT = 0;
$('ut-why').textContent = why;
$('ut-failt').textContent = S.mode === 'shift' ? 'SHIFT OVER' : 'LOST';
if (S.mode === 'shift') { if (S.score > S.best) { S.best = S.score; try { localStorage.setItem('undertow.best', S.best); } catch (e) {} } $('ut-why').textContent = why + ' · ' + S.score + ' boxes saved'; }
const tok = S.tok = (S.tok || 0) + 1; setTimeout(() => { if (S.tok === tok && S.state === 'dying') setState('fail'); }, 1400);
S.state = 'dying';
}
function finishStory() {
S.state = 'cine'; S.endT = 0;
}
function showEnd() {
const mins = Math.floor((performance.now() - S.startTime) / 60000);
$('ut-stats').innerHTML = `<div><b>${deckSlots.filter(s => s.obj).length}</b><span>boxes on the barge</span></div><div><b>1</b><span>stowaway home</span></div><div><b>300</b><span>ferry passengers</span></div>${mins ? `<div><b>${mins}</b><span>minutes</span></div>` : ''}`;
setState('end');
snd('success');
}
function refreshBest() { $('ut-best').textContent = S.best ? 'best ' + S.best : ''; }
refreshBest();
// menus
function buildChapterList() {
const el = $('ut-chapters'); el.innerHTML = '';
CH.forEach((c, i) => { const b = document.createElement('button'); b.textContent = c.name + ' ' + c.title; b.disabled = i > S.reached; b.dataset.ch = i; el.appendChild(b); });
}
ui.addEventListener('click', e => {
const b = e.target.closest('button'); if (!b) return;
snd('resume'); snd('chime');
if (b.dataset.ch !== undefined) { S.startTime = performance.now(); S.totalDelivered = 0; startChapter(+b.dataset.ch); return; }
const a = b.dataset.a;
if (a === 'story') { S.startTime = performance.now(); S.totalDelivered = 0; startChapter(0); }
else if (a === 'chapters') { buildChapterList(); $('ut-chapters').classList.toggle('ut-hide'); }
else if (a === 'shift') startShift();
else if (a === 'resume') setState('play');
else if (a === 'retry') { if (S.mode === 'shift') startShift(); else startChapter(S.ch); }
else if (a === 'title') { resetWorld(); refreshBest(); setState('title'); }
});
addEventListener('pointerdown', () => snd('resume'), { once: false });
addEventListener('keydown', () => snd('resume'));
// touch controls
const tb = { hook: false, boost: false, horn: false };
if (isTouch) {
const st = $('ut-stick'), kn = $('ut-knob');
st.addEventListener('pointerdown', e => { touch.on = true; touch.id = e.pointerId; const r = st.getBoundingClientRect(); touch.sx = r.left + r.width / 2; touch.sy = r.top + r.height / 2; st.setPointerCapture(e.pointerId); mv(e); });
const mv = e => { if (!touch.on) return; touch.x = clamp((e.clientX - touch.sx) / 50, -1, 1); touch.y = clamp((e.clientY - touch.sy) / 50, -1, 1); kn.style.transform = `translate(${touch.x * 40}px,${touch.y * 40}px)`; };
st.addEventListener('pointermove', mv);
const end = () => { touch.on = false; touch.x = touch.y = 0; kn.style.transform = ''; };
st.addEventListener('pointerup', end); st.addEventListener('pointercancel', end);
document.querySelectorAll('.ut-tb').forEach(b => {
b.addEventListener('pointerdown', e => { e.preventDefault(); tb[b.dataset.k] = true; if (b.dataset.k === 'hook') PRESSED.add('KeyE'); });
const off = () => { tb[b.dataset.k] = false; };
b.addEventListener('pointerup', off); b.addEventListener('pointercancel', off); b.addEventListener('pointerleave', off);
});
}
/* ---------- camera */
const cam = { yaw: Math.PI / 2, pitch: 0.32, dist: 15, off: 0, offP: 0, zoom: 0, x: 0, y: 0, z: 0, init: false, orbit: 0 };
function updateCamera(dt, t) {
const look = new T.Vector3();
if (S.state === 'title') {
cam.orbit += dt * 0.05;
const cx = 96, cz = 40;
camera.position.set(cx + Math.cos(cam.orbit) * 46, SEA + 9 + Math.sin(cam.orbit * 0.7) * 2, cz + Math.sin(cam.orbit) * 46);
look.set(cx, SEA + 2, cz); camera.lookAt(look); cam.init = false; return;
}
// mouse orbit
cam.off += ptr.dx * -0.005; cam.offP = clamp(cam.offP + ptr.dy * 0.003, -0.25, 0.6); ptr.dx = ptr.dy = 0;
ptr.idle += dt; if (!ptr.drag && ptr.idle > 1.6) { cam.off = damp(cam.off, 0, 1.6, dt); cam.offP = damp(cam.offP, 0, 1.6, dt); }
cam.zoom = clamp(cam.zoom + ptr.wheel * 1.5, -6, 14); ptr.wheel = 0;
let target = new T.Vector3(tug.x, SEA + 1.5, tug.z);
let dist = 15 + cam.zoom + (tow.b ? 6 : 0) + Math.hypot(tug.vx, tug.vz) * 0.25;
let hy = tug.a;
if (S.state === 'cine' && S.mode === 'story' && S.ch === 4) { target.set(ferry.x, SEA + 6, ferry.z); dist = 70; hy = ferry.a + 2.4 + (S.endT || 0) * 0.05; }
if (S.ch === 4 && S.state === 'play') { dist += 10; target.lerp(new T.Vector3(ferry.x, SEA + 2, ferry.z), 0.25); }
if (!cam.init) { cam.yaw = hy; cam.init = true; }
cam.yaw += wrapA(hy - cam.yaw) * (1 - Math.exp(-2.2 * dt));
cam.tp = damp(cam.tp || 0, tow.b ? 0.16 : 0, 2, dt);
const yaw = cam.yaw + cam.off, pitch = cam.pitch + cam.offP + cam.tp;
const fx = Math.sin(yaw), fz = Math.cos(yaw);
const px = target.x - fx * dist * Math.cos(pitch), pz = target.z - fz * dist * Math.cos(pitch);
let py = target.y + dist * Math.sin(pitch) + 2;
py = Math.max(py, seaH(px, pz) + 1.2);
cam.x = damp(cam.x || px, px, 8, dt); cam.y = damp(cam.y || py, py, 8, dt); cam.z = damp(cam.z || pz, pz, 8, dt);
const sh = S.shake * S.shake;
camera.position.set(cam.x + rand(-1, 1) * sh * 0.6, cam.y + rand(-1, 1) * sh * 0.6 + Math.sin(t * 0.9) * 0.15, cam.z + rand(-1, 1) * sh * 0.6);
look.set(target.x + fx * 5, target.y + 0.5, target.z + fz * 5);
camera.lookAt(look);
camera.rotation.z += Math.sin(t * 0.7) * 0.006 * (0.5 + S.storm);
}
/* ---------- per-frame physics */
function physStep(dt, t) {
// forces: tug drive
const [ux, uxz, uzx, uz] = axes(tug);
const vf = tug.vx * uzx + tug.vz * uz;
let thrust = S.throttle * (S.throttle > 0 ? 62 : 38);
if (S.boost && S.throttle > 0) thrust *= 1.65;
if (S.state !== 'play') thrust = 0;
applyForce(tug, uzx * thrust, uz * thrust);
const turn = -S.rudder * (clamp(vf / 5, -1, 1) * 0.65 + Math.abs(S.throttle) * 0.45 * Math.sign(vf + 0.5) + 0.18) * 2.4;
tug.w += turn * dt * (S.state === 'play' ? 1 : 0);
// wind / current
const wind = 0.6 + S.storm * 1.4 + S.gust * 3;
for (const b of bodies) {
if (b.static || b.kinematic || b.ghost) continue;
if (b.kind === 'box') applyForce(b, -wind * 0.9 * b.m * 0.02, -wind * 0.5 * b.m * 0.02);
}
if (ferry.mode === 'blackout' && !ferry.kinematic) applyForce(ferry, -18, -FERRY_WIND * (0.7 + S.gust * 1.7), ferry.x + rand(-1, 1), ferry.z);
// tow line spring
if (tow.b) {
const b = tow.b; const [sx, sz] = sternPoint(); const [hx, hz] = toWorld(b, tow.lx, 0);
const dx = hx - sx, dz = hz - sz, d = Math.hypot(dx, dz) || 1e-3, nx = dx / d, nz = dz / d;
const [va, vb] = ptVel(tug, sx, sz), [wa, wb] = ptVel(b, hx, hz);
const vrel = (wa - va) * nx + (wb - vb) * nz;
let F = 0;
if (d > tow.L) F = Math.max(0, (d - tow.L) * 48 + vrel * 26);
tow.F = damp(tow.F, F, 10, dt);
if (F > 0) { applyForce(tug, nx * F, nz * F, sx, sz); applyForce(b, -nx * F, -nz * F, hx, hz); }
if (d > 40) snapLine();
}
// integrate
for (const b of bodies) {
if (b.static) continue;
if (!b.kinematic && !b.ghost) {
b.vx += b.fx * b.im * dt; b.vz += b.fz * b.im * dt; b.w += b.tq * b.iI * dt;
}
b.fx = b.fz = b.tq = 0;
if (!b.kinematic) {
const [cx, cxz, czx, cz] = axes(b);
let vF = b.vx * czx + b.vz * cz, vL = b.vx * cx + b.vz * cxz;
if (b.kind === 'box') { vL *= Math.exp(-b.dragF * dt); vF *= Math.exp(-b.dragL * 0.8 * dt); }
else { vF *= Math.exp(-(b.dragF + Math.abs(vF) * 0.035) * dt); vL *= Math.exp(-b.dragL * dt); }
b.vx = cx * vL + czx * vF; b.vz = cxz * vL + cz * vF;
b.w *= Math.exp(-b.dragW * dt);
}
b.x += b.vx * dt; b.z += b.vz * dt; b.a += b.w * dt;
}
// collisions
const n = bodies.length;
for (let i = 0; i < n; i++) for (let j = i + 1; j < n; j++) {
const A = bodies[i], B = bodies[j];
if (A.static && B.static) continue;
if (A.state === 'lift' || B.state === 'lift') continue;
collide(A, B);
}
// quay wall + bounds
const bd = W.bounds;
for (const b of bodies) {
if (b.static || b.kinematic) continue;
const r = Math.min(b.ex, b.ez) + 0.5;
if (b.x < bd.x0 + r) { if (b.vx < -1.5 && b === tug) events.push({ A: tug, B: { kind: 'wall' }, vn: -b.vx, px: b.x - r, pz: b.z }); b.x = bd.x0 + r; b.vx = Math.abs(b.vx) * 0.2; }
if (b === tug) {
const out = b.x > bd.x1 || b.z < bd.z0 || b.z > bd.z1;
if (out) { const cx = 110 - b.x, cz = 30 - b.z, d = Math.hypot(cx, cz); applyForce(b, cx / d * 90, cz / d * 90); if (!S.flags.bounds) { S.flags.bounds = 1; say('HARBOUR', 'Petrel, you’re outside the harbour. Come back in.'); } }
else S.flags.bounds = 0;
}
}
}
/* ---------- rendering sync */
function syncBody(b, t, draft, lift) {
const o = b.obj; if (!o) return;
const h = seaH(b.x, b.z);
const [fx, fz] = toWorld(b, 0, b.ez * 0.8), [bx, bz] = toWorld(b, 0, -b.ez * 0.8);
const [lx, lz] = toWorld(b, b.ex * 0.9, 0), [rx, rz] = toWorld(b, -b.ex * 0.9, 0);
const pitch = Math.atan2(seaH(fx, fz) - seaH(bx, bz), b.ez * 1.6);
const roll = Math.atan2(seaH(lx, lz) - seaH(rx, rz), b.ex * 1.8);
o.position.set(b.x, h - draft + (lift || 0), b.z);
o.rotation.order = 'YXZ';
o.rotation.set(-pitch * 0.8, b.a, roll * 0.8 + (b === tug ? -b.w * 0.12 * clamp(Math.hypot(b.vx, b.vz) / 6, 0, 1) : 0));
if (b.kind === 'box') { o.rotation.set(-pitch * 0.6, b.a, roll * 0.6 + Math.sin(t * 0.7 + b.ph) * 0.02 * (1 - b.float)); }
}
/* ---------- update */
let wakeT = 0, smokeT = 0, pingT = 0, knockVol = 0;
game.update = dt => {
const t = G.time.t;
// menu keys
if (PRESSED.has('Escape') || PRESSED.has('KeyP')) {
if (S.state === 'play') setState('paused'); else if (S.state === 'paused') setState('play');
}
if (S.state === 'paused' || S.state === 'fail' || S.state === 'end') { updateCamera(0, t); snd('setEngine', 0, 0, false); return true; }
radioUpdate(dt);
// controls
const k = KEYS;
let th = (k.has('KeyW') || k.has('ArrowUp') ? 1 : 0) - (k.has('KeyS') || k.has('ArrowDown') ? 1 : 0);
let ru = (k.has('KeyD') || k.has('ArrowRight') ? 1 : 0) - (k.has('KeyA') || k.has('ArrowLeft') ? 1 : 0);
if (touch.on) { th = -touch.y; ru = touch.x; }
if (S.state !== 'play') { th = 0; ru = 0; }
S.throttle = damp(S.throttle, th, th === 0 ? 2.5 : 1.6, dt);
S.rudder = damp(S.rudder, ru, 5, dt);
const wantBoost = (k.has('ShiftLeft') || k.has('ShiftRight') || tb.boost) && S.throttle > 0.3 && S.over <= 0;
S.boost = wantBoost;
if (S.boost) { S.heat += dt * 0.28; if (S.heat >= 1) { S.over = 3.5; S.heat = 1; snd('shipGroan'); flash('ut-warn'); } }
else S.heat = Math.max(0, S.heat - dt * 0.2);
if (S.over > 0) S.over -= dt;
if (S.state === 'play') {
if (PRESSED.has('KeyE') || PRESSED.has('Space') || PRESSED.has('KeyF')) tryHook();
snd('horn', k.has('KeyH') || tb.horn);
} else snd('horn', false);
// storm & gusts
S.gustT -= dt;
if (S.gustT <= 0) { S.gustT = rand(7, 16) * (1.3 - S.storm * 0.6); S.gustDur = rand(1.5, 3); snd('gust'); }
S.gust = S.gustDur > 0 ? Math.sin(clamp(1 - S.gustDur / 3, 0, 1) * Math.PI) * S.storm : 0;
S.gustDur = (S.gustDur || 0) - dt;
try { G.ground.setRain && G.ground.setRain(0.35 + S.storm * 0.65); } catch (e) {}
snd('setStorm', S.storm);
// physics with substeps
const sub = 3; for (let i = 0; i < sub; i++) physStep(dt / sub, t);
// collision consequences
for (const e of events) {
if ((e.A === ferry && e.B.tag === 'breakwater') || (e.B === ferry && e.A.tag === 'breakwater')) S.flags.ferryHit = 1;
const isTug = e.A === tug || e.B === tug;
const other = e.A === tug ? e.B : e.A;
if (isTug && e.vn > 1.2) {
const dmg = Math.max(0, (e.vn - 2.8)) * (other.kind === 'ferry' ? 3 : other.kind === 'box' ? 4 : 4.5);
if (S.state === 'play') S.hull -= dmg;
snd('thud', clamp(e.vn / 7, 0.2, 1)); S.shake = Math.max(S.shake, clamp(e.vn / 6, 0.2, 1));
try { G.fx.splash(new T.Vector3(e.px, SEA + 0.3, e.pz), clamp(e.vn / 3, 0.6, 2)); if (e.vn > 3) G.fx.sparks(new T.Vector3(e.px, SEA + 1, e.pz), new T.Vector3(-e.nx, 0.5, -e.nz), 10); } catch (er) {}
if (dmg > 2) flash('ut-hit');
} else if (e.vn > 2) { snd('thud', clamp(e.vn / 10, 0.1, 0.5)); try { G.fx.splash(new T.Vector3(e.px, SEA + 0.3, e.pz), 0.8); } catch (er) {} }
if (other && other.kind === 'ferry' && isTug && e.vn > 0.3 && ferry.mode === 'blackout') S.flags.pushing = 1.0;
}
events.length = 0;
S.shake = Math.max(0, S.shake - dt * 1.8);
// tow tension
if (tow.b) {
tow.max = tow.b.fragile ? 88 : 150;
const r = tow.F / tow.max;
if (r > 1) tow.stress += dt * (r - 0.85) * 1.6; else tow.stress = Math.max(0, tow.stress - dt * 0.8);
if (tow.stress > 1) snapLine();
snd('setTension', clamp(r, 0, 1));
}
// boxes: sinking + delivery
for (const b of boxes.slice()) {
if (b.state === 'lift' || S.state !== 'play') continue;
b.float -= b.sink * dt * (b.state === 'tow' ? 0.6 : 1);
if (b.float <= 0) {
if (tow.b === b) dropLine();
try { G.fx.splash(new T.Vector3(b.x, SEA, b.z), 2); } catch (e) {}
snd('splash', 0.8);
removeBox(b); onSunk(b); continue;
}
if (Math.hypot(b.x - W.pen.x, b.z - W.pen.z) < W.pen.r - 1.2 && !b.knock) { deliverToBarge(b); onDelivered(b); continue; }
if (b.knock && Math.hypot(b.x - W.medic.x, b.z - W.medic.z) < W.medic.r + 4) { onRescue(b); }
}
updateLifts(dt);
// chapter logic
S.chT += dt;
chapterUpdate(dt, t);
// hull
if (S.hull <= 0 && S.state === 'play') fail('The Petrel is holed and taking on water.');
if (S.state === 'play' && tug.x > W.bw.x - 6 && tug.x < W.bw.x + 6 && tug.z < W.bw.z1 + 4) {}
// keep the sun's shadow frustum over the action
if (sun) {
const fx = S.state === 'title' ? 96 : (S.ch === 4 && S.mode === 'story' ? (tug.x + ferry.x) / 2 : tug.x), fz = S.state === 'title' ? 40 : (S.ch === 4 && S.mode === 'story' ? (tug.z + ferry.z) / 2 : tug.z);
const ox = Math.round(Math.max(0, fx - 22) / 2) * 2, oz = Math.round(clamp(fz, -120, 160) * 0.9 / 2) * 2;
sun.position.set(sun0.x + ox, sun0.y, sun0.z + oz); sun.target.position.set(sunT0.x + ox, sunT0.y, sunT0.z + oz);
sun.updateMatrixWorld(true); sun.target.updateMatrixWorld(true);
}
// sync visuals
syncBody(tug, t, 0.1, 0);
for (const b of boxes) if (b.state !== 'lift') syncBody(b, t, 1.2 + (1 - b.float) * 2.3, 0);
if (ferryObj.visible) syncBody(ferry, t, 0.2, 0);
for (const bu of buoys) {
const h = seaH(bu.x, bu.z); bu.obj.position.y = h - 0.2; bu.obj.rotation.set(Math.sin(t * 1.3 + bu.ph) * 0.12, 0, Math.cos(t * 1.1 + bu.ph) * 0.12);
bu.obj.userData.lamp.visible = ((t + bu.phase) % bu.period) < 0.45;
}
for (const p of penBarrels) { p.obj.position.y = seaH(p.x, p.z) - 0.35; p.obj.rotation.x = Math.sin(t * 1.4 + p.a * 3) * 0.1; }
medicLamps[0].visible = (t * 3) % 1 < 0.5; medicLamps[1].visible = !medicLamps[0].visible;
if (medicLight) { medicLight.intensity = S.ch === 2 && S.flags.found ? 25 : 0; medicLight.color.set(medicLamps[0].visible ? 0x3070ff : 0xff3030); }
lhLamp.visible = (t % 6) < 0.8 || ((t % 6) > 1.2 && (t % 6) < 2.0);
if (lhLight) lhLight.intensity = lhLamp.visible ? 60 : 0;
if (tugLight) { const [lx, lz] = toWorld(tug, 0, 9); tugLight.position.set(lx, SEA + 3, lz); tugLight.intensity = 22; }
if (ferryLight) { ferryLight.position.set(ferry.x, SEA + 10, ferry.z); ferryLight.intensity = ferryObj.visible && ferry.lightsOn ? 50 : 0; }
// tow rope visual
if (tow.b) {
const [sx, sz] = sternPoint(); const [hx, hz] = toWorld(tow.b, tow.lx, 0);
tugObj.updateMatrixWorld(true);
const p0 = new T.Vector3(0, 2.0, -5.0); tugObj.localToWorld(p0);
const p1 = new T.Vector3(hx, tow.b.obj.position.y + 2.2, hz);
const d = p0.distanceTo(p1); const slack = Math.max(0, tow.L + 0.5 - d) * 0.6 + (tow.F < 5 ? 0.5 : 0.05);
setRope(ropeMesh, p0, p1, slack);
}
// fx
const spd = Math.hypot(tug.vx, tug.vz);
wakeT -= dt;
if (spd > 3 && wakeT <= 0 && S.state === 'play') { wakeT = 0.18; const [bx, bz] = toWorld(tug, rand(-1.5, 1.5), 6); try { G.fx.splash(new T.Vector3(bx, seaH(bx, bz) + 0.2, bz), clamp(spd / 6, 0.4, 1.3)); } catch (e) {} }
smokeT -= dt;
if (smokeT <= 0) { smokeT = S.over > 0 ? 0.08 : 0.35 - Math.abs(S.throttle) * 0.2; tugObj.updateMatrixWorld(true); const p = new T.Vector3(0, 3.9, -1.4); tugObj.localToWorld(p); try { G.fx.smoke(p, { size: 0.6 + Math.abs(S.throttle), life: 2.5, rise: 1.2, color: S.over > 0 ? 0x111111 : 0x3a3a3a, count: 1, vel: new T.Vector3(-tug.vx * 0.5 - 1, 0.6, -tug.vz * 0.5 - 0.6) }); } catch (e) {} }
snd('setEngine', S.throttle, clamp(spd / 9, 0, 1), S.boost);
// knocking + hydrophone
const kb = S.knockId && S.knockId.alive && S.knockId.state !== 'lift' ? S.knockId : null;
if (kb && S.ch === 2) {
const d = Math.hypot(kb.x - tug.x, kb.z - tug.z);
const ang = Math.atan2(kb.x - tug.x, kb.z - tug.z), rel = wrapA(ang - tug.a);
knockVol = clamp(1 - d / 90, 0, 1);
snd('setKnock', knockVol * knockVol, clamp(-Math.sin(rel), -1, 1));
pingT -= dt; if (pingT <= 0 && !S.flags.found) { pingT = clamp(d / 25, 0.8, 4); snd('ping', clamp(1 - d / 140, 0.05, 1)); S.pingFlash = 1; }
} else snd('setKnock', 0, 0);
S.pingFlash = Math.max(0, (S.pingFlash || 0) - dt * 1.5);
updateHUD(dt, t);
updateCamera(dt, t);
return true;
};
function onSunk(b) {
S.lost++;
if (S.mode === 'shift') { S.lives--; flash('ut-hit'); say('HARBOUR', pick(['We lost one. It went straight down.', 'Box gone. That’s money on the seabed.', 'Another one sank.'])); if (S.lives <= 0) fail('Too many boxes on the seabed.'); return; }
if (b.knock) { fail('The box with Nico in it went under.'); return; }
if (S.ch === 1) { say('HARBOUR', 'That one’s gone. Plenty more out there.'); spawnBox({ x: rand(140, 165), z: rand(-10, 50) }); }
}
function onDelivered(b) {
S.delivered++; S.totalDelivered++;
snd('success');
if (S.mode === 'shift') { S.score++; S.hull = Math.min(100, S.hull + 12); setObjective('Boxes saved: ' + S.score, 'Lives ' + S.lives); if (Math.random() < 0.5) say('HARBOUR', CARGO[cargoIdx++ % CARGO.length]); return; }
if (S.ch === 1) {
setObjective('Tow boxes into the pen', Math.min(3, S.delivered) + ' / 3');
if (S.delivered < 3) say('HARBOUR', CARGO[cargoIdx++ % CARGO.length]);
} else if (S.ch === 3) say('HARBOUR', 'Penned. That’s out of her way too.');
}
function onRescue(b) {
if (S.flags.rescued) return;
S.flags.rescued = 1; dropLine(); b.state = 'saved'; b.sink = 0; b.im = 0; b.iI = 0; b.vx = b.vz = b.w = 0;
snd('success'); flash('ut-good');
say('HARBOUR', 'Medics have the doors open… we’ve got him. A kid, frozen half to death, but breathing.');
say('NICO', 'Thank you. Thank you. I’m Nico.');
S.flags.doneT = S.chT;
}
function laneCount() { return boxes.filter(b => b.alive && b.state !== 'lift' && b.z > W.lane.z0 - 1.5 && b.z < W.lane.z1 + 1.5 && b.x > W.lane.x0 - 10 && b.x < W.lane.x1 + 10).length; }
function chapterUpdate(dt, t) {
if (S.state !== 'play' && S.state !== 'cine') return;
if (S.mode === 'shift') return shiftUpdate(dt, t);
const id = CH[S.ch].id;
if (id === 'castoff') {
for (const g of gates) {
if (g.done) continue;
const [lx, lz] = toLocal({ x: g.x, z: g.z, a: g.a }, tug.x, tug.z);
if (Math.abs(lx) < 7 && Math.abs(lz) < 3) { g.done = true; g.objs.forEach(o => o.userData.lamp.material = EM(0x30ff70, 8)); snd('chime'); snd('success'); }
}
const n = gates.filter(g => g.done).length; setObjective('Run the gates', n + ' / 3');
if (n === 3 && !S.flags.done) { S.flags.done = 1; S.flags.doneT = S.chT; say('HARBOUR', 'Still got it. The spill is east of the barge. Let’s go fishing.'); }
if (S.flags.done && S.chT - S.flags.doneT > 4) { startChapter(1); return; }
} else if (id === 'flotsam') {
if (S.delivered >= 3 && !S.flags.done) { S.flags.done = 1; S.flags.doneT = S.chT; say('HARBOUR', 'That’s three on the barge. Wait… Petrel, do you hear that?'); }
if (S.flags.done && S.chT - S.flags.doneT > 5) { startChapter(2); return; }
} else if (id === 'knock') {
if (S.flags.rescued && S.chT - S.flags.doneT > 8) { startChapter(3); return; }
} else if (id === 'channel') {
S.timer -= dt;
const n = laneCount();
setObjective('Clear the ferry channel', n ? n + (n === 1 ? ' box' : ' boxes') + ' in the lane' : 'Lane clear');
if (S.timer < 60 && !S.flags.warn60) { S.flags.warn60 = 1; say('ALBATROSS', 'Albatross, one minute out. I can see the breakwater light.'); snd('ferryHorn', 0.9); }
if (n === 1 && !S.flags.one) { S.flags.one = 1; say('HARBOUR', 'One left in the lane!'); }
if (S.timer < 35 && ferry.mode === 'hidden') {
ferry.mode = 'inbound'; ferryObj.visible = true; ferry.ghost = false; ferry.x = 300; ferry.z = 103; ferry.a = -Math.PI / 2; ferrySetDynamic(false);
}
if (ferry.mode === 'inbound') { ferry.vx = -5; ferry.vz = 0; ferry.w = 0; }
if (n === 0 && !S.flags.done) {
S.flags.done = 1; S.flags.doneT = S.chT; snd('success'); flash('ut-good');
say('HARBOUR', 'Channel’s clear. Albatross, you’re good to come in.');
say('ALBATROSS', 'Thank you, Petrel. We owe you a pint.');
}
if (S.flags.done && S.chT - S.flags.doneT > 6) { startChapter(4); return; }
if (!S.flags.done && S.timer <= 0) {
fail('The Albatross ran onto a box in the channel.');
snd('ferryHorn', 0.3);
}
$('ut-timer').textContent = fmtTime(Math.max(0, S.timer));
$('ut-timer').classList.toggle('ut-urgent', S.timer < 45);
} else if (id === 'lee') {
if (S.state === 'cine') { endCine(dt); return; }
// restart progress: faster when she is well clear and while being pushed
const southEdge = Math.min(...corners(ferry).map(c => c[1]));
const clear = southEdge - (W.bw.z1 + 4);
S.flags.pushing = Math.max(0, (S.flags.pushing || 0) - dt * 2);
S.flags.restart = clamp(S.flags.restart + dt / 60 * (clear > 20 ? 1.4 : 1) * (S.flags.pushing > 0 ? 1.25 : 1), 0, 1);
setObjective('Keep the Albatross off the breakwater', 'Engines ' + Math.round(S.flags.restart * 100) + '% · ' + Math.max(0, Math.round(clear)) + ' m to the rocks');
if (S.flags.restart > 0.35 && !S.flags.r1) { S.flags.r1 = 1; say('ALBATROSS', 'Chief has one generator turning over. Keep her off!'); }
if (S.flags.restart > 0.7 && !S.flags.r2) { S.flags.r2 = 1; say('HARBOUR', 'Gust coming through. Lean on her, Petrel!'); S.gustT = 0; }
const hit = S.flags.ferryHit || (ferry.x > W.bw.x - 40 && ferry.x < W.bw.x + 40 && southEdge < W.bw.z1 + 3);
if (hit) { fail('The Albatross went onto the breakwater.'); snd('shipGroan'); return; }
if (S.flags.restart >= 1) {
ferryLights(true); snd('ferryHorn', 0.2); snd('success'); flash('ut-good');
say('ALBATROSS', 'We have power! Steering answers! Petrel, you beautiful little boat.');
say('HARBOUR', 'That’s the night, Petrel. Nico’s asking for the captain who found him. Bring her home.');
ferrySetDynamic(false); ferry.mode = 'home'; finishStory();
}
}
}
function endCine(dt) {
S.endT += dt;
const ta = -Math.PI / 2; ferry.a += wrapA(ta - ferry.a) * dt * 0.3; ferry.vx = Math.sin(ferry.a) * 3.5; ferry.vz = Math.cos(ferry.a) * 3.5 + (103 - ferry.z) * 0.1; ferry.w = 0;
if (S.endT > 14 && S.state === 'cine') { S.state = 'done'; showEnd(); }
}
function shiftUpdate(dt, t) {
S.shiftT += dt;
S.storm = clamp(0.45 + S.shiftT / 600, 0.45, 1);
S.spawnT -= dt;
const alive = boxes.filter(b => b.state !== 'lift').length;
if (S.spawnT <= 0 && alive < 9) { S.spawnT = clamp(22 - S.shiftT / 30, 9, 22); spawnRandomBox(); }
S.ferryT -= dt;
S.timer = S.ferryT; show('ut-timer', true); $('ut-timer').textContent = fmtTime(Math.max(0, S.ferryT)); $('ut-timer').classList.toggle('ut-urgent', S.ferryT < 20);
if (S.ferryT < 20 && ferry.mode === 'hidden') { ferry.mode = 'inbound'; ferryObj.visible = true; ferry.ghost = true; ferry.x = 330; ferry.z = 103; ferry.a = -Math.PI / 2; snd('ferryHorn', 0.8); say('ALBATROSS', 'Albatross inbound. Keep that lane clear!'); }
if (ferry.mode === 'inbound') {
ferry.vx = -8; ferry.vz = 0; ferry.w = 0;
for (const b of boxes.slice()) if (b.state !== 'lift' && inside(ferry, b.x, b.z, 1.5)) {
if (tow.b === b) dropLine(); removeBox(b); S.lives--; snd('thud', 1); snd('ferryHorn', 0.3); flash('ut-hit');
try { G.fx.splash(new T.Vector3(b.x, SEA, b.z), 3); G.fx.debris && G.fx.debris(new T.Vector3(b.x, SEA + 1, b.z), { mat: 'paint_red', count: 12 }); } catch (e) {}
say('ALBATROSS', 'We hit something! Petrel, that lane was supposed to be clear!');
setObjective('Boxes saved: ' + S.score, 'Lives ' + S.lives);
if (S.lives <= 0) { fail('The Albatross hit one too many boxes.'); return; }
}
if (inside(ferry, tug.x, tug.z, 2)) { S.hull -= 60 * dt; S.shake = 1; }
if (ferry.x < 40) { ferry.mode = 'hidden'; ferryObj.visible = false; S.ferryT = 120; }
}
setObjective('Boxes saved: ' + S.score, 'Lives ' + S.lives);
}
const fmtTime = s => Math.floor(s / 60) + ':' + String(Math.floor(s % 60)).padStart(2, '0');
/* ---------- HUD update */
function updateHUD(dt, t) {
$('ut-hull').style.width = clamp(S.hull, 0, 100) + '%';
$('ut-hull').parentElement.classList.toggle('ut-low', S.hull < 35);
$('ut-heat').style.width = S.heat * 100 + '%';
$('ut-heat').parentElement.classList.toggle('ut-low', S.over > 0);
const spd = Math.hypot(tug.vx, tug.vz) * 1.944;
$('ut-kn').textContent = spd.toFixed(1);
$('ut-telv').style.transform = `translateY(${-S.throttle * 34}px)`;
show('ut-tow', !!tow.b);
if (tow.b) {
const r = clamp(tow.F / tow.max, 0, 1.3);
$('ut-tension').style.width = clamp(r / 1.3 * 100, 0, 100) + '%';
$('ut-tension').parentElement.classList.toggle('ut-low', r > 1);
$('ut-lim').style.left = (1 / 1.3 * 100) + '%';
}
// prompt
let prompt = '';
if (S.state === 'play') {
if (tow.b) prompt = (isTouch ? 'HOOK' : 'E') + ' Release';
else {
const [sx, sz] = sternPoint();
const near = boxes.some(b => b.state === 'drift' && (p => Math.hypot(p.x - sx, p.z - sz) < 16)(hookPoint(b)));
if (near) prompt = (isTouch ? 'HOOK' : 'E') + ' Hook';
}
}
$('ut-prompt').textContent = prompt; show('ut-prompt', !!prompt);
// markers
markUsed = 0;
if (S.state === 'play') {
for (const b of boxes) {
if (b.state === 'lift' || b.state === 'saved') continue;
const d = Math.hypot(b.x - tug.x, b.z - tug.z);
if (S.ch === 2 && !S.flags.found) continue;
const urgent = b.float < 0.35;
const cls = (b === tow.b ? 'tow' : b.lane && S.ch === 3 && b.z > W.lane.z0 - 1.5 && b.z < W.lane.z1 + 1.5 ? 'lane' : 'box') + (urgent ? ' urgent' : '');
if (b === tow.b || d < 140) mark(b.x, b.obj.position.y + 4, b.z, cls, b === tow.b ? '' : Math.round(d) + '');
}
if (tow.b) {
if (tow.b.knock) mark(W.medic.x, SEA + 4, W.medic.z, 'goal', 'MEDICS');
else mark(W.pen.x, SEA + 4, W.pen.z, 'goal', 'PEN');
}
if (S.mode === 'story' && S.ch === 0) for (const g of gates) if (!g.done) mark(g.x, SEA + 3, g.z, 'gate', '');
if (S.mode === 'story' && S.ch === 4) mark(ferry.x, SEA + 14, ferry.z, 'ferry', 'ALBATROSS');
}
for (let i = markUsed; i < markPool.length; i++) markPool[i].style.display = 'none';
// radar
drawRadar(t);
}
function drawRadar(t) {
const c = rctx, R = 100, sc = R / 150;
c.clearRect(0, 0, 200, 200);
c.save(); c.translate(100, 100);
c.beginPath(); c.arc(0, 0, 98, 0, TAU); c.fillStyle = 'rgba(11,13,15,.62)'; c.fill(); c.strokeStyle = 'rgba(232,228,218,.25)'; c.lineWidth = 1; c.stroke();
c.beginPath(); c.arc(0, 0, 49, 0, TAU); c.strokeStyle = 'rgba(232,228,218,.08)'; c.stroke();
c.clip();
const ca = Math.cos(-tug.a + Math.PI), sa = Math.sin(-tug.a + Math.PI);
const P = (x, z) => { const dx = (x - tug.x) * sc, dz = (z - tug.z) * sc; return [dx * ca - dz * sa, dx * sa + dz * ca]; };
// quay
c.strokeStyle = 'rgba(232,228,218,.35)'; c.lineWidth = 2; c.beginPath(); let p = P(31, -160); c.moveTo(p[0], p[1]); p = P(31, 200); c.lineTo(p[0], p[1]); c.stroke();
// breakwater
c.lineWidth = 4; c.beginPath(); p = P(W.bw.x, W.bw.z0); c.moveTo(p[0], p[1]); p = P(W.bw.x, W.bw.z1); c.lineTo(p[0], p[1]); c.stroke();
// lane
c.lineWidth = 1; c.setLineDash([3, 4]); c.strokeStyle = 'rgba(255,179,71,.45)';
for (const z of [W.lane.z0, W.lane.z1]) { c.beginPath(); p = P(W.lane.x0, z); c.moveTo(p[0], p[1]); p = P(W.lane.x1 + 60, z); c.lineTo(p[0], p[1]); c.stroke(); }
c.setLineDash([]);
// pen
p = P(W.pen.x, W.pen.z); c.beginPath(); c.arc(p[0], p[1], W.pen.r * sc, 0, TAU); c.strokeStyle = 'rgba(120,220,140,.8)'; c.lineWidth = 1.5; c.stroke();
if (S.ch === 2 && S.flags.found) { p = P(W.medic.x, W.medic.z); c.beginPath(); c.arc(p[0], p[1], 6, 0, TAU); c.strokeStyle = 'rgba(110,160,255,.9)'; c.stroke(); }
// boxes
for (const b of boxes) {
if (b.state === 'lift') continue;
if (S.ch === 2 && b.knock && !S.flags.found) continue;
p = P(b.x, b.z);
c.fillStyle = b.float < 0.35 ? (t % 0.6 < 0.3 ? '#ff5a40' : '#7a2a20') : b === tow.b ? '#ffc977' : '#e8e4da';
c.fillRect(p[0] - 2.5, p[1] - 2.5, 5, 5);
}
// knock ping ring
if (S.ch === 2 && S.knockId && !S.flags.found && S.pingFlash > 0) {
const kb = S.knockId; const d = Math.hypot(kb.x - tug.x, kb.z - tug.z);
const ang = Math.atan2(kb.x - tug.x, kb.z - tug.z); p = P(tug.x + Math.sin(ang) * 60, tug.z + Math.cos(ang) * 60);
c.strokeStyle = `rgba(255,179,71,${S.pingFlash})`; c.lineWidth = 3; c.beginPath(); c.moveTo(p[0] * 0.55, p[1] * 0.55); c.lineTo(p[0] * 1.2, p[1] * 1.2); c.stroke();
c.beginPath(); c.arc(0, 0, (1 - S.pingFlash) * 95, 0, TAU); c.lineWidth = 1; c.stroke();
}
if (ferryObj.visible) {
const cs = corners(ferry).map(([x, z]) => P(x, z));
c.fillStyle = ferry.lightsOn ? 'rgba(255,210,150,.8)' : 'rgba(140,150,160,.8)'; c.beginPath(); cs.forEach(([x, z], i) => i ? c.lineTo(x, z) : c.moveTo(x, z)); c.fill();
}
c.restore();
// own ship
c.fillStyle = '#ffb347'; c.beginPath(); c.moveTo(100, 92); c.lineTo(105, 106); c.lineTo(95, 106); c.closePath(); c.fill();
}
/* ---------- engine hooks */
game.start = (o = {}) => {
const p = G.params;
S.startTime = performance.now();
if (p.mode === 'shift') startShift(); else startChapter(clamp(+(p.ch || 1) - 1, 0, 4));
};
window.__UNDERTOW = { overlaps: () => statics.filter(s => sat(tug, s)).map(s => s.tag), setWind: v => { FERRY_WIND = v; }, S, tug, boxes, ferry, tow, W, startChapter, startShift, bodies, game };
// the main loop runs our update; sync the tug once so the title shot has a boat in it
placeTug(W.berth.x - 4, W.berth.z, Math.PI / 2 * 0);
for (let i = 0; i < 4; i++) spawnBox({ x: rand(110, 170), z: rand(-20, 60) });
syncBody(tug, 0, 0.1, 0);
setState('title');
return game;
}
window.__UT = { input: makeInput, game: (G, L) => makeGame(G, L) };
})();
</script>
<script>
(()=>{var bT=Object.defineProperty;var ar=(n,e)=>{for(var t in e)bT(n,t,{get:e[t],enumerable:!0})};var ut={};ar(ut,{ACESFilmicToneMapping:()=>Of,AddEquation:()=>pr,AddOperation:()=>ox,AdditiveAnimationBlendMode:()=>j2,AdditiveBlending:()=>wr,AgXToneMapping:()=>ux,AlphaFormat:()=>Y2,AlwaysCompare:()=>Rx,AlwaysDepth:()=>Xc,AlwaysStencilFunc:()=>Dm,AmbientLight:()=>Kd,AnimationAction:()=>ap,AnimationClip:()=>kl,AnimationLoader:()=>Km,AnimationMixer:()=>u2,AnimationObjectGroup:()=>c2,AnimationUtils:()=>jm,ArcCurve:()=>Td,ArrayCamera:()=>ip,ArrowHelper:()=>D2,AttachedBindMode:()=>zm,Audio:()=>op,AudioAnalyser:()=>l2,AudioContext:()=>Uf,AudioListener:()=>r2,AudioLoader:()=>s2,AxesHelper:()=>L2,BackSide:()=>ts,BasicDepthPacking:()=>yx,BasicShadowMap:()=>b4,BatchedMesh:()=>bd,Bone:()=>qr,BooleanKeyframeTrack:()=>Yr,Box2:()=>M2,Box3:()=>B0,Box3Helper:()=>I2,BoxGeometry:()=>R0,BoxHelper:()=>P2,BufferAttribute:()=>nt,BufferGeometry:()=>pt,BufferGeometryLoader:()=>np,ByteType:()=>W2,Cache:()=>dr,Camera:()=>zc,CameraHelper:()=>k2,CanvasTexture:()=>Rs,CapsuleGeometry:()=>Uc,CatmullRomCurve3:()=>Sa,CineonToneMapping:()=>lx,CircleGeometry:()=>Bc,ClampToEdgeWrapping:()=>Vi,Clock:()=>sp,Color:()=>Qe,ColorKeyframeTrack:()=>Lf,ColorManagement:()=>S0,CompressedArrayTexture:()=>Ym,CompressedCubeTexture:()=>$m,CompressedTexture:()=>Nc,CompressedTextureLoader:()=>Jm,ConeGeometry:()=>El,ConstantAlphaFactor:()=>nx,ConstantColorFactor:()=>ex,Controls:()=>N2,CubeCamera:()=>Dc,CubeReflectionMapping:()=>Zr,CubeRefractionMapping:()=>Ca,CubeTexture:()=>_l,CubeTextureLoader:()=>Qm,CubeUVReflectionMapping:()=>Yc,CubicBezierCurve:()=>Tf,CubicBezierCurve3:()=>Ad,CubicInterpolant:()=>qd,CullFaceBack:()=>B2,CullFaceFront:()=>V3,CullFaceFrontBack:()=>y4,CullFaceNone:()=>O3,Curve:()=>so,CurvePath:()=>Cd,CustomBlending:()=>cp,CustomToneMapping:()=>cx,CylinderGeometry:()=>io,Cylindrical:()=>y2,Data3DTexture:()=>kc,DataArrayTexture:()=>Cc,DataTexture:()=>li,DataTextureLoader:()=>e2,DataUtils:()=>Ic,DecrementStencilOp:()=>P4,DecrementWrapStencilOp:()=>z4,DefaultLoadingManager:()=>Fx,DepthFormat:()=>Tc,DepthStencilFormat:()=>Kc,DepthTexture:()=>Xr,DetachedBindMode:()=>hx,DirectionalLight:()=>Il,DirectionalLightHelper:()=>C2,DiscreteInterpolant:()=>Xd,DodecahedronGeometry:()=>Ed,DoubleSide:()=>ln,DstAlphaFactor:()=>Z3,DstColorFactor:()=>K3,DynamicCopyUsage:()=>Y4,DynamicDrawUsage:()=>Ao,DynamicReadUsage:()=>G4,EdgesGeometry:()=>Sd,EllipseCurve:()=>Hc,EqualCompare:()=>Ex,EqualDepth:()=>dp,EqualStencilFunc:()=>N4,EquirectangularReflectionMapping:()=>Vf,EquirectangularRefractionMapping:()=>Wf,Euler:()=>_0,EventDispatcher:()=>So,ExternalTexture:()=>Sf,ExtrudeGeometry:()=>vr,FileLoader:()=>Go,Float16BufferAttribute:()=>Vm,Float32BufferAttribute:()=>et,FloatType:()=>us,Fog:()=>gd,FogExp2:()=>md,FramebufferTexture:()=>Xm,FrontSide:()=>Vr,Frustum:()=>wa,FrustumArray:()=>yd,GLBufferAttribute:()=>m2,GLSL1:()=>Z4,GLSL3:()=>jf,GreaterCompare:()=>Sx,GreaterDepth:()=>mp,GreaterEqualCompare:()=>Ax,GreaterEqualDepth:()=>pp,GreaterEqualStencilFunc:()=>O4,GreaterStencilFunc:()=>B4,GridHelper:()=>A2,Group:()=>At,HalfFloatType:()=>ro,HemisphereLight:()=>$d,HemisphereLightHelper:()=>T2,IcosahedronGeometry:()=>zd,ImageBitmapLoader:()=>i2,ImageLoader:()=>Pl,ImageUtils:()=>pd,IncrementStencilOp:()=>k4,IncrementWrapStencilOp:()=>I4,InstancedBufferAttribute:()=>Xs,InstancedBufferGeometry:()=>Ra,InstancedInterleavedBuffer:()=>p2,InstancedMesh:()=>Wo,Int16BufferAttribute:()=>Hm,Int32BufferAttribute:()=>Om,Int8BufferAttribute:()=>Nm,IntType:()=>vp,InterleavedBuffer:()=>wl,InterleavedBufferAttribute:()=>Ma,Interpolant:()=>Tl,InterpolateDiscrete:()=>pf,InterpolateLinear:()=>dd,InterpolateSmooth:()=>ld,InterpolationSamplingMode:()=>J4,InterpolationSamplingType:()=>K4,InvertStencilOp:()=>D4,KeepStencilOp:()=>xl,KeyframeTrack:()=>Ys,LOD:()=>vd,LatheGeometry:()=>yr,Layers:()=>Pc,LessCompare:()=>wx,LessDepth:()=>hp,LessEqualCompare:()=>K2,LessEqualDepth:()=>Ml,LessEqualStencilFunc:()=>U4,LessStencilFunc:()=>F4,Light:()=>br,LightProbe:()=>ep,Line:()=>gr,Line3:()=>_2,LineBasicMaterial:()=>es,LineCurve:()=>Af,LineCurve3:()=>Rd,LineDashedMaterial:()=>Gd,LineLoop:()=>Md,LineSegments:()=>To,LinearFilter:()=>x0,LinearInterpolant:()=>Df,LinearMipMapLinearFilter:()=>E4,LinearMipMapNearestFilter:()=>w4,LinearMipmapLinearFilter:()=>yn,LinearMipmapNearestFilter:()=>Gf,LinearSRGBColorSpace:()=>Wr,LinearToneMapping:()=>rx,LinearTransfer:()=>gf,Loader:()=>fs,LoaderUtils:()=>Nf,LoadingManager:()=>Ff,LoopOnce:()=>dx,LoopPingPong:()=>mx,LoopRepeat:()=>px,MOUSE:()=>x4,Material:()=>Wi,MaterialLoader:()=>tp,MathUtils:()=>ks,Matrix2:()=>b2,Matrix3:()=>Qt,Matrix4:()=>Je,MaxEquation:()=>X3,Mesh:()=>ht,MeshBasicMaterial:()=>An,MeshDepthMaterial:()=>If,MeshDistanceMaterial:()=>zf,MeshLambertMaterial:()=>Vd,MeshMatcapMaterial:()=>Wd,MeshNormalMaterial:()=>Od,MeshPhongMaterial:()=>Bd,MeshPhysicalMaterial:()=>Ud,MeshStandardMaterial:()=>L0,MeshToonMaterial:()=>Hd,MinEquation:()=>q3,MirroredRepeatWrapping:()=>df,MixOperation:()=>sx,MultiplyBlending:()=>O2,MultiplyOperation:()=>Hf,NearestFilter:()=>Dn,NearestMipMapLinearFilter:()=>_4,NearestMipMapNearestFilter:()=>M4,NearestMipmapLinearFilter:()=>$c,NearestMipmapNearestFilter:()=>V2,NeutralToneMapping:()=>fx,NeverCompare:()=>_x,NeverDepth:()=>fp,NeverStencilFunc:()=>L4,NoBlending:()=>qo,NoColorSpace:()=>ci,NoToneMapping:()=>Cs,NormalAnimationBlendMode:()=>Kp,NormalBlending:()=>bl,NotEqualCompare:()=>Tx,NotEqualDepth:()=>gp,NotEqualStencilFunc:()=>H4,NumberKeyframeTrack:()=>Al,Object3D:()=>A0,ObjectLoader:()=>n2,ObjectSpaceNormalMap:()=>Mx,OctahedronGeometry:()=>Sl,OneFactor:()=>qc,OneMinusConstantAlphaFactor:()=>ix,OneMinusConstantColorFactor:()=>tx,OneMinusDstAlphaFactor:()=>j3,OneMinusDstColorFactor:()=>J3,OneMinusSrcAlphaFactor:()=>Sc,OneMinusSrcColorFactor:()=>$3,OrthographicCamera:()=>Mr,PCFShadowMap:()=>Bf,PCFSoftShadowMap:()=>lp,PMREMGenerator:()=>Pa,Path:()=>xr,PerspectiveCamera:()=>zn,Plane:()=>wo,PlaneGeometry:()=>w0,PlaneHelper:()=>z2,PointLight:()=>Aa,PointLightHelper:()=>S2,Points:()=>_d,PointsMaterial:()=>Ef,PolarGridHelper:()=>R2,PolyhedronGeometry:()=>Ea,PositionalAudio:()=>a2,PropertyBinding:()=>X0,PropertyMixer:()=>rp,QuadraticBezierCurve:()=>Rf,QuadraticBezierCurve3:()=>Cf,Quaternion:()=>St,QuaternionKeyframeTrack:()=>Rl,QuaternionLinearInterpolant:()=>Yd,RED_GREEN_RGTC2_Format:()=>Zp,RED_RGTC1_Format:()=>Yp,REVISION:()=>H3,RGBADepthPacking:()=>bx,RGBAFormat:()=>$0,RGBAIntegerFormat:()=>_p,RGBA_ASTC_10x10_Format:()=>Op,RGBA_ASTC_10x5_Format:()=>Up,RGBA_ASTC_10x6_Format:()=>Bp,RGBA_ASTC_10x8_Format:()=>Hp,RGBA_ASTC_12x10_Format:()=>Vp,RGBA_ASTC_12x12_Format:()=>Wp,RGBA_ASTC_4x4_Format:()=>kp,RGBA_ASTC_5x4_Format:()=>Pp,RGBA_ASTC_5x5_Format:()=>Ip,RGBA_ASTC_6x5_Format:()=>zp,RGBA_ASTC_6x6_Format:()=>Dp,RGBA_ASTC_8x5_Format:()=>Lp,RGBA_ASTC_8x6_Format:()=>Fp,RGBA_ASTC_8x8_Format:()=>Np,RGBA_BPTC_Format:()=>Gp,RGBA_ETC2_EAC_Format:()=>Cp,RGBA_PVRTC_2BPPV1_Format:()=>Tp,RGBA_PVRTC_4BPPV1_Format:()=>Sp,RGBA_S3TC_DXT1_Format:()=>Yf,RGBA_S3TC_DXT3_Format:()=>$f,RGBA_S3TC_DXT5_Format:()=>Zf,RGBDepthPacking:()=>T4,RGBFormat:()=>$2,RGBIntegerFormat:()=>S4,RGB_BPTC_SIGNED_Format:()=>qp,RGB_BPTC_UNSIGNED_Format:()=>Xp,RGB_ETC1_Format:()=>Ap,RGB_ETC2_Format:()=>Rp,RGB_PVRTC_2BPPV1_Format:()=>Ep,RGB_PVRTC_4BPPV1_Format:()=>wp,RGB_S3TC_DXT1_Format:()=>Xf,RGDepthPacking:()=>A4,RGFormat:()=>Z2,RGIntegerFormat:()=>Mp,RawShaderMaterial:()=>Gc,Ray:()=>ba,Raycaster:()=>g2,RectAreaLight:()=>Jd,RedFormat:()=>Jc,RedIntegerFormat:()=>qf,ReinhardToneMapping:()=>ax,RenderTarget:()=>bf,RenderTarget3D:()=>f2,RepeatWrapping:()=>qs,ReplaceStencilOp:()=>C4,ReverseSubtractEquation:()=>G3,RingGeometry:()=>Vc,SIGNED_RED_GREEN_RGTC2_Format:()=>jp,SIGNED_RED_RGTC1_Format:()=>$p,SRGBColorSpace:()=>In,SRGBTransfer:()=>Y0,Scene:()=>mr,ShaderChunk:()=>Yt,ShaderLib:()=>Er,ShaderMaterial:()=>vn,ShadowMaterial:()=>Nd,Shape:()=>Qi,ShapeGeometry:()=>Wc,ShapePath:()=>F2,ShapeUtils:()=>As,ShortType:()=>G2,Skeleton:()=>_a,SkeletonHelper:()=>E2,SkinnedMesh:()=>Gr,Source:()=>hr,Sphere:()=>an,SphereGeometry:()=>Gi,Spherical:()=>v2,SphericalHarmonics3:()=>Qd,SplineCurve:()=>kf,SpotLight:()=>jd,SpotLightHelper:()=>w2,Sprite:()=>xd,SpriteMaterial:()=>wf,SrcAlphaFactor:()=>hd,SrcAlphaSaturateFactor:()=>Q3,SrcColorFactor:()=>Y3,StaticCopyUsage:()=>X4,StaticDrawUsage:()=>xf,StaticReadUsage:()=>W4,StereoCamera:()=>o2,StreamCopyUsage:()=>$4,StreamDrawUsage:()=>V4,StreamReadUsage:()=>q4,StringKeyframeTrack:()=>$r,SubtractEquation:()=>W3,SubtractiveBlending:()=>H2,TOUCH:()=>v4,TangentSpaceNormalMap:()=>ka,TetrahedronGeometry:()=>Dd,Texture:()=>_i,TextureLoader:()=>t2,TextureUtils:()=>U2,Timer:()=>x2,TimestampQuery:()=>j4,TorusGeometry:()=>jn,TorusKnotGeometry:()=>Ld,Triangle:()=>fr,TriangleFanDrawMode:()=>vx,TriangleStripDrawMode:()=>xx,TrianglesDrawMode:()=>gx,TubeGeometry:()=>Ta,UVMapping:()=>xp,Uint16BufferAttribute:()=>Mf,Uint32BufferAttribute:()=>_f,Uint8BufferAttribute:()=>Um,Uint8ClampedBufferAttribute:()=>Bm,Uniform:()=>h2,UniformsGroup:()=>d2,UniformsLib:()=>yt,UniformsUtils:()=>zx,UnsignedByteType:()=>wi,UnsignedInt101111Type:()=>X2,UnsignedInt248Type:()=>jc,UnsignedInt5999Type:()=>q2,UnsignedIntType:()=>oo,UnsignedShort4444Type:()=>yp,UnsignedShort5551Type:()=>bp,UnsignedShortType:()=>Zc,VSMShadowMap:()=>_r,Vector2:()=>We,Vector3:()=>K,Vector4:()=>Jt,VectorKeyframeTrack:()=>Cl,VideoFrameTexture:()=>qm,VideoTexture:()=>wd,WebGL3DRenderTarget:()=>Fm,WebGLArrayRenderTarget:()=>Lm,WebGLCoordinateSystem:()=>no,WebGLCubeRenderTarget:()=>Lc,WebGLRenderTarget:()=>Zn,WebGLRenderer:()=>Qp,WebGLUtils:()=>NM,WebGPUCoordinateSystem:()=>Ac,WebXRController:()=>Fc,WireframeGeometry:()=>Fd,WrapAroundEnding:()=>mf,ZeroCurvatureEnding:()=>vl,ZeroFactor:()=>up,ZeroSlopeEnding:()=>yl,ZeroStencilOp:()=>R4,createCanvasElement:()=>Px});var H3="180",x4={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},v4={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},O3=0,B2=1,V3=2,y4=3,b4=0,Bf=1,lp=2,_r=3,Vr=0,ts=1,ln=2,qo=0,bl=1,wr=2,H2=3,O2=4,cp=5,pr=100,W3=101,G3=102,q3=103,X3=104,up=200,qc=201,Y3=202,$3=203,hd=204,Sc=205,Z3=206,j3=207,K3=208,J3=209,Q3=210,ex=211,tx=212,nx=213,ix=214,fp=0,Xc=1,hp=2,Ml=3,dp=4,pp=5,mp=6,gp=7,Hf=0,sx=1,ox=2,Cs=0,rx=1,ax=2,lx=3,Of=4,cx=5,ux=6,fx=7,zm="attached",hx="detached",xp=300,Zr=301,Ca=302,Vf=303,Wf=304,Yc=306,qs=1e3,Vi=1001,df=1002,Dn=1003,V2=1004,M4=1004,$c=1005,_4=1005,x0=1006,Gf=1007,w4=1007,yn=1008,E4=1008,wi=1009,W2=1010,G2=1011,Zc=1012,vp=1013,oo=1014,us=1015,ro=1016,yp=1017,bp=1018,jc=1020,q2=35902,X2=35899,Y2=1021,$2=1022,$0=1023,Tc=1026,Kc=1027,Jc=1028,qf=1029,Z2=1030,Mp=1031,S4=1032,_p=1033,Xf=33776,Yf=33777,$f=33778,Zf=33779,wp=35840,Ep=35841,Sp=35842,Tp=35843,Ap=36196,Rp=37492,Cp=37496,kp=37808,Pp=37809,Ip=37810,zp=37811,Dp=37812,Lp=37813,Fp=37814,Np=37815,Up=37816,Bp=37817,Hp=37818,Op=37819,Vp=37820,Wp=37821,Gp=36492,qp=36494,Xp=36495,Yp=36283,$p=36284,Zp=36285,jp=36286,dx=2200,px=2201,mx=2202,pf=2300,dd=2301,ld=2302,vl=2400,yl=2401,mf=2402,Kp=2500,j2=2501,gx=0,xx=1,vx=2,yx=3200,bx=3201,T4=3202,A4=3203,ka=0,Mx=1,ci="",In="srgb",Wr="srgb-linear",gf="linear",Y0="srgb",R4=0,xl=7680,C4=7681,k4=7682,P4=7683,I4=34055,z4=34056,D4=5386,L4=512,F4=513,N4=514,U4=515,B4=516,H4=517,O4=518,Dm=519,_x=512,wx=513,Ex=514,K2=515,Sx=516,Tx=517,Ax=518,Rx=519,xf=35044,Ao=35048,V4=35040,W4=35045,G4=35049,q4=35041,X4=35046,Y4=35050,$4=35042,Z4="100",jf="300 es",no=2e3,Ac=2001,j4={COMPUTE:"compute",RENDER:"render"},K4={PERSPECTIVE:"perspective",LINEAR:"linear",FLAT:"flat"},J4={NORMAL:"normal",CENTROID:"centroid",SAMPLE:"sample",FIRST:"first",EITHER:"either"},So=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});let i=this._listeners;i[e]===void 0&&(i[e]=[]),i[e].indexOf(t)===-1&&i[e].push(t)}hasEventListener(e,t){let i=this._listeners;return i===void 0?!1:i[e]!==void 0&&i[e].indexOf(t)!==-1}removeEventListener(e,t){let i=this._listeners;if(i===void 0)return;let s=i[e];if(s!==void 0){let o=s.indexOf(t);o!==-1&&s.splice(o,1)}}dispatchEvent(e){let t=this._listeners;if(t===void 0)return;let i=t[e.type];if(i!==void 0){e.target=this;let s=i.slice(0);for(let o=0,r=s.length;o<r;o++)s[o].call(this,e);e.target=null}}},Es=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"],ub=1234567,Ec=Math.PI/180,Rc=180/Math.PI;function Eo(){let n=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Es[n&255]+Es[n>>8&255]+Es[n>>16&255]+Es[n>>24&255]+"-"+Es[e&255]+Es[e>>8&255]+"-"+Es[e>>16&15|64]+Es[e>>24&255]+"-"+Es[t&63|128]+Es[t>>8&255]+"-"+Es[t>>16&255]+Es[t>>24&255]+Es[i&255]+Es[i>>8&255]+Es[i>>16&255]+Es[i>>24&255]).toLowerCase()}function Wt(n,e,t){return Math.max(e,Math.min(t,n))}function Cx(n,e){return(n%e+e)%e}function MT(n,e,t,i,s){return i+(n-e)*(s-i)/(t-e)}function _T(n,e,t){return n!==e?(t-n)/(e-n):0}function cd(n,e,t){return(1-t)*n+t*e}function wT(n,e,t,i){return cd(n,e,1-Math.exp(-t*i))}function ET(n,e=1){return e-Math.abs(Cx(n,e*2)-e)}function ST(n,e,t){return n<=e?0:n>=t?1:(n=(n-e)/(t-e),n*n*(3-2*n))}function TT(n,e,t){return n<=e?0:n>=t?1:(n=(n-e)/(t-e),n*n*n*(n*(n*6-15)+10))}function AT(n,e){return n+Math.floor(Math.random()*(e-n+1))}function RT(n,e){return n+Math.random()*(e-n)}function CT(n){return n*(.5-Math.random())}function kT(n){n!==void 0&&(ub=n);let e=ub+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function PT(n){return n*Ec}function IT(n){return n*Rc}function zT(n){return(n&n-1)===0&&n!==0}function DT(n){return Math.pow(2,Math.ceil(Math.log(n)/Math.LN2))}function LT(n){return Math.pow(2,Math.floor(Math.log(n)/Math.LN2))}function FT(n,e,t,i,s){let o=Math.cos,r=Math.sin,a=o(t/2),l=r(t/2),c=o((e+i)/2),u=r((e+i)/2),f=o((e-i)/2),h=r((e-i)/2),p=o((i-e)/2),d=r((i-e)/2);switch(s){case"XYX":n.set(a*u,l*f,l*h,a*c);break;case"YZY":n.set(l*h,a*u,l*f,a*c);break;case"ZXZ":n.set(l*f,l*h,a*u,a*c);break;case"XZX":n.set(a*u,l*d,l*p,a*c);break;case"YXY":n.set(l*p,a*u,l*d,a*c);break;case"ZYZ":n.set(l*d,l*p,a*u,a*c);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+s)}}function Gs(n,e){switch(e.constructor){case Float32Array:return n;case Uint32Array:return n/4294967295;case Uint16Array:return n/65535;case Uint8Array:return n/255;case Int32Array:return Math.max(n/2147483647,-1);case Int16Array:return Math.max(n/32767,-1);case Int8Array:return Math.max(n/127,-1);default:throw new Error("Invalid component type.")}}function n0(n,e){switch(e.constructor){case Float32Array:return n;case Uint32Array:return Math.round(n*4294967295);case Uint16Array:return Math.round(n*65535);case Uint8Array:return Math.round(n*255);case Int32Array:return Math.round(n*2147483647);case Int16Array:return Math.round(n*32767);case Int8Array:return Math.round(n*127);default:throw new Error("Invalid component type.")}}var ks={DEG2RAD:Ec,RAD2DEG:Rc,generateUUID:Eo,clamp:Wt,euclideanModulo:Cx,mapLinear:MT,inverseLerp:_T,lerp:cd,damp:wT,pingpong:ET,smoothstep:ST,smootherstep:TT,randInt:AT,randFloat:RT,randFloatSpread:CT,seededRandom:kT,degToRad:PT,radToDeg:IT,isPowerOfTwo:zT,ceilPowerOfTwo:DT,floorPowerOfTwo:LT,setQuaternionFromProperEuler:FT,normalize:n0,denormalize:Gs},We=class n{constructor(e=0,t=0){n.prototype.isVector2=!0,this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){let t=this.x,i=this.y,s=e.elements;return this.x=s[0]*t+s[3]*i+s[6],this.y=s[1]*t+s[4]*i+s[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Wt(this.x,e.x,t.x),this.y=Wt(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=Wt(this.x,e,t),this.y=Wt(this.y,e,t),this}clampLength(e,t){let i=this.length();return this.divideScalar(i||1).multiplyScalar(Wt(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let i=this.dot(e)/t;return Math.acos(Wt(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,i=this.y-e.y;return t*t+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){let i=Math.cos(t),s=Math.sin(t),o=this.x-e.x,r=this.y-e.y;return this.x=o*i-r*s+e.x,this.y=o*s+r*i+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},St=class{constructor(e=0,t=0,i=0,s=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=i,this._w=s}static slerpFlat(e,t,i,s,o,r,a){let l=i[s+0],c=i[s+1],u=i[s+2],f=i[s+3],h=o[r+0],p=o[r+1],d=o[r+2],m=o[r+3];if(a===0){e[t+0]=l,e[t+1]=c,e[t+2]=u,e[t+3]=f;return}if(a===1){e[t+0]=h,e[t+1]=p,e[t+2]=d,e[t+3]=m;return}if(f!==m||l!==h||c!==p||u!==d){let x=1-a,v=l*h+c*p+u*d+f*m,y=v>=0?1:-1,b=1-v*v;if(b>Number.EPSILON){let E=Math.sqrt(b),M=Math.atan2(E,v*y);x=Math.sin(x*M)/E,a=Math.sin(a*M)/E}let g=a*y;if(l=l*x+h*g,c=c*x+p*g,u=u*x+d*g,f=f*x+m*g,x===1-a){let E=1/Math.sqrt(l*l+c*c+u*u+f*f);l*=E,c*=E,u*=E,f*=E}}e[t]=l,e[t+1]=c,e[t+2]=u,e[t+3]=f}static multiplyQuaternionsFlat(e,t,i,s,o,r){let a=i[s],l=i[s+1],c=i[s+2],u=i[s+3],f=o[r],h=o[r+1],p=o[r+2],d=o[r+3];return e[t]=a*d+u*f+l*p-c*h,e[t+1]=l*d+u*h+c*f-a*p,e[t+2]=c*d+u*p+a*h-l*f,e[t+3]=u*d-a*f-l*h-c*p,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,i,s){return this._x=e,this._y=t,this._z=i,this._w=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){let i=e._x,s=e._y,o=e._z,r=e._order,a=Math.cos,l=Math.sin,c=a(i/2),u=a(s/2),f=a(o/2),h=l(i/2),p=l(s/2),d=l(o/2);switch(r){case"XYZ":this._x=h*u*f+c*p*d,this._y=c*p*f-h*u*d,this._z=c*u*d+h*p*f,this._w=c*u*f-h*p*d;break;case"YXZ":this._x=h*u*f+c*p*d,this._y=c*p*f-h*u*d,this._z=c*u*d-h*p*f,this._w=c*u*f+h*p*d;break;case"ZXY":this._x=h*u*f-c*p*d,this._y=c*p*f+h*u*d,this._z=c*u*d+h*p*f,this._w=c*u*f-h*p*d;break;case"ZYX":this._x=h*u*f-c*p*d,this._y=c*p*f+h*u*d,this._z=c*u*d-h*p*f,this._w=c*u*f+h*p*d;break;case"YZX":this._x=h*u*f+c*p*d,this._y=c*p*f+h*u*d,this._z=c*u*d-h*p*f,this._w=c*u*f-h*p*d;break;case"XZY":this._x=h*u*f-c*p*d,this._y=c*p*f-h*u*d,this._z=c*u*d+h*p*f,this._w=c*u*f+h*p*d;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+r)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){let i=t/2,s=Math.sin(i);return this._x=e.x*s,this._y=e.y*s,this._z=e.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(e){let t=e.elements,i=t[0],s=t[4],o=t[8],r=t[1],a=t[5],l=t[9],c=t[2],u=t[6],f=t[10],h=i+a+f;if(h>0){let p=.5/Math.sqrt(h+1);this._w=.25/p,this._x=(u-l)*p,this._y=(o-c)*p,this._z=(r-s)*p}else if(i>a&&i>f){let p=2*Math.sqrt(1+i-a-f);this._w=(u-l)/p,this._x=.25*p,this._y=(s+r)/p,this._z=(o+c)/p}else if(a>f){let p=2*Math.sqrt(1+a-i-f);this._w=(o-c)/p,this._x=(s+r)/p,this._y=.25*p,this._z=(l+u)/p}else{let p=2*Math.sqrt(1+f-i-a);this._w=(r-s)/p,this._x=(o+c)/p,this._y=(l+u)/p,this._z=.25*p}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let i=e.dot(t)+1;return i<1e-8?(i=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=i):(this._x=0,this._y=-e.z,this._z=e.y,this._w=i)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=i),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(Wt(this.dot(e),-1,1)))}rotateTowards(e,t){let i=this.angleTo(e);if(i===0)return this;let s=Math.min(1,t/i);return this.slerp(e,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){let i=e._x,s=e._y,o=e._z,r=e._w,a=t._x,l=t._y,c=t._z,u=t._w;return this._x=i*u+r*a+s*c-o*l,this._y=s*u+r*l+o*a-i*c,this._z=o*u+r*c+i*l-s*a,this._w=r*u-i*a-s*l-o*c,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);let i=this._x,s=this._y,o=this._z,r=this._w,a=r*e._w+i*e._x+s*e._y+o*e._z;if(a<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,a=-a):this.copy(e),a>=1)return this._w=r,this._x=i,this._y=s,this._z=o,this;let l=1-a*a;if(l<=Number.EPSILON){let p=1-t;return this._w=p*r+t*this._w,this._x=p*i+t*this._x,this._y=p*s+t*this._y,this._z=p*o+t*this._z,this.normalize(),this}let c=Math.sqrt(l),u=Math.atan2(c,a),f=Math.sin((1-t)*u)/c,h=Math.sin(t*u)/c;return this._w=r*f+this._w*h,this._x=i*f+this._x*h,this._y=s*f+this._y*h,this._z=o*f+this._z*h,this._onChangeCallback(),this}slerpQuaternions(e,t,i){return this.copy(e).slerp(t,i)}random(){let e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),i=Math.random(),s=Math.sqrt(1-i),o=Math.sqrt(i);return this.set(s*Math.sin(e),s*Math.cos(e),o*Math.sin(t),o*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},K=class n{constructor(e=0,t=0,i=0){n.prototype.isVector3=!0,this.x=e,this.y=t,this.z=i}set(e,t,i){return i===void 0&&(i=this.z),this.x=e,this.y=t,this.z=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(fb.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(fb.setFromAxisAngle(e,t))}applyMatrix3(e){let t=this.x,i=this.y,s=this.z,o=e.elements;return this.x=o[0]*t+o[3]*i+o[6]*s,this.y=o[1]*t+o[4]*i+o[7]*s,this.z=o[2]*t+o[5]*i+o[8]*s,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){let t=this.x,i=this.y,s=this.z,o=e.elements,r=1/(o[3]*t+o[7]*i+o[11]*s+o[15]);return this.x=(o[0]*t+o[4]*i+o[8]*s+o[12])*r,this.y=(o[1]*t+o[5]*i+o[9]*s+o[13])*r,this.z=(o[2]*t+o[6]*i+o[10]*s+o[14])*r,this}applyQuaternion(e){let t=this.x,i=this.y,s=this.z,o=e.x,r=e.y,a=e.z,l=e.w,c=2*(r*s-a*i),u=2*(a*t-o*s),f=2*(o*i-r*t);return this.x=t+l*c+r*f-a*u,this.y=i+l*u+a*c-o*f,this.z=s+l*f+o*u-r*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){let t=this.x,i=this.y,s=this.z,o=e.elements;return this.x=o[0]*t+o[4]*i+o[8]*s,this.y=o[1]*t+o[5]*i+o[9]*s,this.z=o[2]*t+o[6]*i+o[10]*s,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Wt(this.x,e.x,t.x),this.y=Wt(this.y,e.y,t.y),this.z=Wt(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=Wt(this.x,e,t),this.y=Wt(this.y,e,t),this.z=Wt(this.z,e,t),this}clampLength(e,t){let i=this.length();return this.divideScalar(i||1).multiplyScalar(Wt(i,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){let i=e.x,s=e.y,o=e.z,r=t.x,a=t.y,l=t.z;return this.x=s*l-o*a,this.y=o*r-i*l,this.z=i*a-s*r,this}projectOnVector(e){let t=e.lengthSq();if(t===0)return this.set(0,0,0);let i=e.dot(this)/t;return this.copy(e).multiplyScalar(i)}projectOnPlane(e){return G5.copy(this).projectOnVector(e),this.sub(G5)}reflect(e){return this.sub(G5.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let i=this.dot(e)/t;return Math.acos(Wt(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return t*t+i*i+s*s}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,i){let s=Math.sin(t)*e;return this.x=s*Math.sin(i),this.y=Math.cos(t)*e,this.z=s*Math.cos(i),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,i){return this.x=e*Math.sin(t),this.y=i,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){let t=this.setFromMatrixColumn(e,0).length(),i=this.setFromMatrixColumn(e,1).length(),s=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=i,this.z=s,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){let e=Math.random()*Math.PI*2,t=Math.random()*2-1,i=Math.sqrt(1-t*t);return this.x=i*Math.cos(e),this.y=t,this.z=i*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},G5=new K,fb=new St,Qt=class n{constructor(e,t,i,s,o,r,a,l,c){n.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,i,s,o,r,a,l,c)}set(e,t,i,s,o,r,a,l,c){let u=this.elements;return u[0]=e,u[1]=s,u[2]=a,u[3]=t,u[4]=o,u[5]=l,u[6]=i,u[7]=r,u[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){let t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],this}extractBasis(e,t,i){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(e){let t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let i=e.elements,s=t.elements,o=this.elements,r=i[0],a=i[3],l=i[6],c=i[1],u=i[4],f=i[7],h=i[2],p=i[5],d=i[8],m=s[0],x=s[3],v=s[6],y=s[1],b=s[4],g=s[7],E=s[2],M=s[5],_=s[8];return o[0]=r*m+a*y+l*E,o[3]=r*x+a*b+l*M,o[6]=r*v+a*g+l*_,o[1]=c*m+u*y+f*E,o[4]=c*x+u*b+f*M,o[7]=c*v+u*g+f*_,o[2]=h*m+p*y+d*E,o[5]=h*x+p*b+d*M,o[8]=h*v+p*g+d*_,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){let e=this.elements,t=e[0],i=e[1],s=e[2],o=e[3],r=e[4],a=e[5],l=e[6],c=e[7],u=e[8];return t*r*u-t*a*c-i*o*u+i*a*l+s*o*c-s*r*l}invert(){let e=this.elements,t=e[0],i=e[1],s=e[2],o=e[3],r=e[4],a=e[5],l=e[6],c=e[7],u=e[8],f=u*r-a*c,h=a*l-u*o,p=c*o-r*l,d=t*f+i*h+s*p;if(d===0)return this.set(0,0,0,0,0,0,0,0,0);let m=1/d;return e[0]=f*m,e[1]=(s*c-u*i)*m,e[2]=(a*i-s*r)*m,e[3]=h*m,e[4]=(u*t-s*l)*m,e[5]=(s*o-a*t)*m,e[6]=p*m,e[7]=(i*l-c*t)*m,e[8]=(r*t-i*o)*m,this}transpose(){let e,t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){let t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,i,s,o,r,a){let l=Math.cos(o),c=Math.sin(o);return this.set(i*l,i*c,-i*(l*r+c*a)+r+e,-s*c,s*l,-s*(-c*r+l*a)+a+t,0,0,1),this}scale(e,t){return this.premultiply(q5.makeScale(e,t)),this}rotate(e){return this.premultiply(q5.makeRotation(-e)),this}translate(e,t){return this.premultiply(q5.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){let t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,i,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){let t=this.elements,i=e.elements;for(let s=0;s<9;s++)if(t[s]!==i[s])return!1;return!0}fromArray(e,t=0){for(let i=0;i<9;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){let i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e}clone(){return new this.constructor().fromArray(this.elements)}},q5=new Qt;function kx(n){for(let e=n.length-1;e>=0;--e)if(n[e]>=65535)return!0;return!1}var NT={Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array};function ff(n,e){return new NT[n](e)}function vf(n){return document.createElementNS("http://www.w3.org/1999/xhtml",n)}function Px(){let n=vf("canvas");return n.style.display="block",n}var hb={};function yf(n){n in hb||(hb[n]=!0,console.warn(n))}function Q4(n,e,t){return new Promise(function(i,s){function o(){switch(n.clientWaitSync(e,n.SYNC_FLUSH_COMMANDS_BIT,0)){case n.WAIT_FAILED:s();break;case n.TIMEOUT_EXPIRED:setTimeout(o,t);break;default:i()}}setTimeout(o,t)})}var db=new Qt().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),pb=new Qt().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function UT(){let n={enabled:!0,workingColorSpace:Wr,spaces:{},convert:function(s,o,r){return this.enabled===!1||o===r||!o||!r||(this.spaces[o].transfer===Y0&&(s.r=ya(s.r),s.g=ya(s.g),s.b=ya(s.b)),this.spaces[o].primaries!==this.spaces[r].primaries&&(s.applyMatrix3(this.spaces[o].toXYZ),s.applyMatrix3(this.spaces[r].fromXYZ)),this.spaces[r].transfer===Y0&&(s.r=hf(s.r),s.g=hf(s.g),s.b=hf(s.b))),s},workingToColorSpace:function(s,o){return this.convert(s,this.workingColorSpace,o)},colorSpaceToWorking:function(s,o){return this.convert(s,o,this.workingColorSpace)},getPrimaries:function(s){retur.........完整代码请登录后点击上方下载按钮下载查看















网友评论0