Prompt specification
Build or customize the Three.js 3D scene "Umbrella rib hub comparison" 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: Umbrella rib hub comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/umbrella-rib-hub-comparison-x0629
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: umbrella rib hub comparison. Show an umbrella's central shaft with one deployed rib and one folded rib beside a cutaway slider; expose how struts connect slider movement to canopy support. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (umbrella-rib-hub-comparison-x0629):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Umbrella Rib Hub — Three.js Cutaway Study</title>
<style>
:root {
--paper: #f2efe7;
--paper-soft: rgba(250, 248, 242, 0.82);
--ink: #18272c;
--muted: #69777a;
--line: rgba(24, 39, 44, 0.14);
--teal: #079c98;
--amber: #e39a38;
--coral: #d85a4d;
--brass: #c7a15a;
}
* { box-sizing: border-box; }
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input { font: inherit; }
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas.dragging { cursor: grabbing; }
.header {
position: fixed;
z-index: 5;
top: 28px;
left: 32px;
max-width: 500px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 0 4px rgba(216, 90, 77, 0.12);
}
h1 {
margin: 0;
font-size: clamp(32px, 4.1vw, 58px);
font-weight: 690;
line-height: 0.98;
letter-spacing: -0.055em;
}
h1 em {
color: var(--teal);
font-family: Georgia, "Times New Roman", serif;
font-weight: 400;
}
.header p {
max-width: 430px;
margin: 14px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.readout {
position: fixed;
z-index: 5;
top: 28px;
right: 30px;
width: 246px;
padding: 16px;
border: 1px solid rgba(24, 39, 44, 0.1);
border-radius: 16px;
background: var(--paper-soft);
box-shadow: 0 16px 48px rgba(31, 42, 43, 0.08);
backdrop-filter: blur(14px);
}
.panel-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding-bottom: 12px;
border-bottom: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#state {
padding: 4px 7px;
border-radius: 999px;
background: rgba(227, 154, 56, 0.14);
color: #a96916;
letter-spacing: 0.08em;
}
.metric {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 14px;
padding-top: 13px;
}
.metric span {
color: var(--muted);
font-size: 11px;
}
.metric strong {
font-size: 21px;
font-weight: 620;
letter-spacing: -0.035em;
}
.microcopy {
margin: 13px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.legend {
position: fixed;
z-index: 5;
left: 32px;
bottom: 132px;
display: grid;
gap: 9px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.swatch {
width: 20px;
height: 3px;
border-radius: 2px;
background: var(--teal);
}
.swatch.amber { background: var(--amber); }
.swatch.coral { background: var(--coral); }
.scene-label {
position: fixed;
z-index: 3;
top: 0;
left: 0;
min-width: 112px;
padding: 7px 9px 7px 11px;
border: 1px solid rgba(24, 39, 44, 0.12);
border-left: 3px solid var(--teal);
border-radius: 7px;
background: rgba(249, 247, 241, 0.87);
box-shadow: 0 7px 24px rgba(30, 44, 46, 0.08);
color: var(--ink);
pointer-events: none;
white-space: nowrap;
backdrop-filter: blur(8px);
transition: opacity 120ms linear;
}
.scene-label.amber { border-left-color: var(--amber); }
.scene-label.coral { border-left-color: var(--coral); }
.scene-label.graphite { border-left-color: #53656a; }
.scene-label span {
display: block;
margin-bottom: 2px;
color: var(--muted);
font-size: 8px;
font-weight: 760;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.scene-label strong {
display: block;
font-size: 10px;
font-weight: 720;
letter-spacing: 0.02em;
}
.scene-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
}
.control-dock {
position: fixed;
z-index: 6;
left: 50%;
bottom: 22px;
width: min(760px, calc(100vw - 32px));
padding: 14px 16px 12px;
transform: translateX(-50%);
border: 1px solid rgba(24, 39, 44, 0.12);
border-radius: 18px;
background: rgba(250, 248, 242, 0.91);
box-shadow: 0 20px 60px rgba(31, 42, 43, 0.12);
backdrop-filter: blur(18px);
}
.control-top {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.control-title {
color: var(--muted);
font-size: 10px;
font-weight: 760;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#positionText {
color: var(--ink);
font-variant-numeric: tabular-nums;
}
.range-row {
display: grid;
grid-template-columns: 42px 1fr 62px;
align-items: center;
gap: 12px;
}
.range-row span {
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.range-row span:last-child { text-align: right; }
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 99px;
outline: none;
background:
linear-gradient(
90deg,
var(--coral) 0%,
var(--coral) var(--pct, 0%),
rgba(24, 39, 44, 0.13) var(--pct, 0%),
rgba(24, 39, 44, 0.13) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 4px solid #fff;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 2px 8px rgba(24, 39, 44, 0.22);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 4px solid #fff;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 2px 8px rgba(24, 39, 44, 0.22);
}
.actions {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
}
.actions button {
padding: 7px 10px;
border: 1px solid rgba(24, 39, 44, 0.13);
border-radius: 8px;
background: rgba(255, 255, 255, 0.52);
color: var(--ink);
font-size: 10px;
font-weight: 700;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}
.actions button:hover {
border-color: rgba(24, 39, 44, 0.28);
background: #fff;
transform: translateY(-1px);
}
.actions button.active {
border-color: rgba(216, 90, 77, 0.3);
background: rgba(216, 90, 77, 0.12);
color: #a63e34;
}
.hint {
margin-left: auto;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.04em;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: var(--paper);
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 850px) {
.header { top: 18px; left: 18px; }
.header p { display: none; }
.readout {
top: auto;
right: 14px;
bottom: 142px;
width: 205px;
transform: scale(0.92);
transform-origin: bottom right;
}
.legend { left: 18px; bottom: 135px; }
.scene-label { transform: scale(0.9); }
}
@media (max-width: 560px) {
h1 { font-size: 32px; }
.eyebrow { font-size: 9px; }
.readout,
.legend { display: none; }
.control-dock { bottom: 12px; padding: 12px; }
.range-row { grid-template-columns: 1fr; gap: 8px; }
.range-row span { display: none; }
.actions .hint { display: none; }
.scene-label { min-width: 96px; padding: 6px 8px; }
.scene-label small { display: none; }
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive 3D umbrella rib and slider mechanism"></div>
<header class="header">
<div class="eyebrow"><span class="live-dot"></span> Mechanism study / 04</div>
<h1>Rib hub <em>comparison</em></h1>
<p>
A deployed reference rib and a live folding rib share one shaft.
Move the cutaway runner to expose the strut load path.
</p>
</header>
<aside class="readout" aria-live="polite">
<div class="panel-head">
Live linkage
<span id="state">Folded</span>
</div>
<div class="metric">
<span>Runner travel</span>
<strong id="travel">0 mm</strong>
</div>
<div class="metric">
<span>Rib spread</span>
<strong id="spread">2°</strong>
</div>
<p class="microcopy">
The cutaway exposes the cam, spring and pivot pins. The upper pivots
transfer runner motion into the canopy ribs.
</p>
</aside>
<div class="legend" aria-hidden="true">
<div class="legend-item"><span class="swatch"></span> Deployed reference</div>
<div class="legend-item"><span class="swatch amber"></span> Live folding rib</div>
<div class="legend-item"><span class="swatch coral"></span> Cutaway runner</div>
</div>
<div id="labelHub" class="scene-label graphite">
<span>Central assembly</span>
<strong>TOP HUB</strong>
<small>Rib rotation pivot</small>
</div>
<div id="labelDeployed" class="scene-label">
<span>Reference rib</span>
<strong>DEPLOYED</strong>
<small>Locked comparison state</small>
</div>
<div id="labelFolded" class="scene-label amber">
<span>Live rib</span>
<strong id="foldState">FOLDED</strong>
<small id="foldAngle">2° from shaft</small>
</div>
<div id="labelSlider" class="scene-label coral">
<span>Sectioned component</span>
<strong>CUTAWAY RUNNER</strong>
<small>Cam + spring exposed</small>
</div>
<div id="labelStrut" class="scene-label graphite">
<span>Load path</span>
<strong>SUPPORT STRUT</strong>
<small>Runner → rib pivot</small>
</div>
<section class="control-dock" aria-label="Mechanism controls">
<div class="control-top">
<span class="control-title">Runner position</span>
<span id="positionText">0%</span>
</div>
<div class="range-row">
<span>Folded</span>
<input
id="travelRange"
type="range"
min="0"
max="100"
value="0"
step="1"
aria-label="Move umbrella runner"
/>
<span>Deployed</span>
</div>
<div class="actions">
<button id="autoButton" type="button">▶ Cycle motion</button>
<button id="resetButton" type="button">↺ Reset view</button>
<span class="hint">Drag to orbit · Scroll to zoom</span>
</div>
</section>
<div id="loading">Loading cutaway assembly…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const range = document.querySelector("#travelRange");
const autoButton = document.querySelector("#autoButton");
const resetButton = document.querySelector("#resetButton");
const stateReadout = document.querySelector("#state");
const travelReadout = document.querySelector("#travel");
const spreadReadout = document.querySelector("#spread");
const positionReadout = document.querySelector("#positionText");
const foldState = document.querySelector("#foldState");
const foldAngle = document.querySelector("#foldAngle");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf2efe7);
scene.fog = new THREE.Fog(0xf2efe7, 14, 25);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional cutaway of an umbrella hub, folding rib and sliding runner"
);
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
60
);
const orbit = {
azimuth: 0.22,
polar: 1.17,
radius: window.innerWidth < 560 ? 12.1 : 10.4,
target: new THREE.Vector3(0, 0.65, 0)
};
function updateCamera() {
const sinPolar = Math.sin(orbit.polar);
camera.position.set(
orbit.target.x +
orbit.radius * sinPolar * Math.sin(orbit.azimuth),
orbit.target.y + orbit.radius * Math.cos(orbit.polar),
orbit.target.z +
orbit.radius * sinPolar * Math.cos(orbit.azimuth)
);
camera.lookAt(orbit.target);
}
updateCamera();
// Direct camera controls; no examples/addons are used.
let dragging = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
orbit.azimuth -= dx * 0.006;
orbit.polar = THREE.MathUtils.clamp(
orbit.polar + dy * 0.005,
0.68,
1.52
);
updateCamera();
});
function endDrag(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", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.006,
7.1,
15.5
);
updateCamera();
},
{ passive: false }
);
resetButton.addEventListener("click", () => {
orbit.azimuth = 0.22;
orbit.polar = 1.17;
orbit.radius = window.innerWidth < 560 ? 12.1 : 10.4;
orbit.target.set(0, 0.65, 0);
updateCamera();
});
const hemisphere = new THREE.HemisphereLight(0xfffbef, 0x9aa8a5, 2.35);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff6df, 3.15);
keyLight.position.set(4.5, 8.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xb8d8dc, 1.45);
rimLight.position.set(-5, 3, -4);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffbb73, 11, 9, 2);
warmFill.position.set(-4.5, 1.8, 4.5);
scene.add(warmFill);
const materials = {
shaft: new THREE.MeshStandardMaterial({
color: 0x34464b,
metalness: 0.82,
roughness: 0.25
}),
shaftHighlight: new THREE.MeshStandardMaterial({
color: 0x9caeb0,
metalness: 0.9,
roughness: 0.2
}),
hub: new THREE.MeshStandardMaterial({
color: 0x6e7c7e,
metalness: 0.78,
roughness: 0.28
}),
dark: new THREE.MeshStandardMaterial({
color: 0x223238,
metalness: 0.6,
roughness: 0.34
}),
teal: new THREE.MeshStandardMaterial({
color: 0x079c98,
metalness: 0.46,
roughness: 0.32,
emissive: 0x023c3a,
emissiveIntensity: 0.2
}),
amber: new THREE.MeshStandardMaterial({
color: 0xe39a38,
metalness: 0.42,
roughness: 0.34,
emissive: 0x4b2707,
emissiveIntensity: 0.16
}),
coral: new THREE.MeshStandardMaterial({
color: 0xd85a4d,
metalness: 0.48,
roughness: 0.31,
emissive: 0x4b100c,
emissiveIntensity: 0.12
}),
brass: new THREE.MeshStandardMaterial({
color: 0xc7a15a,
metalness: 0.82,
roughness: 0.28
}),
spring: new THREE.MeshStandardMaterial({
color: 0xb6c0c1,
metalness: 0.9,
roughness: 0.22
}),
floor: new THREE.MeshStandardMaterial({
color: 0xe9e5dc,
roughness: 0.95,
metalness: 0
})
};
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.94;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(14, 28, 0x8a9897, 0xb4bdb9);
grid.position.y = -2.925;
grid.material.transparent = true;
grid.material.opacity = 0.19;
scene.add(grid);
const yAxis = new THREE.Vector3(0, 1, 0);
const unitCylinder = new THREE.CylinderGeometry(1, 1, 1, 14);
function addCylinderBetween(parent, a, b, radius, material, radialSegments = 14) {
const direction = new THREE.Vector3().subVectors(b, a);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
direction.length(),
radialSegments
),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(yAxis, direction.clone().normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, size, position, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Central umbrella shaft.
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.115, 4.25, 24),
materials.shaft
);
shaft.position.y = -0.06;
shaft.castShadow = true;
scene.add(shaft);
const shaftHighlight = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 4.1, 10),
materials.shaftHighlight
);
shaftHighlight.position.set(0, -0.04, 0.095);
scene.add(shaftHighlight);
const bottomFerrule = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.12, 0.27, 18),
materials.hub
);
bottomFerrule.position.y = -2.25;
bottomFerrule.castShadow = true;
scene.add(bottomFerrule);
const handleCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, -2.15, 0),
new THREE.Vector3(0, -2.53, 0),
new THREE.Vector3(-0.18, -2.73, 0),
new THREE.Vector3(-0.52, -2.72, 0),
new THREE.Vector3(-0.68, -2.49, 0),
new THREE.Vector3(-0.65, -2.31, 0)
]);
const handle = new THREE.Mesh(
new THREE.TubeGeometry(handleCurve, 44, 0.13, 12, false),
materials.coral
);
handle.castShadow = true;
scene.add(handle);
// Top hub and hinge details.
const hubPosition = new THREE.Vector3(0, 1.74, 0);
const hubBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.33, 0.43, 0.37, 28),
materials.hub
);
hubBody.position.copy(hubPosition);
hubBody.castShadow = true;
scene.add(hubBody);
const hubCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.23, 0.31, 0.18, 24),
materials.shaft
);
hubCap.position.set(0, 1.98, 0);
hubCap.castShadow = true;
scene.add(hubCap);
const hubRing = new THREE.Mesh(
new THREE.TorusGeometry(0.35, 0.043, 10, 48),
materials.brass
);
hubRing.rotation.x = Math.PI / 2;
hubRing.position.set(0, 1.83, 0);
scene.add(hubRing);
for (const z of [-0.105, 0.105]) {
const hinge = new THREE.Mesh(
new THREE.CylinderGeometry(0.115, 0.115, 0.12, 18),
materials.dark
);
hinge.rotation.x = Math.PI / 2;
hinge.position.set(0, 1.74, z);
hinge.castShadow = true;
scene.add(hinge);
}
function makeRib(length, color, opacity = 1) {
const group = new THREE.Group();
group.position.copy(hubPosition);
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(length * 0.18, -0.018, 0),
new THREE.Vector3(length * 0.42, -0.05, 0.008),
new THREE.Vector3(length * 0.73, -0.035, 0.012),
new THREE.Vector3(length, 0.015, 0)
]);
const ribMaterial = color.clone();
ribMaterial.transparent = opacity < 1;
ribMaterial.opacity = opacity;
ribMaterial.depthWrite = opacity >= 1;
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 56, 0.055, 9, false),
ribMaterial
);
tube.castShadow = opacity >= 1;
group.add(tube);
// A narrow translucent strip suggests the canopy edge without hiding
// the linkage underneath.
const fabricMaterial = new THREE.MeshStandardMaterial({
color,
transparent: true,
opacity: 0.105 * opacity,
roughness: 0.82,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const positions = [];
const indices = [];
const samples = 24;
for (let i = 0; i <= samples; i++) {
const t = i / samples;
const p = curve.getPoint(t);
const width = 0.028 + Math.sin(Math.PI * t) * 0.145;
p.y -= 0.034;
positions.push(p.x, p.y, p.z - width);
positions.push(p.x, p.y, p.z + width);
if (i < samples) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, b, c, b, d, c);
}
}
const fabricGeometry = new THREE.BufferGeometry();
fabricGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
fabricGeometry.setIndex(indices);
fabricGeometry.computeVertexNormals();
const fabric = new THREE.Mesh(fabricGeometry, fabricMaterial);
group.add(fabric);
const tip = new THREE.Mesh(
new THREE.SphereGeometry(0.093, 16, 12),
ribMaterial
);
tip.position.copy(curve.getPoint(1));
group.add(tip);
const supportLocal = curve.getPoint(0.4);
const supportCollar = new THREE.Mesh(
new THREE.SphereGeometry(0.088, 14, 10),
ribMaterial
);
supportCollar.position.copy(supportLocal);
group.add(supportCollar);
scene.add(group);
return {
group,
curve,
length,
supportLocal,
material: ribMaterial
};
}
const deployedRib = makeRib(2.67, new THREE.Color(0x079c98));
deployedRib.group.rotation.z = Math.PI - 0.04;
const liveRib = makeRib(2.67, new THREE.Color(0xe39a38));
liveRib.group.rotation.z = 1.52;
// Ghosted open position clarifies the swept path of the live rib.
const ghostRib = makeRib(
2.67,
new THREE.Color(0xe39a38),
0.12
);
ghostRib.group.rotation.z = 0.06;
const sweepPoints = [];
for (let i = 0; i <= 64; i++) {
const angle = THREE.MathUtils.lerp(0.06, 1.52, i / 64);
sweepPoints.push(
new THREE.Vector3(
hubPosition.x + Math.cos(angle) * 2.67,
hubPosition.y + Math.sin(angle) * 2.67,
-0.08
)
);
}
const sweepGeometry = new THREE.BufferGeometry().setFromPoints(sweepPoints);
const sweep = new THREE.Line(
sweepGeometry,
new THREE.LineDashedMaterial({
color: 0xc57b20,
dashSize: 0.09,
gapSize: 0.07,
transparent: true,
opacity: 0.48
})
);
sweep.computeLineDistances();
scene.add(sweep);
// Fixed guide rails and mounting brackets around the shaft.
addCylinderBetween(
scene,
new THREE.Vector3(-0.42, -0.48, -0.16),
new THREE.Vector3(-0.42, 0.78, -0.16),
0.035,
materials.dark
);
addCylinderBetween(
scene,
new THREE.Vector3(0.42, -0.48, -0.16),
new THREE.Vector3(0.42, 0.78, -0.16),
0.035,
materials.dark
);
for (const y of [-0.38, 0.68]) {
addBox(
scene,
new THREE.Vector3(0.98, 0.07, 0.08),
new THREE.Vector3(0, y, -0.16),
materials.dark
);
addBox(
scene,
new THREE.Vector3(0.22, 0.06, 0.24),
new THREE.Vector3(0, y, -0.04),
materials.hub
);
}
// The moving runner is sectioned open toward the camera.
const runner = new THREE.Group();
scene.add(runner);
const shellMaterial = materials.coral.clone();
shellMaterial.side = THREE.DoubleSide;
const cutawayShell = new THREE.Mesh(
new THREE.CylinderGeometry(
0.31,
0.31,
0.43,
40,
1,
true,
0.58,
Math.PI * 2 - 1.16
),
shellMaterial
);
cutawayShell.castShadow = true;
runner.add(cutawayShell);
const edgeRadius = 0.31;
const edgeZ = Math.cos(0.58) * edgeRadius;
const edgeX = Math.sin(0.58) * edgeRadius;
addCylinderBetween(
runner,
new THREE.Vector3(edgeX, -0.215, edgeZ),
new THREE.Vector3(edgeX, 0.215, edgeZ),
0.026,
materials.brass
);
addCylinderBetween(
runner,
new THREE.Vector3(-edgeX, -0.215, edgeZ),
new THREE.Vector3(-edgeX, 0.215, edgeZ),
0.026,
materials.brass
);
addBox(
runner,
new THREE.Vector3(0.12, 0.47, 0.22),
new THREE.Vector3(-0.38, 0, -0.02),
materials.coral
);
addBox(
runner,
new THREE.Vector3(0.12, 0.47, 0.22),
new THREE.Vector3(0.38, 0, -0.02),
materials.coral
);
const cam = new THREE.Mesh(
new THREE.CylinderGeometry(0.215, 0.215, 0.15, 24),
materials.brass
);
cam.rotation.x = Math.PI / 2;
cam.position.set(0, 0.015, 0.13);
cam.castShadow = true;
runner.add(cam);
const camCore = new THREE.Mesh(
new THREE.CylinderGeometry(0.087, 0.087, 0.19, 18),
materials.dark
);
camCore.rotation.x = Math.PI / 2;
camCore.position.set(0, 0.015, 0.16);
runner.add(camCore);
class HelixCurve extends THREE.Curve {
constructor(turns, radius, height) {
super();
this.turns = turns;
this.radius = radius;
this.height = height;
}
getPoint(t, target = new THREE.Vector3()) {
const angle = t * Math.PI * 2 * this.turns;
return target.set(
Math.cos(angle) * this.radius,
(t - 0.5) * this.height,
Math.sin(angle) * this.radius
);
}
}
const spring = new THREE.Mesh(
new THREE.TubeGeometry(
new HelixCurve(5.5, 0.16, 0.26),
90,
0.014,
6,
false
),
materials.spring
);
spring.position.set(0, 0.02, 0.23);
runner.add(spring);
const pivotGeometry = new THREE.SphereGeometry(0.075, 16, 12);
const leftPivot = new THREE.Mesh(pivotGeometry, materials.brass);
leftPivot.position.set(-0.38, 0.02, 0.14);
runner.add(leftPivot);
const rightPivot = new THREE.Mesh(pivotGeometry, materials.brass);
rightPivot.position.set(0.38, 0.02, 0.14);
runner.add(rightPivot);
// Small scale ticks make runner travel readable.
for (let i = 0; i <= 6; i++) {
const y = -0.35 + i * 0.18;
const tick = addBox(
scene,
new THREE.Vector3(i % 2 === 0 ? 0.14 : 0.09, 0.012, 0.014),
new THREE.Vector3(-0.58, y, -0.08),
materials.dark
);
tick.castShadow = false;
}
function createStrut(color) {
const group = new THREE.Group();
scene.add(group);
const rodMaterial = new THREE.MeshStandardMaterial({
color,
metalness: 0.7,
roughness: 0.26
});
const rod = new THREE.Mesh(unitCylinder, rodMaterial);
const sleeve = new THREE.Mesh(unitCylinder, materials.dark);
const lowerPin = new THREE.Mesh(pivotGeometry, materials.brass);
const upperPin = new THREE.Mesh(pivotGeometry, rodMaterial);
rod.castShadow = true;
sleeve.castShadow = true;
group.add(rod, sleeve, lowerPin, upperPin);
return { group, rod, sleeve, lowerPin, upperPin };
}
const referenceStrut = createStrut(0x087d7b);
const liveStrut = createStrut(0xc67e22);
const tempDirection = new THREE.Vector3();
const tempMidpoint = new THREE.Vector3();
function updateStrut(strut, lower, upper) {
tempDirection.subVectors(upper, lower);
const length = tempDirection.length();
tempDirection.normalize();
strut.rod.position.copy(lower).add(upper).multiplyScalar(0.5);
strut.rod.quaternion.setFromUnitVectors(yAxis, tempDirection);
strut.rod.scale.set(0.032, length, 0.032);
const sleeveLength = Math.min(0.62, length * 0.36);
tempMidpoint
.copy(lower)
.addScaledVector(tempDirection, sleeveLength * 0.5);
strut.sleeve.position.copy(tempMidpoint);
strut.sleeve.quaternion.setFromUnitVectors(yAxis, tempDirection);
strut.sleeve.scale.set(0.061, sleeveLength, 0.061);
strut.lowerPin.position.copy(lower);
strut.upperPin.position.copy(upper);
}
const deployedUpper = new THREE.Vector3();
const liveUpper = new THREE.Vector3();
const lowerLeft = new THREE.Vector3();
const lowerRight = new THREE.Vector3();
const liveStrutMid = new THREE.Vector3();
let targetTravel = 0;
let currentTravel = 0;
let autoCycle = false;
let cycleStart = performance.now();
function smooth(t) {
return t * t * (3 - 2 * t);
}
function setRangeFill(value) {
range.style.setProperty("--pct", `${value}%`);
}
range.addEventListener("input", () => {
targetTravel = Number(range.value) / 100;
autoCycle = false;
autoButton.classList.remove("active");
autoButton.textContent = "▶ Cycle motion";
});
autoButton.addEventListener("click", () => {
autoCycle = !autoCycle;
cycleStart = performance.now();
autoButton.classList.toggle("active", autoCycle);
autoButton.textContent = autoCycle ? "Ⅱ Pause motion" : "▶ Cycle motion";
});
setRangeFill(0);
const labelHub = document.querySelector("#labelHub");
const labelDeployed = document.querySelector("#labelDeployed");
const labelFolded = document.querySelector("#labelFolded");
const labelSlider = document.querySelector("#labelSlider");
const labelStrut = document.querySelector("#labelStrut");
function placeLabel(element, worldPoint, offsetX = 0, offsetY = 0) {
const projected = worldPoint.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform =
`translate3d(${x + offsetX}px, ${y + offsetY}px, 0) ` +
`translate(-50%, -50%)`;
element.style.opacity = visible ? "1" : "0";
}
let previousTime = performance.now();
function animate(time) {
const delta = Math.min(0.05, (time - previousTime) / 1000);
previousTime = time;
if (autoCycle) {
const elapsed = (time - cycleStart) / 1000;
targetTravel = (Math.sin(elapsed * 0.85 - Math.PI / 2) + 1) * 0.5;
range.value = Math.round(targetTravel * 100);
setRangeFill(targetTravel * 100);
}
currentTravel +=
(targetTravel - currentTravel) * (1 - Math.exp(-delta * 6.2));
const easedTravel = smooth(THREE.MathUtils.clamp(currentTravel, 0, 1));
const runnerY = THREE.MathUtils.lerp(-0.28, 0.63, easedTravel);
const liveAngle = THREE.MathUtils.lerp(1.52, 0.06, easedTravel);
liveRib.group.rotation.z = liveAngle;
runner.position.y = runnerY;
deployedRib.group.updateMatrixWorld(true);
liveRib.group.updateMatrixWorld(true);
deployedUpper
.copy(deployedRib.supportLocal)
.applyMatrix4(deployedRib.group.matrixWorld);
liveUpper
.copy(liveRib.supportLocal)
.applyMatrix4(liveRib.group.matrixWorld);
lowerLeft.set(-0.38, runnerY + 0.02, 0.14);
lowerRight.set(0.38, runnerY + 0.02, 0.14);
updateStrut(referenceStrut, lowerLeft, deployedUpper);
updateStrut(liveStrut, lowerRight, liveUpper);
const spread = Math.round(
THREE.MathUtils.radToDeg(Math.PI / 2 - liveAngle)
);
const travelMM = Math.round(easedTravel * 96);
const percent = Math.round(easedTravel * 100);
let state = "Transition";
if (easedTravel < 0.035) state = "Folded";
else if (easedTravel > 0.965) state = "Deployed";
stateReadout.textContent = state;
travelReadout.textContent = `${travelMM} mm`;
spreadReadout.textContent = `${spread}°`;
positionReadout.textContent = `${percent}%`;
foldState.textContent = state.toUpperCase();
foldAngle.textContent = `${spread}° from shaft`;
const deployedAnchor = deployedRib.curve
.getPoint(0.72)
.applyMatrix4(deployedRib.group.matrixWorld);
const foldedAnchor = liveRib.curve
.getPoint(0.59)
.applyMatrix4(liveRib.group.matrixWorld);
const sliderAnchor = new THREE.Vector3(0.48, runnerY, 0.31);
const hubAnchor = new THREE.Vector3(0.04, 2.08, 0.03);
liveStrutMid
.copy(lowerRight)
.add(liveUpper)
.multiplyScalar(0.5);
placeLabel(labelHub, hubAnchor, 56, -7);
placeLabel(labelDeployed, deployedAnchor, -10, -9);
placeLabel(labelFolded, foldedAnchor, 54, -9);
placeLabel(labelSlider, sliderAnchor, 76, 6);
placeLabel(labelStrut, liveStrutMid, 78, 21);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
</script>
</body>
</html>
```