Prompt specification
Build or customize the Three.js 3D scene "One Wheel Held Differential Counterfactual" 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: One Wheel Held Differential Counterfactual
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/one-wheel-held-differential-counterfactual-x2024
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: one wheel held differential counterfactual. Create a schematic differential experiment fixing one output shaft. Update the other output according to the ideal kinematic relation and separate this from traction-force claims. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (one-wheel-held-differential-counterfactual-x2024):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Held-Wheel Differential Counterfactual</title>
<style>
:root {
--bg: #071018;
--panel: rgba(10, 21, 31, 0.82);
--panel-strong: rgba(9, 19, 29, 0.94);
--line: rgba(176, 220, 232, 0.16);
--text: #e8f2f4;
--muted: #91a8b2;
--held: #ff6b5c;
--free: #38d6d0;
--carrier: #f7b84b;
--ok: #8ee6a8;
}
* { 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;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.panel {
background: linear-gradient(145deg, rgba(18, 33, 45, 0.9), var(--panel));
border: 1px solid var(--line);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
.title-block {
position: absolute;
top: 24px;
left: 24px;
width: min(430px, calc(100vw - 48px));
padding: 18px 20px 17px;
border-radius: 16px;
}
.eyebrow {
color: var(--carrier);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 5px;
font-size: clamp(24px, 3vw, 36px);
line-height: 1.03;
letter-spacing: -0.035em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.status-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 13px;
color: #c8d8dc;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--ok);
box-shadow: 0 0 12px var(--ok);
}
.status-dot.paused {
background: var(--carrier);
box-shadow: 0 0 12px var(--carrier);
}
.legend {
position: absolute;
top: 24px;
right: 24px;
padding: 13px 15px;
border-radius: 14px;
min-width: 205px;
}
.legend-title {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
margin-bottom: 9px;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 6px;
font-size: 12px;
}
.swatch {
width: 11px;
height: 11px;
border-radius: 3px;
box-shadow: 0 0 10px currentColor;
}
.swatch.held { color: var(--held); background: var(--held); }
.swatch.free { color: var(--free); background: var(--free); }
.swatch.carrier { color: var(--carrier); background: var(--carrier); }
.orbit-hint {
position: absolute;
left: 50%;
top: 24px;
transform: translateX(-50%);
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 999px;
color: #91a8b2;
background: rgba(7, 16, 24, 0.55);
font-size: 11px;
white-space: nowrap;
}
.scene-label {
position: absolute;
z-index: 3;
pointer-events: none;
transform: translate(-50%, -100%);
padding: 7px 10px;
border-radius: 9px;
background: rgba(6, 14, 21, 0.88);
border: 1px solid currentColor;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.32);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
line-height: 1.45;
text-align: center;
white-space: nowrap;
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 15px;
background: currentColor;
opacity: 0.7;
}
.scene-label strong {
display: block;
font-size: 11px;
}
.scene-label span {
display: block;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
opacity: 0.92;
}
#label-held { color: var(--held); }
#label-free { color: var(--free); }
#label-carrier { color: var(--carrier); }
.bottom-dock {
position: absolute;
left: 20px;
right: 20px;
bottom: 20px;
display: grid;
grid-template-columns: minmax(330px, 0.95fr) minmax(310px, 1fr) minmax(315px, 0.95fr);
gap: 12px;
align-items: stretch;
pointer-events: none;
}
.dock-card {
border-radius: 16px;
padding: 15px 17px;
pointer-events: auto;
}
.card-kicker {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
margin-bottom: 9px;
}
.equation {
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(21px, 2vw, 29px);
line-height: 1.15;
letter-spacing: 0.01em;
}
.equation .held-color { color: var(--held); }
.equation .free-color { color: var(--free); }
.equation .carrier-color { color: var(--carrier); }
.constraint {
margin-top: 7px;
color: #c7d7db;
font-size: 12px;
}
.live-values {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 12px;
}
.value-box {
min-width: 0;
padding: 8px 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(2, 9, 14, 0.3);
}
.value-box label {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
margin-bottom: 3px;
}
.value-box output {
display: block;
font-variant-numeric: tabular-nums;
font-size: 13px;
font-weight: 750;
}
.control-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.control-head .card-kicker { margin: 0; }
.carrier-command {
color: var(--carrier);
font-size: 12px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
margin: 5px 0 11px;
accent-color: var(--carrier);
cursor: pointer;
}
.button-row {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 9px;
padding: 9px 12px;
color: var(--text);
background: rgba(255, 255, 255, 0.065);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover { background: rgba(255, 255, 255, 0.11); }
button:active { transform: translateY(1px); }
button.primary {
min-width: 92px;
color: #081217;
background: var(--carrier);
border-color: var(--carrier);
}
button.primary:hover { background: #ffc85f; }
.small-note {
color: var(--muted);
font-size: 10px;
line-height: 1.45;
margin-top: 9px;
}
.caveat {
border-color: rgba(242, 184, 75, 0.28);
}
.caveat .card-kicker { color: var(--carrier); }
.caveat-title {
margin: 0 0 8px;
font-size: 15px;
letter-spacing: -0.01em;
}
.caveat ul {
margin: 0;
padding-left: 17px;
color: #b9cbd0;
font-size: 11px;
line-height: 1.5;
}
.caveat li + li { margin-top: 5px; }
.scope-tag {
display: inline-block;
margin-top: 10px;
padding: 5px 8px;
border-radius: 999px;
color: #ffd68f;
background: rgba(247, 184, 75, 0.09);
border: 1px solid rgba(247, 184, 75, 0.2);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 1050px) {
.bottom-dock {
grid-template-columns: 1fr 1fr;
}
.caveat {
grid-column: 1 / -1;
}
.orbit-hint { display: none; }
.legend { top: auto; bottom: 260px; }
}
@media (max-width: 680px) {
.title-block {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
.legend, .scene-label { display: none; }
.bottom-dock {
left: 10px;
right: 10px;
bottom: 10px;
grid-template-columns: 1fr;
max-height: 49vh;
overflow-y: auto;
}
.caveat { grid-column: auto; }
.dock-card { padding: 12px 13px; }
.subtitle { display: none; }
.status-row { margin-top: 9px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly differential experiment"></canvas>
<div class="hud">
<section class="title-block panel" aria-label="Experiment title">
<div class="eyebrow">Schematic experiment · counterfactual</div>
<h1>One output held</h1>
<p class="subtitle">
Ideal symmetric open differential with the left output constrained.
The unheld output follows the kinematic constraint only.
</p>
<div class="status-row">
<span id="statusDot" class="status-dot"></span>
<span id="statusText">Running · constraint satisfied</span>
</div>
</section>
<aside class="legend panel" aria-label="Color legend">
<div class="legend-title">Model elements</div>
<div class="legend-row"><span class="swatch held"></span> Held output / wheel</div>
<div class="legend-row"><span class="swatch free"></span> Kinematic output</div>
<div class="legend-row"><span class="swatch carrier"></span> Carrier / input</div>
</aside>
<div class="orbit-hint">Drag to orbit · scroll to zoom</div>
<div id="label-held" class="scene-label">
<strong>LEFT OUTPUT</strong>
<span>HELD · 0 rpm</span>
</div>
<div id="label-free" class="scene-label">
<strong>RIGHT OUTPUT</strong>
<span>2 × carrier</span>
</div>
<div id="label-carrier" class="scene-label">
<strong>CARRIER</strong>
<span>input rotation</span>
</div>
<main class="bottom-dock">
<section class="dock-card panel" aria-label="Kinematic relation">
<div class="card-kicker">Ideal open-differential kinematics</div>
<div class="equation">
<span class="held-color">ω<sub>H</sub></span> +
<span class="free-color">ω<sub>U</sub></span> =
2<span class="carrier-color">ω<sub>C</sub></span>
</div>
<div class="constraint">
With <strong>ω<sub>H</sub> = 0</strong>:
<strong>ω<sub>U</sub> = 2ω<sub>C</sub></strong>
</div>
<div class="live-values">
<div class="value-box">
<label>Held</label>
<output id="heldRpm" style="color:var(--held)">0 rpm</output>
</div>
<div class="value-box">
<label>Unheld</label>
<output id="freeRpm" style="color:var(--free)">+48 rpm</output>
</div>
<div class="value-box">
<label>Carrier</label>
<output id="carrierRpm" style="color:var(--carrier)">+24 rpm</output>
</div>
</div>
</section>
<section class="dock-card panel" aria-label="Animation controls">
<div class="control-head">
<div class="card-kicker">Carrier command</div>
<output id="carrierCommand" class="carrier-command">+24 rpm</output>
</div>
<input
id="speed"
type="range"
min="-60"
max="60"
step="1"
value="24"
aria-label="Carrier angular velocity in revolutions per minute"
/>
<div class="button-row">
<button id="toggle" class="primary" type="button">Pause</button>
<button id="resetAngle" type="button">Reset angle</button>
<button id="resetView" type="button">Reset view</button>
</div>
<div class="small-note">
The carrier and carrier-mounted ring rotate at 1×; the unheld output
rotates at 2×. Negative commands reverse all prescribed directions.
</div>
</section>
<section class="dock-card panel caveat" aria-label="Traction force limitations">
<div class="card-kicker">Separated from traction-force claims</div>
<h2 class="caveat-title">Angular velocity is not wheel force.</h2>
<ul>
<li>This scene computes only the ideal differential velocity relation.</li>
<li>It does not calculate torque, reaction force, tire slip, or tractive effort.</li>
<li>A real held shaft can transmit reaction torque; that force is outside this model.</li>
</ul>
<span class="scope-tag">Kinematics only · no force solver</span>
</section>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.Fog(0x071018, 11, 23);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const target = new THREE.Vector3(0, 1.35, 0);
const cameraState = {
azimuth: 0.68,
elevation: 0.31,
radius: 9.4
};
function updateCamera() {
const { azimuth, elevation, radius } = 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 hemi = new THREE.HemisphereLight(0xbfe9ff, 0x10151b, 2.0);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xffffff, 3.0);
key.position.set(5, 9, 6);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -7;
key.shadow.camera.right = 7;
key.shadow.camera.top = 7;
key.shadow.camera.bottom = -7;
key.shadow.camera.near = 1;
key.shadow.camera.far = 25;
key.shadow.bias = -0.0004;
scene.add(key);
const rimLight = new THREE.DirectionalLight(0x4edbd8, 1.4);
rimLight.position.set(-6, 4, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff9b52, 16, 10, 2);
warmLight.position.set(2.5, 4, 3);
scene.add(warmLight);
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.62,
metalness: 0.18,
flatShading: true,
...options
});
}
const materials = {
ground: standard(0x0c1821, { roughness: 0.95, metalness: 0.02 }),
platform: standard(0x142630, { roughness: 0.82, metalness: 0.12 }),
case: standard(0x6d8790, {
transparent: true,
opacity: 0.15,
roughness: 0.35,
metalness: 0.42,
depthWrite: false,
side: THREE.DoubleSide
}),
caseRim: standard(0x4b6770, { roughness: 0.38, metalness: 0.55 }),
darkMetal: standard(0x263b45, { roughness: 0.45, metalness: 0.62 }),
steel: standard(0xa9bcc2, { roughness: 0.3, metalness: 0.72 }),
tire: standard(0x11191d, { roughness: 0.96, metalness: 0.02 }),
held: standard(0xff6b5c, { roughness: 0.48, metalness: 0.22 }),
free: standard(0x38d6d0, { roughness: 0.42, metalness: 0.3 }),
carrier: standard(0xf7b84b, { roughness: 0.4, metalness: 0.42 }),
planet: standard(0xffcf69, { roughness: 0.32, metalness: 0.5 }),
rim: standard(0xbfd0d4, { roughness: 0.34, metalness: 0.6 })
};
function mesh(geometry, material, parent = scene) {
const object = new THREE.Mesh(geometry, material);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(size, material, parent, position = [0, 0, 0]) {
const object = mesh(new THREE.BoxGeometry(...size), material, parent);
object.position.set(...position);
return object;
}
function cylinderX(radius, length, segments, material, parent, position = [0, 0, 0]) {
const geometry = new THREE.CylinderGeometry(radius, radius, length, segments);
geometry.rotateZ(Math.PI / 2);
const object = mesh(geometry, material, parent);
object.position.set(...position);
return object;
}
function torusX(radius, tube, radialSegments, tubularSegments, material, parent, position = [0, 0, 0]) {
const geometry = new THREE.TorusGeometry(radius, tube, radialSegments, tubularSegments);
geometry.rotateY(Math.PI / 2);
const object = mesh(geometry, material, parent);
object.position.set(...position);
return object;
}
// Ground and low-poly work surface.
const ground = mesh(
new THREE.PlaneGeometry(40, 40),
materials.ground,
scene
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.04;
ground.castShadow = false;
const platform = mesh(
new THREE.CylinderGeometry(5.6, 5.8, 0.16, 16),
materials.platform,
scene
);
platform.position.y = 0.03;
const grid = new THREE.GridHelper(11, 22, 0x34505a, 0x1b313a);
grid.position.y = 0.125;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
// Pedestal under the differential.
const pedestal = mesh(
new THREE.CylinderGeometry(0.32, 0.48, 1.0, 6),
materials.darkMetal,
scene
);
pedestal.position.set(0, 0.56, 0);
box([1.25, 0.13, 1.0], materials.caseRim, scene, [0, 0.12, 0]);
// Entire axle/differential assembly.
const assembly = new THREE.Group();
assembly.position.y = 1.4;
scene.add(assembly);
// Transparent schematic housing.
const housingGeometry = new THREE.CylinderGeometry(0.92, 0.92, 1.02, 12, 1, true);
housingGeometry.rotateZ(Math.PI / 2);
const housing = mesh(housingGeometry, materials.case, assembly);
housing.castShadow = false;
const housingEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(housingGeometry, 22),
new THREE.LineBasicMaterial({
color: 0x91aeb7,
transparent: true,
opacity: 0.28
})
);
assembly.add(housingEdges);
torusX(0.87, 0.065, 6, 16, materials.caseRim, assembly, [-0.51, 0, 0]);
torusX(0.87, 0.065, 6, 16, materials.caseRim, assembly, [0.51, 0, 0]);
for (const x of [-0.54, 0.54]) {
for (let i = 0; i < 8; i++) {
const a = (i / 8) * Math.PI * 2;
const bolt = mesh(
new THREE.SphereGeometry(0.055, 6, 4),
materials.steel,
assembly
);
bolt.position.set(x, Math.cos(a) * 0.77, Math.sin(a) * 0.77);
}
}
// Carrier assembly: hub, cage, ring gear, and a planet gear.
const carrierGroup = new THREE.Group();
assembly.add(carrierGroup);
cylinderX(0.21, 0.82, 10, materials.carrier, carrierGroup);
for (let i = 0; i < 4; i++) {
const a = i * Math.PI / 2;
const arm = box(
[0.12, 0.54, 0.12],
materials.carrier,
carrierGroup,
[0, Math.cos(a) * 0.31, Math.sin(a) * 0.31]
);
arm.rotation.x = a;
}
torusX(0.69, 0.11, 6, 18, materials.carrier, carrierGroup);
for (let i = 0; i < 24; i++) {
const a = (i / 24) * Math.PI * 2;
const tooth = box(
[0.18, 0.13, 0.10],
materials.carrier,
carrierGroup,
[0, Math.cos(a) * 0.75, Math.sin(a) * 0.75]
);
tooth.rotation.x = a;
}
// A visible index mark makes carrier rotation easy to read.
box([0.16, 0.13, 0.14], materials.planet, carrierGroup, [0, 0.79, 0]);
const planetGroup = new THREE.Group();
planetGroup.position.set(0, 0.48, 0);
carrierGroup.add(planetGroup);
const planetBody = mesh(
new THREE.CylinderGeometry(0.24, 0.24, 0.20, 12),
materials.planet,
planetGroup
);
planetBody.castShadow = true;
for (let i = 0; i < 10; i++) {
const a = (i / 10) * Math.PI * 2;
const tooth = box(
[0.12, 0.19, 0.11],
materials.planet,
planetGroup,
[Math.cos(a) * 0.25, 0, Math.sin(a) * 0.25]
);
tooth.rotation.y = -a;
}
function addSideGear(parent, x, material) {
cylinderX(0.31, 0.18, 12, material, parent, [x, 0, 0]);
for (let i = 0; i < 12; i++) {
const a = (i / 12) * Math.PI * 2;
const tooth = box(
[0.20, 0.18, 0.11],
material,
parent,
[x, Math.cos(a) * 0.36, Math.sin(a) * 0.36]
);
tooth.rotation.x = a;
}
cylinderX(0.11, 0.23, 8, materials.steel, parent, [x, 0, 0]);
}
function addWheel(parent, x, accent, isHeld) {
const wheel = new THREE.Group();
wheel.position.x = x;
parent.add(wheel);
torusX(0.72, 0.23, 6, 16, materials.tire, wheel);
cylinderX(0.51, 0.34, 12, accent, wheel);
cylinderX(0.16, 0.47, 10, materials.steel, wheel);
for (let i = 0; i < 6; i++) {
const a = (i / 6) * Math.PI * 2;
const spoke = box(
[0.38, 0.58, 0.09],
isHeld ? materials.held : materials.free,
wheel,
[0, Math.cos(a) * 0.30, Math.sin(a) * 0.30]
);
spoke.rotation.x = a;
}
// High-contrast marker reveals angular displacement.
box(
[0.50, 0.18, 0.13],
isHeld ? materials.held : materials.free,
wheel,
[0, 0.88, 0]
);
if (isHeld) {
// A stationary brake/lock caliper surrounds the held wheel.
box([0.13, 0.34, 0.25], materials.held, parent, [x - 0.26, 0.79, 0]);
box([0.13, 0.34, 0.25], materials.held, parent, [x + 0.26, 0.79, 0]);
box([0.61, 0.11, 0.22], materials.held, parent, [x, 0.94, 0]);
}
}
// Two output groups. The left is constrained; the right follows twice the carrier.
const heldOutput = new THREE.Group();
const unheldOutput = new THREE.Group();
assembly.add(heldOutput, unheldOutput);
cylinderX(0.085, 1.78, 10, materials.steel, heldOutput, [-1.27, 0, 0]);
cylinderX(0.085, 1.78, 10, materials.steel, unheldOutput, [1.27, 0, 0]);
addSideGear(heldOutput, -0.38, materials.held);
addSideGear(unheldOutput, 0.38, materials.free);
cylinderX(0.16, 0.17, 10, materials.held, heldOutput, [-0.72, 0, 0]);
cylinderX(0.16, 0.17, 10, materials.free, unheldOutput, [0.72, 0, 0]);
// Small non-rotating brackets emphasize that the left collar is locked.
box([0.24, 0.11, 0.11], materials.held, heldOutput, [-0.72, 0.19, 0]);
box([0.24, 0.11, 0.11], materials.held, heldOutput, [-0.72, -0.19, 0]);
addWheel(heldOutput, -2.15, materials.held, true);
addWheel(unheldOutput, 2.15, materials.free, false);
// Minimal state and UI.
const speedInput = document.getElementById("speed");
const toggleButton = document.getElementById("toggle");
const resetAngleButton = document.getElementById("resetAngle");
const resetViewButton = document.getElementById("resetView");
const statusDot = document.getElementById("statusDot");
const statusText = document.getElementById("statusText");
const carrierCommand = document.getElementById("carrierCommand");
const heldRpm = document.getElementById("heldRpm");
const freeRpm = document.getElementById("freeRpm");
const carrierRpm = document.getElementById("carrierRpm");
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
let running = !reducedMotion;
let carrierRpmValue = Number(speedInput.value);
let carrierAngle = 0;
function formatRpm(value) {
const rounded = Math.round(value);
if (rounded === 0) return "0 rpm";
return `${rounded > 0 ? "+" : ""}${rounded} rpm`;
}
function updateInterface() {
const unheldRpmValue = 2 * carrierRpmValue;
carrierCommand.textContent = formatRpm(carrierRpmValue);
heldRpm.textContent = formatRpm(0);
freeRpm.textContent = formatRpm(unheldRpmValue);
carrierRpm.textContent = formatRpm(carrierRpmValue);
toggleButton.textContent = running ? "Pause" : "Play";
statusDot.classList.toggle("paused", !running);
statusText.textContent = running
? "Running · constraint satisfied"
: "Paused · constraint satisfied";
document.getElementById("label-held").querySelector("span").textContent = "HELD · 0 rpm";
document.getElementById("label-free").querySelector("span").textContent = formatRpm(unheldRpmValue);
document.getElementById("label-carrier").querySelector("span").textContent = formatRpm(carrierRpmValue);
}
speedInput.addEventListener("input", () => {
carrierRpmValue = Number(speedInput.value);
updateInterface();
});
toggleButton.addEventListener("click", () => {
running = !running;
updateInterface();
});
resetAngleButton.addEventListener("click", () => {
carrierAngle = 0;
carrierGroup.rotation.x = 0;
unheldOutput.rotation.x = 0;
});
resetViewButton.addEventListener("click", () => {
cameraState.azimuth = 0.68;
cameraState.elevation = 0.31;
cameraState.radius = 9.4;
updateCamera();
});
updateInterface();
// Camera controls implemented directly with Three.js core.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.azimuth -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.005,
-0.05,
1.05
);
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
6.2,
14
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", () => {
cameraState.azimuth = 0.68;
cameraState.elevation = 0.31;
cameraState.radius = 9.4;
updateCamera();
});
// Screen-space labels for the three kinematic elements.
const labelHeld = document.getElementById("label-held");
const labelFree = document.getElementById("label-free");
const labelCarrier = document.getElementById("label-carrier");
const labelPositions = {
held: new THREE.Vector3(-2.15, 2.65, 0),
free: new THREE.Vector3(2.15, 2.65, 0),
carrier: new THREE.Vector3(0, 2.95, 0)
};
function placeLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
if (!visible) return;
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (running) {
const carrierOmega = carrierRpmValue * Math.PI * 2 / 60;
carrierAngle = (carrierAngle + carrierOmega * delta) % (Math.PI * 2);
}
// Ideal symmetric open-differential relation:
// theta_held + theta_unheld = 2 * theta_carrier.
// Since theta_held = 0, theta_unheld = 2 * theta_carrier.
carrierGroup.rotation.x = carrierAngle;
planetGroup.rotation.y = -2 * carrierAngle;
heldOutput.rotation.x = 0;
unheldOutput.rotation.x = 2 * carrierAngle;
placeLabel(labelHeld, labelPositions.held);
placeLabel(labelFree, labelPositions.free);
placeLabel(labelCarrier, labelPositions.carrier);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```