Prompt specification
Build or customize the Three.js 3D scene "Beach-light direction comparison exhibit" 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: Beach-light direction comparison exhibit
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/beach-light-direction-comparison-exhibit-x0712
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring sea-turtle nesting. Create an educational shoreline model with adjustable artificial light markers; compare prescribed orientation cues while clearly labeling the visualization as conceptual and requiring species-specific references. Low-poly.
Working Three.js Starter (beach-light-direction-comparison-exhibit-x0712):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Sea-Turtle Shoreline Lab — Conceptual Orientation Model</title>
<style>
:root {
--ink: #eef8f7;
--muted: #a9c2c5;
--panel: rgba(8, 25, 34, 0.90);
--panel-soft: rgba(16, 42, 52, 0.76);
--line: rgba(182, 226, 226, 0.18);
--cyan: #59e0dc;
--coral: #ff7869;
--gold: #ffd166;
--purple: #b99cff;
--amber: #ffad59;
--radius: 16px;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071a27;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging { cursor: grabbing; }
.glass {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
header {
position: fixed;
top: 18px;
left: 18px;
z-index: 10;
width: 342px;
padding: 17px 18px;
border-radius: var(--radius);
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 4px;
font-size: 23px;
line-height: 1.12;
letter-spacing: -0.035em;
}
.subtitle {
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#concept-banner {
position: fixed;
z-index: 12;
top: 18px;
left: 50%;
width: min(560px, calc(100vw - 820px));
transform: translateX(-50%);
padding: 11px 17px;
border: 1px solid rgba(255, 173, 89, 0.44);
border-radius: 12px;
background: rgba(53, 31, 18, 0.91);
color: #ffe2bd;
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.22);
font-size: 11px;
line-height: 1.45;
text-align: center;
}
#concept-banner strong {
color: #ffc57f;
letter-spacing: 0.08em;
}
#controls {
position: fixed;
z-index: 10;
top: 153px;
left: 18px;
bottom: 52px;
width: 342px;
overflow: auto;
padding: 0 18px 18px;
border-radius: var(--radius);
scrollbar-width: thin;
scrollbar-color: #315967 transparent;
}
#readout {
position: fixed;
z-index: 10;
top: 18px;
right: 18px;
width: 354px;
max-height: calc(100vh - 72px);
overflow: auto;
padding: 17px 18px;
border-radius: var(--radius);
scrollbar-width: thin;
scrollbar-color: #315967 transparent;
}
section {
padding-top: 16px;
margin-top: 15px;
border-top: 1px solid var(--line);
}
section:first-of-type {
padding-top: 0;
margin-top: 0;
border-top: 0;
}
h2 {
margin: 0 0 11px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
color: #d7eeee;
}
.micro {
margin: 7px 0 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.marker-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 12px;
}
.marker-tab {
padding: 8px 5px;
color: var(--muted);
background: rgba(255,255,255,0.04);
border: 1px solid var(--line);
border-radius: 9px;
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: 140ms ease;
}
.marker-tab:hover,
.marker-tab.active {
color: white;
border-color: rgba(89, 224, 220, 0.68);
background: rgba(89, 224, 220, 0.12);
}
.control {
margin-top: 11px;
}
.control-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
margin-bottom: 6px;
color: #d7e8e9;
font-size: 11px;
}
output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
font-weight: 750;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 4px 0;
appearance: none;
background: linear-gradient(90deg, #39767b, #24454e);
border-radius: 99px;
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 2px solid #d8ffff;
border-radius: 50%;
background: #43c8c6;
box-shadow: 0 2px 10px rgba(0,0,0,.35);
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 2px solid #d8ffff;
border-radius: 50%;
background: #43c8c6;
cursor: pointer;
}
select {
width: 100%;
padding: 8px 9px;
color: #eaf8f8;
background: #102d38;
border: 1px solid var(--line);
border-radius: 8px;
outline: none;
font-size: 11px;
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 6px 0;
color: #d8e9e9;
font-size: 11.5px;
}
.toggle {
display: inline-flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
.toggle input {
width: 15px;
height: 15px;
accent-color: var(--cyan);
}
.dot {
display: inline-block;
width: 8px;
height: 8px;
margin-right: 7px;
border-radius: 50%;
vertical-align: 1px;
box-shadow: 0 0 10px currentColor;
}
.buttons {
display: flex;
gap: 7px;
margin-top: 11px;
}
button.action {
flex: 1;
padding: 8px 9px;
color: #dff6f5;
background: rgba(255,255,255,.055);
border: 1px solid var(--line);
border-radius: 9px;
cursor: pointer;
font-size: 10.5px;
font-weight: 700;
}
button.action:hover {
background: rgba(89, 224, 220, .12);
border-color: rgba(89, 224, 220, .40);
}
.callout {
margin-top: 13px;
padding: 11px 12px;
border-left: 3px solid var(--amber);
border-radius: 3px 10px 10px 3px;
background: rgba(255, 173, 89, .09);
color: #e8d3b9;
font-size: 10.5px;
line-height: 1.5;
}
.table-wrap { overflow-x: auto; }
table {
width: 100%;
border-collapse: collapse;
font-size: 10.5px;
}
th {
padding: 6px 5px;
color: #89a9ae;
font-size: 9px;
font-weight: 750;
text-align: right;
letter-spacing: .04em;
text-transform: uppercase;
}
th:first-child, td:first-child { text-align: left; }
td {
padding: 8px 5px;
border-top: 1px solid rgba(182,226,226,.10);
color: #d8e8e8;
text-align: right;
font-variant-numeric: tabular-nums;
}
tr.combined td {
color: #fff0bd;
font-weight: 750;
background: rgba(255, 209, 102, .055);
}
.key {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px 10px;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
}
.key > div {
display: flex;
align-items: center;
gap: 7px;
}
.status {
margin-top: 12px;
padding: 10px 11px;
border-radius: 10px;
background: rgba(89, 224, 220, .075);
color: #cde7e5;
font-size: 10.5px;
line-height: 1.48;
}
#labels {
position: fixed;
z-index: 5;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
padding: 4px 7px;
border: 1px solid rgba(255,255,255,.20);
border-radius: 6px;
background: rgba(5, 18, 25, .76);
color: white;
font-size: 9px;
font-weight: 750;
letter-spacing: .03em;
white-space: nowrap;
opacity: 0;
transform: translate(-50%, -50%);
transition: opacity 120ms linear;
box-shadow: 0 5px 16px rgba(0,0,0,.2);
}
.scene-label.important {
border-color: rgba(89,224,220,.55);
color: #d9ffff;
}
#hint {
position: fixed;
z-index: 10;
left: 50%;
bottom: 14px;
transform: translateX(-50%);
padding: 7px 12px;
border: 1px solid var(--line);
border-radius: 99px;
background: rgba(6, 21, 29, .80);
color: #a9c2c5;
font-size: 10px;
white-space: nowrap;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #071a27;
color: #b7d8d8;
font-size: 12px;
letter-spacing: .08em;
transition: opacity .4s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1120px) {
#concept-banner {
left: 380px;
width: calc(100vw - 400px);
transform: none;
}
#readout {
top: 92px;
}
}
@media (max-width: 820px) {
header {
width: calc(100vw - 36px);
}
#controls {
top: auto;
bottom: 42px;
width: calc(100vw - 36px);
max-height: 43vh;
}
#readout {
top: 158px;
right: 18px;
width: 310px;
max-height: 38vh;
}
#concept-banner {
left: 18px;
top: 153px;
width: calc(100vw - 366px);
min-width: 220px;
}
#hint { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive conceptual sea-turtle nesting shoreline model"></canvas>
<div id="labels" aria-hidden="true"></div>
<header class="glass">
<div class="eyebrow">Shoreline field lab / conceptual model</div>
<h1>Sea-turtle nesting & artificial light</h1>
<div class="subtitle">
Adjust coastal light markers, compare schematic orientation cues, and inspect
a low-poly nesting shoreline.
</div>
</header>
<div id="concept-banner">
<strong>CONCEPTUAL VISUALIZATION</strong><br />
Illustrative only. Verify every cue, response, and management action against
species-specific recovery plans, permits, and peer-reviewed references.
</div>
<aside id="controls" class="glass">
<section>
<h2>Artificial light markers</h2>
<div class="marker-tabs">
<button class="marker-tab active" data-marker="0">Marker A</button>
<button class="marker-tab" data-marker="1">Marker B</button>
<button class="marker-tab" data-marker="2">Marker C</button>
</div>
<label class="toggle-row">
<span>Selected marker active</span>
<span class="toggle">
<input id="markerEnabled" type="checkbox" checked />
<span>On</span>
</span>
</label>
<div class="control">
<div class="control-row">
<label for="markerIntensity">Lamp output</label>
<output id="markerIntensityValue">90%</output>
</div>
<input id="markerIntensity" type="range" min="0" max="100" value="90" />
</div>
<div class="control">
<div class="control-row">
<label for="markerBearing">Bearing from seaward</label>
<output id="markerBearingValue">155°</output>
</div>
<input id="markerBearing" type="range" min="-180" max="180" value="155" />
<div class="micro">0° = directly seaward; +90° = east alongshore; ±180° = inland.</div>
</div>
<div class="control">
<div class="control-row">
<label for="markerDistance">Distance from nest</label>
<output id="markerDistanceValue">18 m</output>
</div>
<input id="markerDistance" type="range" min="8" max="28" value="18" />
</div>
<div class="control">
<div class="control-row"><label for="markerColor">Lamp appearance</label></div>
<select id="markerColor">
<option value="warm">Warm amber · 2700 K</option>
<option value="neutral">Neutral white · 4000 K</option>
<option value="cool">Cool white · 5600 K</option>
</select>
</div>
<div class="buttons">
<button id="allLightsOff" class="action">Turn all lights off</button>
<button id="resetLights" class="action">Reset markers</button>
</div>
</section>
<section>
<h2>Prescribed cue comparison</h2>
<div class="micro">
Enable schematic cue inputs. Each arrow starts at the nest; the gold arrow
is their weighted conceptual combination.
</div>
<label class="toggle-row">
<span><i class="dot" style="color:#59e0dc;background:#59e0dc"></i>Offshore brightness</span>
<input id="cueOffshore" type="checkbox" checked />
</label>
<label class="toggle-row">
<span><i class="dot" style="color:#b99cff;background:#b99cff"></i>Beach gradient</span>
<input id="cueGradient" type="checkbox" checked />
</label>
<label class="toggle-row">
<span><i class="dot" style="color:#ff7869;background:#ff7869"></i>Artificial light</span>
<input id="cueArtificial" type="checkbox" checked />
</label>
<label class="toggle-row">
<span><i class="dot" style="color:#ffd166;background:#ffd166"></i>Reference cue</span>
<input id="cueReference" type="checkbox" />
</label>
<div class="control">
<div class="control-row">
<label for="referenceBearing">Reference bearing</label>
<output id="referenceBearingValue">0°</output>
</div>
<input id="referenceBearing" type="range" min="-180" max="180" value="0" />
</div>
<div class="control">
<div class="control-row"><label for="followMode">Hatchling path follows</label></div>
<select id="followMode">
<option value="combined">Combined conceptual cue</option>
<option value="artificial">Artificial-light cue</option>
<option value="offshore">Offshore-brightness cue</option>
<option value="reference">Reference cue</option>
</select>
</div>
<div class="buttons">
<button id="playPause" class="action">Pause motion</button>
<button id="resetView" class="action">Reset view</button>
</div>
</section>
<section>
<div class="callout">
<strong>Model boundary:</strong> cue weights and hatchling responses are
instructional placeholders, not measured behavior. Orientation may differ
by species, life stage, population, moon phase, cloud cover, beach slope,
and local development.
</div>
</section>
</aside>
<aside id="readout" class="glass">
<h2>Orientation comparison</h2>
<div class="micro">
Headings are measured from the seaward direction. “Offshore alignment”
compares each vector with a 0° seaward heading.
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Conceptual cue</th>
<th>Heading</th>
<th>Sea alignment</th>
</tr>
</thead>
<tbody>
<tr>
<td><i class="dot" style="color:#59e0dc;background:#59e0dc"></i>Offshore</td>
<td id="offshoreHeading">0°</td>
<td id="offshoreAlignment">aligned</td>
</tr>
<tr>
<td><i class="dot" style="color:#b99cff;background:#b99cff"></i>Beach gradient</td>
<td id="gradientHeading">0°</td>
<td id="gradientAlignment">aligned</td>
</tr>
<tr>
<td><i class="dot" style="color:#ff7869;background:#ff7869"></i>Artificial light</td>
<td id="artificialHeading">—</td>
<td id="artificialAlignment">—</td>
</tr>
<tr>
<td><i class="dot" style="color:#ffd166;background:#ffd166"></i>Reference</td>
<td id="referenceHeading">—</td>
<td id="referenceAlignment">—</td>
</tr>
<tr class="combined">
<td>Combined</td>
<td id="combinedHeading">—</td>
<td id="combinedAlignment">—</td>
</tr>
</tbody>
</table>
</div>
<div id="modelStatus" class="status"></div>
<div class="key">
<div><i class="dot" style="color:#59e0dc;background:#59e0dc"></i>Offshore cue</div>
<div><i class="dot" style="color:#b99cff;background:#b99cff"></i>Beach gradient</div>
<div><i class="dot" style="color:#ff7869;background:#ff7869"></i>Light vector</div>
<div><i class="dot" style="color:#ffd166;background:#ffd166"></i>Combined cue</div>
</div>
<section>
<h2>Reading the scene</h2>
<div class="micro">
The adult female is positioned beside a schematic nest. Small hatchlings
illustrate one selected directional response. Their movement is slowed
and reset only to make the comparison legible.
</div>
<div class="callout">
Do not use this model to select lighting, shielding, or beach-management
measures without local ecological review. Consult current species-specific
recovery guidance and relevant authorities before field decisions.
</div>
</section>
</aside>
<div id="hint">Drag to orbit · Wheel to zoom · Double-click to reset view</div>
<div id="loading">Loading the Three.js shoreline…</div>
<script type="module">
import * as THREE from
'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
// -------------------------------------------------------------------------
// Renderer, camera, and lighting
// -------------------------------------------------------------------------
const canvas = document.querySelector('#scene');
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: 'high-performance'
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071a2b);
scene.fog = new THREE.FogExp2(0x071a2b, 0.013);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
220
);
const cameraState = {
azimuth: 0.48,
elevation: 0.62,
radius: 58,
target: new THREE.Vector3(0, 0, 2)
};
function updateCamera() {
const { azimuth, elevation, radius, target } = cameraState;
const horizontal = Math.cos(elevation) * radius;
camera.position.set(
target.x + Math.sin(azimuth) * horizontal,
target.y + Math.sin(elevation) * radius,
target.z + Math.cos(azimuth) * horizontal
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xaedcff, 0x776046, 2.15);
scene.add(hemisphere);
const moonlight = new THREE.DirectionalLight(0xb3d9ff, 2.55);
moonlight.position.set(-22, 32, -18);
moonlight.castShadow = true;
moonlight.shadow.mapSize.set(1024, 1024);
moonlight.shadow.camera.left = -45;
moonlight.shadow.camera.right = 45;
moonlight.shadow.camera.top = 45;
moonlight.shadow.camera.bottom = -45;
moonlight.shadow.camera.near = 1;
moonlight.shadow.camera.far = 100;
moonlight.shadow.bias = -0.0005;
scene.add(moonlight);
const warmFill = new THREE.DirectionalLight(0xffc487, 0.55);
warmFill.position.set(22, 14, 28);
scene.add(warmFill);
// Deterministic randomness keeps the low-poly scene reproducible.
let randomSeed = 73421;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const nestPosition = new THREE.Vector3(0, 0, 9);
// -------------------------------------------------------------------------
// Height field and low-poly shoreline
// -------------------------------------------------------------------------
function heightAt(x, z) {
const submerged = Math.max(0, -z) * 0.055;
const inlandRise = Math.max(0, z) * 0.018;
const duneRise = Math.max(0, z - 16) * 0.075;
const broadBump =
Math.sin(x * 0.16 + z * 0.08) * 0.13 +
Math.cos(x * 0.27 - z * 0.13) * 0.075;
const edge = Math.max(0, Math.min(1, (z + 3) / 5));
return -submerged + (inlandRise + duneRise + broadBump) * edge + 0.12;
}
const terrainGeometry = new THREE.BufferGeometry();
const terrainPositions = [];
const terrainColors = [];
const terrainIndices = [];
const nx = 30;
const nz = 20;
const wetSand = new THREE.Color(0x8b795b);
const drySand = new THREE.Color(0xc5aa76);
const duneSand = new THREE.Color(0xd5bd89);
for (let iz = 0; iz <= nz; iz++) {
const z = -6 + (iz / nz) * 40;
for (let ix = 0; ix <= nx; ix++) {
const x = -36 + (ix / nx) * 72;
const y = heightAt(x, z);
terrainPositions.push(x, y, z);
const color = drySand.clone();
if (z < 3) color.lerp(wetSand, Math.max(0, 1 - z / 7));
if (z > 17) color.lerp(duneSand, Math.min(1, (z - 17) / 16));
color.multiplyScalar(0.94 + random() * 0.09);
terrainColors.push(color.r, color.g, color.b);
}
}
for (let iz = 0; iz < nz; iz++) {
for (let ix = 0; ix < nx; ix++) {
const a = iz * (nx + 1) + ix;
const b = a + 1;
const c = a + nx + 1;
const d = c + 1;
terrainIndices.push(a, c, b, b, c, d);
}
}
terrainGeometry.setAttribute(
'position',
new THREE.Float32BufferAttribute(terrainPositions, 3)
);
terrainGeometry.setAttribute(
'color',
new THREE.Float32BufferAttribute(terrainColors, 3)
);
terrainGeometry.setIndex(terrainIndices);
terrainGeometry.computeVertexNormals();
const terrain = new THREE.Mesh(
terrainGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.98,
metalness: 0,
flatShading: true
})
);
terrain.receiveShadow = true;
scene.add(terrain);
// Faceted ocean surface.
const oceanGeometry = new THREE.PlaneGeometry(74, 38, 20, 12);
oceanGeometry.rotateX(-Math.PI / 2);
oceanGeometry.translate(0, -0.12, -19);
const oceanColors = [];
const oceanPositions = oceanGeometry.attributes.position;
for (let i = 0; i < oceanPositions.count; i++) {
const x = oceanPositions.getX(i);
const z = oceanPositions.getZ(i);
const color = new THREE.Color(0x0b5365);
color.lerp(new THREE.Color(0x167b83), Math.min(1, (z + 38) / 42));
color.multiplyScalar(0.91 + random() * 0.15);
oceanColors.push(color.r, color.g, color.b);
}
oceanGeometry.setAttribute(
'color',
new THREE.Float32BufferAttribute(oceanColors, 3)
);
const ocean = new THREE.Mesh(
oceanGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.58,
metalness: 0.08,
flatShading: true,
transparent: true,
opacity: 0.92
})
);
ocean.receiveShadow = true;
scene.add(ocean);
// Low-poly foam ribbons.
const foamGroup = new THREE.Group();
scene.add(foamGroup);
const foamMaterial = new THREE.MeshBasicMaterial({
color: 0xd9ffff,
transparent: true,
opacity: 0.46,
depthWrite: false,
side: THREE.DoubleSide
});
for (let i = 0; i < 15; i++) {
const foam = new THREE.Mesh(
new THREE.CircleGeometry(0.5 + random() * 1.25, 3),
foamMaterial
);
foam.rotation.x = -Math.PI / 2;
foam.rotation.z = random() * Math.PI;
foam.position.set(-33 + random() * 66, 0.18, -0.4 + random() * 1.4);
foam.scale.y = 0.18 + random() * 0.22;
foam.userData.phase = random() * Math.PI * 2;
foamGroup.add(foam);
}
// Dunes, rocks, and sparse vegetation.
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x777766,
roughness: 1,
flatShading: true
});
const vegetationMaterial = new THREE.MeshStandardMaterial({
color: 0x4f6041,
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
});
for (let i = 0; i < 13; i++) {
const x = -32 + random() * 64;
const z = 23 + random() * 10;
const rock = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.45 + random() * 1.1, 0),
rockMaterial
);
rock.position.set(x, heightAt(x, z) + 0.25, z);
rock.scale.set(1.3, 0.55 + random() * 0.5, 0.9);
rock.rotation.set(random(), random() * Math.PI, random() * 0.3);
rock.castShadow = true;
scene.add(rock);
}
function createGrassTuft(x, z, scale = 1) {
const group = new THREE.Group();
const bladeGeometry = new THREE.BufferGeometry();
bladeGeometry.setAttribute(
'position',
new THREE.Float32BufferAttribute([
-0.11, 0, 0,
0.11, 0, 0,
0.02, 1.4, 0
], 3)
);
bladeGeometry.computeVertexNormals();
for (let i = 0; i < 4; i++) {
const blade = new THREE.Mesh(bladeGeometry, vegetationMaterial);
blade.rotation.y = (i / 4) * Math.PI * 2 + random() * 0.3;
blade.scale.setScalar(0.7 + random() * 0.35);
group.add(blade);
}
group.position.set(x, heightAt(x, z), z);
group.scale.setScalar(scale);
scene.add(group);
}
for (let i = 0; i < 30; i++) {
createGrassTuft(
-34 + random() * 68,
20 + random() * 13,
0.65 + random() * 0.8
);
}
// Moon and sparse stars.
const moon = new THREE.Mesh(
new THREE.IcosahedronGeometry(3.1, 2),
new THREE.MeshBasicMaterial({ color: 0xe5f1de })
);
moon.position.set(-25, 26, -42);
scene.add(moon);
const starPositions = [];
for (let i = 0; i < 95; i++) {
starPositions.push(
-65 + random() * 130,
16 + random() * 40,
-72 + random() * 62
);
}
const starsGeometry = new THREE.BufferGeometry();
starsGeometry.setAttribute(
'position',
new THREE.Float32BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starsGeometry,
new THREE.PointsMaterial({
color: 0xd9f4ff,
size: 0.18,
transparent: true,
opacity: 0.72
})
);
scene.add(stars);
// -------------------------------------------------------------------------
// Low-poly turtles, nest, and eggs
// -------------------------------------------------------------------------
const shellGeometry = new THREE.IcosahedronGeometry(0.78, 1);
const headGeometry = new THREE.IcosahedronGeometry(0.3, 1);
const flipperGeometry = new THREE.ConeGeometry(0.28, 1.15, 4);
const legGeometry = new THREE.ConeGeometry(0.16, 0.43, 4);
const eyeGeometry = new THREE.IcosahedronGeometry(0.055, 0);
function createTurtle(shellColor = 0x526b45, bellyColor = 0xb7ad72) {
const turtle = new THREE.Group();
const shellMaterial = new THREE.MeshStandardMaterial({
color: shellColor,
roughness: 0.86,
flatShading: true
});
const bellyMaterial = new THREE.MeshStandardMaterial({
color: bellyColor,
roughness: 0.92,
flatShading: true
});
const shell = new THREE.Mesh(shellGeometry, shellMaterial);
shell.position.y = 0.39;
shell.scale.set(1.0, 0.52, 1.22);
shell.castShadow = true;
turtle.add(shell);
const belly = new THREE.Mesh(shellGeometry, bellyMaterial);
belly.position.y = 0.22;
belly.scale.set(0.88, 0.26, 1.04);
turtle.add(belly);
const head = new THREE.Mesh(headGeometry, bellyMaterial);
head.position.set(0, 0.34, -1.03);
head.scale.set(0.9, 0.72, 0.88);
head.castShadow = true;
turtle.add(head);
const eyeMaterial = new THREE.MeshBasicMaterial({ color: 0x081014 });
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(eyeGeometry, eyeMaterial);
eye.position.set(side * 0.17, 0.43, -1.22);
turtle.add(eye);
}
for (const side of [-1, 1]) {
const front = new THREE.Mesh(flipperGeometry, shellMaterial);
front.position.set(side * 0.72, 0.25, -0.57);
front.rotation.set(-Math.PI / 2, 0, side * -0.48);
front.scale.set(0.75, 1.15, 0.38);
front.castShadow = true;
turtle.add(front);
const rear = new THREE.Mesh(flipperGeometry, shellMaterial);
rear.position.set(side * 0.65, 0.2, 0.63);
rear.rotation.set(Math.PI / 2, 0, side * 0.44);
rear.scale.set(0.62, 0.85, 0.34);
rear.castShadow = true;
turtle.add(rear);
const leg = new THREE.Mesh(legGeometry, bellyMaterial);
leg.position.set(side * 0.43, 0.12, -0.18);
leg.rotation.z = side * -0.22;
turtle.add(leg);
}
return turtle;
}
const female = createTurtle(0x596844, 0xc3b57c);
female.position.set(2.6, heightAt(2.6, 12.1) + 0.03, 12.1);
female.rotation.y = -0.26;
female.scale.setScalar(1.18);
scene.add(female);
const pit = new THREE.Mesh(
new THREE.CircleGeometry(1.05, 16),
new THREE.MeshStandardMaterial({
color: 0x4f3e2c,
roughness: 1,
flatShading: true
})
);
pit.rotation.x = -Math.PI / 2;
pit.position.set(nestPosition.x, heightAt(0, 9) + 0.035, nestPosition.z);
scene.add(pit);
const nestRim = new THREE.Mesh(
new THREE.TorusGeometry(1.08, 0.14, 5, 14),
new THREE.MeshStandardMaterial({
color: 0xb89c6d,
roughness: 1,
flatShading: true
})
);
nestRim.rotation.x = Math.PI / 2;
nestRim.position.set(0, heightAt(0, 9) + 0.08, 9);
scene.add(nestRim);
const eggMaterial = new THREE.MeshStandardMaterial({
color: 0xe7d8a8,
roughness: 0.9,
flatShading: true
});
for (let i = 0; i < 18; i++) {
const angle = (i / 18) * Math.PI * 2;
const radius = 0.25 + random() * 0.55;
const egg = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.12, 1),
eggMaterial
);
egg.position.set(
Math.cos(angle) * radius,
heightAt(0, 9) + 0.18,
9 + Math.sin(angle) * radius
);
egg.scale.set(0.83, 1.15, 0.83);
egg.castShadow = true;
scene.add(egg);
}
// -------------------------------------------------------------------------
// Artificial light markers
// -------------------------------------------------------------------------
const markerDefaults = [
{
name: 'A',
enabled: true,
intensity: 90,
bearing: 155,
distance: 18,
color: 'warm'
},
{
name: 'B',
enabled: true,
intensity: 55,
bearing: -165,
distance: 24,
color: 'cool'
},
{
name: 'C',
enabled: true,
intensity: 25,
bearing: 115,
distance: 20,
color: 'neutral'
}
];
const lampColors = {
warm: 0xffb35c,
neutral: 0xffe0b0,
cool: 0xc7e9ff
};
const markers = markerDefaults.map((data) => {
const group = new THREE.Group();
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.07, 0.11, 1.9, 6),
new THREE.MeshStandardMaterial({
color: 0x27383b,
roughness: 0.8,
flatShading: true
})
);
post.position.y = 0.95;
post.castShadow = true;
group.add(post);
const lampMaterial = new THREE.MeshStandardMaterial({
color: lampColors[data.color],
emissive: lampColors[data.color],
emissiveIntensity: 1.2,
roughness: 0.42,
flatShading: true
});
const lamp = new THREE.Mesh(
new THREE.BoxGeometry(0.42, 0.25, 0.32),
lampMaterial
);
lamp.position.y = 2.02;
lamp.castShadow = true;
group.add(lamp);
const glowMaterial = new THREE.MeshBasicMaterial({
color: lampColors[data.color],
transparent: true,
opacity: 0.19,
depthWrite: false
});
const glow = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.58, 1),
glowMaterial
);
glow.position.y = 2.02;
group.add(glow);
const beamMaterial = new THREE.MeshBasicMaterial({
color: lampColors[data.color],
transparent: true,
opacity: 0.08,
depthWrite: false,
side: THREE.DoubleSide
});
const beam = new THREE.Mesh(
new THREE.ConeGeometry(2.6, 2.05, 8, 1, true),
beamMaterial
);
beam.position.y = 1.02;
group.add(beam);
const poolMaterial = new THREE.MeshBasicMaterial({
color: lampColors[data.color],
transparent: true,
opacity: 0.08,
depthWrite: false,
side: THREE.DoubleSide
});
const pool = new THREE.Mesh(
new THREE.CircleGeometry(2.65, 12),
poolMaterial
);
pool.rotation.x = -Math.PI / 2;
pool.position.y = 0.045;
group.add(pool);
const selectionMaterial = new THREE.MeshBasicMaterial({
color: 0x59e0dc,
transparent: true,
opacity: 0.65,
depthWrite: false,
side: THREE.DoubleSide
});
const selectionRing = new THREE.Mesh(
new THREE.RingGeometry(0.38, 0.48, 16),
selectionMaterial
);
selectionRing.rotation.x = -Math.PI / 2;
selectionRing.position.y = 0.055;
group.add(selectionRing);
const light = new THREE.PointLight(
lampColors[data.color],
3,
13,
2
);
light.position.y = 2.05;
group.add(light);
scene.add(group);
return {
...data,
group,
lamp,
lampMaterial,
glow,
glowMaterial,
beamMaterial,
poolMaterial,
selectionRing,
light
};
});
function updateMarkerMeshes() {
markers.forEach((marker, index) => {
const angle = THREE.MathUtils.degToRad(marker.bearing);
const x = nestPosition.x + Math.sin(angle) * marker.distance;
const z = nestPosition.z - Math.cos(angle) * marker.distance;
marker.group.position.set(x, heightAt(x, z) + 0.025, z);
marker.group.visible = marker.enabled;
const color = lampColors[marker.color];
marker.lampMaterial.color.setHex(color);
marker.lampMaterial.emissive.setHex(color);
marker.lampMaterial.emissiveIntensity = 0.35 + marker.intensity / 100 * 2.1;
marker.glowMaterial.color.setHex(color);
marker.glowMaterial.opacity = marker.enabled
? 0.07 + marker.intensity / 100 * 0.20
: 0;
marker.beamMaterial.color.setHex(color);
marker.beamMaterial.opacity = marker.enabled
? 0.015 + marker.intensity / 100 * 0.10
: 0;
marker.poolMaterial.color.setHex(color);
marker.poolMaterial.opacity = marker.enabled
? 0.015 + marker.intensity / 100 * 0.085
: 0;
marker.light.color.setHex(color);
marker.light.intensity = marker.enabled
? 0.5 + marker.intensity / 100 * 5.0
: 0;
marker.selectionRing.visible = index === selectedMarker && marker.enabled;
});
}
// -------------------------------------------------------------------------
// Cue arrows
// -------------------------------------------------------------------------
function createArrow(color) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.92,
depthTest: false,
depthWrite: false
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, 1, 6),
material
);
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.31, 0.72, 7),
material
);
group.add(shaft, head);
group.renderOrder = 8;
scene.add(group);
return { group, shaft, head, material, length: 10 };
}
const arrows = {
offshore: createArrow(0x59e0dc),
gradient: createArrow(0xb99cff),
artificial: createArrow(0xff7869),
reference: createArrow(0xffd166),
combined: createArrow(0xffd166)
};
const up = new THREE.Vector3(0, 1, 0);
function setArrow(arrow, direction, length, visible = true) {
arrow.group.visible = visible && !!direction;
if (!direction) return;
direction = direction.clone().normalize();
arrow.length = length;
arrow.group.quaternion.setFromUnitVectors(up, direction);
const shaftLength = Math.max(0.1, length - 0.66);
arrow.shaft.scale.set(1, shaftLength, 1);
arrow.shaft.position.y = shaftLength / 2;
arrow.head.position.y = length - 0.33;
}
// -------------------------------------------------------------------------
// Labels
// -------------------------------------------------------------------------
const labelsLayer = document.querySelector('#labels');
const labelRecords = [];
function addLabel(text, className = '', getPosition = () => new THREE.Vector3()) {
const element = document.createElement('div');
element.className = `scene-label ${className}`;
element.textContent = text;
labelsLayer.appendChild(element);
const record = { element, getPosition };
labelRecords.push(record);
return record;
}
addLabel(
'NEST',
'important',
() => new THREE.Vector3(0, heightAt(0, 9) + 0.5, 9)
);
addLabel(
'SEA · seaward',
'',
() => new THREE.Vector3(-8, 0.9, -7)
);
addLabel(
'NESTING FEMALE',
'',
() => new THREE.Vector3(2.6, heightAt(2.6, 12.1) + 1.5, 12.1)
);
addLabel(
'SHORELINE',
'',
() => new THREE.Vector3(-17, 0.7, 0)
);
const markerLabels = markers.map((marker) =>
addLabel(
`LIGHT ${marker.name}`,
'important',
() => marker.group.position.clone().add(new THREE.Vector3(0, 2.8, 0))
)
);
const cueLabels = {
offshore: addLabel(
'OFFSHORE',
'',
() => arrowEndpoint(arrows.offshore, new THREE.Vector3(-0.45, 0, 0))
),
gradient: addLabel(
'BEACH GRADIENT',
'',
() => arrowEndpoint(arrows.gradient, new THREE.Vector3(0.45, 0, 0))
),
artificial: addLabel(
'ARTIFICIAL LIGHT',
'',
() => arrowEndpoint(arrows.artificial, new THREE.Vector3(0, 0, 0))
),
reference: addLabel(
'REFERENCE CUE',
'',
() => arrowEndpoint(arrows.reference, new THREE.Vector3(-0.25, 0, 0))
),
combined: addLabel(
'COMBINED',
'important',
() => arrowEndpoint(arrows.combined, new THREE.Vector3(0, 0, 0))
)
};
function arrowEndpoint(arrow, offset) {
const direction = new THREE.Vector3(0, 0, -1).applyQuaternion(arrow.group.quaternion);
return nestPosition.clone()
.add(offset)
.addScaledVector(direction, arrow.length)
.add(new THREE.Vector3(0, 0.55, 0));
}
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const record of labelRecords) {
const world = record.getPosition();
const projected = world.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
if (!visible) {
record.element.style.opacity = '0';
continue;
}
record.element.style.opacity = '1';
record.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
record.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// -------------------------------------------------------------------------
// Directional model
// -------------------------------------------------------------------------
const seawardDirection = new THREE.Vector3(0, 0, -1);
function directionFromBearing(degrees) {
const angle = THREE.MathUtils.degToRad(degrees);
return new THREE.Vector3(Math.sin(angle), 0, -Math.cos(angle));
}
function normalizedAngle(degrees) {
return ((degrees + 180) % 360 + 360) % 360 - 180;
}
function headingFromDirection(direction) {
if (!direction) return null;
return normalizedAngle(
THREE.MathUtils.radToDeg(Math.atan2(direction.x, -direction.z))
);
}
function gradientDirection() {
const x = nestPosition.x;
const z = nestPosition.z;
const dx = (heightAt(x + 0.6, z) - heightAt(x - 0.6, z)) / 1.2;
const dz = (heightAt(x, z + 0.6) - heightAt(x, z - 0.6)) / 1.2;
return new THREE.Vector3(-dx, 0, -dz).normalize();
}
function artificialDirection() {
const result = new THREE.Vector3();
let totalWeight = 0;
for (const marker of markers) {
if (!marker.enabled || marker.intensity <= 0) continue;
const angle = THREE.MathUtils.degToRad(marker.bearing);
const direction = new THREE.Vector3(
Math.sin(angle),
0,
-Math.cos(angle)
);
const weight =
(marker.intensity / 100) *
(20 / Math.max(8, marker.distance));
result.addScaledVector(direction, weight);
totalWeight += weight;
}
if (totalWeight < 0.0001) return null;
return result.normalize();
}
function artificialBrightness() {
return markers.reduce((sum, marker) => {
if (!marker.enabled) return sum;
return sum +
(marker.intensity / 100) *
(20 / Math.max(8, marker.distance));
}, 0);
}
const cueState = {
offshore: seawardDirection.clone(),
gradient: gradientDirection(),
artificial: artificialDirection(),
reference: directionFromBearing(0),
combined: null
};
function computeCombinedDirection() {
const sum = new THREE.Vector3();
if (document.querySelector('#cueOffshore').checked) {
sum.addScaledVector(cueState.offshore, 1.0);
}
if (document.querySelector('#cueGradient').checked) {
sum.addScaledVector(cueState.gradient, 0.75);
}
if (document.querySelector('#cueArtificial').checked && cueState.artificial) {
sum.addScaledVector(
cueState.artificial,
Math.min(1.5, artificialBrightness())
);
}
if (document.querySelector('#cueReference').checked) {
sum.addScaledVector(cueState.reference, 1.0);
}
return sum.lengthSq() > 0.00001 ? sum.normalize() : null;
}
function alignmentText(heading) {
if (heading === null) return '—';
const difference = Math.abs(normalizedAngle(heading));
if (difference < 1) return 'aligned';
return `${Math.round(difference)}° off`;
}
function updateReadout() {
document.querySelector('#offshoreHeading').textContent =
`${Math.round(cueState.offshoreHeading ?? headingFromDirection(cueState.offshore))}°`;
document.querySelector('#offshoreAlignment').textContent =
alignmentText(headingFromDirection(cueState.offshore));
const gradientHeading = headingFromDirection(cueState.gradient);
document.querySelector('#gradientHeading').textContent =
`${Math.round(gradientHeading)}°`;
document.querySelector('#gradientAlignment').textContent =
alignmentText(gradientHeading);
const artificialHeading = headingFromDirection(cueState.artificial);
document.querySelector('#artificialHeading').textContent =
artificialHeading === null ? '—' : `${Math.round(artificialHeading)}°`;
document.querySelector('#artificialAlignment').textContent =
alignmentText(artificialHeading);
const referenceHeading = headingFromDirection(cueState.reference);
document.querySelector('#referenceHeading').textContent =
document.querySelector('#cueReference').checked
? `${Math.round(referenceHeading)}°`
: '—';
document.querySelector('#referenceAlignment').textContent =
document.querySelector('#cueReference').checked
? alignmentText(referenceHeading)
: '—';
const combinedHeading = headingFromDirection(cueState.combined);
document.querySelector('#combinedHeading').textContent =
combinedHeading === null ? '—' : `${Math.round(combinedHeading)}°`;
document.querySelector('#combinedAlignment').textContent =
alignmentText(combinedHeading);
const status = document.querySelector('#modelStatus');
if (artificialHeading !== null) {
const artificialDifference = Math.abs(normalizedAngle(artificialHeading));
const combinedDifference = combinedHeading === null
? null
: Math.abs(normalizedAngle(combinedHeading));
status.innerHTML =
`<strong>Conceptual contrast:</strong> the artificial-light vector is ` +
`${Math.round(artificialDifference)}° from seaward. ` +
(combinedDifference === null
? 'The enabled cues do not define a stable combined direction.'
: `The combined vector is ${Math.round(combinedDifference)}° from seaward.`) +
` This illustrates cue competition, not a measured response or risk threshold.`;
} else {
status.innerHTML =
`<strong>Conceptual contrast:</strong> no active lamp contributes a ` +
`light vector. Remaining arrows are schematic cue inputs, not validated ` +
`species-specific orientation rules.`;
}
}
function updateCues() {
cueState.offshore = seawardDirection.clone();
cueState.gradient = gradientDirection();
cueState.artificial = artificialDirection();
const referenceBearing = Number(
document.querySelector('#referenceBearing').value
);
cueState.reference = directionFromBearing(referenceBearing);
cueState.combined = computeCombinedDirection();
const offshoreVisible =
document.querySelector('#cueOffshore').checked && cueState.offshore;
const gradientVisible =
document.querySelector('#cueGradient').checked && cueState.gradient;
const artificialVisible =
document.querySelector('#cueArtificial').checked && cueState.artificial;
const referenceVisible =
document.querySelector('#cueReference').checked && cueState.reference;
setArrow(arrows.offshore, cueState.offshore, 10.8, offshoreVisible);
setArrow(arrows.gradient, cueState.gradient, 9.4, gradientVisible);
setArrow(arrows.artificial, cueState.artificial, 8.4, artificialVisible);
setArrow(arrows.reference, cueState.reference, 11.3, referenceVisible);
setArrow(arrows.combined, cueState.combined, 12.4, !!cueState.combined);
arrows.offshore.group.position.set(-0.45, 0.62, 0);
arrows.gradient.group.position.set(0.45, 0.69, 0);
arrows.artificial.group.position.set(0, 0.76, 0);
arrows.reference.group.position.set(-0.22, 0.83, 0);
arrows.combined.group.position.set(0, 0.92, 0);
cueLabels.offshore.element.style.opacity = '';
updateReadout();
}
// -------------------------------------------------------------------------
// Hatchlings
// -------------------------------------------------------------------------
const hatchlings = [];
for (let i = 0; i < 11; i++) {
const hatchling = createTurtle(
i % 2 ? 0x536b42 : 0x64764a,
0xc3b77d
);
hatchling.scale.setScalar(0.31);
const angle = random() * Math.PI * 2;
const radius = 0.45 + random() * 1.35;
const x = Math.cos(angle) * radius;
const z = 9 + Math.sin(angle) * radius;
hatchling.position.set(x, heightAt(x, z) + 0.04, z);
hatchling.userData.speed = 0.34 + random() * 0.24;
hatchling.userData.phase = random() * Math.PI * 2;
scene.add(hatchling);
hatchlings.push(hatchling);
}
function followDirection() {
const mode = document.querySelector('#followMode').value;
if (mode === 'artificial') return cueState.artificial;
if (mode === 'offshore') return cueState.offshore;
if (mode === 'reference') {
return document.querySelector('#cueReference').checked
? cueState.reference
: cueState.offshore;
}
return cueState.combined || cueState.offshore;
}
function resetHatchling(hatchling) {
const angle = random() * Math.PI * 2;
const radius = 0.35 + random() * 1.1;
const x = Math.cos(angle) * radius;
const z = 9 + Math.sin(angle) * radius;
hatchling.position.set(x, heightAt(x, z) + 0.04, z);
}
let playing = true;
let animationTime = 0;
function updateHatchlings(delta) {
const direction = followDirection();
if (!direction) return;
for (const hatchling of hatchlings) {
const speed =
hatchling.userData.speed *
(0.82 + Math.sin(animationTime * 1.4 + hatchling.userData.phase) * 0.18);
hatchling.position.x += direction.x * speed * delta;
hatchling.position.z += direction.z * speed * delta;
if (
hatchling.position.z < -4 ||
hatchling.position.z > 31 ||
Math.abs(hatchling.position.x) > 32
) {
resetHatchling(hatchling);
}
hatchling.position.y = heightAt(
hatchling.position.x,
hatchling.position.z
) + 0.04;
hatchling.rotation.y = Math.atan2(-direction.x, -direction.z);
}
}
// -------------------------------------------------------------------------
// Interface bindings
// -------------------------------------------------------------------------
let selectedMarker = 0;
const markerTabs = [...document.querySelectorAll('.marker-tab')];
const enabledInput = document.querySelector('#markerEnabled');
const intensityInput = document.querySelector('#markerIntensity');
const bearingInput = document.querySelector('#markerBearing');
const distanceInput = document.querySelector('#markerDistance');
const colorInput = document.querySelector('#markerColor');
function refreshMarkerControls() {
const marker = markers[selectedMarker];
markerTabs.forEach((tab, index) => {
tab.classList.toggle('active', index === selectedMarker);
});
enabledInput.checked = marker.enabled;
intensityInput.value = marker.intensity;
bearingInput.value = marker.bearing;
distanceInput.value = marker.distance;
colorInput.value = marker.color;
document.querySelector('#markerIntensityValue').textContent =
`${marker.intensity}%`;
document.querySelector('#markerBearingValue').textContent =
`${marker.bearing > 0 ? '+' : ''}${marker.bearing}°`;
document.querySelector('#markerDistanceValue').textContent =
`${marker.distance} m`;
updateMarkerMeshes();
updateCues();
}
markerTabs.forEach((tab) => {
tab.addEventListener('click', () => {
selectedMarker = Number(tab.dataset.marker);
refreshMarkerControls();
});
});
enabledInput.addEventListener('change', () => {
markers[selectedMarker].enabled = enabledInput.checked;
refreshMarkerControls();
});
intensityInput.addEventListener('input', () => {
markers[selectedMarker].intensity = Number(intensityInput.value);
refreshMarkerControls();
});
bearingInput.addEventListener('input', () => {
markers[selectedMarker].bearing = Number(bearingInput.value);
refreshMarkerControls();
});
distanceInput.addEventListener('input', () => {
markers[selectedMarker].distance = Number(distanceInput.value);
refreshMarkerControls();
});
colorInput.addEventListener('change', () => {
markers[selectedMarker].color = colorInput.value;
refreshMarkerControls();
});
document.querySelector('#allLightsOff').addEventListener('click', () => {
markers.forEach((marker) => {
marker.enabled = false;
marker.intensity = 0;
});
refreshMarkerControls();
});
document.querySelector('#resetLights').addEventListener('click', () => {
markers.forEach((marker, index) => {
Object.assign(marker, markerDefaults[index]);
});
refreshMarkerControls();
});
['cueOffshore', 'cueGradient', 'cueArtificial', 'cueReference'].forEach((id) => {
document.querySelector(`#${id}`).addEventListener('change', updateCues);
});
document.querySelector('#referenceBearing').addEventListener('input', () => {
const value = Number(document.querySelector('#referenceBearing').value);
document.querySelector('#referenceBearingValue').textContent =
`${value > 0 ? '+' : ''}${value}°`;
updateCues();
});
document.querySelector('#followMode').addEventListener('change', () => {
hatchlings.forEach(resetHatchling);
});
document.querySelector('#playPause').addEventListener('click', (event) => {
playing = !playing;
event.currentTarget.textContent = playing ? 'Pause motion' : 'Resume motion';
});
function resetView() {
cameraState.azimuth = 0.48;
cameraState.elevation = 0.62;
cameraState.radius = 58;
cameraState.target.set(0, 0, 2);
updateCamera();
}
document.querySelector('#resetView').addEventListener('click', resetView);
// -------------------------------------------------------------------------
// Direct camera controls — no addons or example modules
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener('pointerdown', (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.classList.add('dragging');
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener('pointermove', (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.azimuth -= deltaX * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + deltaY * 0.0045,
0.24,
1.25
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove('dragging');
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener('pointerup', stopDragging);
canvas.addEventListener('pointercancel', stopDragging);
canvas.addEventListener('wheel', (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.035,
24,
88
);
updateCamera();
}, { passive: false });
canvas.addEventListener('dblclick', resetView);
canvas.addEventListener('contextmenu', (event) => event.preventDefault());
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let frame = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
animationTime += delta;
updateHatchlings(delta);
}
// Gentle faceted ocean motion.
const oceanPositionsAttribute = oceanGeometry.attributes.position;
for (let i = 0; i < oceanPositionsAttribute.count; i++) {
const x = oceanPositionsAttribute.getX(i);
const z = oceanPositionsAttribute.getZ(i);
const y =
-0.12 +
Math.sin(x * 0.28 + animationTime * 0.72 + z * 0.12) * 0.065 +
Math.cos(z * 0.4 - animationTime * 0.46) * 0.035;
oceanPositionsAttribute.setY(i, y);
}
oceanPositionsAttribute.needsUpdate = true;
foamGroup.children.forEach((foam, index) => {
foam.position.x += Math.sin(animationTime * 0.35 + foam.userData.phase) * 0.004;
foam.material.opacity = 0.39 + Math.sin(animationTime * 1.1 + index) * 0.08;
});
markers.forEach((marker) => {
marker.glow.scale.setScalar(
1 + Math.sin(animationTime * 2.1 + marker.bearing) * 0.045
);
});
frame++;
if (frame % 2 === 0) updateLabels();
renderer.render(scene, camera);
}
refreshMarkerControls();
updateLabels();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.querySelector('#loading').classList.add('hidden');
});
</script>
</body>
</html>
```