Prompt specification
Build or customize the Three.js 3D scene "Sail orientation beside a seasonal wind arrow" 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: Sail orientation beside a seasonal wind arrow
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sail-orientation-beside-a-seasonal-wind-arrow-x2589
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a sailing rig under Indian Ocean monsoon winds. Model a small historically referenced sailing vessel rig beside a wind arrow. Show the assumed sail orientation and distinguish seasonal prevailing winds from guaranteed daily weather. Stylized solid forms.
Working Three.js Starter (sail-orientation-beside-a-seasonal-wind-arrow-x2589):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Indian Ocean Monsoon — Dhow Lateen Rig</title>
<style>
:root {
--ink: #17343a;
--muted: #567076;
--paper: rgba(250, 245, 226, 0.94);
--teal: #078b86;
--amber: #e58b36;
--cyan: #62d7d2;
--line: rgba(23, 52, 58, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #f1dfbd;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.62);
box-shadow:
0 18px 55px rgba(30, 59, 61, 0.16),
0 2px 8px rgba(30, 59, 61, 0.08);
backdrop-filter: blur(12px);
}
.intro {
top: 22px;
left: 22px;
width: min(405px, calc(100vw - 44px));
padding: 22px 24px 19px;
border-radius: 5px 22px 22px 22px;
}
.eyebrow {
margin-bottom: 9px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 3.4vw, 46px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.season-state {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-top: 17px;
padding: 12px 13px;
border: 1px solid rgba(7, 139, 134, 0.24);
border-radius: 10px;
background: rgba(7, 139, 134, 0.075);
}
.season-state strong {
display: block;
font-size: 12px;
}
.season-state span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.compass {
flex: 0 0 auto;
min-width: 72px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
line-height: 1.25;
text-align: center;
}
.compass b {
display: block;
font-size: 23px;
line-height: 1;
}
.reference {
margin: 15px 0 0;
padding-top: 13px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.reference strong {
color: var(--ink);
}
.legend {
right: 22px;
bottom: 22px;
width: min(360px, calc(100vw - 44px));
padding: 18px 19px 16px;
border-radius: 20px 5px 20px 20px;
}
.legend-title {
margin-bottom: 13px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 45px 1fr;
gap: 10px;
align-items: start;
margin: 10px 0;
}
.swatch {
position: relative;
height: 18px;
margin-top: 2px;
}
.swatch.seasonal::before {
content: "";
position: absolute;
top: 7px;
left: 2px;
width: 38px;
height: 5px;
border-radius: 4px;
background: var(--teal);
}
.swatch.seasonal::after {
content: "";
position: absolute;
top: 3px;
right: 1px;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-left: 10px solid var(--teal);
}
.swatch.daily::before {
content: "";
position: absolute;
top: 7px;
left: 1px;
width: 39px;
border-top: 3px dashed var(--amber);
}
.swatch.daily::after {
content: "";
position: absolute;
top: 3px;
right: 1px;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-left: 9px solid var(--amber);
}
.swatch.trim::before {
content: "";
position: absolute;
top: 7px;
left: 2px;
width: 39px;
border-top: 3px solid var(--cyan);
transform: rotate(-12deg);
transform-origin: left center;
}
.legend-row strong {
display: block;
font-size: 12px;
}
.legend-row p {
margin: 3px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.warning {
margin: 13px 0 0;
padding: 10px 11px;
border-radius: 8px;
background: rgba(229, 139, 54, 0.11);
color: #75451f;
font-size: 10px;
line-height: 1.45;
}
.warning strong {
color: #5b3216;
}
.controls {
position: fixed;
z-index: 10;
left: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 9px;
}
.hint {
padding: 9px 12px;
border-radius: 20px;
background: rgba(250, 245, 226, 0.84);
color: var(--muted);
font-size: 10px;
box-shadow: 0 5px 20px rgba(30, 59, 61, 0.09);
}
button {
border: 1px solid rgba(23, 52, 58, 0.18);
border-radius: 20px;
padding: 10px 14px;
background: var(--paper);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
box-shadow: 0 5px 20px rgba(30, 59, 61, 0.09);
}
button:hover,
button:focus-visible {
background: #fff8df;
outline: 2px solid rgba(7, 139, 134, 0.3);
outline-offset: 2px;
}
.world-label {
position: fixed;
z-index: 5;
max-width: 230px;
padding: 9px 11px;
border-left: 4px solid var(--teal);
border-radius: 2px 10px 10px 2px;
background: rgba(21, 50, 55, 0.92);
color: #fbf4dc;
box-shadow: 0 8px 25px rgba(16, 42, 47, 0.16);
pointer-events: none;
transition: opacity 120ms linear;
}
.world-label strong {
display: block;
font-size: 11px;
letter-spacing: 0.01em;
}
.world-label span {
display: block;
margin-top: 3px;
color: rgba(251, 244, 220, 0.72);
font-size: 9px;
line-height: 1.35;
}
.world-label.daily {
border-left-color: var(--amber);
}
.world-label.sail {
border-left-color: var(--cyan);
}
@media (max-width: 720px) {
.intro {
top: 12px;
left: 12px;
width: min(340px, calc(100vw - 24px));
padding: 16px 17px 14px;
}
h1 {
font-size: 31px;
}
.reference {
display: none;
}
.legend {
right: 12px;
bottom: 12px;
width: min(330px, calc(100vw - 24px));
padding: 14px 15px;
}
.legend-row {
margin: 7px 0;
}
.warning {
margin-top: 9px;
}
.controls {
left: 12px;
bottom: auto;
top: 218px;
}
.hint {
display: none;
}
.world-label {
max-width: 165px;
padding: 7px 8px;
}
.world-label strong {
font-size: 9px;
}
.world-label span {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<section class="panel intro" aria-label="Scene explanation">
<div class="eyebrow">Interpretive historical model</div>
<h1>Monsoon Trade</h1>
<p class="subtitle">
Indian Ocean sailing conditions, illustrated with a generalized
dhow-type lateen rig.
</p>
<div class="season-state">
<div>
<strong>Assumed season: southwest monsoon</strong>
<span>Broad regional tendency, roughly June–September; dates vary.</span>
</div>
<div class="compass" aria-label="Wind flows from southwest to northeast">
SW
<b>→</b>
NE
</div>
</div>
<p class="reference">
<strong>Historic reference:</strong> lateen-rigged dhow-type craft were used
across Indian Ocean, Red Sea, and Persian Gulf maritime networks. This is
a generalized rig study, not a reconstruction of one named vessel or date.
</p>
</section>
<aside class="panel legend" aria-label="Wind and sail legend">
<div class="legend-title">Reading the diagram</div>
<div class="legend-row">
<div class="swatch seasonal" aria-hidden="true"></div>
<div>
<strong>Seasonal prevailing wind</strong>
<p>
Wide, solid teal arrow: the climatological SW-monsoon direction.
“Prevailing” means a seasonal tendency, not a daily guarantee.
</p>
</div>
</div>
<div class="legend-row">
<div class="swatch daily" aria-hidden="true"></div>
<div>
<strong>Possible daily breeze</strong>
<p>
Thin, dashed amber arrow: an illustrative day-specific variation.
It is not an observation or forecast; real wind may shift, weaken,
reverse, or disappear.
</p>
</div>
</div>
<div class="legend-row">
<div class="swatch trim" aria-hidden="true"></div>
<div>
<strong>Assumed sail orientation</strong>
<p>
The lateen sail is sheeted roughly 12° off the boat’s centerline to
meet the assumed prevailing flow.
</p>
</div>
</div>
<p class="warning">
<strong>No daily wind is guaranteed.</strong>
Seasonal monsoon patterns and day-to-day weather are different kinds of
information.
</p>
</aside>
<div class="controls">
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<button id="reset" type="button">Reset view</button>
</div>
<div id="seasonLabel" class="world-label">
<strong>Seasonal prevailing wind</strong>
<span>Solid teal · SW monsoon tendency</span>
</div>
<div id="dailyLabel" class="world-label daily">
<strong>Possible daily breeze</strong>
<span>Dashed amber · illustrative only</span>
</div>
<div id="sailLabel" class="world-label sail">
<strong>Assumed sail trim</strong>
<span>Lateen sail sheeted about 12° to port</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene and renderer
// ------------------------------------------------------------
const stage = document.querySelector("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf1dfbd);
scene.fog = new THREE.Fog(0xf1dfbd, 19, 48);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional Indian Ocean sailing scene"
);
stage.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xffefcf, 0x155f70, 2.05);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xffd99b, 3.15);
sunLight.position.set(-7, 11, 8);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -12;
sunLight.shadow.camera.right = 12;
sunLight.shadow.camera.top = 12;
sunLight.shadow.camera.bottom = -12;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 35;
sunLight.shadow.bias = -0.0007;
scene.add(sunLight);
const rimLight = new THREE.DirectionalLight(0x8bdedb, 0.8);
rimLight.position.set(8, 4, -9);
scene.add(rimLight);
// ------------------------------------------------------------
// Helpers
// ------------------------------------------------------------
function flatMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
}
function cylinderBetween(a, b, radius, material, radialSegments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function coneBetween(a, b, radius, material, radialSegments = 12) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.ConeGeometry(
radius,
length,
radialSegments,
1,
false
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
return mesh;
}
function meshFromTriangles(vertices, material) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function lineFromPoints(points, material) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
return new THREE.Line(geometry, material);
}
// ------------------------------------------------------------
// Low-poly ocean
// ------------------------------------------------------------
function waveHeight(x, z) {
return (
0.12 * Math.sin(x * 0.43 + z * 0.18) +
0.075 * Math.sin(z * 0.88 - x * 0.17) +
0.04 * Math.sin(x * 1.38 + z * 1.03)
);
}
const oceanGeometry = new THREE.PlaneGeometry(
70,
70,
38,
38
);
const oceanPositions = oceanGeometry.attributes.position;
for (let i = 0; i < oceanPositions.count; i++) {
const x = oceanPositions.getX(i);
const localY = oceanPositions.getY(i);
const worldZ = -localY;
oceanPositions.setZ(i, waveHeight(x, worldZ));
}
oceanGeometry.rotateX(-Math.PI / 2);
oceanGeometry.computeVertexNormals();
const oceanMaterial = flatMaterial(0x176f83, {
roughness: 0.95,
side: THREE.DoubleSide
});
const ocean = new THREE.Mesh(oceanGeometry, oceanMaterial);
ocean.position.y = -0.33;
ocean.receiveShadow = true;
scene.add(ocean);
const foamMaterial = new THREE.MeshBasicMaterial({
color: 0xbfe4dc,
transparent: true,
opacity: 0.42
});
const foamGeometry = new THREE.BoxGeometry(1, 1, 1);
let seed = 17;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
for (let i = 0; i < 55; i++) {
let x = random() * 27 - 13.5;
let z = random() * 19 - 9.5;
// Leave more visual space around the vessel and arrows.
if (x > -6.5 && x < 7.8 && Math.abs(z) < 3.1) {
x += x < 0 ? -2.4 : 2.4;
}
const foam = new THREE.Mesh(foamGeometry, foamMaterial);
foam.scale.set(
0.35 + random() * 1.15,
0.025,
0.035 + random() * 0.035
);
foam.position.set(
x,
-0.29 + waveHeight(x, z),
z
);
foam.rotation.y = THREE.MathUtils.degToRad(-12 + random() * 12);
scene.add(foam);
}
// ------------------------------------------------------------
// Distant sun, clouds, and island
// ------------------------------------------------------------
const sun = new THREE.Mesh(
new THREE.SphereGeometry(1.05, 18, 12),
new THREE.MeshBasicMaterial({ color: 0xf1b85e })
);
sun.position.set(-10, 10, -22);
scene.add(sun);
const cloudMaterial = flatMaterial(0xf8e9ca, {
roughness: 1
});
function addCloud(x, y, z, scale) {
const cloud = new THREE.Group();
const pieces = [
[-0.95, 0, 0, 0.75],
[-0.25, 0.22, 0.05, 0.95],
[0.55, 0.08, 0, 0.8],
[1.1, -0.03, 0.08, 0.55]
];
for (const [px, py, pz, size] of pieces) {
const piece = new THREE.Mesh(
new THREE.IcosahedronGeometry(size, 1),
cloudMaterial
);
piece.position.set(px, py, pz);
piece.scale.y = 0.55;
piece.castShadow = true;
cloud.add(piece);
}
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
scene.add(cloud);
}
addCloud(-7, 8.4, -13, 1.2);
addCloud(7.5, 9.2, -17, 1.45);
addCloud(-13, 6.5, -7, 0.75);
const island = new THREE.Group();
island.position.set(-8.5, -0.55, -16);
const islandMaterial = flatMaterial(0x315e58);
const islandBody = new THREE.Mesh(
new THREE.ConeGeometry(3.4, 1.8, 7),
islandMaterial
);
islandBody.rotation.y = 0.3;
islandBody.scale.z = 0.45;
island.add(islandBody);
const islandTop = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.75, 0),
flatMaterial(0x587465)
);
islandTop.position.set(-0.35, 1.05, 0);
islandTop.scale.set(1.35, 0.7, 0.8);
island.add(islandTop);
scene.add(island);
// ------------------------------------------------------------
// Dhow-type vessel
// ------------------------------------------------------------
const boat = new THREE.Group();
boat.position.set(-2.05, 0, 0);
scene.add(boat);
const hullMaterial = flatMaterial(0x683b28, {
side: THREE.DoubleSide
});
const deckMaterial = flatMaterial(0xb77d4c, {
side: THREE.DoubleSide
});
const railMaterial = flatMaterial(0xd7a15e);
const mastMaterial = flatMaterial(0x4b3027);
const ropeMaterial = flatMaterial(0x594b39);
const sailMaterial = flatMaterial(0xe9bc60, {
side: THREE.DoubleSide
});
const sailPanelMaterial = flatMaterial(0xc8653e, {
side: THREE.DoubleSide
});
const stations = [
[-3.05, 0.58],
[-2.65, 1.02],
[-1.9, 1.2],
[-0.9, 1.22],
[0.1, 1.12],
[1.1, 0.93],
[2.0, 0.68],
[2.65, 0.38],
[3.15, 0.06]
];
const hullVertices = [];
const hullIndices = [];
for (const [x, width] of stations) {
const topY = 0.44;
const bottomY =
-0.65 +
0.28 * Math.pow(Math.abs(x) / 3.15, 2);
// Four points around each hull cross-section:
// top port, top starboard, bottom starboard, bottom port.
hullVertices.push(
x, topY, -width,
x, topY, width,
x, bottomY, width * 0.28,
x, bottomY, -width * 0.28
);
}
for (let i = 0; i < stations.length - 1; i++) {
for (let j = 0; j < 4; j++) {
const nextJ = (j + 1) % 4;
const a = i * 4 + j;
const b = i * 4 + nextJ;
const c = (i + 1) * 4 + nextJ;
const d = (i + 1) * 4 + j;
hullIndices.push(a, b, d, b, c, d);
}
}
// Close the stern and pointed bow.
hullIndices.push(0, 2, 1, 0, 3, 2);
const lastStation = (stations.length - 1) * 4;
hullIndices.push(
lastStation,
lastStation + 1,
lastStation + 2,
lastStation,
lastStation + 2,
lastStation + 3
);
const hullGeometry = new THREE.BufferGeometry();
hullGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(hullVertices, 3)
);
hullGeometry.setIndex(hullIndices);
hullGeometry.computeVertexNormals();
const hull = new THREE.Mesh(hullGeometry, hullMaterial);
hull.castShadow = true;
hull.receiveShadow = true;
boat.add(hull);
// Deck surface.
const deckVertices = [];
const deckIndices = [];
for (let i = 0; i < stations.length - 1; i++) {
const [x1, w1] = stations[i];
const [x2, w2] = stations[i + 1];
const offset = deckVertices.length / 3;
deckVertices.push(
x1, 0.455, -w1,
x1, 0.455, w1,
x2, 0.455, w2,
x2, 0.455, -w2
);
deckIndices.push(
offset, offset + 1, offset + 2,
offset, offset + 2, offset + 3
);
}
const deckGeometry = new THREE.BufferGeometry();
deckGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(deckVertices, 3)
);
deckGeometry.setIndex(deckIndices);
deckGeometry.computeVertexNormals();
const deck = new THREE.Mesh(deckGeometry, deckMaterial);
deck.castShadow = true;
deck.receiveShadow = true;
boat.add(deck);
// Gunwales.
for (const side of [-1, 1]) {
for (let i = 0; i < stations.length - 1; i++) {
const [x1, w1] = stations[i];
const [x2, w2] = stations[i + 1];
boat.add(
cylinderBetween(
new THREE.Vector3(x1, 0.49, side * w1),
new THREE.Vector3(x2, 0.49, side * w2),
0.045,
railMaterial,
6
)
);
}
}
boat.add(
cylinderBetween(
new THREE.Vector3(-2.8, -0.61, 0),
new THREE.Vector3(2.7, -0.52, 0),
0.075,
mastMaterial,
7
)
);
// Long steering oars.
for (const side of [-1, 1]) {
const oarStart = new THREE.Vector3(-2.35, 0.59, side * 0.72);
const oarEnd = new THREE.Vector3(-3.72, 0.13, side * 1.5);
boat.add(
cylinderBetween(oarStart, oarEnd, 0.045, mastMaterial, 7)
);
const blade = new THREE.Mesh(
new THREE.BoxGeometry(0.72, 0.08, 0.22),
railMaterial
);
blade.position.copy(oarEnd);
blade.rotation.y = side * 0.32;
blade.rotation.z = -0.08;
blade.castShadow = true;
boat.add(blade);
}
// Small cargo sacks.
const sackColors = [0xa98554, 0xc09966, 0x8f6c47];
const cargoPositions = [
[-1.9, 0.66, 0.28],
[-1.45, 0.64, -0.25],
[-1.72, 0.64, -0.52]
];
cargoPositions.forEach((position, index) => {
const sack = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.31, 0),
flatMaterial(sackColors[index])
);
sack.position.set(...position);
sack.scale.set(1, 1.18, 0.9);
sack.rotation.y = index * 0.7;
sack.castShadow = true;
boat.add(sack);
});
// ------------------------------------------------------------
// Lateen rig
// ------------------------------------------------------------
const mastFoot = new THREE.Vector3(0.12, 0.5, 0);
const mastTop = new THREE.Vector3(-0.12, 4.78, 0);
boat.add(
cylinderBetween(mastFoot, mastTop, 0.095, mastMaterial, 9)
);
const trimGroup = new THREE.Group();
const trimAngle = THREE.MathUtils.degToRad(12);
trimGroup.rotation.y = trimAngle;
boat.add(trimGroup);
const sailTack = new THREE.Vector3(1.48, 1.12, 0);
const sailHead = new THREE.Vector3(-2.08, 5.27, 0);
const sailClew = new THREE.Vector3(-1.78, 1.27, 0);
// Long diagonal lateen yard.
trimGroup.add(
cylinderBetween(sailTack, sailHead, 0.067, mastMaterial, 8)
);
// Lower sail spar and leech.
trimGroup.add(
cylinderBetween(sailTack, sailClew, 0.05, mastMaterial, 7)
);
trimGroup.add(
cylinderBetween(sailClew, sailHead, 0.024, ropeMaterial, 6)
);
const sail = meshFromTriangles(
[
sailTack.x, sailTack.y, sailTack.z,
sailHead.x, sailHead.y, sailHead.z,
sailClew.x, sailClew.y, sailClew.z
],
sailMaterial
);
trimGroup.add(sail);
// A contrasting lower panel gives the sail a graphic, solid-form style.
const midTackHead = sailTack.clone().lerp(sailHead, 0.48);
const midTackClew = sailTack.clone().lerp(sailClew, 0.5);
const panel = meshFromTriangles(
[
sailTack.x, sailTack.y, sailTack.z + 0.012,
midTackHead.x, midTackHead.y, midTackHead.z + 0.012,
midTackClew.x, midTackClew.y, midTackClew.z + 0.012
],
sailPanelMaterial
);
trimGroup.add(panel);
// Mast stays.
boat.add(
cylinderBetween(
mastTop,
new THREE.Vector3(2.6, 0.49, 0),
0.018,
ropeMaterial,
6
)
);
boat.add(
cylinderBetween(
mastTop,
new THREE.Vector3(-2.75, 0.5, 0),
0.018,
ropeMaterial,
6
)
);
// Rotated yard head and clew positions for the rigging.
const rotatedHead = sailHead.clone().applyAxisAngle(
new THREE.Vector3(0, 1, 0),
trimAngle
);
const rotatedClew = sailClew.clone().applyAxisAngle(
new THREE.Vector3(0, 1, 0),
trimAngle
);
boat.add(
cylinderBetween(
mastTop,
rotatedHead,
0.019,
ropeMaterial,
6
)
);
boat.add(
cylinderBetween(
rotatedClew,
new THREE.Vector3(rotatedClew.x - 0.2, 0.5, rotatedClew.z),
0.018,
ropeMaterial,
6
)
);
// Cyan trim-angle guide, drawn on the boat's centerline plane.
const guideMaterial = new THREE.LineBasicMaterial({
color: 0x62d7d2,
transparent: true,
opacity: 0.95
});
const guideCenter = new THREE.Vector3(0.12, 0.08, 0);
const guideDirection = new THREE.Vector3(
Math.cos(-trimAngle),
0,
Math.sin(-trimAngle)
);
boat.add(
lineFromPoints(
[
guideCenter,
guideCenter.clone().addScaledVector(guideDirection, 1.24)
],
guideMaterial
)
);
const arcPoints = [];
for (let i = 0; i <= 20; i++) {
const angle = -trimAngle * (i / 20);
arcPoints.push(
new THREE.Vector3(
guideCenter.x + Math.cos(angle) * 0.78,
guideCenter.y,
guideCenter.z + Math.sin(angle) * 0.78
)
);
}
boat.add(lineFromPoints(arcPoints, guideMaterial));
const trimPivot = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 8, 6),
new THREE.MeshBasicMaterial({ color: 0x62d7d2 })
);
trimPivot.position.copy(guideCenter);
boat.add(trimPivot);
// ------------------------------------------------------------
// Wind arrows
// ------------------------------------------------------------
const seasonalColor = 0x078b86;
const dailyColor = 0xe58b36;
const seasonalMaterial = flatMaterial(seasonalColor, {
roughness: 0.7
});
const dailyMaterial = flatMaterial(dailyColor, {
roughness: 0.7
});
const seasonalDirection = new THREE.Vector3(
Math.cos(-trimAngle),
0,
Math.sin(-trimAngle)
).normalize();
const seasonalTail = new THREE.Vector3(3.05, 1.48, 2.15);
const seasonalTip = seasonalTail
.clone()
.addScaledVector(seasonalDirection, 3.42);
const seasonalBase = seasonalTip
.clone()
.addScaledVector(seasonalDirection, -0.67);
scene.add(
cylinderBetween(
seasonalTail,
seasonalBase,
0.145,
seasonalMaterial,
10
)
);
scene.add(
coneBetween(
seasonalBase,
seasonalTip,
0.37,
seasonalMaterial,
14
)
);
// Small tail vanes reinforce the broad-arrow silhouette.
for (const side of [-1, 1]) {
scene.add(
cylinderBetween(
seasonalTail.clone().addScaledVector(seasonalDirection, -0.34),
seasonalTail
.clone()
.add(new THREE.Vector3(0, 0, side * 0.28)),
0.06,
seasonalMaterial,
7
)
);
}
const dailyDirection = new THREE.Vector3(
Math.cos(THREE.MathUtils.degToRad(-4)),
0,
Math.sin(THREE.MathUtils.degToRad(-4))
).normalize();
const dailyTail = new THREE.Vector3(2.85, 0.72, 1.25);
const dailyLength = 3.05;
const dailyTip = dailyTail
.clone()
.addScaledVector(dailyDirection, dailyLength);
const dailyHeadLength = 0.46;
for (let i = 0; i < 5; i++) {
const start = dailyTail
.clone()
.addScaledVector(dailyDirection, i * 0.49);
const end = dailyTail
.clone()
.addScaledVector(dailyDirection, i * 0.49 + 0.27);
scene.add(
cylinderBetween(start, end, 0.047, dailyMaterial, 7)
);
}
const dailyHeadBase = dailyTip
.clone()
.addScaledVector(dailyDirection, -dailyHeadLength);
scene.add(
coneBetween(
dailyHeadBase,
dailyTip,
0.17,
dailyMaterial,
12
)
);
// Pale wind streaks follow the assumed prevailing direction.
const streakMaterial = new THREE.MeshBasicMaterial({
color: 0xeaf0dc,
transparent: true,
opacity: 0.38
});
for (let i = 0; i < 9; i++) {
const center = new THREE.Vector3(
-4.8 + i * 0.85,
0.76 + (i % 3) * 0.43,
-1.85 + (i % 2) * 0.35
);
const length = 0.75 + (i % 3) * 0.26;
const a = center.clone().addScaledVector(seasonalDirection, -length / 2);
const b = center.clone().addScaledVector(seasonalDirection, length / 2);
scene.add(
cylinderBetween(a, b, 0.018, streakMaterial, 6)
);
}
// ------------------------------------------------------------
// Projected HTML labels
// ------------------------------------------------------------
const seasonAnchor = new THREE.Object3D();
seasonAnchor.position.copy(seasonalTip).add(new THREE.Vector3(0, 0.82, 0));
scene.add(seasonAnchor);
const dailyAnchor = new THREE.Object3D();
dailyAnchor.position.copy(dailyTip).add(new THREE.Vector3(-0.2, 0.32, 0));
scene.add(dailyAnchor);
const sailAnchor = new THREE.Object3D();
sailAnchor.position.set(-0.3, 2.6, 0.1);
trimGroup.add(sailAnchor);
const labelDefinitions = [
{
element: document.querySelector("#seasonLabel"),
anchor: seasonAnchor,
offsetX: 12,
offsetY: -4
},
{
element: document.querySelector("#dailyLabel"),
anchor: dailyAnchor,
offsetX: 18,
offsetY: 10
},
{
element: document.querySelector("#sailLabel"),
anchor: sailAnchor,
offsetX: -10,
offsetY: -4
}
];
const projected = new THREE.Vector3();
function updateLabels() {
for (const definition of labelDefinitions) {
definition.anchor.getWorldPosition(projected);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
definition.element.style.left = `${x}px`;
definition.element.style.top = `${y}px`;
definition.element.style.transform =
`translate(${definition.offsetX}px, ${definition.offsetY}px) ` +
"translate(-50%, -100%)";
definition.element.style.opacity = visible ? "1" : "0";
}
}
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard, and reset
// ------------------------------------------------------------
const target = new THREE.Vector3(0.15, 1.65, 0);
camera.position.set(9, 7.2, 12);
const initialOffset = camera.position.clone().sub(target);
const initialSpherical = new THREE.Spherical().setFromVector3(initialOffset);
let theta = initialSpherical.theta;
let phi = initialSpherical.phi;
let radius = initialSpherical.radius;
function updateCamera() {
const offset = new THREE.Vector3().setFromSpherical(
new THREE.Spherical(radius, phi, theta)
);
camera.position.copy(target).add(offset);
camera.lookAt(target);
}
updateCamera();
let dragging = false;
let previousX = 0;
let previousY = 0;
let activePointer = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
activePointer = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
theta -= dx * 0.006;
phi = THREE.MathUtils.clamp(phi - dy * 0.005, 0.28, 1.42);
updateCamera();
});
function endDrag(event) {
if (event.pointerId !== activePointer) return;
dragging = false;
activePointer = null;
renderer.domElement.style.cursor = "grab";
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
7.5,
25
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
if (event.key === "ArrowLeft") theta -= 0.08;
else if (event.key === "ArrowRight") theta += 0.08;
else if (event.key === "ArrowUp") phi = Math.max(0.28, phi - 0.06);
else if (event.key === "ArrowDown") phi = Math.min(1.42, phi + 0.06);
else if (event.key === "+" || event.key === "=") {
radius = Math.max(7.5, radius - 0.7);
} else if (event.key === "-" || event.key === "_") {
radius = Math.min(25, radius + 0.7);
} else {
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
function resetView() {
theta = initialSpherical.theta;
phi = initialSpherical.phi;
radius = initialSpherical.radius;
updateCamera();
}
document.querySelector("#reset").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 720 ? 52 : 42;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", onResize);
onResize();
renderer.setAnimationLoop(() => {
scene.updateMatrixWorld(true);
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```