Prompt specification
Build or customize the Three.js 3D scene "Lap joint contact-area model" 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: Lap joint contact-area model
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/lap-joint-contact-area-model-x0265
Scene Description Prompt:
Please use Three.js from cdnjs for a stylized scene based on this idea: lap joint contact-area model. Show two overlapping wooden strips with a thin colored bond layer between them; mark the shared contact region and keep the nonoverlapping ends visually distinct. Return one self-contained HTML file.
Working Three.js Starter (lap-joint-contact-area-model-x0265):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lap Joint — Contact-Area Model</title>
<style>
:root {
--bg: #07111d;
--panel: rgba(10, 23, 38, 0.78);
--panel-border: rgba(164, 210, 226, 0.16);
--text: #edf7f8;
--muted: #91a8b3;
--cyan: #41e0ca;
--amber: #e7a552;
--rose: #ef7b72;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 52% 42%, #10283a 0%, #091624 37%, #050c15 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.hero {
position: absolute;
top: 28px;
left: 30px;
width: min(370px, calc(100vw - 60px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 2px;
content: "";
background: var(--cyan);
box-shadow: 0 0 12px rgba(65, 224, 202, 0.65);
}
h1 {
margin: 0;
font-size: clamp(35px, 4vw, 58px);
font-weight: 720;
letter-spacing: -0.055em;
line-height: 0.95;
}
.subtitle {
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
letter-spacing: 0.02em;
}
.readout {
position: absolute;
top: 28px;
right: 28px;
width: 252px;
padding: 18px 19px 16px;
overflow: hidden;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
}
.readout::before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 2px;
content: "";
background: linear-gradient(90deg, var(--cyan), transparent 75%);
}
.readout-title {
margin-bottom: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.metric {
display: flex;
align-items: baseline;
justify-content: space-between;
padding: 8px 0;
border-top: 1px solid rgba(164, 210, 226, 0.1);
}
.metric span {
color: var(--muted);
font-size: 11px;
}
.metric strong {
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 12px;
font-weight: 650;
}
.metric strong.accent {
color: var(--cyan);
}
.toolbar {
position: absolute;
left: 30px;
bottom: 28px;
display: flex;
gap: 9px;
pointer-events: auto;
}
button {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 38px;
padding: 0 13px;
border: 1px solid rgba(164, 210, 226, 0.18);
border-radius: 10px;
background: rgba(10, 23, 38, 0.84);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
backdrop-filter: blur(12px);
}
button:hover {
border-color: rgba(65, 224, 202, 0.55);
background: rgba(15, 37, 52, 0.94);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
button.primary {
border-color: rgba(65, 224, 202, 0.38);
color: #bffaf1;
}
button svg {
width: 14px;
height: 14px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.8;
}
.hint {
position: absolute;
right: 28px;
bottom: 29px;
color: rgba(196, 218, 226, 0.65);
font-size: 10px;
letter-spacing: 0.045em;
text-align: right;
line-height: 1.65;
}
.hint b {
color: rgba(232, 247, 249, 0.9);
font-weight: 650;
}
.legend {
position: absolute;
left: 30px;
bottom: 82px;
display: flex;
flex-wrap: wrap;
gap: 8px 15px;
max-width: 430px;
color: var(--muted);
font-size: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 19px;
height: 7px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 3px;
}
.swatch.lower {
background: linear-gradient(90deg, #71401f, #b8753e);
}
.swatch.upper {
background: linear-gradient(90deg, #a86431, #dda663);
}
.swatch.bond {
background: var(--cyan);
box-shadow: 0 0 8px rgba(65, 224, 202, 0.45);
}
.swatch.contact {
background:
repeating-linear-gradient(45deg, rgba(65,224,202,.42) 0 2px, transparent 2px 5px),
rgba(65, 224, 202, 0.14);
border-color: rgba(65, 224, 202, 0.48);
}
#annotation-layer {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.annotation {
position: absolute;
display: flex;
align-items: center;
gap: 9px;
min-width: 132px;
padding: 8px 11px 8px 9px;
border: 1px solid rgba(176, 213, 225, 0.16);
border-left: 2px solid var(--accent, var(--cyan));
border-radius: 9px;
background: rgba(6, 17, 28, 0.86);
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
opacity: 0;
transform: translate(-50%, -50%);
transition: opacity 160ms ease;
backdrop-filter: blur(10px);
}
.annotation-icon {
display: grid;
flex: 0 0 auto;
width: 19px;
height: 19px;
place-items: center;
border-radius: 50%;
background: color-mix(in srgb, var(--accent) 17%, transparent);
color: var(--accent);
font-size: 9px;
font-weight: 800;
}
.annotation strong {
display: block;
color: #edf8f9;
font-size: 9px;
font-weight: 760;
letter-spacing: 0.09em;
line-height: 1.2;
text-transform: uppercase;
}
.annotation small {
display: block;
margin-top: 3px;
color: var(--muted);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
}
.view-state {
display: inline-flex;
align-items: center;
gap: 6px;
margin-top: 10px;
color: var(--cyan);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.view-state::before {
width: 5px;
height: 5px;
content: "";
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 8px currentColor;
}
@media (max-width: 760px) {
.hero {
top: 20px;
left: 20px;
}
h1 {
font-size: 38px;
}
.subtitle {
font-size: 11px;
}
.readout {
top: auto;
right: 18px;
bottom: 76px;
width: 210px;
padding: 13px 15px;
}
.readout-title,
.metric:nth-of-type(n + 4) {
display: none;
}
.metric {
padding: 5px 0;
}
.toolbar {
left: 18px;
bottom: 18px;
}
.legend {
display: none;
}
.hint {
display: none;
}
.annotation {
min-width: auto;
padding: 6px 8px;
}
.annotation small {
display: none;
}
.annotation strong {
font-size: 8px;
}
}
</style>
</head>
<body>
<div class="ui">
<header class="hero">
<div class="eyebrow">Assembly study / 01</div>
<h1>Lap Joint</h1>
<p class="subtitle">Wood-to-wood contact-area model</p>
</header>
<section class="readout" aria-label="Model dimensions">
<div class="readout-title">Model readout</div>
<div class="metric">
<span>Joint type</span>
<strong>Single lap</strong>
</div>
<div class="metric">
<span>Shared contact</span>
<strong class="accent">7.50 × 2.00</strong>
</div>
<div class="metric">
<span>Bond thickness</span>
<strong>0.08 u</strong>
</div>
<div class="metric">
<span>Contact area</span>
<strong>15.00 u²</strong>
</div>
<div class="view-state" id="view-state">Assembled view</div>
</section>
<div class="legend" aria-label="Legend">
<div class="legend-item"><i class="swatch lower"></i>Lower strip</div>
<div class="legend-item"><i class="swatch upper"></i>Upper strip</div>
<div class="legend-item"><i class="swatch bond"></i>Bond layer</div>
<div class="legend-item"><i class="swatch contact"></i>Shared contact</div>
</div>
<div class="toolbar">
<button class="primary" id="explode-button" type="button" aria-pressed="false">
<svg viewBox="0 0 20 20" aria-hidden="true">
<path d="M3 6h14M3 14h14M7 3v3M13 14v3" />
<path d="m5 4 2-2 2 2M11 16l2 2 2-2" />
</svg>
<span>Explode layers</span>
</button>
<button id="reset-button" type="button" title="Reset camera">
<svg viewBox="0 0 20 20" aria-hidden="true">
<path d="M4 7a6.5 6.5 0 1 1-.2 6" />
<path d="M4 3v4h4" />
</svg>
Reset view
</button>
</div>
<div class="hint">
<b>Drag</b> orbit · <b>Shift-drag</b> pan · <b>Scroll</b> zoom<br />
Arrow keys orbit · R resets view
</div>
<div id="annotation-layer">
<div class="annotation" id="label-contact" style="--accent:#41e0ca">
<span class="annotation-icon">C</span>
<div>
<strong>Shared contact</strong>
<small>7.50 × 2.00 footprint</small>
</div>
</div>
<div class="annotation" id="label-bond" style="--accent:#41e0ca">
<span class="annotation-icon">B</span>
<div>
<strong>Bond layer</strong>
<small>0.08 model-unit film</small>
</div>
</div>
<div class="annotation" id="label-end-a" style="--accent:#e7a552">
<span class="annotation-icon">A</span>
<div>
<strong>Free end A</strong>
<small>Lower strip · 3.50 exposed</small>
</div>
</div>
<div class="annotation" id="label-end-b" style="--accent:#ef7b72">
<span class="annotation-icon">B</span>
<div>
<strong>Free end B</strong>
<small>Upper strip · 1.50 exposed</small>
</div>
</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";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x07111d, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x07111d, 19, 38);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// -------------------------------------------------------------------------
// Camera controls implemented directly, without addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0.45, -0.02, 0);
const defaultView = {
theta: 0.69,
phi: 1.03,
radius: 16.3,
target: new THREE.Vector3(0.45, -0.02, 0)
};
let theta = defaultView.theta;
let phi = defaultView.phi;
let radius = defaultView.radius;
let dragging = false;
let dragMode = "orbit";
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const sinPhi = Math.sin(phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetView() {
theta = defaultView.theta;
phi = defaultView.phi;
radius = defaultView.radius;
cameraTarget.copy(defaultView.target);
updateCamera();
}
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (dragMode === "orbit") {
theta -= dx * 0.006;
phi = THREE.MathUtils.clamp(phi - dy * 0.005, 0.23, 1.43);
} else {
const elements = camera.matrixWorld.elements;
const right = new THREE.Vector3(elements[0], elements[1], elements[2]);
const up = new THREE.Vector3(elements[4], elements[5], elements[6]);
const panScale = radius * 0.00115;
cameraTarget.addScaledVector(right, -dx * panScale);
cameraTarget.addScaledVector(up, dy * panScale);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
8.5,
28
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
resetView();
return;
}
if (key === "arrowleft") theta -= 0.09;
if (key === "arrowright") theta += 0.09;
if (key === "arrowup") phi = Math.max(0.23, phi - 0.07);
if (key === "arrowdown") phi = Math.min(1.43, phi + 0.07);
if (key === "+" || key === "=") radius = Math.max(8.5, radius - 0.7);
if (key === "-") radius = Math.min(28, radius + 0.7);
updateCamera();
});
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xc6e9ff, 0x18202a, 1.8);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe0bd, 3.4);
keyLight.position.set(3, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x7bc8ff, 1.4);
fillLight.position.set(-8, 4, -6);
scene.add(fillLight);
const cyanLight = new THREE.PointLight(0x38e0cf, 22, 16, 2);
cyanLight.position.set(2.5, 2.2, 4.5);
scene.add(cyanLight);
// -------------------------------------------------------------------------
// Procedural wood textures
// -------------------------------------------------------------------------
function seededRandom(seed) {
return function random() {
let value = seed += 0x6d2b79f5;
value = Math.imul(value ^ (value >>> 15), value | 1);
value ^= value + Math.imul(value ^ (value >>> 7), value | 61);
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
};
}
function createWoodTexture(base, highlight, shadow, seed) {
const random = seededRandom(seed);
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 1024;
textureCanvas.height = 256;
const context = textureCanvas.getContext("2d");
context.fillStyle = base;
context.fillRect(0, 0, textureCanvas.width, textureCanvas.height);
// Long, gently warped grain lines.
for (let index = 0; index < 185; index += 1) {
const baseY = random() * 256;
const amplitude = 1 + random() * 7;
const frequency = 0.006 + random() * 0.014;
const phase = random() * Math.PI * 2;
context.beginPath();
for (let x = 0; x <= 1024; x += 8) {
const y =
baseY +
Math.sin(x * frequency + phase) * amplitude +
Math.sin(x * frequency * 0.37 + phase) * amplitude * 0.42;
if (x === 0) context.moveTo(x, y);
else context.lineTo(x, y);
}
context.strokeStyle =
index % 4 === 0
? `rgba(255, 226, 178, ${0.035 + random() * 0.06})`
: `rgba(48, 23, 10, ${0.08 + random() * 0.18})`;
context.lineWidth = 0.5 + random() * 1.8;
context.stroke();
}
// Subtle highlighted fibers.
for (let index = 0; index < 34; index += 1) {
const y = random() * 256;
context.beginPath();
context.moveTo(0, y);
context.bezierCurveTo(
280,
y + (random() - 0.5) * 14,
720,
y + (random() - 0.5) * 14,
1024,
y + (random() - 0.5) * 8
);
context.strokeStyle = `rgba(255, 226, 183, ${0.04 + random() * 0.07})`;
context.lineWidth = 0.6 + random() * 1.3;
context.stroke();
}
// Small knots and concentric growth rings.
for (let index = 0; index < 9; index += 1) {
const x = 40 + random() * 940;
const y = 24 + random() * 208;
const radiusX = 10 + random() * 35;
const radiusY = 2.5 + random() * 8;
context.save();
context.translate(x, y);
context.rotate((random() - 0.5) * 0.18);
for (let ring = 0; ring < 4; ring += 1) {
context.beginPath();
context.ellipse(
0,
0,
radiusX + ring * 4,
radiusY + ring * 1.3,
0,
0,
Math.PI * 2
);
context.strokeStyle = `rgba(57, 27, 12, ${0.18 - ring * 0.025})`;
context.lineWidth = 1.2;
context.stroke();
}
context.restore();
}
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
return texture;
}
const lowerWoodTexture = createWoodTexture(
"#9c6033",
"#d79b59",
"#442411",
1427
);
const upperWoodTexture = createWoodTexture(
"#c58a4e",
"#efc27d",
"#75401f",
8129
);
const lowerEndTexture = createWoodTexture(
"#75401f",
"#b8753e",
"#32170b",
113
);
const upperEndTexture = createWoodTexture(
"#dfb77d",
"#f4d29d",
"#8d552c",
774
);
// -------------------------------------------------------------------------
// Model dimensions
// -------------------------------------------------------------------------
const LOWER_LENGTH = 11.0;
const UPPER_LENGTH = 9.0;
const STRIP_WIDTH = 2.0;
const STRIP_THICKNESS = 0.56;
const BOND_THICKNESS = 0.08;
const LOWER_CENTER_X = 0.0;
const UPPER_CENTER_X = 2.5;
const CONTACT_START = -2.0;
const CONTACT_END = 5.5;
const CONTACT_LENGTH = CONTACT_END - CONTACT_START;
const CONTACT_CENTER = (CONTACT_START + CONTACT_END) / 2;
const model = new THREE.Group();
scene.add(model);
// -------------------------------------------------------------------------
// Wooden strips
// -------------------------------------------------------------------------
function createStrip({
length,
width,
thickness,
woodTexture,
endTexture,
exposedEnd,
y
}) {
const group = new THREE.Group();
const sideMaterial = new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0xffffff,
roughness: 0.72,
metalness: 0.02
});
const topMaterial = sideMaterial.clone();
topMaterial.color.set(0xfff8ee);
const endMaterial = new THREE.MeshStandardMaterial({
map: endTexture,
color: 0xffffff,
roughness: 0.79,
metalness: 0.01
});
const bottomMaterial = sideMaterial.clone();
bottomMaterial.color.set(0x8f7c68);
// BoxGeometry material order: +X, -X, +Y, -Y, +Z, -Z.
const materials =
exposedEnd === "right"
? [endMaterial, sideMaterial, topMaterial, bottomMaterial, sideMaterial, sideMaterial]
: [sideMaterial, endMaterial, topMaterial, bottomMaterial, sideMaterial, sideMaterial];
const geometry = new THREE.BoxGeometry(length, thickness, width);
const mesh = new THREE.Mesh(geometry, materials);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
const edgeGeometry = new THREE.EdgesGeometry(geometry, 22);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x2b170c,
transparent: true,
opacity: 0.42
});
const edges = new THREE.LineSegments(edgeGeometry, edgeMaterial);
group.add(edges);
// A fine highlight along the top perimeter adds edge definition.
const halfLength = length / 2;
const halfWidth = width / 2;
const topY = thickness / 2 + 0.003;
const topPoints = [
new THREE.Vector3(-halfLength, topY, -halfWidth),
new THREE.Vector3(halfLength, topY, -halfWidth),
new THREE.Vector3(halfLength, topY, halfWidth),
new THREE.Vector3(-halfLength, topY, halfWidth),
new THREE.Vector3(-halfLength, topY, -halfWidth)
];
const topLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(topPoints),
new THREE.LineBasicMaterial({
color: 0xffe1ad,
transparent: true,
opacity: 0.28
})
);
group.add(topLine);
group.position.y = y;
return group;
}
const lowerStrip = createStrip({
length: LOWER_LENGTH,
width: STRIP_WIDTH,
thickness: STRIP_THICKNESS,
woodTexture: lowerWoodTexture,
endTexture: lowerEndTexture,
exposedEnd: "left",
y: -0.31
});
lowerStrip.position.x = LOWER_CENTER_X;
model.add(lowerStrip);
const upperStrip = createStrip({
length: UPPER_LENGTH,
width: STRIP_WIDTH,
thickness: STRIP_THICKNESS,
woodTexture: upperWoodTexture,
endTexture: upperEndTexture,
exposedEnd: "right",
y: 0.33
});
upperStrip.position.x = UPPER_CENTER_X;
model.add(upperStrip);
// -------------------------------------------------------------------------
// Thin colored bond layer, limited exactly to the shared region
// -------------------------------------------------------------------------
const bondGroup = new THREE.Group();
bondGroup.position.set(CONTACT_CENTER, 0.01, 0);
const bondGeometry = new THREE.BoxGeometry(
CONTACT_LENGTH,
BOND_THICKNESS,
STRIP_WIDTH + 0.025
);
const bondMaterial = new THREE.MeshStandardMaterial({
color: 0x35d8c4,
emissive: 0x0c766d,
emissiveIntensity: 0.72,
roughness: 0.32,
metalness: 0.03,
transparent: true,
opacity: 0.96
});
const bondMesh = new THREE.Mesh(bondGeometry, bondMaterial);
bondMesh.castShadow = true;
bondMesh.receiveShadow = true;
bondGroup.add(bondMesh);
const bondEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(bondGeometry),
new THREE.LineBasicMaterial({
color: 0xa2fff4,
transparent: true,
opacity: 0.8
})
);
bondGroup.add(bondEdges);
// A narrow glossy bead makes the adhesive film legible at the front edge.
const bondBead = new THREE.Mesh(
new THREE.BoxGeometry(
CONTACT_LENGTH,
BOND_THICKNESS * 0.72,
0.034
),
new THREE.MeshStandardMaterial({
color: 0x73ffe9,
emissive: 0x27cdb9,
emissiveIntensity: 1.1,
roughness: 0.24
})
);
bondBead.position.z = STRIP_WIDTH / 2 + 0.014;
bondGroup.add(bondBead);
model.add(bondGroup);
// -------------------------------------------------------------------------
// Shared-contact footprint, dashed boundary, and dimension bracket
// -------------------------------------------------------------------------
const contactLocalCenter = CONTACT_CENTER - UPPER_CENTER_X;
const contactTopY = STRIP_THICKNESS / 2 + 0.012;
const contactFill = new THREE.Mesh(
new THREE.PlaneGeometry(CONTACT_LENGTH, STRIP_WIDTH),
new THREE.MeshBasicMaterial({
color: 0x43e4cf,
transparent: true,
opacity: 0.105,
side: THREE.DoubleSide,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -1,
polygonOffsetUnits: -1
})
);
contactFill.rotation.x = -Math.PI / 2;
contactFill.position.set(contactLocalCenter, contactTopY, 0);
contactFill.renderOrder = 2;
upperStrip.add(contactFill);
const boundaryX0 = contactLocalCenter - CONTACT_LENGTH / 2;
const boundaryX1 = contactLocalCenter + CONTACT_LENGTH / 2;
const boundaryY = contactTopY + 0.005;
const boundaryPoints = [
new THREE.Vector3(boundaryX0, boundaryY, -STRIP_WIDTH / 2),
new THREE.Vector3(boundaryX1, boundaryY, -STRIP_WIDTH / 2),
new THREE.Vector3(boundaryX1, boundaryY, STRIP_WIDTH / 2),
new THREE.Vector3(boundaryX0, boundaryY, STRIP_WIDTH / 2),
new THREE.Vector3(boundaryX0, boundaryY, -STRIP_WIDTH / 2)
];
const boundary = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(boundaryPoints),
new THREE.LineDashedMaterial({
color: 0x55f0d9,
dashSize: 0.16,
gapSize: 0.1,
transparent: true,
opacity: 0.92,
depthWrite: false
})
);
boundary.computeLineDistances();
boundary.renderOrder = 3;
upperStrip.add(boundary);
const bracketMaterial = new THREE.LineBasicMaterial({
color: 0x7af4e4,
transparent: true,
opacity: 0.72,
depthWrite: false
});
const bracketZ = STRIP_WIDTH / 2 + 0.23;
const bracketY = STRIP_THICKNESS / 2 + 0.025;
const bracketPoints = [
new THREE.Vector3(boundaryX0, bracketY, bracketZ),
new THREE.Vector3(boundaryX1, bracketY, bracketZ),
new THREE.Vector3(boundaryX0, bracketY, bracketZ - 0.11),
new THREE.Vector3(boundaryX0, bracketY, bracketZ + 0.11),
new THREE.Vector3(boundaryX1, bracketY, bracketZ - 0.11),
new THREE.Vector3(boundaryX1, bracketY, bracketZ + 0.11)
];
const bracket = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(bracketPoints),
bracketMaterial
);
upperStrip.add(bracket);
// -------------------------------------------------------------------------
// Ground and reference grid
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(48, 48),
new THREE.MeshStandardMaterial({
color: 0x091521,
roughness: 0.96,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.64;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x285169, 0x173344);
grid.position.y = -0.632;
grid.material.transparent = true;
grid.material.opacity = 0.23;
grid.material.depthWrite = false;
scene.add(grid);
// -------------------------------------------------------------------------
// Projected DOM annotations and 3D leader lines
// -------------------------------------------------------------------------
const annotationDefinitions = [
{
element: document.getElementById("label-contact"),
anchor: () => upperStrip.localToWorld(
new THREE.Vector3(contactLocalCenter, STRIP_THICKNESS / 2 + 0.04, 1.03)
),
label: (lift) => new THREE.Vector3(1.2, 1.52 + lift, 0.25)
},
{
element: document.getElementById("label-bond"),
anchor: () => bondGroup.localToWorld(
new THREE.Vector3(0, 0, STRIP_WIDTH / 2 + 0.035)
),
label: (lift) => new THREE.Vector3(0.15, -0.56 + lift, 1.72)
},
{
element: document.getElementById("label-end-a"),
anchor: () => new THREE.Vector3(-4.25, -0.02, 1.04),
label: () => new THREE.Vector3(-4.45, 0.98, 2.02)
},
{
element: document.getElementById("label-end-b"),
anchor: () => upperStrip.localToWorld(
new THREE.Vector3(UPPER_LENGTH / 2 - 0.72, 0.3, 0.93)
),
label: (lift) => new THREE.Vector3(6.35, 1.43 + lift, 1.18)
}
];
const annotationItems = annotationDefinitions.map((definition) => {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0x8db5c0,
transparent: true,
opacity: 0.44,
depthTest: false,
depthWrite: false
})
);
line.renderOrder = 10;
scene.add(line);
const dot = new THREE.Mesh(
new THREE.SphereGeometry(0.035, 12, 8),
new THREE.MeshBasicMaterial({
color: 0xd9fff9,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
dot.renderOrder = 11;
scene.add(dot);
return { definition, line, dot };
});
const projected = new THREE.Vector3();
function updateAnnotations(upperLift, bondLift) {
for (const item of annotationItems) {
const anchor = item.definition.anchor();
const labelPosition = item.definition.label(
item.definition.element.id === "label-end-b" ? upperLift :
item.definition.element.id === "label-bond" ? bondLift : 0
);
const positions = item.line.geometry.attributes.position;
positions.setXYZ(0, anchor.x, anchor.y, anchor.z);
positions.setXYZ(1, labelPosition.x, labelPosition.y, labelPosition.z);
positions.needsUpdate = true;
item.line.geometry.computeBoundingSphere();
item.dot.position.copy(anchor);
projected.copy(labelPosition).project(camera);
const visible =
projected.z >= -1 &&
projected.z <= 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
item.definition.element.style.opacity = visible ? "1" : "0";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
item.definition.element.style.left = `${x}px`;
item.definition.element.style.top = `${y}px`;
}
}
}
// -------------------------------------------------------------------------
// Exploded inspection control
// -------------------------------------------------------------------------
const explodeButton = document.getElementById("explode-button");
const viewState = document.getElementById("view-state");
let explodeTarget = 0;
let explodeAmount = 0;
explodeButton.addEventListener("click", () => {
explodeTarget = explodeTarget > 0.5 ? 0 : 1;
const expanded = explodeTarget > 0.5;
explodeButton.setAttribute("aria-pressed", String(expanded));
explodeButton.querySelector("span").textContent = expanded
? "Assemble joint"
: "Explode layers";
viewState.textContent = expanded
? "Separated inspection"
: "Assembled view";
});
document.getElementById("reset-button").addEventListener("click", resetView);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-delta * 6.5);
explodeAmount += (explodeTarget - explodeAmount) * smoothing;
const upperLift = explodeAmount * 1.25;
const bondLift = explodeAmount * 0.38;
upperStrip.position.y = 0.33 + upperLift;
bondGroup.position.y = 0.01 + bondLift;
model.updateMatrixWorld(true);
updateAnnotations(upperLift, bondLift);
renderer.render(scene, camera);
}
animate();
// -------------------------------------------------------------------------
// Resize handling
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
</script>
</body>
</html>
```