Prompt specification
Build or customize the Three.js 3D scene "Community Sorting Education Station" 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: Community Sorting Education Station
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-sorting-education-station-x3991
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing material categories and contamination in waste sorting. Build an original station with clear bins, example items, and locally configurable labels. Require verified local rules before presenting actual disposal instructions. Voxel style.
Working Three.js Starter (community-sorting-education-station-x3991):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#0b121a">
<title>Sort / Station 04 — Voxel Waste Sorting</title>
<style>
:root {
color-scheme: dark;
--bg: #0b121a;
--panel: #111c27;
--panel-2: #162431;
--line: #2b3b4b;
--text: #eef6ff;
--muted: #94a8ba;
--paper: #f2bd52;
--packaging: #42c8c0;
--glass: #9a84ff;
--organics: #6ec86f;
--danger: #ff5366;
--verified: #6ee7a1;
--pixel-shadow: 4px 4px 0 rgba(0, 0, 0, 0.35);
}
* {
box-sizing: border-box;
}
[hidden] {
display: none !important;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
textarea {
font: inherit;
}
button,
summary {
cursor: pointer;
}
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible,
canvas:focus-visible {
outline: 3px solid var(--packaging);
outline-offset: 2px;
}
.app-header {
height: 76px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: #0d1721;
position: relative;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 3px;
flex: 0 0 auto;
}
.brand-mark span {
display: block;
background: var(--packaging);
}
.brand-mark span:nth-child(2) {
background: var(--paper);
}
.brand-mark span:nth-child(3) {
background: var(--glass);
}
.brand-mark span:nth-child(4) {
background: var(--organics);
}
.eyebrow,
.kicker {
margin: 0;
color: var(--muted);
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 2px 0 0;
font-size: clamp(1.05rem, 2vw, 1.35rem);
line-height: 1;
letter-spacing: 0.04em;
text-transform: uppercase;
}
h1 span {
color: var(--packaging);
}
.header-actions {
display: flex;
align-items: center;
gap: 10px;
}
.status,
.local-badge {
border: 1px solid var(--line);
padding: 8px 10px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.status.locked {
color: var(--paper);
border-color: #66522a;
background: #2a2315;
}
.status.verified {
color: var(--verified);
border-color: #2d6a48;
background: #142d21;
}
.local-badge {
color: var(--muted);
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1fr) 400px;
height: calc(100dvh - 76px);
}
.viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 35%, #1d3142 0, #0b121a 65%);
}
.viewport canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.loading {
position: absolute;
inset: 0;
display: grid;
place-items: center;
z-index: 5;
color: var(--muted);
background: var(--bg);
font-family: ui-monospace, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.view-controls {
position: absolute;
z-index: 3;
top: 18px;
right: 18px;
display: flex;
gap: 5px;
padding: 5px;
border: 1px solid var(--line);
background: rgba(10, 18, 27, 0.88);
box-shadow: var(--pixel-shadow);
backdrop-filter: blur(8px);
}
.view-controls button {
width: 36px;
height: 34px;
padding: 0;
border: 1px solid #34485a;
border-radius: 0;
color: var(--text);
background: #182735;
font-weight: 900;
}
.view-controls button:hover {
color: #071018;
background: var(--packaging);
}
.scene-guide {
position: absolute;
z-index: 2;
top: 18px;
left: 18px;
max-width: 280px;
padding: 10px 12px;
border-left: 3px solid var(--packaging);
background: rgba(10, 18, 27, 0.76);
color: #c8d7e4;
font-size: 0.76rem;
line-height: 1.45;
pointer-events: none;
backdrop-filter: blur(6px);
}
.scene-guide strong {
display: block;
color: var(--text);
font-size: 0.7rem;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.legend {
position: absolute;
z-index: 3;
left: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
gap: 8px 12px;
max-width: min(650px, calc(100% - 36px));
padding: 10px 12px;
border: 1px solid var(--line);
background: rgba(10, 18, 27, 0.88);
box-shadow: var(--pixel-shadow);
backdrop-filter: blur(8px);
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: #c8d7e4;
font-size: 0.7rem;
white-space: nowrap;
}
.swatch {
width: 10px;
height: 10px;
background: var(--c);
box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45);
}
.tooltip {
position: absolute;
z-index: 6;
max-width: 220px;
padding: 7px 9px;
border: 1px solid #4a6073;
background: #091019;
color: var(--text);
font-size: 0.72rem;
pointer-events: none;
box-shadow: var(--pixel-shadow);
}
.panel {
overflow-y: auto;
border-left: 1px solid var(--line);
background: var(--panel);
scrollbar-color: #3b5063 var(--panel);
scrollbar-width: thin;
}
.card {
padding: 22px;
border-bottom: 1px solid var(--line);
}
.card h2,
.card h3 {
margin: 5px 0 10px;
}
.card h2 {
font-size: 1.12rem;
letter-spacing: -0.015em;
}
.card h3 {
font-size: 1.25rem;
line-height: 1.2;
}
.card p {
color: var(--muted);
font-size: 0.82rem;
line-height: 1.55;
}
.rule-card {
background:
linear-gradient(135deg, rgba(66, 200, 192, 0.07), transparent 45%),
var(--panel);
}
.rule-intro {
margin-bottom: 16px !important;
}
.field {
display: block;
margin-top: 13px;
}
.field > span,
.field-label {
display: block;
margin-bottom: 6px;
color: #b8c9d8;
font-size: 0.7rem;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
input[type="text"],
input[type="url"],
textarea {
width: 100%;
border: 1px solid #35495b;
border-radius: 0;
color: var(--text);
background: #0b141e;
padding: 10px 11px;
}
input::placeholder,
textarea::placeholder {
color: #607587;
}
textarea {
min-height: 84px;
resize: vertical;
line-height: 1.4;
}
.attestation {
display: grid;
grid-template-columns: 18px 1fr;
gap: 9px;
align-items: start;
margin: 16px 0;
color: #c8d7e4;
font-size: 0.76rem;
line-height: 1.45;
cursor: pointer;
}
.attestation input {
width: 16px;
height: 16px;
margin: 1px 0 0;
accent-color: var(--packaging);
}
.primary-button,
.secondary-button {
min-height: 40px;
border-radius: 0;
padding: 10px 12px;
font-weight: 850;
letter-spacing: 0.025em;
transition: transform 100ms ease, box-shadow 100ms ease;
}
.primary-button {
width: 100%;
border: 1px solid #59ded6;
color: #061117;
background: var(--packaging);
box-shadow: 3px 3px 0 #175a59;
}
.secondary-button {
border: 1px solid #40576b;
color: var(--text);
background: #192a38;
}
.primary-button:hover,
.secondary-button:hover {
transform: translate(-1px, -1px);
box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.38);
}
.primary-button:disabled {
cursor: not-allowed;
opacity: 0.45;
transform: none;
}
.rule-message {
min-height: 20px;
margin: 12px 0 0 !important;
color: #c8d7e4 !important;
}
.rule-message.error {
color: #ff8795 !important;
}
.rule-message.success {
color: var(--verified) !important;
}
.verified-panel {
margin-top: 16px;
border: 1px solid #326148;
padding: 13px;
background: #12251c;
}
.verified-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
color: var(--verified);
font-size: 0.76rem;
}
.verified-row span {
color: #89a99a;
font-size: 0.65rem;
}
.source-link {
display: inline-block;
margin-top: 9px;
color: #8ce7ff;
font-size: 0.75rem;
}
details {
margin-top: 13px;
border-top: 1px solid #31513f;
padding-top: 12px;
}
summary {
color: var(--text);
font-size: 0.78rem;
font-weight: 800;
}
.rule-note {
margin-top: 14px;
padding-left: 10px;
border-left: 3px solid var(--c);
}
.rule-note h4 {
margin: 0 0 7px;
font-size: 0.78rem;
}
.lock-button {
width: 100%;
margin-top: 14px;
}
.labels-list {
display: grid;
gap: 11px;
margin-top: 16px;
}
.label-row {
display: grid;
grid-template-columns: 12px 1fr;
gap: 9px;
align-items: center;
}
.label-dot {
width: 12px;
height: 12px;
background: var(--c);
box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.4);
}
.label-row input {
padding: 8px 10px;
font-size: 0.8rem;
}
.item-category {
color: var(--packaging);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.item-badge {
display: inline-block;
margin: 4px 0 11px;
padding: 6px 8px;
border: 1px solid #36536a;
color: #9bb5ca;
background: #142331;
font-size: 0.66rem;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.item-badge.contaminated {
border-color: #75303b;
color: #ff8997;
background: #32151b;
}
.instruction-box {
margin-top: 16px;
border: 1px solid #356a4e;
padding: 14px;
background: #11261c;
}
.instruction-box .eyebrow {
color: var(--verified);
}
.instruction-box p {
margin-bottom: 0;
color: #d3e9dd;
white-space: pre-wrap;
}
.lock-notice {
margin-top: 15px;
padding: 12px;
border: 1px dashed #5e4a2b;
color: #d8be8f;
background: #241d12;
font-size: 0.75rem;
line-height: 1.45;
}
.next-button {
width: 100%;
margin-top: 16px;
}
.panel-footer {
padding: 18px 22px 28px;
color: #6f8496;
font-size: 0.68rem;
line-height: 1.5;
}
.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: 900px) {
body {
overflow: auto;
}
.app-header {
position: sticky;
top: 0;
}
.layout {
height: auto;
grid-template-columns: 1fr;
}
.viewport {
height: 60dvh;
min-height: 430px;
}
.panel {
overflow: visible;
border-left: 0;
border-top: 1px solid var(--line);
}
.local-badge {
display: none;
}
}
@media (max-width: 560px) {
.app-header {
height: 68px;
padding: 0 14px;
}
.brand-mark {
width: 30px;
height: 30px;
}
.brand .eyebrow {
display: none;
}
.status {
max-width: 145px;
overflow: hidden;
text-overflow: ellipsis;
}
.card {
padding: 19px 16px;
}
.scene-guide {
top: 64px;
left: 12px;
max-width: 225px;
}
.view-controls {
top: 10px;
right: 10px;
}
.legend {
left: 10px;
bottom: 10px;
gap: 7px 10px;
max-width: calc(100% - 20px);
}
.legend-item {
font-size: 0.63rem;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition: none !important;
}
}
</style>
</head>
<body>
<header class="app-header">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span><span></span>
</div>
<div>
<p class="eyebrow">Voxel material demonstrator</p>
<h1>Sort / Station <span>04</span></h1>
</div>
</div>
<div class="header-actions">
<span id="ruleStatus" class="status locked" aria-live="polite">
Local rules locked
</span>
<span class="local-badge">Local-first</span>
</div>
</header>
<main class="layout">
<section id="viewport" class="viewport" aria-label="Interactive voxel waste sorting station">
<div id="loading" class="loading">Building the sorting station…</div>
<div class="scene-guide">
<strong>Inspect the station</strong>
Drag to orbit, scroll to zoom, and select an example item.
</div>
<div class="view-controls" aria-label="Camera controls">
<button type="button" data-camera="left" aria-label="Rotate left">↶</button>
<button type="button" data-camera="right" aria-label="Rotate right">↷</button>
<button type="button" data-camera="in" aria-label="Zoom in">+</button>
<button type="button" data-camera="out" aria-label="Zoom out">−</button>
<button type="button" data-camera="reset" aria-label="Reset camera">⌂</button>
</div>
<div id="legend" class="legend" aria-label="Material color legend"></div>
<div id="tooltip" class="tooltip" role="status" hidden></div>
</section>
<aside class="panel" aria-label="Station configuration">
<section class="card rule-card">
<p class="kicker">01 / Local rule gate</p>
<h2>Verify before you dispose</h2>
<p class="rule-intro">
Actual disposal instructions remain hidden until you identify and
attest to the rules for your local authority.
</p>
<form id="rulesForm">
<label class="field" for="jurisdiction">
<span>Jurisdiction / authority</span>
<input
id="jurisdiction"
type="text"
autocomplete="organization"
placeholder="Your local waste authority"
maxlength="100"
>
</label>
<label class="field" for="sourceReference">
<span>Official rule reference</span>
<input
id="sourceReference"
type="text"
placeholder="Guide title, page, section, or code"
maxlength="180"
>
</label>
<label class="field" for="sourceUrl">
<span>Optional official URL</span>
<input
id="sourceUrl"
type="url"
inputmode="url"
placeholder="https://official-source.example/page"
maxlength="500"
>
</label>
<label class="attestation" for="attestation">
<input id="attestation" type="checkbox">
<span>
I reviewed the cited local source and confirmed that it applies
to this station’s material categories.
</span>
</label>
<button id="verifyButton" class="primary-button" type="button">
Verify & unlock local notes
</button>
</form>
<p id="ruleMessage" class="rule-message" aria-live="polite">
Verification is self-attested; this page does not perform a live authority lookup.
</p>
<div id="verifiedPanel" class="verified-panel" hidden>
<div class="verified-row">
<strong>✓ Local rules attested</strong>
<span id="verifiedTime"></span>
</div>
<a id="sourceLink" class="source-link" target="_blank" rel="noopener noreferrer" hidden>
Open cited official source ↗
</a>
<details id="notesDetails">
<summary>Transcribe local disposal notes</summary>
<div id="notesFields"></div>
<p>
Notes are saved only in this browser. Copy the applicable wording
from the source you reviewed rather than relying on a generic template.
</p>
</details>
<button id="lockButton" class="secondary-button lock-button" type="button">
Lock actual instructions
</button>
</div>
</section>
<section class="card">
<p class="kicker">02 / Local station labels</p>
<h2>Name each material bay</h2>
<p>These editable names update the physical 3D signs and legend.</p>
<div id="labelsList" class="labels-list"></div>
</section>
<section class="card" aria-live="polite">
<p class="kicker">03 / Example inspector</p>
<div id="itemCategory" class="item-category">Paper bay</div>
<h3 id="itemTitle">Flattened carton</h3>
<span id="itemBadge" class="item-badge">Reference example</span>
<p id="itemDescription"></p>
<div id="instructionBox" class="instruction-box" hidden>
<p class="eyebrow">Local disposal note</p>
<p id="instructionText"></p>
</div>
<div id="lockNotice" class="lock-notice">
Actual local disposal instructions are locked. Complete the rule
verification gate before they can be shown.
</div>
<button id="nextExample" class="secondary-button next-button" type="button">
Inspect next example →
</button>
</section>
<footer class="panel-footer">
Educational visualization only. Material categories, accepted items,
contamination definitions, and disposal directions vary by locality.
The local authority’s current published rules take precedence.
</footer>
</aside>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -----------------------------------------------------------------------
// Categories and local state
// -----------------------------------------------------------------------
const STORAGE_KEY = "sort-station-04-v1";
const categories = [
{
id: "paper",
color: 0xf2bd52,
css: "#f2bd52",
defaultLabel: "Paper & cardboard",
shortLabel: "Paper"
},
{
id: "packaging",
color: 0x42c8c0,
css: "#42c8c0",
defaultLabel: "Containers",
shortLabel: "Containers"
},
{
id: "glass",
color: 0x9a84ff,
css: "#9a84ff",
defaultLabel: "Glass",
shortLabel: "Glass"
},
{
id: "organics",
color: 0x6ec86f,
css: "#6ec86f",
defaultLabel: "Food & organics",
shortLabel: "Organics"
}
];
const defaultState = {
verified: false,
verifiedAt: null,
jurisdiction: "",
source: "",
url: "",
labels: Object.fromEntries(
categories.map(category => [category.id, category.defaultLabel])
),
notes: Object.fromEntries(
categories.map(category => [category.id, ""])
)
};
let state = loadState();
const viewport = document.getElementById("viewport");
const loading = document.getElementById("loading");
const tooltip = document.getElementById("tooltip");
const rulesForm = document.getElementById("rulesForm");
const jurisdictionInput = document.getElementById("jurisdiction");
const sourceInput = document.getElementById("sourceReference");
const urlInput = document.getElementById("sourceUrl");
const attestationInput = document.getElementById("attestation");
const ruleStatus = document.getElementById("ruleStatus");
const ruleMessage = document.getElementById("ruleMessage");
const verifiedPanel = document.getElementById("verifiedPanel");
const verifiedTime = document.getElementById("verifiedTime");
const sourceLink = document.getElementById("sourceLink");
const notesDetails = document.getElementById("notesDetails");
const notesFields = document.getElementById("notesFields");
const labelsList = document.getElementById("labelsList");
const legend = document.getElementById("legend");
function loadState() {
try {
const stored = JSON.parse(localStorage.getItem(STORAGE_KEY));
if (!stored || typeof stored !== "object") return structuredClone(defaultState);
return {
...structuredClone(defaultState),
...stored,
labels: {
...defaultState.labels,
...(stored.labels || {})
},
notes: {
...defaultState.notes,
...(stored.notes || {})
}
};
} catch {
return structuredClone(defaultState);
}
}
function saveState() {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
} catch {
// The application remains usable when browser storage is unavailable.
}
}
function categoryById(id) {
return categories.find(category => category.id === id);
}
function currentLabel(id) {
return (state.labels[id] || "").trim() || categoryById(id).defaultLabel;
}
// -----------------------------------------------------------------------
// UI: labels and legend
// -----------------------------------------------------------------------
function buildLabelEditor() {
labelsList.replaceChildren();
for (const category of categories) {
const row = document.createElement("label");
row.className = "label-row";
row.style.setProperty("--c", category.css);
const dot = document.createElement("span");
dot.className = "label-dot";
dot.setAttribute("aria-hidden", "true");
const input = document.createElement("input");
input.type = "text";
input.value = state.labels[category.id] || category.defaultLabel;
input.maxLength = 28;
input.setAttribute(
"aria-label",
`${category.defaultLabel} bay label`
);
input.addEventListener("input", () => {
state.labels[category.id] = input.value;
saveState();
updateCategoryPresentation(category.id);
updateSelectedItem();
});
row.append(dot, input);
labelsList.append(row);
}
}
function buildLegend() {
legend.replaceChildren();
for (const category of categories) {
const item = document.createElement("span");
item.className = "legend-item";
item.dataset.category = category.id;
const swatch = document.createElement("span");
swatch.className = "swatch";
swatch.style.setProperty("--c", category.css);
const label = document.createElement("span");
label.textContent = currentLabel(category.id);
item.append(swatch, label);
legend.append(item);
}
const contamination = document.createElement("span");
contamination.className = "legend-item";
const swatch = document.createElement("span");
swatch.className = "swatch";
swatch.style.setProperty("--c", "#ff5366");
const label = document.createElement("span");
label.textContent = "Contamination";
contamination.append(swatch, label);
legend.append(contamination);
}
function updateCategoryPresentation(id) {
const category = categoryById(id);
const label = currentLabel(id);
const legendItem = legend.querySelector(`[data-category="${id}"] span:last-child`);
if (legendItem) legendItem.textContent = label;
if (signRecords[id]) {
drawBaySign(signRecords[id], label, category);
}
const noteHeading = document.getElementById(`note-heading-${id}`);
if (noteHeading) noteHeading.textContent = label;
}
// -----------------------------------------------------------------------
// UI: local rule gate
// -----------------------------------------------------------------------
function isValidHttpUrl(value) {
try {
const url = new URL(value);
return url.protocol === "https:" || url.protocol === "http:";
} catch {
return false;
}
}
function invalidateRuleVerification(message = "The rule reference changed. Verify it again before showing local directions.") {
const wasVerified = state.verified;
state.verified = false;
state.verifiedAt = null;
attestationInput.checked = false;
saveState();
applyVerificationUI();
setRuleMessage(message, wasVerified ? "error" : "");
}
function setRuleMessage(message, type = "") {
ruleMessage.textContent = message;
ruleMessage.className = "rule-message";
if (type) ruleMessage.classList.add(type);
}
function applyVerificationUI() {
const verified = Boolean(
state.verified &&
state.jurisdiction.trim() &&
state.source.trim()
);
state.verified = verified;
ruleStatus.textContent = verified ? "Local rules verified" : "Local rules locked";
ruleStatus.className = verified ? "status verified" : "status locked";
verifiedPanel.hidden = !verified;
lockNotice.hidden = verified;
instructionBox.hidden = !verified;
if (!verified) {
sourceLink.hidden = true;
notesFields.replaceChildren();
return;
}
verifiedTime.textContent = state.verifiedAt
? new Date(state.verifiedAt).toLocaleString()
: "Saved locally";
if (isValidHttpUrl(state.url)) {
sourceLink.href = state.url;
sourceLink.hidden = false;
} else {
sourceLink.hidden = true;
}
notesDetails.open = true;
buildNotesEditor();
}
function buildNotesEditor() {
notesFields.replaceChildren();
for (const category of categories) {
const wrapper = document.createElement("div");
wrapper.className = "rule-note";
wrapper.style.setProperty("--c", category.css);
const heading = document.createElement("h4");
heading.id = `note-heading-${category.id}`;
heading.textContent = currentLabel(category.id);
const textarea = document.createElement("textarea");
textarea.maxLength = 700;
textarea.value = state.notes[category.id] || "";
textarea.placeholder = "Transcribe the applicable direction from the verified local source…";
textarea.setAttribute(
"aria-label",
`Local disposal note for ${currentLabel(category.id)}`
);
textarea.addEventListener("input", () => {
state.notes[category.id] = textarea.value;
saveState();
updateSelectedItem();
});
wrapper.append(heading, textarea);
notesFields.append(wrapper);
}
}
jurisdictionInput.addEventListener("input", () => {
state.jurisdiction = jurisdictionInput.value;
if (state.verified) invalidateRuleVerification();
saveState();
});
sourceInput.addEventListener("input", () => {
state.source = sourceInput.value;
if (state.verified) invalidateRuleVerification();
saveState();
});
urlInput.addEventListener("input", () => {
state.url = urlInput.value;
if (state.verified) invalidateRuleVerification();
saveState();
});
document.getElementById("verifyButton").addEventListener("click", event => {
event.preventDefault();
state.jurisdiction = jurisdictionInput.value.trim();
state.source = sourceInput.value.trim();
state.url = urlInput.value.trim();
if (!state.jurisdiction) {
setRuleMessage("Enter the jurisdiction or waste authority.", "error");
jurisdictionInput.focus();
return;
}
if (!state.source) {
setRuleMessage("Enter a reference to the official local rules.", "error");
sourceInput.focus();
return;
}
if (state.url && !isValidHttpUrl(state.url)) {
setRuleMessage("Use a valid HTTP or HTTPS URL, or leave the URL field empty.", "error");
urlInput.focus();
return;
}
if (!attestationInput.checked) {
setRuleMessage("Confirm that you reviewed the cited official source.", "error");
attestationInput.focus();
return;
}
state.verified = true;
state.verifiedAt = Date.now();
saveState();
applyVerificationUI();
setRuleMessage(
"Verified locally. You can now transcribe and display the cited disposal directions.",
"success"
);
});
document.getElementById("lockButton").addEventListener("click", () => {
state.verified = false;
state.verifiedAt = null;
attestationInput.checked = false;
saveState();
applyVerificationUI();
setRuleMessage("Actual disposal instructions are locked again.");
});
// -----------------------------------------------------------------------
// Three.js scene
// -----------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b121a);
scene.fog = new THREE.Fog(0x0b121a, 30, 52);
const camera = new THREE.PerspectiveCamera(45, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.domElement.id = "threeCanvas";
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"3D waste sorting station. Drag to orbit, scroll to zoom, and click examples to inspect them."
);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xcde8ff, 0x17222d, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1d6, 3.1);
sun.position.set(-8, 14, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00025;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x62d9ff, 1.25);
rimLight.position.set(10, 7, -9);
scene.add(rimLight);
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0x101b26,
roughness: 1
}),
groundAlt: new THREE.MeshStandardMaterial({
color: 0x142330,
roughness: 1
}),
platform: new THREE.MeshStandardMaterial({
color: 0x293847,
roughness: 0.88
}),
wall: new THREE.MeshStandardMaterial({
color: 0x1b2b39,
roughness: 0.8
}),
wallTrim: new THREE.MeshStandardMaterial({
color: 0x355064,
roughness: 0.7
}),
dark: new THREE.MeshStandardMaterial({
color: 0x0d1720,
roughness: 0.95
}),
bin: new THREE.MeshStandardMaterial({
color: 0x263746,
roughness: 0.72
}),
white: new THREE.MeshStandardMaterial({
color: 0xe8f1f5,
roughness: 0.72
}),
cardboard: new THREE.MeshStandardMaterial({
color: 0xc99345,
roughness: 0.95
}),
cardboardLight: new THREE.MeshStandardMaterial({
color: 0xe0b66a,
roughness: 0.95
}),
plastic: new THREE.MeshStandardMaterial({
color: 0x44c7d0,
roughness: 0.5
}),
film: new THREE.MeshStandardMaterial({
color: 0xbcebf0,
roughness: 0.25,
transparent: true,
opacity: 0.48
}),
glass: new THREE.MeshStandardMaterial({
color: 0x94e4d4,
roughness: 0.15,
transparent: true,
opacity: 0.52
}),
cap: new THREE.MeshStandardMaterial({
color: 0x7257d8,
roughness: 0.55
}),
food: new THREE.MeshStandardMaterial({
color: 0xe95f4d,
roughness: 0.88
}),
foodLight: new THREE.MeshStandardMaterial({
color: 0xf4bb55,
roughness: 0.9
}),
core: new THREE.MeshStandardMaterial({
color: 0xe9ddbd,
roughness: 1
}),
stain: new THREE.MeshStandardMaterial({
color: 0x70442d,
roughness: 1
}),
contamination: new THREE.MeshStandardMaterial({
color: 0xff425a,
emissive: 0x7c1020,
emissiveIntensity: 1.2,
roughness: 0.45
}),
selection: new THREE.MeshStandardMaterial({
color: 0xe9fbff,
emissive: 0x4fcbd0,
emissiveIntensity: 0.55,
roughness: 0.45
})
};
function addBox(parent, size, position, material, shadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeCanvasTexture(width, height) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
renderer.capabilities.getMaxAnisotropy(),
8
);
return { canvas, context, texture };
}
function drawBaySign(record, label, category) {
const { canvas, context, texture } = record;
const width = canvas.width;
const height = canvas.height;
context.clearRect(0, 0, width, height);
context.fillStyle = "#0d1822";
context.fillRect(0, 0, width, height);
context.fillStyle = category.css;
context.fillRect(0, 0, 25, height);
context.fillRect(0, height - 14, width, 14);
context.strokeStyle = "#3b5264";
context.lineWidth = 8;
context.strokeRect(4, 4, width - 8, height - 8);
let fontSize = 53;
context.font = `800 ${fontSize}px ui-monospace, monospace`;
while (context.measureText(label.toUpperCase()).width > width - 90 && fontSize > 24) {
fontSize -= 2;
context.font = `800 ${fontSize}px ui-monospace, monospace`;
}
context.textBaseline = "middle";
context.fillStyle = "#eef7ff";
context.fillText(label.toUpperCase(), 55, height * 0.45);
context.font = "700 19px ui-monospace, monospace";
context.fillStyle = category.css;
context.fillText("LOCAL MATERIAL BAY", 57, height * 0.76);
texture.needsUpdate = true;
}
function createBaySign(x, label, category) {
const record = makeCanvasTexture(768, 192);
const material = new THREE.MeshBasicMaterial({
map: record.texture,
transparent: true,
toneMapped: false
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(3.2, 0.82), material);
mesh.position.set(x, 3.02, 1.72);
scene.add(mesh);
const recordWithMeta = {
...record,
mesh,
material,
category
};
drawBaySign(recordWithMeta, label, category);
return recordWithMeta;
}
function createTextSprite(text, accent = "#42c8c0", background = "#0b151f") {
const { canvas, context, texture } = makeCanvasTexture(512, 128);
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = accent;
context.fillRect(0, 0, 12, canvas.height);
context.strokeStyle = accent;
context.lineWidth = 6;
context.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
let size = 43;
context.font = `800 ${size}px ui-monospace, monospace`;
while (context.measureText(text.toUpperCase()).width > 430 && size > 20) {
size -= 2;
context.font = `800 ${size}px ui-monospace, monospace`;
}
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#eef7ff";
context.fillText(text.toUpperCase(), 266, 64);
texture.needsUpdate = true;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
toneMapped: false
})
);
sprite.scale.set(1.75, 0.44, 1);
sprite.renderOrder = 20;
return sprite;
}
// Ground and block-built environment
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.39;
ground.receiveShadow = true;
scene.add(ground);
for (let x = -12; x <= 12; x += 2) {
for (let z = -5; z <= 5; z += 2) {
addBox(
scene,
[1.78, 0.08, 1.78],
[x, -0.34, z],
(x + z) % 4 === 0 ? materials.groundAlt : materials.ground,
false
);
}
}
// Platform and back wall
addBox(scene, [18.8, 0.34, 6.8], [0, -0.08, 0.35], materials.platform);
addBox(scene, [18.3, 0.16, 6.5], [0, 0.14, 0.35], materials.wallTrim);
addBox(scene, [18, 3.7, 0.36], [0, 2.05, -1.68], materials.wall);
// Voxel trim blocks on the back wall
for (let x = -8.4; x <= 8.4; x += 1.2) {
addBox(
scene,
[0.9, 0.16, 0.08],
[x, 0.55, -1.46],
materials.wallTrim
);
}
// Structural posts
for (const x of [-7.2, -3.6, 0, 3.6, 7.2]) {
addBox(scene, [0.27, 4.25, 0.27], [x, 2.32, 1.62], materials.wallTrim);
addBox(scene, [0.27, 4.25, 0.27], [x, 2.32, -1.43], materials.wallTrim);
}
// Stepped canopy
addBox(scene, [19.2, 0.3, 3.1], [0, 4.56, -0.75], materials.platform);
addBox(scene, [17.8, 0.24, 2.3], [0, 4.82, -1.02], materials.wallTrim);
addBox(scene, [12.8, 0.16, 1.35], [0, 5.02, -1.22], materials.dark);
// Canopy accent blocks
for (let x = -8.8; x <= 8.8; x += 1.1) {
addBox(
scene,
[0.68, 0.16, 0.16],
[x, 4.39, 0.78],
(Math.round(x * 10) % 2 === 0)
? materials.packaging
: materials.wallTrim
);
}
// Main station title
const titleRecord = makeCanvasTexture(1024, 160);
{
const { context, texture } = titleRecord;
context.fillStyle = "#0c1721";
context.fillRect(0, 0, 1024, 160);
context.fillStyle = "#42c8c0";
context.fillRect(0, 0, 1024, 13);
context.fillStyle = "#eef7ff";
context.font = "800 58px ui-monospace, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText("SORT / STATION 04", 512, 66);
context.fillStyle = "#7290a7";
context.font = "700 20px ui-monospace, monospace";
context.fillText("BLOCK-BY-BLOCK MATERIAL VIEW", 512, 119);
texture.needsUpdate = true;
}
const titlePlane = new THREE.Mesh(
new THREE.PlaneGeometry(5.2, 0.82),
new THREE.MeshBasicMaterial({
map: titleRecord.texture,
transparent: true,
toneMapped: false
})
);
titlePlane.position.set(0, 3.82, -1.47);
scene.add(titlePlane);
// Bins
const binXs = [-5.4, -1.8, 1.8, 5.4];
const signRecords = {};
categories.forEach((category, index) => {
const x = binXs[index];
const colorMaterial = new THREE.MeshStandardMaterial({
color: category.color,
roughness: 0.62,
metalness: 0.05
});
const bin = new THREE.Group();
bin.position.x = x;
scene.add(bin);
addBox(bin, [3.05, 0.18, 2.75], [0, 0.38, 0.83], materials.dark);
addBox(bin, [3.05, 1.58, 0.18], [0, 1.22, -0.43], materials.bin);
addBox(bin, [0.18, 1.58, 2.75], [-1.45, 1.22, 0.83], materials.bin);
addBox(bin, [0.18, 1.58, 2.75], [1.45, 1.22, 0.83], materials.bin);
addBox(bin, [3.05, 1.18, 0.18], [0, 0.99, 2.10], materials.bin);
// Color rim and front identification stripe
addBox(bin, [3.13, 0.16, 0.27], [0, 1.9, -0.43], colorMaterial);
addBox(bin, [0.27, 0.16, 2.75], [-1.45, 1.9, 0.83], colorMaterial);
addBox(bin, [0.27, 0.16, 2.75], [1.45, 1.9, 0.83], colorMaterial);
addBox(bin, [3.13, 0.16, 0.27], [0, 1.64, 2.10], colorMaterial);
addBox(bin, [2.64, 0.38, 0.09], [0, 0.95, 2.21], colorMaterial);
// Small block feet
addBox(bin, [0.38, 0.28, 0.38], [-1.05, 0.29, 2.0], materials.dark);
addBox(bin, [0.38, 0.28, 0.38], [1.05, 0.29, 2.0], materials.dark);
signRecords[category.id] = createBaySign(
x,
currentLabel(category.id),
category
);
// A colored square on the platform in front of each bay
addBox(
scene,
[0.42, 0.12, 0.42],
[x, 0.27, 3.02],
colorMaterial
);
});
// -----------------------------------------------------------------------
// Example objects
// -----------------------------------------------------------------------
const itemMeshes = [];
const contaminationMarkers = [];
const examples = [];
function registerItem(id, meta, group, labelText, accent, labelPosition) {
group.userData.itemId = id;
group.userData.meta = meta;
const label = createTextSprite(labelText, accent);
label.position.copy(labelPosition);
group.add(label);
group.traverse(object => {
if (object.isMesh || object.isSprite) {
object.userData.itemId = id;
itemMeshes.push(object);
}
});
examples.push(meta);
return group;
}
function addContaminationMarker(group, halfWidth = 0.5, halfDepth = 0.42) {
const marker = new THREE.Group();
marker.position.y = 0.52;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addBox(
marker,
[0.32, 0.07, 0.07],
[sx * (halfWidth - 0.16), 0, sz * halfDepth],
materials.contamination,
false
);
addBox(
marker,
[0.07, 0.32, 0.07],
[sx * halfWidth, 0, sz * (halfDepth - 0.16)],
materials.contamination,
false
);
}
}
const beacon = addBox(
marker,
[0.18, 0.18, 0.18],
[0, 0.82, 0],
materials.contamination,
false
);
beacon.userData.isBeacon = true;
group.add(marker);
contaminationMarkers.push(marker);
return marker;
}
// Flattened carton
{
const group = new THREE.Group();
group.position.set(-5.78, 0.56, 0.94);
addBox(group, [1.12, 0.13, 0.82], [0, 0.08, 0], materials.cardboard);
addBox(group, [1.02, 0.12, 0.74], [0.04, 0.22, 0.03], materials.cardboardLight);
addBox(group, [0.88, 0.11, 0.65], [-0.02, 0.35, 0.05], materials.cardboard);
addBox(group, [0.08, 0.13, 0.85], [-0.2, 0.08, 0], materials.cardboardLight);
registerItem(
"paper-clean",
{
id: "paper-clean",
category: "paper",
title: "Flattened carton",
contaminated: false,
observation:
"A representative paper-packaging example placed in the paper material bay.",
x: -5.78,
z: 0.94
},
group,
"Carton",
"#f2bd52",
new THREE.Vector3(0, 1.35, 0)
);
scene.add(group);
}
// Greasy cup: contamination example
{
const group = new THREE.Group();
group.position.set(-4.55, 0.56, 0.94);
addBox(group, [0.55, 0.12, 0.48], [0, 0.07, 0], materials.cardboardLight);
addBox(group, [0.48, 0.44, 0.07], [0, 0.31, -0.19], materials.cardboard);
addBox(group, [0.07, 0.44, 0.43], [-0.23, 0.31, 0], materials.cardboard);
addBox(group, [0.07, 0.44, 0.43], [0.23, 0.31, 0], materials.cardboard);
addBox(group, [0.24, 0.05, 0.2], [0, 0.15, 0.02], materials.stain);
addContaminationMarker(group, 0.42, 0.34);
registerItem(
"paper-contaminated",
{
id: "paper-contaminated",
category: "paper",
title: "Greasy takeaway cup",
contaminated: true,
observation:
"A food-soiled paper item is marked as a contamination example. Its source material category remains paper.",
x: -4.55,
z: 0.94
},
group,
"Greasy cup",
"#ff5366",
new THREE.Vector3(0, 1.55, 0)
);
scene.add(group);
}
// Container bottle
{
const group = new THREE.Group();
group.position.set(-2.08, 0.56, 0.94);
addBox(group, [0.54, 0.66, 0.46], [0, 0.36, 0], materials.plastic);
addBox(group, [0.39, 0.2, 0.36], [0, 0.77, 0], materials.plastic);
addBox(group, [0.23, 0.22, 0.23], [0, 0.98, 0], materials.plastic);
addBox(group, [0.28, 0.12, 0.28], [0, 1.14, 0], materials.cap);
addBox(group, [0.12, 0.43, 0.03], [0, 0.4, 0.24], materials.white);
registerItem(
"packaging-clean",
{
id: "packaging-clean",
category: "packaging",
title: "Plastic container",
contaminated: false,
observation:
"A representative rigid container example placed in the container material bay.",
x: -2.08,
z: 0.94
},
group,
"Container",
"#42c8c0",
new THREE.Vector3(0, 1.65, 0)
);
scene.add(group);
}
// Loose film: contamination example
{
const group = new THREE.Group();
group.position.set(-1.12, 0.58, 0.95);
addBox(group, [0.54, 0.06, 0.46], [0, 0.08, 0], materials.film);
addBox(group, [0.44, 0.05, 0.39], [0.05, 0.18, 0.02], materials.film);
addBox(group, [0.34, 0.05, 0.31], [-0.04, 0.28, -0.02], materials.film);
addBox(group, [0.14, 0.14, 0.08], [0.18, 0.35, 0], materials.contamination);
addContaminationMarker(group, 0.4, 0.34);
registerItem(
"packaging-contaminated",
{
id: "packaging-contaminated",
category: "packaging",
title: "Loose plastic film",
contaminated: true,
observation:
"A loose-film example is flagged to demonstrate contamination in the container material bay.",
x: -1.12,
z: 0.95
},
group,
"Loose film",
"#ff5366",
new THREE.Vector3(0, 1.58, 0)
);
scene.add(group);
}
// Glass jar
{
const group = new THREE.Group();
group.position.set(1.8, 0.56, 0.95);
addBox(group, [0.72, 0.82, 0.65], [0, 0.44, 0], materials.glass);
addBox(group, [0.78, 0.13, 0.71], [0, 0.92, 0], materials.cap);
addBox(group, [0.08, 0.5, 0.03], [0, 0.43, 0.34], materials.white);
registerItem(
"glass-clean",
{
id: "glass-clean",
category: "glass",
title: "Glass jar",
contaminated: false,
observation:
"A representative glass-container example placed in the glass material bay.",
x: 1.8,
z: 0.95
},
group,
"Glass jar",
"#9a84ff",
new THREE.Vector3(0, 1.55, 0)
);
scene.add(group);
}
// Food core
{
const group = new THREE.Group();
group.position.set(5.4, 0.56, 0.96);
addBox(group, [0.52, 0.44, 0.5], [0, 0.26, 0], materials.food);
addBox(group, [0.28, 0.28, 0.28], [0.1, 0.58, 0], materials.foodLight);
addBox(group, [0.34, 0.28, 0.33], [-0.07, 0.59, 0.02], materials.core);
addBox(group, [0.1, 0.34, 0.1], [-0.16, 0.78, 0], materials.core);
registerItem(
"organics-clean",
{
id: "organics-clean",
category: "organics",
title: "Food core",
contaminated: false,
observation:
"A representative food-scrap example placed in the food and organics material bay.",
x: 5.4,
z: 0.96
},
group,
"Food core",
"#6ec86f",
new THREE.Vector3(0, 1.55, 0)
);
scene.add(group);
}
// -----------------------------------------------------------------------
// Selection marker and inspector
// -----------------------------------------------------------------------
const selectionMarker = new THREE.Group();
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addBox(
selectionMarker,
[0.38, 0.055, 0.055],
[sx * 0.62, 0, sz * 0.48],
materials.selection,
false
);
addBox(
selectionMarker,
[0.055, 0.055, 0.38],
[sx * 0.8, 0, sz * 0.3],
materials.selection,
false
);
}
}
scene.add(selectionMarker);
const itemCategory = document.getElementById("itemCategory");
const itemTitle = document.getElementById("itemTitle");
const itemBadge = document.getElementById("itemBadge");
const itemDescription = document.getElementById("itemDescription");
const instructionBox = document.getElementById("instructionBox");
const instructionText = document.getElementById("instructionText");
const lockNotice = document.getElementById("lockNotice");
const nextExample = document.getElementById("nextExample");
let selectedId = "paper-clean";
function updateSelectedItem() {
const meta = examples.find(example => example.id === selectedId) || examples[0];
const category = categoryById(meta.category);
itemCategory.textContent = `${currentLabel(meta.category)} bay`;
itemCategory.style.color = category.css;
itemTitle.textContent = meta.title;
itemDescription.textContent = meta.observation;
itemBadge.textContent = meta.contaminated
? "Contamination example"
: "Reference example";
itemBadge.className = meta.contaminated
? "item-badge contaminated"
: "item-badge";
selectionMarker.position.set(meta.x, 0.5, meta.z);
if (state.verified) {
const note = (state.notes[meta.category] || "").trim();
instructionBox.hidden = false;
instructionText.textContent = note ||
"No local direction has been transcribed for this category yet.";
} else {
instructionBox.hidden = true;
instructionText.textContent = "";
}
lockNotice.hidden = Boolean(state.verified);
}
nextExample.addEventListener("click", () => {
const index = examples.findIndex(example => example.id === selectedId);
selectedId = examples[(index + 1) % examples.length].id;
updateSelectedItem();
});
// -----------------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard and buttons
// -----------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 2.0, 0.35);
const cameraState = {
theta: 0.35,
phi: 1.14,
radius: 23,
targetTheta: 0.35,
targetPhi: 1.14,
targetRadius: 23
};
function resetCamera() {
cameraState.targetTheta = 0.35;
cameraState.targetPhi = 1.14;
cameraState.targetRadius = camera.aspect < 1 ? 28 : 23;
}
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.phi),
cameraTarget.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
}
document.querySelectorAll("[data-camera]").forEach(button => {
button.addEventListener("click", () => {
const action = button.dataset.camera;
if (action === "left") cameraState.targetTheta -= 0.25;
if (action === "right") cameraState.targetTheta += 0.25;
if (action === "in") cameraState.targetRadius = Math.max(13, cameraState.targetRadius - 2);
if (action === "out") cameraState.targetRadius = Math.min(34, cameraState.targetRadius + 2);
if (action === "reset") resetCamera();
});
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerStart = new THREE.Vector2();
let dragging = false;
let pointerId = null;
let dragDistance = 0;
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function hitTest(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(itemMeshes, false);
for (const intersection of intersections) {
const id = intersection.object.userData.itemId;
if (id) return id;
}
return null;
}
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
dragging = true;
pointerId = event.pointerId;
dragDistance = 0;
pointerStart.set(event.clientX, event.clientY);
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (dragging && event.pointerId === pointerId) {
const dx = event.clientX - pointerStart.x;
const dy = event.clientY - pointerStart.y;
dragDistance = Math.max(dragDistance, Math.hypot(dx, dy));
cameraState.targetTheta -= dx * 0.006;
cameraState.targetPhi = THREE.MathUtils.clamp(
cameraState.targetPhi - dy * 0.005,
0.5,
1.45
);
pointerStart.set(event.clientX, event.clientY);
tooltip.hidden = true;
return;
}
const id = hitTest(event);
renderer.domElement.style.cursor = id ? "pointer" : "grab";
if (id) {
const meta = examples.find(example => example.id === id);
tooltip.textContent = `${meta.title} — click to inspect`;
tooltip.hidden = false;
const rect = viewport.getBoundingClientRect();
const x = Math.min(
event.clientX - rect.left + 12,
rect.width - tooltip.offsetWidth - 8
);
const y = Math.min(
event.clientY - rect.top + 12,
rect.height - tooltip.offsetHeight - 8
);
tooltip.style.left = `${x}px`;
tooltip.style.top = `${y}px`;
} else {
tooltip.hidden = true;
}
});
renderer.domElement.addEventListener("pointerup", event => {
if (!dragging || event.pointerId !== pointerId) return;
dragging = false;
pointerId = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.style.cursor = "grab";
if (dragDistance < 6) {
const id = hitTest(event);
if (id) {
selectedId = id;
updateSelectedItem();
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
pointerId = null;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) tooltip.hidden = true;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius + event.deltaY * 0.012,
13,
34
);
}, { passive: false });
renderer.domElement.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.targetTheta -= 0.12;
break;
case "ArrowRight":
cameraState.targetTheta += 0.12;
break;
case "ArrowUp":
cameraState.targetPhi = Math.max(0.5, cameraState.targetPhi - 0.1);
break;
case "ArrowDown":
cameraState.targetPhi = Math.min(1.45, cameraState.targetPhi + 0.1);
break;
case "+":
case "=":
cameraState.targetRadius = Math.max(13, cameraState.targetRadius - 1.5);
break;
case "-":
cameraState.targetRadius = Math.min(34, cameraState.targetRadius + 1.5);
break;
case "Home":
resetCamera();
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
renderer.domElement.addEventListener("dblclick", resetCamera);
// -----------------------------------------------------------------------
// Resize and animation
// -----------------------------------------------------------------------
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
camera.aspect = width / height;
camera.fov = camera.aspect < 1 ? 56 : 45;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
resize();
const clock = new THREE.Clock();
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.exp(-8 * dt);
cameraState.theta += (cameraState.targetTheta - cameraState.theta) * damping;
cameraState.phi += (cameraState.targetPhi - cameraState.phi) * damping;
cameraState.radius += (cameraState.targetRadius - cameraState.radius) * damping;
updateCamera();
if (!reduceMotion) {
contaminationMarkers.forEach((marker, index) => {
const pulse = 1 + Math.sin(clock.elapsedTime * 3.2 + index) * 0.045;
marker.scale.setScalar(pulse);
const beacon = marker.children.find(child => child.userData.isBeacon);
if (beacon) {
beacon.position.y = 0.82 + Math.sin(clock.elapsedTime * 3.2 + index) * 0.08;
beacon.rotation.y = clock.elapsedTime * 0.8;
}
});
selectionMarker.rotation.y = Math.sin(clock.elapsedTime * 0.7) * 0.035;
}
renderer.render(scene, camera);
}
// -----------------------------------------------------------------------
// Initialize UI state
// -----------------------------------------------------------------------
jurisdictionInput.value = state.jurisdiction;
sourceInput.value = state.source;
urlInput.value = state.url;
attestationInput.checked = Boolean(state.verified);
buildLabelEditor();
buildLegend();
applyVerificationUI();
updateSelectedItem();
resetCamera();
updateCamera();
loading.remove();
animate();
</script>
</body>
</html>
```