Prompt specification
Build or customize the Three.js 3D scene "Bicycle frame material teaching studio" 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: Bicycle frame material teaching studio
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bicycle-frame-material-teaching-studio-x1939
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: bicycle frame material teaching studio. Compose a generic frame section beside laminate layers and load-direction arrows; explain orientation-dependent design conceptually without claiming a particular product's construction or safety rating.
Working Three.js Starter (bicycle-frame-material-teaching-studio-x1939):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Bicycle Frame Materials Studio</title>
<style>
:root {
--ink: #142326;
--muted: #536166;
--paper: #eeeae1;
--panel: rgba(248, 245, 237, 0.92);
--line: rgba(20, 35, 38, 0.16);
--teal: #145d63;
--coral: #df654d;
--gold: #d9a83d;
--blue: #2c628c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ddd8cd;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.masthead {
position: fixed;
z-index: 10;
top: 28px;
left: 30px;
max-width: min(560px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 9px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 25px;
height: 4px;
content: "";
background: var(--coral);
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 58px);
font-weight: 780;
line-height: 0.95;
letter-spacing: -0.055em;
}
.subtitle {
max-width: 510px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.badges {
position: fixed;
z-index: 10;
top: 28px;
right: 28px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
pointer-events: none;
}
.badge {
padding: 7px 10px;
border: 1px solid rgba(20, 35, 38, 0.17);
border-radius: 999px;
background: rgba(248, 245, 237, 0.78);
backdrop-filter: blur(12px);
color: #3e4b4f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.panel {
position: fixed;
z-index: 12;
right: 28px;
bottom: 28px;
width: min(385px, calc(100vw - 56px));
overflow: hidden;
border: 1px solid rgba(20, 35, 38, 0.13);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 22px 65px rgba(33, 43, 43, 0.16);
backdrop-filter: blur(18px);
}
.panel::before {
display: block;
width: 100%;
height: 5px;
content: "";
background: linear-gradient(
90deg,
var(--coral) 0 33%,
var(--gold) 33% 66%,
var(--teal) 66% 100%
);
}
.panel-content {
padding: 20px 21px 18px;
}
.panel-kicker {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.reset {
padding: 0;
border: 0;
background: transparent;
color: var(--teal);
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.panel h2 {
margin: 0 0 9px;
font-size: 24px;
line-height: 1.05;
letter-spacing: -0.035em;
}
.panel p {
min-height: 76px;
margin: 0;
color: #536166;
font-size: 12px;
line-height: 1.58;
}
.views {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
margin-top: 16px;
}
.view {
min-height: 48px;
padding: 7px 4px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.38);
color: #59666a;
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
.view:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.8);
}
.view.active {
border-color: var(--ink);
background: var(--ink);
color: #fffdf7;
}
.panel-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
padding: 12px 21px;
border-top: 1px solid var(--line);
background: rgba(255, 255, 255, 0.25);
color: #59666a;
font-size: 10px;
}
.toggle {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
font-weight: 700;
white-space: nowrap;
}
.toggle input {
width: 14px;
height: 14px;
accent-color: var(--coral);
}
.disclaimer {
position: fixed;
z-index: 9;
left: 30px;
bottom: 27px;
width: min(510px, calc(100vw - 450px));
padding: 12px 14px;
border-left: 3px solid var(--coral);
background: rgba(244, 241, 233, 0.78);
backdrop-filter: blur(12px);
color: #4c595d;
font-size: 10px;
line-height: 1.5;
pointer-events: none;
}
.disclaimer strong {
color: var(--ink);
}
.legend {
position: fixed;
z-index: 9;
top: 104px;
left: 30px;
display: flex;
flex-wrap: wrap;
gap: 7px 13px;
width: 340px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: #536166;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.swatch {
width: 14px;
height: 6px;
border-radius: 1px;
}
.controls-hint {
position: fixed;
z-index: 8;
top: 50%;
right: 25px;
color: rgba(20, 35, 38, 0.56);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
writing-mode: vertical-rl;
pointer-events: none;
}
#fallback {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
padding: 30px;
background: #eeeae1;
color: var(--ink);
text-align: center;
}
#fallback[hidden] {
display: none;
}
@media (max-width: 800px) {
.masthead {
top: 18px;
left: 18px;
}
h1 {
font-size: 34px;
}
.subtitle {
max-width: 390px;
font-size: 11px;
}
.badges,
.legend,
.controls-hint {
display: none;
}
.panel {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
}
.panel-content {
padding: 15px 16px 13px;
}
.panel h2 {
font-size: 20px;
}
.panel p {
min-height: 0;
font-size: 11px;
}
.views {
margin-top: 12px;
}
.panel-footer {
padding: 9px 16px;
}
.disclaimer {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
transition: none !important;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel teaching scene showing a generic bicycle frame tube, separated laminate orientations, and conceptual load arrows."
></canvas>
<header class="masthead">
<div class="eyebrow">Voxel materials teaching studio / 01</div>
<h1>Frame / Fiber<br />Orientation</h1>
<p class="subtitle">
A conceptual study of how material direction relates to a generic
bicycle-frame tube and different local load paths.
</p>
</header>
<div class="badges">
<div class="badge">Generic section</div>
<div class="badge">Conceptual only</div>
<div class="badge">No product specification</div>
</div>
<div class="legend" aria-hidden="true">
<div class="legend-item">
<span class="swatch" style="background:#145d63"></span>
Frame envelope
</div>
<div class="legend-item">
<span class="swatch" style="background:#df654d"></span>
Axial load
</div>
<div class="legend-item">
<span class="swatch" style="background:#6655b8"></span>
Transverse load
</div>
<div class="legend-item">
<span class="swatch" style="background:#d9a83d"></span>
Radial / hoop load
</div>
</div>
<aside class="panel" aria-label="Concept explanation and scene views">
<div class="panel-content">
<div class="panel-kicker">
<span>Concept map</span>
<button class="reset" id="reset" type="button">Reset view</button>
</div>
<div aria-live="polite">
<h2 id="conceptTitle">Direction changes the response.</h2>
<p id="conceptCopy">
A generic composite tube is locally directional: fibers carry load
most effectively along their own axis. The design question is how
ply angles align with local axial, bending, torsion, and radial
demands—not which layer is simply “strongest.”
</p>
</div>
<nav class="views" aria-label="Select a conceptual view">
<button class="view active" data-view="overview" type="button">
Overview
</button>
<button class="view" data-view="section" type="button">
Section
</button>
<button class="view" data-view="layers" type="button">
Layers
</button>
<button class="view" data-view="loads" type="button">
Loads
</button>
</nav>
</div>
<div class="panel-footer">
<label class="toggle">
<input id="arrowsToggle" type="checkbox" checked />
Show load vectors
</label>
<span>Drag: orbit · Wheel/pinch: zoom</span>
</div>
</aside>
<div class="disclaimer">
<strong>Teaching model only.</strong>
The geometry, laminate proportions, and arrows are illustrative. This is
not a product construction claim, engineering analysis, material
specification, or safety rating.
</div>
<div class="controls-hint" aria-hidden="true">
Drag to orbit · wheel to zoom · double-click to reset
</div>
<div id="fallback" hidden>
<div>
<h2>WebGL is unavailable.</h2>
<p>This interactive teaching scene requires a browser with WebGL enabled.</p>
</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.querySelector("#scene");
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance",
});
} catch (error) {
document.querySelector("#fallback").hidden = false;
throw error;
}
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xded9ce);
scene.fog = new THREE.Fog(0xded9ce, 20, 38);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const hemi = new THREE.HemisphereLight(0xfff7e8, 0x536064, 2.2);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff9ee, 3.8);
key.position.set(6, 11, 8);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -12;
key.shadow.camera.right = 12;
key.shadow.camera.top = 12;
key.shadow.camera.bottom = -12;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 35;
key.shadow.bias = -0.00025;
scene.add(key);
const fill = new THREE.DirectionalLight(0x9fc8d0, 1.4);
fill.position.set(-8, 5, -7);
scene.add(fill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0xd4cfc3,
roughness: 0.96,
metalness: 0,
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.01;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(36, 36, 0x7b8987, 0xa8aaa2);
grid.position.y = 0.006;
grid.material.transparent = true;
grid.material.opacity = 0.23;
scene.add(grid);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0,
...options,
});
}
function addEdges(mesh, color = 0x233437, opacity = 0.18) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
})
);
edges.position.copy(mesh.position);
edges.rotation.copy(mesh.rotation);
edges.scale.copy(mesh.scale);
mesh.parent?.add(edges);
return edges;
}
function outlinedBox(width, height, depth, color, x, y, z) {
const group = new THREE.Group();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
standardMaterial(color)
);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color: 0x26383a,
transparent: true,
opacity: 0.17,
})
);
group.add(edges);
group.position.set(x, y, z);
scene.add(group);
return group;
}
function dashedLine(points, color = 0x596a6c, opacity = 0.5) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((p) => new THREE.Vector3(...p))
);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color,
dashSize: 0.12,
gapSize: 0.09,
transparent: true,
opacity,
})
);
line.computeLineDistances();
scene.add(line);
return line;
}
function roundedRect(ctx, x, y, w, h, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + w - radius, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + radius);
ctx.lineTo(x + w, y + h - radius);
ctx.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);
ctx.lineTo(x + radius, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function makeLabel(text, accent = "#df654d", compact = false) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 640;
labelCanvas.height = 112;
const ctx = labelCanvas.getContext("2d");
roundedRect(ctx, 3, 3, 634, 106, 18);
ctx.fillStyle = "rgba(17, 29, 32, 0.94)";
ctx.fill();
ctx.fillStyle = accent;
roundedRect(ctx, 3, 3, 13, 106, 6);
ctx.fill();
ctx.fillStyle = "#fffdf6";
ctx.font = `800 ${compact ? 31 : 35}px Inter, system-ui, sans-serif`;
ctx.textBaseline = "middle";
ctx.fillText(text, 32, 57);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
})
);
if (compact) {
sprite.scale.set(1.75, 0.305, 1);
} else {
sprite.scale.set(3.25, 0.57, 1);
}
return sprite;
}
// ---------------------------------------------------------------------
// Display platforms
// ---------------------------------------------------------------------
outlinedBox(4.8, 0.28, 2.3, 0xb8b3a8, -2.45, 0.14, 0);
outlinedBox(4.0, 0.28, 2.25, 0xc4beb1, 2.2, 0.14, 0);
outlinedBox(0.52, 0.72, 0.72, 0x667477, -3.55, 0.64, 0);
outlinedBox(0.52, 0.72, 0.72, 0x667477, -1.3, 0.64, 0);
// ---------------------------------------------------------------------
// Generic hollow tube section, built from separated voxel blocks
// ---------------------------------------------------------------------
const frameRoot = new THREE.Group();
scene.add(frameRoot);
const frameCenterX = -2.45;
const frameCenterY = 1.58;
const frameLeft = -4.32;
const frameRight = -0.58;
const blockCount = 16;
const blockStep = 0.235;
const voxelSize = 0.215;
const shellGeometry = new THREE.BoxGeometry(
voxelSize,
voxelSize,
voxelSize
);
const shellMaterial = standardMaterial(0x145d63);
const shell = new THREE.InstancedMesh(
shellGeometry,
shellMaterial,
blockCount * 4
);
shell.castShadow = true;
shell.receiveShadow = true;
const shellCorners = [
[-0.42, -0.42],
[-0.42, 0.42],
[0.42, -0.42],
[0.42, 0.42],
];
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
let shellIndex = 0;
for (let i = 0; i < blockCount; i++) {
const x = frameLeft + i * blockStep + voxelSize * 0.5;
for (const [dy, dz] of shellCorners) {
matrix.makeTranslation(
x,
frameCenterY + dy,
dz
);
shell.setMatrixAt(shellIndex, matrix);
color.set(0x145d63);
color.offsetHSL(
(i % 3) * 0.004,
0,
((i + shellIndex) % 4 - 1.5) * 0.018
);
shell.setColorAt(shellIndex, color);
shellIndex++;
}
}
shell.instanceMatrix.needsUpdate = true;
if (shell.instanceColor) shell.instanceColor.needsUpdate = true;
frameRoot.add(shell);
// Longitudinal inner reinforcement, visible through the open end.
const innerGeometry = new THREE.BoxGeometry(0.2, 0.07, 0.07);
const innerMesh = new THREE.InstancedMesh(
innerGeometry,
standardMaterial(0x356f9d),
4 * 15
);
innerMesh.castShadow = true;
const innerCorners = [
[-0.2, -0.2],
[-0.2, 0.2],
[0.2, -0.2],
[0.2, 0.2],
];
let innerIndex = 0;
for (let i = 0; i < 15; i++) {
const x = frameLeft + 0.05 + i * blockStep;
for (const [dy, dz] of innerCorners) {
matrix.makeTranslation(
x,
frameCenterY + dy,
dz
);
innerMesh.setMatrixAt(innerIndex++, matrix);
}
}
innerMesh.instanceMatrix.needsUpdate = true;
frameRoot.add(innerMesh);
// A stylized cut face suggests several directional constituents.
const cutFaceX = frameRight + 0.115;
const facePieces = [
[0.115, 0.085, 0.9, 0, 0.43, 0, 0xd9a83d],
[0.115, 0.085, 0.9, 0, -0.43, 0, 0xd9a83d],
[0.115, 0.76, 0.085, 0, 0, 0.43, 0x356f9d],
[0.115, 0.76, 0.085, 0, 0, -0.43, 0x356f9d],
[0.13, 0.055, 0.7, 0, 0.25, 0, 0xdf654d],
[0.13, 0.055, 0.7, 0, -0.25, 0, 0xdf654d],
];
for (const [w, h, d, dx, dy, dz, c] of facePieces) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
standardMaterial(c)
);
mesh.position.set(
cutFaceX + dx,
frameCenterY + dy,
dz
);
mesh.castShadow = true;
frameRoot.add(mesh);
}
const frameLabel = makeLabel("GENERIC FRAME TUBE SECTION", "#d9a83d");
frameLabel.position.set(-2.45, 2.72, 0);
scene.add(frameLabel);
// Local tube axis.
dashedLine(
[
[-4.65, frameCenterY, 0.73],
[0.35, frameCenterY, 0.73],
],
0x8e6a24,
0.55
);
// ---------------------------------------------------------------------
// Exploded laminate layers
// ---------------------------------------------------------------------
const layerRoot = new THREE.Group();
scene.add(layerRoot);
const layerGroups = [];
const layerX = 2.2;
const layerWidth = 3.25;
const layerDepth = 1.35;
const layerYs = [0.52, 0.94, 1.36, 1.78];
function addLayer(index, y, slabColor, angle, angleLabel, accent) {
const group = new THREE.Group();
group.position.set(layerX, y, 0);
const slab = new THREE.Mesh(
new THREE.BoxGeometry(layerWidth, 0.115, layerDepth),
standardMaterial(slabColor)
);
slab.castShadow = true;
slab.receiveShadow = true;
group.add(slab);
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(slab.geometry),
new THREE.LineBasicMaterial({
color: 0x1f3235,
transparent: true,
opacity: 0.22,
})
);
group.add(edge);
const fiberMaterial = standardMaterial(accent, {
roughness: 0.58,
emissive: accent,
emissiveIntensity: 0.035,
});
if (angle === 0) {
// Longitudinal fibers.
for (let z = -0.48; z <= 0.49; z += 0.24) {
const fiber = new THREE.Mesh(
new THREE.BoxGeometry(2.9, 0.028, 0.035),
fiberMaterial
);
fiber.position.set(0, 0.074, z);
group.add(fiber);
}
} else if (angle === 90) {
// Transverse fibers.
for (let x = -1.35; x <= 1.36; x += 0.3) {
const fiber = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.028, 1.12),
fiberMaterial
);
fiber.position.set(x, 0.074, 0);
group.add(fiber);
}
} else {
// Bias fibers.
for (let offset = -0.72; offset <= 0.73; offset += 0.36) {
const fiber = new THREE.Mesh(
new THREE.BoxGeometry(2.25, 0.028, 0.035),
fiberMaterial
);
fiber.position.set(0, 0.074, offset);
fiber.rotation.y = angle;
group.add(fiber);
}
}
const label = makeLabel(angleLabel, accent, true);
label.position.set(4.48, y, 0);
scene.add(label);
layerRoot.add(group);
layerGroups.push({ group, baseY: y, phase: index * 0.7 });
}
addLayer(0, layerYs[0], 0x315d79, 0, "0° / AXIAL", "#8eb8d7");
addLayer(1, layerYs[1], 0xb94f40, Math.PI / 4, "+45° / BIAS", "#f0aa84");
addLayer(2, layerYs[2], 0x9d493f, -Math.PI / 4, "-45° / BIAS", "#f0aa84");
addLayer(3, layerYs[3], 0x2e746a, Math.PI / 2, "90° / CROSS", "#82c3ad");
// Exploded-stack alignment guides.
dashedLine(
[
[0.52, 0.31, 0],
[0.52, 2.18, 0],
],
0x758486,
0.45
);
dashedLine(
[
[3.88, 0.31, 0],
[3.88, 2.18, 0],
],
0x758486,
0.45
);
const laminateLabel = makeLabel("EXPLODED LAMINATE ORIENTATIONS", "#df654d");
laminateLabel.position.set(2.2, 2.55, 0);
scene.add(laminateLabel);
// ---------------------------------------------------------------------
// Voxel arrows for conceptual load cases
// ---------------------------------------------------------------------
const arrowRoot = new THREE.Group();
scene.add(arrowRoot);
const animatedArrows = [];
function createVoxelArrow(origin, direction, length, color, phase = 0) {
const group = new THREE.Group();
const material = standardMaterial(color, {
roughness: 0.55,
});
const headLength = 0.48;
const shaftLength = Math.max(0.1, length - headLength);
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(0.115, shaftLength, 0.115),
material
);
shaft.position.y = shaftLength * 0.5;
shaft.castShadow = true;
group.add(shaft);
const tiers = [
{ y: length - 0.39, width: 0.49 },
{ y: length - 0.25, width: 0.35 },
{ y: length - 0.11, width: 0.21 },
];
for (const tier of tiers) {
const head = new THREE.Mesh(
new THREE.BoxGeometry(tier.width, 0.15, tier.width),
material
);
head.position.y = tier.y;
head.castShadow = true;
group.add(head);
}
group.position.copy(origin);
group.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
group.userData.phase = phase;
arrowRoot.add(group);
animatedArrows.push(group);
return group;
}
createVoxelArrow(
new THREE.Vector3(-5.3, frameCenterY, 0),
new THREE.Vector3(1, 0, 0),
1.05,
0xdf654d,
0.2
);
createVoxelArrow(
new THREE.Vector3(frameRight + 0.02, frameCenterY, 0),
new THREE.Vector3(1, 0, 0),
1.18,
0xdf654d,
1.3
);
createVoxelArrow(
new THREE.Vector3(-2.25, 4.12, 0),
new THREE.Vector3(0, -1, 0),
1.88,
0x6655b8,
2.1
);
createVoxelArrow(
new THREE.Vector3(frameRight + 0.02, frameCenterY, 1.42),
new THREE.Vector3(0, 0, -1),
0.9,
0xd9a83d,
0.8
);
createVoxelArrow(
new THREE.Vector3(frameRight + 0.02, frameCenterY, -1.42),
new THREE.Vector3(0, 0, 1),
0.9,
0xd9a83d,
2.7
);
// ---------------------------------------------------------------------
// Camera and custom controls — no external control add-ons
// ---------------------------------------------------------------------
const cameraState = {
theta: 0.72,
phi: 1.03,
radius: 12.4,
target: new THREE.Vector3(0, 1.2, 0),
};
let cameraTween = null;
function applyCameraState() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function setView(name, immediate = false) {
const presets = {
overview: {
theta: 0.72,
phi: 1.03,
radius: 12.4,
target: new THREE.Vector3(0, 1.2, 0),
title: "Direction changes the response.",
copy:
"A generic composite tube is locally directional: fibers carry load most effectively along their own axis. The design question is how ply angles align with local axial, bending, torsion, and radial demands—not which layer is simply “strongest.”",
},
section: {
theta: 0.84,
phi: 1.08,
radius: 8.25,
target: new THREE.Vector3(-2.35, 1.48, 0),
title: "Read the tube locally.",
copy:
"Follow the specimen’s long axis. A global direction is meaningful only after mapping it onto the tube’s changing local axis. Around bends, one laminate can be longitudinal in one region and off-axis in another.",
},
layers: {
theta: 0.55,
phi: 0.97,
radius: 7.55,
target: new THREE.Vector3(2.15, 1.15, 0),
title: "Layers form a directional balance.",
copy:
"The exploded stack separates 0°, +45°, −45°, and 90° fiber directions for clarity. Their proportions and stacking order affect directional stiffness and load sharing. This display is illustrative, not a laminate recommendation.",
},
loads: {
theta: 0.28,
phi: 0.86,
radius: 10.2,
target: new THREE.Vector3(-2.1, 1.75, 0),
title: "Arrows identify load cases.",
copy:
"Red vectors align with the specimen axis. Purple shows a transverse demand, while gold suggests radial or hoop action around the section. Actual response depends on the material system, wall geometry, joints, manufacturing, and other factors.",
},
};
const preset = presets[name] || presets.overview;
document.querySelector("#conceptTitle").textContent = preset.title;
document.querySelector("#conceptCopy").textContent = preset.copy;
document.querySelectorAll(".view").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
if (immediate) {
cameraState.theta = preset.theta;
cameraState.phi = preset.phi;
cameraState.radius = preset.radius;
cameraState.target.copy(preset.target);
cameraTween = null;
applyCameraState();
return;
}
cameraTween = {
start: performance.now(),
duration: 780,
from: {
theta: cameraState.theta,
phi: cameraState.phi,
radius: cameraState.radius,
target: cameraState.target.clone(),
},
to: {
theta: preset.theta,
phi: preset.phi,
radius: preset.radius,
target: preset.target.clone(),
},
};
}
document.querySelectorAll(".view").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
document.querySelector("#reset").addEventListener("click", () => {
setView("overview");
});
document.querySelector("#arrowsToggle").addEventListener("change", (event) => {
arrowRoot.visible = event.target.checked;
});
const pointers = new Map();
let pinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
canvas.classList.add("dragging");
cameraTween = null;
} else if (pointers.size === 2) {
pinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
cameraState.theta -= dx * 0.007;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.006,
0.42,
1.43
);
applyCameraState();
} else if (pointers.size >= 2) {
const distance = pointerDistance();
if (pinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / distance),
6.2,
19
);
applyCameraState();
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchDistance = 0;
}
if (pointers.size === 0) {
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTween = null;
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
6.2,
19
);
applyCameraState();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => setView("overview"));
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
let handled = true;
cameraTween = null;
switch (event.key) {
case "ArrowLeft":
cameraState.theta += 0.09;
break;
case "ArrowRight":
cameraState.theta -= 0.09;
break;
case "ArrowUp":
cameraState.phi = Math.max(0.42, cameraState.phi - 0.07);
break;
case "ArrowDown":
cameraState.phi = Math.min(1.43, cameraState.phi + 0.07);
break;
case "+":
case "=":
cameraState.radius = Math.max(6.2, cameraState.radius - 0.65);
break;
case "-":
case "_":
cameraState.radius = Math.min(19, cameraState.radius + 0.65);
break;
case "r":
case "R":
setView("overview");
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
applyCameraState();
}
});
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", onResize);
setView("overview", true);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (cameraTween) {
const raw = Math.min(
1,
(performance.now() - cameraTween.start) / cameraTween.duration
);
const t = raw < 0.5
? 4 * raw * raw * raw
: 1 - Math.pow(-2 * raw + 2, 3) / 2;
cameraState.theta = THREE.MathUtils.lerp(
cameraTween.from.theta,
cameraTween.to.theta,
t
);
cameraState.phi = THREE.MathUtils.lerp(
cameraTween.from.phi,
cameraTween.to.phi,
t
);
cameraState.radius = THREE.MathUtils.lerp(
cameraTween.from.radius,
cameraTween.to.radius,
t
);
cameraState.target.lerpVectors(
cameraTween.from.target,
cameraTween.to.target,
t
);
applyCameraState();
if (raw >= 1) {
cameraTween = null;
}
}
if (!reducedMotion) {
for (const item of layerGroups) {
item.group.position.y =
item.baseY + Math.sin(elapsed * 0.75 + item.phase) * 0.016;
}
for (const arrow of animatedArrows) {
const pulse = 1 + Math.sin(elapsed * 1.8 + arrow.userData.phase) * 0.014;
arrow.scale.setScalar(pulse);
}
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```