Prompt specification
Build or customize the Three.js 3D scene "Hollow and solid pasta sections" 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: Hollow and solid pasta sections
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/hollow-and-solid-pasta-sections-x0129
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing extruded pasta shapes. Display short tubes, ribbons, and rods with enlarged end faces; align their cut surfaces on one plane so differences in cross-sectional geometry are unmistakable. Voxel style.
Working Three.js Starter (hollow-and-solid-pasta-sections-x0129):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Pasta — Cut and Compare</title>
<style>
:root {
--background: #17130f;
--cream: #fff0cf;
--muted: #b9aa91;
--accent: #f2b85b;
--panel: rgba(28, 23, 18, 0.82);
--border: rgba(255, 229, 183, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--background);
color: var(--cream);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
position: relative;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
canvas.dragging {
cursor: grabbing;
}
.intro {
position: fixed;
z-index: 5;
top: 30px;
left: 34px;
width: min(430px, calc(100vw - 68px));
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 2px;
background: var(--accent);
box-shadow: 0 0 12px rgba(242, 184, 91, 0.5);
}
h1 {
margin: 0;
max-width: 420px;
font-size: clamp(30px, 3.6vw, 55px);
font-weight: 780;
line-height: 0.98;
letter-spacing: -0.055em;
}
.intro p {
max-width: 390px;
margin: 15px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.plane-badge {
position: fixed;
z-index: 5;
top: 30px;
right: 34px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid var(--border);
border-radius: 999px;
background: var(--panel);
color: #dfd2bb;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(12px);
pointer-events: none;
}
.plane-badge .dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: #8dd6cf;
box-shadow: 0 0 13px rgba(141, 214, 207, 0.75);
}
.controls {
position: fixed;
z-index: 6;
left: 34px;
bottom: 28px;
display: flex;
align-items: center;
gap: 9px;
color: #a99c87;
font-size: 11px;
letter-spacing: 0.025em;
pointer-events: none;
}
.controls kbd {
min-width: 25px;
padding: 5px 7px;
border: 1px solid rgba(255, 234, 197, 0.16);
border-bottom-color: rgba(255, 234, 197, 0.28);
border-radius: 5px;
background: rgba(255, 255, 255, 0.035);
color: #e6d8bf;
font: inherit;
text-align: center;
}
.view-controls {
position: fixed;
z-index: 6;
right: 34px;
bottom: 28px;
display: flex;
gap: 8px;
padding: 5px;
border: 1px solid var(--border);
border-radius: 12px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 14px 45px rgba(0, 0, 0, 0.25);
}
button {
border: 0;
border-radius: 8px;
padding: 9px 12px;
background: transparent;
color: #a99c87;
font: inherit;
font-size: 11px;
font-weight: 720;
letter-spacing: 0.03em;
cursor: pointer;
transition:
color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
button:hover {
color: var(--cream);
background: rgba(255, 255, 255, 0.055);
}
button:active {
transform: translateY(1px);
}
button.active {
background: #f1c477;
color: #261a0e;
box-shadow: 0 5px 16px rgba(241, 196, 119, 0.16);
}
#labels {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.spec-label {
position: absolute;
min-width: 112px;
padding: 7px 10px;
border: 1px solid rgba(255, 231, 189, 0.12);
border-radius: 8px;
background: rgba(22, 18, 14, 0.7);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(8px);
text-align: center;
transform: translate(-50%, 0);
will-change: left, top;
}
.spec-label strong {
display: block;
color: #f6e6c8;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.spec-label span {
display: block;
margin-top: 3px;
color: #9f9079;
font-size: 9px;
letter-spacing: 0.025em;
}
.mobile-key {
display: none;
}
@media (max-width: 780px) {
.intro {
top: 18px;
left: 20px;
width: calc(100vw - 40px);
}
.eyebrow {
margin-bottom: 8px;
font-size: 9px;
}
h1 {
max-width: 290px;
font-size: 29px;
}
.intro p {
display: none;
}
.plane-badge {
top: auto;
right: 18px;
bottom: 74px;
padding: 8px 10px;
font-size: 8px;
}
.controls {
display: none;
}
.view-controls {
right: 18px;
bottom: 18px;
}
button {
padding: 8px 10px;
font-size: 10px;
}
.spec-label {
min-width: 92px;
padding: 5px 7px;
}
.spec-label strong {
font-size: 7px;
}
.spec-label span {
display: none;
}
}
</style>
</head>
<body>
<header class="intro">
<div class="eyebrow">Voxel food study · 05</div>
<h1>Five pasta profiles.<br>One cut plane.</h1>
<p>
Tubes, ribbons, and rods built from stepped voxels.
Every enlarged cut face begins at exactly z = 0.
</p>
</header>
<div class="plane-badge">
<span class="dot"></span>
Aligned cut faces · z = 0
</div>
<div id="labels" aria-hidden="true"></div>
<div class="controls">
<kbd>↔</kbd>
<span>Drag to orbit</span>
<span>·</span>
<kbd>⇅</kbd>
<span>Scroll to zoom</span>
<span>·</span>
<kbd>R</kbd>
<span>Reset</span>
</div>
<div class="view-controls" aria-label="Camera views">
<button id="three-quarter" class="active" type="button">3/4 View</button>
<button id="face-on" type="button">Face-on</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x17130f);
scene.fog = new THREE.Fog(0x17130f, 23, 42);
const camera = new THREE.OrthographicCamera(-8, 8, 4, -4, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel pasta cross-sections with aligned cut faces"
);
renderer.domElement.setAttribute("role", "img");
document.body.prepend(renderer.domElement);
// A dark receiving wall behind the extrusion direction.
const backdrop = new THREE.Mesh(
new THREE.PlaneGeometry(42, 25),
new THREE.MeshStandardMaterial({
color: 0x191510,
roughness: 1,
metalness: 0
})
);
backdrop.position.z = 4.35;
backdrop.rotation.y = Math.PI;
backdrop.receiveShadow = true;
scene.add(backdrop);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xfff0cf,
0x38251b,
1.75
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffdfa1, 3.35);
keyLight.position.set(-7, 10, -8);
keyLight.target.position.set(0, 0, 1);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight, keyLight.target);
const fillLight = new THREE.DirectionalLight(0x9fc4df, 1.05);
fillLight.position.set(9, 2, -5);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xf6a83e, 1.25);
rimLight.position.set(2, 4, 8);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Voxel profiles
// -------------------------------------------------------------------------
const CELL = 0.22;
const DEPTH_SEGMENTS = 4;
function makeMask(bounds, predicate) {
const cells = [];
for (let iy = -bounds.y; iy <= bounds.y; iy++) {
for (let ix = -bounds.x; ix <= bounds.x; ix++) {
const x = ix * CELL;
const y = iy * CELL;
if (predicate(x, y)) {
cells.push({ ix, iy, x, y });
}
}
}
return cells;
}
const roundTubeCells = makeMask(
{ x: 7, y: 7 },
(x, y) => {
const radius = Math.hypot(x, y);
return radius <= 1.27 && radius >= 0.50;
}
);
const squareTubeCells = makeMask(
{ x: 6, y: 6 },
(x, y) => {
const outer = Math.abs(x) <= 1.10 && Math.abs(y) <= 1.10;
const inner = Math.abs(x) <= 0.48 && Math.abs(y) <= 0.48;
return outer && !inner;
}
);
const ribbonCells = makeMask(
{ x: 7, y: 2 },
(x, y) => Math.abs(x) <= 1.32 && Math.abs(y) <= 0.22
);
const roundRodCells = makeMask(
{ x: 6, y: 6 },
(x, y) => Math.hypot(x, y) <= 1.10
);
const squareRodCells = makeMask(
{ x: 6, y: 6 },
(x, y) =>
Math.abs(x) <= 0.99 &&
Math.abs(y) <= 0.99 &&
Math.abs(x) + Math.abs(y) <= 1.65
);
const pastaItems = [
{
name: "Round tube",
detail: "hollow · stepped circle",
cells: roundTubeCells,
color: 0xc98232,
capColor: 0xffd17c,
length: 2.2
},
{
name: "Square tube",
detail: "hollow · square ring",
cells: squareTubeCells,
color: 0xbd6f2c,
capColor: 0xffc66e,
length: 2.2
},
{
name: "Ribbon",
detail: "wide · thin section",
cells: ribbonCells,
color: 0xdda247,
capColor: 0xffe0a0,
length: 2.35
},
{
name: "Round rod",
detail: "solid · stepped circle",
cells: roundRodCells,
color: 0xce8432,
capColor: 0xffd486,
length: 2.15
},
{
name: "Square rod",
detail: "solid · clipped corners",
cells: squareRodCells,
color: 0xc77830,
capColor: 0xffcb7b,
length: 2.15
}
];
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.68,
metalness: 0
});
const capMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.9,
metalness: 0,
emissive: 0x241305,
emissiveIntensity: 0.1
});
const outlineMaterial = new THREE.LineBasicMaterial({
color: 0x5d341b,
transparent: true,
opacity: 0.62
});
const dummy = new THREE.Object3D();
function colorShade(hex, seed, amount = 0.1) {
const color = new THREE.Color(hex);
const hash = (
(seed * 73856093) ^
(seed * 19349663) ^
(seed * 83492791)
) >>> 0;
const factor = 1 - amount + ((hash % 101) / 100) * amount;
return color.multiplyScalar(factor);
}
// BoxGeometry stores the negative-Z face in its last six indices.
// Removing that face leaves the cut opening genuinely exposed.
function makeBoxWithoutFront() {
const geometry = new THREE.BoxGeometry(1, 1, 1);
const index = geometry.index.array;
geometry.setIndex(Array.from(index.slice(0, index.length - 6)));
geometry.clearGroups();
geometry.computeVertexNormals();
return geometry;
}
function createCapGeometry(cells, baseColor) {
const positions = [];
const colors = [];
const indices = [];
const half = CELL * 0.47;
cells.forEach((cell, cellIndex) => {
const x0 = cell.x - half;
const x1 = cell.x + half;
const y0 = cell.y - half;
const y1 = cell.y + half;
const vertex = positions.length / 3;
// Winding faces negative Z, toward the viewer.
positions.push(
x0, y0, 0,
x0, y1, 0,
x1, y1, 0,
x1, y0, 0
);
const color = colorShade(baseColor, cellIndex + 11, 0.075);
for (let i = 0; i < 4; i++) {
colors.push(color.r, color.g, color.b);
}
indices.push(
vertex, vertex + 1, vertex + 2,
vertex, vertex + 2, vertex + 3
);
});
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function createBoundaryLines(cells) {
const occupied = new Set(cells.map((cell) => `${cell.ix},${cell.iy}`));
const positions = [];
const half = CELL * 0.48;
const z = 0.006;
function edge(x1, y1, x2, y2) {
positions.push(x1, y1, z, x2, y2, z);
}
cells.forEach((cell) => {
const left = occupied.has(`${cell.ix - 1},${cell.iy}`);
const right = occupied.has(`${cell.ix + 1},${cell.iy}`);
const down = occupied.has(`${cell.ix},${cell.iy - 1}`);
const up = occupied.has(`${cell.ix},${cell.iy + 1}`);
if (!left) {
edge(cell.x - half, cell.y - half, cell.x - half, cell.y + half);
}
if (!right) {
edge(cell.x + half, cell.y - half, cell.x + half, cell.y + half);
}
if (!down) {
edge(cell.x - half, cell.y - half, cell.x + half, cell.y - half);
}
if (!up) {
edge(cell.x - half, cell.y + half, cell.x + half, cell.y + half);
}
});
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
return new THREE.LineSegments(geometry, outlineMaterial);
}
function createPasta(item) {
const group = new THREE.Group();
const segmentLength = item.length / DEPTH_SEGMENTS;
const depthGap = 0.045;
const horizontalScale = CELL * 0.94;
// First depth segment: no negative-Z face, because the separate cap
// occupies the exact z = 0 cut plane.
const firstMesh = new THREE.InstancedMesh(
makeBoxWithoutFront(),
bodyMaterial,
item.cells.length
);
item.cells.forEach((cell, index) => {
const z0 = 0;
const z1 = segmentLength - depthGap * 0.5;
dummy.position.set(cell.x, cell.y, (z0 + z1) * 0.5);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(
horizontalScale,
horizontalScale,
z1 - z0
);
dummy.updateMatrix();
firstMesh.setMatrixAt(index, dummy.matrix);
firstMesh.setColorAt(
index,
colorShade(item.color, cell.ix * 31 + cell.iy * 17 + 2, 0.14)
);
});
firstMesh.instanceMatrix.needsUpdate = true;
if (firstMesh.instanceColor) firstMesh.instanceColor.needsUpdate = true;
firstMesh.castShadow = true;
firstMesh.receiveShadow = true;
firstMesh.computeBoundingSphere();
group.add(firstMesh);
// Remaining depth segments form the voxel extrusion. Small depth gaps
// expose the grid and give the pasta a stacked, block-built surface.
const remainingCount = item.cells.length * (DEPTH_SEGMENTS - 1);
const remainingMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
bodyMaterial,
remainingCount
);
let instance = 0;
for (let segment = 1; segment < DEPTH_SEGMENTS; segment++) {
const z0 = segment * segmentLength + depthGap * 0.5;
const z1 =
(segment + 1) * segmentLength -
(segment === DEPTH_SEGMENTS - 1 ? 0 : depthGap * 0.5);
item.cells.forEach((cell) => {
dummy.position.set(cell.x, cell.y, (z0 + z1) * 0.5);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(
horizontalScale,
horizontalScale,
z1 - z0
);
dummy.updateMatrix();
remainingMesh.setMatrixAt(instance, dummy.matrix);
remainingMesh.setColorAt(
instance,
colorShade(
item.color,
cell.ix * 23 + cell.iy * 41 + segment * 13 + 9,
0.15
)
);
instance++;
});
}
remainingMesh.instanceMatrix.needsUpdate = true;
if (remainingMesh.instanceColor) remainingMesh.instanceColor.needsUpdate = true;
remainingMesh.castShadow = true;
remainingMesh.receiveShadow = true;
remainingMesh.computeBoundingSphere();
group.add(remainingMesh);
// Enlarged cut face. Every quad lies exactly at z = 0.
const cap = new THREE.Mesh(
createCapGeometry(item.cells, item.capColor),
capMaterial
);
cap.castShadow = true;
cap.receiveShadow = true;
group.add(cap);
group.add(createBoundaryLines(item.cells));
scene.add(group);
item.group = group;
item.minY = Math.min(...item.cells.map((cell) => cell.y));
item.maxY = Math.max(...item.cells.map((cell) => cell.y));
item.anchor = new THREE.Vector3();
}
pastaItems.forEach(createPasta);
// -------------------------------------------------------------------------
// HTML labels
// -------------------------------------------------------------------------
const labelContainer = document.getElementById("labels");
pastaItems.forEach((item) => {
const label = document.createElement("div");
label.className = "spec-label";
label.innerHTML = `
<strong>${item.name}</strong>
<span>${item.detail}</span>
`;
labelContainer.appendChild(label);
item.label = label;
});
// -------------------------------------------------------------------------
// Layout
// -------------------------------------------------------------------------
let mobileLayout = null;
function layoutItems() {
const isMobile = window.innerWidth < 780;
mobileLayout = isMobile;
if (isMobile) {
const positions = [
[-1.55, 1.1],
[1.55, 1.1],
[-1.55, -1.55],
[1.55, -1.55],
[0, -4.2]
];
pastaItems.forEach((item, index) => {
item.group.position.set(positions[index][0], positions[index][1], 0);
});
cameraTarget.set(0, -1.35, 1);
} else {
pastaItems.forEach((item, index) => {
item.group.position.set((index - 2) * 3.05, 0.15, 0);
});
cameraTarget.set(0, 0.05, 1);
}
pastaItems.forEach((item) => {
item.anchor.set(
item.group.position.x,
item.group.position.y + item.minY - 0.29,
-0.02
);
});
}
// -------------------------------------------------------------------------
// Direct camera controls: no external control addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.05, 1);
let azimuth = 0.16;
let polar = 1.27;
let cameraDistance = 18;
function updateCamera() {
const sinPolar = Math.sin(polar);
const cosPolar = Math.cos(polar);
camera.position.set(
cameraTarget.x + cameraDistance * sinPolar * Math.sin(azimuth),
cameraTarget.y + cameraDistance * cosPolar,
cameraTarget.z - cameraDistance * sinPolar * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
if ((width < 780) !== mobileLayout) {
layoutItems();
}
const halfWidth = mobileLayout ? 3.12 : 8.15;
const halfHeight = Math.max(
mobileLayout ? 4.75 : 3.65,
halfWidth / aspect
);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
const threeQuarterButton = document.getElementById("three-quarter");
const faceOnButton = document.getElementById("face-on");
function setActiveButton(button) {
threeQuarterButton.classList.toggle("active", button === threeQuarterButton);
faceOnButton.classList.toggle("active", button === faceOnButton);
}
function setThreeQuarterView() {
azimuth = 0.16;
polar = 1.27;
cameraDistance = 18;
setActiveButton(threeQuarterButton);
updateCamera();
}
function setFaceOnView() {
azimuth = 0;
polar = 1.55;
cameraDistance = 18;
setActiveButton(faceOnButton);
updateCamera();
}
threeQuarterButton.addEventListener("click", setThreeQuarterView);
faceOnButton.addEventListener("click", setFaceOnView);
const canvas = renderer.domElement;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
azimuth = THREE.MathUtils.clamp(
azimuth - dx * 0.005,
-0.72,
0.72
);
polar = THREE.MathUtils.clamp(
polar - dy * 0.004,
0.42,
1.55
);
setActiveButton(null);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance * Math.exp(event.deltaY * 0.001),
11,
28
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
setThreeQuarterView();
}
});
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Render loop and projected labels
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
pastaItems.forEach((item) => {
projected.copy(item.anchor).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
item.label.style.left = `${x}px`;
item.label.style.top = `${y}px`;
item.label.style.opacity = projected.z > 1 ? "0" : "1";
});
}
function animate() {
requestAnimationFrame(animate);
updateLabels();
renderer.render(scene, camera);
}
layoutItems();
resize();
animate();
</script>
</body>
</html>
```