Prompt specification
Build or customize the Three.js 3D scene "Community Fabrication Lab Diorama" 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: Community Fabrication Lab Diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-fabrication-lab-diorama-x2003
Scene Description Prompt:
A voxel fabrication lab with printed parts and assembly benches; changing print orientation reveals geometric support requirements. One HTML file using Three.js from cdnjs.
Working Three.js Starter (community-fabrication-lab-diorama-x2003):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Fab — Orientation Lab</title>
<style>
:root {
--bg: #091019;
--panel: rgba(12, 21, 32, 0.82);
--panel-solid: #101b27;
--line: rgba(165, 201, 221, 0.16);
--text: #edf7fb;
--muted: #91a7b7;
--cyan: #63e4d8;
--cyan-soft: rgba(99, 228, 216, 0.14);
--orange: #ff914d;
--orange-soft: rgba(255, 145, 77, 0.14);
--yellow: #f4c85a;
}
* {
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;
}
body {
user-select: none;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.glass {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px) saturate(125%);
-webkit-backdrop-filter: blur(18px) saturate(125%);
}
.brand {
position: absolute;
top: 26px;
left: 28px;
display: flex;
align-items: center;
gap: 12px;
pointer-events: none;
}
.brand-mark {
width: 34px;
height: 34px;
position: relative;
transform: rotate(30deg) skewY(-6deg);
border: 2px solid var(--cyan);
border-radius: 6px;
box-shadow: inset 0 0 0 6px rgba(99, 228, 216, 0.07),
0 0 24px rgba(99, 228, 216, 0.12);
}
.brand-mark::before {
content: "";
position: absolute;
inset: 7px;
border: 1px solid rgba(99, 228, 216, 0.55);
border-radius: 2px;
}
.brand strong {
display: block;
font-size: 13px;
letter-spacing: 0.22em;
line-height: 1.1;
}
.brand span {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.2em;
}
.control-panel {
position: absolute;
top: 104px;
left: 28px;
width: 326px;
padding: 22px;
border-radius: 18px;
pointer-events: auto;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 10px 0 10px;
font-size: 34px;
line-height: 1.02;
letter-spacing: -0.045em;
font-weight: 670;
}
h1 em {
color: var(--cyan);
font-style: normal;
}
.control-copy p {
margin: 0 0 20px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.section-label {
display: flex;
justify-content: space-between;
align-items: center;
margin: 0 0 9px;
color: #bed0dc;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.section-label span:last-child {
color: #627b8c;
font-size: 9px;
letter-spacing: 0.08em;
}
.orientation-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.orientation-button {
appearance: none;
min-width: 0;
padding: 12px 7px 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
color: #b8cad5;
cursor: pointer;
transition: 160ms ease;
font-family: inherit;
}
.orientation-button:hover {
border-color: rgba(99, 228, 216, 0.35);
background: rgba(99, 228, 216, 0.055);
transform: translateY(-1px);
}
.orientation-button.active {
border-color: rgba(99, 228, 216, 0.72);
background: var(--cyan-soft);
color: var(--text);
box-shadow: inset 0 0 0 1px rgba(99, 228, 216, 0.08),
0 8px 24px rgba(0, 0, 0, 0.15);
}
.orientation-button .angle {
display: block;
margin-bottom: 6px;
color: var(--cyan);
font-size: 17px;
font-weight: 760;
}
.orientation-button span:not(.angle) {
display: block;
overflow: hidden;
font-size: 10px;
font-weight: 650;
text-overflow: ellipsis;
white-space: nowrap;
}
.orientation-button small {
display: block;
margin-top: 5px;
color: #738b9b;
font-size: 9px;
}
.orientation-button.active small {
color: #9fc7c5;
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 14px;
padding: 11px 12px;
border: 1px solid var(--line);
border-radius: 10px;
color: #b9cad4;
font-size: 11px;
cursor: pointer;
}
.toggle-row input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.toggle {
width: 32px;
height: 18px;
padding: 3px;
border-radius: 20px;
background: #263644;
transition: 160ms ease;
}
.toggle::after {
content: "";
display: block;
width: 12px;
height: 12px;
border-radius: 50%;
background: #7d93a2;
transition: 160ms ease;
}
.toggle-row input:checked + .toggle {
background: rgba(255, 145, 77, 0.36);
}
.toggle-row input:checked + .toggle::after {
transform: translateX(14px);
background: var(--orange);
box-shadow: 0 0 12px rgba(255, 145, 77, 0.45);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 13px;
margin-top: 16px;
color: #7f96a5;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 8px;
height: 8px;
border-radius: 2px;
}
.metrics {
position: absolute;
top: 28px;
right: 28px;
width: 238px;
padding: 18px;
border-radius: 17px;
pointer-events: auto;
}
.metric-kicker {
color: #78909f;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.16em;
}
.status-pill {
display: flex;
align-items: center;
gap: 8px;
margin: 12px 0 16px;
padding: 9px 10px;
border: 1px solid rgba(255, 145, 77, 0.24);
border-radius: 9px;
background: var(--orange-soft);
color: #ffc49f;
font-size: 11px;
font-weight: 650;
}
.status-pill i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 10px rgba(255, 145, 77, 0.65);
}
.status-pill.safe {
border-color: rgba(99, 228, 216, 0.24);
background: var(--cyan-soft);
color: #a4ece5;
}
.status-pill.safe i {
background: var(--cyan);
box-shadow: 0 0 10px rgba(99, 228, 216, 0.65);
}
.metric-row {
display: flex;
justify-content: space-between;
align-items: baseline;
padding: 9px 0;
border-top: 1px solid rgba(165, 201, 221, 0.09);
color: #8299a8;
font-size: 10px;
}
.metric-row strong {
color: var(--text);
font-size: 18px;
font-weight: 680;
}
.metric-row strong.orange {
color: var(--orange);
}
.reset-button {
width: 100%;
margin-top: 11px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: transparent;
color: #a7bbc7;
font: inherit;
font-size: 10px;
cursor: pointer;
transition: 150ms ease;
}
.reset-button:hover {
border-color: rgba(99, 228, 216, 0.35);
color: var(--cyan);
}
.scene-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
border: 1px solid rgba(165, 201, 221, 0.16);
border-radius: 6px;
background: rgba(8, 15, 23, 0.72);
color: #a8bbc7;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
pointer-events: none;
}
.scene-label::before {
content: "";
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 8px rgba(99, 228, 216, 0.7);
}
.scene-label.support::before {
background: var(--orange);
box-shadow: 0 0 8px rgba(255, 145, 77, 0.7);
}
.hint {
position: absolute;
right: 29px;
bottom: 25px;
color: #78909f;
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.hint kbd {
padding: 3px 6px;
border: 1px solid var(--line);
border-radius: 4px;
background: rgba(12, 21, 32, 0.72);
color: #afc3ce;
font: inherit;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #091019;
color: var(--cyan);
font-size: 11px;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 16px;
left: 17px;
}
.brand-mark {
width: 29px;
height: 29px;
}
.control-panel {
top: 76px;
left: 17px;
width: min(326px, calc(100vw - 34px));
padding: 17px;
}
h1 {
font-size: 27px;
}
.control-copy p,
.legend {
display: none;
}
.metrics {
top: auto;
right: 17px;
bottom: 17px;
width: 205px;
padding: 14px;
}
.metric-row {
padding: 7px 0;
}
.metric-row strong {
font-size: 15px;
}
.hint {
display: none;
}
.scene-label {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel fabrication laboratory"></canvas>
<div class="ui">
<header class="brand">
<div class="brand-mark"></div>
<div>
<strong>VOXEL FAB</strong>
<span>ORIENTATION LAB / BAY 04</span>
</div>
</header>
<section class="control-panel glass">
<div class="eyebrow">Geometric support study</div>
<h1>Print once.<br /><em>Support differently.</em></h1>
<div class="control-copy">
<p>
Rotate the printed bracket to generate its minimum removable
support structure in real time.
</p>
</div>
<div class="section-label">
<span>Print orientation</span>
<span>Keyboard 1—3</span>
</div>
<div class="orientation-grid">
<button class="orientation-button active" data-index="0">
<span class="angle">0°</span>
<span>Standard</span>
<small>10 supports</small>
</button>
<button class="orientation-button" data-index="1">
<span class="angle">90°</span>
<span>Sideways</span>
<small>6 supports</small>
</button>
<button class="orientation-button" data-index="2">
<span class="angle">180°</span>
<span>Inverted</span>
<small>0 supports</small>
</button>
</div>
<label class="toggle-row">
<span>Show generated supports</span>
<input id="supportToggle" type="checkbox" checked />
<span class="toggle"></span>
</label>
<div class="legend">
<span><i style="background:#63e4d8"></i>Printed voxels</span>
<span><i style="background:#ff914d"></i>Supports</span>
<span><i style="background:#f4c85a"></i>Tooling</span>
</div>
</section>
<aside class="metrics glass">
<div class="metric-kicker">LIVE BUILD ANALYSIS</div>
<div id="statusPill" class="status-pill">
<i></i>
<span id="statusText">Support required</span>
</div>
<div class="metric-row">
<span>Orientation</span>
<strong id="angleMetric">0°</strong>
</div>
<div class="metric-row">
<span>Support columns</span>
<strong id="columnMetric" class="orange">10</strong>
</div>
<div class="metric-row">
<span>Support voxels</span>
<strong id="voxelMetric" class="orange">40</strong>
</div>
<div class="metric-row">
<span>Overhang cells</span>
<strong id="overhangMetric">10</strong>
</div>
<button id="resetCamera" class="reset-button">RESET CAMERA</button>
</aside>
<div id="printerLabel" class="scene-label">Printer / Bay 04</div>
<div id="supportLabel" class="scene-label support">Generated support lattice</div>
<div id="assemblyLabel" class="scene-label">Assembly & finishing</div>
<div id="shelfLabel" class="scene-label">Printed component archive</div>
<div class="hint">
<kbd>Drag</kbd> orbit <kbd>Scroll</kbd> zoom
<kbd>Click part</kbd> cycle orientation
</div>
</div>
<div id="loading">Initializing fabrication bay…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera and lighting
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091019);
scene.fog = new THREE.FogExp2(0x091019, 0.022);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0.1, 1.8, -0.6);
const cameraState = {
yaw: 0.58,
pitch: 1.02,
radius: 16.8,
targetYaw: 0.58,
targetPitch: 1.02,
targetRadius: 16.8
};
const hemisphere = new THREE.HemisphereLight(0xa8ddff, 0x18202a, 1.35);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1db, 3.3);
keyLight.position.set(5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -13;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x64d9ff, 1.4);
rimLight.position.set(-8, 7, -7);
scene.add(rimLight);
const printerGlow = new THREE.PointLight(0x4de8dd, 7, 8, 2);
printerGlow.position.set(-5, 4.1, 0.4);
scene.add(printerGlow);
const benchLight = new THREE.PointLight(0xffc16b, 10, 9, 2);
benchLight.position.set(4.5, 4.7, -1.5);
scene.add(benchLight);
// -------------------------------------------------------------------------
// Shared helpers and materials
// -------------------------------------------------------------------------
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x111b26,
roughness: 0.88,
metalness: 0.08
}),
wall: new THREE.MeshStandardMaterial({
color: 0x172330,
roughness: 0.92,
metalness: 0.04
}),
wallInset: new THREE.MeshStandardMaterial({
color: 0x0e1823,
roughness: 0.85,
metalness: 0.12
}),
steel: new THREE.MeshStandardMaterial({
color: 0x293746,
roughness: 0.42,
metalness: 0.76
}),
darkSteel: new THREE.MeshStandardMaterial({
color: 0x15212c,
roughness: 0.48,
metalness: 0.7
}),
silver: new THREE.MeshStandardMaterial({
color: 0x9caeb8,
roughness: 0.35,
metalness: 0.72
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x49cfc5,
roughness: 0.46,
metalness: 0.12
}),
paleCyan: new THREE.MeshStandardMaterial({
color: 0x9af2e8,
roughness: 0.4,
metalness: 0.06
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xf3c657,
roughness: 0.52,
metalness: 0.18
}),
orange: new THREE.MeshStandardMaterial({
color: 0xf18145,
roughness: 0.52,
metalness: 0.16
}),
wood: new THREE.MeshStandardMaterial({
color: 0x7f5a40,
roughness: 0.8,
metalness: 0.02
}),
mat: new THREE.MeshStandardMaterial({
color: 0x193d3c,
roughness: 0.92,
metalness: 0.01
}),
rubber: new THREE.MeshStandardMaterial({
color: 0x101820,
roughness: 0.96,
metalness: 0
}),
glass: new THREE.MeshStandardMaterial({
color: 0x70dce4,
transparent: true,
opacity: 0.065,
roughness: 0.15,
metalness: 0.08,
side: THREE.DoubleSide,
depthWrite: false
}),
lamp: new THREE.MeshStandardMaterial({
color: 0xffdfb2,
emissive: 0xffc46b,
emissiveIntensity: 1.2,
roughness: 0.28
})
};
function addBox(
parent,
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
material,
x = 0,
y = 0,
z = 0,
segments = 20
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addVoxel(parent, x, y, z, size, material) {
return addBox(
parent,
size,
size,
size,
material,
x,
y,
z
);
}
// -------------------------------------------------------------------------
// Lab shell
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(36, 28),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const floorGrid = new THREE.GridHelper(36, 36, 0x355064, 0x203142);
floorGrid.position.y = 0.008;
floorGrid.material.transparent = true;
floorGrid.material.opacity = 0.34;
scene.add(floorGrid);
addBox(scene, 27, 10, 0.25, materials.wall, 0, 5, -7.4, false);
addBox(scene, 0.25, 10, 23, materials.wall, -12.5, 5, -0.2, false);
for (let x = -11; x <= 11; x += 2.75) {
addBox(
scene,
0.035,
9.6,
0.025,
materials.wallInset,
x,
5,
-7.25,
false
);
}
addBox(scene, 26, 0.08, 0.05, materials.wallInset, 0, 0.12, -7.24, false);
addBox(scene, 26, 0.05, 0.05, materials.wallInset, 0, 7.8, -7.24, false);
// Floor safety markings around the printer.
const markingMaterial = new THREE.MeshStandardMaterial({
color: 0xd9a83d,
emissive: 0x6e4510,
emissiveIntensity: 0.25,
roughness: 0.72
});
const zoneX = -5;
const zoneZ = 0;
const zoneW = 6.2;
const zoneD = 5.1;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addBox(
scene,
1.15,
0.018,
0.055,
markingMaterial,
zoneX + sx * (zoneW / 2 - 0.58),
0.022,
zoneZ + sz * zoneD / 2,
false
);
addBox(
scene,
0.055,
0.018,
1.15,
markingMaterial,
zoneX + sx * zoneW / 2,
0.022,
zoneZ + sz * (zoneD / 2 - 0.58),
false
);
}
}
// -------------------------------------------------------------------------
// Voxel part and support analysis
// -------------------------------------------------------------------------
const CELL = 0.38;
const BED_TOP = 2.16;
const shape = [];
// Portal-shaped bracket: broad lower and upper beams, with end legs.
for (let x = -3; x <= 3; x++) {
for (let z = 0; z <= 1; z++) {
shape.push({ x, y: -2, z });
shape.push({ x, y: 2, z });
}
}
for (const x of [-3, 3]) {
for (let y = -1; y <= 1; y++) {
for (let z = 0; z <= 1; z++) {
shape.push({ x, y, z });
}
}
}
function analyzeOrientation(angle) {
const cosine = Math.cos(angle);
const sine = Math.sin(angle);
const transformed = [];
const occupied = new Set();
let minY = Infinity;
let maxY = -Infinity;
for (const cell of shape) {
const gx = Math.round(cosine * cell.x - sine * cell.y);
const gy = Math.round(sine * cell.x + cosine * cell.y);
const gz = cell.z;
transformed.push({ gx, gy, gz });
occupied.add(`${gx}|${gy}|${gz}`);
minY = Math.min(minY, gy);
maxY = Math.max(maxY, gy);
}
const supportMap = new Map();
let unsupportedCount = 0;
for (const cell of transformed) {
const below = `${cell.gx}|${cell.gy - 1}|${cell.gz}`;
const bottomCells = cell.gy - minY;
if (!occupied.has(below) && bottomCells > 0) {
unsupportedCount++;
const key = `${cell.gx}|${cell.gz}`;
const previous = supportMap.get(key);
if (!previous || bottomCells > previous.bottomCells) {
supportMap.set(key, {
gx: cell.gx,
gz: cell.gz,
bottomCells
});
}
}
}
let supportVoxels = 0;
for (const support of supportMap.values()) {
supportVoxels += Math.ceil(support.bottomCells - 1e-6);
}
return {
angle,
transformed,
occupied,
minY,
maxY,
supportMap,
supportVoxels,
unsupportedCount
};
}
const orientations = [
{
angle: 0,
label: "Standard",
degrees: 0
},
{
angle: Math.PI / 2,
label: "Sideways",
degrees: 90
},
{
angle: Math.PI,
label: "Inverted",
degrees: 180
}
].map((orientation) => ({
...orientation,
analysis: analyzeOrientation(orientation.angle)
}));
// -------------------------------------------------------------------------
// Printer
// -------------------------------------------------------------------------
const printer = new THREE.Group();
printer.position.set(-5, 0, 0);
scene.add(printer);
addBox(printer, 5.25, 0.42, 4.4, materials.darkSteel, 0, 0.22, 0);
addBox(printer, 4.85, 0.13, 4.0, materials.steel, 0, 0.47, 0);
addBox(printer, 4.5, 0.08, 0.08, materials.yellow, 0, 0.53, 1.93);
for (const x of [-2.36, 2.36]) {
for (const z of [-1.78, 1.78]) {
addBox(printer, 0.2, 5.55, 0.2, materials.steel, x, 3.22, z);
addBox(printer, 0.3, 0.09, 0.3, materials.rubber, x, 0.56, z);
}
}
for (const z of [-1.78, 1.78]) {
addBox(printer, 4.9, 0.22, 0.24, materials.steel, 0, 6.0, z);
}
for (const x of [-2.36, 2.36]) {
addBox(printer, 0.24, 0.22, 3.8, materials.steel, x, 6.0, 0);
}
// Transparent enclosure panels.
addBox(
printer,
4.58,
5.25,
0.025,
materials.glass,
0,
3.2,
-1.79,
false
);
addBox(
printer,
0.025,
5.25,
3.48,
materials.glass,
-2.37,
3.2,
0,
false
);
// Print bed and pedestal.
addBox(printer, 2.5, 0.72, 2.05, materials.darkSteel, 0, 1.36, 0);
addBox(printer, 3.6, 0.14, 0.22, materials.silver, 0, 1.78, -0.92);
addBox(printer, 4.25, 0.16, 3.25, materials.silver, 0, BED_TOP - 0.08, 0);
addBox(printer, 4.08, 0.025, 3.08, materials.wallInset, 0, BED_TOP + 0.003, 0);
// Fine build-plate grid.
const bedGridPositions = [];
for (let x = -2; x <= 2.001; x += 0.25) {
bedGridPositions.push(x, BED_TOP + 0.022, -1.48, x, BED_TOP + 0.022, 1.48);
}
for (let z = -1.5; z <= 1.501; z += 0.25) {
bedGridPositions.push(-2, BED_TOP + 0.022, z, 2, BED_TOP + 0.022, z);
}
const bedGridGeometry = new THREE.BufferGeometry();
bedGridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(bedGridPositions, 3)
);
const bedGrid = new THREE.LineSegments(
bedGridGeometry,
new THREE.LineBasicMaterial({
color: 0x72939b,
transparent: true,
opacity: 0.25
})
);
printer.add(bedGrid);
addBox(printer, 0.3, 0.08, 0.16, materials.yellow, -1.78, BED_TOP + 0.04, 1.35);
addBox(printer, 0.3, 0.08, 0.16, materials.yellow, 1.78, BED_TOP + 0.04, 1.35);
// Gantry, rails and print head.
addBox(printer, 4.35, 0.22, 0.26, materials.steel, 0, 4.83, 0.05);
addBox(printer, 4.15, 0.08, 0.12, materials.silver, 0, 4.66, 0.19);
addBox(printer, 0.28, 1.9, 0.2, materials.silver, 0.35, 3.83, -0.12);
addBox(printer, 0.72, 0.46, 0.62, materials.darkSteel, 0.35, 4.36, 0.18);
addBox(printer, 0.52, 0.24, 0.45, materials.orange, 0.35, 4.09, 0.18);
addCylinder(printer, 0.07, 0.11, 0.24, materials.silver, 0.35, 3.86, 0.18, 12);
// Printer status strip.
addBox(
printer,
1.25,
0.08,
0.04,
new THREE.MeshStandardMaterial({
color: 0x63e4d8,
emissive: 0x36d8ca,
emissiveIntensity: 1.6
}),
0,
0.34,
2.21
);
// Printed bracket.
const partPivot = new THREE.Group();
printer.add(partPivot);
const partGeometry = new THREE.BoxGeometry(CELL * 0.92, CELL * 0.92, CELL * 0.92);
const partMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.38,
metalness: 0.08
});
const partMesh = new THREE.InstancedMesh(
partGeometry,
partMaterial,
shape.length
);
partMesh.castShadow = true;
partMesh.receiveShadow = true;
const partDummy = new THREE.Object3D();
const partColor = new THREE.Color();
shape.forEach((cell, index) => {
partDummy.position.set(
cell.x * CELL,
cell.y * CELL,
(cell.z - 0.5) * CELL
);
partDummy.updateMatrix();
partMesh.setMatrixAt(index, partDummy.matrix);
if (Math.abs(cell.x) === 3 && cell.y !== 0) {
partColor.setHex(0xf2c35a);
} else if (cell.z === 1) {
partColor.setHex(0x79e7dc);
} else {
partColor.setHex(0x38bdb4);
}
partMesh.setColorAt(index, partColor);
});
partMesh.instanceMatrix.needsUpdate = true;
if (partMesh.instanceColor) {
partMesh.instanceColor.needsUpdate = true;
}
partPivot.add(partMesh);
// Generated removable supports.
const supportMaterial = new THREE.MeshStandardMaterial({
color: 0xff8d47,
emissive: 0xb84312,
emissiveIntensity: 0.32,
roughness: 0.58,
metalness: 0.05,
transparent: true,
opacity: 0.82,
depthWrite: false
});
const supportGroup = new THREE.Group();
printer.add(supportGroup);
const supportColumns = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
supportMaterial,
256
);
supportColumns.count = 0;
supportColumns.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
const supportPads = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
supportMaterial,
64
);
supportPads.count = 0;
supportPads.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
supportGroup.add(supportColumns, supportPads);
function updateSupports(angle) {
const analysis = analyzeOrientation(angle);
const supportDummy = new THREE.Object3D();
let columnIndex = 0;
let padIndex = 0;
for (const support of analysis.supportMap.values()) {
const bottom = support.bottomCells * CELL;
const blockCount = Math.ceil(support.bottomCells - 1e-6);
const blockHeight = bottom / blockCount;
for (let block = 0; block < blockCount; block++) {
supportDummy.position.set(
support.gx * CELL,
BED_TOP + (block + 0.5) * blockHeight,
(support.gz - 0.5) * CELL
);
supportDummy.scale.set(0.17, blockHeight * 0.94, 0.17);
supportDummy.updateMatrix();
supportColumns.setMatrixAt(columnIndex++, supportDummy.matrix);
}
supportDummy.position.set(
support.gx * CELL,
BED_TOP + 0.025,
(support.gz - 0.5) * CELL
);
supportDummy.scale.set(0.27, 0.035, 0.27);
supportDummy.updateMatrix();
supportPads.setMatrixAt(padIndex++, supportDummy.matrix);
}
supportColumns.count = columnIndex;
supportPads.count = padIndex;
supportColumns.instanceMatrix.needsUpdate = true;
supportPads.instanceMatrix.needsUpdate = true;
}
updateSupports(0);
// -------------------------------------------------------------------------
// Assembly benches and printed parts
// -------------------------------------------------------------------------
function createBench(x, z, width = 4.8, depth = 2.15) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
addBox(group, width, 0.22, depth, materials.wood, 0, 1.46, 0);
addBox(group, width + 0.08, 0.08, depth + 0.08, materials.steel, 0, 1.31, 0);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addBox(
group,
0.16,
1.3,
0.16,
materials.darkSteel,
sx * (width / 2 - 0.28),
0.65,
sz * (depth / 2 - 0.25)
);
}
}
addBox(group, width - 0.7, 0.1, depth - 0.55, materials.darkSteel, 0, 0.48, 0);
return group;
}
function createGear(parent, cx, cy, cz, radius, count = 16) {
for (let i = 0; i < count; i++) {
if (i % 4 === 0) continue;
const angle = (i / count) * Math.PI * 2;
addVoxel(
parent,
cx + Math.cos(angle) * radius,
cy,
cz + Math.sin(angle) * radius,
0.17,
i % 2 === 0 ? materials.paleCyan : materials.cyan
);
}
}
const benchA = createBench(2.0, -2.65);
addBox(benchA, 2.65, 0.028, 1.48, materials.mat, -0.55, 1.585, 0.05);
createGear(benchA, -0.95, 1.7, 0.08, 0.43);
createGear(benchA, -0.95, 1.82, 0.08, 0.25, 12);
// A partially assembled bracket.
for (let x = 0; x < 3; x++) {
addVoxel(benchA, 0.72 + x * 0.22, 1.7, -0.3, 0.2, materials.paleCyan);
}
for (const x of [0.72, 1.16]) {
addVoxel(benchA, x, 1.92, -0.3, 0.2, materials.cyan);
}
// Tooling on the bench.
addBox(benchA, 0.08, 0.06, 0.92, materials.silver, 1.65, 1.61, 0.3);
addBox(benchA, 0.25, 0.1, 0.25, materials.yellow, 1.65, 1.64, 0.75);
const benchB = createBench(6.1, 1.25, 4.0, 2.0);
addBox(benchB, 2.25, 0.025, 1.25, materials.mat, -0.35, 1.585, 0);
// Small voxel robot fixture.
addBox(benchB, 0.8, 0.16, 0.65, materials.darkSteel, -0.85, 1.68, 0.05);
addVoxel(benchB, -0.85, 1.91, 0.05, 0.34, materials.cyan);
addVoxel(benchB, -0.85, 2.23, 0.05, 0.28, materials.paleCyan);
addVoxel(benchB, -0.85, 2.48, 0.05, 0.2, materials.yellow);
// Robotic arm.
addCylinder(benchB, 0.34, 0.4, 0.18, materials.darkSteel, 0.8, 1.67, -0.1);
addBox(benchB, 0.28, 0.95, 0.28, materials.orange, 0.8, 2.12, -0.1);
const armA = new THREE.Group();
armA.position.set(0.8, 2.52, -0.1);
armA.rotation.z = -0.62;
benchB.add(armA);
addBox(armA, 0.24, 1.05, 0.24, materials.orange, 0, 0.45, 0);
const armB = new THREE.Group();
armB.position.set(0, 0.9, 0);
armB.rotation.z = 1.1;
armA.add(armB);
addBox(armB, 0.2, 0.88, 0.2, materials.yellow, 0, 0.38, 0);
addBox(armB, 0.26, 0.26, 0.26, materials.darkSteel, 0, 0.78, 0);
// Parts bins.
for (let i = 0; i < 3; i++) {
const binX = -1.25 + i * 0.63;
addBox(benchB, 0.5, 0.24, 0.52, materials.darkSteel, binX, 1.72, 0.78);
addBox(benchB, 0.42, 0.035, 0.44, i === 1 ? materials.yellow : materials.cyan,
binX, 1.86, 0.78);
}
// Stool.
addCylinder(scene, 0.46, 0.46, 0.16, materials.rubber, 3.3, 0.93, 1.15);
addCylinder(scene, 0.09, 0.09, 0.8, materials.steel, 3.3, 0.48, 1.15);
addCylinder(scene, 0.42, 0.42, 0.08, materials.darkSteel, 3.3, 0.1, 1.15);
// -------------------------------------------------------------------------
// Component archive shelves
// -------------------------------------------------------------------------
const shelf = new THREE.Group();
shelf.position.set(5.1, 0, -6.82);
scene.add(shelf);
for (const sx of [-1, 1]) {
addBox(shelf, 0.12, 5.4, 0.12, materials.steel, sx * 3.35, 2.7, 0);
}
for (const y of [1.05, 2.55, 4.05]) {
addBox(shelf, 6.85, 0.12, 0.82, materials.steel, 0, y, 0);
addBox(shelf, 6.5, 0.035, 0.68, materials.darkSteel, 0, y + 0.08, 0.03);
}
// Stored voxel samples.
addBox(shelf, 0.9, 0.5, 0.5, materials.cyan, -2.2, 1.37, 0.05);
addBox(shelf, 0.7, 0.7, 0.42, materials.paleCyan, -0.95, 1.46, 0.05);
addBox(shelf, 1.15, 0.35, 0.48, materials.yellow, 0.55, 1.29, 0.05);
addBox(shelf, 0.72, 0.72, 0.44, materials.orange, 1.95, 1.47, 0.05);
for (let i = 0; i < 6; i++) {
addVoxel(
shelf,
-2.4 + i * 0.32,
2.87,
0.04,
0.25,
i % 2 ? materials.paleCyan : materials.cyan
);
}
for (let i = 0; i < 4; i++) {
addVoxel(shelf, 0.4 + i * 0.36, 4.37, 0.04, 0.3, materials.yellow);
}
// -------------------------------------------------------------------------
// In-world monitor and sign
// -------------------------------------------------------------------------
const monitorCanvas = document.createElement("canvas");
monitorCanvas.width = 512;
monitorCanvas.height = 320;
const monitorContext = monitorCanvas.getContext("2d");
const monitorTexture = new THREE.CanvasTexture(monitorCanvas);
monitorTexture.colorSpace = THREE.SRGBColorSpace;
function drawMonitor(state) {
const ctx = monitorContext;
const analysis = state.analysis;
ctx.fillStyle = "#07121b";
ctx.fillRect(0, 0, 512, 320);
ctx.strokeStyle = "#102936";
ctx.lineWidth = 1;
for (let x = 0; x <= 512; x += 32) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, 320);
ctx.stroke();
}
for (let y = 0; y <= 320; y += 32) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(512, y);
ctx.stroke();
}
ctx.fillStyle = "#63e4d8";
ctx.font = "700 18px Arial";
ctx.fillText("SUPPORT PLAN", 24, 31);
ctx.fillStyle = "#7896a8";
ctx.font = "13px Arial";
ctx.fillText(`${state.degrees}° / ${state.label.toUpperCase()}`, 376, 30);
ctx.fillStyle = "#9db2c0";
ctx.font = "12px Arial";
ctx.fillText(
`${analysis.supportMap.size} COLUMNS ${analysis.supportVoxels} VOXELS`,
24,
54
);
const gridSize = 28;
const centerX = 256;
const bedY = 281;
// Bed and axis.
ctx.fillStyle = "#344753";
ctx.fillRect(105, bedY, 302, 8);
ctx.fillStyle = "#687d89";
ctx.font = "11px Arial";
ctx.fillText("BUILD PLATE", 118, bedY + 23);
// Support columns in side elevation.
for (const support of analysis.supportMap.values()) {
const top = bedY - support.bottomCells * gridSize;
const offset = (support.gz - 0.5) * 6;
ctx.fillStyle = "#ff914d";
ctx.fillRect(
centerX + support.gx * gridSize - 4 + offset,
top,
8,
bedY - top
);
ctx.fillStyle = "#ffc08d";
ctx.fillRect(
centerX + support.gx * gridSize - 7 + offset,
bedY - 4,
14,
4
);
}
// Part cells.
for (const cell of analysis.transformed) {
const x = centerX + cell.gx * gridSize;
const y = bedY - (cell.gy - analysis.minY + 1) * gridSize;
ctx.fillStyle = "#45cfc4";
ctx.fillRect(x - 13, y + 2, 26, 24);
ctx.strokeStyle = "#91f2e8";
ctx.strokeRect(x - 13.5, y + 1.5, 27, 25);
}
ctx.fillStyle = analysis.supportMap.size === 0 ? "#63e4d8" : "#ffb27e";
ctx.font = "700 13px Arial";
ctx.fillText(
analysis.supportMap.size === 0 ? "SELF-SUPPORTING" : "SUPPORTS REQUIRED",
24,
300
);
monitorTexture.needsUpdate = true;
}
const monitor = new THREE.Group();
monitor.position.set(1.2, 0, -3.82);
scene.add(monitor);
addBox(monitor, 0.16, 0.7, 0.16, materials.steel, 0, 1.82, 0);
addBox(monitor, 1.15, 0.08, 0.5, materials.darkSteel, 0, 2.15, 0);
addBox(monitor, 2.72, 1.78, 0.14, materials.darkSteel, 0, 3.06, 0);
const monitorScreen = new THREE.Mesh(
new THREE.PlaneGeometry(2.54, 1.58),
new THREE.MeshBasicMaterial({
map: monitorTexture,
toneMapped: false
})
);
monitorScreen.position.set(0, 3.06, 0.076);
monitor.add(monitorScreen);
// Wall sign.
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 220;
const signContext = signCanvas.getContext("2d");
signContext.fillStyle = "#0b1620";
signContext.fillRect(0, 0, 1024, 220);
signContext.fillStyle = "#63e4d8";
signContext.font = "700 64px Arial";
signContext.fillText("VOXEL FAB", 48, 92);
signContext.fillStyle = "#708a99";
signContext.font = "700 26px Arial";
signContext.fillText("ORIENTATION LAB / BAY 04", 53, 145);
signContext.fillStyle = "#ff914d";
signContext.fillRect(53, 177, 210, 7);
const signTexture = new THREE.CanvasTexture(signCanvas);
signTexture.colorSpace = THREE.SRGBColorSpace;
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(6.8, 1.46),
new THREE.MeshBasicMaterial({ map: signTexture, toneMapped: false })
);
sign.position.set(5.2, 6.65, -7.255);
scene.add(sign);
// Hanging task lamps.
for (const x of [-4.7, 4.4]) {
addBox(scene, 0.05, 1.2, 0.05, materials.steel, x, 7.0, -1.2);
addCylinder(scene, 0.36, 0.18, 0.28, materials.darkSteel, x, 6.35, -1.2);
addCylinder(scene, 0.29, 0.29, 0.03, materials.lamp, x, 6.2, -1.2);
}
// -------------------------------------------------------------------------
// UI state and orientation controls
// -------------------------------------------------------------------------
const orientationButtons = [...document.querySelectorAll(".orientation-button")];
const supportToggle = document.querySelector("#supportToggle");
const resetCameraButton = document.querySelector("#resetCamera");
const statusPill = document.querySelector("#statusPill");
const statusText = document.querySelector("#statusText");
const angleMetric = document.querySelector("#angleMetric");
const columnMetric = document.querySelector("#columnMetric");
const voxelMetric = document.querySelector("#voxelMetric");
const overhangMetric = document.querySelector("#overhangMetric");
let activeOrientation = 0;
let targetAngle = 0;
let currentAngle = 0;
let supportsVisible = true;
function updateUI(index) {
const state = orientations[index];
const analysis = state.analysis;
const count = analysis.supportMap.size;
orientationButtons.forEach((button, buttonIndex) => {
button.classList.toggle("active", buttonIndex === index);
});
angleMetric.textContent = `${state.degrees}°`;
columnMetric.textContent = String(count);
voxelMetric.textContent = String(analysis.supportVoxels);
overhangMetric.textContent = String(analysis.unsupportedCount);
columnMetric.classList.toggle("orange", count > 0);
voxelMetric.classList.toggle("orange", analysis.supportVoxels > 0);
statusPill.classList.toggle("safe", count === 0);
statusText.textContent =
count === 0 ? "Self-supporting geometry" : `${count} supports required`;
drawMonitor(state);
}
function selectOrientation(index) {
activeOrientation = (index + orientations.length) % orientations.length;
const state = orientations[activeOrientation];
targetAngle = state.angle;
updateSupports(state.angle);
updateUI(activeOrientation);
}
orientationButtons.forEach((button, index) => {
button.addEventListener("click", () => selectOrientation(index));
});
supportToggle.addEventListener("change", () => {
supportsVisible = supportToggle.checked;
supportGroup.visible = supportsVisible;
});
resetCameraButton.addEventListener("click", () => {
cameraState.targetYaw = 0.58;
cameraState.targetPitch = 1.02;
cameraState.targetRadius = 16.8;
});
window.addEventListener("keydown", (event) => {
if (event.key === "1") selectOrientation(0);
if (event.key === "2") selectOrientation(1);
if (event.key === "3") selectOrientation(2);
if (event.key.toLowerCase() === "r") resetCameraButton.click();
});
updateUI(0);
// -------------------------------------------------------------------------
// Custom camera controls and part picking
// -------------------------------------------------------------------------
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let dragging = false;
let pointerStart = { x: 0, y: 0 };
let previousPointer = { x: 0, y: 0 };
let dragDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragDistance = 0;
pointerStart = { x: event.clientX, y: event.clientY };
previousPointer = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointer.x;
const deltaY = event.clientY - previousPointer.y;
dragDistance += Math.abs(deltaX) + Math.abs(deltaY);
cameraState.targetYaw = THREE.MathUtils.clamp(
cameraState.targetYaw - deltaX * 0.005,
-1.2,
1.2
);
cameraState.targetPitch = THREE.MathUtils.clamp(
cameraState.targetPitch - deltaY * 0.0045,
0.48,
1.38
);
previousPointer = { x: event.clientX, y: event.clientY };
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (dragDistance < 6) {
const rect = 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, camera);
const hits = raycaster.intersectObject(partMesh, false);
if (hits.length > 0) {
selectOrientation(activeOrientation + 1);
}
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius * Math.exp(event.deltaY * 0.001),
9.5,
23
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
resetCameraButton.click();
});
// -------------------------------------------------------------------------
// Projected scene labels
// -------------------------------------------------------------------------
const labelDefinitions = [
{
element: document.querySelector("#printerLabel"),
position: new THREE.Vector3(-5, 5.85, 0)
},
{
element: document.querySelector("#supportLabel"),
position: new THREE.Vector3(-5, 3.05, 1.55)
},
{
element: document.querySelector("#assemblyLabel"),
position: new THREE.Vector3(2.2, 2.45, -2.2)
},
{
element: document.querySelector("#shelfLabel"),
position: new THREE.Vector3(5.1, 4.95, -6.55)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labelDefinitions) {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "flex" : "none";
if (visible) {
label.element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const cameraEase = 1 - Math.exp(-delta * 9);
const partEase = 1 - Math.exp(-delta * 7);
cameraState.yaw = THREE.MathUtils.lerp(
cameraState.yaw,
cameraState.targetYaw,
cameraEase
);
cameraState.pitch = THREE.MathUtils.lerp(
cameraState.pitch,
cameraState.targetPitch,
cameraEase
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.targetRadius,
cameraEase
);
const sinPitch = Math.sin(cameraState.pitch);
camera.position.set(
cameraTarget.x +
cameraState.radius * sinPitch * Math.sin(cameraState.yaw),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.pitch),
cameraTarget.z +
cameraState.radius * sinPitch * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraTarget);
currentAngle = THREE.MathUtils.lerp(
currentAngle,
targetAngle,
partEase
);
if (Math.abs(currentAngle - targetAngle) < 0.0005) {
currentAngle = targetAngle;
}
partPivot.rotation.z = currentAngle;
// Keep the rotating part visually seated on the bed.
let continuousMinY = Infinity;
const sine = Math.sin(currentAngle);
const cosine = Math.cos(currentAngle);
for (const cell of shape) {
const rotatedY = sine * cell.x + cosine * cell.y;
continuousMinY = Math.min(continuousMinY, rotatedY);
}
partPivot.position.y =
BED_TOP + (-continuousMinY + 0.5) * CELL;
const targetSupportOpacity = supportsVisible ? 0.82 : 0;
supportMaterial.opacity = THREE.MathUtils.lerp(
supportMaterial.opacity,
targetSupportOpacity,
1 - Math.exp(-delta * 10)
);
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```