Prompt specification
Build or customize the Three.js 3D scene "Proportional Position Control Dial" 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: Proportional Position Control Dial
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/proportional-position-control-dial-x2030
Scene Description Prompt:
Make a cutaway Three.js scene in a self-contained HTML file using cdnjs: proportional position control dial. Animate a simple first-order position model with a proportional controller. Show the declared equations and compare response when gain changes under fixed initial conditions.
Working Three.js Starter (proportional-position-control-dial-x2030):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cutaway Proportional Position Control</title>
<style>
:root {
--bg: #071018;
--panel: rgba(9, 20, 30, 0.88);
--panel-border: rgba(142, 202, 220, 0.22);
--text: #e8f4f7;
--muted: #8fa8b3;
--cyan: #4bf2d1;
--amber: #ffbd59;
--purple: #b58cff;
--pink: #ff6685;
--red: #ff5e70;
}
* { 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, input { font: inherit; }
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.topbar {
position: absolute;
z-index: 10;
top: 18px;
left: 18px;
right: 18px;
min-height: 52px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 10px 12px 10px 18px;
background: rgba(7, 16, 24, 0.76);
border: 1px solid var(--panel-border);
border-radius: 14px;
backdrop-filter: blur(14px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 31px;
height: 31px;
border: 2px solid var(--cyan);
border-radius: 50%;
position: relative;
flex: 0 0 auto;
box-shadow: 0 0 18px rgba(75, 242, 209, 0.2);
}
.brand-mark::before {
content: "";
position: absolute;
width: 2px;
height: 13px;
left: 13px;
top: 2px;
background: var(--cyan);
transform-origin: 50% 100%;
transform: rotate(38deg);
}
.brand h1 {
margin: 0;
font-size: 14px;
font-weight: 700;
letter-spacing: 0.12em;
white-space: nowrap;
}
.brand p {
margin: 3px 0 0;
color: var(--muted);
font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.toolbar {
display: flex;
gap: 7px;
flex-wrap: wrap;
justify-content: flex-end;
}
button {
border: 1px solid rgba(148, 199, 214, 0.25);
border-radius: 8px;
background: rgba(23, 42, 54, 0.82);
color: var(--text);
padding: 8px 11px;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.035em;
cursor: pointer;
transition: background 150ms, border-color 150ms, transform 150ms;
}
button:hover {
background: rgba(39, 70, 84, 0.95);
border-color: rgba(75, 242, 209, 0.55);
}
button:active { transform: translateY(1px); }
button.primary {
color: #061814;
background: var(--cyan);
border-color: var(--cyan);
}
button.active {
color: var(--cyan);
border-color: var(--cyan);
background: rgba(75, 242, 209, 0.11);
}
.panel {
position: absolute;
z-index: 9;
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 14px;
backdrop-filter: blur(15px);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 13px 15px 10px;
border-bottom: 1px solid rgba(145, 199, 215, 0.13);
}
.panel-title h2 {
margin: 0;
font-size: 11px;
letter-spacing: 0.14em;
font-weight: 750;
}
.eyebrow {
color: var(--cyan);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.09em;
}
.equations {
top: 86px;
right: 18px;
width: 348px;
padding-bottom: 12px;
}
.equation-list {
padding: 8px 15px 5px;
}
.eq-row {
display: grid;
grid-template-columns: 94px 1fr;
align-items: baseline;
gap: 8px;
padding: 8px 0;
border-bottom: 1px dashed rgba(151, 195, 207, 0.12);
}
.eq-row:last-child { border-bottom: 0; }
.eq-name {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
}
.eq-code {
color: #effffb;
font: 12px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.eq-code .accent { color: var(--cyan); }
.fixed-note {
margin: 5px 15px 0;
padding: 8px 10px;
border-radius: 8px;
color: #b9ccd3;
background: rgba(75, 242, 209, 0.055);
border: 1px solid rgba(75, 242, 209, 0.12);
font: 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.fixed-note b { color: var(--cyan); }
.controls {
left: 18px;
bottom: 18px;
width: 364px;
padding: 15px;
}
.control-head {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.control-head label {
display: block;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.gain-value {
color: var(--cyan);
font: 25px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 700;
}
.gain-value small {
color: var(--muted);
font-size: 10px;
font-weight: 400;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 8px 0 14px;
appearance: none;
border-radius: 999px;
outline: none;
background: linear-gradient(
to right,
var(--cyan) 0%,
var(--cyan) var(--fill, 5%),
rgba(131, 171, 185, 0.2) var(--fill, 5%),
rgba(131, 171, 185, 0.2) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
appearance: none;
width: 16px;
height: 16px;
border-radius: 50%;
border: 2px solid #dffff8;
background: var(--cyan);
box-shadow: 0 0 12px rgba(75, 242, 209, 0.45);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border-radius: 50%;
border: 2px solid #dffff8;
background: var(--cyan);
}
.hint {
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.hint strong { color: #cfe4e9; }
.button-row {
display: flex;
gap: 7px;
margin: 12px 0;
}
.button-row button { flex: 1; }
.presets {
display: flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
}
.presets > span {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
margin-right: 3px;
}
.presets button {
padding: 6px 9px;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.telemetry {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 13px;
}
.metric {
padding: 8px 7px;
border-radius: 8px;
background: rgba(2, 9, 14, 0.52);
border: 1px solid rgba(136, 190, 207, 0.12);
}
.metric span {
display: block;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.09em;
}
.metric b {
display: block;
margin-top: 4px;
color: var(--text);
font: 13px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.chart {
right: 18px;
bottom: 18px;
width: 548px;
padding-bottom: 10px;
}
#plot {
display: block;
width: 100%;
height: 225px;
overflow: visible;
}
.grid-line {
stroke: rgba(159, 200, 213, 0.11);
stroke-width: 1;
}
.axis-line {
stroke: rgba(183, 220, 231, 0.32);
stroke-width: 1;
}
.axis-text {
fill: #829da8;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.chart-legend {
display: flex;
gap: 14px;
flex-wrap: wrap;
padding: 0 15px;
color: #a9bdc5;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-swatch {
width: 18px;
height: 2px;
background: var(--cyan);
}
.legend-swatch.dashed {
height: 0;
border-top: 2px dashed currentColor;
background: none;
}
.comparison-table {
display: none;
grid-template-columns: 1.25fr 1fr 1fr;
gap: 4px 12px;
margin: 11px 15px 0;
padding: 9px 10px;
border-radius: 8px;
background: rgba(1, 8, 12, 0.48);
color: #a7bcc5;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.comparison-table.visible { display: grid; }
.comparison-table .head {
color: #718c97;
letter-spacing: 0.07em;
}
.comparison-table b {
color: #dbe8ec;
font-weight: 500;
}
.world-label {
position: absolute;
z-index: 5;
left: 0;
top: 0;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
padding: 5px 8px;
border-radius: 6px;
color: #dff8f4;
background: rgba(4, 13, 19, 0.78);
border: 1px solid rgba(75, 242, 209, 0.38);
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
}
.world-label.target {
color: #ffd9df;
border-color: rgba(255, 94, 112, 0.48);
}
.world-label.gain {
color: #d9fff7;
border-color: rgba(75, 242, 209, 0.6);
}
.status {
position: absolute;
z-index: 8;
top: 86px;
left: 18px;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border-radius: 999px;
color: #b7cbd1;
background: rgba(5, 14, 21, 0.72);
border: 1px solid rgba(139, 193, 207, 0.16);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 9px var(--cyan);
}
@media (max-width: 1100px) {
.equations { width: 310px; }
.chart { width: 475px; }
.controls { width: 330px; }
}
@media (max-width: 820px) {
.brand p { display: none; }
.toolbar button { padding: 7px 8px; }
.equations {
top: 82px;
right: 12px;
width: 285px;
max-height: calc(100vh - 335px);
overflow: auto;
}
.chart { display: none; }
.controls {
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
}
.status { left: 12px; top: 82px; }
}
@media (max-width: 560px) {
.brand h1 { font-size: 10px; letter-spacing: 0.08em; }
.brand-mark { display: none; }
.topbar { left: 10px; right: 10px; top: 10px; }
.toolbar button { font-size: 9px; }
.equations { top: 72px; right: 10px; width: 245px; }
.status { display: none; }
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" aria-label="Interactive cutaway proportional position control scene"></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-mark"></div>
<div>
<h1>PROPORTIONAL POSITION CONTROL</h1>
<p>CUTAWAY ACTUATOR · FIRST-ORDER RESPONSE LAB</p>
</div>
</div>
<div class="toolbar">
<button id="resetView">Reset view</button>
<button id="pauseButton" class="primary">Pause</button>
<button id="restartButton">Restart at x₀</button>
<button id="compareButton">Compare gains</button>
</div>
</header>
<div class="status">
<span class="status-dot"></span>
<span id="statusText">RUNNING · FIXED-INITIAL-CONDITION TRIAL</span>
</div>
<aside class="panel equations">
<div class="panel-title">
<h2>DECLARED MODEL</h2>
<span class="eyebrow">CLOSED LOOP</span>
</div>
<div class="equation-list">
<div class="eq-row">
<span class="eq-name">Controller</span>
<code class="eq-code">u(t) = <span class="accent">Kₚ</span>[r(t) − x(t)]</code>
</div>
<div class="eq-row">
<span class="eq-name">Plant</span>
<code class="eq-code">ẋ(t) = [−x(t) + Kᵤu(t)] / τ</code>
</div>
<div class="eq-row">
<span class="eq-name">Closed loop</span>
<code class="eq-code">ẋ = −<span id="eqLambda">1.32</span>x + <span id="eqDrive">1.32</span>r</code>
</div>
<div class="eq-row">
<span class="eq-name">Solution</span>
<code class="eq-code">x(t)=x∞+(x₀−x∞)e<sup>−λt</sup></code>
</div>
<div class="eq-row">
<span class="eq-name">Steady state</span>
<code class="eq-code">x∞ = <span id="eqXInfinity">0.569</span></code>
</div>
<div class="eq-row">
<span class="eq-name">Closed τ</span>
<code class="eq-code">τcl = <span id="eqTau">0.689</span> s</code>
</div>
</div>
<div class="fixed-note">
Fixed trial: <b>r = 1.00</b>, <b>x(0) = 0.05</b><br>
Constants: <b>τ = 1.60 s</b>, <b>Kᵤ = 2.40</b>
</div>
</aside>
<aside class="panel controls">
<div class="control-head">
<div>
<label>Proportional gain</label>
<div class="hint">Drag the 3D dial or use the slider.</div>
</div>
<div class="gain-value">
Kₚ <span id="gainValue">0.55</span><small> / 8.00</small>
</div>
</div>
<input id="gainSlider" type="range" min="0.2" max="8" step="0.05" value="0.55" />
<div class="hint">
Every gain change restarts the model with the same initial position,
<strong>x(0) = 0.05</strong>. Higher Kₚ raises the final position and
shortens the closed-loop time constant.
</div>
<div class="button-row">
<button id="pauseButton2" class="primary">Pause</button>
<button id="restartButton2">Restart</button>
</div>
<div class="presets">
<span>FIXED-x₀ PRESETS</span>
<button data-gain="0.5">Kₚ 0.5</button>
<button data-gain="2">Kₚ 2</button>
<button data-gain="6">Kₚ 6</button>
</div>
<div class="telemetry">
<div class="metric">
<span>POSITION x</span>
<b id="positionMetric">0.050</b>
</div>
<div class="metric">
<span>ERROR r−x</span>
<b id="errorMetric">0.950</b>
</div>
<div class="metric">
<span>CONTROL u</span>
<b id="controlMetric">0.275</b>
</div>
</div>
</aside>
<aside class="panel chart">
<div class="panel-title">
<h2>FIXED-INITIAL-CONDITION RESPONSE</h2>
<span class="eyebrow">x(0) = 0.05 · r = 1.00</span>
</div>
<svg id="plot" viewBox="0 0 540 250" aria-label="Position response graph">
<g id="grid"></g>
<path id="cmp05"
fill="none"
stroke="#ffbd59"
stroke-width="2"
stroke-dasharray="6 5"
opacity="0.85"></path>
<path id="cmp2"
fill="none"
stroke="#b58cff"
stroke-width="2"
stroke-dasharray="6 5"
opacity="0.85"></path>
<path id="cmp6"
fill="none"
stroke="#ff6685"
stroke-width="2"
stroke-dasharray="6 5"
opacity="0.85"></path>
<path id="currentPath"
fill="none"
stroke="#4bf2d1"
stroke-width="3"
stroke-linecap="round"
stroke-linejoin="round"></path>
<line id="timeCursor"
x1="50" x2="50"
y1="18" y2="218"
stroke="rgba(214,239,244,0.28)"
stroke-width="1"
stroke-dasharray="3 4"></line>
<circle id="liveDot"
cx="50" cy="218"
r="4.5"
fill="#effffb"
stroke="#4bf2d1"
stroke-width="2"></circle>
</svg>
<div class="chart-legend">
<span class="legend-item">
<i class="legend-swatch"></i><span id="currentLegend">SELECTED Kₚ = 0.55</span>
</span>
<span class="legend-item" style="color:#ffbd59">
<i class="legend-swatch dashed"></i>Kₚ 0.5
</span>
<span class="legend-item" style="color:#b58cff">
<i class="legend-swatch dashed"></i>Kₚ 2
</span>
<span class="legend-item" style="color:#ff6685">
<i class="legend-swatch dashed"></i>Kₚ 6
</span>
</div>
<div id="comparisonTable" class="comparison-table">
<span class="head">TRIAL</span>
<span class="head">x∞</span>
<span class="head">τcl</span>
<span style="color:#ffbd59">Kₚ = 0.5</span>
<b>0.545</b><b>0.727 s</b>
<span style="color:#b58cff">Kₚ = 2</span>
<b>0.828</b><b>0.276 s</b>
<span style="color:#ff6685">Kₚ = 6</span>
<b>0.935</b><b>0.104 s</b>
</div>
</aside>
<div id="labelDial" class="world-label gain">Kₚ DIAL · 0.55</div>
<div id="labelTarget" class="world-label target">SETPOINT r = 1.00</div>
<div id="labelPosition" class="world-label">POSITION x = 0.050</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
/* ------------------------------------------------------------------
Model and UI state
------------------------------------------------------------------ */
const params = {
tau: 1.60,
Ku: 2.40,
r: 1.00,
x0: 0.05,
gain: 0.55,
minGain: 0.20,
maxGain: 8.00,
trialTime: 8.0
};
const sim = {
t: 0,
x: params.x0,
running: true,
compareVisible: false
};
const $ = selector => document.querySelector(selector);
const canvas = $("#scene");
const gainSlider = $("#gainSlider");
const gainValue = $("#gainValue");
/* ------------------------------------------------------------------
Renderer, scene, camera, and lights
------------------------------------------------------------------ */
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.FogExp2(0x071018, 0.035);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
radius: 14.2,
theta: 0.67,
phi: 1.13,
target: new THREE.Vector3(0, 2.75, 0)
};
function updateCamera() {
const s = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(s).add(cameraState.target);
camera.lookAt(cameraState.target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xbfefff, 0x102028, 1.55));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.0);
keyLight.position.set(5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x42d8ff, 2.1);
rimLight.position.set(-7, 5, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb65d, 24, 18, 2);
warmLight.position.set(-3, 4, 4);
scene.add(warmLight);
/* ------------------------------------------------------------------
Materials and geometry helpers
------------------------------------------------------------------ */
const materials = {
base: new THREE.MeshStandardMaterial({
color: 0x142833,
metalness: 0.72,
roughness: 0.38
}),
frame: new THREE.MeshStandardMaterial({
color: 0x29424b,
metalness: 0.82,
roughness: 0.29
}),
dark: new THREE.MeshStandardMaterial({
color: 0x0b151c,
metalness: 0.66,
roughness: 0.42
}),
steel: new THREE.MeshStandardMaterial({
color: 0xa9bdc4,
metalness: 0.92,
roughness: 0.22
}),
brushed: new THREE.MeshStandardMaterial({
color: 0x607983,
metalness: 0.88,
roughness: 0.33
}),
copper: new THREE.MeshStandardMaterial({
color: 0xd77a3e,
metalness: 0.83,
roughness: 0.26
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x4bf2d1,
emissive: 0x0b8f78,
emissiveIntensity: 0.8,
metalness: 0.42,
roughness: 0.24
}),
red: new THREE.MeshStandardMaterial({
color: 0xff5e70,
emissive: 0x8c1023,
emissiveIntensity: 0.85,
metalness: 0.35,
roughness: 0.25
}),
amber: new THREE.MeshStandardMaterial({
color: 0xffbd59,
emissive: 0x8a4a08,
emissiveIntensity: 0.65,
metalness: 0.5,
roughness: 0.3
}),
glass: new THREE.MeshStandardMaterial({
color: 0x77d8ef,
transparent: true,
opacity: 0.17,
metalness: 0.05,
roughness: 0.15,
side: THREE.DoubleSide,
depthWrite: false
}),
backGlass: new THREE.MeshStandardMaterial({
color: 0x21495c,
transparent: true,
opacity: 0.11,
metalness: 0.08,
roughness: 0.35,
side: THREE.DoubleSide,
depthWrite: false
})
};
function addBox(w, h, d, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(radius, height, material, x, y, z, parent = scene, segments = 48) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x7fa4ae, opacity = 0.32) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 25),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(edges);
return edges;
}
/* ------------------------------------------------------------------
Floor, base, and open cutaway frame
------------------------------------------------------------------ */
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x08131b,
metalness: 0.25,
roughness: 0.82
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.03;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(36, 36, 0x24414c, 0x152832);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const base = addBox(9.3, 0.58, 5.1, materials.base, 0, 0.29, 0);
addEdges(base, 0x86b5bf, 0.26);
addBox(8.35, 0.12, 4.25, materials.dark, 0, 0.64, 0);
addBox(5.5, 0.10, 3.25, materials.brushed, -0.5, 0.73, -0.35);
const backPanel = addBox(
8.45, 5.35, 0.13,
materials.backGlass,
0, 3.35, -1.24
);
addEdges(backPanel, 0x70b9ca, 0.22);
// Open frame: the front cover is intentionally removed.
const frameParts = [
addBox(0.24, 5.45, 0.28, materials.frame, -4.16, 3.33, 0.13),
addBox(0.24, 5.45, 0.28, materials.frame, 4.16, 3.33, 0.13),
addBox(8.55, 0.25, 0.30, materials.frame, 0, 5.98, 0.13),
addBox(8.55, 0.25, 0.30, materials.frame, 0, 0.73, 0.13)
];
frameParts.forEach(part => addEdges(part, 0x8eb6bf, 0.25));
// Front cutaway rim.
addBox(8.5, 0.06, 0.08, materials.cyan, 0, 5.84, 0.32);
addBox(0.06, 5.1, 0.08, materials.cyan, -4.03, 3.31, 0.32);
addBox(0.06, 5.1, 0.08, materials.cyan, 4.03, 3.31, 0.32);
// Corner fasteners.
for (const x of [-4.13, 4.13]) {
for (const y of [0.82, 5.87]) {
const bolt = addCylinder(0.095, 0.12, materials.steel, x, y, 0.36);
bolt.rotation.x = Math.PI / 2;
}
}
/* ------------------------------------------------------------------
Motor, gears, and coupling
------------------------------------------------------------------ */
const motor = new THREE.Group();
motor.position.set(-0.92, 3.24, -0.52);
scene.add(motor);
const motorBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.64, 0.64, 1.78, 48),
materials.brushed
);
motorBody.rotation.z = Math.PI / 2;
motorBody.castShadow = true;
motor.add(motorBody);
for (const x of [-0.91, 0.91]) {
const end = new THREE.Mesh(
new THREE.CylinderGeometry(0.68, 0.68, 0.12, 48),
materials.dark
);
end.rotation.z = Math.PI / 2;
end.position.x = x;
motor.add(end);
}
for (let i = 0; i < 7; i++) {
const coil = new THREE.Mesh(
new THREE.TorusGeometry(0.665, 0.045, 10, 40),
materials.copper
);
coil.rotation.y = Math.PI / 2;
coil.position.x = -0.65 + i * 0.215;
motor.add(coil);
}
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.12, 1.0, 24),
materials.steel
);
shaft.rotation.z = Math.PI / 2;
shaft.position.set(1.15, 0, 0);
motor.add(shaft);
function createGear(radius, colorMaterial, x, y, z, teeth = 18) {
const group = new THREE.Group();
group.position.set(x, y, z);
scene.add(group);
const disk = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, 0.22, 48),
colorMaterial
);
disk.rotation.x = Math.PI / 2;
disk.castShadow = true;
group.add(disk);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius * 0.73, 0.055, 10, 48),
materials.steel
);
ring.position.z = 0.12;
group.add(ring);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(radius * 0.23, radius * 0.23, 0.30, 32),
materials.dark
);
hub.rotation.x = Math.PI / 2;
hub.position.z = 0.04;
group.add(hub);
for (let i = 0; i < teeth; i++) {
const angle = (i / teeth) * Math.PI * 2;
const tooth = addBox(
radius * 0.18,
radius * 0.34,
0.25,
colorMaterial,
Math.cos(angle) * radius * 1.07,
Math.sin(angle) * radius * 1.07,
0,
group
);
tooth.rotation.z = angle;
}
return group;
}
const gearA = createGear(0.62, materials.amber, -0.38, 3.24, 0.73, 18);
const gearB = createGear(0.76, materials.brushed, 0.62, 3.24, 0.73, 22);
/* ------------------------------------------------------------------
Sectioned actuator, helical screw, and moving carriage
------------------------------------------------------------------ */
const actuatorX = 1.85;
const actuatorZ = -0.12;
const actuatorBottom = 0.88;
const actuatorRange = 3.95;
// 270° shell with the front 90° section removed.
const casing = new THREE.Mesh(
new THREE.CylinderGeometry(
1.10, 1.10, 4.35, 64, 1, true,
Math.PI / 4,
Math.PI * 1.5
),
materials.glass
);
casing.position.set(actuatorX, 3.05, actuatorZ);
casing.renderOrder = 3;
scene.add(casing);
for (const theta of [Math.PI / 4, Math.PI * 1.75]) {
const px = actuatorX + Math.sin(theta) * 1.105;
const pz = actuatorZ + Math.cos(theta) * 1.105;
const cutEdge = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(px, 0.87, pz),
new THREE.Vector3(px, 5.23, pz)
]),
new THREE.LineBasicMaterial({
color: 0xffbd59,
transparent: true,
opacity: 0.95
})
);
scene.add(cutEdge);
}
const lowerBearing = addCylinder(
1.03, 0.32, materials.dark, actuatorX, 1.02, actuatorZ
);
const upperBearing = addCylinder(
1.03, 0.30, materials.dark, actuatorX, 5.08, actuatorZ
);
addEdges(lowerBearing, 0x789aa4, 0.25);
addEdges(upperBearing, 0x789aa4, 0.25);
const screwCore = addCylinder(
0.145, 4.0, materials.steel, actuatorX, 3.04, actuatorZ
);
class HelixCurve extends THREE.Curve {
constructor(cx, cz, y0, y1, radius, turns) {
super();
this.cx = cx;
this.cz = cz;
this.y0 = y0;
this.y1 = y1;
this.radius = radius;
this.turns = turns;
}
getPoint(t, target = new THREE.Vector3()) {
const angle = t * Math.PI * 2 * this.turns;
return target.set(
this.cx + Math.cos(angle) * this.radius,
this.y0 + (this.y1 - this.y0) * t,
this.cz + Math.sin(angle) * this.radius
);
}
}
const thread = new THREE.Mesh(
new THREE.TubeGeometry(
new HelixCurve(actuatorX, actuatorZ, 1.15, 4.94, 0.20, 13),
360,
0.035,
6,
false
),
materials.copper
);
thread.castShadow = true;
scene.add(thread);
const carriage = new THREE.Group();
carriage.position.set(actuatorX, actuatorBottom, actuatorZ);
scene.add(carriage);
const collar = addCylinder(
0.48, 0.62, materials.brushed, 0, 0, 0, carriage
);
addEdges(collar, 0x8fb0b8, 0.3);
addBox(1.82, 0.16, 0.16, materials.amber, 0.92, 0, 0.28, carriage);
addBox(0.30, 0.44, 0.34, materials.cyan, 1.86, 0, 0.28, carriage);
/* ------------------------------------------------------------------
Position gauge, target, actual marker, and error indicator
------------------------------------------------------------------ */
const gaugeX = 3.72;
const gaugeZ = 0.48;
addBox(0.08, 4.55, 0.09, materials.steel, gaugeX, 3.0, gaugeZ);
for (let i = 0; i <= 10; i++) {
const y = actuatorBottom + (i / 10) * actuatorRange;
const major = i % 5 === 0;
addBox(
major ? 0.30 : 0.18,
0.035,
0.05,
major ? materials.steel : materials.brushed,
gaugeX + (major ? 0.12 : 0.07),
y,
gaugeZ + 0.05
);
}
const targetY = actuatorBottom + params.r * actuatorRange;
const actualMarker = new THREE.Group();
actualMarker.position.set(gaugeX, actuatorBottom, gaugeZ + 0.14);
scene.add(actualMarker);
addBox(0.62, 0.12, 0.16, materials.cyan, 0.17, 0, 0, actualMarker);
addCylinder(0.105, 0.18, materials.cyan, 0, 0, 0, actualMarker).rotation.x =
Math.PI / 2;
const targetMarker = new THREE.Group();
targetMarker.position.set(gaugeX, targetY, gaugeZ + 0.14);
scene.add(targetMarker);
addBox(0.62, 0.075, 0.15, materials.red, 0.17, 0, 0, targetMarker);
addCylinder(0.09, 0.18, materials.red, 0, 0, 0, targetMarker).rotation.x =
Math.PI / 2;
const errorBar = new THREE.Mesh(
new THREE.BoxGeometry(0.065, 1, 0.07),
materials.red
);
errorBar.position.set(gaugeX + 0.35, actuatorBottom, gaugeZ + 0.14);
scene.add(errorBar);
/* ------------------------------------------------------------------
Interactive 3D proportional-gain dial
------------------------------------------------------------------ */
const dialCenter = new THREE.Vector3(-2.48, 3.42, 1.08);
const dialGroup = new THREE.Group();
dialGroup.position.copy(dialCenter);
scene.add(dialGroup);
const dialFace = new THREE.Mesh(
new THREE.CylinderGeometry(1.48, 1.48, 0.28, 64),
materials.dark
);
dialFace.rotation.x = Math.PI / 2;
dialFace.castShadow = true;
dialGroup.add(dialFace);
const dialOuterRing = new THREE.Mesh(
new THREE.TorusGeometry(1.43, 0.09, 12, 72),
materials.brushed
);
dialOuterRing.position.z = 0.17;
dialGroup.add(dialOuterRing);
const dialInnerRing = new THREE.Mesh(
new THREE.TorusGeometry(1.13, 0.025, 8, 72),
materials.brushed
);
dialInnerRing.position.z = 0.17;
dialGroup.add(dialInnerRing);
const knob = new THREE.Mesh(
new THREE.CylinderGeometry(0.46, 0.46, 0.38, 48),
materials.brushed
);
knob.rotation.x = Math.PI / 2;
knob.position.z = 0.31;
knob.castShadow = true;
dialGroup.add(knob);
const knobCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.35, 0.35, 0.06, 48),
materials.dark
);
knobCap.rotation.x = Math.PI / 2;
knobCap.position.z = 0.53;
dialGroup.add(knobCap);
const pointerPivot = new THREE.Group();
pointerPivot.position.copy(dialCenter);
pointerPivot.position.z += 0.57;
scene.add(pointerPivot);
const pointer = new THREE.Mesh(
new THREE.BoxGeometry(0.95, 0.075, 0.075),
materials.cyan
);
pointer.position.x = 0.47;
pointer.castShadow = true;
pointerPivot.add(pointer);
const pointerTip = new THREE.Mesh(
new THREE.ConeGeometry(0.10, 0.22, 20),
materials.cyan
);
pointerTip.rotation.z = -Math.PI / 2;
pointerTip.position.x = 0.99;
pointerPivot.add(pointerTip);
// Tick marks over the 270° gain sweep.
for (let i = 0; i <= 30; i++) {
const g = i / 30;
const angle = THREE.MathUtils.degToRad(-225 + 270 * g);
const major = i % 5 === 0;
const tick = addBox(
major ? 0.065 : 0.04,
major ? 0.23 : 0.13,
0.045,
major ? materials.steel : materials.brushed,
dialCenter.x + Math.cos(angle) * 1.30,
dialCenter.y + Math.sin(angle) * 1.30,
dialCenter.z + 0.19
);
tick.rotation.z = angle;
}
// Full sweep, faint.
const fullSweepPoints = [];
for (let i = 0; i <= 80; i++) {
const g = i / 80;
const angle = THREE.MathUtils.degToRad(-225 + 270 * g);
fullSweepPoints.push(new THREE.Vector3(
dialCenter.x + Math.cos(angle) * 1.13,
dialCenter.y + Math.sin(angle) * 1.13,
dialCenter.z + 0.19
));
}
scene.add(new THREE.Line(
new THREE.BufferGeometry().setFromPoints(fullSweepPoints),
new THREE.LineBasicMaterial({
color: 0x47707d,
transparent: true,
opacity: 0.55
})
));
let brightArc = null;
function updateDialGeometry() {
const g = (params.gain - params.minGain) /
(params.maxGain - params.minGain);
const angle = THREE.MathUtils.degToRad(-225 + 270 * g);
pointerPivot.rotation.z = angle;
const points = [];
for (let i = 0; i <= 60; i++) {
const a = THREE.MathUtils.degToRad(-225 + 270 * g * (i / 60));
points.push(new THREE.Vector3(
dialCenter.x + Math.cos(a) * 1.13,
dialCenter.y + Math.sin(a) * 1.13,
dialCenter.z + 0.19
));
}
if (brightArc) {
scene.remove(brightArc);
brightArc.geometry.dispose();
brightArc.material.dispose();
}
brightArc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({ color: 0x4bf2d1 })
);
scene.add(brightArc);
}
/* ------------------------------------------------------------------
Response plot
------------------------------------------------------------------ */
const plot = {
left: 50,
right: 505,
top: 18,
bottom: 218,
width: 455,
height: 200,
xMax: params.trialTime,
yMax: 1.05
};
function sx(t) {
return plot.left + (t / plot.xMax) * plot.width;
}
function sy(x) {
return plot.bottom - (x / plot.yMax) * plot.height;
}
function responseAt(kp, t) {
const k = kp * params.Ku;
const xInfinity = k / (1 + k);
const lambda = (1 + k) / params.tau;
return xInfinity + (params.x0 - xInfinity) * Math.exp(-lambda * t);
}
function responsePath(kp) {
let path = "";
const count = 180;
for (let i = 0; i <= count; i++) {
const t = (i / count) * params.trialTime;
const x = responseAt(kp, t);
path += `${i === 0 ? "M" : "L"}${sx(t).toFixed(2)},${sy(x).toFixed(2)} `;
}
return path;
}
function buildPlotGrid() {
const gridGroup = $("#grid");
let markup = "";
for (let i = 0; i <= 4; i++) {
const x = plot.left + (i / 4) * plot.width;
markup += `
<line class="grid-line" x1="${x}" x2="${x}" y1="${plot.top}" y2="${plot.bottom}"></line>
<text class="axis-text" x="${x}" y="238" text-anchor="middle">${(i / 4) * params.trialTime}s</text>
`;
}
for (let i = 0; i <= 4; i++) {
const value = (i / 4) * 1.0;
const y = sy(value);
markup += `
<line class="grid-line" x1="${plot.left}" x2="${plot.right}" y1="${y}" y2="${y}"></line>
<text class="axis-text" x="37" y="${y + 3}" text-anchor="end">${value.toFixed(2)}</text>
`;
}
markup += `
<line class="axis-line" x1="${plot.left}" x2="${plot.right}" y1="${plot.bottom}" y2="${plot.bottom}"></line>
<line class="axis-line" x1="${plot.left}" x2="${plot.left}" y1="${plot.top}" y2="${plot.bottom}"></line>
<text class="axis-text" x="278" y="248" text-anchor="middle">TIME t</text>
<text class="axis-text" x="13" y="118" text-anchor="middle" transform="rotate(-90 13 118)">POSITION x</text>
`;
gridGroup.innerHTML = markup;
}
function updatePlot() {
$("#currentPath").setAttribute("d", responsePath(params.gain));
$("#cmp05").setAttribute("d", responsePath(0.5));
$("#cmp2").setAttribute("d", responsePath(2));
$("#cmp6").setAttribute("d", responsePath(6));
const visible = sim.compareVisible ? "inline" : "none";
$("#cmp05").style.display = visible;
$("#cmp2").style.display = visible;
$("#cmp6").style.display = visible;
$("#comparisonTable").classList.toggle("visible", sim.compareVisible);
$("#currentLegend").textContent =
`SELECTED Kₚ = ${params.gain.toFixed(2)}`;
}
buildPlotGrid();
updatePlot();
/* ------------------------------------------------------------------
Gain updates, model reset, and equation readouts
------------------------------------------------------------------ */
function updateEquationReadouts() {
const k = params.gain * params.Ku;
const xInfinity = k / (1 + k);
const tauClosed = params.tau / (1 + k);
$("#eqLambda").textContent = (1 + k).toFixed(3);
$("#eqDrive").textContent = k.toFixed(3);
$("#eqXInfinity").textContent = xInfinity.toFixed(3);
$("#eqTau").textContent = tauClosed.toFixed(3);
}
function updatePauseButtons() {
const text = sim.running ? "Pause" : "Run";
$("#pauseButton").textContent = text;
$("#pauseButton2").textContent = text;
$("#statusText").textContent = sim.running
? "RUNNING · FIXED-INITIAL-CONDITION TRIAL"
: "PAUSED · MODEL STATE HELD";
}
function resetSimulation() {
sim.t = 0;
sim.x = params.x0;
sim.running = true;
updatePauseButtons();
updateTelemetry();
}
function setGain(value, restart = true) {
params.gain = THREE.MathUtils.clamp(
Number(value),
params.minGain,
params.maxGain
);
gainValue.textContent = params.gain.toFixed(2);
gainSlider.value = params.gain;
const pct = 100 *
(params.gain - params.minGain) /
(params.maxGain - params.minGain);
gainSlider.style.setProperty("--fill", `${pct}%`);
updateDialGeometry();
updateEquationReadouts();
updatePlot();
if (restart) resetSimulation();
}
function updateTelemetry() {
const error = params.r - sim.x;
const control = params.gain * error;
$("#positionMetric").textContent = sim.x.toFixed(3);
$("#errorMetric").textContent = error.toFixed(3);
$("#controlMetric").textContent = control.toFixed(3);
$("#labelDial").textContent = `Kₚ DIAL · ${params.gain.toFixed(2)}`;
$("#labelPosition").textContent = `POSITION x = ${sim.x.toFixed(3)}`;
}
gainSlider.addEventListener("input", event => {
setGain(event.target.value, true);
});
document.querySelectorAll("[data-gain]").forEach(button => {
button.addEventListener("click", () => {
setGain(button.dataset.gain, true);
});
});
function togglePause() {
sim.running = !sim.running;
updatePauseButtons();
}
function toggleComparison() {
sim.compareVisible = !sim.compareVisible;
$("#compareButton").classList.toggle("active", sim.compareVisible);
$("#compareButton").textContent = sim.compareVisible
? "Hide comparison"
: "Compare gains";
updatePlot();
}
$("#pauseButton").addEventListener("click", togglePause);
$("#pauseButton2").addEventListener("click", togglePause);
$("#restartButton").addEventListener("click", resetSimulation);
$("#restartButton2").addEventListener("click", resetSimulation);
$("#compareButton").addEventListener("click", toggleComparison);
$("#resetView").addEventListener("click", () => {
cameraState.radius = 14.2;
cameraState.theta = 0.67;
cameraState.phi = 1.13;
cameraState.target.set(0, 2.75, 0);
updateCamera();
});
/* ------------------------------------------------------------------
Direct camera controls and 3D dial interaction
------------------------------------------------------------------ */
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
const dialHitMeshes = [dialFace, knob, knobCap, dialOuterRing];
let draggingDial = false;
let orbiting = false;
let lastPointerX = 0;
let lastPointerY = 0;
function raycastDial(event) {
const rect = canvas.getBoundingClientRect();
pointerNDC.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
return raycaster.intersectObjects(dialHitMeshes, false).length > 0;
}
canvas.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (raycastDial(event)) {
draggingDial = true;
canvas.style.cursor = "crosshair";
} else {
orbiting = true;
canvas.style.cursor = "grabbing";
}
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (draggingDial) {
const rect = canvas.getBoundingClientRect();
const projected = dialCenter.clone().project(camera);
const cx = rect.left + (projected.x * 0.5 + 0.5) * rect.width;
const cy = rect.top + (-projected.y * 0.5 + 0.5) * rect.height;
const screenAngle = Math.atan2(
event.clientY - cy,
event.clientX - cx
) * 180 / Math.PI;
const normalized = (screenAngle + 360) % 360;
const normalizedGain = ((225 - normalized + 360) % 360) / 270;
const gain = params.minGain +
normalizedGain * (params.maxGain - params.minGain);
setGain(gain, true);
return;
}
if (orbiting) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.38,
1.43
);
updateCamera();
}
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
function endPointer(event) {
draggingDial = false;
orbiting = false;
canvas.style.cursor = "grab";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
8.5,
24
);
updateCamera();
}, { passive: false });
/* ------------------------------------------------------------------
Projected HTML labels
------------------------------------------------------------------ */
const labelDial = $("#labelDial");
const labelTarget = $("#labelTarget");
const labelPosition = $("#labelPosition");
function placeLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
if (projected.z < -1 || projected.z > 1) {
element.style.display = "none";
return;
}
element.style.display = "block";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
element.style.transform = "translate(-50%, -50%)";
}
/* ------------------------------------------------------------------
Animation
------------------------------------------------------------------ */
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (sim.running) {
/*
Exact integration of the closed-loop first-order model:
x(t+dt) = x∞ + [x(t)-x∞] exp(-λdt)
This avoids numerical overshoot even at large proportional gains.
*/
const k = params.gain * params.Ku;
const xInfinity = k / (1 + k);
const lambda = (1 + k) / params.tau;
sim.x = xInfinity +
(sim.x - xInfinity) * Math.exp(-lambda * dt);
sim.t += dt;
if (sim.t >= params.trialTime) {
sim.t = params.trialTime;
sim.running = false;
updatePauseButtons();
}
}
// Move the carriage and actual-position marker.
const carriageY = actuatorBottom + sim.x * actuatorRange;
carriage.position.y = carriageY;
actualMarker.position.y = carriageY;
// Error indicator between actual and target positions.
const errorHeight = Math.max(0.001, Math.abs(params.r - sim.x) * actuatorRange);
errorBar.scale.y = errorHeight;
errorBar.position.y =
actuatorBottom + ((sim.x + params.r) * 0.5) * actuatorRange;
// Mechanical motion.
gearA.rotation.z = -sim.t * params.gain * 1.4;
gearB.rotation.z = sim.t * params.gain * 1.05;
motor.rotation.x = sim.t * params.gain * 0.8;
// Update the plot cursor and live point.
const liveX = sx(sim.t);
const liveY = sy(sim.x);
$("#timeCursor").setAttribute("x1", liveX);
$("#timeCursor").setAttribute("x2", liveX);
$("#liveDot").setAttribute("cx", liveX);
$("#liveDot").setAttribute("cy", liveY);
updateTelemetry();
placeLabel(
labelDial,
new THREE.Vector3(dialCenter.x, dialCenter.y + 1.75, dialCenter.z)
);
placeLabel(
labelTarget,
new THREE.Vector3(gaugeX + 0.30, targetY + 0.26, gaugeZ)
);
placeLabel(
labelPosition,
new THREE.Vector3(gaugeX + 0.35, carriageY - 0.27, gaugeZ)
);
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
setGain(params.gain, true);
updatePauseButtons();
animate();
</script>
</body>
</html>
```