Prompt specification
Build or customize the Three.js 3D scene "Wheel Hub Rim and Spokes" 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: Wheel Hub Rim and Spokes
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/wheel-hub-rim-and-spokes-x3401
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring parts, wholes, and nested object hierarchies. Model a simplified wheel with separable hub, rim, and spokes. Show the whole assembly and individual parts while preserving their structural attachment relationships. Low-poly.
Working Three.js Starter (wheel-hub-rim-and-spokes-x3401):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Wheel Assembly — Three.js Component Study</title>
<style>
:root {
color-scheme: dark;
--bg: #091116;
--panel: rgba(18, 27, 33, 0.86);
--panel-solid: #121b21;
--panel-soft: rgba(255, 255, 255, 0.035);
--line: rgba(219, 232, 239, 0.12);
--line-strong: rgba(219, 232, 239, 0.22);
--text: #edf3f5;
--muted: #91a2aa;
--accent: #ff7448;
--accent-soft: rgba(255, 116, 72, 0.14);
--blue: #91b4c5;
--radius: 18px;
}
* {
box-sizing: border-box;
}
html {
min-width: 320px;
background: var(--bg);
}
body {
min-height: 100vh;
margin: 0;
overflow-x: hidden;
color: var(--text);
background:
radial-gradient(circle at 78% 8%, rgba(72, 117, 139, 0.13), transparent 29rem),
radial-gradient(circle at 8% 78%, rgba(255, 116, 72, 0.07), transparent 28rem),
linear-gradient(145deg, #0a1217 0%, #0b1419 45%, #080e12 100%);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.page {
width: min(1500px, calc(100% - 40px));
margin: 0 auto;
padding: 28px 0 44px;
}
.topbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
margin-bottom: 54px;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
flex: 0 0 auto;
border: 1px solid rgba(255, 255, 255, 0.26);
border-radius: 50%;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
inset: 8px;
border: 1px solid var(--accent);
border-radius: 50%;
}
.brand-mark::after {
inset: 16px;
background: var(--accent);
border: 0;
}
.brand-name {
font-size: 13px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.brand-subtitle {
margin-top: 3px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.05em;
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
}
.button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 39px;
padding: 0 14px;
border: 1px solid var(--line-strong);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.button:hover {
border-color: rgba(255, 255, 255, 0.38);
background: rgba(255, 255, 255, 0.075);
}
.button:active {
transform: translateY(1px);
}
.button svg {
width: 15px;
height: 15px;
}
.hero {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
align-items: end;
gap: 30px;
margin-bottom: 25px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin: 0 0 15px;
color: var(--accent);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 1px;
background: var(--accent);
}
h1 {
max-width: 800px;
margin: 0;
font-size: clamp(38px, 5vw, 72px);
font-weight: 540;
line-height: 0.98;
letter-spacing: -0.055em;
}
.hero-copy {
max-width: 560px;
margin: 20px 0 0;
color: var(--muted);
font-size: 15px;
line-height: 1.65;
}
.hero-stats {
display: flex;
gap: 28px;
padding-bottom: 3px;
}
.stat {
min-width: 92px;
}
.stat-value {
display: block;
margin-bottom: 5px;
font-size: 24px;
font-weight: 650;
letter-spacing: -0.03em;
}
.stat-label {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.workspace {
display: grid;
grid-template-columns: minmax(0, 1.03fr) minmax(0, 0.97fr);
gap: 16px;
}
.view-card,
.info-card {
overflow: hidden;
border: 1px solid var(--line);
border-radius: var(--radius);
background: var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
}
.view-card {
min-width: 0;
}
.view-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
min-height: 74px;
padding: 17px 20px;
border-bottom: 1px solid var(--line);
}
.view-title {
display: flex;
align-items: center;
gap: 11px;
}
.view-index {
display: grid;
width: 29px;
height: 29px;
place-items: center;
border: 1px solid var(--line-strong);
border-radius: 8px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
}
.view-title h2 {
margin: 0;
font-size: 14px;
font-weight: 650;
letter-spacing: -0.01em;
}
.view-title p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
}
.mini-button {
display: grid;
width: 33px;
height: 33px;
padding: 0;
place-items: center;
border: 1px solid var(--line);
border-radius: 9px;
background: transparent;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease;
}
.mini-button:hover {
border-color: var(--line-strong);
background: rgba(255, 255, 255, 0.06);
}
.mini-button svg {
width: 15px;
height: 15px;
}
.viewport {
position: relative;
height: 510px;
overflow: hidden;
isolation: isolate;
background:
radial-gradient(circle at 50% 45%, rgba(79, 116, 133, 0.11), transparent 48%),
linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent);
}
.viewport::after {
content: "";
position: absolute;
inset: 0;
z-index: 1;
pointer-events: none;
background:
linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px);
background-size: 38px 38px;
mask-image: linear-gradient(to bottom, transparent, black 30%, black 75%, transparent);
opacity: 0.35;
}
canvas {
position: absolute;
inset: 0;
z-index: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.viewport-badge {
position: absolute;
top: 15px;
left: 15px;
z-index: 3;
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(8, 15, 19, 0.62);
color: #b8c5ca;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(10px);
pointer-events: none;
}
.viewport-badge::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px rgba(255, 116, 72, 0.7);
}
.viewport-hint {
position: absolute;
right: 15px;
bottom: 15px;
z-index: 3;
display: flex;
gap: 12px;
color: rgba(207, 220, 225, 0.56);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.viewport-hint span {
display: flex;
align-items: center;
gap: 5px;
}
.viewport-hint kbd {
min-width: 19px;
padding: 3px 5px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 4px;
background: rgba(255, 255, 255, 0.04);
color: rgba(235, 244, 247, 0.76);
font: inherit;
text-align: center;
}
.scene-label {
position: absolute;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 7px;
background: rgba(8, 15, 19, 0.72);
color: #c9d4d8;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
pointer-events: none;
white-space: nowrap;
}
.scene-label::before {
content: "";
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--accent);
}
.view-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
min-height: 66px;
padding: 14px 18px;
border-top: 1px solid var(--line);
}
.explode-control {
display: grid;
grid-template-columns: auto minmax(80px, 1fr) 42px;
align-items: center;
gap: 12px;
width: min(100%, 340px);
}
.explode-control label,
.connection-toggle {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.explode-control output {
color: var(--accent);
font-size: 10px;
font-variant-numeric: tabular-nums;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 3px;
appearance: none;
border-radius: 999px;
outline: none;
background: linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--range, 68%),
rgba(255, 255, 255, 0.13) var(--range, 68%),
rgba(255, 255, 255, 0.13) 100%
);
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 3px solid #172127;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent);
cursor: ew-resize;
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #172127;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px var(--accent);
cursor: ew-resize;
}
.connection-toggle {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
white-space: nowrap;
}
.connection-toggle input {
width: 15px;
height: 15px;
accent-color: var(--accent);
}
.lower-grid {
display: grid;
grid-template-columns: minmax(300px, 0.78fr) minmax(420px, 1.22fr);
gap: 16px;
margin-top: 16px;
}
.info-card {
min-width: 0;
padding: 22px;
}
.card-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 20px;
}
.card-heading h2 {
margin: 0;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.card-heading span {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.breadcrumb {
margin-bottom: 10px;
color: var(--accent);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.selection-title {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
font-weight: 560;
line-height: 1.1;
letter-spacing: -0.035em;
}
.selection-description {
max-width: 650px;
min-height: 58px;
margin: 13px 0 21px;
color: var(--muted);
font-size: 13px;
line-height: 1.62;
}
.facts {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 9px;
}
.fact {
min-width: 0;
padding: 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: var(--panel-soft);
}
.fact-label {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.fact-value {
display: block;
overflow-wrap: anywhere;
font-size: 11px;
line-height: 1.4;
}
.children {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 16px;
}
.child-chip {
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255, 255, 255, 0.025);
color: #b8c5ca;
font-size: 10px;
cursor: pointer;
transition: border-color 150ms ease, color 150ms ease;
}
.child-chip:hover {
border-color: rgba(255, 116, 72, 0.55);
color: var(--text);
}
.tree-panel {
max-height: 395px;
overflow: auto;
padding-right: 4px;
scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
scrollbar-width: thin;
}
.tree-row {
position: relative;
display: flex;
align-items: center;
gap: 8px;
min-height: 31px;
padding: 3px 8px 3px 0;
border-radius: 7px;
color: #aebdc3;
cursor: pointer;
transition: background 150ms ease, color 150ms ease;
}
.tree-row:hover {
background: rgba(255, 255, 255, 0.035);
color: var(--text);
}
.tree-row.selected {
background: var(--accent-soft);
color: #fff;
}
.tree-row.selected::before {
content: "";
position: absolute;
left: 0;
width: 2px;
height: 17px;
border-radius: 2px;
background: var(--accent);
}
.tree-icon {
display: grid;
width: 19px;
height: 19px;
flex: 0 0 auto;
place-items: center;
color: #70848d;
font-size: 12px;
}
.tree-row.selected .tree-icon {
color: var(--accent);
}
.tree-label {
min-width: 0;
overflow: hidden;
font-size: 11px;
text-overflow: ellipsis;
white-space: nowrap;
}
.tree-kind {
margin-left: auto;
color: #61747d;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.tree-line {
position: absolute;
top: 0;
bottom: 0;
width: 1px;
background: rgba(255, 255, 255, 0.065);
pointer-events: none;
}
.loading {
position: absolute;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #0d171d;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
.footer-note {
display: flex;
justify-content: space-between;
gap: 18px;
margin-top: 17px;
padding: 0 3px;
color: #60747d;
font-size: 10px;
letter-spacing: 0.05em;
}
@media (max-width: 1050px) {
.hero {
grid-template-columns: 1fr;
}
.hero-stats {
padding: 0;
}
.workspace,
.lower-grid {
grid-template-columns: 1fr;
}
.viewport {
height: 540px;
}
}
@media (max-width: 640px) {
.page {
width: min(100% - 24px, 1500px);
padding-top: 18px;
}
.topbar {
align-items: flex-start;
margin-bottom: 38px;
}
.brand-subtitle {
display: none;
}
.button span {
display: none;
}
h1 {
font-size: 42px;
}
.hero-stats {
gap: 16px;
}
.stat {
min-width: 75px;
}
.viewport {
height: 420px;
}
.view-footer {
align-items: stretch;
flex-direction: column;
}
.explode-control {
width: 100%;
}
.facts {
grid-template-columns: 1fr;
}
.info-card {
padding: 18px;
}
.footer-note {
flex-direction: column;
}
}
</style>
</head>
<body>
<div class="page">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="brand-name">Object Study</div>
<div class="brand-subtitle">Mechanical systems / low-poly series</div>
</div>
</div>
<div class="top-actions">
<button class="button" id="resetScene" type="button" title="Reset the complete scene">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
<path d="M4 10a8 8 0 1 1 2.34 5.66" />
<path d="M4 4v6h6" />
</svg>
<span>Reset scene</span>
</button>
</div>
</header>
<main>
<section class="hero">
<div>
<p class="eyebrow">Assembly 01 / Radial mechanism</p>
<h1>A wheel, understood in layers.</h1>
<p class="hero-copy">
Inspect a complete low-poly wheel and its separated components.
Every spoke still belongs to the spoke set, every set remains mounted
to its hub and rim, and the hierarchy stays visible throughout.
</p>
</div>
<div class="hero-stats" aria-label="Model statistics">
<div class="stat">
<span class="stat-value">17</span>
<span class="stat-label">Components</span>
</div>
<div class="stat">
<span class="stat-value">3</span>
<span class="stat-label">Modules</span>
</div>
<div class="stat">
<span class="stat-value">10×</span>
<span class="stat-label">Symmetry</span>
</div>
</div>
</section>
<section class="workspace" aria-label="Wheel views">
<article class="view-card">
<header class="view-header">
<div class="view-title">
<span class="view-index">01</span>
<div>
<h2>Complete assembly</h2>
<p>Structural relationships in their working position</p>
</div>
</div>
<button
class="mini-button"
id="resetAssembly"
type="button"
title="Reset assembly camera"
aria-label="Reset assembly camera"
>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
<path d="M4 10a8 8 0 1 1 2.34 5.66" />
<path d="M4 4v6h6" />
</svg>
</button>
</header>
<div class="viewport" id="assemblyViewport">
<canvas id="assemblyCanvas" aria-label="Interactive assembled wheel"></canvas>
<div class="viewport-badge">Whole object</div>
<div class="viewport-hint">
<span><kbd>Drag</kbd> orbit</span>
<span><kbd>Wheel</kbd> zoom</span>
</div>
<div class="loading" id="loading">Building assembly</div>
</div>
<footer class="view-footer">
<span class="connection-toggle">Click a component to inspect it</span>
<span class="connection-toggle" id="assemblySelection">Assembly / 01</span>
</footer>
</article>
<article class="view-card">
<header class="view-header">
<div class="view-title">
<span class="view-index">02</span>
<div>
<h2>Exploded components</h2>
<p>Separated along the axle while retaining attachment paths</p>
</div>
</div>
<button
class="mini-button"
id="resetExploded"
type="button"
title="Reset exploded camera"
aria-label="Reset exploded camera"
>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
<path d="M4 10a8 8 0 1 1 2.34 5.66" />
<path d="M4 4v6h6" />
</svg>
</button>
</header>
<div class="viewport" id="explodedViewport">
<canvas id="explodedCanvas" aria-label="Interactive exploded wheel"></canvas>
<div class="viewport-badge">Individual parts</div>
<div class="scene-label" id="labelHub">Hub module</div>
<div class="scene-label" id="labelSpokes">Spoke set</div>
<div class="scene-label" id="labelRim">Rim module</div>
<div class="viewport-hint">
<span><kbd>Drag</kbd> orbit</span>
<span><kbd>Shift</kbd> pan</span>
</div>
</div>
<footer class="view-footer">
<div class="explode-control">
<label for="explodeRange">Separation</label>
<input id="explodeRange" type="range" min="0" max="100" value="68" />
<output id="explodeValue" for="explodeRange">68%</output>
</div>
<label class="connection-toggle" for="guideToggle">
<input id="guideToggle" type="checkbox" checked />
Connection guides
</label>
</footer>
</article>
</section>
<section class="lower-grid">
<article class="info-card" aria-live="polite">
<div class="card-heading">
<h2>Component inspector</h2>
<span id="selectionType">Whole</span>
</div>
<div class="breadcrumb" id="breadcrumb">Wheel assembly</div>
<h3 class="selection-title" id="selectionTitle">Complete wheel</h3>
<p class="selection-description" id="selectionDescription"></p>
<div class="facts">
<div class="fact">
<span class="fact-label">Parent</span>
<span class="fact-value" id="factParent">None</span>
</div>
<div class="fact">
<span class="fact-label">Attachment</span>
<span class="fact-value" id="factAttachment">Three linked modules</span>
</div>
<div class="fact">
<span class="fact-label">Topology</span>
<span class="fact-value" id="factTopology">Radial symmetry ×10</span>
</div>
</div>
<div class="children" id="selectionChildren"></div>
</article>
<article class="info-card">
<div class="card-heading">
<h2>Object hierarchy</h2>
<span>Mirrors the Three.js scene graph</span>
</div>
<div class="tree-panel" id="hierarchyTree" aria-label="Object hierarchy"></div>
</article>
</section>
<div class="footer-note">
<span>Three.js core / custom orbit controls / faceted geometry</span>
<span>Select a part in either viewport or use the hierarchy</span>
</div>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const ACCENT = new THREE.Color(0xff7448);
/*
* The UI hierarchy and the actual Three.js Object3D hierarchy use
* the same IDs. Adding a part to this tree and to buildWheel() keeps
* the structural model and its presentation synchronized.
*/
const hierarchy = {
id: "assembly",
label: "Wheel assembly",
kind: "whole",
children: [
{
id: "hubGroup",
label: "Hub module",
kind: "group",
children: [
{ id: "hubBarrel", label: "Hub barrel", kind: "part" },
{ id: "hubFlange", label: "Hub flange", kind: "part" },
{ id: "axle", label: "Axle", kind: "part" },
{ id: "capLeft", label: "Left cap", kind: "part" },
{ id: "capRight", label: "Right cap", kind: "part" }
]
},
{
id: "rimGroup",
label: "Rim module",
kind: "group",
children: [
{ id: "rim", label: "Rim body", kind: "part" },
{ id: "bead", label: "Inner bead", kind: "part" }
]
},
{
id: "spokeGroup",
label: "Spoke set",
kind: "group",
children: Array.from({ length: 10 }, (_, index) => ({
id: `spoke${String(index + 1).padStart(2, "0")}`,
label: `Spoke ${String(index + 1).padStart(2, "0")}`,
kind: "part"
}))
}
]
};
const nodeMap = new Map();
function indexHierarchy(node) {
nodeMap.set(node.id, node);
node.children?.forEach(indexHierarchy);
}
indexHierarchy(hierarchy);
function collectDescendants(id) {
const result = new Set();
const node = nodeMap.get(id);
function visit(current) {
current.children?.forEach((child) => {
result.add(child.id);
visit(child);
});
}
if (node) visit(node);
return result;
}
function findPath(id) {
const path = [];
function visit(node) {
path.push(node);
if (node.id === id) return true;
for (const child of node.children ?? []) {
if (visit(child)) return true;
}
path.pop();
return false;
}
visit(hierarchy);
return path;
}
function countLeaves(node) {
if (!node.children?.length) return 1;
return node.children.reduce((sum, child) => sum + countLeaves(child), 0);
}
function makePart(group, id, geometry, color, options = {}) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.34,
metalness: options.metalness ?? 0.62,
flatShading: true,
emissive: 0x000000,
emissiveIntensity: 0
});
const mesh = new THREE.Mesh(geometry, material);
mesh.name = id;
mesh.userData.partId = id;
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, options.edgeThreshold ?? 22),
new THREE.LineBasicMaterial({
color: 0x17242c,
transparent: true,
opacity: options.edgeOpacity ?? 0.32
})
);
mesh.add(edges);
return mesh;
}
function buildWheel(scene) {
const root = new THREE.Group();
root.name = "assembly";
root.userData.partId = "assembly";
scene.add(root);
const hubGroup = new THREE.Group();
hubGroup.name = "hubGroup";
hubGroup.userData.partId = "hubGroup";
const rimGroup = new THREE.Group();
rimGroup.name = "rimGroup";
rimGroup.userData.partId = "rimGroup";
const spokeGroup = new THREE.Group();
spokeGroup.name = "spokeGroup";
spokeGroup.userData.partId = "spokeGroup";
root.add(hubGroup, rimGroup, spokeGroup);
const allMeshes = [];
const spokeAngles = [];
const barrelGeometry = new THREE.CylinderGeometry(
0.54, 0.54, 0.68, 12, 1, false
);
barrelGeometry.rotateX(Math.PI / 2);
const barrel = makePart(
hubGroup, "hubBarrel", barrelGeometry, 0x879ba8,
{ roughness: 0.3, metalness: 0.7 }
);
allMeshes.push(barrel);
const flangeGeometry = new THREE.CylinderGeometry(
0.71, 0.71, 0.20, 12, 1, false
);
flangeGeometry.rotateX(Math.PI / 2);
const flange = makePart(
hubGroup, "hubFlange", flangeGeometry, 0xc2cdd2,
{ roughness: 0.28, metalness: 0.68 }
);
allMeshes.push(flange);
const axleGeometry = new THREE.CylinderGeometry(
0.17, 0.17, 1.48, 10, 1, false
);
axleGeometry.rotateX(Math.PI / 2);
const axle = makePart(
hubGroup, "axle", axleGeometry, 0x40545f,
{ roughness: 0.4, metalness: 0.72 }
);
allMeshes.push(axle);
const capGeometry = new THREE.CylinderGeometry(
0.25, 0.25, 0.13, 10, 1, false
);
capGeometry.rotateX(Math.PI / 2);
const leftCap = makePart(
hubGroup, "capLeft", capGeometry.clone(), 0xe06b42,
{ roughness: 0.38, metalness: 0.45 }
);
leftCap.position.z = -0.79;
allMeshes.push(leftCap);
const rightCap = makePart(
hubGroup, "capRight", capGeometry.clone(), 0xe06b42,
{ roughness: 0.38, metalness: 0.45 }
);
rightCap.position.z = 0.79;
allMeshes.push(rightCap);
const rimGeometry = new THREE.TorusGeometry(1.74, 0.13, 6, 24);
const rim = makePart(
rimGroup, "rim", rimGeometry, 0xd6dfe3,
{ roughness: 0.29, metalness: 0.63 }
);
allMeshes.push(rim);
const beadGeometry = new THREE.TorusGeometry(1.62, 0.047, 5, 24);
const bead = makePart(
rimGroup, "bead", beadGeometry, 0x8296a1,
{ roughness: 0.38, metalness: 0.58, edgeOpacity: 0.22 }
);
allMeshes.push(bead);
const spokeCount = 10;
const spokeLength = 0.98;
const spokeMidRadius = 1.13;
for (let index = 0; index < spokeCount; index++) {
const angle = (index / spokeCount) * Math.PI * 2;
const id = `spoke${String(index + 1).padStart(2, "0")}`;
const color = index % 2 === 0 ? 0x6d8592 : 0x9aabb3;
const geometry = new THREE.BoxGeometry(spokeLength, 0.095, 0.085);
const spoke = makePart(
spokeGroup, id, geometry, color,
{ roughness: 0.4, metalness: 0.57, edgeOpacity: 0.24 }
);
spoke.position.set(
Math.cos(angle) * spokeMidRadius,
Math.sin(angle) * spokeMidRadius,
0
);
spoke.rotation.z = angle;
allMeshes.push(spoke);
spokeAngles.push(angle);
}
/*
* Dashed guides connect each spoke's inner and outer attachment
* points across the exploded layers.
*/
const guides = new THREE.Group();
guides.name = "attachmentGuides";
scene.add(guides);
const guideLines = [];
for (let index = 0; index < spokeCount; index++) {
for (let side = 0; side < 2; side++) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color: 0xff8a62,
transparent: true,
opacity: 0.54,
dashSize: 0.08,
gapSize: 0.055,
depthWrite: false
})
);
line.userData.spokeIndex = index;
line.userData.side = side;
line.renderOrder = 3;
guides.add(line);
guideLines.push(line);
}
}
return {
root,
groups: { hubGroup, rimGroup, spokeGroup },
allMeshes,
spokeAngles,
guides,
guideLines
};
}
class OrbitController {
constructor(canvas, camera, options = {}) {
this.canvas = canvas;
this.camera = camera;
this.target = new THREE.Vector3(...(options.target ?? [0, 0, 0]));
this.goalTarget = this.target.clone();
this.theta = options.theta ?? 0.58;
this.phi = options.phi ?? 1.17;
this.radius = options.radius ?? 6.7;
this.goalTheta = this.theta;
this.goalPhi = this.phi;
this.goalRadius = this.radius;
this.dragging = false;
this.pointerId = null;
this.previous = { x: 0, y: 0 };
this.moved = false;
this.bindEvents();
this.updateCamera();
}
bindEvents() {
const canvas = this.canvas;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
if (this.pointerId !== null) return;
this.dragging = true;
this.moved = false;
this.pointerId = event.pointerId;
this.previous.x = event.clientX;
this.previous.y = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!this.dragging || event.pointerId !== this.pointerId) return;
const dx = event.clientX - this.previous.x;
const dy = event.clientY - this.previous.y;
this.previous.x = event.clientX;
this.previous.y = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 1) this.moved = true;
if (event.shiftKey || event.buttons === 2) {
this.pan(dx, dy);
} else {
this.goalTheta -= dx * 0.007;
this.goalPhi = THREE.MathUtils.clamp(
this.goalPhi - dy * 0.007,
0.35,
2.72
);
}
});
const release = (event) => {
if (event.pointerId !== this.pointerId) return;
this.dragging = false;
this.pointerId = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
};
canvas.addEventListener("pointerup", release);
canvas.addEventListener("pointercancel", release);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
this.goalRadius = THREE.MathUtils.clamp(
this.goalRadius * Math.exp(event.deltaY * 0.001),
3.7,
12
);
}, { passive: false });
}
pan(dx, dy) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
this.camera.matrix.extractBasis(right, up, new THREE.Vector3());
const scale = this.radius * 0.00135;
this.goalTarget.addScaledVector(right, -dx * scale);
this.goalTarget.addScaledVector(up, dy * scale);
}
reset() {
this.goalTheta = this.initial.theta;
this.goalPhi = this.initial.phi;
this.goalRadius = this.initial.radius;
this.goalTarget.set(...this.initial.target);
}
setInitial(options) {
this.initial = {
theta: options.theta ?? this.goalTheta,
phi: options.phi ?? this.goalPhi,
radius: options.radius ?? this.goalRadius,
target: [...(options.target ?? [0, 0, 0])]
};
}
updateCamera() {
const sinPhi = Math.sin(this.phi);
this.camera.position.set(
this.target.x + this.radius * sinPhi * Math.sin(this.theta),
this.target.y + this.radius * Math.cos(this.phi),
this.target.z + this.radius * sinPhi * Math.cos(this.theta)
);
this.camera.lookAt(this.target);
}
update() {
const damping = 0.12;
this.theta += (this.goalTheta - this.theta) * damping;
this.phi += (this.goalPhi - this.phi) * damping;
this.radius += (this.goalRadius - this.radius) * damping;
this.target.lerp(this.goalTarget, damping);
this.updateCamera();
}
}
function addEnvironment(scene, renderer) {
const hemisphere = new THREE.HemisphereLight(0xeaf5ff, 0x17232b, 2.15);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xffffff, 3.3);
key.position.set(4.5, 6.5, 7.5);
key.castShadow = true;
key.shadow.mapSize.set(1024, 1024);
key.shadow.camera.left = -5;
key.shadow.camera.right = 5;
key.shadow.camera.top = 5;
key.shadow.camera.bottom = -5;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 22;
key.shadow.bias = -0.0005;
scene.add(key);
const rimLight = new THREE.DirectionalLight(0x7db5d0, 1.7);
rimLight.position.set(-5, 2, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff7a4d, 10, 14, 2);
warmLight.position.set(3.5, -1.5, 3);
scene.add(warmLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(16, 16),
new THREE.ShadowMaterial({
color: 0x000000,
opacity: 0.23,
transparent: true
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.06;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(10, 20, 0x39505a, 0x263841);
grid.position.y = -2.05;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
}
function createView({
canvas,
viewport,
theta,
phi,
radius,
target
}) {
const renderer = new THREE.WebGLRenderer({
canvas,
alpha: true,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(37, 1, 0.1, 100);
addEnvironment(scene, renderer);
const wheel = buildWheel(scene);
const controller = new OrbitController(canvas, camera, {
theta,
phi,
radius,
target
});
controller.setInitial({ theta, phi, radius, target });
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
}
const observer = new ResizeObserver(resize);
observer.observe(viewport);
resize();
return {
canvas,
viewport,
renderer,
scene,
camera,
controller,
wheel
};
}
const assemblyView = createView({
canvas: $("assemblyCanvas"),
viewport: $("assemblyViewport"),
theta: 0.57,
phi: 1.16,
radius: 6.55,
target: [0, 0, 0]
});
const explodedView = createView({
canvas: $("explodedCanvas"),
viewport: $("explodedViewport"),
theta: 0.64,
phi: 1.12,
radius: 7.25,
target: [0, 0, 0]
});
assemblyView.wheel.guides.visible = false;
let selectedId = "assembly";
let explosion = 0.68;
function updateAttachmentGuides(view) {
const wheel = view.wheel;
wheel.root.updateMatrixWorld(true);
const temp = new THREE.Vector3();
for (const line of wheel.guideLines) {
const angle = wheel.spokeAngles[line.userData.spokeIndex];
const cos = Math.cos(angle);
const sin = Math.sin(angle);
let from;
let to;
if (line.userData.side === 0) {
from = temp
.set(cos * 0.68, sin * 0.68, 0)
.applyMatrix4(wheel.groups.hubGroup.matrixWorld)
.clone();
to = temp
.set(cos * 0.65, sin * 0.65, 0)
.applyMatrix4(wheel.groups.spokeGroup.matrixWorld)
.clone();
} else {
from = temp
.set(cos * 1.61, sin * 1.61, 0)
.applyMatrix4(wheel.groups.spokeGroup.matrixWorld)
.clone();
to = temp
.set(cos * 1.61, sin * 1.61, 0)
.applyMatrix4(wheel.groups.rimGroup.matrixWorld)
.clone();
}
const positions = line.geometry.attributes.position.array;
positions[0] = from.x;
positions[1] = from.y;
positions[2] = from.z;
positions[3] = to.x;
positions[4] = to.y;
positions[5] = to.z;
line.geometry.attributes.position.needsUpdate = true;
line.geometry.computeBoundingSphere();
line.computeLineDistances();
}
}
function updateExplosion() {
const offset = explosion * 1.55;
explodedView.wheel.groups.hubGroup.position.z = offset;
explodedView.wheel.groups.rimGroup.position.z = -offset;
explodedView.wheel.groups.spokeGroup.position.z = 0;
explodedView.wheel.root.updateMatrixWorld(true);
updateAttachmentGuides(explodedView);
const percent = Math.round(explosion * 100);
$("explodeValue").textContent = `${percent}%`;
$("explodeRange").style.setProperty("--range", `${percent}%`);
}
function setSelection(id) {
const node = nodeMap.get(id);
if (!node) return;
selectedId = id;
const descendants = collectDescendants(id);
for (const view of [assemblyView, explodedView]) {
for (const mesh of view.wheel.allMeshes) {
const active =
id === "assembly" || descendants.has(mesh.userData.partId);
mesh.material.emissive.copy(active ? ACCENT : new THREE.Color(0x000000));
mesh.material.emissiveIntensity =
id === "assembly" ? 0.07 : active ? 0.48 : 0;
}
}
document.querySelectorAll(".tree-row").forEach((row) => {
const active = row.dataset.id === id;
row.classList.toggle("selected", active);
row.setAttribute("aria-pressed", String(active));
});
updateInspector(node);
}
const descriptions = {
assembly:
"The whole wheel is a single assembly composed of three structural modules. The hub carries the axle and spoke roots, the spokes bridge the hub flange to the rim bead, and the rim completes the outer load-bearing ring.",
hubGroup:
"The hub module contains the central axle, barrel, flange, and end caps. It is the wheel's central structural interface and the root of every spoke.",
rimGroup:
"The rim module is the outer load-bearing shell. Its inner bead provides the ten indexed attachment points that receive the spoke ends.",
spokeGroup:
"Ten repeated spokes form a radial bridge between the hub flange and the rim bead. Although separated in the exploded view, every spoke retains its parent relationship and both attachment constraints."
};
function detailsFor(node) {
const path = findPath(node.id);
const parent = path.length > 1 ? path[path.length - 2] : null;
if (node.id === "assembly") {
return {
type: "Whole",
description: descriptions.assembly,
parent: "None",
attachment: "Hub → spokes → rim",
topology: "Radial symmetry ×10"
};
}
if (node.id === "hubGroup") {
return {
type: "Module",
description: descriptions.hubGroup,
parent: parent?.label ?? "None",
attachment: "Mounts all spoke roots",
topology: "5 components"
};
}
if (node.id === "rimGroup") {
return {
type: "Module",
description: descriptions.rimGroup,
parent: parent?.label ?? "None",
attachment: "Receives all spoke tips",
topology: "2 components"
};
}
if (node.id === "spokeGroup") {
return {
type: "Module",
description: descriptions.spokeGroup,
parent: parent?.label ?? "None",
attachment: "Hub flange → rim bead",
topology: "10 indexed links"
};
}
const partDetails = {
hubBarrel: {
description: "The faceted cylindrical shell forms the hub body around the axle bore.",
attachment: "Axle passes through the center",
topology: "12-sided cylinder"
},
hubFlange: {
description: "The central flange distributes spoke loads around the hub body.",
attachment: "Anchors all 10 spoke roots",
topology: "12-sided flange"
},
axle: {
description: "The axle is the wheel's central mounting shaft and remains parented to the hub module.",
attachment: "Supported by hub barrel",
topology: "10-sided cylinder"
},
capLeft: {
description: "The left end cap closes and visually protects the outer side of the axle.",
attachment: "Fixed to the axle end",
topology: "10-sided cylinder"
},
capRight: {
description: "The right end cap mirrors the left cap and completes the hub's axial symmetry.",
attachment: "Fixed to the axle end",
topology: "10-sided cylinder"
},
rim: {
description: "The main rim body is the wheel's outer structural ring.",
attachment: "Supports the inner bead",
topology: "Low-poly torus"
},
bead: {
description: "The narrower inner bead is the seat that receives the spoke tips.",
attachment: "Receives all 10 spoke tips",
topology: "24-segment torus"
}
};
if (node.id.startsWith("spoke")) {
const number = Number(node.id.slice(5));
return {
type: "Component",
description: `Spoke ${number} is one indexed radial link in the repeated spoke set. Its inner end meets the hub flange and its outer end seats against the rim bead.`,
parent: "Spoke set",
attachment: "Hub flange → rim bead",
topology: `Radial member ${number} / 10`
};
}
const detail = partDetails[node.id];
return {
type: "Component",
description: detail?.description ?? "An individual wheel component.",
parent: parent?.label ?? "None",
attachment: detail?.attachment ?? "Part of its parent module",
topology: detail?.topology ?? "Low-poly geometry"
};
}
function updateInspector(node) {
const detail = detailsFor(node);
$("selectionType").textContent = detail.type;
$("breadcrumb").textContent = findPath(node.id)
.map((item) => item.label)
.join(" / ");
$("selectionTitle").textContent = node.label;
$("selectionDescription").textContent = detail.description;
$("factParent").textContent = detail.parent;
$("factAttachment").textContent = detail.attachment;
$("factTopology").textContent = detail.topology;
const children = $("selectionChildren");
children.replaceChildren();
if (node.children?.length) {
for (const child of node.children) {
const button = document.createElement("button");
button.className = "child-chip";
button.type = "button";
button.textContent = child.label;
button.addEventListener("click", () => setSelection(child.id));
children.appendChild(button);
}
}
$("assemblySelection").textContent =
node.kind === "whole" ? "Assembly / 01" : node.label;
}
function buildTree() {
const container = $("hierarchyTree");
container.replaceChildren();
function visit(node, depth) {
const row = document.createElement("div");
row.className = "tree-row";
row.dataset.id = node.id;
row.setAttribute("role", "button");
row.setAttribute("tabindex", "0");
row.setAttribute("aria-pressed", "false");
if (depth > 0) {
const line = document.createElement("span");
line.className = "tree-line";
line.style.left = `${9 + (depth - 1) * 17}px`;
row.appendChild(line);
}
row.style.paddingLeft = `${9 + depth * 17}px`;
const icon = document.createElement("span");
icon.className = "tree-icon";
icon.textContent =
node.kind === "whole" ? "◎" :
node.kind === "group" ? "▦" : "◇";
const label = document.createElement("span");
label.className = "tree-label";
label.textContent = node.label;
const kind = document.createElement("span");
kind.className = "tree-kind";
kind.textContent = node.kind;
row.append(icon, label, kind);
const activate = () => setSelection(node.id);
row.addEventListener("click", activate);
row.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
activate();
}
});
container.appendChild(row);
node.children?.forEach((child) => visit(child, depth + 1));
}
visit(hierarchy, 0);
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pick(view, event) {
const rect = view.canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, view.camera);
const hits = raycaster.intersectObjects(
view.wheel.allMeshes,
false
);
if (hits.length) {
setSelection(hits[0].object.userData.partId);
} else {
setSelection("assembly");
}
}
function bindPicking(view) {
let down = null;
view.canvas.addEventListener("pointerdown", (event) => {
if (event.button === 0) {
down = { x: event.clientX, y: event.clientY };
}
});
view.canvas.addEventListener("pointerup", (event) => {
if (!down || event.button !== 0) return;
const distance = Math.hypot(
event.clientX - down.x,
event.clientY - down.y
);
if (distance < 5) pick(view, event);
down = null;
});
view.canvas.addEventListener("pointermove", (event) => {
if (view.controller.dragging) return;
const rect = view.canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, view.camera);
const hits = raycaster.intersectObjects(
view.wheel.allMeshes,
false
);
view.canvas.style.cursor = hits.length ? "pointer" : "grab";
});
}
bindPicking(assemblyView);
bindPicking(explodedView);
const labelDefinitions = [
{
element: $("labelHub"),
group: explodedView.wheel.groups.hubGroup,
anchor: new THREE.Vector3(-0.15, 0.86, 0.35)
},
{
element: $("labelSpokes"),
group: explodedView.wheel.groups.spokeGroup,
anchor: new THREE.Vector3(0.1, -1.36, 0)
},
{
element: $("labelRim"),
group: explodedView.wheel.groups.rimGroup,
anchor: new THREE.Vector3(1.22, 1.05, 0)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = explodedView.viewport.clientWidth;
const height = explodedView.viewport.clientHeight;
explodedView.wheel.root.updateMatrixWorld(true);
for (const definition of labelDefinitions) {
projected
.copy(definition.anchor)
.applyMatrix4(definition.group.matrixWorld)
.project(explodedView.camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
definition.element.style.display = visible ? "flex" : "none";
if (visible) {
definition.element.style.left =
`${(projected.x * 0.5 + 0.5) * width}px`;
definition.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
}
$("explodeRange").addEventListener("input", (event) => {
explosion = Number(event.target.value) / 100;
updateExplosion();
});
$("guideToggle").addEventListener("change", (event) => {
explodedView.wheel.guides.visible = event.target.checked;
});
$("resetAssembly").addEventListener("click", () => {
assemblyView.controller.reset();
});
$("resetExploded").addEventListener("click", () => {
explodedView.controller.reset();
});
$("resetScene").addEventListener("click", () => {
assemblyView.controller.reset();
explodedView.controller.reset();
explosion = 0.68;
$("explodeRange").value = "68";
updateExplosion();
setSelection("assembly");
});
buildTree();
updateExplosion();
setSelection("assembly");
function animate() {
requestAnimationFrame(animate);
assemblyView.controller.update();
explodedView.controller.update();
assemblyView.renderer.render(
assemblyView.scene,
assemblyView.camera
);
explodedView.renderer.render(
explodedView.scene,
explodedView.camera
);
updateLabels();
}
animate();
$("loading").classList.add("hidden");
</script>
</body>
</html>
```