Prompt specification
Build or customize the Three.js 3D scene "Arm Chain With Visible Joint Axes" 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: Arm Chain With Visible Joint Axes
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/arm-chain-with-visible-joint-axes-x3733
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a low-poly articulated arm mounted on a small shoulder pedestal. Separate the upper arm, elbow housing, forearm, wrist, and hand with clear joint boundaries while keeping them visibly connected. Draw short local-axis markers at the shoulder and elbow. Provide a few rotation controls so turning the shoulder carries the entire downstream assembly, whereas moving the elbow affects only the forearm and hand. Preserve the length of every segment throughout all shoulder and elbow movements.
Working Three.js Starter (arm-chain-with-visible-joint-axes-x3733):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Low-Poly Articulated Arm</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(12, 18, 30, 0.86);
--border: rgba(255, 255, 255, 0.12);
--muted: #9aa9bd;
--text: #edf4ff;
--accent: #62e3d4;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0b111d;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
top: 18px;
left: 18px;
width: min(330px, calc(100vw - 36px));
padding: 18px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.36);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
user-select: none;
}
h1 {
margin: 0 0 5px;
font-size: 18px;
letter-spacing: 0.01em;
}
.subtitle {
margin: 0 0 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.fixed-note {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 17px;
padding: 9px 11px;
border: 1px solid rgba(98, 227, 212, 0.2);
border-radius: 10px;
background: rgba(98, 227, 212, 0.07);
color: #baf7ef;
font-size: 11px;
line-height: 1.35;
}
.fixed-note::before {
content: "";
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px var(--accent);
}
.control {
margin: 0 0 15px;
}
.control-header {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
font-size: 12px;
}
.control-header label {
color: #d7e2f1;
font-weight: 600;
}
output {
min-width: 52px;
color: var(--accent);
font-variant-numeric: tabular-nums;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 999px;
outline: none;
background: #2a3548;
accent-color: var(--accent);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 2px solid #0d1421;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(98, 227, 212, 0.4);
-webkit-appearance: none;
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 2px solid #0d1421;
border-radius: 50%;
background: var(--accent);
}
.divider {
height: 1px;
margin: 17px 0;
background: var(--border);
}
button {
width: 100%;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 10px;
background: rgba(255, 255, 255, 0.07);
color: var(--text);
font: inherit;
font-size: 12px;
font-weight: 650;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.12);
}
button:active {
transform: translateY(1px);
}
.legend {
display: flex;
justify-content: space-between;
margin-top: 15px;
color: var(--muted);
font-size: 10px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.legend i {
width: 13px;
height: 3px;
border-radius: 3px;
}
.x {
background: #ff5d73;
}
.y {
background: #68e88a;
}
.z {
background: #55a8ff;
}
.hint {
position: fixed;
right: 18px;
bottom: 16px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 999px;
background: rgba(10, 15, 25, 0.68);
color: #aebbd0;
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 600px) {
.panel {
top: 10px;
left: 10px;
width: min(305px, calc(100vw - 20px));
padding: 14px;
}
.subtitle {
margin-bottom: 11px;
}
.fixed-note {
margin-bottom: 12px;
}
.control {
margin-bottom: 11px;
}
.hint {
right: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<aside class="panel">
<h1>Articulated Arm</h1>
<p class="subtitle">
Rotate the shoulder to carry the complete downstream assembly.
The elbow hinge moves only the forearm, wrist, and hand.
</p>
<div class="fixed-note">
Fixed pivot hierarchy — no link scaling or telescoping is used.
</div>
<div class="control">
<div class="control-header">
<label for="shoulderYaw">Shoulder yaw</label>
<output id="shoulderYawValue" for="shoulderYaw">−24°</output>
</div>
<input id="shoulderYaw" type="range" min="-100" max="100" step="1" value="-24">
</div>
<div class="control">
<div class="control-header">
<label for="shoulderPitch">Shoulder pitch</label>
<output id="shoulderPitchValue" for="shoulderPitch">−12°</output>
</div>
<input id="shoulderPitch" type="range" min="-85" max="85" step="1" value="-12">
</div>
<div class="control">
<div class="control-header">
<label for="elbow">Elbow flexion</label>
<output id="elbowValue" for="elbow">34°</output>
</div>
<input id="elbow" type="range" min="0" max="145" step="1" value="34">
</div>
<div class="control">
<div class="control-header">
<label for="wrist">Wrist pitch</label>
<output id="wristValue" for="wrist">8°</output>
</div>
<input id="wrist" type="range" min="-50" max="50" step="1" value="8">
</div>
<div class="divider"></div>
<button id="reset" type="button">Reset pose and camera</button>
<div class="legend" aria-label="Local axis colors">
<span><i class="x"></i>X</span>
<span><i class="y"></i>Y</span>
<span><i class="z"></i>Z</span>
</div>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom</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");
// ---------------------------------------------------------------------
// Renderer, scene, and camera
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b111d);
scene.fog = new THREE.Fog(0x0b111d, 9, 19);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.05,
60
);
const cameraState = {
radius: 8.1,
theta: 0.72,
phi: 1.12,
target: new THREE.Vector3(0, 2.55, 0)
};
function updateCamera() {
const { radius, theta, phi, target } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
// ---------------------------------------------------------------------
// Lighting and environment
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xcfe8ff, 0x172033, 2.0));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(4.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x65aaff, 1.8);
rimLight.position.set(-5, 4, -4);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x101827,
roughness: 0.95,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(18, 36, 0x31445f, 0x1b293d);
grid.position.y = 0.008;
grid.material.transparent = true;
grid.material.opacity = 0.35;
scene.add(grid);
// ---------------------------------------------------------------------
// Materials and geometry helpers
// ---------------------------------------------------------------------
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.08,
flatShading: true,
...options
});
}
const materials = {
pedestal: makeMaterial(0x354154, { roughness: 0.82 }),
pedestalTrim: makeMaterial(0x1d2838, { roughness: 0.6 }),
shoulder: makeMaterial(0xe5edf7, { metalness: 0.25 }),
upper: makeMaterial(0xf3a23b, { metalness: 0.12 }),
upperPanel: makeMaterial(0xffc260),
elbow: makeMaterial(0x3d5878, { metalness: 0.25 }),
forearm: makeMaterial(0x39b7ae, { metalness: 0.15 }),
forearmPanel: makeMaterial(0x6ce4d7),
collar: makeMaterial(0x202b3a, { metalness: 0.28 }),
wrist: makeMaterial(0x596b82, { metalness: 0.28 }),
hand: makeMaterial(0xf0d7a5, { roughness: 0.82 }),
fingers: makeMaterial(0xe5bf83, { roughness: 0.84 })
};
function prepareMesh(mesh, parent, position = [0, 0, 0]) {
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
material,
radialSegments = 8
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
radialSegments,
1,
false
),
material
);
return prepareMesh(mesh, parent, position);
}
function addBox(
parent,
size,
position,
material,
rotation = [0, 0, 0]
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(...size),
material
);
mesh.rotation.set(...rotation);
return prepareMesh(mesh, parent, position);
}
// Local X/Y/Z axis markers.
function addAxisGizmo(parent, size) {
const axes = [
{
direction: new THREE.Vector3(1, 0, 0),
color: 0xff5d73
},
{
direction: new THREE.Vector3(0, 1, 0),
color: 0x68e88a
},
{
direction: new THREE.Vector3(0, 0, 1),
color: 0x55a8ff
}
];
axes.forEach(({ direction, color }) => {
const arrow = new THREE.ArrowHelper(
direction,
new THREE.Vector3(0, 0, 0),
size,
color,
size * 0.23,
size * 0.12
);
arrow.traverse((object) => {
if (object.material) {
object.material.depthTest = false;
object.material.depthWrite = false;
object.material.transparent = true;
object.material.opacity = 0.88;
}
object.renderOrder = 30;
});
parent.add(arrow);
});
const origin = new THREE.Mesh(
new THREE.IcosahedronGeometry(size * 0.07, 0),
new THREE.MeshBasicMaterial({
color: 0xffffff,
depthTest: false
})
);
origin.renderOrder = 31;
parent.add(origin);
}
// ---------------------------------------------------------------------
// Pedestal
// ---------------------------------------------------------------------
const SHOULDER_Y = 1.42;
const UPPER_ARM_LENGTH = 1.65;
const FOREARM_LENGTH = 1.45;
const pedestal = new THREE.Group();
scene.add(pedestal);
addCylinder(
pedestal,
0.60,
0.67,
0.18,
[0, 0.09, 0],
materials.pedestal,
8
);
addCylinder(
pedestal,
0.51,
0.57,
0.065,
[0, 0.205, 0],
materials.pedestalTrim,
8
);
addCylinder(
pedestal,
0.235,
0.33,
1.02,
[0, 0.745, 0],
materials.pedestal,
8
);
addBox(
pedestal,
[0.72, 0.27, 0.47],
[0, 1.17, 0],
materials.pedestalTrim
);
addCylinder(
pedestal,
0.25,
0.31,
0.15,
[0, 1.31, 0],
materials.pedestal,
8
);
// ---------------------------------------------------------------------
// Articulation hierarchy
//
// pedestal
// └── shoulderYaw
// └── shoulderPitch
// ├── shoulder housing
// ├── upper arm
// └── elbowHinge
// ├── elbow housing
// ├── forearm
// └── wristHinge
// ├── wrist housing
// └── hand
//
// Every link has a fixed dimension. Motion is produced exclusively by
// rotating pivot groups, so segment lengths cannot change.
// ---------------------------------------------------------------------
const shoulderYaw = new THREE.Group();
shoulderYaw.position.y = SHOULDER_Y;
scene.add(shoulderYaw);
const shoulderPitch = new THREE.Group();
shoulderYaw.add(shoulderPitch);
// Shoulder joint housing and transverse axle.
const shoulderBall = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.285, 0),
materials.shoulder
);
prepareMesh(shoulderBall, shoulderPitch);
const shoulderAxle = addCylinder(
shoulderPitch,
0.115,
0.115,
0.74,
[0, 0, 0],
materials.collar,
8
);
shoulderAxle.rotation.z = Math.PI / 2;
// Upper arm: its center is exactly halfway between the two joint pivots.
addCylinder(
shoulderPitch,
0.205,
0.275,
UPPER_ARM_LENGTH,
[0, UPPER_ARM_LENGTH / 2, 0],
materials.upper,
7
);
addCylinder(
shoulderPitch,
0.285,
0.285,
0.11,
[0, 0.16, 0],
materials.collar,
8
);
addCylinder(
shoulderPitch,
0.225,
0.225,
0.09,
[0, UPPER_ARM_LENGTH - 0.17, 0],
materials.collar,
8
);
addBox(
shoulderPitch,
[0.09, UPPER_ARM_LENGTH * 0.64, 0.30],
[0, UPPER_ARM_LENGTH * 0.49, 0.19],
materials.upperPanel
);
// Elbow pivot. This group is downstream of both shoulder rotations.
const elbowHinge = new THREE.Group();
elbowHinge.position.y = UPPER_ARM_LENGTH;
shoulderPitch.add(elbowHinge);
const elbowBall = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.255, 0),
materials.elbow
);
prepareMesh(elbowBall, elbowHinge);
const elbowAxle = addCylinder(
elbowHinge,
0.105,
0.105,
0.68,
[0, 0, 0],
materials.collar,
8
);
elbowAxle.rotation.z = Math.PI / 2;
// Forearm: fixed length from the elbow pivot to the wrist pivot.
addCylinder(
elbowHinge,
0.145,
0.205,
FOREARM_LENGTH,
[0, FOREARM_LENGTH / 2, 0],
materials.forearm,
6
);
addCylinder(
elbowHinge,
0.215,
0.215,
0.105,
[0, 0.17, 0],
materials.collar,
8
);
addCylinder(
elbowHinge,
0.165,
0.165,
0.085,
[0, FOREARM_LENGTH - 0.13, 0],
materials.collar,
8
);
addBox(
elbowHinge,
[0.08, FOREARM_LENGTH * 0.62, 0.22],
[0, FOREARM_LENGTH * 0.48, 0.135],
materials.forearmPanel
);
// Wrist pivot.
const wristHinge = new THREE.Group();
wristHinge.position.y = FOREARM_LENGTH;
elbowHinge.add(wristHinge);
addCylinder(
wristHinge,
0.19,
0.19,
0.24,
[0, 0, 0],
materials.wrist,
8
);
addCylinder(
wristHinge,
0.205,
0.205,
0.065,
[0, 0.105, 0],
materials.collar,
8
);
// Low-poly hand and fingers.
const hand = new THREE.Group();
wristHinge.add(hand);
addBox(
hand,
[0.48, 0.38, 0.27],
[0, 0.25, 0],
materials.hand
);
addBox(
hand,
[0.12, 0.38, 0.18],
[-0.16, 0.56, 0],
materials.fingers
);
addBox(
hand,
[0.13, 0.46, 0.19],
[0, 0.62, 0],
materials.fingers
);
addBox(
hand,
[0.12, 0.38, 0.18],
[0.16, 0.56, 0],
materials.fingers
);
addBox(
hand,
[0.14, 0.30, 0.18],
[-0.29, 0.25, 0],
materials.fingers,
[0, 0, -0.62]
);
// Short local-axis markers.
addAxisGizmo(shoulderPitch, 0.43);
addAxisGizmo(elbowHinge, 0.37);
// ---------------------------------------------------------------------
// Controls
// ---------------------------------------------------------------------
const controls = [
{
input: document.getElementById("shoulderYaw"),
output: document.getElementById("shoulderYawValue"),
apply: (degrees) => {
shoulderYaw.rotation.y = THREE.MathUtils.degToRad(degrees);
}
},
{
input: document.getElementById("shoulderPitch"),
output: document.getElementById("shoulderPitchValue"),
apply: (degrees) => {
shoulderPitch.rotation.x = THREE.MathUtils.degToRad(degrees);
}
},
{
input: document.getElementById("elbow"),
output: document.getElementById("elbowValue"),
apply: (degrees) => {
elbowHinge.rotation.x = THREE.MathUtils.degToRad(degrees);
}
},
{
input: document.getElementById("wrist"),
output: document.getElementById("wristValue"),
apply: (degrees) => {
wristHinge.rotation.x = THREE.MathUtils.degToRad(degrees);
}
}
];
function formatAngle(value) {
const number = Number(value);
return `${number < 0 ? "−" : ""}${Math.abs(number)}°`;
}
function syncControl(control) {
const value = Number(control.input.value);
control.apply(value);
control.output.textContent = formatAngle(value);
}
controls.forEach((control) => {
control.input.addEventListener("input", () => syncControl(control));
syncControl(control);
});
const defaultPose = {
shoulderYaw: -24,
shoulderPitch: -12,
elbow: 34,
wrist: 8
};
document.getElementById("reset").addEventListener("click", () => {
controls.forEach((control) => {
const key = control.input.id;
control.input.value = defaultPose[key];
syncControl(control);
});
cameraState.radius = 8.1;
cameraState.theta = 0.72;
cameraState.phi = 1.12;
cameraState.target.set(0, 2.55, 0);
updateCamera();
});
// ---------------------------------------------------------------------
// Camera controls implemented directly here, without external addons.
// ---------------------------------------------------------------------
const canvas = renderer.domElement;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.005,
0.28,
1.46
);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
4.4,
12
);
updateCamera();
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```