Prompt specification
Build or customize the Three.js 3D scene "Sofa module connection edges" 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: Sofa module connection edges
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sofa-module-connection-edges-x0201
Scene Description Prompt:
Stylized sofa modules show a matching connection and a rotated mismatch through visible connector edges. Use Three.js from cdnjs in one HTML file.
Working Three.js Starter (sofa-module-connection-edges-x0201):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Modular Sofa — Connector Alignment Study</title>
<style>
:root {
--ink: #263230;
--muted: #66706d;
--paper: #f1eee8;
--cyan: #12cdb9;
--coral: #ff654f;
--panel: rgba(255, 255, 255, 0.78);
--border: rgba(38, 50, 48, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
header {
position: fixed;
top: 28px;
left: 32px;
z-index: 10;
pointer-events: none;
max-width: 410px;
}
.eyebrow {
margin-bottom: 9px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
color: var(--muted);
}
h1 {
margin: 0;
font-size: clamp(26px, 3vw, 43px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 1.02;
}
header p {
margin: 12px 0 0;
max-width: 350px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
position: fixed;
top: 30px;
right: 30px;
z-index: 10;
display: flex;
gap: 8px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 8px 11px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(255, 255, 255, 0.65);
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(18, 205, 185, 0.13);
}
.dot.coral {
background: var(--coral);
box-shadow: 0 0 0 4px rgba(255, 101, 79, 0.13);
}
.status-card {
position: fixed;
bottom: 28px;
z-index: 10;
width: 230px;
padding: 16px 17px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(16px);
box-shadow: 0 15px 45px rgba(46, 52, 49, 0.08);
}
#matchCard {
left: 30px;
}
#mismatchCard {
left: 274px;
}
.card-top {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.status-line {
width: 20px;
height: 3px;
border-radius: 4px;
background: var(--cyan);
}
.status-line.coral {
background: var(--coral);
}
.status-card strong {
display: block;
margin-bottom: 5px;
font-size: 14px;
}
.status-card small {
display: block;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.controls {
position: fixed;
right: 30px;
bottom: 28px;
z-index: 10;
width: 245px;
padding: 15px 16px 14px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(16px);
box-shadow: 0 15px 45px rgba(46, 52, 49, 0.08);
}
.control-label {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#angleValue {
color: var(--coral);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0 12px;
border-radius: 4px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--coral) 0%,
var(--coral) 60%,
rgba(38, 50, 48, 0.13) 60%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid white;
border-radius: 50%;
appearance: none;
background: var(--coral);
box-shadow: 0 2px 8px rgba(38, 50, 48, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid white;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 2px 8px rgba(38, 50, 48, 0.25);
}
.control-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
color: var(--muted);
font-size: 10px;
}
button {
padding: 7px 10px;
border: 1px solid var(--border);
border-radius: 8px;
background: white;
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 750;
cursor: pointer;
}
button:hover {
border-color: rgba(38, 50, 48, 0.25);
transform: translateY(-1px);
}
.world-label {
position: fixed;
z-index: 8;
min-width: 144px;
padding: 9px 11px;
border: 1px solid rgba(38, 50, 48, 0.12);
border-radius: 10px;
background: rgba(255, 255, 255, 0.82);
backdrop-filter: blur(10px);
box-shadow: 0 8px 25px rgba(38, 50, 48, 0.08);
pointer-events: none;
transform: translate(-50%, -100%);
}
.world-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 25px;
background: rgba(38, 50, 48, 0.25);
content: "";
}
.world-label span {
display: block;
margin-bottom: 3px;
color: var(--cyan);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.world-label.coral span {
color: var(--coral);
}
.world-label strong {
font-size: 11px;
font-weight: 700;
}
@media (max-width: 900px) {
header {
top: 20px;
left: 20px;
}
header p {
display: none;
}
.legend {
top: 20px;
right: 20px;
}
.status-card {
bottom: 18px;
width: 190px;
}
#matchCard {
left: 18px;
}
#mismatchCard {
left: 220px;
}
.controls {
right: 18px;
bottom: 18px;
width: 210px;
}
}
@media (max-width: 680px) {
.legend,
#mismatchCard {
display: none;
}
header {
top: 18px;
left: 18px;
}
h1 {
max-width: 270px;
font-size: 28px;
}
#matchCard {
left: 18px;
bottom: 142px;
width: 170px;
}
.controls {
right: 18px;
bottom: 18px;
left: 18px;
width: auto;
}
.world-label {
min-width: 115px;
padding: 7px 9px;
}
.world-label strong {
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive 3D sofa connector comparison"></div>
<header>
<div class="eyebrow">Connector alignment study · 01</div>
<h1>Modular sofa<br />connection logic</h1>
<p>
A matched datum sits beside a yawed module. Colored connector edges reveal
whether the mating geometry shares the same plane.
</p>
</header>
<div class="legend">
<span><i class="dot"></i>Matched edge</span>
<span><i class="dot coral"></i>Mismatch edge</span>
</div>
<div id="matchLabel" class="world-label">
<span>01 · Matched datum</span>
<strong>Connector edges aligned</strong>
</div>
<div id="mismatchLabel" class="world-label coral">
<span>02 · Rotated module</span>
<strong id="liveAngle">24° yaw offset</strong>
</div>
<div id="matchCard" class="status-card">
<div class="card-top">
<i class="status-line"></i>
Matched connection
</div>
<strong>Shared connector plane</strong>
<small>The cyan edge frames register without positional offset.</small>
</div>
<div id="mismatchCard" class="status-card">
<div class="card-top">
<i class="status-line coral"></i>
Rotated mismatch
</div>
<strong id="mismatchTitle">24° yaw error</strong>
<small id="angleCopy">The coral edge shifts away from the cyan datum.</small>
</div>
<div class="controls">
<div class="control-label">
<span>Mismatch rotation</span>
<span id="angleValue">24°</span>
</div>
<input
id="angle"
type="range"
min="0"
max="40"
value="24"
step="1"
aria-label="Mismatch rotation angle"
/>
<div class="control-footer">
<span>Drag to orbit · Scroll to zoom</span>
<button id="resetView" type="button">Reset view</button>
</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 host = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf1eee8);
scene.fog = new THREE.Fog(0xf1eee8, 28, 54);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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;
host.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xfff8ec, 0x8a9993, 2.2);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff7e9, 3.2);
keyLight.position.set(-7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -18;
keyLight.shadow.camera.right = 18;
keyLight.shadow.camera.top = 14;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xb9fff4, 1.15);
rimLight.position.set(9, 7, -8);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xe9e5dd,
roughness: 0.95,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(44, 44, 0xa8afa9, 0xc9cdc7);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.22;
grid.material.depthWrite = false;
scene.add(grid);
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function roundedBox(width, height, depth, radius = 0.14) {
const w = width / 2;
const h = height / 2;
const r = Math.min(radius, w * 0.45, h * 0.45);
const shape = new THREE.Shape();
shape.moveTo(-w + r, -h);
shape.lineTo(w - r, -h);
shape.quadraticCurveTo(w, -h, w, -h + r);
shape.lineTo(w, h - r);
shape.quadraticCurveTo(w, h, w - r, h);
shape.lineTo(-w + r, h);
shape.quadraticCurveTo(-w, h, -w, h - r);
shape.lineTo(-w, -h + r);
shape.quadraticCurveTo(-w, -h, -w + r, -h);
const bevel = Math.min(0.035, r * 0.28);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: true,
bevelSegments: 3,
steps: 1,
bevelSize: bevel,
bevelThickness: bevel,
curveSegments: 8
});
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
return geometry;
}
function makeMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
...options
});
}
const cyan = 0x12cdb9;
const coral = 0xff654f;
const sage = {
frame: makeMaterial(0x47635e),
cushion: makeMaterial(0x6d8f86, { roughness: 0.93 }),
pillow: makeMaterial(0x7fa097, { roughness: 0.96 }),
seam: new THREE.LineBasicMaterial({
color: 0xaec4bd,
transparent: true,
opacity: 0.75
})
};
const clay = {
frame: makeMaterial(0x945844),
cushion: makeMaterial(0xb8735b, { roughness: 0.93 }),
pillow: makeMaterial(0xc98a70, { roughness: 0.96 }),
seam: new THREE.LineBasicMaterial({
color: 0xe0ad94,
transparent: true,
opacity: 0.75
})
};
const darkHardware = makeMaterial(0x26312f, {
roughness: 0.38,
metalness: 0.48
});
function addShadowed(mesh) {
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeSofa(armSide, palette) {
const root = new THREE.Group();
const base = addShadowed(
new THREE.Mesh(roundedBox(2.45, 0.38, 1.75, 0.16), palette.frame)
);
base.position.y = 0.48;
root.add(base);
const seat = addShadowed(
new THREE.Mesh(roundedBox(2.22, 0.28, 1.52, 0.13), palette.cushion)
);
seat.position.set(0, 0.79, 0.05);
root.add(seat);
const back = addShadowed(
new THREE.Mesh(roundedBox(2.45, 1.28, 0.4, 0.18), palette.frame)
);
back.position.set(0, 1.34, -0.64);
root.add(back);
const pillow = addShadowed(
new THREE.Mesh(roundedBox(2.12, 0.92, 0.25, 0.13), palette.pillow)
);
pillow.position.set(0, 1.42, -0.39);
root.add(pillow);
const arm = addShadowed(
new THREE.Mesh(roundedBox(0.36, 1.02, 1.63, 0.14), palette.frame)
);
arm.position.set(armSide * 1.06, 0.94, -0.03);
root.add(arm);
// Seat piping.
const seamGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.89, 0.925, 0.814),
new THREE.Vector3(0.89, 0.925, 0.814)
]);
root.add(new THREE.Line(seamGeometry, palette.seam));
// Back-cushion seam.
const backSeamGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.91, 1.43, -0.257),
new THREE.Vector3(0.91, 1.43, -0.257)
]);
root.add(new THREE.Line(backSeamGeometry, palette.seam));
// Small upholstery buttons.
const buttonGeometry = new THREE.SphereGeometry(0.043, 12, 8);
const buttonMaterial = makeMaterial(palette.frame, { roughness: 1 });
for (const x of [-0.63, 0, 0.63]) {
const button = new THREE.Mesh(buttonGeometry, buttonMaterial);
button.position.set(x, 1.44, -0.252);
button.scale.z = 0.5;
root.add(button);
}
// Tapered legs.
const legGeometry = new THREE.CylinderGeometry(0.065, 0.085, 0.3, 10);
const legMaterial = makeMaterial(0x393c38, {
roughness: 0.42,
metalness: 0.42
});
for (const x of [-0.88, 0.88]) {
for (const z of [-0.55, 0.55]) {
const leg = addShadowed(
new THREE.Mesh(legGeometry, legMaterial)
);
leg.position.set(x, 0.18, z);
root.add(leg);
}
}
return root;
}
// ------------------------------------------------------------
// Visible connector hardware
// ------------------------------------------------------------
const animatedConnectors = [];
function createConnector(side, accent, isGhost = false) {
const group = new THREE.Group();
const accentMaterial = makeMaterial(accent, {
emissive: accent,
emissiveIntensity: 0.17,
roughness: 0.38,
metalness: 0.28
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: accent,
transparent: true,
opacity: isGhost ? 0.52 : 1,
depthTest: !isGhost,
depthWrite: false
});
const plateGeometry = new THREE.BoxGeometry(0.085, 0.49, 0.91);
if (isGhost) {
const ghostEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(plateGeometry),
new THREE.LineDashedMaterial({
color: accent,
dashSize: 0.075,
gapSize: 0.045,
transparent: true,
opacity: 0.62,
depthTest: false,
depthWrite: false
})
);
ghostEdges.computeLineDistances();
ghostEdges.renderOrder = 8;
group.add(ghostEdges);
for (const y of [-0.14, 0.14]) {
const railGeometry = new THREE.BoxGeometry(0.23, 0.075, 0.14);
const rail = new THREE.LineSegments(
new THREE.EdgesGeometry(railGeometry),
ghostEdges.material
);
rail.computeLineDistances();
rail.position.set(side * 0.12, y, 0);
rail.renderOrder = 8;
group.add(rail);
}
return { group, material: null, edgeMaterial, ring: null };
}
const plate = addShadowed(
new THREE.Mesh(plateGeometry, darkHardware)
);
group.add(plate);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(plateGeometry),
edgeMaterial
);
edges.renderOrder = 6;
group.add(edges);
// Two bright engagement rails make the connection edge easy to read.
for (const y of [-0.14, 0.14]) {
const rail = addShadowed(
new THREE.Mesh(
new THREE.BoxGeometry(0.23, 0.075, 0.14),
accentMaterial
)
);
rail.position.set(side * 0.12, y, 0);
group.add(rail);
}
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.115, 0.023, 8, 28),
accentMaterial
);
ring.rotation.y = Math.PI / 2;
ring.position.x = side * 0.072;
group.add(ring);
const result = {
group,
material: accentMaterial,
edgeMaterial,
ring
};
animatedConnectors.push(result);
return result;
}
// ------------------------------------------------------------
// Matched pair
// ------------------------------------------------------------
const matchLeft = makeSofa(-1, sage);
matchLeft.position.x = -6.0;
scene.add(matchLeft);
const matchRight = makeSofa(1, sage);
matchRight.position.x = -3.42;
scene.add(matchRight);
const matchLeftConnector = createConnector(1, cyan);
matchLeftConnector.group.position.set(1.25, 0.75, 0.19);
matchLeft.add(matchLeftConnector.group);
const matchRightConnector = createConnector(-1, cyan);
matchRightConnector.group.position.set(-1.25, 0.75, 0.19);
matchRight.add(matchRightConnector.group);
// A subtle cyan datum marker above the matched seam.
const matchDatum = new THREE.Mesh(
new THREE.TorusGeometry(0.115, 0.014, 6, 24),
new THREE.MeshBasicMaterial({ color: cyan })
);
matchDatum.rotation.x = Math.PI / 2;
matchDatum.position.set(-4.7, 2.03, 0.19);
scene.add(matchDatum);
// ------------------------------------------------------------
// Rotated / mismatched pair
// ------------------------------------------------------------
const mismatchLeft = makeSofa(-1, clay);
mismatchLeft.position.x = 2.0;
scene.add(mismatchLeft);
const mismatchRight = makeSofa(1, clay);
mismatchRight.position.x = 4.85;
scene.add(mismatchRight);
const mismatchConnector = createConnector(-1, coral);
mismatchConnector.group.position.set(-1.25, 0.75, 0.19);
mismatchRight.add(mismatchConnector.group);
// The expected position of the right-hand connector, shown as a datum.
const ghostConnector = createConnector(-1, cyan, true);
ghostConnector.group.position.set(3.6, 0.75, 0.19);
scene.add(ghostConnector.group);
// Neutral socket on the fixed module.
const socketGeometry = new THREE.BoxGeometry(0.075, 0.46, 0.88);
const socket = addShadowed(
new THREE.Mesh(socketGeometry, darkHardware)
);
socket.position.set(3.25, 0.75, 0.19);
mismatchLeft.add(socket);
const socketEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(socketGeometry),
new THREE.LineBasicMaterial({
color: 0x81908b,
transparent: true,
opacity: 0.72
})
);
socketEdges.position.copy(socket.position);
mismatchLeft.add(socketEdges);
// ------------------------------------------------------------
// Rotation arc and target datum
// ------------------------------------------------------------
const arcGroup = new THREE.Group();
scene.add(arcGroup);
const arcPivot = new THREE.Vector3(4.85, 2.27, 0.0);
const arcRadius = 1.17;
const targetLineGeometry = new THREE.BufferGeometry().setFromPoints([
arcPivot.clone(),
new THREE.Vector3(arcPivot.x - arcRadius, arcPivot.y, arcPivot.z)
]);
const targetLine = new THREE.Line(
targetLineGeometry,
new THREE.LineDashedMaterial({
color: cyan,
dashSize: 0.08,
gapSize: 0.055,
transparent: true,
opacity: 0.58,
depthTest: false
})
);
targetLine.computeLineDistances();
targetLine.renderOrder = 7;
arcGroup.add(targetLine);
const arrowGeometry = new THREE.ConeGeometry(0.085, 0.21, 12);
const arrowMaterial = new THREE.MeshBasicMaterial({ color: coral });
function updateMismatchAngle(degrees) {
const radians = THREE.MathUtils.degToRad(degrees);
mismatchRight.rotation.y = radians;
for (const child of [...arcGroup.children]) {
if (child !== targetLine) {
if (child.geometry) child.geometry.dispose();
arcGroup.remove(child);
}
}
const points = [];
const segments = Math.max(2, Math.ceil(degrees * 1.5));
for (let i = 0; i <= segments; i++) {
const t = radians * (i / segments);
points.push(
new THREE.Vector3(
arcPivot.x - Math.cos(t) * arcRadius,
arcPivot.y,
arcPivot.z + Math.sin(t) * arcRadius
)
);
}
if (degrees > 0.5) {
const arc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: coral,
transparent: true,
opacity: 0.92,
depthTest: false
})
);
arc.renderOrder = 9;
arcGroup.add(arc);
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
arrow.position.copy(points[points.length - 1]);
const tangent = new THREE.Vector3(
Math.sin(radians),
0,
Math.cos(radians)
).normalize();
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
arrow.renderOrder = 9;
arcGroup.add(arrow);
}
document.getElementById("angleValue").textContent = `${degrees}°`;
document.getElementById("liveAngle").textContent =
degrees === 0 ? "0° · aligned" : `${degrees}° yaw offset`;
document.getElementById("mismatchTitle").textContent =
degrees === 0 ? "No yaw error" : `${degrees}° yaw error`;
document.getElementById("angleCopy").textContent =
degrees === 0
? "The module now shares the cyan datum plane."
: "The coral edge shifts away from the cyan datum.";
const percentage = (degrees / 40) * 100;
const slider = document.getElementById("angle");
slider.style.background = `linear-gradient(
to right,
var(--coral) 0%,
var(--coral) ${percentage}%,
rgba(38, 50, 48, 0.13) ${percentage}%
)`;
}
document.getElementById("angle").addEventListener("input", (event) => {
updateMismatchAngle(Number(event.target.value));
});
updateMismatchAngle(24);
// ------------------------------------------------------------
// Custom orbit camera controls — no addons
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.8, 0),
theta: -0.61,
phi: 1.12,
radius: 20.8
};
function updateCamera() {
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);
camera.updateMatrixWorld();
}
updateCamera();
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
cameraState.theta -= dx * 0.0052;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.0048,
0.48,
1.42
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
13,
31
);
updateCamera();
},
{ passive: false }
);
document.getElementById("resetView").addEventListener("click", () => {
cameraState.target.set(0, 0.8, 0);
cameraState.theta = -0.61;
cameraState.phi = 1.12;
cameraState.radius = 20.8;
updateCamera();
});
// ------------------------------------------------------------
// Projected world labels
// ------------------------------------------------------------
const labels = [
{
element: document.getElementById("matchLabel"),
position: new THREE.Vector3(-4.7, 2.2, 0.2)
},
{
element: document.getElementById("mismatchLabel"),
position: new THREE.Vector3(4.05, 2.23, 0.42)
}
];
function updateLabels() {
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", onResize);
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const time = clock.getElapsedTime();
animatedConnectors.forEach((connector, index) => {
if (connector.material) {
connector.material.emissiveIntensity =
0.16 + Math.sin(time * 3.1 + index * 0.8) * 0.08;
}
if (connector.ring) {
const pulse = 1 + Math.sin(time * 2.5 + index) * 0.035;
connector.ring.scale.setScalar(pulse);
}
});
matchDatum.position.y = 2.03 + Math.sin(time * 2.2) * 0.025;
matchDatum.material.opacity = 0.8;
matchDatum.material.transparent = true;
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```