Prompt specification
Build or customize the Three.js 3D scene "Change the Rule Keep the Same Objects" 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: Change the Rule Keep the Same Objects
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/change-the-rule-keep-the-same-objects-x2044
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring geometric sorting by size and shape. Create a classification experiment applying two transparent decision rules to one fixed object set. Display changed assignments and avoid treating either arbitrary rule as ground truth. Low-poly.
Working Three.js Starter (change-the-rule-keep-the-same-objects-x2044):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Geometric Classification Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #0b1013;
--panel: #11181c;
--panel-2: #161f24;
--line: #29353b;
--text: #e8f0f2;
--muted: #8fa1a9;
--g1: #58d8bd;
--g2: #73a9ff;
--g3: #f3c969;
--delta: #ff8b70;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.app {
height: 100vh;
display: grid;
grid-template-rows: 76px minmax(0, 1fr);
}
header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 13px 22px;
border-bottom: 1px solid var(--line);
background: #0d1316;
z-index: 2;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.mark {
position: relative;
width: 40px;
height: 40px;
flex: 0 0 auto;
}
.mark i {
position: absolute;
display: block;
border: 1px solid currentColor;
transform: rotate(30deg) skew(-8deg);
}
.mark i:nth-child(1) {
width: 20px;
height: 20px;
left: 2px;
top: 11px;
color: var(--g1);
}
.mark i:nth-child(2) {
width: 18px;
height: 18px;
left: 18px;
top: 4px;
color: var(--g2);
}
.mark i:nth-child(3) {
width: 14px;
height: 14px;
left: 22px;
top: 21px;
color: var(--g3);
}
.eyebrow {
margin-bottom: 3px;
color: var(--muted);
font: 600 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(17px, 2vw, 23px);
line-height: 1.1;
font-weight: 650;
letter-spacing: -0.025em;
}
.header-meta {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
flex-wrap: wrap;
}
.pill {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 27px;
padding: 5px 9px;
border: 1px solid var(--line);
border-radius: 999px;
background: #121a1e;
color: #b9c7cc;
font-size: 11px;
white-space: nowrap;
}
.pill::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--g1);
box-shadow: 0 0 9px #58d8bd66;
}
.pill.warning::before {
background: var(--delta);
box-shadow: 0 0 9px #ff8b7066;
}
.layout {
min-height: 0;
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
}
.scene {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #101619;
}
#scene {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#scene.dragging {
cursor: grabbing;
}
#scene:focus-visible {
box-shadow: inset 0 0 0 2px var(--g2);
}
.divider {
position: absolute;
z-index: 2;
top: 0;
bottom: 0;
left: 50%;
width: 1px;
pointer-events: none;
background: linear-gradient(
to bottom,
transparent,
#64747c88 12%,
#64747c88 88%,
transparent
);
}
.view-heading {
position: absolute;
z-index: 3;
top: 22px;
padding: 11px 13px;
border: 1px solid #35444b;
border-radius: 8px;
background: #0c1215d9;
backdrop-filter: blur(9px);
pointer-events: none;
}
.view-heading.a {
left: 22px;
border-left: 3px solid var(--g2);
}
.view-heading.b {
right: 22px;
border-left: 3px solid var(--g3);
}
.view-heading .rule {
color: var(--muted);
font: 700 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
}
.view-heading strong {
display: block;
margin-top: 4px;
font-size: 15px;
font-weight: 650;
}
.view-heading small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.scene-actions {
position: absolute;
z-index: 4;
right: 16px;
bottom: 16px;
display: flex;
align-items: center;
gap: 8px;
}
.scene-button {
min-height: 32px;
padding: 7px 10px;
border: 1px solid #35444b;
border-radius: 6px;
background: #0c1215df;
color: #c5d1d5;
font-size: 11px;
cursor: pointer;
transition:
border-color 140ms ease,
background 140ms ease,
color 140ms ease;
}
.scene-button:hover {
border-color: #667b84;
background: #182228;
color: white;
}
.scene-button[aria-pressed="true"] {
border-color: #a45645;
color: #ffab97;
background: #281815df;
}
.scene-hint {
position: absolute;
z-index: 3;
left: 17px;
bottom: 18px;
color: #778991;
font: 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
pointer-events: none;
}
.scene-note {
position: absolute;
z-index: 3;
left: 50%;
bottom: 19px;
transform: translateX(-50%);
padding: 6px 10px;
border-radius: 999px;
background: #0c1215bf;
color: #8fa1a9;
font-size: 10px;
white-space: nowrap;
pointer-events: none;
}
.panel {
min-height: 0;
overflow-y: auto;
padding: 17px;
border-left: 1px solid var(--line);
background: var(--panel);
scrollbar-color: #3b4b52 #11181c;
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.panel-heading h2 {
margin: 0;
font-size: 17px;
font-weight: 650;
letter-spacing: -0.02em;
}
.panel-heading p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.fixed-badge {
flex: 0 0 auto;
padding: 5px 7px;
border: 1px solid #315047;
border-radius: 4px;
color: #77dfc7;
background: #12231f;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 12px;
}
.metric {
padding: 11px 12px;
border: 1px solid var(--line);
border-radius: 7px;
background: var(--panel-2);
}
.metric strong {
display: block;
font: 650 24px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.metric span {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 10px;
}
.metric.changed strong {
color: var(--delta);
}
.metric.same strong {
color: var(--g1);
}
.rule-card {
margin-bottom: 10px;
padding: 13px;
border: 1px solid var(--line);
border-radius: 8px;
background: #141c20;
}
.rule-card.a {
border-top: 2px solid var(--g2);
}
.rule-card.b {
border-top: 2px solid var(--g3);
}
.rule-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 10px;
}
.rule-title h3 {
margin: 0;
font-size: 13px;
font-weight: 650;
}
.rule-letter {
display: inline-grid;
width: 23px;
height: 23px;
place-items: center;
margin-right: 7px;
border: 1px solid #40515a;
border-radius: 4px;
color: #d9e4e8;
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.rule-subtitle {
color: var(--muted);
font-size: 10px;
text-align: right;
}
.bin-list {
display: grid;
gap: 5px;
}
.bin-row {
display: grid;
grid-template-columns: 38px 1fr auto;
align-items: center;
gap: 8px;
min-height: 27px;
padding: 4px 7px;
border-radius: 4px;
background: #0f1619;
color: #aebdc3;
font-size: 10px;
}
.bin-row output,
.bin-row code {
color: #dce6e9;
font: 600 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.control {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid #27343a;
}
.control label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 6px;
color: #b7c5ca;
font-size: 10px;
}
.control output {
color: #e6eff2;
font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0;
accent-color: var(--g2);
cursor: pointer;
}
.small-note {
margin: 8px 0 0;
color: #7f929a;
font-size: 9px;
line-height: 1.45;
}
.ledger {
margin-top: 13px;
border: 1px solid var(--line);
border-radius: 8px;
overflow: hidden;
background: #0e1518;
}
.ledger-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 11px 12px;
border-bottom: 1px solid var(--line);
}
.ledger-header h3 {
margin: 0;
font-size: 13px;
font-weight: 650;
}
.toggle {
display: inline-flex;
align-items: center;
gap: 6px;
color: #9cadb4;
font-size: 9px;
cursor: pointer;
}
.toggle input {
width: 13px;
height: 13px;
accent-color: var(--delta);
}
.table-wrap {
max-height: 330px;
overflow: auto;
scrollbar-color: #3b4b52 #0e1518;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 9px;
}
th {
position: sticky;
top: 0;
z-index: 1;
padding: 8px 7px;
background: #11191d;
color: #71858e;
font-weight: 600;
text-align: left;
white-space: nowrap;
}
td {
padding: 8px 7px;
border-top: 1px solid #202c31;
color: #aebdc3;
white-space: nowrap;
}
tr.changed td:first-child {
box-shadow: inset 2px 0 0 var(--delta);
}
.object-id {
color: #e3ecef;
font: 650 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.mono {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.group {
display: inline-grid;
min-width: 25px;
height: 19px;
place-items: center;
border-radius: 3px;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.g1 {
color: var(--g1);
background: #173a34;
}
.g2 {
color: var(--g2);
background: #1d3153;
}
.g3 {
color: var(--g3);
background: #41361d;
}
.status {
font-weight: 650;
}
.status.changed {
color: var(--delta);
}
.status.same {
color: #70cdb8;
}
.truth-note {
margin-top: 12px;
padding: 11px 12px;
border: 1px solid #49382f;
border-radius: 7px;
background: #1b1715;
color: #baa89f;
font-size: 10px;
line-height: 1.5;
}
.truth-note strong {
color: #f2b39f;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 980px) {
body {
overflow: auto;
}
.app {
height: auto;
min-height: 100vh;
grid-template-rows: auto auto;
}
header {
min-height: 76px;
}
.layout {
display: block;
}
.scene {
height: 70vh;
min-height: 520px;
}
.panel {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
.table-wrap {
max-height: 440px;
}
}
@media (max-width: 650px) {
header {
align-items: flex-start;
padding: 12px 14px;
}
.header-meta {
display: none;
}
.scene {
min-height: 720px;
}
.view-heading {
top: 12px;
left: 12px;
right: auto;
}
.view-heading.b {
top: calc(50% + 12px);
}
.divider {
top: 50%;
bottom: auto;
left: 0;
width: 100%;
height: 1px;
background: linear-gradient(
to right,
transparent,
#64747c88 12%,
#64747c88 88%,
transparent
);
}
.scene-note {
display: none;
}
.scene-hint {
bottom: 58px;
}
.scene-actions {
left: 14px;
right: 14px;
justify-content: space-between;
}
}
</style>
</head>
<body>
<div class="app">
<header>
<div class="brand">
<div class="mark" aria-hidden="true"><i></i><i></i><i></i></div>
<div>
<div class="eyebrow">Classification experiment / 01</div>
<h1>Same objects. Different rules.</h1>
</div>
</div>
<div class="header-meta">
<span class="pill">12 fixed objects</span>
<span class="pill warning">No reference answer</span>
</div>
</header>
<main class="layout">
<section class="scene" aria-label="Side-by-side classification scene">
<canvas
id="scene"
tabindex="0"
aria-label="Interactive three-dimensional scene. Drag to rotate and scroll to zoom."
></canvas>
<div class="divider" aria-hidden="true"></div>
<div class="view-heading a">
<span class="rule">RULE A</span>
<strong>Size bands</strong>
<small>Group by displayed diameter</small>
</div>
<div class="view-heading b">
<span class="rule">RULE B</span>
<strong>Shape lexicon</strong>
<small>Group by chosen shape family</small>
</div>
<div class="scene-hint">DRAG TO ROTATE · SCROLL TO ZOOM</div>
<div class="scene-note">Identical positions and camera in both panes</div>
<div class="scene-actions">
<button
class="scene-button"
id="deltaToggle"
type="button"
aria-pressed="true"
>
Δ Mark differences
</button>
<button class="scene-button" id="resetCamera" type="button">
Reset view
</button>
</div>
</section>
<aside class="panel" aria-label="Experiment controls and assignment ledger">
<div class="panel-heading">
<div>
<h2>Assignment ledger</h2>
<p>Two transparent partitions of one unchanged set.</p>
</div>
<span class="fixed-badge">FIXED SET</span>
</div>
<div class="metrics" aria-live="polite">
<div class="metric changed">
<strong id="changedMetric">—</strong>
<span>changed assignments</span>
</div>
<div class="metric same">
<strong id="sameMetric">—</strong>
<span>same label</span>
</div>
</div>
<section class="rule-card a">
<div class="rule-title">
<h3><span class="rule-letter">A</span>Size ladder</h3>
<span class="rule-subtitle">editable thresholds</span>
</div>
<div class="bin-list">
<div class="bin-row">
<span class="group g1">G1</span>
<span>diameter ≤</span>
<output id="lowInline">0.99</output>
</div>
<div class="bin-row">
<span class="group g2">G2</span>
<span>above G1 and ≤</span>
<output id="highInline">1.44</output>
</div>
<div class="bin-row">
<span class="group g3">G3</span>
<span>diameter above</span>
<output id="highEcho">1.44</output>
</div>
</div>
<div class="control">
<label for="lowThreshold">
<span>Lower size cut</span>
<output id="lowOutput">0.99</output>
</label>
<input
id="lowThreshold"
type="range"
min="0.75"
max="1.20"
step="0.01"
value="0.99"
/>
</div>
<div class="control">
<label for="highThreshold">
<span>Upper size cut</span>
<output id="highOutput">1.44</output>
</label>
<input
id="highThreshold"
type="range"
min="1.20"
max="1.75"
step="0.01"
value="1.44"
/>
</div>
<p class="small-note">
Diameter is the object's maximum displayed dimension. G1–G3 are
shared category labels, not quality scores.
</p>
</section>
<section class="rule-card b">
<div class="rule-title">
<h3><span class="rule-letter">B</span>Shape lexicon</h3>
<span class="rule-subtitle">fixed experimental mapping</span>
</div>
<div class="bin-list">
<div class="bin-row">
<span class="group g1">G1</span>
<span>Block family</span>
<code>cube / cuboid</code>
</div>
<div class="bin-row">
<span class="group g2">G2</span>
<span>Facet family</span>
<code>octa / icosa</code>
</div>
<div class="bin-row">
<span class="group g3">G3</span>
<span>Axial family</span>
<code>tetra / cone</code>
</div>
</div>
<p class="small-note">
This family-to-label mapping is a chosen viewpoint. It is not
presented as a more valid classification.
</p>
</section>
<section class="ledger">
<div class="ledger-header">
<h3>Changed assignments</h3>
<label class="toggle">
<input id="changedOnly" type="checkbox" checked />
Changed only
</label>
</div>
<div class="table-wrap">
<table>
<caption class="sr-only">
Rule A and Rule B assignments for every fixed object
</caption>
<thead>
<tr>
<th>Object</th>
<th>Size</th>
<th>Shape</th>
<th>A</th>
<th>B</th>
<th>Result</th>
</tr>
</thead>
<tbody id="assignmentRows"></tbody>
</table>
</div>
</section>
<div class="truth-note">
<strong>No rule is ground truth.</strong>
A shared label only means that both rules produced the same output.
Agreement does not establish correctness, and the orange Δ marker
indicates where the two assignments differ.
</div>
</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 canvas = document.getElementById("scene");
const stage = canvas.parentElement;
const rowsBody = document.getElementById("assignmentRows");
const GROUP_COLORS = {
1: 0x58d8bd,
2: 0x73a9ff,
3: 0xf3c969
};
const GROUP_CSS = {
1: "g1",
2: "g2",
3: "g3"
};
// One fixed object set. Size is the maximum displayed dimension.
const OBJECTS = [
{ id: "O-01", shape: "Cube", family: "Block", size: 0.72, kind: "cube" },
{ id: "O-02", shape: "Cuboid", family: "Block", size: 0.94, kind: "slab" },
{ id: "O-03", shape: "Cube", family: "Block", size: 1.18, kind: "cube" },
{ id: "O-04", shape: "Cuboid", family: "Block", size: 1.62, kind: "slab" },
{ id: "O-05", shape: "Octahedron", family: "Facet", size: 0.82, kind: "octa" },
{ id: "O-06", shape: "Icosahedron",family: "Facet", size: 1.08, kind: "icosa" },
{ id: "O-07", shape: "Octahedron", family: "Facet", size: 1.36, kind: "octa" },
{ id: "O-08", shape: "Icosahedron",family: "Facet", size: 1.74, kind: "icosa" },
{ id: "O-09", shape: "Tetrahedron",family: "Axial", size: 0.68, kind: "tetra" },
{ id: "O-10", shape: "Cone", family: "Axial", size: 0.92, kind: "cone" },
{ id: "O-11", shape: "Tetrahedron",family: "Axial", size: 1.24, kind: "tetra" },
{ id: "O-12", shape: "Cone", family: "Axial", size: 1.56, kind: "cone" }
];
const SHAPE_MAPPING = {
Block: 1,
Facet: 2,
Axial: 3
};
const state = {
low: 0.99,
high: 1.44,
showDelta: true,
changedOnly: true
};
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x101619, 1);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101619);
scene.fog = new THREE.Fog(0x101619, 10, 19);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 50);
const cameraTarget = new THREE.Vector3(0, 0.58, 0);
const cameraState = {
theta: 0.58,
phi: 1.04,
radius: 10.4
};
const cameraGoal = { ...cameraState };
scene.add(new THREE.HemisphereLight(0xdaf2ff, 0x172026, 1.65));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.7);
keyLight.position.set(4.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x789cff, 1.0);
rimLight.position.set(-5, 4, -6);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(14, 12),
new THREE.MeshStandardMaterial({
color: 0x121a1e,
roughness: 0.96,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(12, 24, 0x34444c, 0x243037);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.6;
scene.add(grid);
const geometryCache = {
cube: new THREE.BoxGeometry(1, 1, 1),
slab: new THREE.BoxGeometry(1.3, 0.7, 0.9),
octa: new THREE.OctahedronGeometry(0.58, 0),
icosa: new THREE.IcosahedronGeometry(0.56, 0),
tetra: new THREE.TetrahedronGeometry(0.62, 0),
cone: new THREE.ConeGeometry(0.56, 1.1, 5, 1, false)
};
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x081014,
transparent: true,
opacity: 0.55
});
const deltaMaterial = new THREE.MeshBasicMaterial({
color: 0xff8b70,
transparent: true,
opacity: 0.9
});
const records = [];
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function createLabel() {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 384;
labelCanvas.height = 112;
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.42, 0.414, 1);
sprite.renderOrder = 10;
return { canvas: labelCanvas, ctx: labelCanvas.getContext("2d"), texture, sprite };
}
function drawLabel(label, id, group, changed) {
const ctx = label.ctx;
ctx.clearRect(0, 0, label.canvas.width, label.canvas.height);
const color = `#${GROUP_COLORS[group].toString(16).padStart(6, "0")}`;
roundedRect(ctx, 4, 5, 376, 102, 17);
ctx.fillStyle = "rgba(8, 13, 16, 0.91)";
ctx.fill();
ctx.lineWidth = state.showDelta && changed ? 5 : 3;
ctx.strokeStyle = state.showDelta && changed ? "#ff8b70" : color;
ctx.stroke();
ctx.textBaseline = "middle";
ctx.textAlign = "left";
ctx.fillStyle = "#e8f0f2";
ctx.font = "650 31px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText(id, 22, 56);
ctx.textAlign = "right";
ctx.fillStyle = color;
ctx.font = "750 42px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText(`G${group}`, 316, 56);
if (state.showDelta && changed) {
ctx.textAlign = "center";
ctx.fillStyle = "#ff8b70";
ctx.font = "700 39px ui-sans-serif, system-ui, sans-serif";
ctx.fillText("Δ", 354, 56);
}
label.texture.needsUpdate = true;
}
OBJECTS.forEach((object, index) => {
const root = new THREE.Group();
const col = index % 4;
const row = Math.floor(index / 4);
root.position.set(
(col - 1.5) * 1.85,
0,
(row - 1) * 1.85
);
scene.add(root);
const geometry = geometryCache[object.kind];
geometry.computeBoundingBox();
const bounds = geometry.boundingBox;
const maxDimension = Math.max(
bounds.max.x - bounds.min.x,
bounds.max.y - bounds.min.y,
bounds.max.z - bounds.min.z
);
const scale = object.size / maxDimension;
const height = (bounds.max.y - bounds.min.y) * scale;
const material = new THREE.MeshStandardMaterial({
color: 0x58d8bd,
roughness: 0.68,
metalness: 0.06,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.scale.setScalar(scale);
mesh.position.y = height / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 18),
edgeMaterial
);
mesh.add(edges);
root.add(mesh);
const disk = new THREE.Mesh(
new THREE.CylinderGeometry(0.56, 0.56, 0.025, 32),
new THREE.MeshStandardMaterial({
color: 0x58d8bd,
transparent: true,
opacity: 0.13,
roughness: 1,
depthWrite: false
})
);
disk.position.y = 0.015;
root.add(disk);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.59, 0.025, 6, 32),
new THREE.MeshBasicMaterial({
color: 0x58d8bd,
transparent: true,
opacity: 0.9
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.035;
root.add(ring);
const deltaMarker = new THREE.Mesh(
new THREE.TorusGeometry(0.67, 0.035, 6, 32),
deltaMaterial
);
deltaMarker.rotation.x = Math.PI / 2;
deltaMarker.position.y = 0.038;
deltaMarker.visible = false;
root.add(deltaMarker);
const labelA = createLabel();
const labelB = createLabel();
labelA.sprite.position.y = height + 0.56;
labelB.sprite.position.y = height + 0.56;
root.add(labelA.sprite, labelB.sprite);
records.push({
object,
root,
mesh,
disk,
ring,
deltaMarker,
labelA,
labelB,
a: 1,
b: 1,
changed: false
});
});
function ruleA(object) {
if (object.size <= state.low) return 1;
if (object.size <= state.high) return 2;
return 3;
}
function ruleB(object) {
return SHAPE_MAPPING[object.family];
}
function updateThresholdText() {
const low = state.low.toFixed(2);
const high = state.high.toFixed(2);
document.getElementById("lowInline").textContent = low;
document.getElementById("lowOutput").textContent = low;
document.getElementById("highInline").textContent = high;
document.getElementById("highEcho").textContent = high;
document.getElementById("highOutput").textContent = high;
}
function updateExperiment() {
let changedCount = 0;
let sameCount = 0;
const assignments = records.map(record => {
const a = ruleA(record.object);
const b = ruleB(record.object);
const changed = a !== b;
record.a = a;
record.b = b;
record.changed = changed;
if (changed) changedCount++;
else sameCount++;
drawLabel(record.labelA, record.object.id, a, changed);
drawLabel(record.labelB, record.object.id, b, changed);
record.deltaMarker.visible = changed && state.showDelta;
return {
id: record.object.id,
size: record.object.size,
shape: record.object.shape,
a,
b,
changed
};
});
document.getElementById("changedMetric").textContent = changedCount;
document.getElementById("sameMetric").textContent = sameCount;
const visible = assignments
.filter(row => !state.changedOnly || row.changed)
.sort((a, b) =>
Number(b.changed) - Number(a.changed) ||
a.id.localeCompare(b.id)
);
rowsBody.innerHTML = visible.map(row => `
<tr class="${row.changed ? "changed" : "same-row"}">
<td class="object-id">${row.id}</td>
<td class="mono">${row.size.toFixed(2)}</td>
<td>${row.shape}</td>
<td>
<span class="group ${GROUP_CSS[row.a]}">G${row.a}</span>
</td>
<td>
<span class="group ${GROUP_CSS[row.b]}">G${row.b}</span>
</td>
<td class="status ${row.changed ? "changed" : "same"}">
${row.changed ? "Changed" : "Same"}
</td>
</tr>
`).join("");
updateThresholdText();
}
function applyRule(rule) {
records.forEach(record => {
const group = rule === "a" ? record.a : record.b;
const color = GROUP_COLORS[group];
record.mesh.material.color.setHex(color);
record.mesh.material.emissive.setHex(color);
record.mesh.material.emissiveIntensity = 0.07;
record.disk.material.color.setHex(color);
record.ring.material.color.setHex(color);
record.labelA.sprite.visible = rule === "a";
record.labelB.sprite.visible = rule === "b";
});
}
const lowSlider = document.getElementById("lowThreshold");
const highSlider = document.getElementById("highThreshold");
lowSlider.addEventListener("input", () => {
state.low = Math.min(
Number(lowSlider.value),
state.high - 0.05
);
lowSlider.value = state.low.toFixed(2);
updateExperiment();
});
highSlider.addEventListener("input", () => {
state.high = Math.max(
Number(highSlider.value),
state.low + 0.05
);
highSlider.value = state.high.toFixed(2);
updateExperiment();
});
document.getElementById("changedOnly").addEventListener("change", event => {
state.changedOnly = event.target.checked;
updateExperiment();
});
document.getElementById("deltaToggle").addEventListener("click", event => {
state.showDelta = !state.showDelta;
event.currentTarget.setAttribute("aria-pressed", String(state.showDelta));
updateExperiment();
});
// Direct camera controls: no examples/addons or OrbitControls.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function setCameraGoal() {
cameraGoal.theta = 0.58;
cameraGoal.phi = 1.04;
cameraGoal.radius = 10.4;
}
document.getElementById("resetCamera").addEventListener("click", setCameraGoal);
canvas.addEventListener("pointerdown", event => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraGoal.theta -= dx * 0.008;
cameraGoal.phi = THREE.MathUtils.clamp(
cameraGoal.phi - dy * 0.006,
0.64,
1.42
);
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event?.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraGoal.radius = THREE.MathUtils.clamp(
cameraGoal.radius + event.deltaY * 0.008,
7.2,
15
);
}, { passive: false });
canvas.addEventListener("keydown", event => {
const key = event.key;
if (key === "ArrowLeft") cameraGoal.theta += 0.12;
else if (key === "ArrowRight") cameraGoal.theta -= 0.12;
else if (key === "ArrowUp") {
cameraGoal.phi = THREE.MathUtils.clamp(cameraGoal.phi - 0.09, 0.64, 1.42);
} else if (key === "ArrowDown") {
cameraGoal.phi = THREE.MathUtils.clamp(cameraGoal.phi + 0.09, 0.64, 1.42);
} else if (key === "+" || key === "=") {
cameraGoal.radius = Math.max(7.2, cameraGoal.radius - 0.6);
} else if (key === "-" || key === "_") {
cameraGoal.radius = Math.min(15, cameraGoal.radius + 0.6);
} else return;
event.preventDefault();
});
let viewWidth = 1;
let viewHeight = 1;
let stacked = false;
function resize() {
const rect = stage.getBoundingClientRect();
viewWidth = Math.max(1, Math.floor(rect.width));
viewHeight = Math.max(1, Math.floor(rect.height));
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(viewWidth, viewHeight, false);
stacked = viewWidth < 720;
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
function renderView(rule, x, y, width, height) {
renderer.setViewport(x, y, width, height);
renderer.setScissor(x, y, width, height);
camera.aspect = width / Math.max(1, height);
camera.updateProjectionMatrix();
applyRule(rule);
renderer.render(scene, camera);
}
function animate() {
requestAnimationFrame(animate);
const damping = 0.12;
cameraState.theta += (cameraGoal.theta - cameraState.theta) * damping;
cameraState.phi += (cameraGoal.phi - cameraState.phi) * damping;
cameraState.radius += (cameraGoal.radius - cameraState.radius) * damping;
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
renderer.setScissorTest(true);
if (stacked) {
const topHeight = Math.floor(viewHeight / 2);
renderView("a", 0, topHeight, viewWidth, viewHeight - topHeight);
renderView("b", 0, 0, viewWidth, topHeight);
} else {
const leftWidth = Math.floor(viewWidth / 2);
renderView("a", 0, 0, leftWidth, viewHeight);
renderView("b", leftWidth, 0, viewWidth - leftWidth, viewHeight);
}
renderer.setScissorTest(false);
}
updateExperiment();
resize();
animate();
</script>
</body>
</html>
```