Prompt specification
Build or customize the Three.js 3D scene "Bridge movement teaching diorama" 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: Bridge movement teaching diorama
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bridge-movement-teaching-diorama-x1507
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this voxel scene: Compose a bridge deck, sliding bearing, and expansion joint with an enlarged inset; explain allowed movement without presenting the scene as a structural design specification.
Working Three.js Starter (bridge-movement-teaching-diorama-x1507):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Bridge Deck, Sliding Bearing & Expansion Joint</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(10, 23, 36, 0.88);
--panel-border: rgba(167, 218, 224, 0.19);
--text: #edf7f7;
--muted: #a7bdc5;
--teal: #68d8c8;
--amber: #ffbd69;
--blue: #8fc5ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07131f;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.title-block {
position: absolute;
top: 24px;
left: 28px;
z-index: 5;
max-width: 520px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
}
.eyebrow {
margin-bottom: 8px;
color: var(--teal);
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--text);
font-size: clamp(1.45rem, 3vw, 2.55rem);
font-weight: 720;
line-height: 1.06;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 0.88rem;
line-height: 1.5;
}
.concept-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 12px;
padding: 6px 9px;
border: 1px solid rgba(255, 189, 105, 0.3);
border-radius: 999px;
background: rgba(30, 25, 21, 0.66);
color: #ffd59f;
font-size: 0.67rem;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.concept-badge::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--amber);
content: "";
box-shadow: 0 0 10px rgba(255, 189, 105, 0.7);
}
.info-panel {
position: absolute;
left: 24px;
bottom: 24px;
z-index: 6;
width: min(410px, calc(100vw - 48px));
padding: 18px 19px 16px;
border: 1px solid var(--panel-border);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.panel-heading h2 {
margin: 0;
color: var(--text);
font-size: 0.85rem;
letter-spacing: 0.03em;
}
#motion-state {
color: var(--muted);
font-size: 0.65rem;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.movement-list {
display: grid;
gap: 10px;
margin: 0;
padding: 0;
list-style: none;
}
.movement-list li {
display: grid;
grid-template-columns: 25px 1fr;
gap: 10px;
align-items: start;
}
.movement-list .number {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border: 1px solid rgba(104, 216, 200, 0.32);
border-radius: 7px;
background: rgba(104, 216, 200, 0.08);
color: var(--teal);
font-size: 0.68rem;
font-weight: 800;
}
.movement-list strong {
display: block;
margin-bottom: 2px;
color: #f2fbfb;
font-size: 0.78rem;
}
.movement-list p {
margin: 0;
color: var(--muted);
font-size: 0.73rem;
line-height: 1.48;
}
.panel-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.09);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 12px;
color: var(--muted);
font-size: 0.64rem;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.legend i {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--teal);
}
.legend .amber {
background: var(--amber);
}
#movement-toggle {
flex: 0 0 auto;
padding: 8px 11px;
border: 1px solid rgba(104, 216, 200, 0.38);
border-radius: 9px;
background: rgba(104, 216, 200, 0.11);
color: #c9fff7;
cursor: pointer;
font: inherit;
font-size: 0.69rem;
font-weight: 780;
transition:
background 160ms ease,
transform 160ms ease;
}
#movement-toggle:hover {
background: rgba(104, 216, 200, 0.2);
transform: translateY(-1px);
}
#movement-toggle:focus-visible {
outline: 2px solid var(--teal);
outline-offset: 3px;
}
.disclaimer {
margin: 12px 0 0;
color: #879ca6;
font-size: 0.63rem;
line-height: 1.45;
}
#inset-frame {
position: absolute;
top: 88px;
right: 24px;
z-index: 4;
overflow: hidden;
border: 1px solid rgba(168, 221, 226, 0.28);
border-radius: 16px;
background: transparent;
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.4);
pointer-events: none;
}
.inset-header {
position: absolute;
top: 0;
right: 0;
left: 0;
z-index: 2;
padding: 12px 14px 24px;
background: linear-gradient(
to bottom,
rgba(6, 17, 28, 0.96),
rgba(6, 17, 28, 0.65) 65%,
transparent
);
}
.inset-kicker {
margin-bottom: 3px;
color: var(--teal);
font-size: 0.59rem;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.inset-header h2 {
margin: 0;
color: #f1fbfb;
font-size: 0.9rem;
font-weight: 720;
}
.inset-footer {
position: absolute;
right: 0;
bottom: 0;
left: 0;
z-index: 2;
display: flex;
justify-content: space-between;
gap: 8px;
padding: 22px 12px 10px;
background: linear-gradient(
to top,
rgba(6, 17, 28, 0.94),
transparent
);
color: #a9c1ca;
font-size: 0.58rem;
font-weight: 700;
letter-spacing: 0.04em;
}
.inset-footer .teal {
color: var(--teal);
}
.inset-footer .amber {
color: var(--amber);
}
.callout {
position: absolute;
z-index: 3;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px 6px 7px;
border: 1px solid rgba(192, 228, 232, 0.22);
border-radius: 999px;
background: rgba(7, 20, 31, 0.82);
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
color: #eef9f9;
font-size: 0.66rem;
font-weight: 760;
letter-spacing: 0.02em;
pointer-events: none;
transform: translate(-50%, -125%);
backdrop-filter: blur(7px);
-webkit-backdrop-filter: blur(7px);
white-space: nowrap;
}
.callout::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 17px;
background: linear-gradient(var(--teal), transparent);
content: "";
}
.callout b {
display: grid;
width: 18px;
height: 18px;
place-items: center;
border-radius: 50%;
background: var(--teal);
color: #06241f;
font-size: 0.61rem;
}
.hint {
position: absolute;
right: 25px;
bottom: 24px;
z-index: 5;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 9px;
background: rgba(7, 19, 29, 0.64);
color: #91a8b1;
font-size: 0.62rem;
pointer-events: none;
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
@media (max-width: 760px) {
.title-block {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
.subtitle {
max-width: 75%;
}
.concept-badge {
margin-top: 8px;
}
#inset-frame {
top: 78px;
right: 16px;
}
.info-panel {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 14px;
}
.movement-list {
gap: 7px;
}
.movement-list p {
font-size: 0.68rem;
}
.disclaimer {
font-size: 0.59rem;
}
.callout {
display: none;
}
.hint {
display: none;
}
.panel-footer {
align-items: flex-end;
}
}
@media (max-height: 690px) and (min-width: 761px) {
.info-panel {
bottom: 14px;
padding: 14px 16px;
}
.movement-list {
gap: 6px;
}
.disclaimer {
margin-top: 8px;
}
#inset-frame {
top: 70px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel bridge scene"></canvas>
<header class="title-block">
<div class="eyebrow">Infrastructure / Motion Study</div>
<h1>Bridge deck, bearing & joint</h1>
<p class="subtitle">
An interactive voxel cutaway illustrating longitudinal deck movement.
</p>
<div class="concept-badge">Concept visualization · not a design specification</div>
</header>
<div id="inset-frame" aria-label="Enlarged inset of the sliding bearing and expansion joint">
<div class="inset-header">
<div class="inset-kicker">Enlarged cutaway</div>
<h2>Sliding interface & joint</h2>
</div>
<div class="inset-footer">
<span><b class="teal">TEAL</b> sliding surface</span>
<span><b class="amber">AMBER</b> bearing pad</span>
<span>ARROWS = DIRECTION</span>
</div>
</div>
<div id="label-deck" class="callout"><b>1</b> Bridge deck</div>
<div id="label-bearing" class="callout"><b>2</b> Sliding bearing</div>
<div id="label-joint" class="callout"><b>3</b> Expansion joint</div>
<section class="info-panel" aria-labelledby="movement-heading">
<div class="panel-heading">
<h2 id="movement-heading">Illustrated allowed movement</h2>
<span id="motion-state">Paused</span>
</div>
<ol class="movement-list">
<li>
<span class="number">1</span>
<div>
<strong>Longitudinal deck translation</strong>
<p>
The arrows represent relative movement along the bridge axis, as
commonly associated with thermal expansion and contraction.
</p>
</div>
</li>
<li>
<span class="number">2</span>
<div>
<strong>Sliding bearing function</strong>
<p>
The bearing visually supports the deck while permitting horizontal
sliding at the interface. Its restraint and load behavior are not
specified here.
</p>
</div>
</li>
<li>
<span class="number">3</span>
<div>
<strong>Expansion-joint function</strong>
<p>
The joint accommodates the changing gap between adjacent deck ends.
Transverse motion, rotation, uplift, and seismic displacement are
not illustrated.
</p>
</div>
</li>
</ol>
<div class="panel-footer">
<div class="legend" aria-label="Inset color legend">
<span><i></i> Sliding surface</span>
<span><i class="amber"></i> Bearing pad</span>
</div>
<button id="movement-toggle" type="button" aria-pressed="false">
Play movement
</button>
</div>
<p class="disclaimer">
Conceptual illustration only. Arrows show direction, not magnitude.
Actual clearances, movement limits, restraints, loads, and joint details
are project-specific and require verification by qualified structural
engineers.
</p>
</section>
<div class="hint">Drag to orbit · Scroll / pinch to zoom · Double-click to reset</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 insetFrame = document.querySelector("#inset-frame");
const movementButton = document.querySelector("#movement-toggle");
const motionState = document.querySelector("#motion-state");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.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(0x07131f);
scene.fog = new THREE.Fog(0x07131f, 24, 48);
const insetScene = new THREE.Scene();
insetScene.background = new THREE.Color(0x0b1b28);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const insetCamera = new THREE.OrthographicCamera(
-4.9,
4.9,
3.45,
-3.45,
0.1,
30
);
insetCamera.position.set(7.2, 6.1, 8.3);
insetCamera.lookAt(0, 1.2, 0);
const hemi = new THREE.HemisphereLight(0xb9e8ff, 0x24302b, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d6, 3.2);
sun.position.set(10, 18, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -19;
sun.shadow.camera.right = 19;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x67bfff, 1.15);
fill.position.set(-12, 8, -10);
scene.add(fill);
const insetHemi = new THREE.HemisphereLight(0xd7f5ff, 0x172630, 2.4);
insetScene.add(insetHemi);
const insetSun = new THREE.DirectionalLight(0xffefd5, 3.3);
insetSun.position.set(5, 9, 8);
insetScene.add(insetSun);
const materialCache = new Map();
const edgeMaterialCache = new Map();
function getMaterial(color, metalness = 0, roughness = 0.82) {
const key = `${color}-${metalness}-${roughness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
metalness,
roughness
})
);
}
return materialCache.get(key);
}
function getEdgeMaterial(color = 0x07131f, opacity = 0.42) {
const key = `${color}-${opacity}`;
if (!edgeMaterialCache.has(key)) {
edgeMaterialCache.set(
key,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
}
return edgeMaterialCache.get(key);
}
function block(
parent,
size,
position,
color,
options = {}
) {
const geometry = new THREE.BoxGeometry(...size);
const material =
options.material ||
getMaterial(
color,
options.metalness ?? 0,
options.roughness ?? 0.82
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
if (options.edge) {
const edgeColor =
typeof options.edge === "number" ? options.edge : 0x07131f;
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
getEdgeMaterial(edgeColor)
);
mesh.add(edges);
}
parent.add(mesh);
return mesh;
}
function arrow(parent, origin, direction, length, color) {
const helper = new THREE.ArrowHelper(
new THREE.Vector3(...direction).normalize(),
new THREE.Vector3(...origin),
length,
color,
0.22,
0.13
);
parent.add(helper);
return helper;
}
// ---------------------------------------------------------------------
// Main voxel landscape
// ---------------------------------------------------------------------
const ground = block(
scene,
[32, 0.65, 18],
[0, -0.62, 0],
0x34433f,
{ roughness: 0.95 }
);
block(
scene,
[8.4, 0.18, 18],
[0, -0.23, 0],
0x1b7187,
{ roughness: 0.32, metalness: 0.12 }
);
block(
scene,
[12, 0.18, 18],
[-10.2, -0.24, 0],
0x4d5c4c,
{ roughness: 0.96 }
);
block(
scene,
[12, 0.18, 18],
[10.2, -0.24, 0],
0x4d5c4c,
{ roughness: 0.96 }
);
// Small block-like water highlights.
const waterColors = [0x2b8297, 0x257a91, 0x318ca0, 0x216f87];
for (let z = -7.5; z <= 7.5; z += 1.5) {
for (let x = -3.25; x <= 3.25; x += 1.25) {
const color = waterColors[Math.floor(Math.random() * waterColors.length)];
block(
scene,
[0.8, 0.035, 0.72],
[x + (Math.random() - 0.5) * 0.18, -0.125, z],
color,
{
castShadow: false,
roughness: 0.4,
metalness: 0.08
}
);
}
}
// Low, voxelized bank details.
for (const side of [-1, 1]) {
for (let i = 0; i < 14; i++) {
const x = side * (9.1 + Math.random() * 3.8);
const z = -7.4 + Math.random() * 14.8;
const height = 0.25 + Math.random() * 0.55;
block(
scene,
[0.45 + Math.random() * 0.6, height, 0.45 + Math.random() * 0.6],
[x, -0.06 + height * 0.5, z],
i % 3 === 0 ? 0x6a7657 : 0x59684d,
{ roughness: 0.98 }
);
}
}
function buildAbutment(x) {
const group = new THREE.Group();
scene.add(group);
block(
group,
[2.35, 2.55, 6.1],
[x, 1.05, 0],
0x78838a,
{ edge: true }
);
block(
group,
[3.0, 0.46, 7.0],
[x, 2.43, 0],
0x8b969c,
{ edge: true }
);
block(
group,
[2.7, 0.18, 6.5],
[x, 2.76, 0],
0x9aa5a9
);
// Stepped abutment face.
for (let i = 0; i < 4; i++) {
block(
group,
[0.55, 0.42, 5.9 - i * 0.55],
[x - Math.sign(x) * 1.18, 0.15 + i * 0.4, 0],
0x707b82
);
}
}
function buildPier(x) {
const group = new THREE.Group();
scene.add(group);
block(
group,
[1.55, 2.95, 3.15],
[x, 1.27, 0],
0x69757c,
{ edge: true }
);
block(
group,
[2.15, 0.5, 4.65],
[x, 2.9, 0],
0x8b979b,
{ edge: true }
);
block(
group,
[2.35, 0.14, 4.85],
[x, 3.22, 0],
0xa0abad
);
}
buildAbutment(-7.25);
buildAbutment(7.25);
buildPier(-3.45);
buildPier(3.45);
function buildSlidingBearing(parent, x, z, scale = 1, highlighted = false) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
parent.add(group);
block(
group,
[1.18, 0.12, 0.78],
[0, 0.06, 0],
0x3c4c55,
{ metalness: 0.55, roughness: 0.42, edge: true }
);
block(
group,
[0.98, 0.17, 0.64],
[0, 0.205, 0],
highlighted ? 0xffb85f : 0xd79245,
{ roughness: 0.72 }
);
block(
group,
[0.88, 0.075, 0.56],
[0, 0.327, 0],
0x58d5c5,
{ metalness: 0.3, roughness: 0.3 }
);
block(
group,
[1.12, 0.12, 0.74],
[0, 0.425, 0],
highlighted ? 0xc3d5da : 0x91a1a8,
{ metalness: 0.65, roughness: 0.35, edge: true }
);
return group;
}
const bearingPositions = [-6.85, -3.45, 3.45, 6.85];
for (const x of bearingPositions) {
buildSlidingBearing(scene, x, -1.78);
buildSlidingBearing(scene, x, 1.78);
}
// Dark joint cavity below the deck opening.
block(
scene,
[1.27, 0.16, 5.32],
[0, 3.56, 0],
0x14232c,
{ castShadow: false }
);
function buildDeckSegment(centerX, direction) {
const group = new THREE.Group();
group.position.x = centerX;
scene.add(group);
const width = 7.1;
// Structural slab and longitudinal girders.
block(
group,
[width, 0.68, 5.5],
[0, 3.96, 0],
0x9aa7aa,
{ edge: true }
);
block(
group,
[width, 0.13, 5.36],
[0, 4.365, 0],
0x344652,
{ roughness: 0.93 }
);
for (const z of [-1.85, 0, 1.85]) {
block(
group,
[width - 0.12, 0.3, 0.34],
[0, 3.49, z],
0x78878d,
{ metalness: 0.08 }
);
}
// Edge girders.
for (const z of [-2.48, 2.48]) {
block(
group,
[width, 0.36, 0.34],
[0, 3.48, z],
0x7a8a91
);
}
// Surface seams.
for (let localX = -2.8; localX <= 2.8; localX += 1.4) {
block(
group,
[0.025, 0.012, 5.0],
[localX, 4.437, 0],
0x21333f,
{ castShadow: false }
);
}
// Dashed center marking.
for (let localX = -3.0; localX <= 3.0; localX += 0.72) {
block(
group,
[0.38, 0.018, 0.095],
[localX, 4.446, 0],
0xf2c86a,
{ castShadow: false }
);
}
// Parapets and rails.
for (const z of [-2.79, 2.79]) {
block(
group,
[width, 0.26, 0.28],
[0, 4.55, z],
0x71838b,
{ edge: true }
);
block(
group,
[width - 0.08, 0.13, 0.13],
[0, 5.42, z],
0x66cdbf,
{ metalness: 0.35, roughness: 0.4 }
);
for (let localX = -3.1; localX <= 3.1; localX += 1.033) {
block(
group,
[0.13, 0.82, 0.13],
[localX, 5.01, z],
0x66cdbf,
{ metalness: 0.35, roughness: 0.4 }
);
}
}
const jointEdge = direction * (width * 0.5);
// Joint edge rail.
block(
group,
[0.18, 0.10, 5.18],
[jointEdge - direction * 0.08, 4.47, 0],
0x78909b,
{ metalness: 0.68, roughness: 0.3 }
);
// Alternating finger-joint elements.
for (let i = 0; i < 11; i++) {
const z = -2.4 + i * 0.48;
const belongsToSegment = i % 2 === 0;
if (belongsToSegment === (direction < 0)) {
block(
group,
[0.43, 0.095, 0.18],
[jointEdge + direction * 0.215, 4.46, z],
0x8ea4ad,
{ metalness: 0.7, roughness: 0.3 }
);
}
}
// Highlight the deck ends adjacent to the joint.
const endCap = direction * (width * 0.5 - 0.14);
block(
group,
[0.16, 0.33, 5.24],
[endCap, 4.52, 0],
0xe6aa55
);
return group;
}
const leftDeck = buildDeckSegment(-4.2, 1);
const rightDeck = buildDeckSegment(4.2, -1);
// Main-scene movement arrows.
arrow(scene, [-1.75, 5.03, -0.25], [1, 0, 0], 1.25, 0xffbd69);
arrow(scene, [1.75, 5.03, -0.25], [-1, 0, 0], 1.25, 0xffbd69);
// ---------------------------------------------------------------------
// Enlarged inset assembly
// ---------------------------------------------------------------------
const insetGround = block(
insetScene,
[12, 0.2, 8],
[0, -0.25, 0],
0x102733,
{ castShadow: false }
);
const insetGrid = new THREE.GridHelper(10, 20, 0x294654, 0x1b3440);
insetGrid.position.y = -0.13;
insetScene.add(insetGrid);
function buildInsetSupport(x) {
block(
insetScene,
[1.6, 1.1, 3.0],
[x, 0.42, 0],
0x5d6e76,
{ edge: true }
);
block(
insetScene,
[2.0, 0.18, 3.45],
[x, 1.05, 0],
0x8b999e,
{ edge: true }
);
buildSlidingBearing(insetScene, x, 0, 1.02, true);
}
buildInsetSupport(-2.05);
buildInsetSupport(2.05);
function buildInsetDeck(centerX, direction) {
const group = new THREE.Group();
group.position.x = centerX;
insetScene.add(group);
const width = 3.4;
block(
group,
[width, 0.62, 4.75],
[0, 1.78, 0],
0x9ca9ac,
{ edge: true }
);
block(
group,
[width, 0.12, 4.62],
[0, 2.15, 0],
0x344753
);
for (const z of [-2.37, 2.37]) {
block(
group,
[width, 0.22, 0.2],
[0, 1.47, z],
0x70858d
);
}
const edge = direction * (width * 0.5);
block(
group,
[0.18, 0.1, 4.4],
[edge - direction * 0.08, 2.23, 0],
0x93aab2,
{ metalness: 0.7, roughness: 0.3 }
);
for (let i = 0; i < 9; i++) {
const z = -1.9 + i * 0.475;
const belongsToSegment = i % 2 === 0;
if (belongsToSegment === (direction < 0)) {
block(
group,
[0.28, 0.09, 0.17],
[edge + direction * 0.14, 2.22, z],
0x9cb2ba,
{ metalness: 0.7, roughness: 0.3 }
);
}
}
// Small cutaway marker blocks at the joint edge.
block(
group,
[0.13, 0.29, 4.42],
[edge - direction * 0.06, 2.2, 0],
0xe6aa55
);
return group;
}
const insetLeftDeck = buildInsetDeck(-2.02, 1);
const insetRightDeck = buildInsetDeck(2.02, -1);
block(
insetScene,
[0.6, 0.12, 4.52],
[0, 2.08, 0],
0x10242f,
{ castShadow: false }
);
arrow(insetScene, [-1.28, 2.78, 0], [1, 0, 0], 0.9, 0x68d8c8);
arrow(insetScene, [1.28, 2.78, 0], [-1, 0, 0], 0.9, 0x68d8c8);
// ---------------------------------------------------------------------
// Direct camera controls: orbit, zoom, reset, and touch pinch
// ---------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 2.25, 0),
radius: 25,
yaw: 0.76,
pitch: 0.67
};
function applyCamera() {
const sinPitch = Math.sin(controls.pitch);
const cosPitch = Math.cos(controls.pitch);
camera.position.set(
controls.target.x +
controls.radius * sinPitch * Math.sin(controls.yaw),
controls.target.y + controls.radius * cosPitch,
controls.target.z +
controls.radius * sinPitch * Math.cos(controls.yaw)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.radius = 25;
controls.yaw = 0.76;
controls.pitch = 0.67;
controls.target.set(0, 2.25, 0);
applyCamera();
}
const activePointers = new Map();
let previousPinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
previousPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = activePointers.get(event.pointerId);
if (!previous) return;
const current = {
x: event.clientX,
y: event.clientY
};
if (activePointers.size === 1) {
const dx = current.x - previous.x;
const dy = current.y - previous.y;
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.0045,
0.26,
1.28
);
} else if (activePointers.size === 2) {
activePointers.set(event.pointerId, current);
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (previousPinchDistance > 0 && distance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * (previousPinchDistance / distance),
10,
42
);
}
previousPinchDistance = distance;
}
activePointers.set(event.pointerId, current);
applyCamera();
});
function releasePointer(event) {
activePointers.delete(event.pointerId);
previousPinchDistance = 0;
}
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),
10,
42
);
applyCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
applyCamera();
// ---------------------------------------------------------------------
// Responsive inset viewport
// ---------------------------------------------------------------------
const insetRect = {
width: 430,
height: 300,
top: 88,
right: 24,
x: 0,
y: 0
};
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
const mobile = width <= 760;
insetRect.width = Math.min(
mobile ? width - 32 : 430,
Math.max(260, width - 40)
);
insetRect.height = Math.min(
mobile ? 205 : 300,
Math.max(180, height - 150)
);
insetRect.right = mobile ? 16 : 24;
insetRect.top = mobile ? 78 : 88;
const frameStyle = getComputedStyle(insetFrame);
insetRect.top = parseFloat(frameStyle.top) || insetRect.top;
insetRect.right = parseFloat(frameStyle.right) || insetRect.right;
insetFrame.style.width = `${insetRect.width}px`;
insetFrame.style.height = `${insetRect.height}px`;
insetRect.x = Math.floor(width - insetRect.right - insetRect.width);
insetRect.y = Math.floor(height - insetRect.top - insetRect.height);
const aspect = insetRect.width / insetRect.height;
insetCamera.left = -3.45 * aspect;
insetCamera.right = 3.45 * aspect;
insetCamera.top = 3.45;
insetCamera.bottom = -3.45;
insetCamera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
// ---------------------------------------------------------------------
// Projected HTML callouts
// ---------------------------------------------------------------------
const callouts = [
{
element: document.querySelector("#label-deck"),
point: new THREE.Vector3(-2.9, 4.66, 2.95)
},
{
element: document.querySelector("#label-bearing"),
point: new THREE.Vector3(-6.85, 3.23, 2.25)
},
{
element: document.querySelector("#label-joint"),
point: new THREE.Vector3(0, 4.58, 2.75)
}
];
function updateCallouts() {
for (const callout of callouts) {
const projected = callout.point.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
callout.element.style.display = visible ? "flex" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
callout.element.style.left = `${x}px`;
callout.element.style.top = `${y}px`;
}
}
// ---------------------------------------------------------------------
// Optional movement demonstration
// ---------------------------------------------------------------------
let movementEnabled = false;
let movementPhase = 0;
let displayedMovement = 0;
movementButton.addEventListener("click", () => {
movementEnabled = !movementEnabled;
movementButton.setAttribute("aria-pressed", String(movementEnabled));
movementButton.textContent = movementEnabled
? "Pause movement"
: "Play movement";
motionState.textContent = movementEnabled ? "Playing" : "Paused";
});
// ---------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (movementEnabled) {
movementPhase += delta * 0.85;
}
const targetMovement = movementEnabled
? (1 - Math.cos(movementPhase)) * 0.5
: 0;
displayedMovement +=
(targetMovement - displayedMovement) * Math.min(1, delta * 5);
leftDeck.position.x = -0.18 * displayedMovement;
rightDeck.position.x = 0.18 * displayedMovement;
insetLeftDeck.position.x = -2.02 - 0.11 * displayedMovement;
insetRightDeck.position.x = 2.02 + 0.11 * displayedMovement;
updateCallouts();
renderer.setScissorTest(false);
renderer.setViewport(0, 0, window.innerWidth, window.innerHeight);
renderer.render(scene, camera);
renderer.setScissorTest(true);
renderer.setScissor(
insetRect.x,
insetRect.y,
insetRect.width,
insetRect.height
);
renderer.setViewport(
insetRect.x,
insetRect.y,
insetRect.width,
insetRect.height
);
renderer.render(insetScene, insetCamera);
renderer.setScissorTest(false);
}
animate();
</script>
</body>
</html>
```