Prompt specification
Build or customize the Three.js 3D scene "Helmet shell and liner section" 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: Helmet shell and liner section
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/helmet-shell-and-liner-section-x0605
Scene Description Prompt:
Show a stylized bicycle-helmet cutaway with shell, liner, straps, and head clearance. Use Three.js from cdnjs in one HTML file.
Working Three.js Starter (helmet-shell-and-liner-section-x0605):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Helmet Cutaway — Three.js</title>
<style>
:root {
--ink: #17262d;
--muted: #60757d;
--paper: rgba(246, 249, 247, 0.82);
--line: rgba(23, 38, 45, 0.14);
--coral: #ed5946;
--foam: #f2c84b;
--strap: #263b43;
--head: #75bdcf;
--clearance: #ffca4b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
background:
radial-gradient(circle at 76% 22%, rgba(255, 255, 255, 0.95), transparent 28%),
linear-gradient(145deg, #dce9eb 0%, #eef1eb 52%, #d8e2df 100%);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.hero {
position: fixed;
top: clamp(22px, 4vw, 52px);
left: clamp(22px, 4vw, 56px);
z-index: 10;
width: min(390px, calc(100vw - 44px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
color: var(--coral);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 2px;
content: "";
background: var(--coral);
}
h1 {
margin: 0;
font-size: clamp(38px, 5vw, 68px);
font-weight: 820;
line-height: 0.9;
letter-spacing: -0.065em;
text-transform: uppercase;
}
.subtitle {
max-width: 340px;
margin: 19px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.spec {
display: inline-flex;
gap: 16px;
margin-top: 18px;
padding-top: 13px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend {
position: fixed;
z-index: 10;
top: clamp(24px, 4vw, 52px);
right: clamp(22px, 4vw, 56px);
width: 210px;
padding: 18px 19px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 16px;
background: rgba(248, 250, 247, 0.64);
box-shadow: 0 16px 50px rgba(37, 63, 67, 0.08);
backdrop-filter: blur(16px);
pointer-events: none;
}
.legend-title {
margin-bottom: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin: 10px 0;
font-size: 11px;
font-weight: 650;
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.45);
}
.swatch.shell { background: var(--coral); }
.swatch.liner { background: var(--foam); }
.swatch.straps { background: var(--strap); }
.swatch.head { background: var(--head); }
.swatch.clearance { background: var(--clearance); }
.toolbar {
position: fixed;
z-index: 20;
left: 50%;
bottom: clamp(22px, 4vw, 42px);
display: flex;
align-items: center;
gap: 6px;
max-width: calc(100vw - 36px);
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.76);
border-radius: 16px;
background: rgba(248, 250, 247, 0.76);
box-shadow: 0 18px 50px rgba(39, 64, 68, 0.12);
backdrop-filter: blur(18px);
transform: translateX(-50%);
}
.toolbar button {
min-height: 36px;
padding: 0 13px;
border: 0;
border-radius: 10px;
color: var(--muted);
background: transparent;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: color 160ms ease, background 160ms ease, transform 160ms ease;
white-space: nowrap;
}
.toolbar button:hover {
color: var(--ink);
background: rgba(23, 38, 45, 0.06);
}
.toolbar button:active {
transform: scale(0.97);
}
.toolbar button[aria-pressed="true"] {
color: #fff;
background: var(--ink);
}
.toolbar .divider {
width: 1px;
height: 22px;
margin: 0 2px;
background: var(--line);
}
.hint {
position: fixed;
z-index: 10;
left: clamp(22px, 4vw, 56px);
bottom: clamp(24px, 4vw, 46px);
color: rgba(23, 38, 45, 0.58);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
.callout {
position: fixed;
z-index: 8;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 10px;
color: var(--ink);
background: rgba(249, 251, 248, 0.82);
box-shadow: 0 9px 25px rgba(40, 65, 70, 0.09);
backdrop-filter: blur(12px);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
transform: translate(-50%, -50%);
transition: opacity 150ms ease;
pointer-events: none;
white-space: nowrap;
}
.callout i {
width: 7px;
height: 7px;
border-radius: 50%;
}
@media (max-width: 760px) {
.hero {
top: 20px;
left: 20px;
}
h1 {
font-size: 38px;
}
.subtitle,
.spec,
.legend,
.hint {
display: none;
}
.toolbar {
bottom: 16px;
gap: 2px;
padding: 5px;
}
.toolbar button {
padding: 0 9px;
font-size: 8px;
}
.callout {
padding: 6px 8px;
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional bicycle helmet cutaway"></canvas>
<header class="hero">
<div class="eyebrow">Safety / Structure</div>
<h1>Helmet<br>Cutaway</h1>
<p class="subtitle">
An exploded view of a road bicycle helmet, revealing the impact shell,
EPS liner, retention system, and protective head clearance.
</p>
<div class="spec">
<span>01 / Shell</span>
<span>02 / Liner</span>
<span>03 / Clearance</span>
</div>
</header>
<aside class="legend" aria-label="Material legend">
<div class="legend-title">Material key</div>
<div class="legend-row"><i class="swatch shell"></i>Polycarbonate shell</div>
<div class="legend-row"><i class="swatch liner"></i>EPS impact liner</div>
<div class="legend-row"><i class="swatch straps"></i>Nylon webbing</div>
<div class="legend-row"><i class="swatch head"></i>Head envelope</div>
<div class="legend-row"><i class="swatch clearance"></i>Air clearance</div>
</aside>
<div id="callout-shell" class="callout"><i style="background:var(--coral)"></i>Outer shell</div>
<div id="callout-liner" class="callout"><i style="background:var(--foam)"></i>EPS liner</div>
<div id="callout-straps" class="callout"><i style="background:var(--strap)"></i>Retention straps</div>
<div id="callout-clearance" class="callout"><i style="background:var(--clearance)"></i>Head clearance</div>
<nav class="toolbar" aria-label="Visible components">
<button data-layer="shell" aria-pressed="true">Shell</button>
<button data-layer="liner" aria-pressed="true">Liner</button>
<button data-layer="straps" aria-pressed="true">Straps</button>
<button data-layer="head" aria-pressed="true">Head</button>
<button data-layer="clearance" aria-pressed="true">Clearance</button>
<span class="divider"></span>
<button id="reset">Reset view</button>
</nav>
<div class="hint">Drag to orbit · Scroll or pinch to zoom</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 canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe3ecea, 9, 19);
const camera = new THREE.PerspectiveCamera(
35,
window.innerWidth / window.innerHeight,
0.1,
40
);
const controls = {
target: new THREE.Vector3(0, 0.78, 0),
azimuth: 0.67,
polar: 1.14,
radius: 7.25,
dragging: false,
previousX: 0,
previousY: 0,
pointers: new Map(),
pinchDistance: 0
};
function updateCamera() {
const sinPolar = Math.sin(controls.polar);
camera.position.set(
controls.target.x + controls.radius * sinPolar * Math.sin(controls.azimuth),
controls.target.y + controls.radius * Math.cos(controls.polar),
controls.target.z + controls.radius * sinPolar * Math.cos(controls.azimuth)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.azimuth = 0.67;
controls.polar = 1.14;
controls.radius = 7.25;
updateCamera();
}
updateCamera();
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xffffff, 0x70858b, 2.15));
const keyLight = new THREE.DirectionalLight(0xfff6e8, 3.2);
keyLight.position.set(4.5, 7, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb7e3f0, 1.5);
fillLight.position.set(-5, 3, -3);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffd4bd, 1.7);
rimLight.position.set(-2, 4, 5);
scene.add(rimLight);
// ------------------------------------------------------------
// Display platform
// ------------------------------------------------------------
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(2.72, 2.85, 0.12, 96),
new THREE.MeshStandardMaterial({
color: 0xcbd9d7,
roughness: 0.84,
metalness: 0.04
})
);
platform.position.y = -0.37;
platform.receiveShadow = true;
scene.add(platform);
const platformRing = new THREE.Mesh(
new THREE.RingGeometry(2.48, 2.495, 128),
new THREE.MeshBasicMaterial({
color: 0x8da3a4,
transparent: true,
opacity: 0.28,
side: THREE.DoubleSide
})
);
platformRing.rotation.x = -Math.PI / 2;
platformRing.position.y = -0.303;
scene.add(platformRing);
const shadowPlane = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.ShadowMaterial({
color: 0x5b6e70,
opacity: 0.12
})
);
shadowPlane.rotation.x = -Math.PI / 2;
shadowPlane.position.y = -0.305;
shadowPlane.receiveShadow = true;
scene.add(shadowPlane);
// ------------------------------------------------------------
// Helmet geometry helpers
// ------------------------------------------------------------
const HELMET_CENTER_Y = 1.15;
const CUT_CENTER = 0.78;
const CUT_HALF_WIDTH = 0.58;
function angularDistance(a, b) {
return Math.abs(Math.atan2(Math.sin(a - b), Math.cos(a - b)));
}
function smoothstep(min, max, value) {
return THREE.MathUtils.smoothstep(value, min, max);
}
function shellThetaMax(phi, cutMax, normalMax) {
const distance = angularDistance(phi, CUT_CENTER);
const cutWeight = 1 - smoothstep(CUT_HALF_WIDTH, CUT_HALF_WIDTH + 0.28, distance);
return THREE.MathUtils.lerp(normalMax, cutMax, cutWeight);
}
function ellipsoidPoint(rx, rz, ry, theta, phi, centerY = HELMET_CENTER_Y) {
return new THREE.Vector3(
rx * Math.sin(theta) * Math.cos(phi),
centerY + ry * Math.cos(theta),
rz * Math.sin(theta) * Math.sin(phi)
);
}
function createPatchGeometry(
rx,
rz,
ry,
thetaMaxFunction,
reverse = false
) {
const phiSegments = 112;
const thetaSegments = 30;
const positions = [];
const indices = [];
for (let row = 0; row <= thetaSegments; row++) {
for (let column = 0; column < phiSegments; column++) {
const phi = (column / phiSegments) * Math.PI * 2;
const theta = thetaMaxFunction(phi) * (row / thetaSegments);
const point = ellipsoidPoint(rx, rz, ry, theta, phi);
positions.push(point.x, point.y, point.z);
}
}
for (let row = 0; row < thetaSegments; row++) {
for (let column = 0; column < phiSegments; column++) {
const nextColumn = (column + 1) % phiSegments;
const a = row * phiSegments + column;
const b = row * phiSegments + nextColumn;
const c = (row + 1) * phiSegments + column;
const d = (row + 1) * phiSegments + nextColumn;
if (reverse) {
indices.push(a, c, b, b, c, d);
} else {
indices.push(a, b, c, b, d, c);
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function createRimGeometry(
outerRx,
outerRz,
outerRy,
innerRx,
innerRz,
innerRy,
thetaMaxFunction
) {
const segments = 112;
const positions = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const phi = (i / segments) * Math.PI * 2;
const theta = thetaMaxFunction(phi);
const outer = ellipsoidPoint(outerRx, outerRz, outerRy, theta, phi);
const inner = ellipsoidPoint(innerRx, innerRz, innerRy, theta, phi);
positions.push(outer.x, outer.y, outer.z);
positions.push(inner.x, inner.y, inner.z);
}
for (let i = 0; i < segments; i++) {
const a = i * 2;
const b = i * 2 + 1;
const c = (i + 1) * 2;
const d = (i + 1) * 2 + 1;
indices.push(a, c, b, b, c, d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function createShellLayer({
outer,
inner,
cutMax,
normalMax,
outerMaterial,
innerMaterial,
rimMaterial
}) {
const group = new THREE.Group();
const thetaMax = (phi) => shellThetaMax(phi, cutMax, normalMax);
const outerMesh = new THREE.Mesh(
createPatchGeometry(
outer.rx,
outer.rz,
outer.ry,
thetaMax,
false
),
outerMaterial
);
const innerMesh = new THREE.Mesh(
createPatchGeometry(
inner.rx,
inner.rz,
inner.ry,
thetaMax,
true
),
innerMaterial
);
const rimMesh = new THREE.Mesh(
createRimGeometry(
outer.rx,
outer.rz,
outer.ry,
inner.rx,
inner.rz,
inner.ry,
thetaMax
),
rimMaterial
);
outerMesh.castShadow = true;
outerMesh.receiveShadow = true;
innerMesh.castShadow = true;
innerMesh.receiveShadow = true;
rimMesh.castShadow = true;
group.add(outerMesh, innerMesh, rimMesh);
const trimPoints = [];
for (let i = 0; i <= 160; i++) {
const phi = (i / 160) * Math.PI * 2;
const theta = thetaMax(phi);
trimPoints.push(
ellipsoidPoint(outer.rx, outer.rz, outer.ry, theta, phi)
);
}
const trim = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(trimPoints),
new THREE.LineBasicMaterial({
color: 0xffb096,
transparent: true,
opacity: 0.75
})
);
group.add(trim);
return group;
}
// ------------------------------------------------------------
// Outer shell and EPS liner
// ------------------------------------------------------------
const shellGroup = new THREE.Group();
shellGroup.name = "shell";
const shellOuterMaterial = new THREE.MeshPhysicalMaterial({
color: 0xec5845,
roughness: 0.28,
metalness: 0.03,
clearcoat: 0.65,
clearcoatRoughness: 0.22,
side: THREE.DoubleSide
});
const shellInnerMaterial = new THREE.MeshStandardMaterial({
color: 0xa92f30,
roughness: 0.56,
metalness: 0.01,
side: THREE.DoubleSide
});
const shellRimMaterial = new THREE.MeshStandardMaterial({
color: 0xff9872,
roughness: 0.38,
metalness: 0.02,
side: THREE.DoubleSide
});
shellGroup.add(
createShellLayer({
outer: { rx: 1.50, rz: 1.72, ry: 1.05 },
inner: { rx: 1.40, rz: 1.61, ry: 0.94 },
cutMax: 1.02,
normalMax: 1.58,
outerMaterial: shellOuterMaterial,
innerMaterial: shellInnerMaterial,
rimMaterial: shellRimMaterial
})
);
scene.add(shellGroup);
const linerGroup = new THREE.Group();
linerGroup.name = "liner";
const foamOuterMaterial = new THREE.MeshStandardMaterial({
color: 0xf0c64b,
roughness: 0.91,
metalness: 0,
side: THREE.DoubleSide
});
const foamInnerMaterial = new THREE.MeshStandardMaterial({
color: 0xe9b83a,
roughness: 0.96,
metalness: 0,
side: THREE.DoubleSide
});
const foamRimMaterial = new THREE.MeshStandardMaterial({
color: 0xffe99a,
roughness: 0.84,
metalness: 0,
side: THREE.DoubleSide
});
linerGroup.add(
createShellLayer({
outer: { rx: 1.39, rz: 1.60, ry: 0.93 },
inner: { rx: 1.18, rz: 1.38, ry: 0.72 },
cutMax: 1.24,
normalMax: 1.55,
outerMaterial: foamOuterMaterial,
innerMaterial: foamInnerMaterial,
rimMaterial: foamRimMaterial
})
);
scene.add(linerGroup);
// ------------------------------------------------------------
// Recessed-looking ventilation slots
// ------------------------------------------------------------
function roundedRectangle(width, height, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
const ventGeometry = new THREE.ExtrudeGeometry(
roundedRectangle(0.19, 0.64, 0.085),
{
depth: 0.035,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.012,
bevelThickness: 0.01,
curveSegments: 12
}
);
const ventMaterial = new THREE.MeshStandardMaterial({
color: 0x23343a,
roughness: 0.44,
metalness: 0.08
});
const ventPlacements = [
[-2.30, 0.70],
[-1.68, 0.82],
[-1.06, 0.74],
[-0.44, 0.86],
[1.88, 0.80],
[2.48, 0.68],
[3.08, 0.82],
[3.68, 0.69],
[4.28, 0.77]
];
function placeVent(phi, theta) {
const rx = 1.50;
const rz = 1.72;
const ry = 1.05;
const point = ellipsoidPoint(rx, rz, ry, theta, phi);
const normal = new THREE.Vector3(
point.x / (rx * rx),
(point.y - HELMET_CENTER_Y) / (ry * ry),
point.z / (rz * rz)
).normalize();
const phiTangent = ellipsoidPoint(
rx,
rz,
ry,
theta,
phi + 0.005
).sub(ellipsoidPoint(rx, rz, ry, theta, phi - 0.005)).normalize();
const thetaTangent = ellipsoidPoint(
rx,
rz,
ry,
theta + 0.005,
phi
).sub(ellipsoidPoint(rx, rz, ry, theta - 0.005, phi))
.projectOnPlane(normal)
.normalize();
const basis = new THREE.Matrix4().makeBasis(
phiTangent,
thetaTangent,
normal
);
const vent = new THREE.Mesh(ventGeometry, ventMaterial);
vent.quaternion.setFromRotationMatrix(basis);
vent.position.copy(point).addScaledVector(normal, 0.012);
vent.castShadow = true;
shellGroup.add(vent);
}
ventPlacements.forEach(([phi, theta]) => placeVent(phi, theta));
// ------------------------------------------------------------
// Retention straps
// ------------------------------------------------------------
const strapGroup = new THREE.Group();
strapGroup.name = "straps";
const strapMaterial = new THREE.MeshStandardMaterial({
color: 0x263a42,
roughness: 0.88,
metalness: 0,
side: THREE.DoubleSide
});
const strapEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x172a31,
roughness: 0.95,
side: THREE.DoubleSide
});
function createRibbonGeometry(points, width, widthAxis) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point)),
false,
"centripetal"
);
const segments = 48;
const positions = [];
const indices = [];
const axis = new THREE.Vector3(...widthAxis).normalize();
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const point = curve.getPoint(t);
const tangent = curve.getTangent(t).normalize();
const side = axis.clone().projectOnPlane(tangent).normalize().multiplyScalar(width / 2);
positions.push(
point.x - side.x,
point.y - side.y,
point.z - side.z,
point.x + side.x,
point.y + side.y,
point.z + side.z
);
if (i < segments) {
const a = i * 2;
indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const strapPaths = [
{
points: [[0, 0.48, 1.47], [0, 0.14, 1.16], [0, -0.055, 0.64]],
axis: [1, 0, 0],
width: 0.135
},
{
points: [[0, 0.47, -1.42], [0, 0.11, -1.02], [0, -0.075, 0.55]],
axis: [1, 0, 0],
width: 0.125
},
{
points: [[-1.29, 0.46, 0], [-1.08, 0.10, -0.04], [-0.41, -0.06, 0.55]],
axis: [0, 0, 1],
width: 0.13
},
{
points: [[1.29, 0.46, 0], [1.08, 0.10, -0.04], [0.41, -0.06, 0.55]],
axis: [0, 0, 1],
width: 0.13
}
];
for (const strapPath of strapPaths) {
const strap = new THREE.Mesh(
createRibbonGeometry(
strapPath.points,
strapPath.width,
strapPath.axis
),
strapMaterial
);
strap.castShadow = true;
strapGroup.add(strap);
}
const buckleGeometry = new THREE.ExtrudeGeometry(
roundedRectangle(0.37, 0.25, 0.065),
{
depth: 0.095,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.012,
bevelThickness: 0.01
}
);
const buckle = new THREE.Mesh(
buckleGeometry,
new THREE.MeshStandardMaterial({
color: 0x182a30,
roughness: 0.38,
metalness: 0.22
})
);
buckle.position.set(0, -0.055, 0.55);
buckle.castShadow = true;
strapGroup.add(buckle);
const buckleSlot = new THREE.Mesh(
new THREE.ExtrudeGeometry(
roundedRectangle(0.24, 0.075, 0.025),
{
depth: 0.014,
bevelEnabled: false
}
),
new THREE.MeshStandardMaterial({
color: 0x6f858a,
roughness: 0.4,
metalness: 0.3
})
);
buckleSlot.position.set(0, -0.047, 0.66);
strapGroup.add(buckleSlot);
scene.add(strapGroup);
// ------------------------------------------------------------
// Translucent head envelope
// ------------------------------------------------------------
const headGroup = new THREE.Group();
headGroup.name = "head";
const headMaterial = new THREE.MeshPhysicalMaterial({
color: 0x77c4d4,
transparent: true,
opacity: 0.19,
roughness: 0.46,
metalness: 0,
transmission: 0.08,
thickness: 0.3,
depthWrite: false,
side: THREE.DoubleSide
});
const head = new THREE.Mesh(
new THREE.SphereGeometry(1, 56, 40),
headMaterial
);
head.scale.set(0.82, 1.0, 0.94);
head.position.set(0, 0.60, 0.02);
head.renderOrder = 3;
headGroup.add(head);
const nose = new THREE.Mesh(
new THREE.ConeGeometry(0.105, 0.27, 20),
headMaterial
);
nose.rotation.x = Math.PI / 2;
nose.position.set(0, 0.59, 0.91);
nose.renderOrder = 3;
headGroup.add(nose);
for (const side of [-1, 1]) {
const ear = new THREE.Mesh(
new THREE.SphereGeometry(1, 24, 18),
headMaterial
);
ear.scale.set(0.12, 0.23, 0.17);
ear.position.set(side * 0.78, 0.55, 0.03);
ear.renderOrder = 3;
headGroup.add(ear);
}
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.35, 0.72, 32),
headMaterial
);
neck.position.set(0, -0.12, -0.02);
neck.renderOrder = 3;
headGroup.add(neck);
const contourMaterial = new THREE.LineBasicMaterial({
color: 0x4c9eaf,
transparent: true,
opacity: 0.36,
depthWrite: false
});
function addHeadContour(y, radiusScale) {
const points = [];
for (let i = 0; i <= 96; i++) {
const angle = (i / 96) * Math.PI * 2;
points.push(
new THREE.Vector3(
Math.cos(angle) * 0.82 * radiusScale,
y,
Math.sin(angle) * 0.94 * radiusScale + 0.02
)
);
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
contourMaterial
);
line.renderOrder = 4;
headGroup.add(line);
}
addHeadContour(0.91, 0.80);
addHeadContour(0.60, 1.0);
addHeadContour(0.28, 0.93);
scene.add(headGroup);
// ------------------------------------------------------------
// Clearance measurement
// ------------------------------------------------------------
const clearanceGroup = new THREE.Group();
clearanceGroup.name = "clearance";
const clearanceTheta = 0.84;
const clearancePhi = CUT_CENTER;
const headClearancePoint = ellipsoidPoint(
0.82,
0.94,
1.0,
clearanceTheta,
clearancePhi,
0.60
);
const linerClearancePoint = ellipsoidPoint(
1.18,
1.38,
0.72,
clearanceTheta,
clearancePhi
);
const clearanceLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
headClearancePoint,
linerClearancePoint
]),
new THREE.LineDashedMaterial({
color: 0xffc743,
dashSize: 0.075,
gapSize: 0.045,
transparent: true,
opacity: 0.98,
depthTest: false
})
);
clearanceLine.computeLineDistances();
clearanceLine.renderOrder = 8;
clearanceGroup.add(clearanceLine);
const clearanceDotMaterial = new THREE.MeshBasicMaterial({
color: 0xffc743,
depthTest: false
});
for (const point of [headClearancePoint, linerClearancePoint]) {
const dot = new THREE.Mesh(
new THREE.SphereGeometry(0.037, 16, 12),
clearanceDotMaterial
);
dot.position.copy(point);
dot.renderOrder = 9;
clearanceGroup.add(dot);
}
scene.add(clearanceGroup);
// ------------------------------------------------------------
// Direct camera controls: drag, wheel, and pinch
// ------------------------------------------------------------
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
controls.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (controls.pointers.size === 1) {
controls.dragging = true;
controls.previousX = event.clientX;
controls.previousY = event.clientY;
} else if (controls.pointers.size === 2) {
const points = [...controls.pointers.values()];
controls.pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.pointers.has(event.pointerId)) return;
controls.pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (controls.pointers.size === 2) {
const points = [...controls.pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (controls.pinchDistance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * (controls.pinchDistance / distance),
4.5,
11
);
updateCamera();
}
controls.pinchDistance = distance;
return;
}
if (!controls.dragging) return;
const deltaX = event.clientX - controls.previousX;
const deltaY = event.clientY - controls.previousY;
controls.azimuth -= deltaX * 0.007;
controls.polar = THREE.MathUtils.clamp(
controls.polar + deltaY * 0.006,
0.38,
1.48
);
controls.previousX = event.clientX;
controls.previousY = event.clientY;
updateCamera();
});
function releasePointer(event) {
controls.pointers.delete(event.pointerId);
if (controls.pointers.size < 2) {
controls.pinchDistance = 0;
}
if (controls.pointers.size === 0) {
controls.dragging = false;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
4.5,
11
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
document.querySelector("#reset").addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Layer controls
// ------------------------------------------------------------
const layerObjects = {
shell: shellGroup,
liner: linerGroup,
straps: strapGroup,
head: headGroup,
clearance: clearanceGroup
};
const layerCallouts = {
shell: document.querySelector("#callout-shell"),
liner: document.querySelector("#callout-liner"),
straps: document.querySelector("#callout-straps"),
clearance: document.querySelector("#callout-clearance")
};
document.querySelectorAll("[data-layer]").forEach((button) => {
button.addEventListener("click", () => {
const layer = button.dataset.layer;
const visible = !layerObjects[layer].visible;
layerObjects[layer].visible = visible;
button.setAttribute("aria-pressed", String(visible));
if (layerCallouts[layer]) {
layerCallouts[layer].style.opacity = visible ? "1" : "0";
}
});
});
// ------------------------------------------------------------
// Projected HTML callouts
// ------------------------------------------------------------
const strapAnchorCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(1.29, 0.46, 0),
new THREE.Vector3(1.08, 0.10, -0.04),
new THREE.Vector3(0.41, -0.06, 0.55)
]
);
const calloutData = [
{
element: layerCallouts.shell,
anchor: ellipsoidPoint(1.50, 1.72, 1.05, 0.69, -0.78),
offset: [-94, -30],
layer: "shell"
},
{
element: layerCallouts.liner,
anchor: ellipsoidPoint(1.39, 1.60, 0.93, 1.19, CUT_CENTER),
offset: [104, 5],
layer: "liner"
},
{
element: layerCallouts.straps,
anchor: strapAnchorCurve.getPoint(0.43),
offset: [100, 38],
layer: "straps"
},
{
element: layerCallouts.clearance,
anchor: headClearancePoint.clone().lerp(linerClearancePoint, 0.56),
offset: [-100, -42],
layer: "clearance"
}
];
function updateCallouts() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const callout of calloutData) {
const projected = callout.anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
layerObjects[callout.layer].visible;
callout.element.style.display = visible ? "flex" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * width + callout.offset[0];
const y = (-projected.y * 0.5 + 0.5) * height + callout.offset[1];
callout.element.style.left = `${x}px`;
callout.element.style.top = `${y}px`;
}
}
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
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);
}
window.addEventListener("resize", resize);
resize();
function animate() {
renderer.render(scene, camera);
updateCallouts();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```