Prompt specification
Build or customize the Three.js 3D scene "Similarity-matching exploration puzzle" 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: Similarity-matching exploration puzzle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/similarity-matching-exploration-puzzle-x1736
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows geometric similarity under uniform scaling. Let users identify corresponding sides and choose a scale factor between shapes; verify proportional lengths and angles rather than relying only on visual resemblance. Voxel style.
Working Three.js Starter (similarity-matching-exploration-puzzle-x1736):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Scale Lab — Geometric Similarity</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: #0c1721;
--panel-2: #101f2b;
--line: #213543;
--text: #e8f4f7;
--muted: #89a2ae;
--cyan: #49e3c5;
--orange: #ff9e64;
--lime: #b7f25b;
--red: #ff657a;
--yellow: #ffd166;
--mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
--sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family: var(--sans);
}
body {
overflow: hidden;
}
button, input { font: inherit; }
button {
color: inherit;
cursor: pointer;
}
.app {
height: 100dvh;
display: flex;
flex-direction: column;
}
header {
height: 76px;
flex: 0 0 76px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background:
linear-gradient(90deg, rgba(73, 227, 197, .07), transparent 34%),
#09131c;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-icon {
width: 38px;
height: 38px;
position: relative;
transform: rotate(30deg) skewY(-10deg);
border: 2px solid var(--cyan);
box-shadow: 5px 5px 0 rgba(73, 227, 197, .17);
}
.brand-icon::before,
.brand-icon::after {
content: "";
position: absolute;
background: var(--cyan);
}
.brand-icon::before {
width: 2px;
height: 23px;
left: 16px;
top: 6px;
opacity: .45;
}
.brand-icon::after {
width: 22px;
height: 2px;
left: 6px;
top: 16px;
opacity: .45;
}
.eyebrow {
color: var(--cyan);
font: 700 10px/1.2 var(--mono);
letter-spacing: .18em;
text-transform: uppercase;
}
h1 {
margin: 3px 0 0;
font-size: 20px;
line-height: 1;
letter-spacing: -.02em;
}
.header-meta {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font: 600 10px var(--mono);
letter-spacing: .08em;
text-transform: uppercase;
}
.header-meta span {
border: 1px solid var(--line);
padding: 8px 10px;
background: #0b1720;
}
main {
min-height: 0;
flex: 1;
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
isolation: isolate;
background: #071018;
}
#viewport,
#labelLayer {
position: absolute;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#labelLayer {
z-index: 3;
pointer-events: none;
}
.hud {
position: absolute;
z-index: 4;
pointer-events: none;
}
.hud-left {
top: 18px;
left: 18px;
}
.mode-chip,
.legend-chip {
background: rgba(7, 16, 24, .86);
border: 1px solid #29404e;
box-shadow: 4px 4px 0 rgba(0, 0, 0, .18);
backdrop-filter: blur(8px);
}
.mode-chip {
padding: 10px 12px;
font: 700 10px var(--mono);
letter-spacing: .08em;
text-transform: uppercase;
}
.mode-chip b {
color: var(--lime);
margin-left: 7px;
}
.legend {
top: 18px;
right: 18px;
display: flex;
gap: 7px;
}
.legend-chip {
display: flex;
align-items: center;
gap: 7px;
padding: 8px 10px;
font: 700 9px var(--mono);
text-transform: uppercase;
letter-spacing: .08em;
}
.legend-chip i {
width: 9px;
height: 9px;
display: inline-block;
background: var(--cyan);
box-shadow: 2px 2px 0 rgba(255,255,255,.16);
}
.legend-chip.copy i { background: var(--orange); }
.model-tag {
position: absolute;
z-index: 4;
transform: translate(-50%, -100%);
padding: 7px 10px;
white-space: nowrap;
pointer-events: none;
border: 1px solid currentColor;
background: rgba(7, 16, 24, .84);
font: 800 9px var(--mono);
letter-spacing: .1em;
text-transform: uppercase;
box-shadow: 3px 3px 0 rgba(0,0,0,.22);
}
.model-tag.original { color: var(--cyan); }
.model-tag.copy { color: var(--orange); }
.side-label {
position: absolute;
min-width: 25px;
height: 25px;
padding: 0 5px;
display: grid;
place-items: center;
transform: translate(-50%, -50%);
border: 1px solid currentColor;
background: rgba(6, 14, 21, .92);
color: var(--cyan);
box-shadow: 3px 3px 0 rgba(0,0,0,.25);
font: 800 10px var(--mono);
pointer-events: auto;
cursor: crosshair;
user-select: none;
}
.side-label.copy { color: var(--orange); }
.side-label.paired { color: var(--lime); }
.side-label.pending {
color: #fff;
background: var(--cyan);
}
.stage-bottom {
position: absolute;
left: 18px;
right: 18px;
bottom: 17px;
z-index: 4;
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 15px;
pointer-events: none;
}
.camera-help,
.view-tools {
background: rgba(7, 16, 24, .84);
border: 1px solid #233a48;
backdrop-filter: blur(8px);
}
.camera-help {
padding: 9px 11px;
color: var(--muted);
font: 600 9px var(--mono);
letter-spacing: .04em;
}
.view-tools {
display: flex;
pointer-events: auto;
}
.tool-button {
border: 0;
border-right: 1px solid #29404e;
background: transparent;
color: var(--muted);
padding: 10px 12px;
font: 800 9px var(--mono);
text-transform: uppercase;
letter-spacing: .06em;
}
.tool-button:last-child { border-right: 0; }
.tool-button:hover { color: var(--text); background: #142532; }
.tool-button.active { color: var(--cyan); background: #12262c; }
#toast {
position: absolute;
left: 50%;
bottom: 67px;
z-index: 8;
transform: translate(-50%, 12px);
opacity: 0;
pointer-events: none;
padding: 10px 14px;
color: #071018;
background: var(--lime);
border: 1px solid #d7ff94;
box-shadow: 4px 4px 0 rgba(0,0,0,.3);
font: 800 10px var(--mono);
transition: .2s ease;
max-width: 90%;
text-align: center;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
aside {
min-height: 0;
overflow-y: auto;
padding: 18px;
border-left: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(73,227,197,.035), transparent 220px),
var(--panel);
scrollbar-width: thin;
scrollbar-color: #2b4555 transparent;
}
.panel-title {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
margin-bottom: 15px;
}
.panel-title h2 {
margin: 3px 0 0;
font-size: 18px;
letter-spacing: -.02em;
}
.unit-badge {
color: var(--muted);
border: 1px solid var(--line);
padding: 7px 8px;
font: 700 9px var(--mono);
white-space: nowrap;
}
.step-card {
border: 1px solid var(--line);
background: #0d1a24;
margin-bottom: 12px;
box-shadow: 4px 4px 0 rgba(0,0,0,.15);
}
.step-head {
display: flex;
align-items: center;
gap: 10px;
padding: 12px 13px;
border-bottom: 1px solid var(--line);
}
.step-number {
width: 25px;
height: 25px;
display: grid;
place-items: center;
flex: 0 0 auto;
border: 1px solid var(--cyan);
color: var(--cyan);
font: 800 10px var(--mono);
}
.step-head h3 {
margin: 0;
font-size: 13px;
letter-spacing: .01em;
}
.step-body { padding: 13px; }
.instructions {
margin: 0;
color: #a9bdc6;
font-size: 12px;
line-height: 1.55;
}
.instructions strong { color: var(--text); }
.pair-summary {
display: flex;
align-items: center;
justify-content: space-between;
margin: 12px 0 9px;
color: var(--muted);
font: 700 9px var(--mono);
text-transform: uppercase;
letter-spacing: .08em;
}
.progress {
height: 5px;
background: #071018;
border: 1px solid #213543;
overflow: hidden;
margin-bottom: 10px;
}
.progress > div {
width: 0;
height: 100%;
background: var(--lime);
box-shadow: 0 0 12px rgba(183,242,91,.35);
transition: width .2s ease;
}
#pairList {
max-height: 205px;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: #2b4555 transparent;
border: 1px solid #1c303d;
background: #09141c;
}
.empty-pairs {
min-height: 78px;
display: grid;
place-items: center;
padding: 14px;
color: #66808d;
text-align: center;
font: 600 10px/1.5 var(--mono);
}
.pair-row {
display: grid;
grid-template-columns: 31px 20px 31px 1fr 25px;
align-items: center;
gap: 5px;
min-height: 48px;
padding: 7px 8px;
border-bottom: 1px solid #172833;
}
.pair-row:last-child { border-bottom: 0; }
.pair-row.incompatible { background: rgba(255, 101, 122, .055); }
.side-chip {
height: 25px;
display: grid;
place-items: center;
border: 1px solid var(--cyan);
color: var(--cyan);
background: rgba(73,227,197,.06);
font: 800 10px var(--mono);
}
.side-chip.copy {
border-color: var(--orange);
color: var(--orange);
background: rgba(255,158,100,.06);
}
.pair-arrow {
color: #617986;
text-align: center;
font: 700 12px var(--mono);
}
.pair-meta {
min-width: 0;
display: flex;
gap: 8px;
align-items: center;
color: #8ca5b1;
font: 600 9px var(--mono);
white-space: nowrap;
}
.pair-meta span:first-child { color: var(--lime); }
.pair-row.incompatible .pair-meta span:first-child { color: var(--red); }
.remove-pair {
width: 24px;
height: 24px;
padding: 0;
border: 1px solid transparent;
background: transparent;
color: #667f8b;
font: 700 13px var(--mono);
}
.remove-pair:hover {
color: var(--red);
border-color: rgba(255,101,122,.35);
}
.button-row {
display: flex;
gap: 8px;
margin-top: 10px;
}
.secondary-button,
.primary-button {
border: 1px solid #2a4352;
background: #11222d;
padding: 10px 11px;
font: 800 9px var(--mono);
letter-spacing: .06em;
text-transform: uppercase;
transition: .15s ease;
}
.secondary-button:hover {
border-color: #456271;
background: #172b37;
}
.primary-button {
border-color: var(--cyan);
color: #061018;
background: var(--cyan);
box-shadow: 4px 4px 0 #174f49;
}
.primary-button:hover {
background: #78f0d7;
transform: translate(-1px, -1px);
box-shadow: 5px 5px 0 #174f49;
}
.primary-button:active {
transform: translate(2px, 2px);
box-shadow: 2px 2px 0 #174f49;
}
.primary-button.full { width: 100%; }
.scale-line {
display: grid;
grid-template-columns: 1fr 72px;
gap: 11px;
align-items: center;
margin: 13px 0 9px;
}
input[type="range"] {
width: 100%;
height: 6px;
margin: 0;
appearance: none;
background:
linear-gradient(90deg, var(--cyan) 0 var(--pct, 33.33%), #243b48 var(--pct, 33.33%) 100%);
border: 1px solid #34505e;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 20px;
appearance: none;
background: var(--cyan);
border: 2px solid #071018;
box-shadow: 2px 2px 0 rgba(0,0,0,.3);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 18px;
border-radius: 0;
background: var(--cyan);
border: 2px solid #071018;
}
.number-wrap {
position: relative;
}
.number-wrap::before {
content: "×";
position: absolute;
left: 9px;
top: 50%;
transform: translateY(-50%);
color: var(--cyan);
font: 800 12px var(--mono);
pointer-events: none;
}
#scaleNumber {
width: 100%;
height: 35px;
padding: 0 7px 0 24px;
border: 1px solid #34505e;
border-radius: 0;
outline: none;
color: var(--text);
background: #08131b;
font: 800 12px var(--mono);
}
#scaleNumber:focus { border-color: var(--cyan); }
.microcopy {
margin: 8px 0 0;
color: #708995;
font: 500 9px/1.45 var(--mono);
}
#results {
min-height: 112px;
padding: 12px;
border: 1px solid #263e4c;
background:
linear-gradient(135deg, rgba(73,227,197,.035), transparent 55%),
#09141c;
}
.result-placeholder {
min-height: 84px;
display: grid;
place-items: center;
color: #6c8793;
text-align: center;
font: 600 10px/1.55 var(--mono);
}
.verdict {
display: flex;
align-items: flex-start;
gap: 10px;
padding-bottom: 10px;
margin-bottom: 9px;
border-bottom: 1px solid #203541;
}
.verdict-icon {
width: 30px;
height: 30px;
flex: 0 0 auto;
display: grid;
place-items: center;
border: 1px solid currentColor;
font: 900 13px var(--mono);
}
.verdict h4 {
margin: 0 0 3px;
font-size: 12px;
}
.verdict p {
margin: 0;
color: #8ea7b2;
font: 500 9px/1.45 var(--mono);
}
.verdict.pass { color: var(--lime); }
.verdict.fail { color: var(--red); }
.verdict.warn { color: var(--yellow); }
.result-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.result-card {
min-height: 66px;
padding: 8px;
border: 1px solid #213744;
background: #0d1a23;
}
.result-card b {
display: block;
margin-bottom: 5px;
font: 800 8px var(--mono);
letter-spacing: .06em;
text-transform: uppercase;
}
.result-card span {
color: #8fa8b3;
font: 500 9px/1.35 var(--mono);
}
.result-card.pass b { color: var(--lime); }
.result-card.fail b { color: var(--red); }
.result-card.warn b { color: var(--yellow); }
.measured {
margin-top: 8px;
color: #8da6b1;
font: 600 9px/1.4 var(--mono);
}
.measured strong { color: var(--cyan); }
details {
border: 1px solid var(--line);
background: #0a161f;
margin-top: 12px;
}
summary {
padding: 11px 12px;
cursor: pointer;
color: #a9bdc6;
font: 800 9px var(--mono);
text-transform: uppercase;
letter-spacing: .06em;
}
.angle-key {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
padding: 0 11px 11px;
}
.angle-item {
border: 1px solid #243d4b;
background: #0e1d27;
padding: 7px 5px;
text-align: center;
font: 700 9px var(--mono);
}
.angle-item span {
display: block;
margin-top: 4px;
color: var(--yellow);
font-size: 10px;
}
.panel-note {
margin: 11px 2px 0;
color: #58717e;
font: 500 9px/1.55 var(--mono);
}
@media (max-width: 900px) {
body { overflow: auto; }
.app { height: auto; min-height: 100dvh; }
header { padding: 0 15px; }
.header-meta span:first-child { display: none; }
main { display: block; }
#stage { height: 61dvh; min-height: 470px; }
aside {
overflow: visible;
border-left: 0;
border-top: 1px solid var(--line);
padding: 15px;
}
.legend { top: 62px; left: 18px; right: auto; }
.stage-bottom { left: 12px; right: 12px; }
.camera-help { display: none; }
.stage-bottom { justify-content: flex-end; }
}
@media (max-width: 520px) {
header { height: 68px; flex-basis: 68px; }
h1 { font-size: 17px; }
.brand-icon { width: 32px; height: 32px; }
.brand-icon::before { left: 13px; height: 18px; }
.brand-icon::after { top: 13px; }
.header-meta { display: none; }
#stage { min-height: 440px; }
.legend-chip { padding: 7px 8px; }
.result-grid { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="brand-icon" aria-hidden="true"></div>
<div>
<div class="eyebrow">Geometric Proof Workspace</div>
<h1>Scale Lab</h1>
</div>
</div>
<div class="header-meta">
<span>Three.js / Voxel Geometry</span>
<span>Similarity ≠ Resemblance</span>
</div>
</header>
<main>
<section id="stage" aria-label="Interactive geometric similarity scene">
<div id="viewport"></div>
<div id="labelLayer"></div>
<div class="hud hud-left">
<div class="mode-chip">Correspondence mode <b id="stagePairCount">0 / 8</b></div>
</div>
<div class="hud legend">
<div class="legend-chip"><i></i>Original</div>
<div class="legend-chip copy"><i></i>Copy</div>
</div>
<div id="originalTag" class="model-tag original">Original · unit scale</div>
<div id="copyTag" class="model-tag copy">Copy · fixed pose</div>
<div class="stage-bottom">
<div class="camera-help">DRAG TO ORBIT · SCROLL TO ZOOM · CLICK EDGES TO PAIR</div>
<div class="view-tools">
<button class="tool-button active" id="labelsToggle" type="button">Labels on</button>
<button class="tool-button" id="resetCamera" type="button">Reset view</button>
</div>
</div>
<div id="toast" role="status" aria-live="polite"></div>
</section>
<aside>
<div class="panel-title">
<div>
<div class="eyebrow">Similarity Checklist</div>
<h2>Prove the relationship</h2>
</div>
<div class="unit-badge">UNIT: CELL</div>
</div>
<section class="step-card">
<div class="step-head">
<div class="step-number">01</div>
<h3>Identify corresponding sides</h3>
</div>
<div class="step-body">
<p class="instructions">
Click one highlighted edge on the <strong>original</strong>, then its
corresponding edge on the <strong>copy</strong>. Repeat for all eight sides.
</p>
<div class="pair-summary">
<span>Correspondence map</span>
<span id="pairCount">0 / 8 paired</span>
</div>
<div class="progress"><div id="pairProgress"></div></div>
<div id="pairList">
<div class="empty-pairs">No pairs yet.<br>Start with any edge on either model.</div>
</div>
<div class="button-row">
<button class="secondary-button" id="hintButton" type="button">Give a hint</button>
<button class="secondary-button" id="clearPairsButton" type="button">Clear pairs</button>
</div>
</div>
</section>
<section class="step-card">
<div class="step-head">
<div class="step-number">02</div>
<h3>Propose the uniform scale factor</h3>
</div>
<div class="step-body">
<p class="instructions">
Choose <strong>k = copy length ÷ original length</strong>. The copy stays fixed so
your proposed factor can be independently checked.
</p>
<div class="scale-line">
<input
id="scaleRange"
type="range"
min="0.5"
max="1.8"
step="0.05"
value="1"
aria-label="Proposed scale factor"
/>
<div class="number-wrap">
<input
id="scaleNumber"
type="number"
min="0.5"
max="1.8"
step="0.05"
value="1.00"
aria-label="Proposed scale factor value"
/>
</div>
</div>
<p class="microcopy">Allowed range: 0.50× to 1.80× · one factor applies to every direction.</p>
</div>
</section>
<section class="step-card">
<div class="step-head">
<div class="step-number">03</div>
<h3>Verify lengths and angles</h3>
</div>
<div class="step-body">
<button class="primary-button full" id="verifyButton" type="button">Run similarity verification</button>
<div id="results" style="margin-top:10px" aria-live="polite">
<div class="result-placeholder">
Pair the sides and propose a factor.<br>
Verification checks ratios, edge order, and corner angles.
</div>
</div>
<details>
<summary>Corner-angle key</summary>
<div class="angle-key" id="angleKey"></div>
</details>
</div>
</section>
<p class="panel-note">
A visual match is not a proof. The checker requires one-to-one correspondence,
proportional edge lengths, preserved adjacency, and matching interior angles.
</p>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const CELL = 0.52;
const COPY_SCALE = 1.30;
const TOLERANCE = 0.008;
const stage = document.getElementById("stage");
const viewport = document.getElementById("viewport");
const labelLayer = document.getElementById("labelLayer");
const pairList = document.getElementById("pairList");
const pairCount = document.getElementById("pairCount");
const stagePairCount = document.getElementById("stagePairCount");
const pairProgress = document.getElementById("pairProgress");
const scaleRange = document.getElementById("scaleRange");
const scaleNumber = document.getElementById("scaleNumber");
const results = document.getElementById("results");
const toast = document.getElementById("toast");
const sourceDisplay = ["A", "B", "C", "D", "E", "F", "G", "H"];
// Target labels are deliberately shuffled so the user must use geometric evidence.
const targetDisplay = ["6", "3", "8", "1", "5", "2", "7", "4"];
const polygonVertices = [
new THREE.Vector2(-4, 0),
new THREE.Vector2(4, 0),
new THREE.Vector2(4, 2),
new THREE.Vector2(1, 2),
new THREE.Vector2(1, 5),
new THREE.Vector2(-1, 5),
new THREE.Vector2(-1, 2),
new THREE.Vector2(-4, 2)
];
const sourceLengths = polygonVertices.map((v, i) => {
const next = polygonVertices[(i + 1) % polygonVertices.length];
return v.distanceTo(next);
});
const targetLengths = sourceLengths.map(length => length * COPY_SCALE);
const interiorAngles = calculateInteriorAngles(polygonVertices);
let pairs = [];
let pendingSource = null;
let hovered = null;
let labelsVisible = true;
let toastTimer = null;
const hitBoxes = [];
const stripRecords = [];
const projectedLabels = [];
// ---------- Three.js scene ----------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.Fog(0x071018, 15, 29);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: false, powerPreference: "high-performance" });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.6));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute("aria-label", "3D scene. Drag to orbit, scroll to zoom, and click edges to pair them.");
viewport.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0x9eeeff, 0x16232c, 1.55);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(-3, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x49e3c5, 24, 22, 2);
rimLight.position.set(-7, 3, -3);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff9e64, 19, 20, 2);
warmLight.position.set(7, 2, -1);
scene.add(warmLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x08131b,
roughness: 0.92,
metalness: 0.02
});
const floor = new THREE.Mesh(new THREE.BoxGeometry(16, 0.18, 10), floorMaterial);
floor.position.set(0, -1.63, -0.4);
floor.receiveShadow = true;
scene.add(floor);
createFloorTiles();
createBackgroundBlocks();
const originalGroup = createVoxelShape("source");
originalGroup.position.set(-3.70, -1.44, 0);
originalGroup.rotation.y = 0.065;
scene.add(originalGroup);
const copyGroup = createVoxelShape("target");
copyGroup.position.set(3.35, -1.44, -0.10);
copyGroup.rotation.y = -0.12;
copyGroup.scale.setScalar(COPY_SCALE);
scene.add(copyGroup);
addModelTag(originalGroup, document.getElementById("originalTag"), new THREE.Vector3(0, 3.10, 0));
addModelTag(copyGroup, document.getElementById("copyTag"), new THREE.Vector3(0, 3.10, 0));
// ---------- Camera controls (implemented directly, no addons) ----------
const cameraState = {
azimuth: 0.16,
polar: 1.16,
radius: 14.2,
target: new THREE.Vector3(0, 0.18, 0)
};
function updateCamera() {
const aspect = Math.max(0.35, viewport.clientWidth / Math.max(1, viewport.clientHeight));
const fit = Math.max(1, 1.25 / aspect);
const radius = cameraState.radius * fit;
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x + radius * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y + radius * Math.cos(cameraState.polar),
cameraState.target.z + radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.azimuth = 0.16;
cameraState.polar = 1.16;
cameraState.radius = 14.2;
updateCamera();
showToast("View reset");
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragState = null;
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
dragState = {
pointerId: event.pointerId,
startX: event.clientX,
startY: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (dragState && dragState.pointerId === event.pointerId) {
const dx = event.clientX - dragState.lastX;
const dy = event.clientY - dragState.lastY;
const totalDistance = Math.hypot(
event.clientX - dragState.startX,
event.clientY - dragState.startY
);
if (totalDistance > 4) dragState.moved = true;
if (dragState.moved) {
cameraState.azimuth -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(cameraState.polar + dy * 0.005, 0.43, 1.49);
updateCamera();
}
dragState.lastX = event.clientX;
dragState.lastY = event.clientY;
setHovered(null);
} else {
updateHoveredFromPointer(event);
}
});
renderer.domElement.addEventListener("pointerup", event => {
if (!dragState || dragState.pointerId !== event.pointerId) return;
if (!dragState.moved) {
const hit = pickAt(event.clientX, event.clientY);
if (hit) chooseSide(hit.object.userData.model, hit.object.userData.sideId);
}
dragState = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
dragState = null;
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragState) setHovered(null);
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
8,
22
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("keydown", event => {
const key = event.key.toLowerCase();
let handled = true;
if (key === "arrowleft") cameraState.azimuth += 0.08;
else if (key === "arrowright") cameraState.azimuth -= 0.08;
else if (key === "arrowup") cameraState.polar = Math.max(0.43, cameraState.polar - 0.06);
else if (key === "arrowdown") cameraState.polar = Math.min(1.49, cameraState.polar + 0.06);
else if (key === "+" || key === "=") cameraState.radius = Math.max(8, cameraState.radius - 0.5);
else if (key === "-") cameraState.radius = Math.min(22, cameraState.radius + 0.5);
else handled = false;
if (handled) {
event.preventDefault();
updateCamera();
}
});
document.getElementById("resetCamera").addEventListener("click", resetCamera);
document.getElementById("labelsToggle").addEventListener("click", event => {
labelsVisible = !labelsVisible;
event.currentTarget.textContent = labelsVisible ? "Labels on" : "Labels off";
event.currentTarget.classList.toggle("active", labelsVisible);
updateProjectedLabels();
});
// ---------- Geometry construction ----------
function createVoxelShape(model) {
const group = new THREE.Group();
const isSource = model === "source";
const baseColor = new THREE.Color(isSource ? 0x35d8bf : 0xff9560);
const occupied = [];
for (let y = 0; y < 5; y++) {
for (let x = -4; x < 4; x++) {
const inLowerBar = y < 2;
const inUpperBar = y >= 2 && x >= -1 && x < 1;
if (inLowerBar || inUpperBar) occupied.push([x, y]);
}
}
const depthCells = 3;
const cubeGeometry = new THREE.BoxGeometry(CELL * 0.92, CELL * 0.92, CELL * 0.92);
const cubeMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.72,
metalness: 0.06
});
const cubes = new THREE.InstancedMesh(
cubeGeometry,
cubeMaterial,
occupied.length * depthCells
);
cubes.castShadow = true;
cubes.receiveShadow = true;
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
let instance = 0;
for (const [x, y] of occupied) {
for (let z = -1; z <= 1; z++) {
matrix.makeTranslation(
(x + 0.5) * CELL,
(y + 0.5) * CELL,
z * CELL
);
cubes.setMatrixAt(instance, matrix);
color.copy(baseColor);
color.offsetHSL(
((x + y + z) % 3) * 0.008,
((x * y + z) % 2) * 0.035,
((x + y + z) % 4) * 0.025
);
cubes.setColorAt(instance, color);
instance++;
}
}
cubes.instanceMatrix.needsUpdate = true;
if (cubes.instanceColor) cubes.instanceColor.needsUpdate = true;
group.add(cubes);
const outlinePoints = polygonVertices.map(v => new THREE.Vector3(v.x * CELL, v.y * CELL, 1.5 * CELL));
const outlineGeometry = new THREE.BufferGeometry().setFromPoints(outlinePoints);
const outlineMaterial = new THREE.LineBasicMaterial({
color: isSource ? 0x9affea : 0xffc19a,
transparent: true,
opacity: 0.86
});
group.add(new THREE.LineLoop(outlineGeometry, outlineMaterial));
const depthLines = [];
for (const point of outlinePoints) {
depthLines.push(
new THREE.Vector3(point.x, point.y, -1.5 * CELL),
new THREE.Vector3(point.x, point.y, 1.5 * CELL)
);
}
const depthGeometry = new THREE.BufferGeometry().setFromPoints(depthLines);
group.add(new THREE.LineSegments(
depthGeometry,
new THREE.LineBasicMaterial({
color: isSource ? 0x4fc8b8 : 0xc77352,
transparent: true,
opacity: 0.28
})
));
polygonVertices.forEach((vertex, index) => {
const next = polygonVertices[(index + 1) % polygonVertices.length];
const midpoint = vertex.clone().add(next).multiplyScalar(0.5);
const length = vertex.distanceTo(next);
const horizontal = Math.abs(next.x - vertex.x) > Math.abs(next.y - vertex.y);
const geometry = horizontal
? new THREE.BoxGeometry(length * CELL + 0.04, 0.095, 0.095)
: new THREE.BoxGeometry(0.095, length * CELL + 0.04, 0.095);
const material = new THREE.MeshBasicMaterial({
color: isSource ? 0x49e3c5 : 0xff9e64,
transparent: true,
opacity: 0.34,
depthWrite: false
});
const strip = new THREE.Mesh(geometry, material);
strip.position.set(
midpoint.x * CELL,
midpoint.y * CELL,
1.5 * CELL + 0.075
);
strip.userData = { model, sideId: index };
group.add(strip);
hitBoxes.push(strip);
const record = {
mesh: strip,
model,
sideId: index,
baseColor: isSource ? 0x49e3c5 : 0xff9e64
};
stripRecords.push(record);
const label = document.createElement("div");
label.className = `side-label${isSource ? "" : " copy"}`;
label.textContent = isSource ? sourceDisplay[index] : targetDisplay[index];
label.title = `${isSource ? "Original" : "Copy"} edge ${isSource ? sourceDisplay[index] : targetDisplay[index]}`;
labelLayer.appendChild(label);
projectedLabels.push({
element: label,
group,
local: new THREE.Vector3(
strip.position.x,
strip.position.y,
strip.position.z + 0.08
),
sideRef: record
});
label.addEventListener("pointerdown", event => event.stopPropagation());
label.addEventListener("click", event => {
event.stopPropagation();
chooseSide(model, index);
});
label.addEventListener("pointerenter", () => setHovered(record));
label.addEventListener("pointerleave", () => setHovered(null));
});
return group;
}
function createFloorTiles() {
const tileGeometry = new THREE.BoxGeometry(0.50, 0.10, 0.50);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95,
metalness: 0
});
const columns = 30;
const rows = 18;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, columns * rows);
const matrix = new THREE.Matrix4();
const color = new THREE.Color();
let index = 0;
for (let x = 0; x < columns; x++) {
for (let z = 0; z < rows; z++) {
const px = (x - columns / 2 + 0.5) * 0.54;
const pz = (z - rows / 2 + 0.5) * 0.54 - 0.4;
matrix.makeTranslation(px, -1.51, pz);
tiles.setMatrixAt(index, matrix);
const light = (x + z) % 2 === 0;
color.set(light ? 0x10222d : 0x0c1b25);
tiles.setColorAt(index, color);
index++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
scene.add(tiles);
}
function createBackgroundBlocks() {
const material = new THREE.MeshStandardMaterial({
color: 0x112a35,
roughness: 0.88,
metalness: 0.03
});
const blocks = [
[-6.7, 0.7, -3.7, 1.5, 1.4, 1.2],
[-6.7, 1.7, -3.7, 0.9, 0.7, 1.0],
[6.7, 0.55, -3.6, 1.7, 1.1, 1.3],
[6.4, 1.35, -3.6, 0.8, 0.7, 0.9],
[-4.8, 0.35, -4.1, 1.1, 0.7, 0.8],
[4.8, 0.45, -4.0, 1.4, 0.9, 0.9]
];
for (const [x, y, z, w, h, d] of blocks) {
const block = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
block.position.set(x, -1.44 + h / 2, z);
block.castShadow = true;
block.receiveShadow = true;
scene.add(block);
}
}
function addModelTag(group, element, anchor) {
projectedLabels.push({
element,
group,
local: anchor,
modelTag: true
});
}
// ---------- Correspondence interaction ----------
function chooseSide(model, sideId) {
if (model === "source") {
pairs = pairs.filter(pair => pair.sourceId !== sideId);
pendingSource = sideId;
showToast(`Original edge ${sourceDisplay[sideId]} selected — now choose its mate on the copy.`);
} else {
if (pendingSource === null) {
showToast("Choose an edge on the original first.");
return;
}
pairs = pairs.filter(pair =>
pair.sourceId !== pendingSource && pair.targetId !== sideId
);
pairs.push({
sourceId: pendingSource,
targetId: sideId
});
pendingSource = null;
showToast(
`Paired ${sourceDisplay[pairs[pairs.length - 1].sourceId]} → ${targetDisplay[pairs[pairs.length - 1].targetId]}`
);
}
renderPairs();
refreshStripAppearance();
}
function renderPairs() {
const count = pairs.length;
pairCount.textContent = `${count} / 8 paired`;
stagePairCount.textContent = `${count} / 8`;
pairProgress.style.width = `${(count / 8) * 100}%`;
if (!count) {
pairList.innerHTML = `
<div class="empty-pairs">
No pairs yet.<br>Start with any edge on either model.
</div>`;
return;
}
pairList.innerHTML = pairs.map((pair, index) => {
const ratio = targetLengths[pair.targetId] / sourceLengths[pair.sourceId];
const sourceAngles = sideAngles(pair.sourceId);
const targetAngles = sideAngles(pair.targetId);
const angleMatch = sourceAngles.join(",") === targetAngles.join(",");
const normalizedLengthMatch =
Math.abs(targetLengths[pair.targetId] / COPY_SCALE - sourceLengths[pair.sourceId]) < TOLERANCE;
const compatible = angleMatch && normalizedLengthMatch;
return `
<div class="pair-row ${compatible ? "" : "incompatible"}">
<div class="side-chip">${sourceDisplay[pair.sourceId]}</div>
<div class="pair-arrow">→</div>
<div class="side-chip copy">${targetDisplay[pair.targetId]}</div>
<div class="pair-meta" title="Measured length ratio and endpoint angles">
<span>×${ratio.toFixed(2)}</span>
<span>${angleMatch ? targetAngles.join("° / ") + "°" : "angle mismatch"}</span>
</div>
<button class="remove-pair" type="button" data-remove="${index}" aria-label="Remove pair">×</button>
</div>`;
}).join("");
pairList.querySelectorAll("[data-remove]").forEach(button => {
button.addEventListener("click", () => {
pairs.splice(Number(button.dataset.remove), 1);
renderPairs();
refreshStripAppearance();
});
});
}
function updateHoveredFromPointer(event) {
const hit = pickAt(event.clientX, event.clientY);
if (!hit) {
setHovered(null);
return;
}
const record = stripRecords.find(item =>
item.mesh === hit.object
);
setHovered(record || null);
}
function pickAt(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(hitBoxes, false);
return intersections.length ? intersections[0] : null;
}
function setHovered(record) {
if (hovered === record) return;
hovered = record;
renderer.domElement.style.cursor = record ? "crosshair" : "grab";
refreshStripAppearance();
}
function refreshStripAppearance() {
for (const record of stripRecords) {
const isPaired = pairs.some(pair =>
pair.sourceId === record.sideId && record.model === "source" ||
pair.targetId === record.sideId && record.model === "target"
);
const isPending = record.model === "source" && pendingSource === record.sideId;
const isHovered = hovered === record;
const color = new THREE.Color(record.baseColor);
let opacity = 0.34;
if (isPaired) {
color.set(0xb7f25b);
opacity = 0.78;
} else if (isPending) {
color.set(0xffffff);
opacity = 0.96;
} else if (isHovered) {
color.lerp(new THREE.Color(0xffffff), 0.42);
opacity = 0.72;
}
record.mesh.material.color.copy(color);
record.mesh.material.opacity = opacity;
}
for (const label of projectedLabels) {
if (!label.sideRef) continue;
const { model, sideId } = label.sideRef;
const isPaired = pairs.some(pair =>
pair.sourceId === sideId && model === "source" ||
pair.targetId === sideId && model === "target"
);
const isPending = model === "source" && pendingSource === sideId;
label.element.classList.toggle("paired", isPaired);
label.element.classList.toggle("pending", isPending);
}
}
// ---------- Mathematical verification ----------
function calculateInteriorAngles(vertices) {
const signedArea = vertices.reduce((sum, v, i) => {
const next = vertices[(i + 1) % vertices.length];
return sum + v.x * next.y - next.x * v.y;
}, 0);
const orientation = signedArea > 0 ? 1 : -1;
return vertices.map((vertex, i) => {
const previous = vertices[(i - 1 + vertices.length) % vertices.length];
const next = vertices[(i + 1) % vertices.length];
const incoming = vertex.clone().sub(previous);
const outgoing = next.clone().sub(vertex);
const cross = incoming.x * outgoing.y - incoming.y * outgoing.x;
const dot = incoming.dot(outgoing);
const turn = Math.atan2(cross * orientation, dot);
return THREE.MathUtils.radToDeg(Math.PI - turn);
});
}
function sideAngles(sideId) {
return [
interiorAngles[sideId],
interiorAngles[(sideId + 1) % interiorAngles.length]
].sort((a, b) => a - b);
}
function findDihedralMapping() {
if (pairs.length !== 8) return null;
const map = new Map(pairs.map(pair => [pair.sourceId, pair.targetId]));
if (map.size !== 8 || new Set(map.values()).size !== 8) return null;
for (let shift = 0; shift < 8; shift++) {
let preserving = true;
let reversing = true;
for (let sourceId = 0; sourceId < 8; sourceId++) {
const preservingTarget = (sourceId + shift) % 8;
const reversingTarget = ((shift - sourceId - 1) % 8 + 8) % 8;
if (map.get(sourceId) !== preservingTarget) preserving = false;
if (map.get(sourceId) !== reversingTarget) reversing = false;
}
if (preserving) {
return {
type: "preserving",
shift,
vertexMap: i => (i + shift) % 8
};
}
if (reversing) {
return {
type: "reversing",
shift,
vertexMap: i => (shift - i + 8) % 8
};
}
}
return null;
}
function median(values) {
if (!values.length) return NaN;
const sorted = [...values].sort((a, b) => a - b);
const middle = Math.floor(sorted.length / 2);
return sorted.length % 2
? sorted[middle]
: (sorted[middle - 1] + sorted[middle]) / 2;
}
function runVerification() {
const proposedScale = Number(scaleNumber.value);
const complete = pairs.length === 8 &&
new Set(pairs.map(pair => pair.sourceId)).size === 8 &&
new Set(pairs.map(pair => pair.targetId)).size === 8;
const ratios = pairs.map(pair =>
targetLengths[pair.targetId] / sourceLengths[pair.sourceId]
);
const matchingAnglePairs = pairs.filter(pair => {
const a = sideAngles(pair.sourceId);
const b = sideAngles(pair.targetId);
return a[0] === b[0] && a[1] === b[1];
}).length;
const dihedral = findDihedralMapping();
const topologyValid = Boolean(dihedral);
const normalizedLengthValid = complete && pairs.every(pair =>
Math.abs(
targetLengths[pair.targetId] / COPY_SCALE -
sourceLengths[pair.sourceId]
) < TOLERANCE
);
const mappedAnglesValid = Boolean(dihedral) && interiorAngles.every((angle, sourceVertex) => {
const targetVertex = dihedral.vertexMap(sourceVertex);
return Math.abs(angle - interiorAngles[targetVertex]) < 0.01;
});
const anglesValid = complete && matchingAnglePairs === 8 && mappedAnglesValid;
const proportionsValid = complete && ratios.every(ratio =>
Math.abs(ratio - proposedScale) < TOLERANCE
);
const actualSimilarity = complete && topologyValid && normalizedLengthValid && anglesValid;
const overallPass = actualSimilarity && proportionsValid;
const measuredScale = actualSimilarity ? median(ratios) : NaN;
let correspondenceStatus = "warn";
let correspondenceText = `${pairs.length}/8 sides paired`;
if (complete && topologyValid && normalizedLengthValid) {
correspondenceStatus = "pass";
correspondenceText = "Order and edge signature match";
} else if (complete && !topologyValid) {
correspondenceStatus = "fail";
correspondenceText = "Side order does not preserve adjacency";
} else if (complete && !normalizedLengthValid) {
correspondenceStatus = "fail";
correspondenceText = "Mapped sides have different signatures";
}
const proportionStatus = proportionsValid ? "pass" : complete ? "fail" : "warn";
const proportionText = proportionsValid
? `All 8 ratios match ×${proposedScale.toFixed(2)}`
: complete
? `${ratios.filter(r => Math.abs(r - proposedScale) < TOLERANCE).length}/8 ratios match`
: "Pair every side first";
const angleStatus = anglesValid ? "pass" : complete ? "fail" : "warn";
const angleText = anglesValid
? "8/8 angle pairs preserved"
: complete
? `${matchingAnglePairs}/8 angle pairs agree`
: "Pair every side first";
const verdictTitle = overallPass
? "Geometric similarity confirmed"
: actualSimilarity
? "The factor needs another look"
: complete
? "Correspondence proof incomplete"
: "Verification is ready";
const verdictText = overallPass
? `Every length is multiplied by ×${proposedScale.toFixed(2)}, and all corresponding angles are preserved.`
: actualSimilarity
? `The copy is similar to the original, but its measured factor is ×${measuredScale.toFixed(2)}.`
: complete
? "Check the side order, length signatures, and endpoint angles."
: `You have paired ${pairs.length} of 8 sides. Continue to complete the proof.`;
const verdictClass = overallPass ? "pass" : actualSimilarity ? "warn" : "fail";
const icon = overallPass ? "✓" : actualSimilarity ? "!" : "×";
results.innerHTML = `
<div class="verdict ${verdictClass}">
<div class="verdict-icon">${icon}</div>
<div>
<h4>${verdictTitle}</h4>
<p>${verdictText}</p>
</div>
</div>
<div class="result-grid">
<div class="result-card ${correspondenceStatus}">
<b>Correspondence</b>
<span>${correspondenceText}</span>
</div>
<div class="result-card ${proportionStatus}">
<b>Proportional lengths</b>
<span>${proportionText}</span>
</div>
<div class="result-card ${angleStatus}">
<b>Angle preservation</b>
<span>${angleText}</span>
</div>
<div class="result-card ${actualSimilarity ? "pass" : "warn"}">
<b>Interior angles</b>
<span>${actualSimilarity
? `${dihedral.type === "preserving" ? "Direct" : "Reversed"} vertex map verified`
: "Global vertex map not proven"
}</span>
</div>
</div>
<div class="measured">
Measured uniform factor:
<strong>${Number.isFinite(measuredScale) ? `×${measuredScale.toFixed(2)}` : "not yet certifiable"}</strong>
<br>
Proposed factor: <strong>×${proposedScale.toFixed(2)}</strong>
</div>`;
if (overallPass) {
showToast("Similarity verified: lengths and angles both match.");
}
}
// ---------- Scale controls ----------
function syncScaleFromRange() {
const value = Number(scaleRange.value);
scaleNumber.value = value.toFixed(2);
updateRangeFill();
}
function syncScaleFromNumber() {
let value = Number(scaleNumber.value);
if (!Number.isFinite(value)) value = 1;
value = THREE.MathUtils.clamp(value, 0.5, 1.8);
scaleNumber.value = value.toFixed(2);
scaleRange.value = value.toFixed(2);
updateRangeFill();
}
function updateRangeFill() {
const value = Number(scaleRange.value);
const percentage = ((value - 0.5) / (1.8 - 0.5)) * 100;
scaleRange.style.setProperty("--pct", `${percentage}%`);
}
scaleRange.addEventListener("input", syncScaleFromRange);
scaleNumber.addEventListener("input", syncScaleFromNumber);
scaleNumber.addEventListener("change", syncScaleFromNumber);
document.getElementById("verifyButton").addEventListener("click", runVerification);
document.getElementById("clearPairsButton").addEventListener("click", () => {
pairs = [];
pendingSource = null;
renderPairs();
refreshStripAppearance();
showToast("Correspondence map cleared.");
});
document.getElementById("hintButton").addEventListener("click", () => {
const usedSources = new Set(pairs.map(pair => pair.sourceId));
const usedTargets = new Set(pairs.map(pair => pair.targetId));
for (let sideId = 0; sideId < 8; sideId++) {
if (!usedSources.has(sideId) && !usedTargets.has(sideId)) {
pairs.push({ sourceId: sideId, targetId: sideId });
renderPairs();
refreshStripAppearance();
showToast(
`Hint: ${sourceDisplay[sideId]} matches ${targetDisplay[sideId]}.`
);
return;
}
}
showToast("All eight correspondences are already paired.");
});
// ---------- UI helpers ----------
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2400);
}
function buildAngleKey() {
const key = document.getElementById("angleKey");
key.innerHTML = interiorAngles.map((angle, index) => `
<div class="angle-item">
V${index + 1}
<span>${Math.round(angle)}°</span>
</div>
`).join("");
}
function updateProjectedLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
for (const label of projectedLabels) {
if (label.sideRef && !labelsVisible) {
label.element.style.display = "none";
continue;
}
const world = label.local.clone();
label.group.localToWorld(world);
world.project(camera);
const visible = world.z > -1 && world.z < 1;
if (!visible) {
label.element.style.display = "none";
continue;
}
label.element.style.display = "";
label.element.style.left = `${(world.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-world.y * 0.5 + 0.5) * height}px`;
}
}
// ---------- Resize and animation ----------
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(1, height);
camera.updateProjectionMatrix();
updateCamera();
updateProjectedLabels();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
function animate() {
requestAnimationFrame(animate);
updateCamera();
renderer.render(scene, camera);
updateProjectedLabels();
}
buildAngleKey();
renderPairs();
refreshStripAppearance();
updateRangeFill();
resize();
animate();
</script>
</body>
</html>
```