Prompt specification
Build or customize the Three.js 3D scene "Boundary Agreement Revision Table" 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: Boundary Agreement Revision Table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/boundary-agreement-revision-table-x3240
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing negotiated boundaries between personal and shared space. Build a fictional neighborhood model with competing access requests. Let users revise an explicit agreement and show affected paths and permissions before applying the change. Voxel style.
Working Three.js Starter (boundary-agreement-revision-table-x3240):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Common Ground — Boundary Negotiation Sandbox</title>
<style>
:root {
--ink: #17262b;
--muted: #68777a;
--paper: #f5f2e9;
--panel: #fffdf7;
--line: #dcded6;
--private: #e88975;
--shared: #42b69f;
--public: #dfc45c;
--grant: #aa5ee8;
--restrict: #ed884d;
--navy: #122126;
--shadow: 0 12px 32px rgba(24, 37, 40, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
background: var(--navy);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
font-size: 14px;
}
button,
input {
font: inherit;
}
button {
cursor: pointer;
}
button:disabled {
cursor: not-allowed;
opacity: 0.48;
}
[hidden] {
display: none !important;
}
.header {
height: 68px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 22px;
background: #101d21;
color: #f7f4ea;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
position: relative;
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 3px;
transform: rotate(-4deg);
}
.brand-mark i {
display: block;
border-radius: 2px;
background: #f4f0e6;
}
.brand-mark i:nth-child(1),
.brand-mark i:nth-child(5),
.brand-mark i:nth-child(9) {
background: var(--shared);
}
.brand-mark i:nth-child(3),
.brand-mark i:nth-child(7) {
background: var(--private);
}
.brand-title {
font-size: 16px;
font-weight: 760;
letter-spacing: -0.01em;
}
.brand-subtitle {
margin-top: 3px;
color: #9fb0b2;
font-size: 11px;
letter-spacing: 0.02em;
}
.header-center {
display: flex;
align-items: center;
gap: 10px;
color: #c8d2d0;
font-size: 12px;
}
.scenario-chip {
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 999px;
background: rgba(255, 255, 255, 0.05);
}
.local-chip {
color: #8fa2a4;
}
.local-chip::before {
content: "";
display: inline-block;
width: 6px;
height: 6px;
margin-right: 7px;
border-radius: 50%;
background: #61d6b9;
box-shadow: 0 0 10px rgba(97, 214, 185, 0.6);
}
.header-actions {
display: flex;
align-items: center;
gap: 10px;
}
.version-pill {
padding: 7px 10px;
color: #dce4e2;
border-radius: 7px;
background: rgba(255, 255, 255, 0.07);
font-size: 11px;
white-space: nowrap;
}
.ghost-button {
border: 1px solid rgba(255, 255, 255, 0.15);
color: #e4ebe9;
background: transparent;
border-radius: 8px;
padding: 8px 11px;
font-size: 12px;
}
.ghost-button:hover {
background: rgba(255, 255, 255, 0.08);
}
.app-shell {
height: calc(100vh - 68px);
display: grid;
grid-template-columns: 292px minmax(420px, 1fr) 360px;
min-height: 0;
}
.side-panel {
background: var(--paper);
min-height: 0;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: #c4c9c0 transparent;
position: relative;
z-index: 10;
}
.requests-panel {
border-right: 1px solid #d4d7cf;
}
.agreement-panel {
border-left: 1px solid #d4d7cf;
}
.panel-inner {
padding: 22px 19px;
}
.eyebrow {
color: #7d8887;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.panel-title-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.panel-title {
margin: 7px 0 0;
font-size: 21px;
line-height: 1.15;
letter-spacing: -0.035em;
}
.count-badge {
min-width: 24px;
height: 24px;
display: grid;
place-items: center;
border-radius: 8px;
background: #e4e6de;
color: #5e6969;
font-size: 11px;
font-weight: 800;
}
.panel-description {
margin: 10px 0 19px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.request-list {
display: grid;
gap: 11px;
}
.request-card {
border: 1px solid #dadcd4;
border-radius: 13px;
background: rgba(255, 253, 247, 0.88);
padding: 13px;
transition: border-color 160ms ease, box-shadow 160ms ease,
transform 160ms ease;
}
.request-card:hover {
border-color: #aeb9b3;
box-shadow: 0 8px 20px rgba(36, 49, 47, 0.07);
transform: translateY(-1px);
}
.request-card.in-draft {
border-color: #c19ae9;
background: #fbf8ff;
}
.request-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.request-icon {
width: 30px;
height: 30px;
display: grid;
place-items: center;
border-radius: 9px;
background: #e8e9e2;
color: #415250;
font-size: 15px;
font-weight: 800;
}
.request-card.in-draft .request-icon {
background: #eadcfa;
color: #8146b8;
}
.request-status {
padding: 4px 7px;
border-radius: 999px;
background: #ecece6;
color: #737d7b;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
white-space: nowrap;
}
.request-status.included {
color: #2e796a;
background: #d9f0e8;
}
.request-status.draft {
color: #7844a9;
background: #eadcfa;
}
.request-card h3 {
margin: 11px 0 4px;
font-size: 14px;
line-height: 1.25;
letter-spacing: -0.015em;
}
.request-by {
color: #88918f;
font-size: 10px;
}
.request-ask {
margin: 10px 0;
color: #53615f;
font-size: 12px;
line-height: 1.45;
}
.conflict-note {
display: flex;
align-items: flex-start;
gap: 7px;
padding-top: 9px;
border-top: 1px solid #e3e4dd;
color: #8a684d;
font-size: 10px;
line-height: 1.35;
}
.conflict-note::before {
content: "↔";
color: #d28755;
font-size: 13px;
font-weight: 900;
}
.request-action {
width: 100%;
margin-top: 11px;
padding: 8px 10px;
border: 1px solid #ccd2ca;
border-radius: 8px;
background: #f8f7f1;
color: #364744;
font-size: 11px;
font-weight: 750;
}
.request-action:hover {
border-color: #9eaba4;
background: #fff;
}
.request-action.included {
color: #63418a;
border-color: #d5bcec;
background: #f4ecfc;
}
.scenario-note {
margin-top: 18px;
padding: 13px;
border-radius: 11px;
background: #e8ebe3;
color: #61706b;
font-size: 11px;
line-height: 1.5;
}
.scenario-note strong {
display: block;
margin-bottom: 3px;
color: #3b4d48;
font-size: 11px;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #d8e0db;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.stage-top {
position: absolute;
z-index: 3;
top: 16px;
left: 16px;
right: 16px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
pointer-events: none;
}
.map-label {
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.56);
border-radius: 10px;
background: rgba(249, 248, 240, 0.86);
box-shadow: 0 7px 20px rgba(31, 48, 45, 0.1);
backdrop-filter: blur(10px);
}
.map-label strong {
display: block;
font-size: 11px;
letter-spacing: 0.03em;
}
.map-label span {
display: block;
margin-top: 3px;
color: #73807d;
font-size: 9px;
}
.legend {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: 270px;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
padding: 6px 8px;
border-radius: 8px;
background: rgba(249, 248, 240, 0.86);
color: #4b5b58;
box-shadow: 0 5px 16px rgba(31, 48, 45, 0.08);
font-size: 9px;
font-weight: 700;
backdrop-filter: blur(8px);
}
.legend-dot {
width: 8px;
height: 8px;
border-radius: 2px;
}
.view-tools {
position: absolute;
z-index: 4;
top: 77px;
left: 16px;
display: grid;
gap: 6px;
}
.tool-button {
width: 34px;
height: 34px;
display: grid;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 9px;
background: rgba(249, 248, 240, 0.9);
color: #40514e;
box-shadow: 0 5px 16px rgba(31, 48, 45, 0.08);
font-size: 17px;
}
.tool-button:hover {
background: #fff;
}
.tile-card {
position: absolute;
z-index: 5;
top: 78px;
left: 59px;
width: 214px;
padding: 13px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 11px;
background: rgba(255, 253, 247, 0.94);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
}
.tile-card small {
color: #83908c;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.tile-card strong {
display: block;
margin: 5px 0 4px;
font-size: 13px;
}
.tile-card span {
display: block;
color: #687673;
font-size: 10px;
line-height: 1.45;
}
.tile-card button {
position: absolute;
top: 7px;
right: 8px;
width: 22px;
height: 22px;
padding: 0;
border: 0;
background: transparent;
color: #84908d;
font-size: 18px;
}
.tooltip {
position: absolute;
z-index: 9;
pointer-events: none;
max-width: 210px;
padding: 8px 10px;
border-radius: 8px;
background: rgba(20, 33, 36, 0.93);
color: #f7f4ea;
box-shadow: 0 8px 20px rgba(16, 28, 31, 0.2);
font-size: 10px;
line-height: 1.4;
transform: translate(12px, 12px);
}
.tooltip strong {
display: block;
margin-bottom: 2px;
color: #ffffff;
font-size: 11px;
}
.preview-dock {
position: absolute;
z-index: 6;
left: 16px;
right: 16px;
bottom: 16px;
padding: 13px 14px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 13px;
background: rgba(255, 253, 247, 0.94);
box-shadow: 0 13px 36px rgba(22, 38, 39, 0.18);
backdrop-filter: blur(14px);
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
}
.preview-copy {
min-width: 0;
}
.preview-kicker {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 4px;
color: #7a8682;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.preview-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #aeb7b2;
}
.preview-dot.active {
background: var(--grant);
box-shadow: 0 0 0 4px rgba(170, 94, 232, 0.12);
}
.preview-title {
font-size: 13px;
font-weight: 800;
}
.preview-summary {
margin-top: 3px;
color: #6f7c78;
font-size: 10px;
line-height: 1.35;
}
.preview-actions {
display: flex;
gap: 8px;
flex-shrink: 0;
}
.secondary-button,
.primary-button {
border-radius: 8px;
padding: 9px 12px;
font-size: 11px;
font-weight: 800;
}
.secondary-button {
border: 1px solid #d3d7cf;
background: #fffefa;
color: #55635f;
}
.primary-button {
border: 1px solid #253a38;
background: #243c39;
color: #f9f6ed;
box-shadow: 0 5px 12px rgba(32, 57, 53, 0.18);
}
.primary-button:hover:not(:disabled) {
background: #31514c;
}
.agreement-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.draft-badge {
padding: 5px 8px;
border-radius: 7px;
background: #e5e8df;
color: #68736f;
font-size: 9px;
font-weight: 800;
white-space: nowrap;
}
.draft-badge.changed {
color: #71419d;
background: #eadcf7;
}
.agreement-intro {
margin: 12px 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.section-label {
display: flex;
align-items: center;
gap: 8px;
margin: 18px 0 9px;
color: #73807b;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.section-label::after {
content: "";
height: 1px;
flex: 1;
background: #d9dcd3;
}
.clause {
padding: 12px;
margin-bottom: 9px;
border: 1px solid #dbddd5;
border-radius: 11px;
background: rgba(255, 253, 247, 0.85);
}
.clause-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.clause-name {
display: flex;
align-items: center;
gap: 9px;
min-width: 0;
}
.clause-index {
width: 23px;
height: 23px;
flex: 0 0 auto;
display: grid;
place-items: center;
border-radius: 7px;
background: #e9ebe4;
color: #75817d;
font-size: 9px;
font-weight: 850;
}
.clause strong {
display: block;
font-size: 11px;
line-height: 1.25;
}
.clause small {
display: block;
margin-top: 3px;
color: #89928f;
font-size: 9px;
line-height: 1.35;
}
.switch {
position: relative;
width: 34px;
height: 20px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch span {
position: absolute;
inset: 0;
border-radius: 999px;
background: #c9cec7;
transition: background 160ms ease;
}
.switch span::after {
content: "";
position: absolute;
width: 14px;
height: 14px;
left: 3px;
top: 3px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 3px rgba(22, 34, 33, 0.22);
transition: transform 160ms ease;
}
.switch input:checked + span {
background: var(--shared);
}
.switch input:checked + span::after {
transform: translateX(14px);
}
.range-wrap {
margin-top: 12px;
padding-top: 10px;
border-top: 1px solid #e2e3dd;
}
.range-labels {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
color: #73807c;
font-size: 9px;
}
.range-output {
padding: 3px 6px;
border-radius: 5px;
background: #e8ebe4;
color: #42544f;
font-size: 10px;
font-weight: 850;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 7px 0 0;
accent-color: var(--shared);
cursor: pointer;
}
.impact-note {
margin-top: 12px;
padding: 11px;
border-radius: 9px;
border: 1px solid #d8dbd2;
background: #eaede6;
color: #61706b;
font-size: 10px;
line-height: 1.45;
}
.impact-note.warning {
color: #81543a;
border-color: #ead2bd;
background: #f7e9dd;
}
.impact-note strong {
color: inherit;
}
.change-list {
display: grid;
gap: 7px;
}
.change-row {
display: grid;
grid-template-columns: 8px 1fr;
gap: 9px;
padding: 10px;
border: 1px solid #dcddd6;
border-radius: 9px;
background: #fffefa;
}
.change-dot {
width: 7px;
height: 7px;
margin-top: 4px;
border-radius: 2px;
background: var(--grant);
}
.change-dot.restrict {
background: var(--restrict);
}
.change-row strong {
display: block;
font-size: 10px;
}
.change-row span {
display: block;
margin-top: 3px;
color: #7a8581;
font-size: 9px;
line-height: 1.4;
}
.empty-state {
padding: 13px;
border: 1px dashed #cfd4cc;
border-radius: 9px;
color: #7b8782;
font-size: 10px;
line-height: 1.5;
text-align: center;
}
.panel-footer-note {
margin-top: 16px;
color: #8a938f;
font-size: 9px;
line-height: 1.5;
}
.toast {
position: fixed;
z-index: 50;
left: 50%;
bottom: 24px;
transform: translate(-50%, 18px);
padding: 11px 15px;
border-radius: 9px;
background: #172b28;
color: #f7f5eb;
box-shadow: 0 14px 34px rgba(17, 31, 29, 0.28);
font-size: 11px;
font-weight: 700;
opacity: 0;
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.webgl-error {
position: absolute;
z-index: 20;
inset: 20px;
display: grid;
place-items: center;
padding: 30px;
border-radius: 15px;
background: #fffdf7;
color: #5b6864;
text-align: center;
line-height: 1.6;
}
@media (max-width: 1120px) {
.app-shell {
grid-template-columns: 255px minmax(360px, 1fr) 325px;
}
.panel-inner {
padding: 19px 15px;
}
.header-center {
display: none;
}
}
@media (max-width: 900px) {
body {
height: auto;
overflow: auto;
}
.header {
position: sticky;
top: 0;
}
.local-chip {
display: none;
}
.app-shell {
height: auto;
display: flex;
flex-direction: column;
}
.side-panel {
overflow: visible;
}
.requests-panel {
order: 1;
border-right: 0;
border-bottom: 1px solid #d4d7cf;
}
.stage {
order: 2;
height: 68vh;
min-height: 520px;
}
.agreement-panel {
order: 3;
border-left: 0;
border-top: 1px solid #d4d7cf;
}
.request-list {
grid-template-columns: repeat(3, minmax(220px, 1fr));
}
.scenario-note {
display: none;
}
}
@media (max-width: 620px) {
.header {
height: 62px;
padding: 0 13px;
}
.brand-subtitle,
.version-pill {
display: none;
}
.app-shell {
min-height: calc(100vh - 62px);
}
.request-list {
grid-template-columns: 1fr;
}
.stage {
min-height: 560px;
}
.legend {
max-width: 150px;
}
.legend-item {
font-size: 8px;
}
.preview-dock {
align-items: stretch;
flex-direction: column;
}
.preview-actions {
display: grid;
grid-template-columns: 1fr 1fr;
}
}
</style>
</head>
<body>
<header class="header">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
</div>
<div>
<div class="brand-title">Common Ground</div>
<div class="brand-subtitle">Boundary negotiation sandbox</div>
</div>
</div>
<div class="header-center">
<span class="scenario-chip">Maple Quarter</span>
<span class="local-chip">Fictional local data</span>
</div>
<div class="header-actions">
<span class="version-pill" id="header-version">Agreement v3</span>
<button class="ghost-button" id="reset-view">Reset view</button>
</div>
</header>
<main class="app-shell">
<aside class="side-panel requests-panel">
<div class="panel-inner">
<div class="panel-title-row">
<div>
<div class="eyebrow">Access requests</div>
<h1 class="panel-title">Three competing claims</h1>
</div>
<span class="count-badge">3</span>
</div>
<p class="panel-description">
Review what each household needs, then compare the consequences before
revising the neighborhood agreement.
</p>
<div class="request-list" id="request-list"></div>
<div class="scenario-note">
<strong>Shared condition</strong>
Any permission can include personal plots. Opening one path may create
new access at nearby plots.
</div>
</div>
</aside>
<section class="stage" id="stage">
<canvas id="scene" aria-label="Interactive voxel neighborhood model"></canvas>
<div class="stage-top">
<div class="map-label">
<strong>MAPLE QUARTER</strong>
<span>18 × 12 neighborhood blocks</span>
</div>
<div class="legend" aria-label="Map legend">
<div class="legend-item">
<span class="legend-dot" style="background:#e88975"></span>
Personal
</div>
<div class="legend-item">
<span class="legend-dot" style="background:#42b69f"></span>
Shared
</div>
<div class="legend-item">
<span class="legend-dot" style="background:#dfc45c"></span>
Common
</div>
<div class="legend-item">
<span class="legend-dot" style="background:#aa5ee8"></span>
Proposed
</div>
</div>
</div>
<div class="view-tools">
<button class="tool-button" id="zoom-in" title="Zoom in" aria-label="Zoom in">+</button>
<button class="tool-button" id="zoom-out" title="Zoom out" aria-label="Zoom out">−</button>
<button class="tool-button" id="fit-view" title="Fit neighborhood" aria-label="Fit neighborhood">⌂</button>
</div>
<div class="tile-card" id="tile-card" hidden>
<button id="close-tile" aria-label="Close details">×</button>
<small>Selected plot</small>
<strong id="tile-title"></strong>
<span id="tile-description"></span>
</div>
<div class="tooltip" id="tooltip" hidden></div>
<div class="preview-dock">
<div class="preview-copy">
<div class="preview-kicker">
<span class="preview-dot" id="preview-dot"></span>
<span id="preview-kicker">Revision preview</span>
</div>
<div class="preview-title" id="preview-title">No pending changes</div>
<div class="preview-summary" id="preview-summary">
Edit an agreement clause to preview affected paths.
</div>
</div>
<div class="preview-actions">
<button class="secondary-button" id="discard-changes">Discard</button>
<button class="primary-button" id="apply-changes" disabled>Apply revision</button>
</div>
</div>
</section>
<aside class="side-panel agreement-panel">
<div class="panel-inner">
<div class="agreement-heading">
<div>
<div class="eyebrow">Explicit agreement</div>
<h2 class="panel-title">Boundary rules</h2>
</div>
<span class="draft-badge" id="draft-badge">Matches v3</span>
</div>
<p class="agreement-intro">
These clauses define who may use each route and when. Changes are
highlighted in the model until the revision is applied.
</p>
<div class="section-label">Open access</div>
<div class="clause">
<div class="clause-top">
<div class="clause-name">
<span class="clause-index">01</span>
<div>
<strong>Front footpaths</strong>
<small>Shared access to the Maple Court entrances</small>
</div>
</div>
<label class="switch">
<input id="frontPaths" type="checkbox" />
<span></span>
</label>
</div>
</div>
<div class="clause">
<div class="clause-top">
<div class="clause-name">
<span class="clause-index">02</span>
<div>
<strong>Garden cut-through</strong>
<small>Crosses two private garden plots</small>
</div>
</div>
<label class="switch">
<input id="gardenCrossing" type="checkbox" />
<span></span>
</label>
</div>
</div>
<div class="section-label">Time windows</div>
<div class="clause">
<div class="clause-top">
<div class="clause-name">
<span class="clause-index">03</span>
<div>
<strong>Community garden closes</strong>
<small>Current: <span id="current-community">19:00</span></small>
</div>
</div>
</div>
<div class="range-wrap">
<div class="range-labels">
<span>Closing time</span>
<span class="range-output" id="community-output">19:00</span>
</div>
<input id="communityEnd" type="range" min="7" max="24" step="1" />
</div>
</div>
<div class="clause">
<div class="clause-top">
<div class="clause-name">
<span class="clause-index">04</span>
<div>
<strong>Service gate closes</strong>
<small>Current: <span id="current-service">17:00</span></small>
</div>
</div>
</div>
<div class="range-wrap">
<div class="range-labels">
<span>Closing time</span>
<span class="range-output" id="service-output">17:00</span>
</div>
<input id="serviceEnd" type="range" min="9" max="24" step="1" />
</div>
</div>
<div class="clause">
<div class="clause-top">
<div class="clause-name">
<span class="clause-index">05</span>
<div>
<strong>Delivery bay closes</strong>
<small>Current: <span id="current-delivery">18:00</span></small>
</div>
</div>
</div>
<div class="range-wrap">
<div class="range-labels">
<span>Closing time</span>
<span class="range-output" id="delivery-output">18:00</span>
</div>
<input id="deliveryEnd" type="range" min="8" max="22" step="1" />
</div>
</div>
<div class="impact-note" id="impact-note"></div>
<div class="section-label">Proposed changes</div>
<div class="change-list" id="change-list"></div>
<p class="panel-footer-note">
Applying a revision replaces the current agreement for every resident.
“24:00” represents continuous access until midnight.
</p>
</div>
</aside>
</main>
<div class="toast" id="toast"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (id) => document.getElementById(id);
const COLORS = {
private: 0xe88975,
shared: 0x42b69f,
public: 0xdfc45c,
road: 0x5d6b70,
grant: 0xaa5ee8,
restrict: 0xed884d,
white: 0xf7f3e8
};
const zoneNames = {
private: "Personal space",
shared: "Shared garden",
public: "Common ground",
road: "Public street"
};
const routes = {
front: [
[8, 3], [7, 3], [6, 3], [5, 3], [4, 3], [3, 3]
],
garden: [
[8, 4], [7, 4], [6, 4], [5, 4], [4, 4], [3, 4], [2, 4]
],
community: [
[8, 9], [9, 9], [10, 9], [11, 9], [12, 9],
[13, 9], [14, 9], [15, 9], [15, 10]
],
service: [
[10, 0], [11, 0], [12, 0], [13, 0], [14, 0],
[15, 0], [16, 0], [16, 1], [16, 2], [16, 3], [16, 4]
],
delivery: [
[0, 6], [4, 6], [7, 6], [8, 6], [11, 6],
[14, 6], [16, 6], [16, 7]
]
};
const requestDefinitions = [
{
id: "bus",
icon: "↗",
title: "Earlier bus connection",
by: "No. 12 · Rivera household",
ask: "Use the garden cut-through from 06:30–08:00.",
conflict: "Crosses two private garden plots and creates a new through-route.",
rule: "gardenCrossing",
route: "garden",
required: true
},
{
id: "studio",
icon: "◷",
title: "Evening studio sessions",
by: "Maple Arts Collective",
ask: "Keep the community garden open until 21:00.",
conflict: "Extends shared use two hours beyond the current closing time.",
rule: "communityEnd",
route: "community",
required: 21
},
{
id: "care",
icon: "+",
title: "Overnight caregiver access",
by: "East block care network",
ask: "Allow service-gate access until midnight.",
conflict: "Provides continuous access beside private homes and parked cars.",
rule: "serviceEnd",
route: "service",
required: 24
}
];
let agreementVersion = 3;
let currentAgreement = {
frontPaths: true,
gardenCrossing: false,
communityEnd: 19,
serviceEnd: 17,
deliveryEnd: 18
};
let draftAgreement = { ...currentAgreement };
const clauseDefinitions = {
frontPaths: {
label: "Front footpaths",
route: "front",
format: (value) => value ? "Shared access" : "Personal only",
permission: (value) => value
? "All residents may use the front footpaths."
: "Front footpaths return to personal use."
},
gardenCrossing: {
label: "Garden cut-through",
route: "garden",
format: (value) => value ? "Open crossing" : "Private only",
permission: (value) => value
? "The cut-through becomes a shared route."
: "The private garden crossing is closed."
},
communityEnd: {
label: "Community garden hours",
route: "community",
format: (value) => `${formatHour(value)} close`,
permission: (value) => `Community garden access runs until ${formatHour(value)}.`
},
serviceEnd: {
label: "Service gate hours",
route: "service",
format: (value) => `${formatHour(value)} close`,
permission: (value) => `Service-gate access runs until ${formatHour(value)}.`
},
deliveryEnd: {
label: "Delivery bay hours",
route: "delivery",
format: (value) => `${formatHour(value)} close`,
permission: (value) => `Delivery-bay access runs until ${formatHour(value)}.`
}
};
function formatHour(hour) {
if (hour >= 24) return "24:00";
return `${String(hour).padStart(2, "0")}:00`;
}
function getDiff() {
const result = [];
for (const key of Object.keys(clauseDefinitions)) {
const before = currentAgreement[key];
const after = draftAgreement[key];
if (before === after) continue;
const definition = clauseDefinitions[key];
const isTimeRule = typeof before === "number";
const grantsAccess = isTimeRule ? after > before : after === true;
result.push({
key,
label: definition.label,
route: definition.route,
before: definition.format(before),
after: definition.format(after),
permission: definition.permission(after),
kind: grantsAccess ? "grant" : "restrict"
});
}
return result;
}
function requestSatisfied(request, agreement = draftAgreement) {
if (typeof request.required === "boolean") {
return agreement[request.rule] === request.required;
}
return agreement[request.rule] >= request.required;
}
function currentRequestSatisfied(request) {
return requestSatisfied(request, currentAgreement);
}
function renderRequests() {
const list = $("request-list");
list.innerHTML = "";
for (const request of requestDefinitions) {
const satisfied = requestSatisfied(request);
const alreadyCurrent = currentRequestSatisfied(request);
const card = document.createElement("article");
card.className = "request-card" + (satisfied ? " in-draft" : "");
const status = satisfied
? (alreadyCurrent ? "Granted" : "In draft")
: "Not included";
const statusClass = satisfied
? (alreadyCurrent ? "included" : "draft")
: "";
card.innerHTML = `
<div class="request-head">
<div class="request-icon">${request.icon}</div>
<span class="request-status ${statusClass}">${status}</span>
</div>
<h3>${request.title}</h3>
<div class="request-by">${request.by}</div>
<p class="request-ask">${request.ask}</p>
<div class="conflict-note">${request.conflict}</div>
<button class="request-action ${satisfied ? "included" : ""}">
${satisfied ? "View route in model" : "Include in draft"}
</button>
`;
card.querySelector("button").addEventListener("click", () => {
if (!requestSatisfied(request)) {
if (typeof request.required === "boolean") {
draftAgreement[request.rule] = request.required;
} else {
draftAgreement[request.rule] = Math.max(
draftAgreement[request.rule],
request.required
);
}
renderAll();
showToast(`${request.title} added to the draft.`);
}
focusRoute(request.route);
});
list.appendChild(card);
}
}
function renderControls() {
$("frontPaths").checked = draftAgreement.frontPaths;
$("gardenCrossing").checked = draftAgreement.gardenCrossing;
$("communityEnd").value = draftAgreement.communityEnd;
$("serviceEnd").value = draftAgreement.serviceEnd;
$("deliveryEnd").value = draftAgreement.deliveryEnd;
$("community-output").textContent = formatHour(draftAgreement.communityEnd);
$("service-output").textContent = formatHour(draftAgreement.serviceEnd);
$("delivery-output").textContent = formatHour(draftAgreement.deliveryEnd);
$("current-community").textContent = formatHour(currentAgreement.communityEnd);
$("current-service").textContent = formatHour(currentAgreement.serviceEnd);
$("current-delivery").textContent = formatHour(currentAgreement.deliveryEnd);
$("header-version").textContent = `Agreement v${agreementVersion}`;
const changed = getDiff().length > 0;
const badge = $("draft-badge");
badge.textContent = changed ? "Unapplied revision" : `Matches v${agreementVersion}`;
badge.classList.toggle("changed", changed);
const impact = $("impact-note");
if (draftAgreement.gardenCrossing) {
impact.className = "impact-note warning";
impact.innerHTML =
"<strong>Personal-space impact:</strong> The garden route now crosses two private plots. The preview marks the affected plots and route before application.";
} else if (draftAgreement.serviceEnd >= 24) {
impact.className = "impact-note warning";
impact.innerHTML =
"<strong>Continuous access:</strong> The service route will remain open until midnight, including hours beside occupied homes.";
} else if (draftAgreement.communityEnd >= 21) {
impact.className = "impact-note warning";
impact.innerHTML =
"<strong>Extended use:</strong> Evening shared access continues past 20:00. Noise and lighting conditions should be reviewed.";
} else {
impact.className = "impact-note";
impact.innerHTML =
"<strong>Conflict check:</strong> The current draft introduces no new overnight or private-plot access.";
}
}
function renderPreview() {
const diff = getDiff();
const list = $("change-list");
list.innerHTML = "";
const applyButton = $("apply-changes");
const discardButton = $("discard-changes");
if (!diff.length) {
$("preview-dot").classList.remove("active");
$("preview-kicker").textContent = "Revision preview";
$("preview-title").textContent = "No pending changes";
$("preview-summary").textContent =
"Edit an agreement clause to preview affected paths.";
applyButton.disabled = true;
discardButton.disabled = true;
list.innerHTML =
'<div class="empty-state">The draft currently matches the active agreement.</div>';
renderWorldPreview();
return;
}
const routeCount = new Set(diff.map((item) => item.route)).size;
const grantCount = diff.filter((item) => item.kind === "grant").length;
const restrictCount = diff.length - grantCount;
$("preview-dot").classList.add("active");
$("preview-kicker").textContent = "Unapplied revision";
$("preview-title").textContent =
`${diff.length} permission change${diff.length === 1 ? "" : "s"} on ${routeCount} route${routeCount === 1 ? "" : "s"}`;
$("preview-summary").textContent =
`${grantCount} newly opened · ${restrictCount} restricted · paths are highlighted in the model.`;
applyButton.disabled = false;
discardButton.disabled = false;
for (const item of diff) {
const row = document.createElement("div");
row.className = "change-row";
row.innerHTML = `
<div class="change-dot ${item.kind === "restrict" ? "restrict" : ""}"></div>
<div>
<strong>${item.label}: ${item.before} → ${item.after}</strong>
<span>${item.permission}</span>
</div>
`;
list.appendChild(row);
}
renderWorldPreview();
}
function renderAll() {
renderControls();
renderRequests();
renderPreview();
}
// ---------- Three.js scene ----------
const stage = $("stage");
const canvas = $("scene");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
const message = document.createElement("div");
message.className = "webgl-error";
message.textContent =
"This neighborhood model requires WebGL. Please open the file in a browser with hardware acceleration enabled.";
stage.appendChild(message);
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8e0db);
scene.fog = new THREE.Fog(0xd8e0db, 28, 55);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const cameraState = {
target: new THREE.Vector3(0, 0, 0),
targetGoal: new THREE.Vector3(0, 0, 0),
yaw: 0.72,
pitch: 0.83,
distance: 27,
distanceGoal: 27
};
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x64786f, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3d6, 3.1);
sun.position.set(-10, 18, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const world = new THREE.Group();
const currentPermissionLayer = new THREE.Group();
const previewLayer = new THREE.Group();
scene.add(world, currentPermissionLayer, previewLayer);
const tileMeshes = [];
const tileGeometry = new THREE.BoxGeometry(0.95, 0.18, 0.95);
const materialCache = new Map();
function getMaterial(color, roughness = 0.88) {
const key = `${color}-${roughness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({ color, roughness })
);
}
return materialCache.get(key);
}
function zoneAt(ix, iz) {
if (ix === 8 || ix === 9 || iz === 5 || iz === 6) return "road";
if (ix >= 11 && ix <= 15 && iz >= 8 && iz <= 10) {
return "shared";
}
const northwest = ix >= 1 && ix <= 6 && iz >= 1 && iz <= 4;
const northeast = ix >= 11 && ix <= 16 && iz >= 1 && iz <= 4;
const southwest = ix >= 1 && ix <= 6 && iz >= 8 && iz <= 10;
if (northwest || northeast || southwest) return "private";
return "public";
}
function worldX(ix) {
return ix - 8.5;
}
function worldZ(iz) {
return iz - 5.5;
}
function addBox(
width,
height,
depth,
x,
z,
color,
options = {}
) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const material = options.material || getMaterial(color);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(
x,
options.base !== undefined ? options.base + height / 2 : height / 2,
z
);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = true;
world.add(mesh);
return mesh;
}
function buildGround() {
const base = new THREE.Mesh(
new THREE.BoxGeometry(19.3, 0.34, 13.3),
getMaterial(0xaebdb1)
);
base.position.y = -0.24;
base.receiveShadow = true;
world.add(base);
const zoneColors = {
private: COLORS.private,
shared: COLORS.shared,
public: COLORS.public,
road: COLORS.road
};
for (let iz = 0; iz < 12; iz++) {
for (let ix = 0; ix < 18; ix++) {
const zone = zoneAt(ix, iz);
const mesh = new THREE.Mesh(tileGeometry, getMaterial(zoneColors[zone]));
mesh.position.set(worldX(ix), 0, worldZ(iz));
mesh.receiveShadow = true;
mesh.userData = { ix, iz, zone };
world.add(mesh);
tileMeshes.push(mesh);
}
}
}
function addFenceSegment(x, z, alongX, color) {
const railWidth = alongX ? 1 : 0.065;
const railDepth = alongX ? 0.065 : 1;
addBox(railWidth, 0.07, railDepth, x, z, color, {
base: 0.3,
castShadow: false
});
addBox(0.09, 0.42, 0.09, x - (alongX ? 0.44 : 0), z - (alongX ? 0 : 0.44), color, {
base: 0.1
});
}
function buildBoundaries() {
for (let iz = 0; iz < 12; iz++) {
for (let ix = 0; ix < 18; ix++) {
const zone = zoneAt(ix, iz);
if (zone !== "private" && zone !== "shared") continue;
const color = zone === "private" ? 0xf4d8b8 : 0xd2eee5;
if (ix < 17) {
const neighbor = zoneAt(ix + 1, iz);
if (neighbor !== zone) {
addFenceSegment(ix - 8, worldZ(iz), false, color);
}
}
if (iz < 11) {
const neighbor = zoneAt(ix, iz + 1);
if (neighbor !== zone) {
addFenceSegment(worldX(ix), iz - 5, true, color);
}
}
}
}
}
function addWindow(x, y, z, width = 0.34, height = 0.34) {
addBox(width, height, 0.035, x, z, 0xbfe6df, {
base: y,
castShadow: false
});
}
function addHouse(cx, cz, width, depth, height, bodyColor, roofColor) {
addBox(width, height, depth, cx, cz, bodyColor, { base: 0.1 });
addBox(width + 0.12, 0.22, depth + 0.12, cx, cz, roofColor, {
base: 0.1 + height
});
addBox(width * 0.24, height * 0.58, 0.05, cx, cz + depth / 2 + 0.025, 0x385052, {
base: 0.12
});
const windowY = 0.1 + height * 0.56;
const windowOffset = width * 0.28;
addWindow(cx - windowOffset, windowY, cz + depth / 2 + 0.045);
addWindow(cx + windowOffset, windowY, cz + depth / 2 + 0.045);
}
function addTree(x, z, scale = 1) {
addBox(0.18 * scale, 0.7 * scale, 0.18 * scale, x, z, 0x8a6a47, {
base: 0.1
});
addBox(0.72 * scale, 0.66 * scale, 0.72 * scale, x, z, 0x739c61, {
base: 0.58 * scale
});
addBox(0.52 * scale, 0.42 * scale, 0.52 * scale, x + 0.13 * scale, z, 0x86aa6d, {
base: 1.04 * scale
});
}
function addGardenBed(x, z, width = 0.65, depth = 0.48) {
addBox(width, 0.18, depth, x, z, 0xb67b53, { base: 0.1 });
addBox(width - 0.1, 0.11, depth - 0.08, x, z, 0x5f985e, {
base: 0.27
});
}
function addBench(x, z, rotation = 0) {
const bench = new THREE.Group();
const geometry = new THREE.BoxGeometry(0.72, 0.1, 0.22);
const material = getMaterial(0x8e6646);
const seat = new THREE.Mesh(geometry, material);
seat.position.y = 0.3;
seat.castShadow = true;
bench.add(seat);
const back = new THREE.Mesh(
new THREE.BoxGeometry(0.72, 0.25, 0.08),
material
);
back.position.set(0, 0.48, -0.1);
back.castShadow = true;
bench.add(back);
bench.position.set(x, 0, z);
bench.rotation.y = rotation;
world.add(bench);
}
function addStreetMarks() {
for (let ix = 1; ix < 17; ix += 2) {
if (ix === 8 || ix === 9) continue;
addBox(0.42, 0.025, 0.075, worldX(ix), worldZ(5), 0xe8d78f, {
base: 0.105,
castShadow: false
});
addBox(0.42, 0.025, 0.075, worldX(ix), worldZ(6), 0xe8d78f, {
base: 0.105,
castShadow: false
});
}
for (let iz = 1; iz < 11; iz += 2) {
if (iz === 5 || iz === 6) continue;
addBox(0.075, 0.025, 0.42, worldX(8), worldZ(iz), 0xe8d78f, {
base: 0.105,
castShadow: false
});
addBox(0.075, 0.025, 0.42, worldX(9), worldZ(iz), 0xe8d78f, {
base: 0.105,
castShadow: false
});
}
}
function addBusStop() {
addBox(0.12, 1.55, 0.12, worldX(8) + 0.38, worldZ(4), 0x3b5053, {
base: 0.1
});
addBox(0.12, 1.55, 0.12, worldX(8) + 0.38, worldZ(3), 0x3b5053, {
base: 0.1
});
addBox(0.12, 0.1, 1.2, worldX(8) + 0.38, worldZ(3.5), 0x3b5053, {
base: 1.5
});
addBox(0.42, 0.62, 0.08, worldX(8) + 0.38, worldZ(3), 0xe7c85e, {
base: 0.72
});
}
function makeLabel(text, color = "#17302d", background = "rgba(255,253,247,.92)") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.fillStyle = background;
context.beginPath();
context.roundRect(6, 6, 500, 116, 22);
context.fill();
context.strokeStyle = "rgba(31,55,51,.16)";
context.lineWidth = 4;
context.stroke();
context.fillStyle = color;
context.font = "700 42px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(4.1, 1.02, 1);
sprite.renderOrder = 20;
return sprite;
}
function addLabels() {
const maple = makeLabel("MAPLE COURT");
maple.position.set(worldX(3.5), 2.55, worldZ(2));
scene.add(maple);
const garden = makeLabel("COMMON GARDEN", "#17564c");
garden.position.set(worldX(13), 2.25, worldZ(8.8));
scene.add(garden);
const service = makeLabel("EAST SERVICE LANE");
service.position.set(worldX(14.7), 2.1, worldZ(0.6));
scene.add(service);
}
function buildBuildingsAndDetails() {
// Northwest homes.
addHouse(worldX(2), worldZ(1), 3.0, 1.8, 1.45, 0xe4b981, 0x9d5c4f);
addHouse(worldX(5), worldZ(1), 2.1, 1.8, 1.8, 0xc8d6c2, 0x5b7475);
// Northeast homes and garage.
addHouse(worldX(12), worldZ(1), 3.0, 1.8, 1.55, 0xead4a6, 0x8d5f52);
addHouse(worldX(14), worldZ(1), 2.0, 1.7, 1.65, 0xbad0c5, 0x5e7772);
addBox(0.85, 0.7, 1.0, worldX(16), worldZ(0), 0x94a39d, { base: 0.1 });
addBox(0.86, 0.08, 1.02, worldX(16), worldZ(0), 0x596d6d, { base: 0.78 });
// Southwest homes.
addHouse(worldX(2), worldZ(9), 3.0, 1.7, 1.45, 0xd8b5a1, 0x8a5c50);
addHouse(worldX(5), worldZ(9), 2.1, 1.7, 1.7, 0xc5d4c6, 0x667d78);
// Shared pavilion.
addBox(2.7, 1.1, 1.0, worldX(12), worldZ(8), 0xd9c69c, { base: 0.1 });
addBox(3.0, 0.18, 1.25, worldX(12), worldZ(8), 0x4e7770, { base: 1.2 });
// Community garden beds.
addGardenBed(worldX(13), worldZ(8));
addGardenBed(worldX(14), worldZ(8));
addGardenBed(worldX(13), worldZ(10));
addGardenBed(worldX(14), worldZ(10));
// Personal garden planting.
addGardenBed(worldX(4), worldZ(4), 0.5, 0.45);
addGardenBed(worldX(4.7), worldZ(4), 0.5, 0.45);
addGardenBed(worldX(5.4), worldZ(4), 0.5, 0.45);
// Trees.
addTree(worldX(1), worldZ(4), 0.85);
addTree(worldX(6), worldZ(4), 0.82);
addTree(worldX(11), worldZ(3), 0.86);
addTree(worldX(1), worldZ(8), 0.85);
addTree(worldX(6), worldZ(10), 0.9);
addTree(worldX(15), worldZ(10), 0.8);
// Benches and bus stop.
addBench(worldX(10.4), worldZ(9.2), Math.PI / 2);
addBench(worldX(12.5), worldZ(10.3), 0);
addBusStop();
// Small parked car.
addBox(0.52, 0.35, 1.0, worldX(9.45), worldZ(1.3), 0xe5b85d, { base: 0.1 });
addBox(0.44, 0.3, 0.52, worldX(9.45), worldZ(1.25), 0x587477, { base: 0.45 });
// Street lights.
for (const [ix, iz] of [[7, 2], [10, 7], [7, 9], [10, 3]]) {
addBox(0.09, 1.55, 0.09, worldX(ix), worldZ(iz), 0x3e5354, { base: 0.1 });
addBox(0.28, 0.09, 0.28, worldX(ix), worldZ(iz), 0xf0dfaa, { base: 1.55 });
}
}
buildGround();
buildBoundaries();
buildBuildingsAndDetails();
addStreetMarks();
addLabels();
function routeToPoints(routeName, y = 0.27) {
return routes[routeName].map(
([ix, iz]) => new THREE.Vector3(worldX(ix), y, worldZ(iz))
);
}
function clearGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach((material) => material.dispose());
} else {
object.material.dispose();
}
}
});
}
}
function addRouteLine(group, routeName, color, opacity, y, dashed = true) {
const geometry = new THREE.BufferGeometry().setFromPoints(
routeToPoints(routeName, y)
);
const material = dashed
? new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize: 0.36,
gapSize: 0.2,
depthTest: true
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
const line = new THREE.Line(geometry, material);
if (dashed) line.computeLineDistances();
group.add(line);
return line;
}
function renderCurrentPermissions() {
clearGroup(currentPermissionLayer);
const enabledRoutes = [
["front", currentAgreement.frontPaths],
["garden", currentAgreement.gardenCrossing],
["community", true],
["service", true],
["delivery", true]
];
for (const [route, enabled] of enabledRoutes) {
if (!enabled) continue;
addRouteLine(currentPermissionLayer, route, 0xe9fff7, 0.48, 0.225, true);
}
}
const animatedMarkers = [];
function renderWorldPreview() {
clearGroup(previewLayer);
animatedMarkers.length = 0;
const diff = getDiff();
if (!diff.length) return;
const overlayGeometry = new THREE.BoxGeometry(0.91, 0.035, 0.91);
const markerGeometry = new THREE.BoxGeometry(0.15, 0.15, 0.15);
for (const item of diff) {
const color = item.kind === "grant" ? COLORS.grant : COLORS.restrict;
addRouteLine(previewLayer, item.route, color, 0.95, 0.43, false);
const seen = new Set();
for (const [ix, iz] of routes[item.route]) {
const key = `${ix},${iz}`;
if (seen.has(key)) continue;
seen.add(key);
const overlay = new THREE.Mesh(
overlayGeometry,
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.29,
depthWrite: false
})
);
overlay.position.set(worldX(ix), 0.115, worldZ(iz));
previewLayer.add(overlay);
}
for (let markerIndex = 0; markerIndex < 4; markerIndex++) {
const marker = new THREE.Mesh(
markerGeometry,
new THREE.MeshBasicMaterial({ color })
);
marker.userData = {
route: item.route,
phase: markerIndex / 4,
speed: 0.065 + markerIndex * 0.006
};
previewLayer.add(marker);
animatedMarkers.push(marker);
}
}
}
function sampleRoute(routeName, t) {
const points = routes[routeName];
const scaled = THREE.MathUtils.clamp(t, 0, 0.999999) * (points.length - 1);
const index = Math.floor(scaled);
const fraction = scaled - index;
const a = points[index];
const b = points[Math.min(index + 1, points.length - 1)];
return new THREE.Vector3(
THREE.MathUtils.lerp(worldX(a[0]), worldX(b[0]), fraction),
0.48,
THREE.MathUtils.lerp(worldZ(a[1]), worldZ(b[1]), fraction)
);
}
function focusRoute(routeName) {
const route = routes[routeName];
const averageX = route.reduce((sum, point) => sum + point[0], 0) / route.length;
const averageZ = route.reduce((sum, point) => sum + point[1], 0) / route.length;
cameraState.targetGoal.set(
worldX(averageX),
0,
worldZ(averageZ)
);
cameraState.distanceGoal = 15.5;
}
function resetView() {
cameraState.targetGoal.set(0, 0, 0);
cameraState.distanceGoal = 27;
cameraState.yaw = 0.72;
cameraState.pitch = 0.83;
}
function updateCamera() {
const horizontal = Math.cos(cameraState.pitch) * cameraState.distance;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.distance,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
}
// ---------- Camera and pointer interaction ----------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
function getIntersectedTile(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(tileMeshes, false);
return hits.length ? hits[0].object : null;
}
function describeTile(tile) {
const { ix, iz, zone } = tile.userData;
const matchingRoutes = Object.entries(routes).filter(([, points]) =>
points.some(([x, z]) => x === ix && z === iz)
);
let permission = {
private: "Personal plot · no through access.",
shared: "Shared space · available during agreement hours.",
public: "Common ground · public access.",
road: "Public street · access permitted."
}[zone];
if (matchingRoutes.some(([name]) => name === "garden")) {
permission = currentAgreement.gardenCrossing
? "Garden cut-through is approved in the current agreement."
: "Garden cut-through remains personal space.";
} else if (matchingRoutes.some(([name]) => name === "front")) {
permission = currentAgreement.frontPaths
? "Front footpaths are shared with residents."
: "Front footpaths are not part of the shared route.";
}
return {
title: `${zoneNames[zone]} · block ${ix + 1}.${iz + 1}`,
description: permission
};
}
canvas.addEventListener("pointerdown", (event) => {
pointerDown = {
x: event.clientX,
y: event.clientY,
moved: false,
pointerId: event.pointerId
};
canvas.setPointerCapture(event.pointerId);
$("tooltip").hidden = true;
});
canvas.addEventListener("pointermove", (event) => {
if (pointerDown) {
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.abs(dx) + Math.abs(dy) > 4) pointerDown.moved = true;
if (pointerDown.moved) {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.38,
1.36
);
}
return;
}
const tile = getIntersectedTile(event);
const tooltip = $("tooltip");
if (!tile) {
tooltip.hidden = true;
return;
}
const details = describeTile(tile);
const rect = stage.getBoundingClientRect();
tooltip.innerHTML = `<strong>${details.title}</strong>${details.description}`;
tooltip.style.left = `${event.clientX - rect.left}px`;
tooltip.style.top = `${event.clientY - rect.top}px`;
tooltip.hidden = false;
});
canvas.addEventListener("pointerup", (event) => {
if (pointerDown && !pointerDown.moved) {
const tile = getIntersectedTile(event);
if (tile) {
const details = describeTile(tile);
$("tile-title").textContent = details.title;
$("tile-description").textContent = details.description;
$("tile-card").hidden = false;
}
}
pointerDown = null;
});
canvas.addEventListener("pointercancel", () => {
pointerDown = null;
});
canvas.addEventListener("pointerleave", () => {
$("tooltip").hidden = true;
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.distanceGoal = THREE.MathUtils.clamp(
cameraState.distanceGoal + event.deltaY * 0.015,
10,
42
);
}, { passive: false });
$("close-tile").addEventListener("click", () => {
$("tile-card").hidden = true;
});
$("zoom-in").addEventListener("click", () => {
cameraState.distanceGoal = THREE.MathUtils.clamp(
cameraState.distanceGoal - 3,
10,
42
);
});
$("zoom-out").addEventListener("click", () => {
cameraState.distanceGoal = THREE.MathUtils.clamp(
cameraState.distanceGoal + 3,
10,
42
);
});
$("fit-view").addEventListener("click", resetView);
$("reset-view").addEventListener("click", resetView);
// ---------- Agreement controls ----------
$("frontPaths").addEventListener("change", (event) => {
draftAgreement.frontPaths = event.target.checked;
renderAll();
});
$("gardenCrossing").addEventListener("change", (event) => {
draftAgreement.gardenCrossing = event.target.checked;
renderAll();
});
for (const key of ["communityEnd", "serviceEnd", "deliveryEnd"]) {
$(key).addEventListener("input", (event) => {
draftAgreement[key] = Number(event.target.value);
renderAll();
});
}
$("discard-changes").addEventListener("click", () => {
draftAgreement = { ...currentAgreement };
renderAll();
showToast("Draft changes discarded.");
});
$("apply-changes").addEventListener("click", () => {
const diff = getDiff();
if (!diff.length) return;
currentAgreement = { ...draftAgreement };
agreementVersion += 1;
renderCurrentPermissions();
renderAll();
showToast(`Revision applied as agreement v${agreementVersion}.`);
});
let toastTimer;
function showToast(message) {
const toast = $("toast");
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.classList.remove("visible");
}, 2600);
}
// ---------- Resize and animation ----------
function resizeRenderer() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(stage);
resizeRenderer();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
cameraState.target.lerp(cameraState.targetGoal, 0.085);
cameraState.distance = THREE.MathUtils.lerp(
cameraState.distance,
cameraState.distanceGoal,
0.085
);
updateCamera();
for (const marker of animatedMarkers) {
const data = marker.userData;
const progress = (elapsed * data.speed + data.phase) % 1;
marker.position.copy(sampleRoute(data.route, progress));
marker.rotation.y = elapsed * 1.4;
}
renderer.render(scene, camera);
}
renderCurrentPermissions();
renderAll();
updateCamera();
animate();
</script>
</body>
</html>
```