Prompt specification
Build or customize the Three.js 3D scene "Oar Pivot and Blade Sweep" 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: Oar Pivot and Blade Sweep
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/oar-pivot-and-blade-sweep-x3641
Scene Description Prompt:
Model an oar in a fixed rowlock with a visible pivot and blade path. Show the lever geometry without claiming a complete hydrodynamic force simulation. Use Three.js from cdnjs in a single HTML file, with low-poly forms.
Working Three.js Starter (oar-pivot-and-blade-sweep-x3641):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Fixed Rowlock — Oar Lever Geometry</title>
<style>
:root {
--ink: #18252c;
--muted: #64747c;
--panel: rgba(248, 251, 252, 0.9);
--line: rgba(40, 65, 74, 0.16);
--accent: #e09b28;
--accent-2: #168a91;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8eef0;
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;
touch-action: none;
}
.panel {
position: fixed;
z-index: 5;
background: var(--panel);
border: 1px solid rgba(255,255,255,0.75);
box-shadow: 0 12px 38px rgba(30, 55, 65, 0.13);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
border-radius: 14px;
}
#header {
top: 18px;
left: 18px;
padding: 16px 18px;
max-width: 430px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
color: var(--accent-2);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent-2);
box-shadow: 0 0 0 4px rgba(22,138,145,0.12);
}
h1 {
margin: 7px 0 5px;
font-size: clamp(21px, 2.2vw, 30px);
line-height: 1.05;
letter-spacing: -0.035em;
}
#header p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
#controls {
left: 18px;
bottom: 18px;
width: 310px;
padding: 14px;
}
.control-title {
margin-bottom: 11px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--muted);
}
.row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin: 10px 0;
font-size: 12px;
}
.row label {
font-weight: 650;
white-space: nowrap;
}
output {
min-width: 54px;
text-align: right;
color: var(--accent-2);
font-variant-numeric: tabular-nums;
font-weight: 800;
}
input[type="range"] {
width: 100%;
accent-color: var(--accent-2);
cursor: pointer;
}
.buttons {
display: flex;
gap: 7px;
flex-wrap: wrap;
margin-top: 11px;
}
button {
appearance: none;
border: 1px solid var(--line);
background: rgba(255,255,255,0.76);
color: var(--ink);
border-radius: 8px;
padding: 8px 10px;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}
button:hover {
background: white;
border-color: rgba(22,138,145,0.35);
}
button:active { transform: translateY(1px); }
button.primary {
color: white;
background: var(--accent-2);
border-color: var(--accent-2);
}
button.active {
color: white;
background: var(--ink);
border-color: var(--ink);
}
.checks {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
}
.checks label {
display: flex;
align-items: center;
gap: 7px;
font-size: 11px;
color: #40535c;
cursor: pointer;
}
.checks input { accent-color: var(--accent-2); }
#metrics {
right: 18px;
bottom: 18px;
width: 258px;
padding: 14px;
}
.metric {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 12px;
padding: 8px 0;
border-bottom: 1px solid var(--line);
font-size: 11px;
}
.metric:last-of-type { border-bottom: 0; }
.metric span { color: var(--muted); }
.metric strong {
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.note {
margin-top: 10px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.label {
position: absolute;
left: 0;
top: 0;
padding: 5px 8px;
border: 1px solid rgba(255,255,255,0.8);
border-radius: 6px;
background: rgba(255,255,255,0.88);
box-shadow: 0 4px 14px rgba(30,55,65,0.12);
color: #31454e;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.055em;
text-transform: uppercase;
white-space: nowrap;
will-change: transform;
}
.label::before {
content: "";
display: inline-block;
width: 6px;
height: 6px;
margin-right: 5px;
border-radius: 50%;
background: var(--accent-2);
}
.label.pivot::before { background: var(--accent); }
.label.blade::before { background: #d39b25; }
#help {
position: fixed;
z-index: 5;
right: 18px;
top: 18px;
padding: 9px 11px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
text-align: right;
}
@media (max-width: 760px) {
#header {
top: 10px;
left: 10px;
right: 10px;
max-width: none;
padding: 12px 14px;
}
#header p { display: none; }
#controls {
left: 10px;
bottom: 10px;
width: min(300px, calc(100vw - 20px));
}
#metrics { display: none; }
#help { display: none; }
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels"></div>
<section id="header" class="panel">
<div class="eyebrow">Kinematic geometry study</div>
<h1>Fixed rowlock & oar lever</h1>
<p>
The vertical pivot remains fixed while the oar sweeps about it.
The cyan arc traces the blade-center path; dashed lines identify the lever arms.
</p>
</section>
<section id="controls" class="panel">
<div class="control-title">Oar controls</div>
<div class="row">
<label for="angle">Sweep angle</label>
<output id="angleValue">0°</output>
</div>
<input id="angle" type="range" min="-38" max="38" value="0" step="1">
<div class="row">
<label for="speed">Cycle speed</label>
<output id="speedValue">0.65×</output>
</div>
<input id="speed" type="range" min="0.2" max="1.4" value="0.65" step="0.05">
<div class="buttons">
<button id="play" class="primary">Pause</button>
<button id="reset">Reset oar</button>
</div>
<div class="buttons">
<button class="view active" data-view="3d">3D</button>
<button class="view" data-view="top">Top</button>
<button class="view" data-view="side">Side</button>
</div>
<div class="checks">
<label><input id="pathToggle" type="checkbox" checked> Blade path</label>
<label><input id="ghostToggle" type="checkbox" checked> End ghosts</label>
<label><input id="labelToggle" type="checkbox" checked> Labels</label>
<label><input id="waterToggle" type="checkbox" checked> Reference plane</label>
</div>
</section>
<section id="metrics" class="panel">
<div class="control-title">Illustrative geometry</div>
<div class="metric"><span>Outboard arm</span><strong>2.98 m</strong></div>
<div class="metric"><span>Inboard arm</span><strong>1.70 m</strong></div>
<div class="metric"><span>Arm ratio</span><strong>1.75 : 1</strong></div>
<div class="metric"><span>Total sweep</span><strong>76°</strong></div>
<div class="note">
Lengths and motion are illustrative. This model does not calculate blade
pressure, drag, torque, or a complete hydrodynamic force solution.
</div>
</section>
<div id="help" class="panel">
Drag to orbit · Shift/right-drag to pan<br>
Mouse wheel to zoom
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const labelLayer = document.getElementById("labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8eef0);
scene.fog = new THREE.Fog(0xe8eef0, 11, 22);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
40, window.innerWidth / window.innerHeight, 0.1, 80
);
const target = new THREE.Vector3(0.35, 0.12, 0);
const cameraState = {
theta: 0.72,
phi: 1.02,
radius: 7.4
};
const desiredCamera = { ...cameraState };
const desiredTarget = target.clone();
function updateCamera() {
const smoothing = 0.12;
cameraState.theta += (desiredCamera.theta - cameraState.theta) * smoothing;
cameraState.phi += (desiredCamera.phi - cameraState.phi) * smoothing;
cameraState.radius += (desiredCamera.radius - cameraState.radius) * smoothing;
target.lerp(desiredTarget, smoothing);
camera.position.setFromSphericalCoords(
cameraState.radius, cameraState.phi, cameraState.theta
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf8fcff, 0x7e8f91, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(4, 8, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xa8dce0, 1.1);
rimLight.position.set(-5, 3, -4);
scene.add(rimLight);
const materials = {
deck: new THREE.MeshStandardMaterial({
color: 0xd5d9d8, roughness: 0.9, flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: 0x34464d, roughness: 0.48, metalness: 0.6, flatShading: true
}),
darkMetal: new THREE.MeshStandardMaterial({
color: 0x1e2b30, roughness: 0.62, metalness: 0.45, flatShading: true
}),
pivot: new THREE.MeshStandardMaterial({
color: 0xe09b28, roughness: 0.42, metalness: 0.35, flatShading: true
}),
shaft: new THREE.MeshStandardMaterial({
color: 0xa66e38, roughness: 0.72, flatShading: true
}),
grip: new THREE.MeshStandardMaterial({
color: 0x253137, roughness: 0.85, flatShading: true
}),
blade: new THREE.MeshStandardMaterial({
color: 0xe8b43c, roughness: 0.58, flatShading: true
}),
rib: new THREE.MeshStandardMaterial({
color: 0xa97013, roughness: 0.7, flatShading: true
}),
edge: new THREE.LineBasicMaterial({
color: 0x745015, transparent: true, opacity: 0.8
})
};
function addEdges(mesh, material = materials.edge) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 25), material
);
mesh.add(edges);
return edges;
}
function cylinderBetween(a, b, radiusA, radiusB, material, segments = 10) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radiusB, radiusA, length, segments, 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;
}
/* ---------- Fixed mounting deck and rowlock ---------- */
const mount = new THREE.Group();
scene.add(mount);
const deck = new THREE.Mesh(
new THREE.BoxGeometry(2.15, 0.16, 1.08),
materials.deck
);
deck.position.set(-0.58, -0.02, 0);
deck.castShadow = true;
deck.receiveShadow = true;
mount.add(deck);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.31, 0.36, 0.13, 10),
materials.metal
);
base.position.y = 0.125;
base.castShadow = true;
mount.add(base);
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.066, 0.078, 0.58, 10),
materials.metal
);
post.position.y = 0.42;
post.castShadow = true;
mount.add(post);
const pin = new THREE.Mesh(
new THREE.CylinderGeometry(0.051, 0.051, 0.12, 10),
materials.pivot
);
pin.position.y = 0.70;
pin.castShadow = true;
mount.add(pin);
const pivotMarker = new THREE.Mesh(
new THREE.TorusGeometry(0.255, 0.017, 6, 28),
materials.pivot
);
pivotMarker.rotation.x = Math.PI / 2;
pivotMarker.position.set(0, 0.071, 0);
mount.add(pivotMarker);
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.08, 0),
new THREE.Vector3(0, 0.82, 0)
]);
const axisLine = new THREE.Line(
axisGeometry,
new THREE.LineDashedMaterial({
color: 0xe09b28,
dashSize: 0.045,
gapSize: 0.03,
transparent: true,
opacity: 0.8
})
);
axisLine.computeLineDistances();
mount.add(axisLine);
/* ---------- Oar and rotating sleeve ---------- */
const pivotY = 0.78;
const oar = new THREE.Group();
oar.position.set(0, pivotY, 0);
scene.add(oar);
const sleeve = new THREE.Mesh(
new THREE.CylinderGeometry(0.145, 0.16, 0.18, 12, 1, true),
materials.darkMetal
);
sleeve.position.y = -0.105;
sleeve.castShadow = true;
oar.add(sleeve);
const sleeveRing = new THREE.Mesh(
new THREE.TorusGeometry(0.135, 0.033, 6, 12),
materials.darkMetal
);
sleeveRing.rotation.x = Math.PI / 2;
sleeveRing.position.y = -0.025;
sleeveRing.castShadow = true;
oar.add(sleeveRing);
const inboardStart = new THREE.Vector3(-0.12, 0, 0);
const inboardEnd = new THREE.Vector3(-1.72, 0.27, 0);
oar.add(cylinderBetween(
inboardStart, inboardEnd, 0.042, 0.031, materials.shaft, 10
));
const grip = cylinderBetween(
new THREE.Vector3(-1.77, 0.274, 0),
new THREE.Vector3(-1.46, 0.248, 0),
0.049, 0.049, materials.grip, 10
);
oar.add(grip);
const gripCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.052, 0.052, 0.045, 10),
materials.darkMetal
);
gripCap.position.set(-1.785, 0.276, 0);
gripCap.rotation.z = Math.PI / 2;
gripCap.castShadow = true;
oar.add(gripCap);
const outboardStart = new THREE.Vector3(0.12, 0, 0);
const outboardEnd = new THREE.Vector3(2.86, -0.27, 0);
oar.add(cylinderBetween(
outboardStart, outboardEnd, 0.043, 0.024, materials.shaft, 10
));
const bladeLocal = new THREE.Vector3(2.98, -0.66, 0);
function makeBladeGeometry() {
const shape = new THREE.Shape();
shape.moveTo(-0.38, 0.40);
shape.lineTo(0.38, 0.40);
shape.lineTo(0.47, -0.26);
shape.lineTo(0.28, -0.42);
shape.lineTo(-0.28, -0.42);
shape.lineTo(-0.47, -0.26);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.07,
bevelEnabled: false,
steps: 1
});
geometry.translate(0, 0, -0.035);
geometry.computeVertexNormals();
return geometry;
}
const bladeGeometry = makeBladeGeometry();
const bladeFeather = new THREE.Group();
bladeFeather.position.copy(bladeLocal);
bladeFeather.rotation.x = THREE.MathUtils.degToRad(14);
oar.add(bladeFeather);
const blade = new THREE.Mesh(bladeGeometry, materials.blade);
blade.castShadow = true;
blade.receiveShadow = true;
bladeFeather.add(blade);
addEdges(blade);
const bladeRib = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.66, 0.025),
materials.rib
);
bladeRib.position.z = 0.047;
bladeFeather.add(bladeRib);
/* ---------- Lever geometry overlays ---------- */
const outboardLeverGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, 0.07),
bladeLocal.clone().add(new THREE.Vector3(0, 0, 0.07))
]);
const outboardLever = new THREE.Line(
outboardLeverGeometry,
new THREE.LineDashedMaterial({
color: 0xe09b28,
dashSize: 0.07,
gapSize: 0.035,
transparent: true,
opacity: 0.85
})
);
outboardLever.computeLineDistances();
oar.add(outboardLever);
const inboardLeverGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, 0.07),
new THREE.Vector3(-1.70, 0.26, 0.07)
]);
const inboardLever = new THREE.Line(
inboardLeverGeometry,
new THREE.LineDashedMaterial({
color: 0x168a91,
dashSize: 0.055,
gapSize: 0.03,
transparent: true,
opacity: 0.9
})
);
inboardLever.computeLineDistances();
oar.add(inboardLever);
/* ---------- Reference water plane ---------- */
const water = new THREE.Mesh(
new THREE.PlaneGeometry(14, 10),
new THREE.MeshStandardMaterial({
color: 0x8fc8cc,
roughness: 0.74,
metalness: 0.02,
transparent: true,
opacity: 0.38,
side: THREE.DoubleSide,
depthWrite: false
})
);
water.rotation.x = -Math.PI / 2;
water.position.y = -0.40;
water.receiveShadow = true;
scene.add(water);
const grid = new THREE.GridHelper(12, 24, 0x6a9da1, 0x91b8bb);
grid.position.y = -0.392;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
/* ---------- Blade-center path ---------- */
const maxSweep = THREE.MathUtils.degToRad(38);
const pathRadius = Math.hypot(bladeLocal.x, bladeLocal.z);
const pathY = pivotY + bladeLocal.y;
const pathPoints = [];
for (let i = 0; i <= 100; i++) {
const a = THREE.MathUtils.lerp(-maxSweep, maxSweep, i / 100);
pathPoints.push(new THREE.Vector3(
pathRadius * Math.cos(a),
pathY,
-pathRadius * Math.sin(a)
));
}
const pathGeometry = new THREE.BufferGeometry().setFromPoints(pathPoints);
const pathLine = new THREE.Line(
pathGeometry,
new THREE.LineDashedMaterial({
color: 0x168a91,
dashSize: 0.095,
gapSize: 0.055,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
pathLine.computeLineDistances();
pathLine.renderOrder = 4;
scene.add(pathLine);
const endpointMaterial = new THREE.MeshBasicMaterial({
color: 0x168a91,
transparent: true,
opacity: 0.8
});
for (const a of [-maxSweep, maxSweep]) {
const endpoint = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 8, 6),
endpointMaterial
);
endpoint.position.set(
pathRadius * Math.cos(a),
pathY,
-pathRadius * Math.sin(a)
);
scene.add(endpoint);
}
/* ---------- Ghost blade positions at sweep limits ---------- */
const ghostMaterial = new THREE.MeshBasicMaterial({
color: 0xe8b43c,
transparent: true,
opacity: 0.13,
side: THREE.DoubleSide,
depthWrite: false
});
const ghostEdgeMaterial = new THREE.LineBasicMaterial({
color: 0xc68a1d,
transparent: true,
opacity: 0.48
});
const ghosts = [];
function setGhostTransform(mesh, angle) {
const qY = new THREE.Quaternion().setFromAxisAngle(
new THREE.Vector3(0, 1, 0), angle
);
mesh.position.copy(bladeLocal)
.applyAxisAngle(new THREE.Vector3(0, 1, 0), angle)
.add(oar.position);
mesh.quaternion.copy(qY).multiply(bladeFeather.quaternion);
}
for (const a of [-maxSweep, maxSweep]) {
const ghost = new THREE.Mesh(bladeGeometry, ghostMaterial);
ghost.renderOrder = 2;
addEdges(ghost, ghostEdgeMaterial);
setGhostTransform(ghost, a);
scene.add(ghost);
ghosts.push(ghost);
}
/* ---------- HTML annotations projected from 3D ---------- */
const labels = [];
function addLabel(text, getPosition, className = "") {
const element = document.createElement("div");
element.className = `label ${className}`;
element.textContent = text;
labelLayer.appendChild(element);
labels.push({ element, getPosition });
}
const bladeWorld = new THREE.Vector3();
addLabel(
"Fixed pivot / oarlock",
() => new THREE.Vector3(0, 0.91, 0),
"pivot"
);
addLabel(
"Inboard handle · 1.70 m",
() => new THREE.Vector3(-1.68, 0.25, 0).applyMatrix4(oar.matrixWorld)
);
addLabel(
"Outboard lever · 2.98 m",
() => bladeLocal.clone().applyMatrix4(oar.matrixWorld)
.add(new THREE.Vector3(0, 0.08, 0)),
"blade"
);
addLabel(
"Blade-center path",
() => {
const a = -maxSweep * 0.64;
return new THREE.Vector3(
pathRadius * Math.cos(a),
pathY + 0.08,
-pathRadius * Math.sin(a)
);
}
);
addLabel(
"Waterline reference",
() => new THREE.Vector3(-1.15, -0.38, 1.15),
"pivot"
);
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
const point = label.getPosition().project(camera);
const visible =
point.z > -1 && point.z < 1 &&
point.x > -1.15 && point.x < 1.15 &&
point.y > -1.15 && point.y < 1.15;
label.element.style.visibility = visible ? "visible" : "hidden";
label.element.style.transform = `
translate(-50%, -50%)
translate(${(point.x * 0.5 + 0.5) * width}px,
${(-point.y * 0.5 + 0.5) * height}px)
`;
}
}
/* ---------- Direct camera controls ---------- */
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
previousX = event.clientX;
previousY = event.clientY;
pointerId = event.pointerId;
renderer.domElement.setPointerCapture(pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 1);
const panScale = cameraState.radius * 0.0015;
desiredTarget.addScaledVector(right, -dx * panScale);
desiredTarget.addScaledVector(up, dy * panScale);
} else {
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi + dy * 0.005, 0.10, Math.PI - 0.10
);
}
});
function endDrag(event) {
if (!dragging) return;
dragging = false;
if (pointerId !== null &&
renderer.domElement.hasPointerCapture(pointerId)) {
renderer.domElement.releasePointerCapture(pointerId);
}
pointerId = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius + event.deltaY * 0.006,
3.8, 15
);
}, { passive: false });
/* ---------- UI ---------- */
const angleInput = document.getElementById("angle");
const angleValue = document.getElementById("angleValue");
const speedInput = document.getElementById("speed");
const speedValue = document.getElementById("speedValue");
const playButton = document.getElementById("play");
const pathToggle = document.getElementById("pathToggle");
const ghostToggle = document.getElementById("ghostToggle");
const labelToggle = document.getElementById("labelToggle");
const waterToggle = document.getElementById("waterToggle");
let playing = true;
let angleDegrees = 0;
let cycleSpeed = Number(speedInput.value);
let cycleTime = 0;
angleInput.addEventListener("input", () => {
angleDegrees = Number(angleInput.value);
playing = false;
playButton.textContent = "Play";
playButton.classList.remove("primary");
});
speedInput.addEventListener("input", () => {
cycleSpeed = Number(speedInput.value);
speedValue.textContent = `${cycleSpeed.toFixed(2)}×`;
});
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
playButton.classList.toggle("primary", playing);
});
document.getElementById("reset").addEventListener("click", () => {
angleDegrees = 0;
playing = false;
playButton.textContent = "Play";
playButton.classList.remove("primary");
});
pathToggle.addEventListener("change", () => {
pathLine.visible = pathToggle.checked;
});
ghostToggle.addEventListener("change", () => {
ghosts.forEach(ghost => ghost.visible = ghostToggle.checked);
});
labelToggle.addEventListener("change", () => {
labelLayer.style.display = labelToggle.checked ? "block" : "none";
});
waterToggle.addEventListener("change", () => {
water.visible = waterToggle.checked;
grid.visible = waterToggle.checked;
});
const viewButtons = [...document.querySelectorAll(".view")];
viewButtons.forEach(button => {
button.addEventListener("click", () => {
viewButtons.forEach(b => b.classList.remove("active"));
button.classList.add("active");
const view = button.dataset.view;
desiredTarget.set(0.35, 0.12, 0);
if (view === "3d") {
desiredCamera.theta = 0.72;
desiredCamera.phi = 1.02;
desiredCamera.radius = 7.4;
} else if (view === "top") {
desiredCamera.theta = 0;
desiredCamera.phi = 0.10;
desiredCamera.radius = 6.9;
desiredTarget.set(0.45, -0.05, 0);
} else if (view === "side") {
desiredCamera.theta = 0;
desiredCamera.phi = Math.PI / 2;
desiredCamera.radius = 6.8;
desiredTarget.set(0.45, 0.15, 0);
}
});
});
/* ---------- Resize and animation ---------- */
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() {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
cycleTime += delta * cycleSpeed;
angleDegrees = THREE.MathUtils.radToDeg(
maxSweep * Math.sin(cycleTime)
);
angleInput.value = angleDegrees.toFixed(0);
}
const angle = THREE.MathUtils.degToRad(angleDegrees);
oar.rotation.y = angle;
oar.updateMatrixWorld(true);
angleValue.textContent = `${angleDegrees.toFixed(0)}°`;
updateCamera();
scene.updateMatrixWorld(true);
bladeFeather.getWorldPosition(bladeWorld);
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```