Prompt specification
Build or customize the Three.js 3D scene "Toy Sail Trim Demonstrator" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Toy Sail Trim Demonstrator
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/toy-sail-trim-demonstrator-x3678
Scene Description Prompt:
Create a bounded sailing display using an explicitly qualitative propulsion rule. Change sail angle and show predicted motion without implying a real nautical training simulator. Use Three.js from cdnjs in a single HTML file, with a 3D cutaway.
Working Three.js Starter (toy-sail-trim-demonstrator-x3678):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bounded Sail — Qualitative Motion Display</title>
<style>
:root {
color-scheme: dark;
--bg: #071116;
--panel: #0c1a21;
--panel-2: #10232c;
--line: rgba(161, 211, 222, 0.16);
--text: #e8f4f5;
--muted: #91a9b0;
--cyan: #66e0e7;
--cyan-soft: rgba(102, 224, 231, 0.14);
--amber: #ffb85c;
--red: #ff817d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
display: grid;
grid-template-rows: auto minmax(0, 1fr);
height: 100vh;
min-height: 620px;
}
header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
min-height: 72px;
padding: 14px 22px;
border-bottom: 1px solid var(--line);
background: rgba(7, 17, 22, 0.96);
z-index: 2;
}
.brand {
display: flex;
align-items: center;
gap: 14px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
flex: 0 0 auto;
border: 1px solid rgba(102, 224, 231, 0.55);
border-radius: 50%;
background:
linear-gradient(90deg, transparent 48%, rgba(102, 224, 231, 0.6) 49%, rgba(102, 224, 231, 0.6) 51%, transparent 52%),
linear-gradient(0deg, transparent 48%, rgba(102, 224, 231, 0.28) 49%, rgba(102, 224, 231, 0.28) 51%, transparent 52%);
}
.brand-mark::after {
content: "";
position: absolute;
left: 17px;
top: 5px;
width: 1px;
height: 27px;
background: var(--cyan);
transform: rotate(25deg);
transform-origin: bottom;
}
h1 {
margin: 0;
font-size: clamp(17px, 2vw, 23px);
line-height: 1.1;
letter-spacing: -0.025em;
font-weight: 680;
}
.subtitle {
margin-top: 5px;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.035em;
}
.not-simulator {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid rgba(255, 185, 92, 0.35);
border-radius: 999px;
color: #ffd09b;
background: rgba(255, 185, 92, 0.08);
font-size: 10px;
font-weight: 760;
letter-spacing: 0.13em;
white-space: nowrap;
}
.not-simulator::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 12px rgba(255, 184, 92, 0.8);
}
main {
display: grid;
grid-template-columns: minmax(0, 1fr) 350px;
min-height: 0;
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 35%, #15313c 0%, #091820 48%, #061116 100%);
}
#canvas-host,
#canvas-host canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#canvas-host canvas {
cursor: grab;
touch-action: none;
}
#canvas-host canvas:active {
cursor: grabbing;
}
.overlay {
position: absolute;
z-index: 1;
pointer-events: none;
}
.scene-top {
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.scene-chip {
display: inline-flex;
align-items: center;
gap: 9px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 8px;
color: #bcd2d7;
background: rgba(7, 17, 22, 0.72);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 680;
letter-spacing: 0.095em;
text-transform: uppercase;
}
.scene-chip .dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px rgba(102, 224, 231, 0.7);
}
.camera-tools {
display: flex;
gap: 7px;
pointer-events: auto;
}
.small-button {
border: 1px solid var(--line);
border-radius: 8px;
padding: 8px 10px;
color: #bcd2d7;
background: rgba(7, 17, 22, 0.75);
backdrop-filter: blur(10px);
cursor: pointer;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.04em;
}
.small-button:hover {
color: white;
border-color: rgba(102, 224, 231, 0.45);
background: rgba(102, 224, 231, 0.1);
}
.scene-bottom {
left: 18px;
right: 18px;
bottom: 18px;
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 8px;
}
.metric {
min-width: 0;
padding: 11px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(7, 17, 22, 0.78);
backdrop-filter: blur(12px);
}
.metric-label {
display: block;
margin-bottom: 4px;
overflow: hidden;
color: var(--muted);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.1em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.metric-value {
display: block;
overflow: hidden;
color: #edf8f9;
font-size: 16px;
font-variant-numeric: tabular-nums;
font-weight: 690;
text-overflow: ellipsis;
white-space: nowrap;
}
.metric-value.cyan {
color: var(--cyan);
}
.metric-value.amber {
color: var(--amber);
}
.cutaway-note {
left: 18px;
bottom: 106px;
display: flex;
align-items: center;
gap: 8px;
color: rgba(201, 222, 226, 0.75);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.cutaway-note::before {
content: "";
width: 24px;
height: 1px;
background: var(--cyan);
opacity: 0.65;
}
aside {
min-height: 0;
overflow: auto;
border-left: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(255, 255, 255, 0.018), transparent 25%),
var(--panel);
scrollbar-color: rgba(102, 224, 231, 0.25) transparent;
scrollbar-width: thin;
}
.panel-section {
padding: 20px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 9px;
font-weight: 760;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h2 {
margin: 0 0 8px;
font-size: 17px;
letter-spacing: -0.015em;
}
p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.angle-head {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin: 18px 0 12px;
}
.angle-number {
color: var(--cyan);
font-size: 34px;
font-weight: 720;
letter-spacing: -0.055em;
line-height: 0.95;
font-variant-numeric: tabular-nums;
}
.angle-number span {
color: var(--muted);
font-size: 16px;
letter-spacing: 0;
}
.angle-side {
padding-bottom: 2px;
color: #c5d7da;
font-size: 11px;
font-weight: 650;
}
input[type="range"] {
width: 100%;
height: 22px;
margin: 0;
appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 5px;
border-radius: 999px;
background:
linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) var(--pct, 50%),
rgba(160, 204, 211, 0.16) var(--pct, 50%),
rgba(160, 204, 211, 0.16) 100%
);
}
input[type="range"]::-moz-range-track {
height: 5px;
border-radius: 999px;
background: rgba(160, 204, 211, 0.16);
}
input[type="range"]::-moz-range-progress {
height: 5px;
border-radius: 999px;
background: var(--cyan);
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
margin-top: -6.5px;
appearance: none;
border: 3px solid var(--panel);
border-radius: 50%;
background: #d8fbff;
box-shadow: 0 0 0 1px var(--cyan), 0 0 14px rgba(102, 224, 231, 0.3);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid var(--panel);
border-radius: 50%;
background: #d8fbff;
box-shadow: 0 0 0 1px var(--cyan);
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 3px;
color: #718a91;
font-size: 9px;
letter-spacing: 0.04em;
}
.push-meter {
margin-top: 17px;
}
.meter-head {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
}
.meter-head strong {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
.meter-track {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: rgba(160, 204, 211, 0.12);
}
.meter-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #3caab7, var(--cyan));
transition: width 120ms ease;
}
.presets {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
margin-top: 16px;
}
.preset {
padding: 8px 4px;
border: 1px solid var(--line);
border-radius: 7px;
color: #9eb5bb;
background: rgba(255, 255, 255, 0.018);
cursor: pointer;
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.preset:hover,
.preset.active {
color: #dffbff;
border-color: rgba(102, 224, 231, 0.48);
background: var(--cyan-soft);
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 18px;
}
.primary-button,
.secondary-button {
min-height: 40px;
border-radius: 8px;
cursor: pointer;
font-size: 11px;
font-weight: 720;
letter-spacing: 0.045em;
}
.primary-button {
border: 1px solid var(--cyan);
color: #052027;
background: var(--cyan);
}
.primary-button:hover {
background: #91edf1;
}
.secondary-button {
padding: 0 13px;
border: 1px solid var(--line);
color: #aec3c8;
background: transparent;
}
.secondary-button:hover {
color: white;
border-color: rgba(102, 224, 231, 0.4);
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 13px;
color: #a9bec3;
font-size: 11px;
}
.toggle-row input {
width: 16px;
height: 16px;
accent-color: var(--cyan);
cursor: pointer;
}
.formula {
margin: 13px 0;
padding: 12px;
border: 1px solid rgba(102, 224, 231, 0.18);
border-radius: 8px;
color: #d7edf0;
background: rgba(102, 224, 231, 0.055);
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 10px;
line-height: 1.7;
}
.formula .muted {
color: #78949b;
}
.rule-note {
padding-left: 10px;
border-left: 2px solid var(--amber);
color: #a9bdc2;
}
.warning {
border-left-color: var(--red);
}
.warning strong {
color: #ffaaa7;
}
.legend {
display: grid;
gap: 9px;
margin-top: 13px;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: #9db3b9;
font-size: 10px;
}
.swatch {
width: 24px;
height: 3px;
border-radius: 999px;
background: var(--cyan);
}
.swatch.amber {
background: var(--amber);
}
.swatch.wind {
position: relative;
width: 24px;
height: 1px;
background: var(--amber);
}
.swatch.wind::after {
content: "";
position: absolute;
right: 0;
top: -3px;
border-left: 5px solid var(--amber);
border-top: 3px solid transparent;
border-bottom: 3px solid transparent;
}
.small-print {
margin-top: 14px;
color: #718990;
font-size: 9px;
line-height: 1.55;
}
@media (max-width: 900px) {
body {
overflow: auto;
}
#app {
height: auto;
min-height: 100vh;
}
main {
grid-template-columns: 1fr;
}
.viewport {
height: 62vh;
min-height: 480px;
}
aside {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
.panel-section {
padding: 18px;
}
.not-simulator {
font-size: 8px;
}
}
@media (max-width: 560px) {
header {
padding: 12px 14px;
}
.subtitle {
display: none;
}
.not-simulator {
padding: 7px 8px;
letter-spacing: 0.08em;
}
.scene-bottom {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.cutaway-note {
display: none;
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Bounded Sail</h1>
<div class="subtitle">Qualitative trim-to-motion display</div>
</div>
</div>
<div class="not-simulator">Concept model · not a simulator</div>
</header>
<main>
<section class="viewport" id="viewport" aria-label="Interactive 3D sailing display">
<div id="canvas-host"></div>
<div class="overlay scene-top">
<div class="scene-chip">
<span class="dot"></span>
Bounded field · 18 × 12 model units
</div>
<div class="camera-tools">
<button class="small-button camera-hint" id="camera-reset" type="button">
Reset camera
</button>
</div>
</div>
<div class="overlay cutaway-note">
Cutaway view · near hull side removed
</div>
<div class="overlay scene-bottom">
<div class="metric">
<span class="metric-label">Predicted path</span>
<span class="metric-value cyan" id="metric-distance">—</span>
</div>
<div class="metric">
<span class="metric-label">Qualitative push</span>
<span class="metric-value" id="metric-push">—</span>
</div>
<div class="metric">
<span class="metric-label">Look-ahead</span>
<span class="metric-value">12.0 s</span>
</div>
<div class="metric">
<span class="metric-label">Boundary</span>
<span class="metric-value amber" id="metric-boundary">—</span>
</div>
</div>
</section>
<aside>
<section class="panel-section">
<div class="eyebrow">Sail control</div>
<h2>Change the trim offset</h2>
<p>
The sail rotates around the mast. The cyan path is generated by the
same invented rule used for the run preview.
</p>
<div class="angle-head">
<div class="angle-number" id="angle-value">
38<span>°</span>
</div>
<div class="angle-side" id="angle-side">right-side trim</div>
</div>
<label for="trim-slider" class="metric-label">Offset from centerline</label>
<input
id="trim-slider"
type="range"
min="-70"
max="70"
step="1"
value="38"
aria-label="Sail trim angle"
/>
<div class="range-labels">
<span>−70° left</span>
<span>0° center</span>
<span>right +70°</span>
</div>
<div class="push-meter">
<div class="meter-head">
<span>Rule output</span>
<strong id="push-label">69%</strong>
</div>
<div class="meter-track">
<div class="meter-fill" id="push-fill"></div>
</div>
</div>
<div class="presets" aria-label="Trim presets">
<button class="preset" type="button" data-angle="-45">−45°</button>
<button class="preset" type="button" data-angle="0">0°</button>
<button class="preset active" type="button" data-angle="38">38°</button>
<button class="preset" type="button" data-angle="70">70°</button>
</div>
<div class="actions">
<button class="primary-button" id="play-button" type="button">
Run preview
</button>
<button class="secondary-button" id="reset-button" type="button">
Reset
</button>
</div>
<label class="toggle-row" for="show-prediction">
<span>Show predicted path</span>
<input id="show-prediction" type="checkbox" checked />
</label>
</section>
<section class="panel-section">
<div class="eyebrow">Explicit model rule</div>
<h2>Invented, qualitative propulsion</h2>
<div class="formula">
<div>P(a) = sin[π/2 · clamp((|a| − 8°)/62°, 0, 1)]</div>
<div>vₙ₊₁ = vₙ + [0.42P(a) − 0.30vₙ]Δt</div>
<div>ψₙ₊₁ = ψₙ − 0.045aΔt</div>
<div class="muted">a in radians for the turn term; all units are arbitrary.</div>
</div>
<p class="rule-note">
Push appears only beyond 8° of trim and increases toward 70°.
The side of trim changes the qualitative turn direction. This rule
is intentionally not a sail, wind, or vessel-performance model.
</p>
</section>
<section class="panel-section">
<div class="eyebrow">Display key</div>
<h2>What is being shown</h2>
<div class="legend">
<div class="legend-item">
<span class="swatch"></span>
Dashed cyan line: predicted motion
</div>
<div class="legend-item">
<span class="swatch amber"></span>
Amber line: motion during playback
</div>
<div class="legend-item">
<span class="swatch wind"></span>
Amber arrow: fixed visual wind cue
</div>
</div>
<p class="small-print">
Drag to orbit, scroll to zoom, and double-click the scene to reset
the camera. The prediction is truncated when the vessel display
boundary is reached.
</p>
</section>
<section class="panel-section">
<div class="eyebrow">Important limitation</div>
<p class="rule-note warning">
<strong>For qualitative exploration only.</strong>
This display is not navigation, safety, vessel-performance, weather,
or nautical training software. It must not be used to make real-world
sailing decisions.
</p>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------
const host = document.getElementById("canvas-host");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071116);
scene.fog = new THREE.FogExp2(0x071116, 0.026);
const camera = new THREE.PerspectiveCamera(
43,
host.clientWidth / host.clientHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(host.clientWidth, host.clientHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
host.appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xc5efff, 0x142329, 2.15));
const keyLight = new THREE.DirectionalLight(0xfff2d6, 3.1);
keyLight.position.set(5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x68dce8, 1.65);
rimLight.position.set(-7, 5, -8);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb85c, 18, 14, 2);
warmLight.position.set(-5, 3.5, -3);
scene.add(warmLight);
// ------------------------------------------------------------
// Bounded display basin
// ------------------------------------------------------------
const basin = new THREE.Group();
scene.add(basin);
const basinWidth = 18;
const basinDepth = 12;
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x071820,
roughness: 0.88,
metalness: 0.08
});
const basinBase = new THREE.Mesh(
new THREE.BoxGeometry(basinWidth, 0.36, basinDepth),
baseMaterial
);
basinBase.position.y = -0.76;
basinBase.receiveShadow = true;
basin.add(basinBase);
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x1d8190,
transparent: true,
opacity: 0.16,
roughness: 0.3,
metalness: 0.05,
transmission: 0.12,
depthWrite: false
});
const waterVolume = new THREE.Mesh(
new THREE.BoxGeometry(basinWidth, 0.58, basinDepth),
waterMaterial
);
waterVolume.position.y = -0.29;
basin.add(waterVolume);
const surfaceMaterial = new THREE.MeshPhysicalMaterial({
color: 0x3bb2bd,
transparent: true,
opacity: 0.12,
roughness: 0.28,
metalness: 0.02,
depthWrite: false,
side: THREE.DoubleSide
});
const surface = new THREE.Mesh(
new THREE.PlaneGeometry(basinWidth, basinDepth),
surfaceMaterial
);
surface.rotation.x = -Math.PI / 2;
surface.position.y = 0.018;
surface.receiveShadow = true;
basin.add(surface);
const gridVertices = [];
for (let x = -9; x <= 9; x += 1) {
gridVertices.push(x, 0.035, -6, x, 0.035, 6);
}
for (let z = -6; z <= 6; z += 1) {
gridVertices.push(-9, 0.035, z, 9, 0.035, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridVertices, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x83dce2,
transparent: true,
opacity: 0.12
})
);
basin.add(grid);
const basinEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(basinWidth, 0.6, basinDepth)
),
new THREE.LineBasicMaterial({
color: 0x70dbe3,
transparent: true,
opacity: 0.56
})
);
basinEdges.position.y = -0.3;
basin.add(basinEdges);
const cornerGeometry = new THREE.BoxGeometry(0.45, 0.08, 0.08);
const cornerMaterial = new THREE.MeshStandardMaterial({
color: 0xffb85c,
emissive: 0x4a2608,
emissiveIntensity: 0.6
});
for (const x of [-8.7, 8.7]) {
for (const z of [-5.7, 5.7]) {
const marker = new THREE.Mesh(cornerGeometry, cornerMaterial);
marker.position.set(x, 0.06, z);
basin.add(marker);
}
}
// Fixed wind cue, deliberately not used as a physical input.
const windDirection = new THREE.Vector3(0.82, 0, -0.52).normalize();
const windArrow = new THREE.ArrowHelper(
windDirection,
new THREE.Vector3(-7.3, 2.7, -4.2),
3.1,
0xffb85c,
0.48,
0.24
);
windArrow.line.material.transparent = true;
windArrow.line.material.opacity = 0.75;
windArrow.cone.material.transparent = true;
windArrow.cone.material.opacity = 0.9;
scene.add(windArrow);
// ------------------------------------------------------------
// Cutaway boat construction
// ------------------------------------------------------------
const boat = new THREE.Group();
boat.rotation.order = "YXZ";
boat.scale.setScalar(1.08);
scene.add(boat);
const hullMaterial = new THREE.MeshStandardMaterial({
color: 0xdde7e5,
roughness: 0.5,
metalness: 0.08,
side: THREE.DoubleSide
});
const interiorMaterial = new THREE.MeshStandardMaterial({
color: 0x7c9ba0,
roughness: 0.78,
metalness: 0.02
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0x28aeb9,
roughness: 0.35,
metalness: 0.18
});
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0xa66c3f,
roughness: 0.82,
metalness: 0.01
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x173038,
roughness: 0.75,
metalness: 0.08
});
// A half hull is intentionally used: the near side is removed so the
// interior structure can be seen.
const sections = [
{ x: -1.7, w: 1.02 },
{ x: -1.3, w: 1.2 },
{ x: -0.7, w: 1.18 },
{ x: 0.15, w: 1.02 },
{ x: 0.9, w: 0.72 },
{ x: 1.48, w: 0.36 },
{ x: 1.88, w: 0.035 }
];
const hullPositions = [];
const hullIndices = [];
for (const section of sections) {
hullPositions.push(
section.x, -0.43, 0,
section.x, 0.34, -section.w
);
}
for (let i = 0; i < sections.length - 1; i++) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
hullIndices.push(a, c, b, b, c, d);
}
const hullGeometry = new THREE.BufferGeometry();
hullGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(hullPositions, 3)
);
hullGeometry.setIndex(hullIndices);
hullGeometry.computeVertexNormals();
const hull = new THREE.Mesh(hullGeometry, hullMaterial);
hull.castShadow = true;
hull.receiveShadow = true;
boat.add(hull);
// Stern transom closes the cutaway half.
const sternGeometry = new THREE.BufferGeometry();
sternGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[-1.7, -0.43, 0, -1.7, 0.34, -1.02, -1.7, 0.34, 0],
3
)
);
sternGeometry.setIndex([0, 1, 2]);
sternGeometry.computeVertexNormals();
const stern = new THREE.Mesh(sternGeometry, hullMaterial);
stern.castShadow = true;
boat.add(stern);
const railPoints = sections.map(
(section) => new THREE.Vector3(section.x, 0.34, -section.w)
);
const railCurve = new THREE.CatmullRomCurve3(railPoints);
const rail = new THREE.Mesh(
new THREE.TubeGeometry(railCurve, 70, 0.045, 8, false),
trimMaterial
);
rail.castShadow = true;
boat.add(rail);
const keelCurve = new THREE.CatmullRomCurve3(
sections.map((section) => new THREE.Vector3(section.x, -0.43, 0))
);
const keel = new THREE.Mesh(
new THREE.TubeGeometry(keelCurve, 60, 0.035, 7, false),
darkMaterial
);
boat.add(keel);
// Visible ribs and center cut line.
for (let i = 1; i < sections.length - 1; i++) {
const section = sections[i];
const ribGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(section.x, -0.43, 0),
new THREE.Vector3(section.x, 0.34, -section.w)
]);
boat.add(
new THREE.Line(
ribGeometry,
new THREE.LineBasicMaterial({
color: 0x54747a,
transparent: true,
opacity: 0.86
})
)
);
}
const cutLineGeometry = new THREE.BufferGeometry().setFromPoints(
sections.map((section) => new THREE.Vector3(section.x, 0.35, 0))
);
const cutLine = new THREE.Line(
cutLineGeometry,
new THREE.LineDashedMaterial({
color: 0xffb85c,
dashSize: 0.12,
gapSize: 0.08,
transparent: true,
opacity: 0.8
})
);
cutLine.computeLineDistances();
boat.add(cutLine);
// Interior floor, benches, and cockpit.
const interiorFloor = new THREE.Mesh(
new THREE.BoxGeometry(2.55, 0.08, 0.38),
interiorMaterial
);
interiorFloor.position.set(-0.05, -0.24, -0.2);
interiorFloor.castShadow = true;
boat.add(interiorFloor);
for (const x of [-1.0, 0.25]) {
const bench = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.12, 0.86),
woodMaterial
);
bench.position.set(x, 0.17, -0.52);
bench.castShadow = true;
boat.add(bench);
}
const cockpit = new THREE.Mesh(
new THREE.BoxGeometry(0.75, 0.11, 0.67),
darkMaterial
);
cockpit.position.set(-0.7, 0.04, -0.54);
boat.add(cockpit);
// Mast and rigging.
const mast = new THREE.Mesh(
new THREE.CylinderGeometry(0.043, 0.057, 4.15, 12),
trimMaterial
);
mast.position.set(-0.25, 2.38, 0);
mast.castShadow = true;
boat.add(mast);
const riggingMaterial = new THREE.LineBasicMaterial({
color: 0xb9d5d9,
transparent: true,
opacity: 0.6
});
const riggingPoints = [
new THREE.Vector3(-0.25, 4.42, 0),
new THREE.Vector3(1.82, 0.35, 0),
new THREE.Vector3(-0.25, 4.42, 0),
new THREE.Vector3(-1.65, 0.35, 0)
];
boat.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(riggingPoints),
riggingMaterial
)
);
// Sail pivot. The sail triangle lies in the local X/Y plane and rotates
// around the mast by the requested trim offset.
const sailPivot = new THREE.Group();
sailPivot.position.set(-0.25, 0.5, 0);
boat.add(sailPivot);
const sailGeometry = new THREE.BufferGeometry();
sailGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0, 0, 0,
-1.92, 0.47, 0,
0, 3.78, 0
],
3
)
);
sailGeometry.setIndex([0, 1, 2]);
sailGeometry.computeVertexNormals();
const sailMaterial = new THREE.MeshStandardMaterial({
color: 0xfff2d9,
emissive: 0x2c2113,
emissiveIntensity: 0.16,
roughness: 0.88,
metalness: 0,
side: THREE.DoubleSide
});
const sail = new THREE.Mesh(sailGeometry, sailMaterial);
sail.castShadow = true;
sailPivot.add(sail);
const sailSeam = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, 0.012),
new THREE.Vector3(-1.92, 0.47, 0.012),
new THREE.Vector3(0, 3.78, 0.012),
new THREE.Vector3(0, 0, 0.012)
]),
new THREE.LineBasicMaterial({
color: 0xb8976d,
transparent: true,
opacity: 0.62
})
);
sailPivot.add(sailSeam);
const boom = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 1.92, 10),
trimMaterial
);
boom.rotation.z = Math.PI / 2;
boom.position.set(-0.96, 0.47, 0);
boom.castShadow = true;
sailPivot.add(boom);
// A visible trim range around the mast.
const trimArcPoints = [];
for (let i = 0; i <= 70; i++) {
const a = THREE.MathUtils.degToRad(-70 + (140 * i) / 70);
trimArcPoints.push(
new THREE.Vector3(
-0.25 - 0.76 * Math.cos(a),
0.515,
0.76 * Math.sin(a)
)
);
}
const trimArc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(trimArcPoints),
new THREE.LineBasicMaterial({
color: 0x66e0e7,
transparent: true,
opacity: 0.22
})
);
boat.add(trimArc);
// ------------------------------------------------------------
// Prediction and playback markers
// ------------------------------------------------------------
const predictionGroup = new THREE.Group();
scene.add(predictionGroup);
let predictedLine = null;
const endpointMaterial = new THREE.MeshBasicMaterial({
color: 0x66e0e7,
transparent: true,
opacity: 0.95
});
const endpointMarker = new THREE.Mesh(
new THREE.TorusGeometry(0.25, 0.035, 8, 32),
endpointMaterial
);
endpointMarker.rotation.x = Math.PI / 2;
predictionGroup.add(endpointMarker);
const collisionMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 16, 12),
new THREE.MeshBasicMaterial({ color: 0xffb85c })
);
collisionMarker.visible = false;
predictionGroup.add(collisionMarker);
const startMarker = new THREE.Mesh(
new THREE.RingGeometry(0.2, 0.25, 32),
new THREE.MeshBasicMaterial({
color: 0x66e0e7,
transparent: true,
opacity: 0.55,
side: THREE.DoubleSide
})
);
startMarker.rotation.x = -Math.PI / 2;
predictionGroup.add(startMarker);
const trailMaterial = new THREE.LineBasicMaterial({
color: 0xffb85c,
transparent: true,
opacity: 0.9
});
let trailLine = null;
// ------------------------------------------------------------
// Explicit qualitative model
// ------------------------------------------------------------
const INITIAL_STATE = {
x: -6.25,
z: 1.0,
heading: -0.08,
speed: 0
};
const BOUNDS = {
x: 7.2,
z: 4.8
};
const FIXED_STEP = 0.05;
const PREDICTION_STEPS = 240; // 12 seconds
const MAX_ANGLE = 70;
const DEAD_ZONE = 8;
let trimAngle = 38;
let running = false;
let accumulator = 0;
let elapsed = 0;
const state = { ...INITIAL_STATE };
let trailPoints = [new THREE.Vector3(state.x, 0.13, state.z)];
function qualitativePush(angleDegrees) {
const normalized = THREE.MathUtils.clamp(
(Math.abs(angleDegrees) - DEAD_ZONE) / (MAX_ANGLE - DEAD_ZONE),
0,
1
);
return Math.sin((Math.PI / 2) * normalized);
}
function stepModel(model, angleDegrees, dt) {
const previousX = model.x;
const previousZ = model.z;
const push = qualitativePush(angleDegrees);
const angleRadians = THREE.MathUtils.degToRad(angleDegrees);
model.speed +=
(0.42 * push - 0.30 * model.speed) * dt;
model.heading -= 0.045 * angleRadians * dt;
model.x += Math.cos(model.heading) * model.speed * dt;
model.z -= Math.sin(model.heading) * model.speed * dt;
const outsideX = Math.abs(model.x) > BOUNDS.x;
const outsideZ = Math.abs(model.z) > BOUNDS.z;
if (outsideX || outsideZ) {
const xRatio = outsideX
? (Math.sign(model.x) * BOUNDS.x - previousX) /
(model.x - previousX)
: 2;
const zRatio = outsideZ
? (Math.sign(model.z) * BOUNDS.z - previousZ) /
(model.z - previousZ)
: 2;
const ratio = THREE.MathUtils.clamp(
Math.min(xRatio, zRatio),
0,
1
);
model.x = THREE.MathUtils.lerp(previousX, model.x, ratio);
model.z = THREE.MathUtils.lerp(previousZ, model.z, ratio);
model.speed *= 0.35;
return true;
}
return false;
}
function updateTrail() {
const geometry = new THREE.BufferGeometry().setFromPoints(trailPoints);
if (trailLine) {
boat.parent.remove(trailLine);
trailLine.geometry.dispose();
}
trailLine = new THREE.Line(geometry, trailMaterial);
scene.add(trailLine);
}
function predict() {
const predictionState = { ...INITIAL_STATE };
const points = [
new THREE.Vector3(predictionState.x, 0.13, predictionState.z)
];
let distance = 0;
let hitBoundary = false;
for (let i = 0; i < PREDICTION_STEPS; i++) {
const before = {
x: predictionState.x,
z: predictionState.z
};
const hit = stepModel(predictionState, trimAngle, FIXED_STEP);
const after = {
x: predictionState.x,
z: predictionState.z
};
distance += Math.hypot(after.x - before.x, after.z - before.z);
points.push(new THREE.Vector3(after.x, 0.13, after.z));
if (hit) {
hitBoundary = true;
break;
}
}
if (predictedLine) {
predictionGroup.remove(predictedLine);
predictedLine.geometry.dispose();
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
predictedLine = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color: 0x66e0e7,
dashSize: 0.2,
gapSize: 0.12,
transparent: true,
opacity: 0.95
})
);
predictedLine.computeLineDistances();
predictionGroup.add(predictedLine);
const endpoint = points[points.length - 1];
endpointMarker.position.copy(endpoint);
collisionMarker.position.copy(endpoint);
collisionMarker.visible = hitBoundary;
startMarker.position.set(INITIAL_STATE.x, 0.13, INITIAL_STATE.z);
document.getElementById("metric-distance").textContent =
`${distance.toFixed(1)} u`;
document.getElementById("metric-boundary").textContent =
hitBoundary ? "Edge reached" : "Inside boundary";
return { distance, hitBoundary };
}
function resetMotion() {
running = false;
accumulator = 0;
elapsed = 0;
Object.assign(state, INITIAL_STATE);
trailPoints = [new THREE.Vector3(state.x, 0.13, state.z)];
updateTrail();
boat.position.set(state.x, 0, state.z);
boat.rotation.set(0, state.heading, 0);
document.getElementById("play-button").textContent = "Run preview";
predict();
}
function togglePlayback() {
if (!running) {
if (elapsed >= PREDICTION_STEPS * FIXED_STEP) {
resetMotion();
}
running = true;
document.getElementById("play-button").textContent = "Pause";
} else {
running = false;
document.getElementById("play-button").textContent = "Resume";
}
}
// ------------------------------------------------------------
// UI
// ------------------------------------------------------------
const slider = document.getElementById("trim-slider");
const angleValue = document.getElementById("angle-value");
const angleSide = document.getElementById("angle-side");
const pushLabel = document.getElementById("push-label");
const pushFill = document.getElementById("push-fill");
const metricPush = document.getElementById("metric-push");
const presetButtons = [...document.querySelectorAll(".preset")];
function updateSliderAppearance() {
const percent =
((Number(slider.value) - Number(slider.min)) /
(Number(slider.max) - Number(slider.min))) *
100;
slider.style.setProperty("--pct", `${percent}%`);
}
function setTrim(angle, reset = true) {
trimAngle = THREE.MathUtils.clamp(Number(angle), -70, 70);
slider.value = String(trimAngle);
updateSliderAppearance();
angleValue.innerHTML = `${trimAngle}<span>°</span>`;
if (trimAngle > 1) {
angleSide.textContent = "right-side trim";
} else if (trimAngle < -1) {
angleSide.textContent = "left-side trim";
} else {
angleSide.textContent = "centered · no push";
}
const push = qualitativePush(trimAngle);
const pushPercent = Math.round(push * 100);
pushLabel.textContent = `${pushPercent}%`;
pushFill.style.width = `${pushPercent}%`;
metricPush.textContent = `${pushPercent}%`;
for (const button of presetButtons) {
button.classList.toggle(
"active",
Number(button.dataset.angle) === trimAngle
);
}
if (reset) {
resetMotion();
} else {
predict();
}
}
slider.addEventListener("input", () => {
setTrim(slider.value, true);
});
for (const button of presetButtons) {
button.addEventListener("click", () => {
setTrim(button.dataset.angle, true);
});
}
document.getElementById("play-button").addEventListener("click", togglePlayback);
document.getElementById("reset-button").addEventListener("click", resetMotion);
document.getElementById("show-prediction").addEventListener("change", (event) => {
predictionGroup.visible = event.target.checked;
});
// ------------------------------------------------------------
// Direct camera controls — no addons
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.15, 0);
let cameraTheta = 0.73;
let cameraPhi = 0.91;
let cameraRadius = 17.8;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
function updateCamera() {
camera.position.set(
cameraTarget.x + cameraRadius * Math.sin(cameraPhi) * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * Math.sin(cameraPhi) * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraTheta = 0.73;
cameraPhi = 0.91;
cameraRadius = 17.8;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - dy * 0.0045,
0.34,
1.36
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
9,
27
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("camera-reset").addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
const resizeObserver = new ResizeObserver(() => {
const width = host.clientWidth;
const height = host.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
});
resizeObserver.observe(host);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const frameDelta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (running) {
accumulator += frameDelta;
while (accumulator >= FIXED_STEP && running) {
const hit = stepModel(state, trimAngle, FIXED_STEP);
elapsed += FIXED_STEP;
trailPoints.push(new THREE.Vector3(state.x, 0.13, state.z));
updateTrail();
if (hit || elapsed >= PREDICTION_STEPS * FIXED_STEP) {
running = false;
document.getElementById("play-button").textContent = "Run again";
}
accumulator -= FIXED_STEP;
}
}
boat.position.set(state.x, 0, state.z);
const push = qualitativePush(trimAngle);
const motionAmount = THREE.MathUtils.clamp(Math.abs(state.speed), 0, 1.5);
boat.rotation.set(
Math.sin(time * 1.8) * 0.018 * motionAmount,
state.heading,
Math.sin(time * 1.25 + 0.7) * 0.025 * motionAmount
);
// The sail's baseline points aft. The trim value rotates around it.
sailPivot.rotation.y = Math.PI + THREE.MathUtils.degToRad(trimAngle);
windArrow.position.y = 2.7 + Math.sin(time * 0.8) * 0.04;
endpointMarker.rotation.z = time * 0.4;
startMarker.rotation.z = -time * 0.22;
renderer.render(scene, camera);
}
setTrim(38, false);
resetMotion();
updateCamera();
animate();
</script>
</body>
</html>
```