Prompt specification
Build or customize the Three.js 3D scene "Original Service Robot Elbow Module" 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: Original Service Robot Elbow Module
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/original-service-robot-elbow-module-x3741
Scene Description Prompt:
Model a friendly original service robot arm with one hinge and visible stops. Make the allowed angular range readable from the joint housing geometry. Build this with Three.js from cdnjs as a cutaway scene in one self-contained HTML file.
Working Three.js Starter (original-service-robot-elbow-module-x3741):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mallow — One-Hinge Service Robot</title>
<style>
:root {
color-scheme: light;
--ink: #253842;
--muted: #62737b;
--cream: #f5f0e5;
--coral: #ff765f;
--mint: #58d8c3;
--yellow: #ffd04a;
--glass: rgba(255, 255, 255, 0.78);
--line: rgba(37, 56, 66, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9efeb;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 28px;
left: 30px;
max-width: 390px;
padding: 18px 20px 17px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--glass);
box-shadow: 0 16px 50px rgba(40, 58, 65, 0.09);
backdrop-filter: blur(14px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 0 4px rgba(88, 216, 195, 0.16);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 37px);
line-height: 1;
letter-spacing: -0.055em;
}
.brand p {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.telemetry {
position: absolute;
top: 28px;
right: 30px;
width: 218px;
padding: 17px 18px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--glass);
box-shadow: 0 16px 50px rgba(40, 58, 65, 0.09);
backdrop-filter: blur(14px);
}
.telemetry-label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#angleValue {
display: block;
margin: 4px 0 8px;
font-variant-numeric: tabular-nums;
font-size: 40px;
font-weight: 750;
line-height: 1;
letter-spacing: -0.05em;
}
.range-copy {
color: var(--muted);
font-size: 11px;
}
.motion-state {
display: flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.motion-state::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--yellow);
content: "";
box-shadow: 0 0 0 4px rgba(255, 208, 74, 0.18);
}
.controls {
position: absolute;
right: 30px;
bottom: 27px;
left: 30px;
display: flex;
align-items: center;
gap: 16px;
padding: 13px 15px;
border: 1px solid var(--line);
border-radius: 19px;
background: var(--glass);
box-shadow: 0 18px 55px rgba(40, 58, 65, 0.11);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.button {
flex: 0 0 auto;
min-height: 39px;
padding: 0 15px;
border: 0;
border-radius: 12px;
background: var(--ink);
color: white;
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 750;
transition: transform 150ms ease, background 150ms ease;
}
.button:hover {
transform: translateY(-1px);
background: #17262d;
}
.button.secondary {
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.72);
color: var(--ink);
}
.button.secondary:hover {
background: white;
}
.slider-wrap {
display: grid;
flex: 1 1 auto;
grid-template-columns: auto minmax(120px, 1fr) auto;
align-items: center;
gap: 12px;
min-width: 180px;
}
.slider-wrap label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.endpoint {
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
border-radius: 999px;
appearance: none;
background: linear-gradient(
90deg,
var(--coral),
var(--yellow),
var(--mint)
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
border: 3px solid white;
border-radius: 50%;
appearance: none;
background: var(--ink);
box-shadow: 0 2px 8px rgba(30, 45, 52, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid white;
border-radius: 50%;
background: var(--ink);
box-shadow: 0 2px 8px rgba(30, 45, 52, 0.25);
}
.hint {
flex: 0 0 auto;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
text-align: right;
}
.legend {
position: absolute;
bottom: 102px;
left: 30px;
display: grid;
gap: 7px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.66);
color: var(--muted);
font-size: 10px;
backdrop-filter: blur(10px);
}
.legend div {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 16px;
height: 5px;
border-radius: 4px;
}
.swatch.pointer {
background: var(--yellow);
}
.swatch.stop {
background: var(--coral);
}
.swatch.section {
background: var(--mint);
}
@media (max-width: 760px) {
.brand {
top: 14px;
left: 14px;
max-width: calc(100vw - 156px);
padding: 13px 15px;
}
.brand p {
display: none;
}
.telemetry {
top: 14px;
right: 14px;
width: 128px;
padding: 12px;
}
#angleValue {
font-size: 30px;
}
.range-copy,
.motion-state {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
left: 14px;
flex-wrap: wrap;
gap: 9px;
}
.slider-wrap {
order: -1;
flex-basis: 100%;
}
.hint,
.legend {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="overlay">
<section class="brand">
<div class="eyebrow">Original service robot concept</div>
<h1>Mallow</h1>
<p>
A friendly single-hinge service arm with an exposed servo bay and a
geometry-defined angular envelope.
</p>
</section>
<section class="telemetry">
<div class="telemetry-label">Shoulder angle</div>
<span id="angleValue">+08°</span>
<div class="range-copy">Allowed envelope: −45° to +65°</div>
<div class="motion-state" id="motionState">Sweeping between stops</div>
</section>
<section class="legend">
<div><span class="swatch pointer"></span>Rotating pointer</div>
<div><span class="swatch stop"></span>Fixed mechanical stops</div>
<div><span class="swatch section"></span>Sectioned drive bay</div>
</section>
<section class="controls">
<button class="button" id="playButton" type="button">Pause sweep</button>
<div class="slider-wrap">
<label for="angleSlider">Angle</label>
<input
id="angleSlider"
type="range"
min="-45"
max="65"
step="1"
value="8"
aria-label="Shoulder angle"
>
<span class="endpoint">−45° / +65°</span>
</div>
<button class="button secondary" id="cutawayButton" type="button">
Close cutaway
</button>
<button class="button secondary" id="resetButton" type="button">
Reset view
</button>
<div class="hint">
Drag to orbit · Shift-drag to pan<br>
Scroll to zoom · Arrow keys adjust
</div>
</section>
</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.background = new THREE.Color(0xe9efeb);
scene.fog = new THREE.Fog(0xe9efeb, 10, 22);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.05,
60
);
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
viewport.innerHTML =
'<div style="padding:2rem;font:600 16px system-ui">' +
"This scene requires a browser with WebGL enabled.</div>";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
viewport.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D view of the Mallow one-hinge service robot"
);
// ------------------------------------------------------------
// Lighting and stage
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xffffff,
0x71857d,
2.35
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0dc, 4.1);
keyLight.position.set(4.5, 8.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x65d9ca, 28, 10, 2);
rimLight.position.set(-4, 4, -2.5);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffc8a8, 18, 9, 2);
warmFill.position.set(3.5, 3, 4.5);
scene.add(warmFill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({
color: 0xe5ebe6,
roughness: 0.94,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.13;
floor.receiveShadow = true;
scene.add(floor);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(2.65, 2.78, 0.16, 96),
new THREE.MeshStandardMaterial({
color: 0xf3f1e8,
roughness: 0.72
})
);
platform.position.y = -0.04;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const platformRim = new THREE.Mesh(
new THREE.TorusGeometry(2.61, 0.025, 10, 128),
new THREE.MeshStandardMaterial({
color: 0xaac1b8,
roughness: 0.5
})
);
platformRim.rotation.x = Math.PI / 2;
platformRim.position.y = 0.045;
scene.add(platformRim);
const contactShadow = new THREE.Mesh(
new THREE.CircleGeometry(1.25, 64),
new THREE.MeshBasicMaterial({
color: 0x51625c,
transparent: true,
opacity: 0.09,
depthWrite: false
})
);
contactShadow.rotation.x = -Math.PI / 2;
contactShadow.position.set(0, 0.048, 0.08);
contactShadow.scale.set(1.25, 0.82, 1);
scene.add(contactShadow);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.56,
metalness: 0,
...options
});
}
const cream = standard(0xf4efe2, { roughness: 0.48 });
const creamSide = standard(0xe5dfd2, { roughness: 0.62 });
const coral = standard(0xff765f, { roughness: 0.42 });
const coralDark = standard(0xd95348, { roughness: 0.5 });
const mint = standard(0x58d8c3, { roughness: 0.38 });
const navy = standard(0x263842, { roughness: 0.44 });
const navySoft = standard(0x3e535d, { roughness: 0.62 });
const yellow = standard(0xffd04a, {
roughness: 0.34,
emissive: 0x6c4b00,
emissiveIntensity: 0.12
});
const copper = standard(0xc77943, {
roughness: 0.3,
metalness: 0.72
});
const metal = standard(0x9aadb2, {
roughness: 0.28,
metalness: 0.82
});
const darkMetal = standard(0x566a72, {
roughness: 0.36,
metalness: 0.7
});
const pcb = standard(0x2e806b, { roughness: 0.72 });
const chip = standard(0x17272d, { roughness: 0.5 });
const white = standard(0xfff9ed, { roughness: 0.65 });
const mintLight = standard(0x9fffe9, {
roughness: 0.25,
emissive: 0x35d7b4,
emissiveIntensity: 0.65
});
const glass = new THREE.MeshPhysicalMaterial({
color: 0xbceee5,
roughness: 0.14,
metalness: 0,
transmission: 0.18,
transparent: true,
opacity: 0.28,
depthWrite: false,
side: THREE.DoubleSide
});
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function roundedRectShape(width, height, radius) {
const w = width / 2;
const h = height / 2;
const r = Math.min(radius, w, h);
const shape = new THREE.Shape();
shape.moveTo(-w + r, -h);
shape.lineTo(w - r, -h);
shape.quadraticCurveTo(w, -h, w, -h + r);
shape.lineTo(w, h - r);
shape.quadraticCurveTo(w, h, w - r, h);
shape.lineTo(-w + r, h);
shape.quadraticCurveTo(-w, h, -w, h - r);
shape.lineTo(-w, -h + r);
shape.quadraticCurveTo(-w, -h, -w + r, -h);
shape.closePath();
return shape;
}
function roundedBoxGeometry(width, height, depth, radius) {
const actualDepth = Math.max(0.025, depth - 0.05);
const bevel = Math.min(0.025, actualDepth * 0.22);
const geometry = new THREE.ExtrudeGeometry(
roundedRectShape(width, height, radius),
{
depth: actualDepth,
steps: 1,
curveSegments: 8,
bevelEnabled: true,
bevelSegments: 2,
bevelThickness: bevel,
bevelSize: Math.min(radius * 0.28, 0.035)
}
);
geometry.translate(0, 0, -actualDepth / 2);
geometry.computeVertexNormals();
return geometry;
}
function addMesh(geometry, material, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addRounded(
width,
height,
depth,
radius,
material,
position,
parent = scene
) {
const mesh = addMesh(
roundedBoxGeometry(width, height, depth, radius),
material,
parent
);
mesh.position.copy(position);
return mesh;
}
function addBox(
width,
height,
depth,
material,
position,
parent = scene
) {
const mesh = addMesh(
new THREE.BoxGeometry(width, height, depth),
material,
parent
);
mesh.position.copy(position);
return mesh;
}
function addCylinder(
radius,
height,
material,
position,
parent = scene,
radialSegments = 32
) {
const mesh = addMesh(
new THREE.CylinderGeometry(radius, radius, height, radialSegments),
material,
parent
);
mesh.position.copy(position);
return mesh;
}
function addTube(points, radius, material, parent = scene) {
const curve = new THREE.CatmullRomCurve3(points);
const mesh = addMesh(
new THREE.TubeGeometry(curve, 40, radius, 8, false),
material,
parent
);
return mesh;
}
function addLabel(text, position, accent = "#ffd04a", width = 1.05) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
const r = 26;
const x = 8;
const y = 10;
const w = 496;
const h = 108;
context.beginPath();
context.moveTo(x + r, y);
context.lineTo(x + w - r, y);
context.quadraticCurveTo(x + w, y, x + w, y + r);
context.lineTo(x + w, y + h - r);
context.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
context.lineTo(x + r, y + h);
context.quadraticCurveTo(x, y + h, x, y + h - r);
context.lineTo(x, y + r);
context.quadraticCurveTo(x, y, x + r, y);
context.closePath();
context.fillStyle = "rgba(31, 48, 56, 0.94)";
context.fill();
context.fillStyle = accent;
context.fillRect(18, 24, 10, 80);
context.fillStyle = "#ffffff";
context.font = "750 48px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 266, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.copy(position);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
// ------------------------------------------------------------
// Fixed lower body: intentionally sectioned
// ------------------------------------------------------------
const robot = new THREE.Group();
scene.add(robot);
addRounded(
2.18,
0.24,
1.62,
0.18,
creamSide,
new THREE.Vector3(0, 0.17, 0),
robot
);
addRounded(
1.92,
0.08,
1.37,
0.08,
navySoft,
new THREE.Vector3(0, 0.315, 0),
robot
);
// Rear shell.
addRounded(
1.76,
1.15,
0.32,
0.18,
cream,
new THREE.Vector3(0, 0.91, -0.52),
robot
);
// Left wall remains nearly full depth.
addRounded(
0.25,
1.15,
1.03,
0.13,
cream,
new THREE.Vector3(-0.76, 0.91, -0.04),
robot
);
// Right wall is cut back to expose the interior.
addRounded(
0.25,
1.15,
0.57,
0.13,
creamSide,
new THREE.Vector3(0.76, 0.91, -0.23),
robot
);
addRounded(
1.78,
0.22,
1.10,
0.12,
cream,
new THREE.Vector3(0, 1.49, -0.03),
robot
);
addRounded(
1.52,
0.16,
0.18,
0.07,
creamSide,
new THREE.Vector3(0, 0.39, 0.43),
robot
);
// Orange section faces emphasize that the casing has been cut open.
addBox(
0.035,
0.94,
0.035,
coral,
new THREE.Vector3(-0.625, 0.91, 0.335),
robot
);
addBox(
0.035,
0.94,
0.035,
coral,
new THREE.Vector3(0.625, 0.91, 0.335),
robot
);
addBox(
1.25,
0.035,
0.035,
coral,
new THREE.Vector3(0, 0.43, 0.53),
robot
);
// Optional clear cover used by the cutaway toggle.
const clearCover = addRounded(
1.31,
0.97,
0.055,
0.10,
glass,
new THREE.Vector3(0, 0.91, 0.555),
robot
);
clearCover.visible = false;
clearCover.castShadow = false;
// ------------------------------------------------------------
// Exposed internal electronics and power bay
// ------------------------------------------------------------
const internals = new THREE.Group();
robot.add(internals);
addRounded(
1.25,
0.67,
0.065,
0.04,
pcb,
new THREE.Vector3(0, 0.97, -0.02),
internals
);
addRounded(
0.31,
0.24,
0.055,
0.025,
chip,
new THREE.Vector3(-0.19, 1.02, 0.045),
internals
);
addRounded(
0.22,
0.16,
0.045,
0.018,
chip,
new THREE.Vector3(0.26, 1.08, 0.037),
internals
);
addRounded(
0.31,
0.13,
0.04,
0.018,
metal,
new THREE.Vector3(0.27, 0.84, 0.034),
internals
);
// Copper PCB traces.
[
[-0.49, 1.08, 0.032, 0.26, 0.012],
[-0.49, 0.87, 0.032, 0.18, 0.012],
[0.49, 1.13, 0.032, 0.14, 0.012],
[-0.02, 0.71, 0.012, 0.12, 0.45]
].forEach(([x, y, w, h, z]) => {
addBox(w, h, 0.012, copper, new THREE.Vector3(x, y, z), internals);
});
// Small cylindrical capacitors, axes facing the viewer.
[-0.48, -0.36, 0.42].forEach((x) => {
const capacitor = addCylinder(
0.045,
0.065,
metal,
new THREE.Vector3(x, 0.78, 0.075),
internals,
20
);
capacitor.rotation.x = Math.PI / 2;
});
// Battery cells.
[-0.28, 0.28].forEach((x) => {
addCylinder(
0.14,
0.48,
navySoft,
new THREE.Vector3(x, 0.56, 0.17),
internals,
28
);
addCylinder(
0.115,
0.035,
mint,
new THREE.Vector3(x, 0.815, 0.17),
internals,
28
);
});
addRounded(
0.76,
0.12,
0.12,
0.04,
coralDark,
new THREE.Vector3(0, 0.59, 0.19),
internals
);
// Wiring from the electronics into the shoulder actuator.
addTube(
[
new THREE.Vector3(-0.39, 1.16, 0.10),
new THREE.Vector3(-0.46, 1.40, 0.08),
new THREE.Vector3(-0.28, 1.58, -0.02),
new THREE.Vector3(-0.16, 1.73, -0.10)
],
0.027,
coral,
internals
);
addTube(
[
new THREE.Vector3(0.38, 1.12, 0.09),
new THREE.Vector3(0.47, 1.34, 0.06),
new THREE.Vector3(0.29, 1.56, -0.02),
new THREE.Vector3(0.16, 1.72, -0.10)
],
0.024,
mint,
internals
);
// ------------------------------------------------------------
// Fixed shoulder support and exposed servo stator
// ------------------------------------------------------------
const pivotPosition = new THREE.Vector3(0, 1.86, 0);
addRounded(
1.13,
0.73,
0.35,
0.18,
creamSide,
new THREE.Vector3(0, 1.52, -0.31),
robot
);
const stator = addCylinder(
0.285,
0.33,
darkMetal,
new THREE.Vector3(0, pivotPosition.y, -0.13),
robot,
40
);
stator.rotation.x = Math.PI / 2;
// Copper stator segments visible below the rotating shell.
for (let i = 0; i < 7; i++) {
const a = THREE.MathUtils.degToRad(-165 + i * 22);
const segment = addRounded(
0.12,
0.22,
0.13,
0.025,
copper,
new THREE.Vector3(
Math.cos(a) * 0.40,
pivotPosition.y + Math.sin(a) * 0.40,
0.015
),
robot
);
segment.rotation.z = a - Math.PI / 2;
}
// ------------------------------------------------------------
// Angular-range housing geometry
// ------------------------------------------------------------
const MIN_ANGLE = -45;
const MAX_ANGLE = 65;
function annularSectorGeometry(
innerRadius,
outerRadius,
startRadians,
endRadians,
depth
) {
const shape = new THREE.Shape();
shape.moveTo(
Math.cos(startRadians) * outerRadius,
Math.sin(startRadians) * outerRadius
);
shape.absarc(
0,
0,
outerRadius,
startRadians,
endRadians,
false
);
shape.lineTo(
Math.cos(endRadians) * innerRadius,
Math.sin(endRadians) * innerRadius
);
shape.absarc(
0,
0,
innerRadius,
endRadians,
startRadians,
true
);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
curveSegments: 72,
bevelEnabled: true,
bevelSegments: 2,
bevelThickness: 0.012,
bevelSize: 0.012
});
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
return geometry;
}
// Standard polar angle: zero is the +X axis.
const startRadians = THREE.MathUtils.degToRad(90 + MIN_ANGLE);
const endRadians = THREE.MathUtils.degToRad(90 + MAX_ANGLE);
const rangeHousing = new THREE.Group();
rangeHousing.position.copy(pivotPosition);
scene.add(rangeHousing);
const track = addMesh(
annularSectorGeometry(
0.77,
0.99,
startRadians,
endRadians,
0.12
),
navy,
rangeHousing
);
track.position.z = 0.19;
const outerRim = addMesh(
annularSectorGeometry(
0.985,
1.075,
startRadians,
endRadians,
0.15
),
creamSide,
rangeHousing
);
outerRim.position.z = 0.185;
const rangeAccent = addMesh(
annularSectorGeometry(
1.004,
1.033,
startRadians + 0.006,
endRadians - 0.006,
0.022
),
mint,
rangeHousing
);
rangeAccent.position.z = 0.278;
// Tick marks are physical pieces of the joint housing.
for (let angle = MIN_ANGLE; angle <= MAX_ANGLE; angle += 5) {
const radians = THREE.MathUtils.degToRad(angle);
const major = Math.abs(angle % 15) < 0.001;
const radius = 0.885;
const height = major ? 0.17 : 0.095;
const tick = addBox(
major ? 0.043 : 0.026,
height,
0.025,
major ? white : navySoft,
new THREE.Vector3(
-Math.sin(radians) * radius,
Math.cos(radians) * radius,
0.275
),
rangeHousing
);
tick.rotation.z = radians;
}
// Fixed mechanical stops. The yellow pointer visibly contacts them.
[MIN_ANGLE, MAX_ANGLE].forEach((angle, index) => {
const radians = THREE.MathUtils.degToRad(angle);
const radius = 0.835;
const stop = addRounded(
0.16,
0.30,
0.17,
0.035,
coral,
new THREE.Vector3(
-Math.sin(radians) * radius,
Math.cos(radians) * radius,
0.35
),
rangeHousing
);
stop.rotation.z = radians;
const stopCap = addBox(
0.095,
0.18,
0.025,
index === 0 ? coralDark : yellow,
new THREE.Vector3(
-Math.sin(radians) * radius,
Math.cos(radians) * radius,
0.445
),
rangeHousing
);
stopCap.rotation.z = radians;
});
// Housing screws.
[-25, 10, 45].forEach((angle) => {
const radians = THREE.MathUtils.degToRad(angle);
const screw = addCylinder(
0.032,
0.024,
metal,
new THREE.Vector3(
-Math.sin(radians) * 1.025,
Math.cos(radians) * 1.025,
0.285
),
rangeHousing,
20
);
screw.rotation.x = Math.PI / 2;
});
addLabel(
"−45° STOP",
new THREE.Vector3(
pivotPosition.x - Math.sin(THREE.MathUtils.degToRad(MIN_ANGLE)) * 1.32,
pivotPosition.y + Math.cos(THREE.MathUtils.degToRad(MIN_ANGLE)) * 1.32,
0.65
),
"#ff765f",
1.13
);
addLabel(
"+65° STOP",
new THREE.Vector3(
pivotPosition.x - Math.sin(THREE.MathUtils.degToRad(MAX_ANGLE)) * 1.34,
pivotPosition.y + Math.cos(THREE.MathUtils.degToRad(MAX_ANGLE)) * 1.34,
0.65
),
"#ff765f",
1.13
);
// ------------------------------------------------------------
// Single rotating assembly: arm, gripper, gear, and pointer
// ------------------------------------------------------------
const armPivot = new THREE.Group();
armPivot.position.copy(pivotPosition);
scene.add(armPivot);
// Exposed rotating gear.
const gear = addCylinder(
0.40,
0.10,
darkMetal,
new THREE.Vector3(0, 0, 0.22),
armPivot,
48
);
gear.rotation.x = Math.PI / 2;
for (let i = 0; i < 16; i++) {
const a = (i / 16) * Math.PI * 2;
const tooth = addBox(
0.095,
0.13,
0.09,
metal,
new THREE.Vector3(
Math.cos(a) * 0.41,
Math.sin(a) * 0.41,
0.22
),
armPivot
);
tooth.rotation.z = a - Math.PI / 2;
}
const rotorCap = addCylinder(
0.29,
0.16,
coral,
new THREE.Vector3(0, 0, 0.36),
armPivot,
48
);
rotorCap.rotation.x = Math.PI / 2;
const rotorInset = addCylinder(
0.17,
0.025,
navy,
new THREE.Vector3(0, 0, 0.455),
armPivot,
40
);
rotorInset.rotation.x = Math.PI / 2;
// Main single arm shell.
addRounded(
0.62,
1.62,
0.46,
0.24,
cream,
new THREE.Vector3(0, 1.00, 0),
armPivot
);
// Coral spine.
addRounded(
0.16,
1.18,
0.035,
0.07,
coral,
new THREE.Vector3(0, 0.95, 0.249),
armPivot
);
// Right-side inspection window and internal linkage rods.
addRounded(
0.035,
0.93,
0.30,
0.08,
navy,
new THREE.Vector3(0.301, 0.87, 0.015),
armPivot
);
[-0.095, 0, 0.095].forEach((z) => {
addBox(
0.018,
0.72,
0.018,
copper,
new THREE.Vector3(0.326, 0.87, z),
armPivot
);
});
const sideGlass = addRounded(
0.018,
0.84,
0.25,
0.07,
glass,
new THREE.Vector3(0.346, 0.87, 0.015),
armPivot
);
sideGlass.castShadow = false;
// Friendly face display.
addRounded(
0.43,
0.63,
0.06,
0.13,
navy,
new THREE.Vector3(0, 1.20, 0.25),
armPivot
);
[-0.105, 0.105].forEach((x) => {
const eye = addMesh(
new THREE.SphereGeometry(1, 20, 14),
mintLight,
armPivot
);
eye.position.set(x, 1.31, 0.303);
eye.scale.set(0.052, 0.075, 0.024);
});
const smileCurve = new THREE.QuadraticBezierCurve3(
new THREE.Vector3(-0.105, 1.12, 0.312),
new THREE.Vector3(0, 1.035, 0.325),
new THREE.Vector3(0.105, 1.12, 0.312)
);
const smile = addMesh(
new THREE.TubeGeometry(smileCurve, 24, 0.016, 8, false),
mintLight,
armPivot
);
smile.castShadow = false;
// Static soft gripper; there are no additional articulated joints.
addRounded(
0.67,
0.24,
0.55,
0.11,
coral,
new THREE.Vector3(0, 1.88, 0),
armPivot
);
addRounded(
0.73,
0.30,
0.61,
0.13,
cream,
new THREE.Vector3(0, 2.08, 0),
armPivot
);
addRounded(
0.17,
0.34,
0.37,
0.075,
mint,
new THREE.Vector3(0, 2.32, 0.04),
armPivot
);
const leftFinger = addRounded(
0.16,
0.31,
0.34,
0.07,
mint,
new THREE.Vector3(-0.25, 2.27, 0.015),
armPivot
);
leftFinger.rotation.z = -0.13;
const rightFinger = addRounded(
0.16,
0.31,
0.34,
0.07,
mint,
new THREE.Vector3(0.25, 2.27, 0.015),
armPivot
);
rightFinger.rotation.z = 0.13;
// Rotating yellow pointer, local +Y.
const pointerShape = new THREE.Shape();
pointerShape.moveTo(0, 0.88);
pointerShape.lineTo(0.06, 0.71);
pointerShape.lineTo(0.026, 0.71);
pointerShape.lineTo(0.026, 0.48);
pointerShape.lineTo(-0.026, 0.48);
pointerShape.lineTo(-0.026, 0.71);
pointerShape.lineTo(-0.06, 0.71);
pointerShape.closePath();
const pointer = addMesh(
new THREE.ExtrudeGeometry(pointerShape, {
depth: 0.035,
bevelEnabled: true,
bevelThickness: 0.008,
bevelSize: 0.008,
bevelSegments: 2
}),
yellow,
armPivot
);
pointer.position.z = 0.52;
// ------------------------------------------------------------
// UI state and motion
// ------------------------------------------------------------
const angleSlider = document.getElementById("angleSlider");
const angleValue = document.getElementById("angleValue");
const motionState = document.getElementById("motionState");
const playButton = document.getElementById("playButton");
const cutawayButton = document.getElementById("cutawayButton");
const resetButton = document.getElementById("resetButton");
let angle = 8;
let playing = true;
let sweepClock = 0;
function smoothStep(t) {
const x = THREE.MathUtils.clamp(t, 0, 1);
return x * x * (3 - 2 * x);
}
function sweepAngle(time) {
const cycle = time % 10;
const span = MAX_ANGLE - MIN_ANGLE;
if (cycle < 1.1) {
return MIN_ANGLE;
}
if (cycle < 4.6) {
return MIN_ANGLE + span * smoothStep((cycle - 1.1) / 3.5);
}
if (cycle < 6.2) {
return MAX_ANGLE;
}
if (cycle < 9.7) {
return MAX_ANGLE - span * smoothStep((cycle - 6.2) / 3.5);
}
return MIN_ANGLE;
}
function formatAngle(value) {
const rounded = Math.round(value);
const sign = rounded >= 0 ? "+" : "−";
return `${sign}${String(Math.abs(rounded)).padStart(2, "0")}°`;
}
function updateReadout() {
angleValue.textContent = formatAngle(angle);
angleSlider.value = String(Math.round(angle));
if (!playing) {
motionState.textContent = "Manual angle selected";
} else if (
Math.abs(angle - MIN_ANGLE) < 0.7 ||
Math.abs(angle - MAX_ANGLE) < 0.7
) {
motionState.textContent = "Mechanical stop reached";
} else {
motionState.textContent = "Sweeping between stops";
}
}
angleSlider.addEventListener("input", () => {
angle = Number(angleSlider.value);
playing = false;
playButton.textContent = "Play sweep";
updateReadout();
});
playButton.addEventListener("click", () => {
playing = !playing;
if (playing && (
Math.abs(angle - MIN_ANGLE) < 0.1 ||
Math.abs(angle - MAX_ANGLE) < 0.1
)) {
sweepClock = 0;
}
playButton.textContent = playing ? "Pause sweep" : "Play sweep";
updateReadout();
});
cutawayButton.addEventListener("click", () => {
const isOpen = internals.visible;
internals.visible = !isOpen;
clearCover.visible = isOpen;
cutawayButton.textContent = isOpen
? "Open cutaway"
: "Close cutaway";
});
// ------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, keyboard
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 2.02, 0);
const defaultCamera = {
azimuth: 0.57,
polar: 1.255,
radius: 7.55,
target: new THREE.Vector3(0, 2.02, 0)
};
let azimuth = defaultCamera.azimuth;
let polar = defaultCamera.polar;
let radius = defaultCamera.radius;
const activePointers = new Map();
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
cameraTarget.x + radius * sinPolar * Math.sin(azimuth),
cameraTarget.y + radius * Math.cos(polar),
cameraTarget.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
azimuth = defaultCamera.azimuth;
polar = defaultCamera.polar;
radius = defaultCamera.radius;
cameraTarget.copy(defaultCamera.target);
updateCamera();
}
resetButton.addEventListener("click", resetCamera);
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
dragging = true;
panning = event.shiftKey || event.button === 2;
previousX = event.clientX;
previousY = event.clientY;
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) {
return;
}
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (renderer.domElement._pinchDistance) {
const scale = renderer.domElement._pinchDistance / distance;
radius = THREE.MathUtils.clamp(radius * scale, 4.2, 11.5);
}
renderer.domElement._pinchDistance = distance;
return;
}
if (!dragging) {
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const panScale = radius * 0.0012;
cameraTarget.addScaledVector(right, -dx * panScale);
cameraTarget.addScaledVector(up, dy * panScale);
cameraTarget.y = THREE.MathUtils.clamp(
cameraTarget.y,
0.7,
4.0
);
} else {
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(
polar + dy * 0.005,
0.48,
1.48
);
}
});
function releasePointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size === 0) {
dragging = false;
panning = false;
renderer.domElement._pinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
4.2,
11.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
event.preventDefault();
playing = false;
playButton.textContent = "Play sweep";
const step = event.key === "ArrowLeft" ? -1 : 1;
angle = THREE.MathUtils.clamp(
angle + step,
MIN_ANGLE,
MAX_ANGLE
);
updateReadout();
}
});
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
sweepClock += delta;
angle = sweepAngle(sweepClock);
}
armPivot.rotation.z = THREE.MathUtils.degToRad(angle);
updateReadout();
updateCamera();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```