Prompt specification
Build or customize the Three.js 3D scene "Two-Person Rowing Coordination Scene" 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: Two-Person Rowing Coordination Scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-person-rowing-coordination-scene-x3643
Scene Description Prompt:
Compare two voxel rowers using synchronized and offset strokes, with visible phase markers and a simplified boat-motion rule. Three.js from cdnjs, one HTML file.
Working Three.js Starter (two-person-rowing-coordination-scene-x3643):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Stroke Lab — Synchronized vs Offset</title>
<style>
:root {
--bg: #071923;
--panel: rgba(8, 25, 35, 0.82);
--line: rgba(171, 221, 235, 0.18);
--text: #e8f8fb;
--muted: #8fb1bc;
--sync: #59e1f2;
--offset: #ff8b72;
--drive: #d9fff1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 10;
pointer-events: none;
}
.panel {
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 16px 44px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-panel {
top: 20px;
left: 20px;
width: min(460px, calc(100vw - 40px));
padding: 17px 19px;
border-radius: 16px;
}
.eyebrow {
margin-bottom: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.5vw, 31px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 7px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.crew-grid {
top: 20px;
right: 20px;
display: grid;
grid-template-columns: repeat(2, minmax(260px, 310px));
gap: 12px;
}
.crew-card {
position: relative;
overflow: hidden;
padding: 15px;
border-radius: 16px;
}
.crew-card::before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 3px;
background: var(--crew-color);
content: "";
box-shadow: 0 0 18px color-mix(in srgb, var(--crew-color), transparent 45%);
}
.crew-card.sync {
--crew-color: var(--sync);
}
.crew-card.offset {
--crew-color: var(--offset);
}
.crew-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
}
.crew-heading h2 {
margin: 0;
font-size: 17px;
letter-spacing: -0.02em;
}
.crew-heading p {
margin: 3px 0 0;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.status {
flex: none;
padding: 5px 7px;
border: 1px solid color-mix(in srgb, var(--crew-color), transparent 60%);
border-radius: 999px;
color: var(--crew-color);
background: color-mix(in srgb, var(--crew-color), transparent 92%);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin: 13px 0 12px;
}
.metric {
min-width: 0;
padding: 8px 9px;
border: 1px solid rgba(255, 255, 255, 0.065);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.metric-label {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-value {
display: block;
overflow: hidden;
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 16px;
font-weight: 750;
text-overflow: ellipsis;
white-space: nowrap;
}
.metric-value small {
color: var(--muted);
font-size: 9px;
font-weight: 600;
}
.phase-row {
display: grid;
grid-template-columns: 45px 1fr 34px;
align-items: center;
gap: 8px;
margin-top: 8px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.phase-track {
position: relative;
height: 9px;
overflow: visible;
border-radius: 999px;
background:
linear-gradient(
90deg,
transparent 0 8%,
rgba(217, 255, 241, 0.27) 8% 50%,
transparent 50% 92%,
rgba(255, 255, 255, 0.07) 92% 100%
);
}
.drive-zone {
position: absolute;
top: 1px;
bottom: 1px;
left: 8%;
width: 42%;
border-radius: 999px;
background: color-mix(in srgb, var(--crew-color), transparent 30%);
opacity: 0.55;
}
.phase-marker {
position: absolute;
top: 50%;
width: 8px;
height: 15px;
border: 2px solid #071923;
border-radius: 4px;
background: var(--crew-color);
box-shadow: 0 0 9px var(--crew-color);
transform: translate(-50%, -50%);
}
.phase-value {
text-align: right;
}
.rule-panel {
bottom: 20px;
left: 20px;
width: min(520px, calc(100vw - 40px));
padding: 14px 16px;
border-radius: 15px;
}
.rule-title {
margin-bottom: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.formula {
color: #dfffff;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
line-height: 1.5;
}
.rule-copy {
margin-top: 6px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.controls {
right: 20px;
bottom: 20px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
pointer-events: auto;
}
.controls button {
min-height: 36px;
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--text);
background: rgba(8, 25, 35, 0.88);
cursor: pointer;
font-size: 11px;
font-weight: 700;
transition: border-color 150ms, background 150ms, transform 150ms;
}
.controls button:hover {
border-color: rgba(171, 221, 235, 0.42);
background: rgba(18, 48, 60, 0.95);
transform: translateY(-1px);
}
.controls button.primary {
border-color: rgba(89, 225, 242, 0.4);
color: var(--sync);
}
.camera-hint {
right: 20px;
bottom: 69px;
color: rgba(207, 231, 237, 0.55);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
letter-spacing: 0.04em;
}
.race-readout {
left: 50%;
bottom: 22px;
padding: 7px 11px;
border-radius: 999px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
transform: translateX(-50%);
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
color: var(--muted);
background: var(--bg);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
letter-spacing: 0.08em;
transition: opacity 250ms;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.title-panel {
width: calc(100vw - 40px);
}
.crew-grid {
top: 160px;
right: 20px;
left: 20px;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.rule-panel {
display: none;
}
.race-readout {
bottom: 76px;
}
}
@media (max-width: 590px) {
.crew-grid {
grid-template-columns: 1fr;
top: 154px;
}
.crew-card {
padding: 11px 13px;
}
.crew-card.offset {
display: none;
}
.camera-hint {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
justify-content: center;
}
.race-readout {
bottom: 65px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="hud panel title-panel">
<div class="eyebrow">Voxel Motion Study / 02</div>
<h1>Stroke Phase Lab</h1>
<div class="subtitle">
Compare equal mean stroke effort with synchronized and 180°-offset timing.
</div>
</header>
<section class="hud crew-grid">
<article class="hud panel crew-card sync" id="sync-card">
<div class="crew-heading">
<div>
<h2>Synchronized Crew</h2>
<p>Both rowers share one phase</p>
</div>
<span class="status" id="sync-status">RUNNING</span>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Speed</span>
<span class="metric-value"><span id="sync-speed">0.00</span> <small>m/s</small></span>
</div>
<div class="metric">
<span class="metric-label">Distance</span>
<span class="metric-value"><span id="sync-distance">0.0</span> <small>m</small></span>
</div>
<div class="metric">
<span class="metric-label">Drive</span>
<span class="metric-value"><span id="sync-thrust">0</span> <small>N</small></span>
</div>
</div>
<div class="phase-row">
<span>ROWER A</span>
<div class="phase-track">
<div class="drive-zone"></div>
<div class="phase-marker" id="sync-phase-0"></div>
</div>
<span class="phase-value" id="sync-phase-value-0">0%</span>
</div>
<div class="phase-row">
<span>ROWER B</span>
<div class="phase-track">
<div class="drive-zone"></div>
<div class="phase-marker" id="sync-phase-1"></div>
</div>
<span class="phase-value" id="sync-phase-value-1">0%</span>
</div>
</article>
<article class="hud panel crew-card offset" id="offset-card">
<div class="crew-heading">
<div>
<h2>Offset Crew</h2>
<p>Rowers are separated by 180°</p>
</div>
<span class="status" id="offset-status">RUNNING</span>
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Speed</span>
<span class="metric-value"><span id="offset-speed">0.00</span> <small>m/s</small></span>
</div>
<div class="metric">
<span class="metric-label">Distance</span>
<span class="metric-value"><span id="offset-distance">0.0</span> <small>m</small></span>
</div>
<div class="metric">
<span class="metric-label">Drive</span>
<span class="metric-value"><span id="offset-thrust">0</span> <small>N</small></span>
</div>
</div>
<div class="phase-row">
<span>ROWER A</span>
<div class="phase-track">
<div class="drive-zone"></div>
<div class="phase-marker" id="offset-phase-0"></div>
</div>
<span class="phase-value" id="offset-phase-value-0">0%</span>
</div>
<div class="phase-row">
<span>ROWER B</span>
<div class="phase-track">
<div class="drive-zone"></div>
<div class="phase-marker" id="offset-phase-1"></div>
</div>
<span class="phase-value" id="offset-phase-value-1">50%</span>
</div>
</article>
</section>
<aside class="hud panel rule-panel">
<div class="rule-title">Simplified boat-motion rule</div>
<div class="formula">
a = [ΣF<sub>drive</sub> − (1.8v + 0.55v²)] / 100
</div>
<div class="rule-copy">
Each rower contributes up to 15 N during the drive. Linear and quadratic drag
smooth the hull response. Synchronization creates larger force pulses;
offset timing distributes thrust more evenly.
</div>
</aside>
<div class="hud race-readout" id="race-readout">
T 0.0 s · LEAD 0.00 m
</div>
<div class="hud camera-hint">
DRAG TO ORBIT · WHEEL TO ZOOM · DOUBLE-CLICK TO RESET VIEW
</div>
<nav class="hud controls">
<button class="primary" id="pause-button">Pause</button>
<button id="speed-button">Speed 1×</button>
<button id="reset-button">Reset race</button>
<button id="camera-button">Reset camera</button>
</nav>
<div id="loading">BUILDING VOXEL CREWS…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("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;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071923);
scene.fog = new THREE.Fog(0x071923, 22, 62);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
140
);
const hemiLight = new THREE.HemisphereLight(0xbfefff, 0x17313b, 2.0);
scene.add(hemiLight);
const sun = new THREE.DirectionalLight(0xffffff, 3.2);
sun.position.set(-8, 17, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x4fd9ef, 1.25);
rimLight.position.set(12, 5, -13);
scene.add(rimLight);
const START_X = -7;
const FINISH_X = 8;
const RACE_DISTANCE = FINISH_X - START_X;
const CYCLE_SECONDS = 2.2;
const MASS = 100;
const MAX_ROWER_FORCE = 15;
const palette = {
water: 0x0a3442,
waterDark: 0x082631,
foam: 0xb7eaf0,
hull: 0x183b48,
hullDark: 0x0d2732,
cockpit: 0x071c25,
skin: 0xd8a783,
skinDark: 0xa96e50,
shorts: 0x102b39,
shoe: 0xe2f1f1,
sync: 0x59e1f2,
offset: 0xff8b72
};
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.06,
flatShading: true,
...options
});
const materials = {
water: material(palette.water, {
roughness: 0.28,
metalness: 0.18
}),
hull: material(palette.hull),
hullDark: material(palette.hullDark),
cockpit: material(palette.cockpit, { roughness: 0.95 }),
skin: material(palette.skin),
skinDark: material(palette.skinDark),
shorts: material(palette.shorts),
shoe: material(palette.shoe),
sync: material(palette.sync, {
roughness: 0.38,
metalness: 0.12,
emissive: 0x0a3038,
emissiveIntensity: 0.35
}),
offset: material(palette.offset, {
roughness: 0.38,
metalness: 0.12,
emissive: 0x35140d,
emissiveIntensity: 0.35
}),
ring: material(0xa9dce4, {
transparent: true,
opacity: 0.42,
roughness: 1
})
};
const yAxis = new THREE.Vector3(0, 1, 0);
function addBox(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), mat);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeBeam(parent, width, mat) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, 1, width), mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function updateBeam(mesh, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.scale.y = Math.max(length, 0.0001);
mesh.quaternion.setFromUnitVectors(yAxis, direction.normalize());
}
function makeLabelSprite(text, color) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(7, 25, 35, 0.88)";
context.fillRect(0, 10, canvas.width, 76);
context.strokeStyle = color;
context.lineWidth = 4;
context.strokeRect(2, 12, canvas.width - 4, 72);
context.fillStyle = color;
context.font = "800 30px ui-monospace, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(2.65, 0.5, 1);
sprite.renderOrder = 20;
return sprite;
}
// -------------------------------------------------------------------------
// Water, lane markers, start and finish gates
// -------------------------------------------------------------------------
const water = new THREE.Mesh(
new THREE.PlaneGeometry(90, 60),
materials.water
);
water.rotation.x = -Math.PI / 2;
water.position.set(2, 0, 0);
water.receiveShadow = true;
scene.add(water);
const laneZ = [-2.7, 2.7];
const laneLineMaterial = new THREE.LineDashedMaterial({
color: 0x8ccbd6,
transparent: true,
opacity: 0.26,
dashSize: 0.42,
gapSize: 0.34
});
const dashMaterial = new THREE.MeshBasicMaterial({
color: 0x9edbe2,
transparent: true,
opacity: 0.16,
depthWrite: false
});
const buoyMaterial = material(0x9bdce1, {
emissive: 0x153a40,
emissiveIntensity: 0.2
});
for (const z of laneZ) {
for (const side of [-1, 1]) {
const points = [
new THREE.Vector3(-12, 0.035, z + side * 1.35),
new THREE.Vector3(14, 0.035, z + side * 1.35)
];
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
laneLineMaterial
);
line.computeLineDistances();
scene.add(line);
}
for (let x = -11; x <= 13; x += 1) {
addBox(
scene,
[0.035, 0.012, 0.38],
[x, 0.025, z],
dashMaterial,
false
);
}
for (let x = -10; x <= 12; x += 3) {
addBox(scene, [0.18, 0.18, 0.18], [x, 0.09, z - 1.35], buoyMaterial);
addBox(scene, [0.18, 0.18, 0.18], [x, 0.09, z + 1.35], buoyMaterial);
}
// Finish gate.
const gateMaterial = material(
z < 0 ? palette.sync : palette.offset,
{ emissive: 0x15333a, emissiveIntensity: 0.25 }
);
addBox(scene, [0.13, 1.55, 0.13], [FINISH_X, 0.78, z - 1.18], gateMaterial);
addBox(scene, [0.13, 1.55, 0.13], [FINISH_X, 0.78, z + 1.18], gateMaterial);
addBox(scene, [0.13, 0.13, 2.5], [FINISH_X, 1.5, z], gateMaterial);
// Start posts.
addBox(scene, [0.1, 0.72, 0.1], [START_X, 0.36, z - 1.18], buoyMaterial);
addBox(scene, [0.1, 0.72, 0.1], [START_X, 0.36, z + 1.18], buoyMaterial);
}
const startLabel = makeLabelSprite("START 0 m", "#b9e9ee");
startLabel.position.set(START_X, 1.65, 0);
startLabel.scale.set(2.3, 0.43, 1);
scene.add(startLabel);
const finishLabel = makeLabelSprite("FINISH 15 m", "#f2fbfc");
finishLabel.position.set(FINISH_X, 2.0, 0);
finishLabel.scale.set(2.3, 0.43, 1);
scene.add(finishLabel);
// Small static water glints.
const glintMaterial = new THREE.MeshBasicMaterial({
color: 0x86cbd4,
transparent: true,
opacity: 0.07,
depthWrite: false
});
const glintMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.7, 0.012, 0.045),
glintMaterial,
130
);
const dummy = new THREE.Object3D();
let glintSeed = 9137;
function seededRandom() {
glintSeed = (glintSeed * 16807) % 2147483647;
return (glintSeed - 1) / 2147483646;
}
for (let i = 0; i < 130; i++) {
dummy.position.set(
-18 + seededRandom() * 46,
0.015,
-11 + seededRandom() * 22
);
dummy.rotation.y = seededRandom() * Math.PI;
dummy.scale.x = 0.5 + seededRandom() * 1.8;
dummy.updateMatrix();
glintMesh.setMatrixAt(i, dummy.matrix);
}
scene.add(glintMesh);
// -------------------------------------------------------------------------
// Voxel rower construction
// -------------------------------------------------------------------------
function createPhaseWheel(parent, accentMaterial) {
const group = new THREE.Group();
group.position.set(0, 2.27, 0);
parent.add(group);
const radius = 0.31;
for (let i = 0; i < 24; i++) {
const angle = (i / 24) * Math.PI * 2;
const block = addBox(
group,
[0.065, 0.065, 0.055],
[Math.cos(angle) * radius, Math.sin(angle) * radius, 0],
materials.ring,
false
);
block.rotation.z = angle;
}
addBox(
group,
[0.035, 0.42, 0.035],
[0, -0.48, 0],
materials.ring,
false
);
const marker = addBox(
group,
[0.14, 0.14, 0.11],
[radius, 0, 0.035],
accentMaterial,
false
);
return { group, marker, radius };
}
function createRower(boatRoot, rowerIndex, accentMaterial) {
const root = new THREE.Group();
root.position.x = rowerIndex === 0 ? -0.73 : 0.78;
boatRoot.add(root);
const skinMaterial =
rowerIndex === 0 ? materials.skin : materials.skinDark;
const body = new THREE.Group();
root.add(body);
addBox(body, [0.43, 0.28, 0.5], [0, 0.78, 0], materials.shorts);
const upper = new THREE.Group();
upper.position.y = 0.88;
body.add(upper);
addBox(upper, [0.42, 0.65, 0.54], [-0.08, 0.32, 0], accentMaterial);
addBox(upper, [0.35, 0.35, 0.36], [-0.13, 0.81, 0], skinMaterial);
addBox(upper, [0.37, 0.1, 0.38], [-0.12, 0.99, 0], materials.hullDark);
addBox(
upper,
[0.055, 0.13, 0.33],
[-0.32, 0.83, 0],
materials.hullDark,
false
);
const legs = [];
const arms = [];
const hands = [];
const oars = [];
for (const side of [-1, 1]) {
const upperLeg = makeBeam(root, 0.15, materials.skin);
const lowerLeg = makeBeam(root, 0.13, materials.skin);
legs.push({ upperLeg, lowerLeg, side });
const arm = makeBeam(root, 0.105, skinMaterial);
const hand = addBox(
root,
[0.13, 0.13, 0.13],
[0, 0, 0],
skinMaterial,
false
);
arms.push(arm);
hands.push(hand);
const pivot = new THREE.Group();
pivot.position.set(0.05, 1.0, 0);
root.add(pivot);
const shaft = makeBeam(pivot, 0.055, materials.hullDark);
const blade = addBox(
pivot,
[0.38, 0.105, 0.36],
[0, 0, 0],
accentMaterial
);
const bladeTip = addBox(
pivot,
[0.1, 0.11, 0.37],
[0, 0, 0],
materials.hullDark
);
oars.push({ pivot, shaft, blade, bladeTip, side });
// Fixed foot and shoe.
addBox(
root,
[0.34, 0.12, 0.18],
[-0.61, 0.57, side * 0.17],
materials.shoe
);
}
const phaseWheel = createPhaseWheel(root, accentMaterial);
return {
root,
body,
upper,
legs,
arms,
hands,
oars,
phaseWheel
};
}
function createCrew(id, z, accentColor, offsets) {
const root = new THREE.Group();
root.position.set(START_X, 0, z);
scene.add(root);
const accentMaterial = material(accentColor, {
roughness: 0.4,
metalness: 0.1,
emissive: accentColor,
emissiveIntensity: 0.07
});
// Voxel shell: broad center, stepped bow and stern.
addBox(root, [4.25, 0.27, 1.0], [0, 0.23, 0], materials.hull);
addBox(root, [0.72, 0.22, 0.73], [2.36, 0.22, 0], accentMaterial);
addBox(root, [0.46, 0.19, 0.56], [2.86, 0.2, 0], materials.hull);
addBox(root, [0.62, 0.21, 0.68], [-2.32, 0.22, 0], materials.hullDark);
addBox(root, [3.72, 0.08, 0.65], [0, 0.395, 0], materials.cockpit);
for (const side of [-1, 1]) {
addBox(root, [4.35, 0.11, 0.09], [0, 0.43, side * 0.55], accentMaterial);
addBox(root, [3.7, 0.08, 0.08], [0, 0.27, side * 0.53], materials.hullDark);
}
// Seats and riggers.
for (const x of [-0.73, 0.78]) {
addBox(root, [0.36, 0.11, 0.57], [x, 0.5, 0], materials.hullDark);
addBox(root, [0.08, 0.28, 0.9], [x + 0.34, 0.78, 0], materials.hullDark);
}
const rowers = [
createRower(root, 0, accentMaterial),
createRower(root, 1, accentMaterial)
];
const label = makeLabelSprite(
id === "sync" ? "SYNC / 0°" : "OFFSET / 180°",
accentColor === palette.sync ? "#59e1f2" : "#ff8b72"
);
label.position.set(0, 2.96, 0);
root.add(label);
// Stylized wake.
const wake = [];
for (let i = 0; i < 14; i++) {
const wakeMaterial = new THREE.MeshBasicMaterial({
color: accentColor,
transparent: true,
opacity: 0.07,
depthWrite: false
});
const dash = addBox(
root,
[0.72, 0.012, 0.075],
[-2.5 - i * 0.43, 0.018, i % 2 === 0 ? -0.16 : 0.16],
wakeMaterial,
false
);
wake.push(dash);
}
return {
id,
root,
rowers,
wake,
offsets,
state: {
distance: 0,
speed: 0,
thrust: 0,
finished: false
}
};
}
const syncCrew = createCrew("sync", laneZ[0], palette.sync, [0, 0]);
const offsetCrew = createCrew("offset", laneZ[1], palette.offset, [0, 0.5]);
// -------------------------------------------------------------------------
// Stroke and boat-motion model
// -------------------------------------------------------------------------
const clamp01 = value => Math.max(0, Math.min(1, value));
const lerp = (a, b, t) => a + (b - a) * t;
const smooth01 = value => {
const t = clamp01(value);
return t * t * (3 - 2 * t);
};
function phaseFor(crew, rowerIndex, simulationTime) {
const phase =
(simulationTime / CYCLE_SECONDS + crew.offsets[rowerIndex]) % 1;
return phase < 0 ? phase + 1 : phase;
}
function driveForce(phase) {
// Catch at 8%, finish at 50%, then recovery until 92%.
if (phase < 0.08 || phase > 0.5) {
return 0;
}
const driveProgress = (phase - 0.08) / 0.42;
const pulse = Math.pow(Math.sin(Math.PI * driveProgress), 1.18);
return MAX_ROWER_FORCE * pulse;
}
function updatePhysics(crew, dt, simulationTime) {
if (crew.state.finished) {
return;
}
let thrust = 0;
for (let i = 0; i < crew.rowers.length; i++) {
thrust += driveForce(phaseFor(crew, i, simulationTime));
}
const speed = crew.state.speed;
const drag = 1.8 * speed + 0.55 * speed * speed;
const acceleration = (thrust - drag) / MASS;
crew.state.speed = Math.max(0, speed + acceleration * dt);
crew.state.distance += crew.state.speed * dt;
crew.state.thrust = thrust;
if (crew.state.distance >= RACE_DISTANCE) {
crew.state.distance = RACE_DISTANCE;
crew.state.speed = 0;
crew.state.finished = true;
}
}
function updateRower(rower, phase, time) {
let extension = 0;
let sweep = -0.74;
if (phase >= 0.08 && phase <= 0.5) {
const t = (phase - 0.08) / 0.42;
const eased = smooth01(t);
extension = eased;
sweep = lerp(-0.74, 0.74, eased);
} else if (phase > 0.5 && phase <= 0.92) {
const t = (phase - 0.5) / 0.42;
const eased = smooth01(t);
extension = 1 - eased;
sweep = lerp(0.74, -0.74, eased);
}
const bodyX = lerp(-0.14, 0.16, extension);
const lean = lerp(0.22, -0.13, extension);
rower.body.position.x = bodyX;
rower.upper.rotation.z = lean;
// Upper-body shoulder location after torso lean.
const shoulderY = 0.48;
const shoulderX = -Math.sin(lean) * shoulderY;
const shoulderWorldY = 0.88 + Math.cos(lean) * shoulderY;
rower.legs.forEach(({ upperLeg, lowerLeg, side }) => {
const hip = new THREE.Vector3(bodyX + 0.03, 0.79, side * 0.16);
const knee = new THREE.Vector3(
lerp(-0.43, -0.04, extension),
lerp(0.73, 0.68, extension),
side * 0.16
);
const foot = new THREE.Vector3(-0.61, 0.61, side * 0.17);
updateBeam(upperLeg, hip, knee);
updateBeam(lowerLeg, knee, foot);
});
rower.oars.forEach((oar, index) => {
const side = oar.side;
const angle = side > 0 ? sweep : -sweep;
oar.pivot.rotation.y = angle;
const handleLocal = new THREE.Vector3(0.32, 0.22, side * 0.28);
const bladeLocal = new THREE.Vector3(-0.38, -0.7, side * 1.42);
const handle = handleLocal.clone().applyAxisAngle(yAxis, angle);
const blade = bladeLocal.clone().applyAxisAngle(yAxis, angle);
oar.shaft.position.set(
(handle.x + blade.x) * 0.5,
(handle.y + blade.y) * 0.5,
(handle.z + blade.z) * 0.5
);
const shaftDirection = new THREE.Vector3().subVectors(blade, handle);
oar.shaft.scale.y = shaftDirection.length();
oar.shaft.quaternion.setFromUnitVectors(yAxis, shaftDirection.normalize());
oar.blade.position.copy(blade);
oar.bladeTip.position.copy(blade).add(
new THREE.Vector3(-0.19, 0, 0)
);
const shoulder = new THREE.Vector3(
bodyX + shoulderX,
shoulderWorldY,
side * 0.22
);
const handPosition = new THREE.Vector3(
0.05 + handle.x,
1.0 + handle.y,
handle.z
);
updateBeam(rower.arms[index], shoulder, handPosition);
rower.hands[index].position.copy(handPosition);
});
// Visible phase wheel: bright block travels around the ring.
const markerAngle = phase * Math.PI * 2;
rower.phaseWheel.marker.position.set(
Math.cos(markerAngle) * rower.phaseWheel.radius,
Math.sin(markerAngle) * rower.phaseWheel.radius,
0.055
);
rower.phaseWheel.marker.rotation.z = markerAngle;
}
function updateCrewVisual(crew, simulationTime) {
crew.root.position.x = START_X + crew.state.distance;
crew.root.position.y =
0.012 + Math.sin(simulationTime * 3.1 + crew.root.position.z) * 0.018;
crew.root.rotation.x =
Math.sin(simulationTime * 2.7 + crew.root.position.z) * 0.013;
crew.root.rotation.z =
Math.sin(simulationTime * 2.15 + 1.2) * 0.009;
crew.rowers.forEach((rower, index) => {
const phase = phaseFor(crew, index, simulationTime);
updateRower(rower, phase, simulationTime);
});
const speedRatio = clamp01(crew.state.speed / 3.2);
crew.wake.forEach((dash, index) => {
dash.material.opacity =
(0.018 + speedRatio * 0.08) * (1 - index / crew.wake.length);
});
}
// -------------------------------------------------------------------------
// HUD
// -------------------------------------------------------------------------
function updateCrewHUD(crew) {
const prefix = crew.id;
document.getElementById(`${prefix}-speed`).textContent =
crew.state.speed.toFixed(2);
document.getElementById(`${prefix}-distance`).textContent =
crew.state.distance.toFixed(1);
document.getElementById(`${prefix}-thrust`).textContent =
crew.state.thrust.toFixed(0);
const status = document.getElementById(`${prefix}-status`);
status.textContent = crew.state.finished ? "FINISHED" : "RUNNING";
crew.rowers.forEach((_, index) => {
const phase = phaseFor(crew, index, simulationTime);
document.getElementById(`${prefix}-phase-${index}`).style.left =
`${phase * 100}%`;
document.getElementById(`${prefix}-phase-value-${index}`).textContent =
`${Math.round(phase * 100)}%`;
});
}
// -------------------------------------------------------------------------
// Camera controls implemented directly without Three.js addons
// -------------------------------------------------------------------------
const orbit = {
yaw: 0.56,
pitch: 0.51,
radius: 19
};
const defaultOrbit = { ...orbit };
const cameraTarget = new THREE.Vector3(START_X + 1, 0.45, 0);
const desiredTarget = cameraTarget.clone();
function updateCamera() {
const horizontalRadius = orbit.radius * Math.cos(orbit.pitch);
camera.position.set(
cameraTarget.x + horizontalRadius * Math.sin(orbit.yaw),
cameraTarget.y + orbit.radius * Math.sin(orbit.pitch),
cameraTarget.z + horizontalRadius * Math.cos(orbit.yaw)
);
camera.lookAt(cameraTarget);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.yaw -= deltaX * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + deltaY * 0.0045,
0.22,
1.0
);
});
function stopDragging() {
dragging = false;
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
10,
30
);
},
{ passive: false }
);
function resetCamera() {
orbit.yaw = defaultOrbit.yaw;
orbit.pitch = defaultOrbit.pitch;
orbit.radius = defaultOrbit.radius;
}
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Controls and simulation loop
// -------------------------------------------------------------------------
let running = true;
let simulationTime = 0;
let simulationRate = 1;
const rateOptions = [0.5, 1, 2];
let rateIndex = 1;
const pauseButton = document.getElementById("pause-button");
const speedButton = document.getElementById("speed-button");
const resetButton = document.getElementById("reset-button");
const cameraButton = document.getElementById("camera-button");
pauseButton.addEventListener("click", () => {
running = !running;
pauseButton.textContent = running ? "Pause" : "Resume";
});
speedButton.addEventListener("click", () => {
rateIndex = (rateIndex + 1) % rateOptions.length;
simulationRate = rateOptions[rateIndex];
speedButton.textContent = `Speed ${simulationRate}×`;
});
function resetRace() {
simulationTime = 0;
[syncCrew, offsetCrew].forEach(crew => {
crew.state.distance = 0;
crew.state.speed = 0;
crew.state.thrust = 0;
crew.state.finished = false;
});
cameraTarget.set(START_X + 1, 0.45, 0);
desiredTarget.copy(cameraTarget);
}
resetButton.addEventListener("click", resetRace);
cameraButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
resetRace();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const realDelta = Math.min(clock.getDelta(), 0.05);
const simulationDelta = running ? realDelta * simulationRate : 0;
if (running) {
simulationTime += simulationDelta;
}
updatePhysics(syncCrew, simulationDelta, simulationTime);
updatePhysics(offsetCrew, simulationDelta, simulationTime);
updateCrewVisual(syncCrew, simulationTime);
updateCrewVisual(offsetCrew, simulationTime);
updateCrewHUD(syncCrew);
updateCrewHUD(offsetCrew);
const difference = syncCrew.state.distance - offsetCrew.state.distance;
const leader =
Math.abs(difference) < 0.005
? "TIED"
: difference > 0
? "SYNC LEADS"
: "OFFSET LEADS";
document.getElementById("race-readout").textContent =
`T ${simulationTime.toFixed(1)} s · ${leader} ${Math.abs(difference).toFixed(2)} m`;
const averageDistance =
(syncCrew.state.distance + offsetCrew.state.distance) * 0.5;
desiredTarget.set(START_X + averageDistance, 0.45, 0);
cameraTarget.lerp(
desiredTarget,
1 - Math.exp(-realDelta * 2.8)
);
updateCamera();
renderer.render(scene, camera);
}
updateCamera();
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```