Prompt specification
Build or customize the Three.js 3D scene "Sailboat With Wind and Heading Arrows" 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: Sailboat With Wind and Heading Arrows
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sailboat-with-wind-and-heading-arrows-x3677
Scene Description Prompt:
Sailboat with wind and heading arrows. Model a simple sailboat with distinct wind, heading, and sail-angle indicators. Keep the mast, boom, and sail orientation visible from above. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (sailboat-with-wind-and-heading-arrows-x3677):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Low-Poly Sailboat Indicator</title>
<style>
:root {
--wind: #13b9d5;
--heading: #ff8a3d;
--sail: #e85d9e;
--ink: #102832;
--panel: rgba(245, 251, 252, 0.92);
--line: rgba(16, 40, 50, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b8d6dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.panel {
position: absolute;
pointer-events: auto;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 16px 40px rgba(14, 42, 51, 0.16),
inset 0 1px 0 rgba(255, 255, 255, 0.75);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#title {
top: 18px;
left: 18px;
padding: 15px 18px 14px;
}
#title h1 {
margin: 0;
font-size: clamp(17px, 2vw, 23px);
line-height: 1.05;
letter-spacing: -0.035em;
}
#title p {
margin: 6px 0 0;
max-width: 330px;
color: rgba(16, 40, 50, 0.65);
font-size: 12px;
line-height: 1.45;
}
#controls {
left: 18px;
bottom: 18px;
width: min(330px, calc(100vw - 36px));
padding: 16px;
}
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
}
.control-heading strong {
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.control-heading span {
color: rgba(16, 40, 50, 0.52);
font-size: 11px;
}
.control {
margin: 0 0 13px;
}
.control label {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 5px;
font-size: 12px;
font-weight: 650;
}
output {
min-width: 55px;
color: rgba(16, 40, 50, 0.68);
text-align: right;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0;
accent-color: var(--ink);
cursor: pointer;
}
#heading { accent-color: var(--heading); }
#sail { accent-color: var(--sail); }
#windAngle { accent-color: var(--wind); }
#windSpeed { accent-color: var(--wind); }
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
button {
min-height: 34px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease;
}
button:hover {
background: white;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#legend {
top: 18px;
right: 18px;
width: 220px;
padding: 15px;
}
#legend h2 {
margin: 0 0 12px;
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-item {
display: grid;
grid-template-columns: 13px 1fr;
gap: 9px;
align-items: start;
margin-top: 10px;
font-size: 12px;
}
.legend-item strong {
display: block;
font-size: 12px;
}
.legend-item small {
display: block;
margin-top: 2px;
color: rgba(16, 40, 50, 0.58);
font-size: 10px;
line-height: 1.35;
}
.swatch {
width: 11px;
height: 11px;
margin-top: 2px;
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.72);
}
.wind { background: var(--wind); }
.heading { background: var(--heading); }
.sail { background: var(--sail); }
#hint {
position: absolute;
right: 18px;
bottom: 18px;
padding: 9px 12px;
border-radius: 999px;
background: rgba(16, 40, 50, 0.72);
color: white;
font-size: 11px;
letter-spacing: 0.015em;
box-shadow: 0 8px 24px rgba(14, 42, 51, 0.14);
}
@media (max-width: 680px) {
#title {
max-width: calc(100vw - 36px);
}
#title p {
display: none;
}
#legend {
top: 84px;
right: 12px;
width: 180px;
padding: 12px;
}
.legend-item {
margin-top: 7px;
}
.legend-item small {
display: none;
}
#controls {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 13px;
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<div id="hud">
<section id="title" class="panel">
<h1>Low-Poly Sail Trim</h1>
<p>
A top-readable sailing diagram with separate wind-flow, heading,
and sail-angle indicators.
</p>
</section>
<section id="legend" class="panel">
<h2>Indicators</h2>
<div class="legend-item">
<span class="swatch wind"></span>
<div>
<strong>Wind flow</strong>
<small>Direction the air is traveling.</small>
</div>
</div>
<div class="legend-item">
<span class="swatch heading"></span>
<div>
<strong>Boat heading</strong>
<small>Direction the bow is pointing.</small>
</div>
</div>
<div class="legend-item">
<span class="swatch sail"></span>
<div>
<strong>Sail angle</strong>
<small>Boom offset from the centerline.</small>
</div>
</div>
</section>
<section id="controls" class="panel">
<div class="control-heading">
<strong>Navigation</strong>
<span>Flow vs. heading: <b id="relativeValue">-145°</b></span>
</div>
<div class="control">
<label for="heading">
<span>Boat heading</span>
<output id="headingValue">035°</output>
</label>
<input id="heading" type="range" min="0" max="360" value="35" />
</div>
<div class="control">
<label for="sail">
<span>Sail trim</span>
<output id="sailValue">+28°</output>
</label>
<input id="sail" type="range" min="-70" max="70" value="28" />
</div>
<div class="control">
<label for="windAngle">
<span>Wind-flow bearing</span>
<output id="windAngleValue">250°</output>
</label>
<input id="windAngle" type="range" min="0" max="360" value="250" />
</div>
<div class="control">
<label for="windSpeed">
<span>Wind speed</span>
<output id="windSpeedValue">12 kn</output>
</label>
<input id="windSpeed" type="range" min="4" max="24" value="12" />
</div>
<div class="button-row">
<button id="topView" type="button">Top view</button>
<button id="reset" type="button">Reset all</button>
</div>
</section>
<div id="hint">Drag to orbit · Wheel to zoom · Double-click to reset</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb8d6dc);
scene.fog = new THREE.Fog(0xb8d6dc, 24, 62);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const clock = new THREE.Clock();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xeaf9ff, 0x46616a, 2.1));
const sun = new THREE.DirectionalLight(0xfff3dd, 3.1);
sun.position.set(7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8ee9ff, 0.75);
fill.position.set(-8, 6, -5);
scene.add(fill);
// -------------------------------------------------------------------------
// Water and compass
// -------------------------------------------------------------------------
const water = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
new THREE.MeshStandardMaterial({
color: 0x68aeba,
roughness: 0.92,
metalness: 0.02
})
);
water.rotation.x = -Math.PI / 2;
water.position.y = -0.24;
water.receiveShadow = true;
scene.add(water);
const grid = new THREE.GridHelper(70, 35, 0x397b88, 0x5c9ca7);
grid.position.y = -0.225;
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
const compassPoints = [];
const compassRadius = 6.0;
for (let i = 0; i < 96; i++) {
const a = (i / 96) * Math.PI * 2;
compassPoints.push(
new THREE.Vector3(
Math.sin(a) * compassRadius,
-0.205,
Math.cos(a) * compassRadius
)
);
}
const compass = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(compassPoints),
new THREE.LineBasicMaterial({
color: 0xe6fbff,
transparent: true,
opacity: 0.48
})
);
scene.add(compass);
// -------------------------------------------------------------------------
// World-space billboard labels
// -------------------------------------------------------------------------
function makeLabel(text, color = "#ffffff", width = 2.8) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 20;
sprite.userData.canvas = canvas;
sprite.userData.context = context;
sprite.userData.texture = texture;
sprite.userData.color = color;
updateLabel(sprite, text, color);
return sprite;
}
function updateLabel(sprite, text, color = sprite.userData.color) {
const context = sprite.userData.context;
const texture = sprite.userData.texture;
context.clearRect(0, 0, 512, 128);
context.fillStyle = "rgba(12, 31, 39, 0.88)";
context.strokeStyle = color;
context.lineWidth = 4;
context.beginPath();
if (context.roundRect) {
context.roundRect(5, 5, 502, 118, 24);
} else {
context.rect(5, 5, 502, 118);
}
context.fill();
context.stroke();
context.fillStyle = color;
context.font = "700 34px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 65);
sprite.userData.color = color;
texture.needsUpdate = true;
}
const cardinalLabels = [
{ text: "N", position: [0, 0.25, 6.25] },
{ text: "E", position: [6.25, 0.25, 0] },
{ text: "S", position: [0, 0.25, -6.25] },
{ text: "W", position: [-6.25, 0.25, 0] }
];
for (const item of cardinalLabels) {
const label = makeLabel(item.text, "#eaffff", 0.85);
label.position.set(...item.position);
scene.add(label);
}
// -------------------------------------------------------------------------
// Solid low-poly arrow
// -------------------------------------------------------------------------
const Z_AXIS = new THREE.Vector3(0, 0, 1);
function makeSolidArrow(color, shaftLength = 3.2, headLength = 0.85) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.42,
metalness: 0.08,
emissive: color,
emissiveIntensity: 0.08
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.09, shaftLength, 8),
material
);
shaft.rotation.x = Math.PI / 2;
shaft.position.z = shaftLength / 2;
shaft.castShadow = true;
group.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.31, headLength, 8),
material
);
head.rotation.x = Math.PI / 2;
head.position.z = shaftLength + headLength / 2;
head.castShadow = true;
group.add(head);
return group;
}
// -------------------------------------------------------------------------
// Sailboat hierarchy
//
// boatHeading controls compass heading.
// boatFloat provides subtle floating and rolling.
// -------------------------------------------------------------------------
const boatHeading = new THREE.Group();
const boatFloat = new THREE.Group();
boatHeading.add(boatFloat);
scene.add(boatHeading);
// Hull -------------------------------------------------------------------
const sections = [
{ z: -2.65, width: 0.52, top: 0.55, bottom: 0.02 },
{ z: -1.80, width: 0.92, top: 0.61, bottom: -0.18 },
{ z: 0.25, width: 1.05, top: 0.67, bottom: -0.32 },
{ z: 1.65, width: 0.80, top: 0.71, bottom: -0.17 },
{ z: 2.78, width: 0.07, top: 0.75, bottom: 0.43 }
];
const sectionVertices = sections.map(section => [
new THREE.Vector3(-section.width, section.top, section.z),
new THREE.Vector3(
-section.width * 0.55,
section.bottom,
section.z
),
new THREE.Vector3(
section.width * 0.55,
section.bottom,
section.z
),
new THREE.Vector3( section.width, section.top, section.z)
]);
const hullPositions = [];
const hullGroups = [];
function appendTriangle(a, b, c) {
hullPositions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
}
for (let s = 0; s < sections.length - 1; s++) {
for (let side = 0; side < 3; side++) {
const start = hullPositions.length / 3;
const a = sectionVertices[s][side];
const b = sectionVertices[s][side + 1];
const c = sectionVertices[s + 1][side];
const d = sectionVertices[s + 1][side + 1];
appendTriangle(a, b, d);
appendTriangle(a, d, c);
hullGroups.push({
start,
count: 6,
materialIndex: side === 1 ? 1 : 0
});
}
}
// Stern and bow caps.
let capStart = hullPositions.length / 3;
const stern = sectionVertices[0];
appendTriangle(stern[0], stern[1], stern[2]);
appendTriangle(stern[0], stern[2], stern[3]);
hullGroups.push({
start: capStart,
count: 6,
materialIndex: 0
});
capStart = hullPositions.length / 3;
const bow = sectionVertices[sectionVertices.length - 1];
appendTriangle(bow[0], bow[1], bow[2]);
appendTriangle(bow[0], bow[2], bow[3]);
hullGroups.push({
start: capStart,
count: 6,
materialIndex: 0
});
const hullGeometry = new THREE.BufferGeometry();
hullGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(hullPositions, 3)
);
hullGeometry.computeVertexNormals();
for (const group of hullGroups) {
hullGeometry.addGroup(
group.start,
group.count,
group.materialIndex
);
}
const hull = new THREE.Mesh(
hullGeometry,
[
new THREE.MeshStandardMaterial({
color: 0xc95d3e,
roughness: 0.76,
flatShading: true,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0x244955,
roughness: 0.82,
flatShading: true,
side: THREE.DoubleSide
})
]
);
hull.castShadow = true;
hull.receiveShadow = true;
boatFloat.add(hull);
// Deck -------------------------------------------------------------------
const deckBoundary = [
new THREE.Vector3(-0.50, 0.67, -2.60),
new THREE.Vector3( 0.50, 0.67, -2.60),
new THREE.Vector3( 0.91, 0.67, -1.78),
new THREE.Vector3( 1.01, 0.67, 0.25),
new THREE.Vector3( 0.76, 0.67, 1.64),
new THREE.Vector3( 0.08, 0.67, 2.73),
new THREE.Vector3(-0.08, 0.67, 2.73),
new THREE.Vector3(-0.76, 0.67, 1.64),
new THREE.Vector3(-1.01, 0.67, 0.25),
new THREE.Vector3(-0.91, 0.67, -1.78)
];
const deckPositions = [0, 0.67, -0.05];
for (const point of deckBoundary) {
deckPositions.push(point.x, point.y, point.z);
}
const deckIndices = [];
for (let i = 0; i < deckBoundary.length; i++) {
const current = i + 1;
const next = (i + 1) % deckBoundary.length + 1;
deckIndices.push(0, next, current);
}
const deckGeometry = new THREE.BufferGeometry();
deckGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(deckPositions, 3)
);
deckGeometry.setIndex(deckIndices);
deckGeometry.computeVertexNormals();
const deck = new THREE.Mesh(
deckGeometry,
new THREE.MeshStandardMaterial({
color: 0xf3e2bb,
roughness: 0.9,
flatShading: true,
side: THREE.DoubleSide
})
);
deck.receiveShadow = true;
boatFloat.add(deck);
const deckEdge = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(deckBoundary),
new THREE.LineBasicMaterial({ color: 0xfff6d8 })
);
boatFloat.add(deckEdge);
// Cockpit and deck details.
const cockpit = new THREE.Mesh(
new THREE.BoxGeometry(0.96, 0.09, 1.18),
new THREE.MeshStandardMaterial({
color: 0x263f45,
roughness: 0.9
})
);
cockpit.position.set(0, 0.735, -1.37);
cockpit.receiveShadow = true;
boatFloat.add(cockpit);
for (const x of [-0.43, 0.43]) {
const bench = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.11, 1.08),
new THREE.MeshStandardMaterial({
color: 0xd7b978,
roughness: 0.85
})
);
bench.position.set(x, 0.77, -1.37);
bench.castShadow = true;
boatFloat.add(bench);
}
const hatch = new THREE.Mesh(
new THREE.BoxGeometry(0.55, 0.06, 0.62),
new THREE.MeshStandardMaterial({
color: 0x5c7779,
roughness: 0.8
})
);
hatch.position.set(0, 0.75, 0.72);
hatch.castShadow = true;
boatFloat.add(hatch);
// Mast -------------------------------------------------------------------
const mast = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.075, 3.95, 8),
new THREE.MeshStandardMaterial({
color: 0x6b4b35,
roughness: 0.7,
metalness: 0.08
})
);
mast.position.set(0, 2.62, -0.10);
mast.castShadow = true;
boatFloat.add(mast);
const mastCollar = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.11, 8),
new THREE.MeshStandardMaterial({
color: 0x334c53,
roughness: 0.55,
metalness: 0.2
})
);
mastCollar.position.set(0, 0.73, -0.10);
boatFloat.add(mastCollar);
// Main sail and boom -----------------------------------------------------
const boomRig = new THREE.Group();
boomRig.position.set(0, 1.04, -0.10);
boatFloat.add(boomRig);
const boom = new THREE.Mesh(
new THREE.CylinderGeometry(0.043, 0.043, 2.48, 8),
new THREE.MeshStandardMaterial({
color: 0xd09b45,
roughness: 0.55,
metalness: 0.15
})
);
boom.rotation.x = -Math.PI / 2;
boom.position.z = -1.24;
boom.castShadow = true;
boomRig.add(boom);
const mainSailGeometry = new THREE.BufferGeometry();
mainSailGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, 0.00, 0.00,
0, 3.35, 0.00,
0, 0.02, -2.45
], 3)
);
mainSailGeometry.setIndex([0, 1, 2]);
mainSailGeometry.computeVertexNormals();
const mainSail = new THREE.Mesh(
mainSailGeometry,
new THREE.MeshStandardMaterial({
color: 0xffefc9,
roughness: 0.95,
side: THREE.DoubleSide,
flatShading: true
})
);
mainSail.castShadow = true;
mainSail.receiveShadow = true;
boomRig.add(mainSail);
const sailOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(mainSailGeometry),
new THREE.LineBasicMaterial({ color: 0x9a7546 })
);
boomRig.add(sailOutline);
// A colored lower sail panel adds a readable low-poly accent.
const sailPanelGeometry = new THREE.BufferGeometry();
sailPanelGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0.012, 1.32, 0.00,
0.012, 0.08, 0.00,
0.012, 0.08, -2.35
], 3)
);
sailPanelGeometry.setIndex([0, 1, 2]);
sailPanelGeometry.computeVertexNormals();
const sailPanel = new THREE.Mesh(
sailPanelGeometry,
new THREE.MeshStandardMaterial({
color: 0xd86545,
roughness: 0.92,
side: THREE.DoubleSide
})
);
boomRig.add(sailPanel);
// Jib --------------------------------------------------------------------
const jibGeometry = new THREE.BufferGeometry();
jibGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
0, 3.95, -0.10,
0, 0.75, 2.43,
0, 0.75, -0.10
], 3)
);
jibGeometry.setIndex([0, 1, 2]);
jibGeometry.computeVertexNormals();
const jib = new THREE.Mesh(
jibGeometry,
new THREE.MeshStandardMaterial({
color: 0xfff3d4,
roughness: 0.95,
side: THREE.DoubleSide,
flatShading: true,
transparent: true,
opacity: 0.94
})
);
jib.castShadow = true;
boatFloat.add(jib);
const jibOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(jibGeometry),
new THREE.LineBasicMaterial({ color: 0x9a7546 })
);
boatFloat.add(jibOutline);
// Sail-angle guide: translucent top-down sweep ---------------------------
const sweepPositions = new Float32Array(9);
const sweepGeometry = new THREE.BufferGeometry();
sweepGeometry.setAttribute(
"position",
new THREE.BufferAttribute(sweepPositions, 3)
);
const sailSweep = new THREE.Mesh(
sweepGeometry,
new THREE.MeshBasicMaterial({
color: 0xe85d9e,
transparent: true,
opacity: 0.14,
depthWrite: false,
side: THREE.DoubleSide
})
);
sailSweep.renderOrder = 1;
boatFloat.add(sailSweep);
// Sail-angle arc.
const ARC_STEPS = 28;
const arcPositions = new Float32Array((ARC_STEPS + 1) * 3);
const arcGeometry = new THREE.BufferGeometry();
arcGeometry.setAttribute(
"position",
new THREE.BufferAttribute(arcPositions, 3)
);
const sailArc = new THREE.Line(
arcGeometry,
new THREE.LineBasicMaterial({
color: 0xe85d9e,
transparent: true,
opacity: 0.95
})
);
boatFloat.add(sailArc);
const centerline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.79, -0.10),
new THREE.Vector3(0, 0.79, -2.05)
]),
new THREE.LineDashedMaterial({
color: 0xe85d9e,
dashSize: 0.12,
gapSize: 0.09,
transparent: true,
opacity: 0.65
})
);
centerline.computeLineDistances();
boatFloat.add(centerline);
// -------------------------------------------------------------------------
// Distinct indicator arrows
// -------------------------------------------------------------------------
// Heading arrow: local forward direction.
const headingArrow = makeSolidArrow(0xff8a3d, 1.35, 0.68);
headingArrow.position.set(0, 0.97, 1.18);
boatFloat.add(headingArrow);
const headingLabel = makeLabel("HEADING 035°", "#ffad72", 2.65);
headingLabel.position.set(0, 1.36, 2.95);
boatFloat.add(headingLabel);
// Sail-angle arrow: starts at the mast and follows the boom direction.
const sailArrow = makeSolidArrow(0xe85d9e, 1.25, 0.58);
sailArrow.position.set(0, 0.82, -0.10);
boatFloat.add(sailArrow);
const sailLabel = makeLabel("SAIL +28°", "#f38ab9", 2.1);
boatFloat.add(sailLabel);
// Wind arrow: world-space and independent of the boat.
const windArrow = makeSolidArrow(0x13b9d5, 3.35, 0.95);
windArrow.position.set(-4.35, 0.12, 0.35);
scene.add(windArrow);
const windLabel = makeLabel("WIND FLOW · 12 kn", "#62d9eb", 3.45);
windLabel.position.set(0, 0.70, 1.45);
windArrow.add(windLabel);
// Small wake lines behind the hull.
const wakeMaterial = new THREE.LineBasicMaterial({
color: 0xe8fbff,
transparent: true,
opacity: 0.42
});
for (const side of [-1, 1]) {
const wake = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(side * 0.45, 0.12, -2.45),
new THREE.Vector3(side * 0.82, 0.12, -3.05),
new THREE.Vector3(side * 1.15, 0.12, -3.75)
]),
wakeMaterial
);
boatFloat.add(wake);
}
// -------------------------------------------------------------------------
// UI state
// -------------------------------------------------------------------------
const headingInput = document.getElementById("heading");
const sailInput = document.getElementById("sail");
const windAngleInput = document.getElementById("windAngle");
const windSpeedInput = document.getElementById("windSpeed");
const headingValue = document.getElementById("headingValue");
const sailValue = document.getElementById("sailValue");
const windAngleValue = document.getElementById("windAngleValue");
const windSpeedValue = document.getElementById("windSpeedValue");
const relativeValue = document.getElementById("relativeValue");
const DEG = Math.PI / 180;
function signedDegrees(value) {
const rounded = Math.round(value);
return `${rounded >= 0 ? "+" : ""}${rounded}°`;
}
function compassDegrees(value) {
return `${Math.round(((value % 360) + 360) % 360)}°`;
}
function updateSailGuide(sailRadians) {
const radius = 2.45;
// Horizontal translucent sweep from the centerline to the boom.
sweepPositions.set([
0, 0.78, -0.10,
-Math.sin(sailRadians) * radius,
0.78,
-0.10 - Math.cos(sailRadians) * radius,
0,
0.78,
-0.10 - radius
]);
sweepGeometry.attributes.position.needsUpdate = true;
sweepGeometry.computeBoundingSphere();
// Arc measured from the stern centerline.
for (let i = 0; i <= ARC_STEPS; i++) {
const t = sailRadians * (i / ARC_STEPS);
arcPositions[i * 3] = -Math.sin(t) * 1.55;
arcPositions[i * 3 + 1] = 0.79;
arcPositions[i * 3 + 2] = -0.10 - Math.cos(t) * 1.55;
}
arcGeometry.attributes.position.needsUpdate = true;
arcGeometry.computeBoundingSphere();
const direction = new THREE.Vector3(
-Math.sin(sailRadians),
0,
-Math.cos(sailRadians)
);
sailArrow.quaternion.setFromUnitVectors(Z_AXIS, direction);
sailLabel.position.set(
direction.x * 1.75,
1.10,
-0.10 + direction.z * 1.75
);
}
function updateScene() {
const heading = Number(headingInput.value);
const sail = Number(sailInput.value);
const windAngle = Number(windAngleInput.value);
const windSpeed = Number(windSpeedInput.value);
const headingRadians = heading * DEG;
const sailRadians = sail * DEG;
const windRadians = windAngle * DEG;
boatHeading.rotation.y = headingRadians;
boomRig.rotation.y = sailRadians;
const windDirection = new THREE.Vector3(
Math.sin(windRadians),
0,
Math.cos(windRadians)
);
windArrow.quaternion.setFromUnitVectors(Z_AXIS, windDirection);
windArrow.scale.set(1, 1, 0.76 + windSpeed / 28);
updateSailGuide(sailRadians);
headingValue.value = compassDegrees(heading);
sailValue.value = signedDegrees(sail);
windAngleValue.value = compassDegrees(windAngle);
windSpeedValue.value = `${windSpeed} kn`;
const relative = ((windAngle - heading + 540) % 360) - 180;
relativeValue.textContent = signedDegrees(relative);
updateLabel(headingLabel, `HEADING ${compassDegrees(heading)}`, "#ffad72");
updateLabel(sailLabel, `SAIL ${signedDegrees(sail)}`, "#f38ab9");
updateLabel(
windLabel,
`WIND FLOW · ${windSpeed} kn`,
"#62d9eb"
);
}
for (const input of [
headingInput,
sailInput,
windAngleInput,
windSpeedInput
]) {
input.addEventListener("input", updateScene);
}
document.getElementById("reset").addEventListener("click", () => {
headingInput.value = 35;
sailInput.value = 28;
windAngleInput.value = 250;
windSpeedInput.value = 12;
updateScene();
resetCamera();
});
updateScene();
// -------------------------------------------------------------------------
// Custom camera controls, implemented without addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.35, 0);
let cameraTheta = 0.72;
let cameraPhi = 0.78;
let cameraRadius = 13.2;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraTheta = 0.72;
cameraPhi = 0.78;
cameraRadius = 13.2;
updateCamera();
}
document.getElementById("topView").addEventListener("click", () => {
cameraTheta = 0;
cameraPhi = 0.08;
cameraRadius = 14.5;
updateCamera();
});
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - deltaY * 0.005,
0.08,
1.35
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
7,
24
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
updateCamera();
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
boatFloat.position.y = Math.sin(elapsed * 1.05) * 0.022;
boatFloat.rotation.z = Math.sin(elapsed * 0.82) * 0.008;
renderer.render(scene, camera);
});
</script>
</body>
</html>
```