Prompt specification
Build or customize the Three.js 3D scene "Fiber-reinforced material cross 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: Fiber-reinforced material cross section
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/fiber-reinforced-material-cross-section-x1937
Scene Description Prompt:
An exploded composite cutaway exposes continuous reinforcing fibers inside a contrasting matrix. Single HTML file with Three.js from cdnjs.
Working Three.js Starter (fiber-reinforced-material-cross-section-x1937):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Continuous Composite — Exploded Cutaway</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: rgba(9, 19, 29, 0.78);
--line: rgba(160, 195, 220, 0.18);
--text: #e8f1f7;
--muted: #8194a5;
--orange: #ffad4d;
--cyan: #79d8ff;
}
* {
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;
display: block;
width: 100%;
height: 100%;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.frame-corner {
position: fixed;
z-index: 2;
width: 44px;
height: 44px;
pointer-events: none;
opacity: 0.42;
}
.frame-corner::before,
.frame-corner::after {
content: "";
position: absolute;
background: var(--cyan);
}
.frame-corner::before {
width: 44px;
height: 1px;
}
.frame-corner::after {
width: 1px;
height: 44px;
}
.frame-corner.tl {
top: 18px;
left: 18px;
}
.frame-corner.tr {
top: 18px;
right: 18px;
transform: rotate(90deg);
}
.frame-corner.br {
bottom: 18px;
right: 18px;
transform: rotate(180deg);
}
.frame-corner.bl {
bottom: 18px;
left: 18px;
transform: rotate(270deg);
}
.title-block {
position: fixed;
z-index: 4;
top: 32px;
left: 36px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--orange);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.25em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 2px;
background: var(--orange);
box-shadow: 0 0 12px rgba(255, 173, 77, 0.65);
}
h1 {
margin: 0;
font-size: clamp(25px, 3.2vw, 46px);
font-weight: 300;
letter-spacing: 0.08em;
line-height: 1;
text-transform: uppercase;
}
.subtitle {
margin-top: 13px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.spec-tag {
position: fixed;
z-index: 4;
top: 34px;
right: 38px;
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.17em;
text-transform: uppercase;
pointer-events: none;
}
.spec-tag .signal {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
.legend {
position: fixed;
z-index: 4;
left: 36px;
bottom: 34px;
display: grid;
gap: 11px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 11px;
color: #aebdca;
font-size: 10px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.swatch {
width: 27px;
height: 3px;
border-radius: 3px;
background: linear-gradient(
90deg,
#16232d,
#526d82,
#0e171f
);
box-shadow: 0 0 7px rgba(83, 122, 151, 0.45);
}
.swatch.matrix {
background: linear-gradient(
90deg,
rgba(255, 173, 77, 0.25),
#ffad4d,
rgba(255, 173, 77, 0.28)
);
box-shadow: 0 0 8px rgba(255, 173, 77, 0.35);
}
.control-panel {
position: fixed;
z-index: 5;
right: 34px;
bottom: 30px;
width: min(290px, calc(100vw - 40px));
padding: 18px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(14px);
}
.control-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 17px;
color: #c9d6df;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.17em;
text-transform: uppercase;
}
#explodeValue {
color: var(--orange);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 3px;
margin: 0;
border-radius: 4px;
appearance: none;
background: linear-gradient(
90deg,
var(--orange) 0%,
var(--orange) 78%,
#253544 78%,
#253544 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
border: 2px solid #101c25;
border-radius: 50%;
appearance: none;
background: var(--orange);
box-shadow: 0 0 0 1px var(--orange), 0 0 12px rgba(255, 173, 77, 0.45);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #101c25;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 0 1px var(--orange);
}
.control-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 17px;
}
button {
min-height: 34px;
border: 1px solid rgba(151, 187, 211, 0.2);
border-radius: 3px;
background: rgba(22, 38, 50, 0.58);
color: #9eb0bf;
font: inherit;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.13em;
text-transform: uppercase;
cursor: pointer;
transition: border-color 160ms, color 160ms, background 160ms;
}
button:hover,
button.active {
border-color: rgba(121, 216, 255, 0.52);
background: rgba(39, 74, 95, 0.44);
color: var(--cyan);
}
.help {
position: fixed;
z-index: 4;
bottom: 36px;
left: 50%;
transform: translateX(-50%);
color: rgba(158, 179, 194, 0.62);
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
white-space: nowrap;
}
.annotation {
position: fixed;
z-index: 3;
display: flex;
align-items: center;
gap: 9px;
min-width: max-content;
color: #dce8f0;
font-size: 9px;
font-weight: 600;
letter-spacing: 0.14em;
text-transform: uppercase;
pointer-events: none;
transform: translateY(-50%);
transition: opacity 120ms;
text-shadow: 0 2px 8px #000;
}
.annotation::before {
content: "";
width: 24px;
height: 1px;
background: rgba(121, 216, 255, 0.55);
}
.annotation::after {
content: "";
position: absolute;
left: -25px;
width: 4px;
height: 4px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 8px var(--cyan);
}
.annotation.matrix::before {
background: rgba(255, 173, 77, 0.6);
}
.annotation.matrix::after {
background: var(--orange);
box-shadow: 0 0 8px var(--orange);
}
.annotation small {
display: block;
margin-top: 4px;
color: #748896;
font-size: 7px;
font-weight: 500;
letter-spacing: 0.12em;
}
#loader {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #071018;
transition: opacity 700ms ease, visibility 700ms;
}
#loader.hidden {
visibility: hidden;
opacity: 0;
}
.loader-inner {
width: min(320px, 70vw);
color: var(--muted);
font-size: 10px;
letter-spacing: 0.2em;
text-align: center;
text-transform: uppercase;
}
.loader-line {
position: relative;
height: 1px;
margin-top: 16px;
overflow: hidden;
background: #1b2b37;
}
.loader-line::after {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(
90deg,
transparent,
var(--orange),
transparent
);
animation: scan 1.1s linear infinite;
}
@keyframes scan {
from {
transform: translateX(-100%);
}
to {
transform: translateX(100%);
}
}
@media (max-width: 760px) {
.title-block {
top: 24px;
left: 22px;
}
.spec-tag,
.help,
.annotation {
display: none;
}
.legend {
left: 22px;
bottom: 152px;
}
.control-panel {
right: 20px;
bottom: 20px;
left: 20px;
width: auto;
}
.frame-corner {
transform: scale(0.75);
}
.frame-corner.tr,
.frame-corner.br {
transform: rotate(90deg) scale(0.75);
}
.frame-corner.bl {
transform: rotate(270deg) scale(0.75);
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive exploded composite cutaway"></canvas>
<div class="frame-corner tl"></div>
<div class="frame-corner tr"></div>
<div class="frame-corner br"></div>
<div class="frame-corner bl"></div>
<header class="title-block">
<div class="eyebrow">Material study / 01</div>
<h1>Continuous<br />Composite</h1>
<div class="subtitle">Reinforced architecture / exploded cutaway</div>
</header>
<div class="spec-tag">
<span class="signal"></span>
Live technical model
</div>
<div class="legend">
<div class="legend-item">
<span class="swatch"></span>
Continuous carbon reinforcement
</div>
<div class="legend-item">
<span class="swatch matrix"></span>
Contrasting amber resin matrix
</div>
</div>
<div class="annotation matrix" id="matrixLabel">
<span>Matrix shell<small>Expanded resin sector</small></span>
</div>
<div class="annotation" id="fiberLabel">
<span>Continuous tow<small>Unbroken longitudinal fiber</small></span>
</div>
<div class="annotation" id="hoopLabel">
<span>Wrap hoop<small>Circumferential reinforcement</small></span>
</div>
<div class="annotation" id="dimensionLabel">
<span>Continuous span<small>Longitudinal reinforcement axis</small></span>
</div>
<section class="control-panel" aria-label="Scene controls">
<div class="control-head">
<span>Exploded separation</span>
<span id="explodeValue">78%</span>
</div>
<input
id="explode"
type="range"
min="0"
max="100"
value="78"
aria-label="Exploded separation"
/>
<div class="control-buttons">
<button id="autoOrbit" type="button">Auto orbit</button>
<button id="resetView" type="button">Reset view</button>
</div>
</section>
<div class="help">Drag to orbit · Wheel to zoom · Shift-drag to pan</div>
<div id="loader">
<div class="loader-inner">
Assembling composite specimen
<div class="loader-line"></div>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const loader = document.getElementById("loader");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.Fog(0x071018, 12, 28);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const controls = {
theta: 0.64,
phi: 1.10,
radius: 10.8,
target: new THREE.Vector3(0, -0.05, 0),
dragging: null,
lastX: 0,
lastY: 0,
autoOrbit: false
};
const spherical = new THREE.Spherical();
function updateCamera() {
spherical.set(
controls.radius,
THREE.MathUtils.clamp(controls.phi, 0.28, Math.PI - 0.28),
controls.theta
);
camera.position.setFromSpherical(spherical).add(controls.target);
camera.lookAt(controls.target);
}
updateCamera();
// Lighting
scene.add(new THREE.AmbientLight(0xffffff, 0.24));
const hemisphere = new THREE.HemisphereLight(
0xb8dcff,
0x20140e,
1.55
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffd3a2, 3.2);
keyLight.position.set(5.5, 7.5, 6.5);
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x5caeff, 2.0);
fillLight.position.set(-6, 2.5, -4.5);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0x70d9ff, 26, 14, 2);
rimLight.position.set(3.5, 1.2, -4.5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff9d3e, 22, 10, 2);
warmLight.position.set(-3.5, 3.5, 3.5);
scene.add(warmLight);
// Presentation platform
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x0a1720,
roughness: 0.72,
metalness: 0.25
});
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(5.35, 5.55, 0.18, 96),
platformMaterial
);
platform.position.y = -1.79;
platform.receiveShadow = true;
scene.add(platform);
const grid = new THREE.GridHelper(
10.6,
22,
0x31546a,
0x193340
);
grid.position.y = -1.685;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0x41728c,
transparent: true,
opacity: 0.24
});
[3.45, 4.55, 5.15].forEach((radius, index) => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.008, 4, 128),
ringMaterial.clone()
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -1.675 + index * 0.002;
ring.material.opacity = 0.24 - index * 0.045;
scene.add(ring);
});
// Soft contact shadow generated locally.
function createShadowTexture() {
const shadowCanvas = document.createElement("canvas");
shadowCanvas.width = 256;
shadowCanvas.height = 128;
const context = shadowCanvas.getContext("2d");
const gradient = context.createRadialGradient(
128,
64,
4,
128,
64,
120
);
gradient.addColorStop(0, "rgba(0,0,0,0.62)");
gradient.addColorStop(0.5, "rgba(0,0,0,0.27)");
gradient.addColorStop(1, "rgba(0,0,0,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 256, 128);
const texture = new THREE.CanvasTexture(shadowCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const contactShadow = new THREE.Mesh(
new THREE.PlaneGeometry(8.4, 4.5),
new THREE.MeshBasicMaterial({
map: createShadowTexture(),
transparent: true,
depthWrite: false,
opacity: 0.72
})
);
contactShadow.rotation.x = -Math.PI / 2;
contactShadow.position.y = -1.67;
scene.add(contactShadow);
const specimen = new THREE.Group();
scene.add(specimen);
/*
* Creates a closed annular sector.
* Local X is the specimen axis; the sector is centered around local Y.
*/
function createAnnularSectorGeometry(
innerRadius,
outerRadius,
length,
startAngle,
endAngle,
segments = 40
) {
const positions = [];
const normals = [];
const uvs = [];
const indices = [];
const halfLength = length * 0.5;
function vertex(x, radius, angle, normal, u, v) {
const index = positions.length / 3;
positions.push(
x,
radius * Math.cos(angle),
radius * Math.sin(angle)
);
normals.push(normal.x, normal.y, normal.z);
uvs.push(u, v);
return index;
}
const xValues = [-halfLength, halfLength];
// Smooth outer wall.
const outerStart = positions.length / 3;
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const angle = THREE.MathUtils.lerp(startAngle, endAngle, t);
const normal = new THREE.Vector3(
0,
Math.cos(angle),
Math.sin(angle)
);
for (let j = 0; j < 2; j++) {
vertex(
xValues[j],
outerRadius,
angle,
normal,
j,
t
);
}
}
for (let i = 0; i < segments; i++) {
const a = outerStart + i * 2;
const b = outerStart + (i + 1) * 2;
const c = b + 1;
const d = a + 1;
indices.push(a, b, c, b, c, d);
}
// Smooth inner wall.
const innerStart = positions.length / 3;
for (let i = 0; i <= segments; i++) {
const t = i / 3;
const angle = THREE.MathUtils.lerp(startAngle, endAngle, t);
const normal = new THREE.Vector3(
0,
-Math.cos(angle),
-Math.sin(angle)
);
for (let j = 0; j < 2; j++) {
vertex(
xValues[j],
innerRadius,
angle,
normal,
j,
t
);
}
}
for (let i = 0; i < segments; i++) {
const a = innerStart + i * 2;
const b = innerStart + (i + 1) * 2;
const c = b + 1;
const d = a + 1;
indices.push(a, c, b, b, c, d);
}
// End caps.
[-halfLength, halfLength].forEach((x, endIndex) => {
const normal = new THREE.Vector3(endIndex === 0 ? -1 : 1, 0, 0);
for (let i = 0; i < segments; i++) {
const t0 = i / segments;
const t1 = (i + 1) / segments;
const angle0 = THREE.MathUtils.lerp(startAngle, endAngle, t0);
const angle1 = THREE.MathUtils.lerp(startAngle, endAngle, t1);
const a = vertex(
x,
innerRadius,
angle0,
normal,
t0,
0
);
const b = vertex(
x,
outerRadius,
angle0,
normal,
t0,
1
);
const c = vertex(
x,
outerRadius,
angle1,
normal,
t1,
1
);
const d = vertex(
x,
innerRadius,
angle1,
normal,
t1,
0
);
if (endIndex === 0) {
indices.push(a, c, b, a, d, c);
} else {
indices.push(a, b, c, a, c, d);
}
}
});
// Radial cut faces.
[startAngle, endAngle].forEach((angle, edgeIndex) => {
const tangent = new THREE.Vector3(
0,
-Math.sin(angle),
Math.cos(angle)
);
const normal = edgeIndex === 0
? tangent.clone().multiplyScalar(-1)
: tangent.clone();
const a = vertex(
-halfLength,
innerRadius,
angle,
normal,
0,
0
);
const b = vertex(
halfLength,
innerRadius,
angle,
normal,
1,
0
);
const c = vertex(
halfLength,
outerRadius,
angle,
normal,
1,
1
);
const d = vertex(
-halfLength,
outerRadius,
angle,
normal,
0,
1
);
indices.push(a, b, c, a, c, d);
});
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"normal",
new THREE.Float32BufferAttribute(normals, 3)
);
geometry.setAttribute(
"uv",
new THREE.Float32BufferAttribute(uvs, 2)
);
geometry.setIndex(indices);
geometry.computeBoundingSphere();
return geometry;
}
const innerRadius = 1.04;
const outerRadius = 1.56;
const specimenLength = 6.0;
const matrixBaseMaterial = new THREE.MeshPhysicalMaterial({
color: 0xffa33d,
roughness: 0.27,
metalness: 0.02,
clearcoat: 0.78,
clearcoatRoughness: 0.22,
transmission: 0.08,
thickness: 0.35,
ior: 1.46,
transparent: true,
opacity: 0.62,
depthWrite: false,
side: THREE.DoubleSide
});
const edgeBaseMaterial = new THREE.LineBasicMaterial({
color: 0xffd18c,
transparent: true,
opacity: 0.45,
depthWrite: false
});
const sectorSpecs = [
{ start: -18, end: 72, distance: 2.25, opacity: 0.74 },
{ start: 72, end: 162, distance: 1.55, opacity: 0.61 },
{ start: 162, end: 252, distance: 0.38, opacity: 0.37 },
{ start: 252, end: 342, distance: 0.62, opacity: 0.43 }
];
const sectors = sectorSpecs.map((spec) => {
const group = new THREE.Group();
const midpoint = THREE.MathUtils.degToRad((spec.start + spec.end) * 0.5);
const geometry = createAnnularSectorGeometry(
innerRadius,
outerRadius,
specimenLength,
THREE.MathUtils.degToRad(spec.start),
THREE.MathUtils.degToRad(spec.end)
);
const material = matrixBaseMaterial.clone();
material.opacity = spec.opacity;
const mesh = new THREE.Mesh(geometry, material);
mesh.renderOrder = 3;
group.add(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 28),
edgeBaseMaterial.clone()
);
edges.material.opacity = 0.52;
edges.renderOrder = 5;
group.add(edges);
const direction = new THREE.Vector3(
0,
Math.cos(midpoint),
Math.sin(midpoint)
);
const arrow = new THREE.ArrowHelper(
direction,
direction.clone().multiplyScalar(outerRadius),
0,
0xffad4d,
0.13,
0.065
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.34;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.46;
arrow.visible = false;
scene.add(arrow);
specimen.add(group);
return {
...spec,
group,
mesh,
direction,
arrow,
midpoint
};
});
/*
* Continuous longitudinal fiber paths.
* Alternating fibers introduce a gentle crossed/helical architecture.
*/
class FiberCurve extends THREE.Curve {
constructor(baseAngle, turns, radius, length) {
super();
this.baseAngle = baseAngle;
this.turns = turns;
this.radius = radius;
this.length = length;
}
getPoint(t, target = new THREE.Vector3()) {
const angle =
this.baseAngle + t * this.turns * Math.PI * 2;
const x = -this.length * 0.5 + t * this.length;
const radius =
this.radius +
0.012 *
Math.sin(t * Math.PI * 8 + this.baseAngle * 2);
return target.set(
x,
radius * Math.cos(angle),
radius * Math.sin(angle)
);
}
}
const fiberGroup = new THREE.Group();
specimen.add(fiberGroup);
const graphiteFiber = new THREE.MeshPhysicalMaterial({
color: 0x17222c,
metalness: 0.72,
roughness: 0.27,
clearcoat: 0.36,
clearcoatRoughness: 0.26
});
const blueFiber = new THREE.MeshPhysicalMaterial({
color: 0x334d61,
metalness: 0.66,
roughness: 0.3,
clearcoat: 0.28
});
const silverFiber = new THREE.MeshPhysicalMaterial({
color: 0x8b9ca7,
metalness: 0.78,
roughness: 0.23,
clearcoat: 0.3
});
const fiberCurves = [];
const fiberCount = 64;
for (let i = 0; i < fiberCount; i++) {
const baseAngle = (i / fiberCount) * Math.PI * 2;
const turns =
(i % 5 === 0 ? 0.42 : 0.045) *
(i % 2 === 0 ? 1 : -1);
const radius = 1.12 + (i % 3) * 0.025;
const curve = new FiberCurve(
baseAngle,
turns,
radius,
specimenLength
);
fiberCurves.push(curve);
const prominent = i % 9 === 0;
const tubeRadius = prominent ? 0.017 : 0.0085;
const geometry = new THREE.TubeGeometry(
curve,
prominent ? 76 : 58,
tubeRadius,
prominent ? 6 : 5,
false
);
let material = graphiteFiber;
if (i % 7 === 0) material = blueFiber;
if (prominent && i % 18 === 0) material = silverFiber;
const fiber = new THREE.Mesh(geometry, material);
fiber.castShadow = true;
fiberGroup.add(fiber);
}
// Circumferential wrap fibers.
const hoopMaterial = new THREE.MeshPhysicalMaterial({
color: 0x263c4e,
metalness: 0.7,
roughness: 0.29,
clearcoat: 0.24
});
for (let i = 0; i < 11; i++) {
const x = -2.82 + i * 0.564;
const hoop = new THREE.Mesh(
new THREE.TorusGeometry(1.18, 0.0115, 6, 112),
hoopMaterial
);
hoop.rotation.y = Math.PI / 2;
hoop.position.x = x;
hoop.castShadow = true;
fiberGroup.add(hoop);
}
// Visible cut fiber ends.
const endpointGeometry = new THREE.SphereGeometry(0.016, 7, 5);
const endpointMaterial = new THREE.MeshStandardMaterial({
color: 0x6f8797,
metalness: 0.72,
roughness: 0.28
});
const endpoints = new THREE.InstancedMesh(
endpointGeometry,
endpointMaterial,
fiberCount * 2
);
const endpointDummy = new THREE.Object3D();
fiberCurves.forEach((curve, index) => {
const start = curve.getPoint(0);
const end = curve.getPoint(1);
endpointDummy.position.copy(start);
endpointDummy.scale.setScalar(index % 9 === 0 ? 1.45 : 1);
endpointDummy.updateMatrix();
endpoints.setMatrixAt(index * 2, endpointDummy.matrix);
endpointDummy.position.copy(end);
endpointDummy.scale.setScalar(index % 9 === 0 ? 1.45 : 1);
endpointDummy.updateMatrix();
endpoints.setMatrixAt(index * 2 + 1, endpointDummy.matrix);
});
endpoints.instanceMatrix.needsUpdate = true;
specimen.add(endpoints);
// Section boundary highlights.
[-3.01, 3.01].forEach((x, index) => {
const boundary = new THREE.Mesh(
new THREE.TorusGeometry(outerRadius + 0.006, 0.012, 6, 128),
new THREE.MeshBasicMaterial({
color: index === 1 ? 0xffbd66 : 0x6f99ad,
transparent: true,
opacity: index === 1 ? 0.7 : 0.32
})
);
boundary.rotation.y = Math.PI / 2;
boundary.position.x = x;
specimen.add(boundary);
});
// Subtle longitudinal center axis.
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-3.45, 0, 0),
new THREE.Vector3(3.45, 0, 0)
]);
const axis = new THREE.Line(
axisGeometry,
new THREE.LineDashedMaterial({
color: 0x79d8ff,
transparent: true,
opacity: 0.2,
dashSize: 0.08,
gapSize: 0.07
})
);
axis.computeLineDistances();
specimen.add(axis);
// Technical span dimension.
const dimensionPoints = [
new THREE.Vector3(-3.55, -1.48, 1.76),
new THREE.Vector3(3.55, -1.48, 1.76),
new THREE.Vector3(-3.55, -1.61, 1.76),
new THREE.Vector3(-3.55, -1.35, 1.76),
new THREE.Vector3(3.55, -1.61, 1.76),
new THREE.Vector3(3.55, -1.35, 1.76),
new THREE.Vector3(0, -1.48, 1.76),
new THREE.Vector3(0, -1.59, 1.76)
];
const dimensionGeometry = new THREE.BufferGeometry().setFromPoints(
dimensionPoints
);
const dimensionLines = new THREE.LineSegments(
dimensionGeometry,
new THREE.LineBasicMaterial({
color: 0x60879d,
transparent: true,
opacity: 0.36
})
);
scene.add(dimensionLines);
// Sparse technical particles in the background.
const particlePositions = [];
for (let i = 0; i < 380; i++) {
const radius = 8 + Math.random() * 12;
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
particlePositions.push(
radius * Math.sin(phi) * Math.cos(theta),
radius * Math.cos(phi),
radius * Math.sin(phi) * Math.sin(theta)
);
}
const particleGeometry = new THREE.BufferGeometry();
particleGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(particlePositions, 3)
);
const particles = new THREE.Points(
particleGeometry,
new THREE.PointsMaterial({
color: 0x80a7bd,
size: 0.018,
transparent: true,
opacity: 0.34,
depthWrite: false
})
);
scene.add(particles);
// UI
const explodeInput = document.getElementById("explode");
const explodeValue = document.getElementById("explodeValue");
const autoOrbitButton = document.getElementById("autoOrbit");
const resetButton = document.getElementById("resetView");
let desiredExplosion = Number(explodeInput.value) / 100;
function updateRangeBackground() {
const percent = Number(explodeInput.value);
explodeInput.style.background = `
linear-gradient(
90deg,
var(--orange) 0%,
var(--orange) ${percent}%,
#253544 ${percent}%,
#253544 100%
)
`;
}
updateRangeBackground();
explodeInput.addEventListener("input", () => {
desiredExplosion = Number(explodeInput.value) / 100;
explodeValue.textContent = `${explodeInput.value}%`;
updateRangeBackground();
});
autoOrbitButton.addEventListener("click", () => {
controls.autoOrbit = !controls.autoOrbit;
autoOrbitButton.classList.toggle("active", controls.autoOrbit);
autoOrbitButton.textContent = controls.autoOrbit
? "Orbit on"
: "Auto orbit";
});
resetButton.addEventListener("click", () => {
controls.theta = 0.64;
controls.phi = 1.10;
controls.radius =
window.innerWidth / window.innerHeight < 0.8 ? 13.2 : 10.8;
controls.target.set(0, -0.05, 0);
});
// Custom orbit / pan / zoom controls.
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = event.shiftKey || event.button === 2
? "pan"
: "orbit";
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
if (controls.dragging === "orbit") {
controls.theta -= dx * 0.0052;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.0052,
0.28,
Math.PI - 0.28
);
} else {
camera.updateMatrixWorld();
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(
camera.quaternion
);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(
camera.quaternion
);
const amount = controls.radius * 0.00135;
controls.target
.addScaledVector(right, -dx * amount)
.addScaledVector(up, dy * amount);
}
});
function endPointer(event) {
controls.dragging = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
6.3,
18
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
controls.theta = 0.64;
controls.phi = 1.10;
controls.radius =
window.innerWidth / window.innerHeight < 0.8 ? 13.2 : 10.8;
controls.target.set(0, -0.05, 0);
});
// Projected DOM annotations.
const labels = {
matrix: document.getElementById("matrixLabel"),
fiber: document.getElementById("fiberLabel"),
hoop: document.getElementById("hoopLabel"),
dimension: document.getElementById("dimensionLabel")
};
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, offsetX, offsetY) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
element.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth + offsetX}px`;
element.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight + offsetY}px`;
}
const matrixAnchor = new THREE.Vector3();
const fiberAnchor = new THREE.Vector3(1.65, 1.12, 0.42);
const hoopAnchor = new THREE.Vector3(-2.28, 0.0, 1.18);
const dimensionAnchor = new THREE.Vector3(0, -1.48, 1.76);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.fov = width / height < 0.8 ? 52 : 38;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-dt * 5.2);
if (controls.autoOrbit && !controls.dragging) {
controls.theta -= dt * 0.13;
}
sectors.forEach((sector) => {
const desiredPosition = sector.direction
.clone()
.multiplyScalar(sector.distance * desiredExplosion);
sector.group.position.lerp(desiredPosition, smoothing);
const separation = sector.group.position.length();
sector.arrow.visible = separation > 0.06;
sector.arrow.setLength(
separation,
Math.min(0.16, separation * 0.2),
Math.min(0.075, separation * 0.1)
);
});
updateCamera();
specimen.updateMatrixWorld(true);
const primarySector = sectors[0];
matrixAnchor.set(
0,
outerRadius * Math.cos(primarySector.midpoint),
outerRadius * Math.sin(primarySector.midpoint)
);
primarySector.group.localToWorld(matrixAnchor);
placeLabel(labels.matrix, matrixAnchor, 20, -42);
placeLabel(labels.fiber, fiberAnchor, 22, -28);
placeLabel(labels.hoop, hoopAnchor, -124, 22);
placeLabel(labels.dimension, dimensionAnchor, -10, 29);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => {
loader.classList.add("hidden");
});
}
}
animate();
</script>
</body>
</html>
```