Prompt specification
Build or customize the Three.js 3D scene "Backpack compartments and load blocks" 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: Backpack compartments and load blocks
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/backpack-compartments-and-load-blocks-x0561
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Show a backpack cutaway with padded back panel, straps, and separate compartments; place symbolic mass blocks at different depths to reveal their distance from the body.
Working Three.js Starter (backpack-compartments-and-load-blocks-x0561):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Carry System — Cutaway Study</title>
<style>
:root {
--ink: #17383d;
--muted: #627477;
--paper: #f5efe3;
--line: rgba(23, 56, 61, 0.18);
--gold: #dfa83f;
--coral: #e9694a;
--teal: #4e8d86;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e5da;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app,
#stage {
position: fixed;
inset: 0;
}
#stage {
background:
radial-gradient(circle at 42% 46%, rgba(255, 255, 255, 0.94) 0%, rgba(255, 255, 255, 0.38) 31%, transparent 58%),
linear-gradient(145deg, #efede5 0%, #dfddd3 100%);
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.hero {
position: fixed;
z-index: 5;
top: 30px;
left: 34px;
width: min(370px, calc(100vw - 68px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 2px;
background: var(--coral);
content: "";
}
h1 {
margin: 0;
font-size: clamp(38px, 5.2vw, 76px);
font-weight: 520;
letter-spacing: -0.055em;
line-height: 0.91;
}
.hero p {
max-width: 320px;
margin: 18px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.study-tag {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 18px;
padding: 8px 11px;
border: 1px solid rgba(23, 56, 61, 0.14);
border-radius: 100px;
background: rgba(250, 247, 239, 0.62);
backdrop-filter: blur(12px);
color: var(--ink);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.study-tag span {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 0 4px rgba(233, 105, 74, 0.12);
}
.rail-heading {
position: fixed;
z-index: 5;
top: 34px;
right: 34px;
width: 224px;
pointer-events: none;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.rail-heading strong {
display: block;
margin-top: 7px;
color: var(--ink);
font-size: 11px;
letter-spacing: 0.12em;
}
#leaders {
position: fixed;
z-index: 3;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
.leader-path {
fill: none;
stroke-width: 1.2;
stroke-dasharray: 3 5;
opacity: 0.75;
}
.anchor-ring {
fill: rgba(245, 239, 227, 0.94);
stroke-width: 1.6;
}
.load-card {
position: fixed;
z-index: 5;
width: 224px;
padding: 15px 16px 14px;
transform: translateY(-50%);
border: 1px solid rgba(23, 56, 61, 0.14);
border-radius: 13px;
background: rgba(248, 244, 235, 0.86);
box-shadow: 0 16px 38px rgba(45, 59, 57, 0.09);
backdrop-filter: blur(15px);
pointer-events: none;
}
.load-card::before {
position: absolute;
top: 14px;
bottom: 14px;
left: 0;
width: 3px;
border-radius: 0 4px 4px 0;
background: var(--accent);
content: "";
}
.card-top {
display: flex;
align-items: center;
justify-content: space-between;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.card-top b {
color: var(--accent);
font-size: 11px;
}
.load-card h2 {
margin: 8px 0 3px;
font-size: 16px;
font-weight: 650;
letter-spacing: -0.02em;
}
.mass {
margin: 0 0 12px;
color: var(--muted);
font-size: 11px;
}
.distance {
display: flex;
align-items: center;
gap: 8px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--ink);
font-size: 10px;
font-weight: 700;
}
.distance i {
width: 22px;
height: 1px;
background: var(--accent);
}
.part-label {
position: fixed;
z-index: 4;
transform: translate(-50%, -50%);
padding: 6px 8px;
border: 1px solid rgba(23, 56, 61, 0.13);
border-radius: 5px;
background: rgba(245, 239, 227, 0.78);
color: var(--ink);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(8px);
}
.part-label::after {
position: absolute;
top: 50%;
left: 7px;
width: 4px;
height: 4px;
margin-top: -2px;
border-radius: 50%;
background: var(--coral);
content: "";
}
.part-label {
padding-left: 17px;
}
.mini-load {
position: fixed;
z-index: 5;
display: none;
transform: translate(-50%, -130%);
padding: 5px 7px;
border-radius: 4px;
background: rgba(248, 244, 235, 0.9);
color: var(--ink);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
pointer-events: none;
}
.controls {
position: fixed;
z-index: 6;
right: 34px;
bottom: 29px;
display: flex;
align-items: center;
gap: 15px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.controls span {
display: flex;
align-items: center;
gap: 7px;
}
.controls b {
width: 17px;
height: 17px;
border: 1px solid rgba(23, 56, 61, 0.22);
border-radius: 50%;
font-size: 9px;
font-weight: 500;
line-height: 15px;
text-align: center;
}
#resetView {
padding: 8px 11px;
border: 1px solid rgba(23, 56, 61, 0.18);
border-radius: 100px;
background: rgba(248, 244, 235, 0.7);
color: var(--ink);
cursor: pointer;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: background 160ms ease, transform 160ms ease;
}
#resetView:hover {
background: rgba(255, 255, 255, 0.94);
transform: translateY(-1px);
}
.datum {
position: fixed;
z-index: 4;
bottom: 29px;
left: 34px;
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
pointer-events: none;
}
.datum i {
width: 34px;
height: 1px;
background: var(--ink);
}
.mobile-summary {
position: fixed;
z-index: 6;
right: 16px;
bottom: 16px;
left: 16px;
display: none;
gap: 7px;
pointer-events: none;
}
.mobile-summary div {
flex: 1;
padding: 10px 8px;
border: 1px solid rgba(23, 56, 61, 0.13);
border-radius: 9px;
background: rgba(248, 244, 235, 0.84);
color: var(--muted);
font-size: 8px;
font-weight: 700;
line-height: 1.4;
text-align: center;
backdrop-filter: blur(12px);
}
.mobile-summary b {
display: block;
margin-bottom: 2px;
color: var(--ink);
font-size: 10px;
}
@media (max-width: 900px) {
.hero {
top: 22px;
left: 22px;
}
.hero p {
max-width: 270px;
}
.rail-heading {
right: 22px;
}
}
@media (max-width: 760px) {
.hero {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
font-size: clamp(38px, 13vw, 54px);
}
.hero p {
max-width: 245px;
margin-top: 11px;
font-size: 11px;
}
.study-tag,
.rail-heading,
.load-card,
.datum,
.controls {
display: none;
}
.part-label {
font-size: 7px;
}
.mini-load {
display: block;
}
.mobile-summary {
display: flex;
}
}
</style>
</head>
<body>
<main id="app">
<div id="stage" aria-label="Interactive 3D cutaway of a backpack"></div>
<header class="hero">
<div class="eyebrow">Carry system / study 04</div>
<h1>Load,<br />carried.</h1>
<p>
An exploded cutaway revealing three storage layers, a padded contact
surface, and the distance between carried mass and the body.
</p>
<div class="study-tag"><span></span> Exploded cutaway / 03 layers</div>
</header>
<div class="rail-heading">
Depth index
<strong>Mass relative to body datum</strong>
</div>
<svg id="leaders" aria-hidden="true"></svg>
<article class="load-card" id="card-0" style="--accent: var(--gold)">
<div class="card-top"><b>01</b><span>Contact layer</span></div>
<h2>Dense core</h2>
<p class="mass">0.42 kg symbolic mass</p>
<div class="distance"><i></i> 0.35 m from body</div>
</article>
<article class="load-card" id="card-1" style="--accent: var(--coral)">
<div class="card-top"><b>02</b><span>Main chamber</span></div>
<h2>Balanced kit</h2>
<p class="mass">0.78 kg symbolic mass</p>
<div class="distance"><i></i> 0.75 m from body</div>
</article>
<article class="load-card" id="card-2" style="--accent: var(--teal)">
<div class="card-top"><b>03</b><span>Outer pocket</span></div>
<h2>Outer cargo</h2>
<p class="mass">1.25 kg symbolic mass</p>
<div class="distance"><i></i> 1.20 m from body</div>
</article>
<div class="part-label" id="panel-label">Padded back panel + straps</div>
<div class="part-label" id="body-label">Body contact datum</div>
<div class="part-label" id="sleeve-label">01 / Tech sleeve</div>
<div class="part-label" id="bay-label">02 / Load bay</div>
<div class="part-label" id="pocket-label">03 / Quick access</div>
<div class="mini-load" id="mini-0">01 · 0.35 m</div>
<div class="mini-load" id="mini-1">02 · 0.75 m</div>
<div class="mini-load" id="mini-2">03 · 1.20 m</div>
<div class="datum"><i></i> Contact plane / rear datum</div>
<div class="controls">
<span><b>↔</b> Drag to orbit</span>
<span><b>⌁</b> Scroll to zoom</span>
<button id="resetView" type="button">Reset view</button>
</div>
<div class="mobile-summary">
<div><b>01</b>0.35 m / core</div>
<div><b>02</b>0.75 m / kit</div>
<div><b>03</b>1.20 m / cargo</div>
</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const leaders = document.querySelector("#leaders");
const cards = [...document.querySelectorAll(".load-card")];
const miniLabels = [
document.querySelector("#mini-0"),
document.querySelector("#mini-1"),
document.querySelector("#mini-2")
];
const scene = new THREE.Scene();
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: 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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x000000, 0);
stage.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
target: new THREE.Vector3(0.95, 0, 0.2),
azimuth: 0.47,
polar: 1.31,
radius: 10.8,
wantedAzimuth: 0.47,
wantedPolar: 1.31,
wantedRadius: 10.8
};
const model = new THREE.Group();
scene.add(model);
const BODY_X = 0.55;
const BODY_Z = -0.72;
const palette = {
ink: 0x17383d,
deep: 0x102f35,
teal: 0x3e7374,
pad: 0x557f82,
orange: 0xe9694a,
gold: 0xdfa83f,
tealMass: 0x4e8d86,
cream: 0xf0e6d4,
steel: 0x8ba1a0
};
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.02,
...options
});
}
const mat = {
deep: material(palette.deep),
ink: material(palette.ink),
teal: material(palette.teal),
pad: material(palette.pad, { roughness: 0.94 }),
orange: material(palette.orange, { roughness: 0.66 }),
gold: material(palette.gold, { roughness: 0.6 }),
cream: material(palette.cream, { roughness: 0.88 }),
steel: material(palette.steel, { metalness: 0.32, roughness: 0.45 }),
darkFabric: material(0x21464c, { roughness: 0.96 })
};
// Rounded geometry is created directly from Three.js core shapes.
function roundedShape(width, height, radius) {
const w = width / 2;
const h = height / 2;
const r = Math.min(radius, w, h);
const s = new THREE.Shape();
s.moveTo(-w + r, -h);
s.lineTo(w - r, -h);
s.quadraticCurveTo(w, -h, w, -h + r);
s.lineTo(w, h - r);
s.quadraticCurveTo(w, h, w - r, h);
s.lineTo(-w + r, h);
s.quadraticCurveTo(-w, h, -w, h - r);
s.lineTo(-w, -h + r);
s.quadraticCurveTo(-w, -h, -w + r, -h);
s.closePath();
return s;
}
function roundedHole(width, height, radius) {
const w = width / 2;
const h = height / 2;
const r = Math.min(radius, w, h);
const p = new THREE.Path();
// Clockwise path for the shape hole.
p.moveTo(w - r, -h);
p.lineTo(-w + r, -h);
p.quadraticCurveTo(-w, -h, -w, -h + r);
p.lineTo(-w, h - r);
p.quadraticCurveTo(-w, h, -w + r, h);
p.lineTo(w - r, h);
p.quadraticCurveTo(w, h, w, h - r);
p.lineTo(w, -h + r);
p.quadraticCurveTo(w, -h, w - r, -h);
p.closePath();
return p;
}
function roundedBox(width, height, depth, radius, bevel = 0.035) {
const geometry = new THREE.ExtrudeGeometry(roundedShape(width, height, radius), {
depth,
steps: 1,
curveSegments: 12,
bevelEnabled: bevel > 0,
bevelSegments: 3,
bevelSize: bevel,
bevelThickness: bevel
});
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
return geometry;
}
function roundedFrame(width, height, radius, border, depth) {
const shape = roundedShape(width, height, radius);
shape.holes.push(
roundedHole(
width - border * 2,
height - border * 2,
Math.max(0.04, radius - border)
)
);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
curveSegments: 12,
bevelEnabled: false
});
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
return geometry;
}
function mesh(geometry, materialValue, position, parent = model) {
const object = new THREE.Mesh(geometry, materialValue);
if (position) object.position.copy(position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function line(points, color, options = {}) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const lineMaterial = new THREE.LineDashedMaterial({
color,
transparent: true,
opacity: 0.55,
dashSize: 0.12,
gapSize: 0.08,
depthWrite: false,
...options
});
const object = new THREE.Line(geometry, lineMaterial);
object.computeLineDistances();
model.add(object);
return object;
}
// Lighting
scene.add(new THREE.HemisphereLight(0xfff6df, 0x789096, 2.25));
const key = new THREE.DirectionalLight(0xfff2d9, 3.1);
key.position.set(5.5, 8, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -7;
key.shadow.camera.right = 7;
key.shadow.camera.top = 7;
key.shadow.camera.bottom = -7;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 25;
key.shadow.bias = -0.0008;
scene.add(key);
const fill = new THREE.DirectionalLight(0xa9d1d4, 1.25);
fill.position.set(-5, 2, 4);
scene.add(fill);
const rim = new THREE.DirectionalLight(0xffb38f, 0.85);
rim.position.set(1, 3, -5);
scene.add(rim);
// Ground shadow and technical floor rings.
const shadowFloor = new THREE.Mesh(
new THREE.PlaneGeometry(35, 35),
new THREE.ShadowMaterial({
color: 0x345255,
opacity: 0.16
})
);
shadowFloor.rotation.x = -Math.PI / 2;
shadowFloor.position.y = -2.52;
shadowFloor.receiveShadow = true;
scene.add(shadowFloor);
for (const radius of [2.5, 3.05, 3.58]) {
const points = [];
for (let i = 0; i <= 96; i++) {
const a = (i / 96) * Math.PI * 2;
points.push(
new THREE.Vector3(
BODY_X + Math.cos(a) * radius,
-2.505,
0.15 + Math.sin(a) * radius * 0.48
)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const floorLine = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0x6f8583,
transparent: true,
opacity: 0.16
})
);
scene.add(floorLine);
}
// Translucent body silhouette and rear contact datum.
const bodyShape = new THREE.Shape();
bodyShape.moveTo(-0.56, -2.25);
bodyShape.lineTo(0.56, -2.25);
bodyShape.lineTo(0.78, -1.72);
bodyShape.lineTo(0.72, -0.36);
bodyShape.lineTo(0.92, 0.64);
bodyShape.lineTo(1.26, 1.22);
bodyShape.lineTo(0.82, 1.72);
bodyShape.lineTo(0.36, 1.82);
bodyShape.lineTo(0.28, 2.36);
bodyShape.lineTo(-0.28, 2.36);
bodyShape.lineTo(-0.36, 1.82);
bodyShape.lineTo(-0.82, 1.72);
bodyShape.lineTo(-1.26, 1.22);
bodyShape.lineTo(-0.92, 0.64);
bodyShape.lineTo(-0.72, -0.36);
bodyShape.lineTo(-0.78, -1.72);
bodyShape.closePath();
const bodyMesh = new THREE.Mesh(
new THREE.ShapeGeometry(bodyShape, 32),
new THREE.MeshBasicMaterial({
color: 0x668e91,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false
})
);
bodyMesh.position.set(BODY_X, 0, BODY_Z);
bodyMesh.renderOrder = -2;
model.add(bodyMesh);
const bodyOutlinePoints = bodyShape.getPoints(72).map(
(p) => new THREE.Vector3(p.x, p.y, BODY_Z + 0.012)
);
const bodyOutline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(bodyOutlinePoints),
new THREE.LineDashedMaterial({
color: 0x527b7e,
transparent: true,
opacity: 0.4,
dashSize: 0.1,
gapSize: 0.075
})
);
bodyOutline.position.x = BODY_X;
bodyOutline.computeLineDistances();
model.add(bodyOutline);
const datumPlane = mesh(
roundedBox(3.18, 4.8, 0.025, 0.4, 0),
new THREE.MeshBasicMaterial({
color: 0x789b9d,
transparent: true,
opacity: 0.035,
depthWrite: false,
side: THREE.DoubleSide
}),
new THREE.Vector3(BODY_X, 0.03, BODY_Z - 0.035)
);
datumPlane.castShadow = false;
// Main backpack body and three separate compartment frames.
mesh(
roundedBox(2.72, 3.82, 0.12, 0.31),
mat.deep,
new THREE.Vector3(BODY_X, 0, -0.08)
);
mesh(
roundedFrame(2.7, 3.78, 0.32, 0.14, 0.12),
mat.teal,
new THREE.Vector3(BODY_X, 0, 0.02)
);
mesh(
roundedFrame(2.91, 3.58, 0.34, 0.13, 0.13),
mat.orange,
new THREE.Vector3(BODY_X, -0.02, 0.62)
);
mesh(
roundedFrame(2.61, 3.02, 0.31, 0.12, 0.13),
mat.gold,
new THREE.Vector3(BODY_X, -0.31, 1.25)
);
// A translucent, displaced front shell indicates the cutaway.
const ghostShell = mesh(
roundedBox(1.02, 2.72, 0.07, 0.25, 0.02),
new THREE.MeshPhysicalMaterial({
color: palette.orange,
transparent: true,
opacity: 0.18,
roughness: 0.5,
transmission: 0.08,
side: THREE.DoubleSide
}),
new THREE.Vector3(BODY_X + 1.18, -0.34, 1.48)
);
ghostShell.castShadow = false;
// Fine rails connect the separated compartments.
for (const side of [-1, 1]) {
line(
[
new THREE.Vector3(BODY_X + side * 1.34, 1.7, -0.08),
new THREE.Vector3(BODY_X + side * 1.43, 1.57, 0.63),
new THREE.Vector3(BODY_X + side * 1.29, 1.33, 1.25)
],
0x6c8989,
{ opacity: 0.4, dashSize: 0.08, gapSize: 0.07 }
);
line(
[
new THREE.Vector3(BODY_X + side * 1.34, -1.72, -0.08),
new THREE.Vector3(BODY_X + side * 1.43, -1.66, 0.63),
new THREE.Vector3(BODY_X + side * 1.29, -1.62, 1.25)
],
0x6c8989,
{ opacity: 0.4, dashSize: 0.08, gapSize: 0.07 }
);
}
// Hinged padded back panel.
const panelPivot = new THREE.Group();
panelPivot.position.set(BODY_X - 1.45, 0, -0.25);
panelPivot.rotation.y = THREE.MathUtils.degToRad(-125);
model.add(panelPivot);
mesh(
roundedBox(2.82, 3.9, 0.2, 0.34),
mat.ink,
new THREE.Vector3(1.4, 0, 0),
panelPivot
);
// Three horizontal padded channels and a lumbar pad.
for (let i = 0; i < 3; i++) {
mesh(
roundedBox(2.18, 0.78, 0.13, 0.23),
mat.pad,
new THREE.Vector3(1.4, 0.93 - i * 0.91, -0.16),
panelPivot
);
const padLine = line(
[
new THREE.Vector3(0.55, 0.93 - i * 0.91, -0.235),
new THREE.Vector3(2.25, 0.93 - i * 0.91, -0.235)
],
0xbdd0c9,
{ opacity: 0.48, dashSize: 0.055, gapSize: 0.045 }
);
panelPivot.add(padLine);
padLine.position.z = 0;
}
mesh(
roundedBox(2.25, 0.54, 0.15, 0.2),
mat.teal,
new THREE.Vector3(1.4, -1.38, -0.18),
panelPivot
);
function createRibbon(points, width, materialValue) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p))
);
const samples = curve.getPoints(44);
const vertices = [];
const indices = [];
samples.forEach((p) => {
vertices.push(p.x - width / 2, p.y, p.z);
vertices.push(p.x + width / 2, p.y, p.z);
});
for (let i = 0; i < samples.length - 1; i++) {
const a = i * 2;
indices.push(a, a + 1, a + 2);
indices.push(a + 1, a + 3, a + 2);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(vertices, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const ribbon = new THREE.Mesh(geometry, materialValue);
ribbon.castShadow = true;
panelPivot.add(ribbon);
return ribbon;
}
const strapMaterial = material(0x274e54, {
roughness: 0.95,
side: THREE.DoubleSide
});
createRibbon(
[
[0.6, 1.72, -0.32],
[0.38, 1.18, -0.43],
[0.23, 0.46, -0.46],
[0.38, -0.43, -0.43],
[0.65, -1.28, -0.27]
],
0.29,
strapMaterial
);
createRibbon(
[
[2.2, 1.72, -0.32],
[2.42, 1.18, -0.43],
[2.57, 0.46, -0.46],
[2.42, -0.43, -0.43],
[2.15, -1.28, -0.27]
],
0.29,
strapMaterial
);
createRibbon(
[
[1.06, 1.91, -0.02],
[1.1, 2.22, -0.05],
[1.4, 2.39, -0.08],
[1.7, 2.22, -0.05],
[1.74, 1.91, -0.02]
],
0.23,
strapMaterial
);
for (const x of [0.61, 2.19]) {
const adjuster = mesh(
roundedBox(0.38, 0.22, 0.08, 0.055),
mat.steel,
new THREE.Vector3(x, 0.42, -0.5),
panelPivot
);
adjuster.rotation.z = x < 1 ? -0.12 : 0.12;
}
// Hinge details.
for (const y of [-1.14, 1.12]) {
const hinge = mesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.34, 24),
mat.gold,
new THREE.Vector3(BODY_X - 1.45, y, -0.25)
);
hinge.castShadow = true;
}
// Weight-label texture, generated locally.
function weightTexture(text) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 256;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(248, 244, 235, 0.94)";
context.beginPath();
context.roundRect(18, 18, 476, 220, 34);
context.fill();
context.fillStyle = "#17383d";
context.font = "700 102px Arial, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 130);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const loadData = [
{
position: new THREE.Vector3(-0.22, 0.66, 0.18),
size: 0.63,
depth: 0.53,
color: palette.gold,
weight: "0.42",
css: "#dfa83f"
},
{
position: new THREE.Vector3(1.27, 0.05, 0.76),
size: 0.84,
depth: 0.58,
color: palette.orange,
weight: "0.78",
css: "#e9694a"
},
{
position: new THREE.Vector3(0.22, -0.62, 1.43),
size: 1.06,
depth: 0.64,
color: palette.tealMass,
weight: "1.25",
css: "#4e8d86"
}
];
const loadAnchors = [];
loadData.forEach((entry, index) => {
const group = new THREE.Group();
group.position.copy(entry.position);
model.add(group);
mesh(
roundedBox(
entry.size,
entry.size,
entry.depth,
0.12,
0.045
),
material(entry.color, { roughness: 0.62 }),
new THREE.Vector3(),
group
);
// Small inset top detail gives the blocks a physical, symbolic quality.
mesh(
roundedBox(entry.size * 0.46, entry.size * 0.16, 0.045, 0.045),
mat.cream,
new THREE.Vector3(0, entry.size * 0.28, entry.depth / 2 + 0.026),
group
);
const label = new THREE.Mesh(
new THREE.PlaneGeometry(entry.size * 0.82, entry.size * 0.41),
new THREE.MeshBasicMaterial({
map: weightTexture(entry.weight),
transparent: true,
depthWrite: false,
toneMapped: false
})
);
label.position.set(0, -0.02, entry.depth / 2 + 0.033);
group.add(label);
const depthLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(entry.position.x, entry.position.y, BODY_Z + 0.035),
new THREE.Vector3(entry.position.x, entry.position.y, entry.position.z)
]),
new THREE.LineDashedMaterial({
color: entry.color,
transparent: true,
opacity: 0.9,
dashSize: 0.09,
gapSize: 0.055,
depthTest: false,
depthWrite: false
})
);
depthLine.computeLineDistances();
depthLine.renderOrder = 8;
model.add(depthLine);
const datumDot = new THREE.Mesh(
new THREE.SphereGeometry(0.047, 18, 12),
new THREE.MeshBasicMaterial({
color: entry.color,
depthTest: false,
depthWrite: false
})
);
datumDot.position.set(
entry.position.x,
entry.position.y,
BODY_Z + 0.04
);
datumDot.renderOrder = 9;
model.add(datumDot);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.07, 0.17, 16),
new THREE.MeshBasicMaterial({
color: entry.color,
depthTest: false,
depthWrite: false
})
);
arrow.position.set(
entry.position.x,
entry.position.y,
entry.position.z - 0.11
);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0, 0, -1)
);
arrow.renderOrder = 9;
model.add(arrow);
loadAnchors.push(entry.position.clone());
});
// Projected DOM leaders.
const SVG_NS = "http://www.w3.org/2000/svg";
const leaderPaths = [];
const anchorRings = [];
loadData.forEach((entry) => {
const path = document.createElementNS(SVG_NS, "path");
path.setAttribute("class", "leader-path");
path.setAttribute("stroke", entry.css);
leaders.appendChild(path);
leaderPaths.push(path);
const circle = document.createElementNS(SVG_NS, "circle");
circle.setAttribute("class", "anchor-ring");
circle.setAttribute("r", "5");
circle.setAttribute("stroke", entry.css);
leaders.appendChild(circle);
anchorRings.push(circle);
});
function projectPoint(point) {
const projected = point.clone().project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight,
visible:
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15
};
}
function positionPartLabel(element, point, offsetX = 0, offsetY = 0) {
const projected = projectPoint(point);
element.style.left = `${projected.x + offsetX}px`;
element.style.top = `${projected.y + offsetY}px`;
element.style.opacity = projected.visible ? "1" : "0";
}
function updateOverlays() {
const width = window.innerWidth;
const height = window.innerHeight;
const desktop = width > 760;
loadAnchors.forEach((point, index) => {
const projected = projectPoint(point);
const mini = miniLabels[index];
mini.style.left = `${projected.x}px`;
mini.style.top = `${projected.y}px`;
mini.style.opacity = projected.visible ? "1" : "0";
if (!desktop) {
leaderPaths[index].setAttribute("d", "");
anchorRings[index].setAttribute("r", "0");
return;
}
const cardX = width - 246;
const cardY = height * (0.29 + index * 0.205);
const endX = cardX - 14;
cards[index].style.left = `${cardX}px`;
cards[index].style.top = `${cardY}px`;
cards[index].style.opacity = projected.visible ? "1" : "0.42";
const bendX = projected.x + Math.max(35, (endX - projected.x) * 0.48);
leaderPaths[index].setAttribute(
"d",
`M ${projected.x} ${projected.y}
C ${bendX} ${projected.y},
${endX - 28} ${cardY},
${endX} ${cardY}`
);
leaderPaths[index].style.opacity = projected.visible ? "0.78" : "0.18";
anchorRings[index].setAttribute("cx", projected.x);
anchorRings[index].setAttribute("cy", projected.y);
anchorRings[index].setAttribute("r", projected.visible ? "5" : "0");
});
model.updateMatrixWorld(true);
const panelAnchor = panelPivot.localToWorld(
new THREE.Vector3(1.4, 0.74, -0.47)
);
positionPartLabel(
document.querySelector("#panel-label"),
panelAnchor,
-30,
-28
);
positionPartLabel(
document.querySelector("#body-label"),
new THREE.Vector3(BODY_X + 1.08, 1.9, BODY_Z + 0.02),
30,
-8
);
positionPartLabel(
document.querySelector("#sleeve-label"),
new THREE.Vector3(BODY_X + 1.12, 1.91, 0.02),
34,
-4
);
positionPartLabel(
document.querySelector("#bay-label"),
new THREE.Vector3(BODY_X + 1.28, 1.76, 0.62),
34,
-4
);
positionPartLabel(
document.querySelector("#pocket-label"),
new THREE.Vector3(BODY_X + 1.16, 1.31, 1.25),
34,
-4
);
}
// Direct camera controls: orbit, zoom, keyboard, touch and reset.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
controls.wantedAzimuth -= dx * 0.006;
controls.wantedPolar = THREE.MathUtils.clamp(
controls.wantedPolar - dy * 0.005,
0.65,
1.78
);
});
function stopDragging(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.wantedRadius = THREE.MathUtils.clamp(
controls.wantedRadius * Math.exp(event.deltaY * 0.001),
6.3,
17
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
const step = 0.09;
if (event.key === "ArrowLeft") controls.wantedAzimuth += step;
if (event.key === "ArrowRight") controls.wantedAzimuth -= step;
if (event.key === "ArrowUp") controls.wantedPolar -= step;
if (event.key === "ArrowDown") controls.wantedPolar += step;
if (event.key === "+" || event.key === "=") {
controls.wantedRadius = Math.max(6.3, controls.wantedRadius - 0.5);
}
if (event.key === "-") {
controls.wantedRadius = Math.min(17, controls.wantedRadius + 0.5);
}
if (event.key === "r" || event.key === "R") resetView();
});
function resetView() {
controls.wantedAzimuth = 0.47;
controls.wantedPolar = 1.31;
controls.wantedRadius = window.innerWidth < 760 ? 12.4 : 10.8;
controls.target.set(
window.innerWidth < 760 ? 0.3 : 0.95,
0,
0.2
);
}
document.querySelector("#resetView").addEventListener("click", resetView);
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);
leaders.setAttribute("viewBox", `0 0 ${width} ${height}`);
leaders.setAttribute("width", width);
leaders.setAttribute("height", height);
if (width < 760) {
controls.target.x = 0.3;
controls.wantedRadius = Math.max(controls.wantedRadius, 11.7);
} else {
controls.target.x = 0.95;
}
}
window.addEventListener("resize", resize);
resize();
resetView();
function animate() {
requestAnimationFrame(animate);
const damping = 0.085;
controls.azimuth +=
(controls.wantedAzimuth - controls.azimuth) * damping;
controls.polar +=
(controls.wantedPolar - controls.polar) * damping;
controls.radius +=
(controls.wantedRadius - controls.radius) * damping;
const sinPolar = Math.sin(controls.polar);
const cosPolar = Math.cos(controls.polar);
camera.position.set(
controls.target.x +
controls.radius * sinPolar * Math.sin(controls.azimuth),
controls.target.y + controls.radius * cosPolar,
controls.target.z +
controls.radius * sinPolar * Math.cos(controls.azimuth)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
updateOverlays();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```