Prompt specification
Build or customize the Three.js 3D scene "Target Marker Sensor and Motor Pointer" 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: Target Marker Sensor and Motor Pointer
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/target-marker-sensor-and-motor-pointer-x2029
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a feedback-controlled position actuator. Model a rotating pointer, target angle, sensor indicator, and motor arrow. Distinguish the desired state, measured state, error, and control action. Low-poly.
Working Three.js Starter (target-marker-sensor-and-motor-pointer-x2029):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Feedback-Controlled Position Actuator</title>
<style>
:root {
--bg: #080d16;
--panel: #101824;
--panel-2: #151f2d;
--line: rgba(173, 199, 226, 0.14);
--text: #edf5ff;
--muted: #8fa3ba;
--cyan: #45d8ff;
--orange: #ffb454;
--red: #ff667a;
--purple: #b88cff;
--green: #5ee89a;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
height: 100%;
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 {
height: 100%;
display: grid;
grid-template-rows: 72px minmax(0, 1fr);
}
header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(9, 15, 24, 0.94);
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 14px;
}
.brand-icon {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border: 1px solid rgba(69, 216, 255, 0.38);
background: rgba(69, 216, 255, 0.07);
clip-path: polygon(25% 0, 75% 0, 100% 25%, 100% 75%, 75% 100%, 25% 100%, 0 75%, 0 25%);
}
.brand-icon::after {
content: "";
width: 13px;
height: 13px;
border: 3px solid var(--cyan);
border-right-color: transparent;
border-radius: 50%;
transform: rotate(-25deg);
}
h1 {
margin: 0;
font-size: 16px;
line-height: 1.2;
letter-spacing: 0.015em;
}
.subtitle {
margin-top: 4px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.1em;
background: rgba(255, 255, 255, 0.025);
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 12px rgba(255, 180, 84, 0.6);
}
.status[data-state="locked"] .status-dot {
background: var(--green);
box-shadow: 0 0 12px rgba(94, 232, 154, 0.7);
}
.status[data-state="tracking"] .status-dot {
background: var(--red);
box-shadow: 0 0 12px rgba(255, 102, 122, 0.7);
}
.layout {
min-height: 0;
display: grid;
grid-template-columns: minmax(0, 1fr) 350px;
}
#viewport {
position: relative;
min-width: 0;
overflow: hidden;
background:
radial-gradient(circle at 47% 40%, rgba(39, 72, 108, 0.25), transparent 42%),
linear-gradient(180deg, #0b1421 0%, #080d16 100%);
}
#viewport::after {
content: "";
position: absolute;
inset: 0;
pointer-events: none;
background: radial-gradient(circle, transparent 52%, rgba(2, 6, 12, 0.42) 100%);
z-index: 1;
}
canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
z-index: 0;
}
canvas.dragging { cursor: grabbing; }
.scene-heading {
position: absolute;
top: 22px;
left: 24px;
z-index: 3;
pointer-events: none;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.scene-heading h2 {
margin: 6px 0 0;
font-size: clamp(18px, 2.1vw, 28px);
font-weight: 650;
letter-spacing: -0.025em;
}
.scene-heading p {
margin: 6px 0 0;
color: var(--muted);
font-size: 12px;
}
.view-tools {
position: absolute;
right: 20px;
top: 20px;
z-index: 4;
display: flex;
gap: 8px;
}
.tool-button {
border: 1px solid var(--line);
border-radius: 8px;
padding: 8px 11px;
color: #c9d8e8;
background: rgba(12, 21, 33, 0.78);
backdrop-filter: blur(10px);
cursor: pointer;
font-size: 11px;
}
.tool-button:hover {
border-color: rgba(69, 216, 255, 0.38);
color: white;
}
.camera-hint {
position: absolute;
left: 24px;
bottom: 20px;
z-index: 3;
color: rgba(173, 199, 226, 0.6);
font-size: 10px;
letter-spacing: 0.06em;
pointer-events: none;
}
.scene-label {
--c: white;
position: absolute;
z-index: 5;
min-width: 112px;
padding: 7px 9px 7px 11px;
border: 1px solid color-mix(in srgb, var(--c) 42%, transparent);
border-left: 3px solid var(--c);
border-radius: 6px;
background: rgba(8, 15, 24, 0.86);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(10px);
pointer-events: none;
white-space: nowrap;
}
.scene-label strong {
display: block;
color: var(--c);
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scene-label span {
display: block;
margin-top: 2px;
color: #c8d5e4;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.label-desired { --c: var(--cyan); }
.label-measured { --c: var(--orange); }
.label-error { --c: var(--red); }
.label-control { --c: var(--purple); }
.label-sensor { --c: var(--green); }
aside {
min-height: 0;
overflow-y: auto;
padding: 22px;
border-left: 1px solid var(--line);
background: linear-gradient(180deg, rgba(18, 28, 42, 0.97), rgba(11, 18, 28, 0.99));
scrollbar-width: thin;
scrollbar-color: #34475f transparent;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 18px;
}
.panel-title h3 {
margin: 0;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.panel-title span {
color: var(--muted);
font-size: 10px;
}
.section {
padding: 17px 0;
border-top: 1px solid var(--line);
}
.section:first-of-type { padding-top: 0; border-top: 0; }
.control-label {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-bottom: 11px;
color: #d8e4f2;
font-size: 12px;
}
.control-label output {
color: var(--cyan);
font-size: 15px;
font-weight: 700;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 7px 0;
border-radius: 999px;
appearance: none;
background: linear-gradient(90deg, #30475f, #1c2b3d);
accent-color: var(--cyan);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid #0d1723;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(69, 216, 255, 0.5);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #0d1723;
border-radius: 50%;
background: var(--cyan);
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 8px;
color: #6f849c;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.readouts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.readout {
min-width: 0;
padding: 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.022);
}
.readout .name {
display: flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.readout .name::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--c);
box-shadow: 0 0 8px var(--c);
}
.readout .value {
margin-top: 8px;
font-size: 20px;
font-weight: 650;
font-variant-numeric: tabular-nums;
}
.readout .unit {
color: var(--muted);
font-size: 10px;
font-weight: 500;
}
.meter-label {
display: flex;
justify-content: space-between;
margin: 13px 0 7px;
color: var(--muted);
font-size: 10px;
}
.meter {
position: relative;
height: 7px;
overflow: hidden;
border-radius: 99px;
background: #1b2939;
}
.meter::after {
content: "";
position: absolute;
left: 50%;
top: 0;
bottom: 0;
width: 1px;
background: rgba(255, 255, 255, 0.22);
}
.meter-fill {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 0;
border-radius: 99px;
background: var(--red);
transition: width 80ms linear;
}
.control-meter .meter-fill { background: var(--purple); }
.formula {
margin: 14px 0 0;
padding: 10px;
border: 1px solid var(--line);
border-radius: 7px;
color: #9fb3c8;
background: rgba(0, 0, 0, 0.13);
font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 14px;
}
.action-button {
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 7px;
color: #c8d7e7;
background: #162333;
cursor: pointer;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.03em;
}
.action-button:hover {
border-color: rgba(69, 216, 255, 0.35);
color: white;
}
.switch-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 15px;
color: #b9c9da;
font-size: 11px;
}
.switch {
position: relative;
width: 38px;
height: 21px;
}
.switch input {
width: 0;
height: 0;
opacity: 0;
}
.switch-track {
position: absolute;
inset: 0;
border: 1px solid #34485f;
border-radius: 99px;
background: #1b2939;
cursor: pointer;
transition: 150ms;
}
.switch-track::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 13px;
height: 13px;
border-radius: 50%;
background: #8398ae;
transition: 150ms;
}
.switch input:checked + .switch-track {
border-color: rgba(255, 102, 122, 0.6);
background: rgba(255, 102, 122, 0.16);
}
.switch input:checked + .switch-track::after {
left: 20px;
background: var(--red);
}
.legend {
display: grid;
gap: 10px;
}
.legend-item {
display: grid;
grid-template-columns: 9px 1fr auto;
align-items: center;
gap: 9px;
color: #b7c6d6;
font-size: 11px;
}
.legend-swatch {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--c);
box-shadow: 0 0 8px color-mix(in srgb, var(--c) 60%, transparent);
}
.legend-item small {
color: #6f849c;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.sensor-note {
display: flex;
gap: 10px;
padding: 12px;
border: 1px solid rgba(94, 232, 154, 0.2);
border-radius: 8px;
color: #a9c4b5;
background: rgba(94, 232, 154, 0.045);
font-size: 10px;
line-height: 1.45;
}
.sensor-note::before {
content: "";
flex: 0 0 auto;
width: 7px;
height: 7px;
margin-top: 4px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 10px rgba(94, 232, 154, 0.8);
}
@media (max-width: 850px) {
html, body { overflow: auto; }
.app {
height: auto;
min-height: 100%;
grid-template-rows: 64px auto;
}
header { padding: 0 14px; }
.subtitle { display: none; }
.status { padding: 7px 9px; }
.layout {
grid-template-columns: 1fr;
}
#viewport {
height: 62vh;
min-height: 430px;
}
aside {
overflow: visible;
border-left: 0;
border-top: 1px solid var(--line);
}
.scene-heading { left: 16px; top: 17px; }
.camera-hint { left: 16px; }
.view-tools { right: 12px; top: 12px; }
.scene-label { min-width: 94px; padding: 6px 7px; }
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-icon" aria-hidden="true"></div>
<div>
<h1>Position Actuator Lab</h1>
<div class="subtitle">Feedback control · kinematic schematic</div>
</div>
</div>
<div class="status" id="status" data-state="settling">
<span class="status-dot"></span>
<span id="statusText">SETTLING</span>
</div>
</header>
<div class="layout">
<section id="viewport" aria-label="Interactive 3D actuator diagram">
<div class="scene-heading">
<div class="eyebrow">Closed-loop system</div>
<h2>Rotary position actuator</h2>
<p>Target → sensor → error → motor command</p>
</div>
<div class="view-tools">
<button class="tool-button" id="viewButton" type="button">Front view</button>
<button class="tool-button" id="resetButton" type="button">Reset view</button>
</div>
<div class="scene-label label-desired" id="labelDesired">
<strong>Desired state</strong>
<span id="desiredLabel">θd = +45.0°</span>
</div>
<div class="scene-label label-measured" id="labelMeasured">
<strong>Measured state</strong>
<span id="measuredLabel">θm = −22.0°</span>
</div>
<div class="scene-label label-error" id="labelError">
<strong>Tracking error</strong>
<span id="errorLabel">e = +67.0°</span>
</div>
<div class="scene-label label-control" id="labelControl">
<strong>Control action</strong>
<span id="controlLabel">u = +90%</span>
</div>
<div class="scene-label label-sensor" id="labelSensor">
<strong>Position sensor</strong>
<span>Valid measurement</span>
</div>
<div class="camera-hint">DRAG TO ORBIT · WHEEL TO ZOOM · DOUBLE-CLICK TO RESET</div>
</section>
<aside>
<div class="panel-title">
<h3>Controller</h3>
<span>PD feedback</span>
</div>
<section class="section">
<label class="control-label" for="targetSlider">
<span>Desired angle θd</span>
<output id="targetOutput">+45°</output>
</label>
<input id="targetSlider" type="range" min="-110" max="110" value="45" step="1" />
<div class="range-labels">
<span>−110°</span>
<span>0°</span>
<span>+110°</span>
</div>
<label class="control-label" for="gainSlider" style="margin-top:20px">
<span>Proportional gain Kp</span>
<output id="gainOutput">18.0</output>
</label>
<input id="gainSlider" type="range" min="8" max="28" value="18" step="0.5" />
<div class="switch-row">
<span>Apply external load disturbance</span>
<label class="switch">
<input id="disturbance" type="checkbox" />
<span class="switch-track"></span>
</label>
</div>
<div class="button-row">
<button class="action-button" id="stepButton" type="button">STEP TARGET +30°</button>
<button class="action-button" id="centerButton" type="button">CENTER TARGET</button>
</div>
</section>
<section class="section">
<div class="readouts">
<div class="readout" style="--c: var(--cyan)">
<div class="name">Desired θd</div>
<div class="value"><span id="desiredValue">+45.0</span><span class="unit"> °</span></div>
</div>
<div class="readout" style="--c: var(--orange)">
<div class="name">Measured θm</div>
<div class="value"><span id="measuredValue">−22.0</span><span class="unit"> °</span></div>
</div>
<div class="readout" style="--c: var(--red)">
<div class="name">Error e</div>
<div class="value"><span id="errorValue">+67.0</span><span class="unit"> °</span></div>
</div>
<div class="readout" style="--c: var(--purple)">
<div class="name">Motor u</div>
<div class="value"><span id="controlValue">+90</span><span class="unit"> %</span></div>
</div>
</div>
<div class="meter-label">
<span>Error magnitude</span>
<span id="errorMagnitude">61%</span>
</div>
<div class="meter">
<div class="meter-fill" id="errorFill"></div>
</div>
<div class="meter-label">
<span>Bidirectional motor command</span>
<span id="velocityValue">0.0°/s</span>
</div>
<div class="meter control-meter">
<div class="meter-fill" id="controlFill"></div>
</div>
<div class="formula">u = Kp(θd − θm) − Kd·θ̇</div>
</section>
<section class="section">
<div class="panel-title">
<h3>Signal key</h3>
<span>Five feedback signals</span>
</div>
<div class="legend">
<div class="legend-item" style="--c: var(--cyan)">
<span class="legend-swatch"></span>
<span>Desired state</span>
<small>θd</small>
</div>
<div class="legend-item" style="--c: var(--orange)">
<span class="legend-swatch"></span>
<span>Measured pointer</span>
<small>θm</small>
</div>
<div class="legend-item" style="--c: var(--red)">
<span class="legend-swatch"></span>
<span>Angular error</span>
<small>e</small>
</div>
<div class="legend-item" style="--c: var(--purple)">
<span class="legend-swatch"></span>
<span>Motor torque</span>
<small>u</small>
</div>
<div class="legend-item" style="--c: var(--green)">
<span class="legend-swatch"></span>
<span>Sensor feedback</span>
<small>valid</small>
</div>
</div>
</section>
<section class="section">
<div class="sensor-note">
The sensor reports the orange pointer angle. The controller compares it
with the cyan target, then drives the purple motor arrow to reduce error.
</div>
</section>
</aside>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x080d16, 12, 25);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Three-dimensional rotary actuator");
viewport.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 60);
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
let cameraYaw = 0.22;
let cameraPitch = 0.11;
let cameraRadius = 8.6;
let frontView = false;
function updateCamera() {
const cp = Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + cameraRadius * cp * Math.sin(cameraYaw),
cameraTarget.y + cameraRadius * Math.sin(cameraPitch),
cameraTarget.z + cameraRadius * cp * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraYaw = 0.22;
cameraPitch = 0.11;
cameraRadius = 8.6;
frontView = false;
document.getElementById("viewButton").textContent = "Front view";
updateCamera();
}
document.getElementById("resetButton").addEventListener("click", resetCamera);
document.getElementById("viewButton").addEventListener("click", () => {
frontView = !frontView;
if (frontView) {
cameraYaw = 0;
cameraPitch = 0.035;
cameraRadius = 8.1;
} else {
cameraYaw = 0.22;
cameraPitch = 0.11;
cameraRadius = 8.6;
}
document.getElementById("viewButton").textContent =
frontView ? "3D view" : "Front view";
updateCamera();
});
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraYaw -= dx * 0.006;
cameraPitch += dy * 0.004;
cameraPitch = THREE.MathUtils.clamp(cameraPitch, -0.32, 0.58);
updateCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
5.8,
13
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
const hemi = new THREE.HemisphereLight(0xbad9ff, 0x172033, 2.0);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff0d5, 3.2);
keyLight.position.set(-5, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x45d8ff, 1.8);
rimLight.position.set(5, 3, -4);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0xb88cff, 18, 8, 2);
fillLight.position.set(-2.5, 1, 3);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(22, 22),
new THREE.MeshStandardMaterial({
color: 0x0c1520,
roughness: 0.95,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.05;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(18, 24, 0x35506b, 0x203247);
grid.position.y = -1.035;
grid.material.transparent = true;
grid.material.opacity = 0.27;
scene.add(grid);
const rig = new THREE.Group();
rig.position.y = 1.15;
scene.add(rig);
const materials = {
body: new THREE.MeshStandardMaterial({
color: 0x26374c,
roughness: 0.62,
metalness: 0.52,
flatShading: true
}),
bodyLight: new THREE.MeshStandardMaterial({
color: 0x38506a,
roughness: 0.58,
metalness: 0.42,
flatShading: true
}),
dark: new THREE.MeshStandardMaterial({
color: 0x111b28,
roughness: 0.75,
metalness: 0.45,
flatShading: true
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x45d8ff,
emissive: 0x0b617a,
emissiveIntensity: 0.8,
roughness: 0.35,
metalness: 0.2,
flatShading: true
}),
orange: new THREE.MeshStandardMaterial({
color: 0xffb454,
emissive: 0x6f3510,
emissiveIntensity: 0.55,
roughness: 0.4,
metalness: 0.25,
flatShading: true
}),
purple: new THREE.MeshStandardMaterial({
color: 0xb88cff,
emissive: 0x42216f,
emissiveIntensity: 0.9,
roughness: 0.35,
metalness: 0.2,
flatShading: true
}),
green: new THREE.MeshStandardMaterial({
color: 0x5ee89a,
emissive: 0x1a8d51,
emissiveIntensity: 1.1,
roughness: 0.3,
flatShading: true
})
};
function addMesh(geometry, material, parent = rig) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Dark dial backing.
const backing = addMesh(
new THREE.CircleGeometry(2.52, 48),
new THREE.MeshBasicMaterial({
color: 0x0d1826,
transparent: true,
opacity: 0.88,
side: THREE.DoubleSide
})
);
backing.position.z = -0.13;
backing.castShadow = false;
backing.receiveShadow = false;
// Faceted actuator base and pedestal.
const base = addMesh(
new THREE.CylinderGeometry(1.15, 1.28, 0.34, 10),
materials.body
);
base.position.y = -2.02;
const baseInset = addMesh(
new THREE.CylinderGeometry(0.82, 0.93, 0.10, 10),
materials.bodyLight
);
baseInset.position.y = -1.80;
const pedestal = addMesh(
new THREE.BoxGeometry(1.18, 1.88, 0.86),
materials.body
);
pedestal.position.set(0, -1.0, -0.12);
const pedestalInset = addMesh(
new THREE.BoxGeometry(0.76, 1.24, 0.08),
materials.bodyLight
);
pedestalInset.position.set(0, -1.02, 0.34);
// Low-poly motor can.
const motor = addMesh(
new THREE.CylinderGeometry(0.74, 0.80, 0.76, 12),
materials.body
);
motor.rotation.x = Math.PI / 2;
motor.position.z = -0.62;
const motorFace = addMesh(
new THREE.CylinderGeometry(0.82, 0.82, 0.13, 12),
materials.bodyLight
);
motorFace.rotation.x = Math.PI / 2;
motorFace.position.z = -0.18;
const shaft = addMesh(
new THREE.CylinderGeometry(0.14, 0.14, 1.05, 10),
materials.dark
);
shaft.rotation.x = Math.PI / 2;
shaft.position.z = 0.12;
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const bolt = addMesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.065, 6),
materials.dark
);
bolt.rotation.x = Math.PI / 2;
bolt.position.set(
Math.cos(angle) * 0.63,
Math.sin(angle) * 0.63,
-0.09
);
}
const bearing = addMesh(
new THREE.TorusGeometry(0.34, 0.115, 4, 16),
materials.bodyLight
);
bearing.position.z = 0.48;
// Angular scale.
const scaleArc = addMesh(
new THREE.TorusGeometry(2.22, 0.035, 4, 96, THREE.MathUtils.degToRad(260)),
materials.bodyLight
);
scaleArc.rotation.z = THREE.MathUtils.degToRad(-130);
scaleArc.position.z = 0.12;
for (let angle = -120; angle <= 120; angle += 10) {
const radians = THREE.MathUtils.degToRad(angle);
const major = angle % 30 === 0;
const tick = addMesh(
new THREE.BoxGeometry(major ? 0.15 : 0.075, 0.025, 0.035),
major ? materials.cyan : materials.bodyLight
);
tick.position.set(
Math.cos(radians) * 2.13,
Math.sin(radians) * 2.13,
0.16
);
tick.rotation.z = radians;
tick.castShadow = false;
}
// Measured pointer.
const measuredPointer = new THREE.Group();
measuredPointer.position.z = 0.59;
rig.add(measuredPointer);
const pointerBeam = addMesh(
new THREE.BoxGeometry(1.94, 0.11, 0.09),
materials.orange,
measuredPointer
);
pointerBeam.position.x = 0.97;
const pointerHead = addMesh(
new THREE.ConeGeometry(0.20, 0.42, 4),
materials.orange,
measuredPointer
);
pointerHead.rotation.z = -Math.PI / 2;
pointerHead.position.x = 2.15;
const pointerTail = addMesh(
new THREE.BoxGeometry(0.48, 0.13, 0.10),
materials.orange,
measuredPointer
);
pointerTail.position.x = -0.24;
const hub = addMesh(
new THREE.CylinderGeometry(0.27, 0.27, 0.16, 12),
materials.dark,
measuredPointer
);
hub.rotation.x = Math.PI / 2;
// Desired target marker and dashed radial reference.
const desiredLineGeometry = new THREE.BufferGeometry();
desiredLineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3)
);
const desiredLine = new THREE.Line(
desiredLineGeometry,
new THREE.LineDashedMaterial({
color: 0x45d8ff,
dashSize: 0.11,
gapSize: 0.075,
transparent: true,
opacity: 0.8
})
);
desiredLine.position.z = 0.38;
rig.add(desiredLine);
const targetMarker = new THREE.Group();
targetMarker.position.z = 0.67;
rig.add(targetMarker);
const targetStem = addMesh(
new THREE.BoxGeometry(0.34, 0.07, 0.08),
materials.cyan,
targetMarker
);
targetStem.position.x = 2.25;
const targetDiamond = addMesh(
new THREE.OctahedronGeometry(0.17, 0),
materials.cyan,
targetMarker
);
targetDiamond.position.x = 2.47;
// Angular error arc.
const errorSegments = 32;
const errorPositions = new Float32Array((errorSegments + 1) * 3);
const errorGeometry = new THREE.BufferGeometry();
errorGeometry.setAttribute(
"position",
new THREE.BufferAttribute(errorPositions, 3)
);
const errorArc = new THREE.Line(
errorGeometry,
new THREE.LineBasicMaterial({
color: 0xff667a,
transparent: true,
opacity: 0.95
})
);
errorArc.position.z = 0.46;
rig.add(errorArc);
const errorBead = addMesh(
new THREE.OctahedronGeometry(0.09, 0),
new THREE.MeshBasicMaterial({ color: 0xff667a })
);
errorBead.position.z = 0.47;
errorBead.castShadow = false;
// Motor command / torque arrow around the shaft.
const controlSegments = 30;
const controlPositions = new Float32Array((controlSegments + 1) * 3);
const controlGeometry = new THREE.BufferGeometry();
controlGeometry.setAttribute(
"position",
new THREE.BufferAttribute(controlPositions, 3)
);
const controlArc = new THREE.Line(
controlGeometry,
new THREE.LineBasicMaterial({
color: 0xb88cff,
transparent: true,
opacity: 0.98
})
);
controlArc.position.z = 0.86;
rig.add(controlArc);
const controlArrow = addMesh(
new THREE.ConeGeometry(0.13, 0.29, 4),
materials.purple
);
controlArrow.position.z = 0.87;
// Sensor bracket and indicator LED.
const sensorBracket = addMesh(
new THREE.BoxGeometry(0.31, 0.17, 0.18),
materials.dark
);
sensorBracket.position.set(0.69, -0.43, 0.56);
sensorBracket.rotation.z = -0.35;
const sensorMaterial = new THREE.MeshStandardMaterial({
color: 0x5ee89a,
emissive: 0x1a8d51,
emissiveIntensity: 1.3,
roughness: 0.25,
flatShading: true
});
const sensorLED = addMesh(
new THREE.SphereGeometry(0.105, 8, 6),
sensorMaterial
);
sensorLED.position.set(0.75, -0.48, 0.73);
const sensorRing = addMesh(
new THREE.TorusGeometry(0.15, 0.018, 4, 12),
materials.green
);
sensorRing.position.copy(sensorLED.position);
// Simulation state.
const targetSlider = document.getElementById("targetSlider");
const gainSlider = document.getElementById("gainSlider");
const disturbanceInput = document.getElementById("disturbance");
let targetAngle = THREE.MathUtils.degToRad(Number(targetSlider.value));
let measuredAngle = THREE.MathUtils.degToRad(-22);
let angularVelocity = 0;
const angularLimit = THREE.MathUtils.degToRad(125);
function shortestError() {
let error = targetAngle - measuredAngle;
while (error > Math.PI) error -= Math.PI * 2;
while (error < -Math.PI) error += Math.PI * 2;
return error;
}
function signedDegrees(radians) {
const degrees = THREE.MathUtils.radToDeg(radians);
return `${degrees >= 0 ? "+" : "−"}${Math.abs(degrees).toFixed(1)}`;
}
function signedPercent(value) {
const percent = Math.round(value * 100);
return `${percent >= 0 ? "+" : "−"}${Math.abs(percent)}`;
}
function updateDesiredMarker() {
targetMarker.rotation.z = targetAngle;
const positions = desiredLine.geometry.attributes.position.array;
positions[0] = Math.cos(targetAngle) * 0.38;
positions[1] = Math.sin(targetAngle) * 0.38;
positions[2] = 0;
positions[3] = Math.cos(targetAngle) * 2.18;
positions[4] = Math.sin(targetAngle) * 2.18;
positions[5] = 0;
desiredLine.geometry.attributes.position.needsUpdate = true;
desiredLine.computeLineDistances();
}
function updateErrorAndControl(error, command) {
const errorStart = measuredAngle;
for (let i = 0; i <= errorSegments; i++) {
const t = i / errorSegments;
const angle = errorStart + error * t;
const offset = i * 3;
errorPositions[offset] = Math.cos(angle) * 1.43;
errorPositions[offset + 1] = Math.sin(angle) * 1.43;
errorPositions[offset + 2] = 0;
}
errorGeometry.attributes.position.needsUpdate = true;
errorGeometry.computeBoundingSphere();
const errorMid = errorStart + error * 0.5;
errorBead.position.set(
Math.cos(errorMid) * 1.43,
Math.sin(errorMid) * 1.43,
0.47
);
const span = 0.16 + Math.abs(command) * 1.48;
const start = command >= 0 ? -span * 0.5 : span * 0.5;
const end = command >= 0 ? span * 0.5 : -span * 0.5;
for (let i = 0; i <= controlSegments; i++) {
const t = i / controlSegments;
const angle = start + (end - start) * t;
const offset = i * 3;
controlPositions[offset] = Math.cos(angle) * 0.76;
controlPositions[offset + 1] = Math.sin(angle) * 0.76;
controlPositions[offset + 2] = 0;
}
controlGeometry.attributes.position.needsUpdate = true;
controlGeometry.computeBoundingSphere();
controlArrow.position.set(
Math.cos(end) * 0.76,
Math.sin(end) * 0.76,
0.87
);
const tangent = command >= 0
? new THREE.Vector2(-Math.sin(end), Math.cos(end))
: new THREE.Vector2(Math.sin(end), -Math.cos(end));
controlArrow.rotation.z =
Math.atan2(tangent.y, tangent.x) - Math.PI / 2;
return { errorMid, end };
}
const labels = {
desired: document.getElementById("labelDesired"),
measured: document.getElementById("labelMeasured"),
error: document.getElementById("labelError"),
control: document.getElementById("labelControl"),
sensor: document.getElementById("labelSensor")
};
function projectLabel(element, worldPosition, offsetX, offsetY) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
const x = (projected.x * 0.5 + 0.5) * viewport.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * viewport.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.style.transform =
`translate(calc(-50% + ${offsetX}px), calc(-50% + ${offsetY}px))`;
element.style.opacity = visible ? "1" : "0";
}
function updateLabels(errorMid, controlEnd) {
rig.updateMatrixWorld(true);
const desiredWorld = rig.localToWorld(
new THREE.Vector3(
Math.cos(targetAngle) * 2.47,
Math.sin(targetAngle) * 2.47,
0.8
)
);
const measuredWorld = rig.localToWorld(
new THREE.Vector3(
Math.cos(measuredAngle) * 2.16,
Math.sin(measuredAngle) * 2.16,
0.8
)
);
const errorWorld = rig.localToWorld(
new THREE.Vector3(
Math.cos(errorMid) * 1.54,
Math.sin(errorMid) * 1.54,
0.75
)
);
const controlWorld = rig.localToWorld(
new THREE.Vector3(
Math.cos(controlEnd) * 0.78,
Math.sin(controlEnd) * 0.78,
0.9
)
);
const sensorWorld = rig.localToWorld(
new THREE.Vector3(0.75, -0.48, 0.8)
);
projectLabel(labels.desired, desiredWorld, 38, -36);
projectLabel(labels.measured, measuredWorld, 40, 24);
projectLabel(labels.error, errorWorld, -18, 35);
projectLabel(labels.control, controlWorld, 58, 26);
projectLabel(labels.sensor, sensorWorld, 48, 28);
}
function updateReadouts(error, command) {
const desiredDegrees = THREE.MathUtils.radToDeg(targetAngle);
const measuredDegrees = THREE.MathUtils.radToDeg(measuredAngle);
const errorDegrees = THREE.MathUtils.radToDeg(error);
document.getElementById("targetOutput").textContent =
`${desiredDegrees >= 0 ? "+" : "−"}${Math.abs(desiredDegrees).toFixed(0)}°`;
document.getElementById("desiredValue").textContent = signedDegrees(targetAngle);
document.getElementById("measuredValue").textContent = signedDegrees(measuredAngle);
document.getElementById("errorValue").textContent = signedDegrees(error);
document.getElementById("controlValue").textContent = signedPercent(command);
document.getElementById("desiredLabel").textContent =
`θd = ${signedDegrees(targetAngle)}°`;
document.getElementById("measuredLabel").textContent =
`θm = ${signedDegrees(measuredAngle)}°`;
document.getElementById("errorLabel").textContent =
`e = ${signedDegrees(error)}°`;
document.getElementById("controlLabel").textContent =
`u = ${signedPercent(command)}%`;
const errorMagnitude = Math.min(Math.abs(errorDegrees) / 110, 1);
document.getElementById("errorMagnitude").textContent =
`${Math.round(errorMagnitude * 100)}%`;
document.getElementById("errorFill").style.width =
`${errorMagnitude * 100}%`;
const commandMagnitude = Math.abs(command) * 50;
const controlFill = document.getElementById("controlFill");
if (command >= 0) {
controlFill.style.left = "50%";
controlFill.style.width = `${commandMagnitude}%`;
} else {
controlFill.style.left = `${50 - commandMagnitude}%`;
controlFill.style.width = `${commandMagnitude}%`;
}
document.getElementById("velocityValue").textContent =
`${signedDegrees(angularVelocity)}°/s`;
const statusElement = document.getElementById("status");
const statusText = document.getElementById("statusText");
if (Math.abs(error) < THREE.MathUtils.degToRad(0.8) &&
Math.abs(angularVelocity) < THREE.MathUtils.degToRad(0.8)) {
statusElement.dataset.state = "locked";
statusText.textContent = "TARGET LOCKED";
} else if (Math.abs(error) > THREE.MathUtils.degToRad(5)) {
statusElement.dataset.state = "tracking";
statusText.textContent = "TRACKING";
} else {
statusElement.dataset.state = "settling";
statusText.textContent = "SETTLING";
}
}
targetSlider.addEventListener("input", () => {
targetAngle = THREE.MathUtils.degToRad(Number(targetSlider.value));
updateDesiredMarker();
});
gainSlider.addEventListener("input", () => {
document.getElementById("gainOutput").textContent =
Number(gainSlider.value).toFixed(1);
});
document.getElementById("stepButton").addEventListener("click", () => {
let next = THREE.MathUtils.radToDeg(targetAngle) + 30;
if (next > 110) next -= 220;
targetSlider.value = String(Math.round(next));
targetAngle = THREE.MathUtils.degToRad(Number(targetSlider.value));
updateDesiredMarker();
});
document.getElementById("centerButton").addEventListener("click", () => {
targetSlider.value = "0";
targetAngle = 0;
updateDesiredMarker();
});
const resizeObserver = new ResizeObserver(() => {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
});
resizeObserver.observe(viewport);
updateCamera();
updateDesiredMarker();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.04);
const kp = Number(gainSlider.value);
const kd = 2 * Math.sqrt(kp) * 0.85;
let error = shortestError();
const motorTorque = kp * error - kd * angularVelocity;
const externalAcceleration = disturbanceInput.checked ? -3.4 : 0;
angularVelocity += (motorTorque + externalAcceleration) * dt;
measuredAngle += angularVelocity * dt;
if (measuredAngle > angularLimit) {
measuredAngle = angularLimit;
angularVelocity = Math.min(0, angularVelocity);
} else if (measuredAngle < -angularLimit) {
measuredAngle = -angularLimit;
angularVelocity = Math.max(0, angularVelocity);
}
error = shortestError();
const command = THREE.MathUtils.clamp(motorTorque / 22, -1, 1);
measuredPointer.rotation.z = measuredAngle;
const { errorMid, end } = updateErrorAndControl(error, command);
const speedFactor = Math.min(Math.abs(angularVelocity) / 3, 1);
sensorMaterial.emissiveIntensity =
1.1 + speedFactor * 0.7 + Math.sin(performance.now() * 0.004) * 0.08;
updateReadouts(error, command);
updateLabels(errorMid, end);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```