Prompt specification
Build or customize the Three.js 3D scene "Toy casing repair table" 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: Toy casing repair table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/toy-casing-repair-table-x0307
Scene Description Prompt:
Build one HTML scene using Three.js from cdnjs to inspect misaligned snap tabs on a voxel toy casing before rejoining its parts.
Working Three.js Starter (toy-casing-repair-table-x0307):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Snap Lab — Casing Inspection</title>
<style>
:root {
color-scheme: dark;
--bg: #071118;
--panel: #0d1b23;
--panel-2: #11242d;
--line: rgba(156, 218, 226, 0.14);
--text: #eaf8f7;
--muted: #8ca8ae;
--cyan: #71e6df;
--orange: #ffad48;
--yellow: #ffd166;
--red: #ff756b;
--green: #79dfaa;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
height: 100%;
display: grid;
grid-template-rows: 64px minmax(0, 1fr);
}
header {
position: relative;
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background: rgba(8, 20, 28, 0.94);
backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
display: grid;
place-items: center;
flex: 0 0 auto;
border: 1px solid rgba(113, 230, 223, 0.35);
border-radius: 9px;
background:
linear-gradient(135deg, rgba(113, 230, 223, 0.16), rgba(255, 209, 102, 0.12)),
#0c2028;
color: var(--cyan);
font-size: 12px;
font-weight: 850;
letter-spacing: -0.05em;
box-shadow: inset 0 0 0 3px rgba(113, 230, 223, 0.035);
}
.brand-copy {
min-width: 0;
}
.brand-copy strong {
display: block;
font-size: 14px;
letter-spacing: 0.01em;
}
.brand-copy span {
display: block;
margin-top: 2px;
overflow: hidden;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.16em;
text-transform: uppercase;
text-overflow: ellipsis;
white-space: nowrap;
}
.header-actions {
display: flex;
align-items: center;
gap: 12px;
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 30px;
padding: 0 11px;
border: 1px solid rgba(255, 173, 72, 0.25);
border-radius: 999px;
background: rgba(255, 173, 72, 0.08);
color: #ffd39a;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
}
.status-pill::before {
width: 7px;
height: 7px;
content: "";
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 12px rgba(255, 173, 72, 0.75);
}
.header-button,
.view-button,
.zoom-button {
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}
.header-button {
height: 34px;
padding: 0 13px;
color: #cce2e3;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.header-button:hover,
.view-button:hover,
.zoom-button:hover {
border-color: rgba(113, 230, 223, 0.4);
background: rgba(113, 230, 223, 0.09);
}
.header-button:active,
.view-button:active,
.zoom-button:active {
transform: translateY(1px);
}
main {
min-height: 0;
display: grid;
grid-template-columns: 310px minmax(0, 1fr);
}
aside {
position: relative;
z-index: 5;
min-height: 0;
overflow: auto;
border-right: 1px solid var(--line);
background: linear-gradient(180deg, #0d1b23 0%, #09161d 100%);
scrollbar-width: thin;
scrollbar-color: #28434b transparent;
}
.side-section {
padding: 20px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
margin: 0 0 9px;
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 23px;
line-height: 1.1;
letter-spacing: -0.035em;
}
.intro {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.status-card {
display: grid;
grid-template-columns: 70px 1fr;
gap: 15px;
align-items: center;
margin-top: 18px;
padding: 14px;
border: 1px solid rgba(255, 173, 72, 0.2);
border-radius: 12px;
background:
linear-gradient(135deg, rgba(255, 173, 72, 0.09), transparent 65%),
rgba(255, 255, 255, 0.025);
}
.status-number {
color: var(--orange);
font-size: 38px;
font-weight: 800;
line-height: 1;
letter-spacing: -0.06em;
}
.status-number small {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.status-copy strong {
display: block;
margin-bottom: 5px;
font-size: 12px;
}
.status-copy span {
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.section-heading h2 {
margin: 0;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.section-heading span {
color: var(--muted);
font-size: 9px;
}
#tabList {
display: grid;
gap: 7px;
}
.tab-row {
width: 100%;
display: grid;
grid-template-columns: 10px 1fr auto;
gap: 10px;
align-items: center;
padding: 10px;
border: 1px solid transparent;
border-radius: 9px;
background: rgba(255, 255, 255, 0.025);
text-align: left;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
.tab-row:hover {
background: rgba(113, 230, 223, 0.055);
}
.tab-row.active {
border-color: rgba(255, 173, 72, 0.4);
background: rgba(255, 173, 72, 0.075);
}
.tab-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--orange);
box-shadow: 0 0 8px rgba(255, 173, 72, 0.25);
}
.tab-row.medium .tab-dot {
background: var(--yellow);
}
.tab-row.low .tab-dot {
background: var(--cyan);
}
.tab-copy strong,
.tab-copy span {
display: block;
}
.tab-copy strong {
margin-bottom: 3px;
font-size: 11px;
}
.tab-copy span {
color: var(--muted);
font-size: 9px;
}
.tab-drift {
color: #ffd39a;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 700;
}
.range-header {
display: flex;
align-items: center;
justify-content: space-between;
margin: 4px 0 9px;
color: #c6dadd;
font-size: 11px;
}
.range-value {
color: var(--cyan);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 7px 0 14px;
appearance: none;
border-radius: 99px;
outline: none;
background: linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) 58%,
#263b43 58%,
#263b43 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 3px solid #0d1b23;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 1px var(--cyan), 0 0 12px rgba(113, 230, 223, 0.28);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #0d1b23;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 1px var(--cyan);
}
.toggle {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 8px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.02);
color: #c9dcdf;
font-size: 11px;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
.toggle:hover {
border-color: rgba(113, 230, 223, 0.3);
}
.toggle-track {
position: relative;
width: 31px;
height: 17px;
flex: 0 0 auto;
border-radius: 99px;
background: #263a42;
transition: background 150ms ease;
}
.toggle-track::after {
position: absolute;
top: 3px;
left: 3px;
width: 11px;
height: 11px;
content: "";
border-radius: 50%;
background: #7d969c;
transition: transform 150ms ease, background 150ms ease;
}
.toggle.active .toggle-track {
background: rgba(113, 230, 223, 0.32);
}
.toggle.active .toggle-track::after {
background: var(--cyan);
transform: translateX(14px);
box-shadow: 0 0 8px rgba(113, 230, 223, 0.35);
}
.selection-card {
border: 1px solid rgba(113, 230, 223, 0.17);
border-radius: 11px;
background: rgba(113, 230, 223, 0.035);
overflow: hidden;
}
.selection-top {
padding: 13px;
border-bottom: 1px solid var(--line);
}
.selection-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.selection-title strong {
font-size: 12px;
}
.severity {
padding: 4px 6px;
border-radius: 5px;
background: rgba(255, 117, 107, 0.12);
color: #ff9d95;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.severity.medium {
background: rgba(255, 209, 102, 0.12);
color: #ffe29c;
}
.severity.low {
background: rgba(113, 230, 223, 0.12);
color: #a2f4ee;
}
.selection-subtitle {
margin-top: 6px;
color: var(--muted);
font-size: 10px;
}
.detail-grid {
display: grid;
grid-template-columns: 1fr 1fr;
}
.detail {
min-width: 0;
padding: 11px 13px;
}
.detail:nth-child(odd) {
border-right: 1px solid var(--line);
}
.detail:nth-child(n + 3) {
border-top: 1px solid var(--line);
}
.detail span,
.detail strong {
display: block;
}
.detail span {
margin-bottom: 5px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.detail strong {
overflow: hidden;
color: #d9ebed;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.focus-button {
width: 100%;
margin-top: 10px;
padding: 9px;
border: 1px solid rgba(113, 230, 223, 0.25);
border-radius: 8px;
background: rgba(113, 230, 223, 0.08);
color: #baf7f2;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
}
.focus-button:hover {
background: rgba(113, 230, 223, 0.14);
}
.side-footer {
padding: 16px 20px 22px;
color: #6f8d93;
font-size: 9px;
line-height: 1.7;
}
.key {
display: inline-grid;
min-width: 18px;
height: 18px;
margin: 0 2px;
place-items: center;
border: 1px solid #2a4149;
border-radius: 4px;
background: #10232b;
color: #a4bdc1;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 8px;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 40%, rgba(27, 83, 89, 0.24), transparent 42%),
linear-gradient(145deg, #0a1a22 0%, #071118 72%);
}
#viewport::after {
position: absolute;
inset: 0;
z-index: 1;
pointer-events: none;
content: "";
background:
linear-gradient(rgba(255, 255, 255, 0.012) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.012) 1px, transparent 1px);
background-size: 44px 44px;
mask-image: radial-gradient(circle at center, black, transparent 78%);
}
#viewport canvas {
position: absolute;
inset: 0;
z-index: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.viewport-top {
position: absolute;
z-index: 3;
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.live-chip {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(7, 17, 24, 0.72);
backdrop-filter: blur(12px);
color: #94b4b9;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live-chip::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 9px rgba(121, 223, 170, 0.75);
}
.view-controls {
display: flex;
gap: 5px;
pointer-events: auto;
}
.view-button {
min-width: 38px;
height: 32px;
padding: 0 10px;
background: rgba(7, 17, 24, 0.76);
backdrop-filter: blur(12px);
color: #a8c1c5;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.view-button.active {
border-color: rgba(113, 230, 223, 0.42);
color: var(--cyan);
}
.legend {
position: absolute;
z-index: 3;
left: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
gap: 13px;
padding: 9px 11px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(7, 17, 24, 0.76);
backdrop-filter: blur(12px);
color: #89a4a9;
font-size: 9px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.legend-swatch {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--orange);
}
.legend-swatch.receiver {
background: var(--cyan);
}
.legend-swatch.guide {
width: 15px;
height: 1px;
border-radius: 0;
background: var(--yellow);
}
.zoom-controls {
position: absolute;
z-index: 3;
right: 18px;
bottom: 18px;
display: grid;
gap: 5px;
}
.zoom-button {
width: 34px;
height: 34px;
background: rgba(7, 17, 24, 0.76);
backdrop-filter: blur(12px);
color: #c8dfe1;
font-size: 17px;
}
#annotation {
position: absolute;
z-index: 4;
display: none;
min-width: 150px;
padding: 8px 10px;
border: 1px solid rgba(255, 173, 72, 0.45);
border-radius: 7px;
background: rgba(10, 19, 24, 0.92);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.26);
color: #ffd7a8;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
line-height: 1.5;
pointer-events: none;
transform: translate(-50%, calc(-100% - 12px));
white-space: nowrap;
}
#annotation::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 12px;
content: "";
background: rgba(255, 173, 72, 0.65);
}
#hoverTip {
position: absolute;
z-index: 5;
display: none;
padding: 6px 8px;
border: 1px solid var(--line);
border-radius: 6px;
background: rgba(6, 15, 20, 0.92);
color: #c9dddf;
font-size: 9px;
pointer-events: none;
transform: translate(12px, 12px);
white-space: nowrap;
}
@media (max-width: 820px) {
html,
body {
overflow: auto;
}
#app {
min-height: 100%;
height: auto;
grid-template-rows: 58px auto;
}
header {
padding: 0 14px;
}
.status-pill {
display: none;
}
main {
display: flex;
flex-direction: column-reverse;
}
aside {
overflow: visible;
border-top: 1px solid var(--line);
border-right: 0;
}
#viewport {
height: 62vh;
min-height: 430px;
}
.view-button {
min-width: 32px;
padding: 0 7px;
}
.live-chip {
display: none;
}
.viewport-top {
justify-content: flex-end;
}
.legend {
right: 62px;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark">VX</div>
<div class="brand-copy">
<strong>Voxel Snap Lab</strong>
<span>Casing inspection / unit VT-07</span>
</div>
</div>
<div class="header-actions">
<div class="status-pill">4 deviations detected</div>
<button id="resetAll" class="header-button">Reset scene</button>
</div>
</header>
<main>
<aside>
<section class="side-section">
<p class="eyebrow">Pre-assembly inspection</p>
<h1>Snap-tab alignment</h1>
<p class="intro">
Inspect the separated upper shell and lower casing before applying
closure force.
</p>
<div class="status-card">
<div class="status-number">
04
<small>Deviating tabs</small>
</div>
<div class="status-copy">
<strong>Re-seating required</strong>
<span>Maximum measured drift: 0.42 mm along the X axis.</span>
</div>
</div>
</section>
<section class="side-section">
<div class="section-heading">
<h2>Snap features</h2>
<span>Click to inspect</span>
</div>
<div id="tabList"></div>
</section>
<section class="side-section">
<div class="section-heading">
<h2>Inspection aids</h2>
</div>
<div class="range-header">
<span>Lid separation</span>
<span id="separationValue" class="range-value">58%</span>
</div>
<input
id="separation"
type="range"
min="0"
max="100"
value="58"
aria-label="Lid separation"
/>
<button id="guidesToggle" class="toggle active" aria-pressed="true">
<span>Alignment guides</span>
<span class="toggle-track"></span>
</button>
<button id="xrayToggle" class="toggle" aria-pressed="false">
<span>Casing x-ray</span>
<span class="toggle-track"></span>
</button>
</section>
<section class="side-section">
<div class="section-heading">
<h2>Selected feature</h2>
</div>
<div class="selection-card">
<div class="selection-top">
<div class="selection-title">
<strong id="selectedName">ST-01 · Front-left hook</strong>
<span id="selectedSeverity" class="severity">High drift</span>
</div>
<div id="selectedSubtitle" class="selection-subtitle">
Flexible cantilever tab / receiver B4
</div>
</div>
<div class="detail-grid">
<div class="detail">
<span>Drift vector</span>
<strong id="selectedDrift">+0.42 mm X</strong>
</div>
<div class="detail">
<span>Receiver</span>
<strong id="selectedSlot">B4 / front-left</strong>
</div>
<div class="detail">
<span>Condition</span>
<strong id="selectedCondition">Offset</strong>
</div>
<div class="detail">
<span>Action</span>
<strong id="selectedAction">Re-seat tab</strong>
</div>
</div>
</div>
<button id="focusSelected" class="focus-button">Frame selected feature</button>
</section>
<div class="side-footer">
<span class="key">L</span> orbit
<span class="key">R</span> / drag to pan
<span class="key">F</span> focus
<span class="key">G</span> guides
<span class="key">X</span> x-ray
</div>
</aside>
<section id="viewport" aria-label="Interactive 3D casing inspection scene">
<div class="viewport-top">
<div class="live-chip">Live geometry inspection</div>
<div class="view-controls" aria-label="Camera views">
<button class="view-button active" data-view="iso">Iso</button>
<button class="view-button" data-view="top">Top</button>
<button class="view-button" data-view="front">Front</button>
<button class="view-button" data-view="side">Side</button>
</div>
</div>
<div class="legend">
<div class="legend-item">
<span class="legend-swatch"></span>
Snap tab
</div>
<div class="legend-item">
<span class="legend-swatch receiver"></span>
Receiver
</div>
<div class="legend-item">
<span class="legend-swatch guide"></span>
Drift vector
</div>
</div>
<div class="zoom-controls">
<button id="zoomIn" class="zoom-button" aria-label="Zoom in">+</button>
<button id="zoomOut" class="zoom-button" aria-label="Zoom out">−</button>
</div>
<div id="annotation"></div>
<div id="hoverTip"></div>
</section>
</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 viewport = document.getElementById("viewport");
const annotation = document.getElementById("annotation");
const hoverTip = document.getElementById("hoverTip");
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x071118, 18, 42);
const camera = new THREE.PerspectiveCamera(
38,
1,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(viewport.clientWidth, viewport.clientHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional voxel toy casing. Drag to orbit, shift-drag to pan, and scroll to zoom."
);
viewport.prepend(renderer.domElement);
// -------------------------------------------------------------------------
// Lighting and environment
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xb9f5ff, 0x17232a, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0cf, 3.2);
keyLight.position.set(6, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x55d9e6, 2.4);
rimLight.position.set(-7, 4, -6);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0xffb45d, 12, 12, 2);
fillLight.position.set(-4, 1, 5);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.ShadowMaterial({ opacity: 0.28 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.37;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x3b7780, 0x193640);
grid.position.y = -1.35;
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const standard = (options) =>
new THREE.MeshStandardMaterial({
roughness: 0.68,
metalness: 0.04,
flatShading: true,
...options
});
const materials = {
shellA: standard({ color: 0x2aa99a }),
shellB: standard({ color: 0x258e89 }),
shellLight: standard({ color: 0x66c8b7 }),
shellDark: standard({ color: 0x164d58 }),
interior: standard({ color: 0x102d38 }),
yellow: standard({ color: 0xffc857 }),
yellowDark: standard({ color: 0xd9942f }),
orange: standard({
color: 0xff9638,
emissive: 0x5d1e00,
emissiveIntensity: 0.32,
roughness: 0.46
}),
orangeLight: standard({
color: 0xffbd67,
emissive: 0x5d2800,
emissiveIntensity: 0.18,
roughness: 0.5
}),
black: standard({ color: 0x07171e }),
screen: standard({
color: 0x0b3b46,
emissive: 0x0a4d55,
emissiveIntensity: 0.25,
roughness: 0.3
}),
green: standard({
color: 0x73e6a1,
emissive: 0x1a6e3b,
emissiveIntensity: 0.45
})
};
const xrayMaterials = [
materials.shellA,
materials.shellB,
materials.shellLight,
materials.shellDark,
materials.interior,
materials.yellow,
materials.yellowDark
];
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x082a31,
transparent: true,
opacity: 0.34
});
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function addBox(
parent,
width,
height,
depth,
x,
y,
z,
material,
showEdges = false
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (showEdges) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
edgeMaterial
);
edges.renderOrder = 2;
mesh.add(edges);
}
return mesh;
}
function buildVoxelFloor(parent) {
const cols = 8;
const rows = 6;
const pitch = 0.66;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
const x = (col - (cols - 1) / 2) * pitch;
const z = (row - (rows - 1) / 2) * pitch;
const material = (col + row) % 4 === 0
? materials.shellB
: materials.shellDark;
addBox(
parent,
0.62,
0.15,
0.62,
x,
-0.93,
z,
material
);
}
}
}
function buildVoxelWall(parent, axis, count, rows, offset, materialA, materialB) {
const pitch = 0.62;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < count; col++) {
const along = (col - (count - 1) / 2) * pitch;
const y = -0.61 + row * pitch;
const material = (row + col) % 3 === 0 ? materialB : materialA;
if (axis === "x") {
addBox(
parent,
0.59,
0.59,
0.34,
along,
y,
offset,
material
);
} else {
addBox(
parent,
0.34,
0.59,
0.59,
offset,
y,
along,
material
);
}
}
}
}
// -------------------------------------------------------------------------
// Assembly and inspection data
// -------------------------------------------------------------------------
const assembly = new THREE.Group();
scene.add(assembly);
const bodyGroup = new THREE.Group();
bodyGroup.userData.inspectType = "body";
bodyGroup.userData.title = "Lower casing";
assembly.add(bodyGroup);
const lidGroup = new THREE.Group();
lidGroup.userData.inspectType = "lid";
lidGroup.userData.title = "Upper shell";
assembly.add(lidGroup);
const tabs = [
{
id: "ST-01",
label: "Front-left hook",
receiver: "B4 / front-left",
slotX: -1.45,
slotZ: 1.91,
visualX: 0.27,
visualZ: 0.10,
drift: "+0.42 mm X",
vector: "+X 0.42 / +Z 0.09",
severity: "High drift",
severityClass: "high",
rowClass: "",
condition: "Offset",
action: "Re-seat tab",
receiverLabel: "B4"
},
{
id: "ST-02",
label: "Front-right hook",
receiver: "A2 / front-right",
slotX: 1.45,
slotZ: 1.91,
visualX: -0.24,
visualZ: 0.13,
drift: "-0.38 mm X",
vector: "-X 0.38 / +Z 0.11",
severity: "High drift",
severityClass: "high",
rowClass: "",
condition: "Offset",
action: "Re-seat tab",
receiverLabel: "A2"
},
{
id: "ST-03",
label: "Rear-left hook",
receiver: "C1 / rear-left",
slotX: -1.45,
slotZ: -1.91,
visualX: 0.18,
visualZ: -0.12,
drift: "+0.31 mm Z",
vector: "+X 0.17 / -Z 0.31",
severity: "Medium drift",
severityClass: "medium",
rowClass: "medium",
condition: "Angled",
action: "Align hook",
receiverLabel: "C1"
},
{
id: "ST-04",
label: "Rear-right hook",
receiver: "D3 / rear-right",
slotX: 1.45,
slotZ: -1.91,
visualX: -0.12,
visualZ: -0.08,
drift: "-0.24 mm Z",
vector: "-X 0.11 / -Z 0.24",
severity: "Low drift",
severityClass: "low",
rowClass: "low",
condition: "Near alignment",
action: "Verify position",
receiverLabel: "D3"
}
];
const tabRoots = [];
const slotRoots = [];
const guideLines = [];
// -------------------------------------------------------------------------
// Lower casing
// -------------------------------------------------------------------------
addBox(
bodyGroup,
5.52,
0.28,
4.22,
0,
-1.12,
0,
materials.interior,
true
);
buildVoxelFloor(bodyGroup);
buildVoxelWall(
bodyGroup,
"x",
8,
3,
-1.88,
materials.shellA,
materials.shellB
);
buildVoxelWall(
bodyGroup,
"x",
8,
3,
1.88,
materials.shellA,
materials.shellB
);
buildVoxelWall(
bodyGroup,
"z",
6,
3,
-2.43,
materials.shellB,
materials.shellA
);
buildVoxelWall(
bodyGroup,
"z",
6,
3,
2.43,
materials.shellB,
materials.shellA
);
// Reinforced top rim with four receiver openings.
const railY = 1.05;
const frontRailSegments = [
[-2.55, -1.81],
[-1.09, 1.09],
[1.81, 2.55]
];
for (const [start, end] of frontRailSegments) {
const width = end - start;
const center = (start + end) / 2;
addBox(
bodyGroup,
width,
0.22,
0.38,
center,
railY,
1.91,
materials.shellLight,
true
);
addBox(
bodyGroup,
width,
0.22,
0.38,
center,
railY,
-1.91,
materials.shellLight,
true
);
}
addBox(
bodyGroup,
0.38,
0.22,
3.45,
-2.45,
railY,
0,
materials.shellLight,
true
);
addBox(
bodyGroup,
0.38,
0.22,
3.45,
2.45,
railY,
0,
materials.shellLight,
true
);
// Front face panel and toy-like display.
addBox(
bodyGroup,
3.50,
0.78,
0.16,
0,
-0.24,
2.10,
materials.shellLight,
true
);
addBox(
bodyGroup,
1.42,
0.48,
0.10,
0,
-0.20,
2.22,
materials.screen,
true
);
addBox(bodyGroup, 0.18, 0.15, 0.07, -0.25, -0.18, 2.30, materials.green);
addBox(bodyGroup, 0.18, 0.15, 0.07, 0.25, -0.18, 2.30, materials.green);
addBox(bodyGroup, 0.18, 0.07, 0.07, 0, -0.30, 2.30, materials.yellow);
for (let i = 0; i < 5; i++) {
addBox(
bodyGroup,
0.11,
0.11,
0.07,
1.02 + i * 0.18,
-0.28,
2.23,
materials.black
);
}
// Yellow voxel corner bumpers.
for (const x of [-2.42, 2.42]) {
for (const z of [-1.86, 1.86]) {
for (let i = 0; i < 3; i++) {
addBox(
bodyGroup,
0.42,
0.42,
0.42,
x,
-0.66 + i * 0.54,
z,
i === 1 ? materials.yellowDark : materials.yellow,
true
);
}
}
}
// Interior battery bay.
addBox(
bodyGroup,
1.25,
0.13,
1.45,
-0.75,
-0.79,
-0.45,
materials.black,
true
);
addBox(
bodyGroup,
0.18,
0.09,
1.05,
-1.17,
-0.75,
-0.45,
materials.yellowDark
);
// -------------------------------------------------------------------------
// Receiver slots
// -------------------------------------------------------------------------
function createReceiver(tab, index) {
const group = new THREE.Group();
group.position.set(tab.slotX, 1.08, tab.slotZ);
group.userData.inspectType = "slot";
group.userData.index = index;
group.userData.title = `Receiver ${tab.receiverLabel}`;
bodyGroup.add(group);
addBox(
group,
0.61,
0.12,
0.49,
0,
-0.03,
0,
materials.black,
true
);
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0x71e6df,
transparent: true,
opacity: 0.95
});
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addBox(
group,
0.07,
0.055,
0.18,
sx * 0.30,
0.06,
sz * 0.25,
markerMaterial
);
}
}
slotRoots.push(group);
}
tabs.forEach(createReceiver);
// -------------------------------------------------------------------------
// Upper shell
// -------------------------------------------------------------------------
addBox(
lidGroup,
5.55,
0.32,
4.25,
0,
0,
0,
materials.shellDark,
true
);
const lidCols = 8;
const lidRows = 6;
const lidPitch = 0.66;
for (let row = 0; row < lidRows; row++) {
for (let col = 0; col < lidCols; col++) {
const x = (col - (lidCols - 1) / 2) * lidPitch;
const z = (row - (lidRows - 1) / 2) * lidPitch;
const centerStripe =
Math.abs(x) < 0.38 && Math.abs(z) < 1.25;
const cornerAccent =
Math.abs(x) > 2.1 && Math.abs(z) > 1.45;
const material = centerStripe || cornerAccent
? materials.yellow
: (col + row) % 4 === 0
? materials.shellB
: materials.shellA;
addBox(
lidGroup,
0.62,
0.13,
0.62,
x,
0.21,
z,
material
);
}
}
// Raised handle details.
addBox(
lidGroup,
1.55,
0.20,
0.46,
0,
0.37,
-0.28,
materials.yellowDark,
true
);
for (const x of [-0.68, 0.68]) {
addBox(
lidGroup,
0.24,
0.30,
0.46,
x,
0.32,
-0.28,
materials.yellow,
true
);
}
// -------------------------------------------------------------------------
// Snap tabs and drift vectors
// -------------------------------------------------------------------------
function createTab(tab, index) {
const group = new THREE.Group();
group.position.set(
tab.slotX + tab.visualX,
-0.18,
tab.slotZ + tab.visualZ
);
group.userData.inspectType = "tab";
group.userData.index = index;
group.userData.title = `${tab.id} · ${tab.label}`;
lidGroup.add(group);
addBox(
group,
0.34,
0.62,
0.34,
0,
-0.38,
0,
materials.orange,
true
);
addBox(
group,
0.48,
0.12,
0.29,
0,
-0.72,
0,
materials.orangeLight,
true
);
addBox(
group,
0.22,
0.17,
0.47,
0.11,
-0.82,
0,
materials.orange,
true
);
const tip = new THREE.Object3D();
tip.position.set(0.11, -0.93, 0);
group.add(tip);
const guideGeometry = new THREE.BufferGeometry();
guideGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3)
);
const guide = new THREE.Line(
guideGeometry,
new THREE.LineDashedMaterial({
color: 0xffd166,
dashSize: 0.12,
gapSize: 0.07,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
guide.frustumCulled = false;
guide.renderOrder = 8;
scene.add(guide);
tabRoots.push(group);
guideLines.push({ guide, tip, tab });
}
tabs.forEach(createTab);
// -------------------------------------------------------------------------
// Scene state and camera controller
// -------------------------------------------------------------------------
const state = {
separation: 0.58,
guides: true,
xray: false,
selected: tabRoots[0]
};
const cameraController = {
current: {
target: new THREE.Vector3(0, 0.35, 0),
spherical: new THREE.Spherical(10.8, 1.02, 0.72)
},
desired: {
target: new THREE.Vector3(0, 0.35, 0),
spherical: new THREE.Spherical(10.8, 1.02, 0.72)
}
};
const selectionHelper = new THREE.Box3Helper(
new THREE.Box3(),
0xffd166
);
selectionHelper.material.depthTest = false;
selectionHelper.material.transparent = true;
selectionHelper.material.opacity = 0.92;
selectionHelper.renderOrder = 10;
scene.add(selectionHelper);
function updateLidPosition() {
lidGroup.position.y = 1.45 + state.separation * 1.60;
lidGroup.position.x = 0;
lidGroup.position.z = 0;
assembly.updateMatrixWorld(true);
for (const { guide, tip, tab } of guideLines) {
const start = new THREE.Vector3();
const end = new THREE.Vector3(
tab.slotX,
1.15,
tab.slotZ
);
tip.getWorldPosition(start);
const positions = guide.geometry.attributes.position;
positions.setXYZ(0, start.x, start.y, start.z);
positions.setXYZ(1, end.x, end.y, end.z);
positions.needsUpdate = true;
guide.computeLineDistances();
guide.visible = state.guides;
}
document.getElementById("separationValue").textContent =
`${Math.round(state.separation * 100)}%`;
const percentage = Math.round(state.separation * 100);
const slider = document.getElementById("separation");
slider.style.background =
`linear-gradient(90deg, var(--cyan) 0%, var(--cyan) ${percentage}%, ` +
`#263b43 ${percentage}%, #263b43 100%)`;
}
function setView(name) {
const views = {
iso: { radius: 10.8, phi: 1.02, theta: 0.72, target: [0, 0.35, 0] },
top: { radius: 10.4, phi: 0.16, theta: 0.02, target: [0, 0.2, 0] },
front: { radius: 10.2, phi: 1.20, theta: 0.02, target: [0, 0.25, 0] },
side: { radius: 10.4, phi: 1.08, theta: 1.52, target: [0, 0.25, 0] }
};
const view = views[name];
cameraController.desired.spherical.set(
view.radius,
view.phi,
view.theta
);
cameraController.desired.target.set(...view.target);
document.querySelectorAll(".view-button").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
function focusSelected() {
if (!state.selected) return;
const target = new THREE.Vector3();
if (state.selected.userData.inspectType === "tab") {
const index = state.selected.userData.index;
const tip = guideLines[index].tip;
tip.getWorldPosition(target);
cameraController.desired.spherical.radius = 4.2;
cameraController.desired.spherical.phi = 1.00;
cameraController.desired.spherical.theta = 0.68;
} else {
state.selected.getWorldPosition(target);
cameraController.desired.spherical.radius = 8.8;
cameraController.desired.spherical.phi = 1.02;
}
cameraController.desired.target.copy(target);
}
function setXray(enabled) {
state.xray = enabled;
for (const material of xrayMaterials) {
material.transparent = enabled;
material.opacity = enabled ? 0.16 : 1;
material.depthWrite = !enabled;
material.needsUpdate = true;
}
document.getElementById("xrayToggle").classList.toggle("active", enabled);
document.getElementById("xrayToggle").setAttribute(
"aria-pressed",
String(enabled)
);
}
// -------------------------------------------------------------------------
// UI construction and selection
// -------------------------------------------------------------------------
const tabList = document.getElementById("tabList");
tabs.forEach((tab, index) => {
const button = document.createElement("button");
button.className = `tab-row ${tab.rowClass}`;
button.innerHTML = `
<span class="tab-dot"></span>
<span class="tab-copy">
<strong>${tab.id} · ${tab.label}</strong>
<span>${tab.receiver}</span>
</span>
<span class="tab-drift">${tab.drift}</span>
`;
button.addEventListener("click", () => {
selectObject(tabRoots[index]);
});
tabList.appendChild(button);
});
function inspectableAncestor(object) {
let current = object;
while (current) {
if (current.userData.inspectType) return current;
current = current.parent;
}
return null;
}
function selectObject(object) {
if (!object) return;
state.selected = object;
selectionHelper.box.setFromObject(object);
selectionHelper.updateMatrixWorld(true);
document.querySelectorAll(".tab-row").forEach((row, index) => {
row.classList.toggle(
"active",
object.userData.inspectType === "tab" &&
object.userData.index === index
);
});
const type = object.userData.inspectType;
const name = document.getElementById("selectedName");
const severity = document.getElementById("selectedSeverity");
const subtitle = document.getElementById("selectedSubtitle");
const drift = document.getElementById("selectedDrift");
const slot = document.getElementById("selectedSlot");
const condition = document.getElementById("selectedCondition");
const action = document.getElementById("selectedAction");
severity.className = "severity";
if (type === "tab") {
const tab = tabs[object.userData.index];
name.textContent = `${tab.id} · ${tab.label}`;
severity.textContent = tab.severity;
severity.classList.add(tab.severityClass);
subtitle.textContent = `Flexible cantilever tab / receiver ${tab.receiverLabel}`;
drift.textContent = tab.vector;
slot.textContent = tab.receiver;
condition.textContent = tab.condition;
action.textContent = tab.action;
annotation.textContent = `${tab.id} ${tab.drift}`;
} else if (type === "slot") {
const tab = tabs[object.userData.index];
name.textContent = `Receiver ${tab.receiverLabel}`;
severity.textContent = "Receiver";
severity.classList.add("low");
subtitle.textContent = `Receiving channel for ${tab.id}`;
drift.textContent = tab.vector;
slot.textContent = tab.receiver;
condition.textContent = "Open / clear";
action.textContent = "Align tab";
annotation.textContent = `RECEIVER ${tab.receiverLabel}`;
} else if (type === "lid") {
name.textContent = "Upper shell";
severity.textContent = "Part";
severity.classList.add("low");
subtitle.textContent = "Voxel top shell / lid assembly";
drift.textContent = "Not applicable";
slot.textContent = "—";
condition.textContent = "Separated";
action.textContent = "Inspect tabs";
annotation.textContent = "";
} else {
name.textContent = "Lower casing";
severity.textContent = "Part";
severity.classList.add("low");
subtitle.textContent = "Voxel lower shell / receiver bed";
drift.textContent = "Not applicable";
slot.textContent = "4 receivers";
condition.textContent = "Inspection state";
action.textContent = "Inspect receivers";
annotation.textContent = "";
}
}
// -------------------------------------------------------------------------
// Direct pointer camera controls and raycast picking
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
raycaster.params.Line.threshold = 0.04;
const pointer = new THREE.Vector2();
let drag = null;
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pick(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObject(assembly, true);
for (const intersection of intersections) {
if (!intersection.object.isMesh) continue;
const object = inspectableAncestor(intersection.object);
if (object) return object;
}
return null;
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
drag = {
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY,
startX: event.clientX,
startY: event.clientY,
moved: false,
mode: event.button === 2 || event.shiftKey ? "pan" : "orbit"
};
hoverTip.style.display = "none";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (drag && drag.pointerId === event.pointerId) {
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
if (
Math.abs(event.clientX - drag.startX) +
Math.abs(event.clientY - drag.startY) > 4
) {
drag.moved = true;
}
if (drag.mode === "orbit") {
cameraController.desired.spherical.theta -= dx * 0.006;
cameraController.desired.spherical.phi -= dy * 0.006;
cameraController.desired.spherical.phi = THREE.MathUtils.clamp(
cameraController.desired.spherical.phi,
0.12,
1.46
);
} else {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
1
);
const scale =
cameraController.desired.spherical.radius * 0.00125;
cameraController.desired.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
cameraController.desired.target.y = THREE.MathUtils.clamp(
cameraController.desired.target.y,
-0.5,
3.0
);
}
drag.x = event.clientX;
drag.y = event.clientY;
return;
}
const object = pick(event);
if (object) {
let text = object.userData.title || "Inspect feature";
if (object.userData.inspectType === "tab") {
const tab = tabs[object.userData.index];
text = `${tab.id} · ${tab.drift}`;
}
hoverTip.textContent = text;
hoverTip.style.display = "block";
const rect = viewport.getBoundingClientRect();
hoverTip.style.left = `${event.clientX - rect.left}px`;
hoverTip.style.top = `${event.clientY - rect.top}px`;
renderer.domElement.style.cursor = "pointer";
} else {
hoverTip.style.display = "none";
renderer.domElement.style.cursor = "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!drag) return;
if (!drag.moved) {
const object = pick(event);
if (object) selectObject(object);
}
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
drag = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
drag = null;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraController.desired.spherical.radius *= Math.exp(
event.deltaY * 0.001
);
cameraController.desired.spherical.radius = THREE.MathUtils.clamp(
cameraController.desired.spherical.radius,
3.4,
21
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
focusSelected();
});
// -------------------------------------------------------------------------
// Interface events
// -------------------------------------------------------------------------
document.getElementById("separation").addEventListener("input", (event) => {
state.separation = Number(event.target.value) / 100;
updateLidPosition();
});
document.getElementById("guidesToggle").addEventListener("click", () => {
state.guides = !state.guides;
document.getElementById("guidesToggle").classList.toggle(
"active",
state.guides
);
document.getElementById("guidesToggle").setAttribute(
"aria-pressed",
String(state.guides)
);
for (const { guide } of guideLines) {
guide.visible = state.guides;
}
});
document.getElementById("xrayToggle").addEventListener("click", () => {
setXray(!state.xray);
});
document.getElementById("focusSelected").addEventListener("click", () => {
focusSelected();
});
document.getElementById("zoomIn").addEventListener("click", () => {
cameraController.desired.spherical.radius = THREE.MathUtils.clamp(
cameraController.desired.spherical.radius * 0.84,
3.4,
21
);
});
document.getElementById("zoomOut").addEventListener("click", () => {
cameraController.desired.spherical.radius = THREE.MathUtils.clamp(
cameraController.desired.spherical.radius * 1.18,
3.4,
21
);
});
document.querySelectorAll(".view-button").forEach((button) => {
button.addEventListener("click", () => {
setView(button.dataset.view);
});
});
document.getElementById("resetAll").addEventListener("click", () => {
state.separation = 0.58;
document.getElementById("separation").value = "58";
updateLidPosition();
state.guides = true;
document.getElementById("guidesToggle").classList.add("active");
document.getElementById("guidesToggle").setAttribute(
"aria-pressed",
"true"
);
for (const { guide } of guideLines) {
guide.visible = true;
}
setXray(false);
setView("iso");
selectObject(tabRoots[0]);
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
switch (event.key.toLowerCase()) {
case "r":
document.getElementById("resetAll").click();
break;
case "f":
focusSelected();
break;
case "g":
document.getElementById("guidesToggle").click();
break;
case "x":
document.getElementById("xrayToggle").click();
break;
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
new ResizeObserver(resize).observe(viewport);
resize();
const clock = new THREE.Clock();
const projectedPoint = new THREE.Vector3();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.pow(0.001, delta);
const current = cameraController.current;
const desired = cameraController.desired;
current.radius = THREE.MathUtils.lerp(
current.radius,
desired.radius,
damping
);
current.phi = THREE.MathUtils.lerp(
current.phi,
desired.phi,
damping
);
current.theta = THREE.MathUtils.lerp(
current.theta,
desired.theta,
damping
);
current.target.lerp(desired.target, damping);
camera.position.setFromSpherical(current.spherical).add(current.target);
camera.lookAt(current.target);
camera.updateMatrixWorld();
if (state.selected) {
selectionHelper.box.setFromObject(state.selected);
selectionHelper.updateMatrixWorld(true);
const type = state.selected.userData.inspectType;
if (type === "tab" || type === "slot") {
if (type === "tab") {
const index = state.selected.userData.index;
guideLines[index].tip.getWorldPosition(projectedPoint);
} else {
state.selected.getWorldPosition(projectedPoint);
}
projectedPoint.project(camera);
const visible = projectedPoint.z > -1 && projectedPoint.z < 1;
annotation.style.display = visible ? "block" : "none";
if (visible) {
annotation.style.left =
`${(projectedPoint.x * 0.5 + 0.5) * viewport.clientWidth}px`;
annotation.style.top =
`${(-projectedPoint.y * 0.5 + 0.5) * viewport.clientHeight}px`;
}
} else {
annotation.style.display = "none";
}
}
renderer.render(scene, camera);
}
updateLidPosition();
selectObject(tabRoots[0]);
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```