Prompt specification
Build or customize the Three.js 3D scene "Engage a Schematic Clutch" 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: Engage a Schematic Clutch
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/engage-a-schematic-clutch-x2018
Scene Description Prompt:
Make a cutaway Three.js scene in a self-contained HTML file using cdnjs: engage a schematic clutch. Animate two disks approaching and sharing rotation under an explicitly simplified coupling rule. Label omitted friction and heating rather than implying instantaneous physical synchronization is exact.
Working Three.js Starter (engage-a-schematic-clutch-x2018):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Schematic Cutaway Clutch</title>
<style>
:root {
color-scheme: dark;
--bg: #07121b;
--panel: rgba(10, 23, 34, 0.88);
--line: rgba(164, 213, 230, 0.18);
--text: #e8f4f7;
--muted: #93abb5;
--cyan: #58d6eb;
--violet: #c08cff;
--amber: #ffbd59;
--green: #74e0a3;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#app {
position: fixed;
inset: 0;
}
.glass {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
}
#title-block {
position: fixed;
top: 22px;
left: 24px;
z-index: 5;
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 39px);
font-weight: 720;
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 8px;
color: var(--muted);
font-size: 13px;
}
#warning {
position: fixed;
top: 22px;
left: 50%;
z-index: 7;
transform: translateX(-50%);
padding: 9px 14px;
border: 1px solid rgba(255, 189, 89, 0.5);
border-radius: 999px;
background: rgba(40, 28, 12, 0.86);
color: #ffd99b;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
white-space: nowrap;
pointer-events: none;
}
#panel {
position: fixed;
top: 92px;
right: 22px;
z-index: 8;
width: min(350px, calc(100vw - 44px));
max-height: calc(100vh - 116px);
padding: 18px;
border-radius: 18px;
overflow: auto;
}
.panel-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
#phase {
padding: 6px 9px;
border-radius: 999px;
border: 1px solid rgba(88, 214, 235, 0.38);
background: rgba(88, 214, 235, 0.09);
color: var(--cyan);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
text-align: center;
}
.section-title {
margin: 18px 0 9px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.timeline {
position: relative;
height: 6px;
overflow: hidden;
border-radius: 10px;
background: rgba(255, 255, 255, 0.08);
}
#timeline-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--cyan), var(--green));
box-shadow: 0 0 14px rgba(116, 224, 163, 0.4);
}
.timeline-labels {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: #6f8994;
font-size: 10px;
}
.readout {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.metric {
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
}
.metric-label {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
}
.metric-value {
margin-top: 4px;
font-variant-numeric: tabular-nums;
font-size: 18px;
font-weight: 760;
}
.metric-value.cyan { color: var(--cyan); }
.metric-value.violet { color: var(--violet); }
.metric-value.amber { color: var(--amber); }
.bar {
height: 4px;
margin-top: 8px;
overflow: hidden;
border-radius: 4px;
background: rgba(255, 255, 255, 0.07);
}
.bar > div {
width: 0;
height: 100%;
border-radius: inherit;
transition: width 80ms linear;
}
#omega1-bar { background: var(--cyan); }
#omega2-bar { background: var(--violet); }
.equation {
padding: 12px;
border: 1px solid rgba(88, 214, 235, 0.22);
border-radius: 12px;
background: rgba(17, 53, 65, 0.27);
font-family: Georgia, "Times New Roman", serif;
font-size: 16px;
line-height: 1.5;
text-align: center;
}
.equation small {
display: block;
margin-top: 7px;
color: var(--muted);
font-family: inherit;
font-size: 11px;
}
.disclaimer {
margin-top: 13px;
padding: 11px 12px;
border-left: 3px solid var(--amber);
border-radius: 0 10px 10px 0;
background: rgba(255, 189, 89, 0.07);
color: #dfcaa7;
font-size: 11px;
line-height: 1.55;
}
.disclaimer strong {
color: #ffd79a;
}
.buttons {
display: flex;
gap: 8px;
margin-top: 14px;
}
button {
flex: 1;
min-height: 36px;
border: 1px solid rgba(171, 218, 232, 0.24);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
}
button:hover {
border-color: rgba(88, 214, 235, 0.65);
background: rgba(88, 214, 235, 0.1);
}
button:active { transform: translateY(1px); }
#help {
position: fixed;
left: 24px;
bottom: 22px;
z-index: 6;
padding: 10px 13px;
border-radius: 12px;
color: var(--muted);
font-size: 11px;
pointer-events: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.scene-tag {
position: absolute;
transform: translate(-50%, -100%);
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(7, 18, 27, 0.82);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
color: var(--text);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.07em;
white-space: nowrap;
opacity: 0;
}
.scene-tag::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 17px;
background: currentColor;
opacity: 0.45;
}
#input-tag { color: var(--cyan); }
#output-tag { color: var(--violet); }
#cutaway-tag { color: var(--amber); }
#contact-tag { color: var(--green); }
@media (max-width: 800px) {
#warning {
top: 82px;
font-size: 9px;
}
#panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 43vh;
padding: 14px;
}
#title-block {
top: 15px;
left: 16px;
}
#help {
display: none;
}
.scene-tag { font-size: 8px; }
}
</style>
</head>
<body>
<div id="app"></div>
<header id="title-block">
<div class="eyebrow">Mechanical study / 01</div>
<h1>Schematic Cutaway Clutch</h1>
<div class="subtitle">Axial approach and simplified rotational coupling</div>
</header>
<div id="warning">CONCEPT ONLY · FRICTION + HEATING OMITTED</div>
<div id="labels" aria-hidden="true">
<div id="input-tag" class="scene-tag">INPUT · ω₁</div>
<div id="output-tag" class="scene-tag">OUTPUT · ω₂</div>
<div id="cutaway-tag" class="scene-tag">SECTIONED HOUSING</div>
<div id="contact-tag" class="scene-tag">SCHEMATIC CONTACT</div>
</div>
<aside id="panel" class="glass">
<div class="panel-row">
<span class="eyebrow" style="margin:0">Engagement state</span>
<span id="phase" aria-live="polite">APPROACH</span>
</div>
<div class="section-title">Sequence</div>
<div class="timeline"><div id="timeline-fill"></div></div>
<div class="timeline-labels">
<span>approach</span>
<span>contact</span>
<span>coupling ramp</span>
</div>
<div class="section-title">Angular velocities</div>
<div class="readout">
<div class="metric">
<div class="metric-label">INPUT ω₁</div>
<div id="omega1-value" class="metric-value cyan">1.80</div>
<div class="bar"><div id="omega1-bar"></div></div>
</div>
<div class="metric">
<div class="metric-label">OUTPUT ω₂</div>
<div id="omega2-value" class="metric-value violet">0.16</div>
<div class="bar"><div id="omega2-bar"></div></div>
</div>
<div class="metric">
<div class="metric-label">VELOCITY DIFFERENCE</div>
<div id="delta-value" class="metric-value amber">1.64</div>
</div>
<div class="metric">
<div class="metric-label">COUPLING κ</div>
<div id="kappa-value" class="metric-value">0.00</div>
</div>
</div>
<div class="section-title">Explicit simplified rule</div>
<div class="equation">
ω₂ ← ω₂ + [1 − e<sup>−κΔt</sup>] (ω₁ − ω₂)
<small>
Applied only after schematic contact; κ ramps from 0 to 1.
This is a kinematic velocity blend, not a friction or torque model.
</small>
</div>
<div class="disclaimer">
<strong>Not an exact physical synchronization model.</strong>
Friction, contact pressure, slip heating, torque transmission,
structural compliance, and losses are intentionally omitted.
</div>
<div class="buttons">
<button id="pause" type="button">Pause</button>
<button id="replay" type="button">Replay engagement</button>
<button id="reset-camera" type="button">Reset view</button>
</div>
</aside>
<div id="help" class="glass">
Drag: orbit · Right-drag / Shift-drag: pan · Wheel: zoom · Double-click: reset
</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 app = document.getElementById("app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07121b);
scene.fog = new THREE.FogExp2(0x07121b, 0.035);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xaedff1, 0x17202a, 1.45));
const keyLight = new THREE.DirectionalLight(0xdff8ff, 3.2);
keyLight.position.set(4.5, 7, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
scene.add(keyLight);
const cyanRim = new THREE.PointLight(0x38c9ef, 18, 11, 2);
cyanRim.position.set(-3.6, 2.3, -2.8);
scene.add(cyanRim);
const violetRim = new THREE.PointLight(0xb87aff, 16, 10, 2);
violetRim.position.set(3.2, 1.4, -2.4);
scene.add(violetRim);
const warmLight = new THREE.PointLight(0xffb44f, 9, 8, 2);
warmLight.position.set(0, 3.5, 1.5);
scene.add(warmLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x091722,
roughness: 0.93,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.96;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(20, 40, 0x27495a, 0x142c39);
grid.position.y = -1.945;
grid.material.transparent = true;
grid.material.opacity = 0.46;
scene.add(grid);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
function metal(color, roughness = 0.42, metalness = 0.72) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
function cylinderX(radius, length, material, radialSegments = 64) {
const geometry = new THREE.CylinderGeometry(
radius, radius, length, radialSegments, 1, false
);
geometry.rotateZ(Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function torusX(radius, tube, material, radialSegments = 16) {
const geometry = new THREE.TorusGeometry(
radius, tube, radialSegments, 72
);
geometry.rotateY(Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
return mesh;
}
function ringX(inner, outer, material, thetaStart, thetaLength) {
const geometry = new THREE.RingGeometry(
inner, outer, 18, 1, thetaStart, thetaLength
);
geometry.rotateY(Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
return mesh;
}
const housingMaterial = new THREE.MeshStandardMaterial({
color: 0x304752,
roughness: 0.48,
metalness: 0.62,
transparent: true,
opacity: 0.78,
side: THREE.DoubleSide
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xffb34e,
transparent: true,
opacity: 0.95
});
const darkMetal = metal(0x253640, 0.5, 0.78);
const bearingMaterial = metal(0x627985, 0.3, 0.9);
const amberMaterial = metal(0xf3a73f, 0.48, 0.58);
const amberDarkMaterial = metal(0xb86f2a, 0.52, 0.62);
// ------------------------------------------------------------
// Sectioned housing: a 210-degree shell, leaving the camera-facing
// upper/front quadrant removed to expose the mechanism.
// ------------------------------------------------------------
const housingLength = 4.8;
const housingRadius = 1.58;
const shellStart = Math.PI * (11 / 12);
const shellLengthAngle = Math.PI * (7 / 6);
const shellGeometry = new THREE.CylinderGeometry(
housingRadius,
housingRadius,
housingLength,
80,
1,
true,
shellStart,
shellLengthAngle
);
shellGeometry.rotateZ(Math.PI / 2);
const shell = new THREE.Mesh(shellGeometry, housingMaterial);
shell.castShadow = true;
shell.receiveShadow = true;
scene.add(shell);
// Thin end hoops preserve the housing silhouette.
for (const x of [-housingLength / 2, housingLength / 2]) {
const hoop = torusX(housingRadius, 0.055, bearingMaterial, 12);
hoop.position.x = x;
scene.add(hoop);
}
// Bright section boundaries.
for (const theta of [
shellStart,
shellStart + shellLengthAngle
]) {
const y = housingRadius * Math.sin(theta);
const z = housingRadius * Math.cos(theta);
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-housingLength / 2, y, z),
new THREE.Vector3(housingLength / 2, y, z)
]);
scene.add(new THREE.Line(geometry, edgeMaterial));
}
// Feet and support blocks.
const footMaterial = metal(0x1a2b35, 0.62, 0.64);
for (const x of [-1.75, 1.75]) {
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.62, 0.2, 1.55),
footMaterial
);
foot.position.set(x, -1.82, 0);
foot.castShadow = true;
scene.add(foot);
const strut = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.7, 0.38),
footMaterial
);
strut.position.set(x, -1.42, -0.25);
strut.castShadow = true;
scene.add(strut);
}
// ------------------------------------------------------------
// Clutch plates
// ------------------------------------------------------------
const plateThickness = 0.34;
const contactFaceOffset = plateThickness / 2;
function createPlate(isInput) {
const group = new THREE.Group();
const bodyMaterial = metal(
isInput ? 0x286371 : 0x554773,
0.38,
0.74
);
const accentMaterial = metal(
isInput ? 0x58d6eb : 0xc08cff,
0.3,
0.58
);
const body = cylinderX(1.10, 0.26, bodyMaterial, 72);
group.add(body);
// Outer rim on both faces.
for (const side of [-1, 1]) {
const rim = torusX(1.105, 0.105, darkMetal, 14);
rim.position.x = side * 0.135;
group.add(rim);
}
// Hub.
const hub = cylinderX(0.40, 0.48, accentMaterial, 56);
group.add(hub);
const hubCap = cylinderX(0.24, 0.53, darkMetal, 48);
group.add(hubCap);
// Radial spokes, one set on each face.
const spokeGeometry = new THREE.BoxGeometry(0.07, 0.115, 0.72);
for (const side of [-1, 1]) {
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const spoke = new THREE.Mesh(spokeGeometry, accentMaterial);
spoke.position.set(
side * 0.215,
Math.sin(angle) * 0.55,
Math.cos(angle) * 0.55
);
spoke.rotation.x = -angle;
spoke.castShadow = true;
group.add(spoke);
}
}
// Schematic contact pads on the inward-facing side.
const contactSide = isInput ? 1 : -1;
const sectorCount = 8;
const sectorArc = (Math.PI * 2) / sectorCount;
for (let i = 0; i < sectorCount; i++) {
const pad = ringX(
0.51,
1.055,
i % 2 === 0 ? amberMaterial : amberDarkMaterial,
i * sectorArc + 0.035,
sectorArc - 0.07
);
pad.position.x = contactSide * 0.16;
group.add(pad);
}
// A visible phase marker on the outer circumference.
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.23, 0.15),
accentMaterial
);
marker.position.set(0.22, 1.13, 0);
marker.castShadow = true;
group.add(marker);
scene.add(group);
return group;
}
const inputPlate = createPlate(true);
const outputPlate = createPlate(false);
// ------------------------------------------------------------
// Shafts and fixed bearing collars
// ------------------------------------------------------------
const inputShaft = new THREE.Group();
const inputShaftMesh = cylinderX(0.15, 2.85, bearingMaterial, 48);
inputShaftMesh.position.x = -1.1;
inputShaft.add(inputShaftMesh);
const inputKey = new THREE.Mesh(
new THREE.BoxGeometry(1.9, 0.06, 0.08),
metal(0x58d6eb, 0.35, 0.7)
);
inputKey.position.set(-1.15, 0.15, 0);
inputShaft.add(inputKey);
const outputShaft = new THREE.Group();
const outputShaftMesh = cylinderX(0.15, 2.85, bearingMaterial, 48);
outputShaftMesh.position.x = 1.1;
outputShaft.add(outputShaftMesh);
const outputKey = new THREE.Mesh(
new THREE.BoxGeometry(1.9, 0.06, 0.08),
metal(0xc08cff, 0.35, 0.7)
);
outputKey.position.set(1.15, 0.15, 0);
outputShaft.add(outputKey);
scene.add(inputShaft, outputShaft);
for (const x of [-2.42, 2.42]) {
const bearing = cylinderX(0.31, 0.22, darkMetal, 56);
bearing.position.x = x;
scene.add(bearing);
}
// Centerline.
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-3.1, 0, 0),
new THREE.Vector3(3.1, 0, 0)
]);
const axis = new THREE.Line(
axisGeometry,
new THREE.LineDashedMaterial({
color: 0x5ea8ba,
dashSize: 0.12,
gapSize: 0.09,
transparent: true,
opacity: 0.45
})
);
axis.computeLineDistances();
scene.add(axis);
// ------------------------------------------------------------
// Axial approach arrows and dynamic gap dimension
// ------------------------------------------------------------
const leftArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-1.6, 1.56, 0.05),
0.7,
0xffbd59,
0.16,
0.09
);
const rightArrow = new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(1.6, 1.56, 0.05),
0.7,
0xffbd59,
0.16,
0.09
);
scene.add(leftArrow, rightArrow);
for (const arrow of [leftArrow, rightArrow]) {
arrow.line.material.transparent = true;
arrow.cone.material.transparent = true;
}
const gapPositions = new Float32Array(18);
const gapGeometry = new THREE.BufferGeometry();
gapGeometry.setAttribute(
"position",
new THREE.BufferAttribute(gapPositions, 3)
.setUsage(THREE.DynamicDrawUsage)
);
const gapLine = new THREE.LineSegments(
gapGeometry,
new THREE.LineBasicMaterial({
color: 0xffbd59,
transparent: true,
opacity: 0.9
})
);
gapLine.frustumCulled = false;
scene.add(gapLine);
function updateGapLine(gap) {
const left = -gap / 2;
const right = gap / 2;
const y = -1.48;
const z = 1.12;
const tick = 0.10;
gapPositions.set([
left, y, z,
right, y, z,
left, y - tick, z,
left, y + tick, z,
right, y - tick, z,
right, y + tick, z
]);
gapGeometry.attributes.position.needsUpdate = true;
gapLine.visible = gap > 0.025;
}
// ------------------------------------------------------------
// Camera controls implemented without Three.js addons
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, -0.05, 0);
const spherical = new THREE.Spherical(10.2, 1.23, 0.36);
function applyCamera() {
const position = new THREE.Vector3()
.setFromSpherical(spherical)
.add(cameraTarget);
camera.position.copy(position);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraTarget.set(0, -0.05, 0);
spherical.set(10.2, 1.23, 0.36);
applyCamera();
}
let drag = null;
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
button: event.button,
pan: event.button === 2 || event.shiftKey
};
});
renderer.domElement.addEventListener("pointermove", event => {
if (!drag || drag.id !== event.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.pan) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const scale = spherical.radius * 0.00125;
cameraTarget.addScaledVector(right, -dx * scale);
cameraTarget.addScaledVector(up, dy * scale);
} else {
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi,
0.24,
Math.PI - 0.28
);
}
applyCamera();
});
function endDrag(event) {
if (drag && drag.id === event.pointerId) drag = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
4.4,
17
);
applyCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
resetCamera();
// ------------------------------------------------------------
// Simplified clutch model
//
// Before contact: plates approach axially with no coupling.
// After contact:
//
// omega2 += [1 - exp(-kappa * dt)] * (omega1 - omega2)
//
// kappa ramps from 0 to 1. No friction, pressure, torque, heating,
// structural compliance, or loss model is included.
// ------------------------------------------------------------
const phaseElement = document.getElementById("phase");
const timelineFill = document.getElementById("timeline-fill");
const omega1Value = document.getElementById("omega1-value");
const omega2Value = document.getElementById("omega2-value");
const deltaValue = document.getElementById("delta-value");
const kappaValue = document.getElementById("kappa-value");
const omega1Bar = document.getElementById("omega1-bar");
const omega2Bar = document.getElementById("omega2-bar");
const pauseButton = document.getElementById("pause");
const APPROACH_DURATION = 2.4;
const CONTACT_DURATION = 0.4;
const CONTACT_TIME = APPROACH_DURATION + CONTACT_DURATION;
const COUPLING_RAMP_DURATION = 0.9;
const INITIAL_GAP = 1.15;
const omega1 = 1.80;
let omega2 = 0.16;
let simulationTime = 0;
let inputAngle = 0;
let outputAngle = 0;
let paused = false;
function smoothstep01(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function resetSimulation() {
simulationTime = 0;
omega2 = 0.16;
inputAngle = 0;
outputAngle = 0;
paused = false;
pauseButton.textContent = "Pause";
}
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
document.getElementById("replay").addEventListener("click", resetSimulation);
document.getElementById("reset-camera").addEventListener("click", resetCamera);
function updateSimulation(dt) {
simulationTime += dt;
// Plate travel and contact.
let gap;
if (simulationTime < APPROACH_DURATION) {
const p = smoothstep01(simulationTime / APPROACH_DURATION);
gap = THREE.MathUtils.lerp(INITIAL_GAP, 0.08, p);
} else if (simulationTime < CONTACT_TIME) {
const p = smoothstep01(
(simulationTime - APPROACH_DURATION) / CONTACT_DURATION
);
gap = THREE.MathUtils.lerp(0.08, 0, p);
} else {
gap = 0;
}
inputPlate.position.x =
-contactFaceOffset - gap / 2;
outputPlate.position.x =
contactFaceOffset + gap / 2;
// Coupling starts only after the schematic contact point.
const kappa = smoothstep01(
(simulationTime - CONTACT_TIME) / COUPLING_RAMP_DURATION
);
if (kappa > 0) {
const blend = 1 - Math.exp(-3.0 * kappa * dt);
omega2 += blend * (omega1 - omega2);
}
inputAngle += omega1 * dt;
outputAngle += omega2 * dt;
inputPlate.rotation.x = inputAngle;
outputPlate.rotation.x = outputAngle;
inputShaft.rotation.x = inputAngle;
outputShaft.rotation.x = outputAngle;
updateGapLine(gap);
const arrowOpacity = THREE.MathUtils.clamp(
1 - (simulationTime - APPROACH_DURATION) / 0.45,
0,
1
);
leftArrow.visible = arrowOpacity > 0.01;
rightArrow.visible = arrowOpacity > 0.01;
leftArrow.line.material.opacity = arrowOpacity;
leftArrow.cone.material.opacity = arrowOpacity;
rightArrow.line.material.opacity = arrowOpacity;
rightArrow.cone.material.opacity = arrowOpacity;
leftArrow.position.set(
inputPlate.position.x - 0.86,
1.57,
0.05
);
rightArrow.position.set(
outputPlate.position.x + 0.86,
1.57,
0.05
);
// Interface and panel readouts.
if (simulationTime < APPROACH_DURATION) {
phaseElement.textContent = "AXIAL APPROACH";
} else if (simulationTime < CONTACT_TIME) {
phaseElement.textContent = "SCHEMATIC CONTACT";
} else if (simulationTime < CONTACT_TIME + COUPLING_RAMP_DURATION) {
phaseElement.textContent = "COUPLING RAMP";
} else {
phaseElement.textContent = "ENGAGED · HOLD";
}
const progress = THREE.MathUtils.clamp(
simulationTime / (CONTACT_TIME + COUPLING_RAMP_DURATION + 3),
0,
1
);
timelineFill.style.width = `${progress * 100}%`;
omega1Value.textContent = omega1.toFixed(2);
omega2Value.textContent = omega2.toFixed(2);
deltaValue.textContent = Math.abs(omega1 - omega2).toFixed(2);
kappaValue.textContent = kappa.toFixed(2);
omega1Bar.style.width = `${(omega1 / 2.1) * 100}%`;
omega2Bar.style.width = `${(omega2 / 2.1) * 100}%`;
}
// ------------------------------------------------------------
// Screen-space annotation positioning
// ------------------------------------------------------------
const labelElements = {
input: document.getElementById("input-tag"),
output: document.getElementById("output-tag"),
cutaway: document.getElementById("cutaway-tag"),
contact: document.getElementById("contact-tag")
};
function placeLabel(element, worldPosition) {
const projected = worldPosition.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) {
element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.opacity = "0.92";
}
function updateLabels() {
scene.updateMatrixWorld(true);
const inputAnchor = inputPlate.localToWorld(
new THREE.Vector3(0, 1.46, 0.15)
);
const outputAnchor = outputPlate.localToWorld(
new THREE.Vector3(0, 1.46, 0.15)
);
const cutawayTheta = shellStart;
const cutawayAnchor = new THREE.Vector3(
1.15,
housingRadius * Math.sin(cutawayTheta),
housingRadius * Math.cos(cutawayTheta)
);
const contactAnchor = new THREE.Vector3(
0,
1.28,
0.25
);
placeLabel(labelElements.input, inputAnchor);
placeLabel(labelElements.output, outputAnchor);
placeLabel(labelElements.cutaway, cutawayAnchor);
placeLabel(labelElements.contact, contactAnchor);
}
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
let previousTime = performance.now();
function render(now) {
requestAnimationFrame(render);
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) updateSimulation(dt);
updateLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(render);
</script>
</body>
</html>
```