Prompt specification
Build or customize the Three.js 3D scene "Emergency Shelter Supply Choices" 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: Emergency Shelter Supply Choices
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/emergency-shelter-supply-choices-x3160
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring allocation of scarce resources among competing uses. Create a fictional shelter with limited blankets, water containers, and transport slots. Compare two explicit allocation rules, showing unmet needs without assigning moral scores to people. Low-poly.
Working Three.js Starter (emergency-shelter-supply-choices-x3160):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fictional Riverside Shelter — Resource Allocation</title>
<style>
:root {
color-scheme: dark;
--bg: #07131a;
--panel: rgba(9, 24, 32, 0.88);
--panel-strong: rgba(12, 31, 40, 0.96);
--line: rgba(177, 220, 224, 0.16);
--text: #edf7f4;
--muted: #9fb5b6;
--teal: #74d7cb;
--blanket: #e8bb73;
--water: #59c8e8;
--transport: #f29a62;
--shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
ellipse at 50% 44%,
transparent 38%,
rgba(2, 8, 12, 0.3) 100%
),
linear-gradient(
to bottom,
rgba(3, 10, 15, 0.28),
transparent 24%,
transparent 72%,
rgba(3, 10, 15, 0.45)
);
}
.header {
position: fixed;
top: 22px;
left: 26px;
right: 26px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 22px;
pointer-events: none;
z-index: 5;
}
.brand {
max-width: 650px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 2.6vw, 38px);
line-height: 1.02;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
max-width: 610px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.inventory {
display: flex;
align-items: center;
gap: 9px;
flex-wrap: wrap;
justify-content: flex-end;
max-width: 480px;
}
.stock,
.inventory-note {
border: 1px solid var(--line);
background: rgba(8, 23, 30, 0.75);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.stock {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 11px;
border-radius: 12px;
color: #d7e6e4;
font-size: 12px;
font-weight: 650;
white-space: nowrap;
}
.stock i,
.resource-dot {
width: 9px;
height: 9px;
display: inline-block;
border-radius: 3px;
flex: 0 0 auto;
}
.stock i.blanket,
.resource-dot.blanket {
background: var(--blanket);
}
.stock i.water,
.resource-dot.water {
background: var(--water);
}
.stock i.transport,
.resource-dot.transport {
background: var(--transport);
}
.inventory-note {
padding: 9px 12px;
border-radius: 12px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.inspector {
position: fixed;
top: 116px;
right: 26px;
width: 294px;
padding: 17px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
z-index: 6;
}
.inspector-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
}
.group-name {
display: flex;
align-items: center;
gap: 9px;
font-size: 18px;
font-weight: 800;
}
.group-id {
display: grid;
place-items: center;
width: 29px;
height: 29px;
border-radius: 9px;
color: #082025;
background: var(--teal);
font-size: 14px;
}
.residents {
color: var(--muted);
font-size: 11px;
white-space: nowrap;
}
.request-line {
display: flex;
gap: 6px;
flex-wrap: wrap;
margin-bottom: 13px;
}
.request-chip {
display: flex;
align-items: center;
gap: 5px;
padding: 5px 7px;
border: 1px solid var(--line);
border-radius: 8px;
color: #c9d9d8;
background: rgba(255, 255, 255, 0.025);
font-size: 10px;
}
.inspector-rule {
padding: 11px 0;
border-top: 1px solid var(--line);
}
.inspector-rule:first-of-type {
border-top: 0;
}
.inspector-rule-title {
display: flex;
justify-content: space-between;
align-items: center;
gap: 8px;
margin-bottom: 7px;
font-size: 11px;
font-weight: 750;
}
.inspector-rule-title span:last-child {
color: var(--muted);
font-weight: 500;
}
.allocation-line {
color: #dbe9e7;
font-size: 11px;
line-height: 1.65;
}
.allocation-line strong {
color: white;
}
.unmet-line {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.inspector-footnote {
margin-top: 8px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #8ea6a7;
font-size: 10px;
line-height: 1.45;
}
.view-controls {
position: fixed;
left: 26px;
top: 145px;
display: flex;
align-items: center;
gap: 8px;
z-index: 7;
}
.view-controls button {
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 10px;
color: #b9cece;
background: rgba(8, 23, 30, 0.78);
backdrop-filter: blur(10px);
cursor: pointer;
font-size: 11px;
font-weight: 650;
transition:
color 150ms ease,
border-color 150ms ease,
background 150ms ease;
}
.view-controls button:hover,
.view-controls button.active {
color: #071a20;
border-color: var(--teal);
background: var(--teal);
}
.camera-hint {
position: fixed;
left: 26px;
bottom: 255px;
color: rgba(207, 226, 224, 0.6);
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
z-index: 4;
}
.ledger {
position: fixed;
left: 26px;
right: 26px;
bottom: 20px;
min-height: 216px;
display: grid;
grid-template-columns: 285px 300px minmax(360px, 1fr);
gap: 14px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--panel-strong);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
z-index: 8;
}
.rule-card,
.comparison-card {
min-width: 0;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.025);
overflow: hidden;
}
.rule-card {
padding: 15px;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.rule-number {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 8px;
color: var(--teal);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.rule-number::before {
content: "";
width: 18px;
height: 2px;
border-radius: 2px;
background: var(--teal);
}
.rule-card h2,
.comparison-card h2 {
margin: 0;
font-size: 15px;
letter-spacing: -0.01em;
}
.rule-card p {
margin: 9px 0 14px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.rule-stat {
padding-top: 11px;
border-top: 1px solid var(--line);
color: #d9e8e6;
font-size: 10px;
line-height: 1.45;
}
.rule-stat strong {
display: block;
margin-bottom: 2px;
color: white;
font-size: 13px;
}
.comparison-card {
display: flex;
flex-direction: column;
}
.comparison-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
padding: 13px 15px 10px;
border-bottom: 1px solid var(--line);
}
.comparison-head p {
margin: 4px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.same-total {
flex: 0 0 auto;
padding: 5px 8px;
border: 1px solid rgba(116, 215, 203, 0.22);
border-radius: 8px;
color: var(--teal);
background: rgba(116, 215, 203, 0.06);
font-size: 9px;
font-weight: 750;
white-space: nowrap;
}
.table-wrap {
min-height: 0;
overflow: auto;
scrollbar-width: thin;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
th {
padding: 9px 10px;
color: #8ea6a7;
font-weight: 700;
text-align: left;
white-space: nowrap;
}
td {
padding: 8px 10px;
border-top: 1px solid rgba(177, 220, 224, 0.08);
color: #d8e6e4;
white-space: nowrap;
}
tbody tr {
cursor: pointer;
transition: background 120ms ease;
}
tbody tr:hover,
tbody tr.selected {
background: rgba(116, 215, 203, 0.07);
}
.table-group {
display: flex;
align-items: center;
gap: 7px;
font-weight: 800;
}
.table-id {
display: grid;
place-items: center;
width: 22px;
height: 22px;
border-radius: 7px;
color: #092026;
background: var(--teal);
}
.triplet {
display: inline-flex;
align-items: center;
gap: 7px;
}
.triplet span {
display: inline-flex;
align-items: center;
gap: 3px;
}
.resource-dot {
width: 6px;
height: 6px;
border-radius: 2px;
}
.world-layer {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
z-index: 3;
}
.world-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -100%);
white-space: nowrap;
will-change: transform;
}
.rule-world-label {
padding: 7px 11px;
border: 1px solid rgba(116, 215, 203, 0.25);
border-radius: 10px;
color: #dcebea;
background: rgba(7, 22, 29, 0.84);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(8px);
text-align: center;
}
.rule-world-label small {
display: block;
margin-bottom: 2px;
color: var(--teal);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.rule-world-label strong {
font-size: 11px;
}
.group-world-label {
min-width: 92px;
padding: 6px 8px;
border: 1px solid rgba(184, 214, 215, 0.18);
border-radius: 10px;
color: #d9e6e5;
background: rgba(7, 20, 27, 0.82);
box-shadow: 0 7px 22px rgba(0, 0, 0, 0.23);
backdrop-filter: blur(8px);
pointer-events: auto;
cursor: pointer;
transition:
border-color 140ms ease,
background 140ms ease;
}
.group-world-label:hover,
.group-world-label.selected {
border-color: rgba(116, 215, 203, 0.8);
background: rgba(11, 38, 45, 0.94);
}
.group-label-main {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 4px;
}
.group-label-main strong {
color: var(--teal);
font-size: 11px;
}
.group-label-main span {
color: #a6b9b8;
font-size: 8px;
}
.group-unmet {
display: flex;
align-items: center;
justify-content: space-between;
gap: 5px;
color: #c5d4d3;
font-size: 8px;
}
.group-unmet span {
display: inline-flex;
align-items: center;
gap: 3px;
}
.group-unmet .resource-dot {
width: 5px;
height: 5px;
}
@media (max-width: 1080px) {
.header {
right: 20px;
left: 20px;
}
.inventory-note {
display: none;
}
.inspector {
right: 20px;
width: 270px;
}
.view-controls {
left: 20px;
}
.ledger {
left: 20px;
right: 20px;
grid-template-columns: 240px 260px minmax(340px, 1fr);
}
}
@media (max-width: 820px) {
.header {
display: block;
}
.inventory {
justify-content: flex-start;
margin-top: 13px;
}
.inspector {
top: auto;
bottom: 242px;
right: 14px;
width: 250px;
padding: 12px;
}
.view-controls {
top: auto;
bottom: 252px;
left: 14px;
flex-direction: column;
align-items: flex-start;
}
.camera-hint {
display: none;
}
.ledger {
left: 12px;
right: 12px;
bottom: 12px;
height: 218px;
min-height: 0;
grid-template-columns: 210px 230px minmax(330px, 1fr);
overflow-x: auto;
}
}
@media (max-width: 560px) {
.inventory {
display: none;
}
.inspector {
display: none;
}
.view-controls {
bottom: 244px;
}
.ledger {
grid-template-columns: 200px 220px minmax(330px, 1fr);
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<div id="world-layer" class="world-layer"></div>
<header class="header">
<div class="brand">
<div class="eyebrow">Fictional scenario · transparent allocation model</div>
<h1>Riverside Shelter</h1>
<p class="subtitle">
Compare two procedural rules for scarce blankets, water containers, and
transport slots. Counts describe requests and allocations only—no
person or group receives a moral score.
</p>
</div>
<div class="inventory" aria-label="Available shelter resources">
<div class="stock"><i class="blanket"></i>4 blankets</div>
<div class="stock"><i class="water"></i>3 water containers</div>
<div class="stock"><i class="transport"></i>4 transport slots</div>
<div class="inventory-note">Identical stock<br />in both rule panels</div>
</div>
</header>
<nav class="view-controls" aria-label="Camera views">
<button data-view="overview" class="active">Overview</button>
<button data-view="equal">Rule 1</button>
<button data-view="proportional">Rule 2</button>
</nav>
<aside id="inspector" class="inspector" aria-live="polite"></aside>
<div class="camera-hint">Drag to orbit · wheel to zoom · select a group to inspect</div>
<section class="ledger" aria-label="Allocation rules and unmet requests">
<article class="rule-card">
<div>
<div class="rule-number">Rule 1</div>
<h2>Equal-household rounds</h2>
<p>
Give one unit to each group with an open request in A→D order, then
begin another round when stock remains.
</p>
</div>
<div class="rule-stat">
<strong>15 requests remain unmet</strong>
The same 11 available units are distributed, but the distribution
differs by group.
</div>
</article>
<article class="rule-card">
<div>
<div class="rule-number">Rule 2</div>
<h2>Resident-proportional split</h2>
<p>
Split each resource proportionally to resident count among groups
with an open request. Use largest-remainder rounding; requests cap
allocations.
</p>
</div>
<div class="rule-stat">
<strong>15 requests remain unmet</strong>
Total unmet units are unchanged here; only which group carries them
changes.
</div>
</article>
<article class="comparison-card">
<div class="comparison-head">
<div>
<h2>Unmet requests by group</h2>
<p>Order within each triplet: blanket · water · transport</p>
</div>
<div class="same-total">Same stock · same total unmet</div>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Group</th>
<th>Residents</th>
<th>Requested</th>
<th>Rule 1 unmet</th>
<th>Rule 2 unmet</th>
</tr>
</thead>
<tbody id="comparison-body"></tbody>
</table>
</div>
</article>
</section>
<noscript>This scene requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scenario data
// -------------------------------------------------------------------------
const groups = [
{
id: "A",
residents: 8,
requests: { blankets: 5, water: 3, transport: 2 }
},
{
id: "B",
residents: 4,
requests: { blankets: 4, water: 2, transport: 1 }
},
{
id: "C",
residents: 2,
requests: { blankets: 2, water: 1, transport: 2 }
},
{
id: "D",
residents: 1,
requests: { blankets: 1, water: 2, transport: 1 }
}
];
const supply = {
blankets: 4,
water: 3,
transport: 4
};
const resources = {
blankets: {
label: "blankets",
plural: "blankets",
color: 0xe8bb73,
css: "#e8bb73"
},
water: {
label: "water containers",
plural: "water containers",
color: 0x59c8e8,
css: "#59c8e8"
},
transport: {
label: "transport slots",
plural: "transport slots",
color: 0xf29a62,
css: "#f29a62"
}
};
const resourceOrder = ["blankets", "water", "transport"];
// Rule 1: one unit per requesting group per round.
// A -> D is the explicit stable tie order.
function allocateEqualHousehold(resource) {
const allocation = groups.map(() => 0);
let remaining = supply[resource];
while (remaining > 0) {
let allocatedThisRound = false;
for (let i = 0; i < groups.length && remaining > 0; i++) {
if (allocation[i] < groups[i].requests[resource]) {
allocation[i] += 1;
remaining -= 1;
allocatedThisRound = true;
}
}
if (!allocatedThisRound) break;
}
return allocation;
}
// Rule 2: proportional to residents, largest-remainder rounding.
// Each group's request is a cap.
function allocateResidentProportional(resource) {
const eligible = groups
.map((group, index) => ({ ...group, index }))
.filter(group => group.requests[resource] > 0);
const totalResidents = eligible.reduce(
(sum, group) => sum + group.residents,
0
);
const allocation = groups.map(() => 0);
const remainders = [];
for (const group of eligible) {
const ideal =
(supply[resource] * group.residents) / totalResidents;
allocation[group.index] = Math.floor(ideal);
remainders.push({
index: group.index,
fraction: ideal - Math.floor(ideal),
residents: group.residents
});
}
let remaining =
supply[resource] - allocation.reduce((sum, count) => sum + count, 0);
remainders.sort(
(a, b) =>
b.fraction - a.fraction ||
b.residents - a.residents ||
a.index - b.index
);
for (const candidate of remainders) {
if (remaining <= 0) break;
const cap = groups[candidate.index].requests[resource];
if (allocation[candidate.index] < cap) {
allocation[candidate.index] += 1;
remaining -= 1;
}
}
return allocation;
}
const allocations = {
equal: Object.fromEntries(
resourceOrder.map(resource => [
resource,
allocateEqualHousehold(resource)
])
),
proportional: Object.fromEntries(
resourceOrder.map(resource => [
resource,
allocateResidentProportional(resource)
])
)
};
function unmet(rule, groupIndex, resource) {
return (
groups[groupIndex].requests[resource] -
allocations[rule][resource][groupIndex]
);
}
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const sceneContainer = document.querySelector("#scene");
const worldLayer = document.querySelector("#world-layer");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131a);
scene.fog = new THREE.Fog(0x07131a, 24, 48);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D shelter allocation comparison. Drag to orbit and use the view buttons to focus a rule."
);
sceneContainer.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xc8f2ff, 0x263b38, 1.8);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffedcf, 3.1);
sun.position.set(-7, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x74d7cb, 1.25);
rim.position.set(10, 8, -12);
scene.add(rim);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function standardMaterial(color) {
const key = String(color);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.02,
flatShading: true
})
);
}
return materialCache.get(key);
}
function addBox(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
options.material || standardMaterial(color)
);
mesh.position.set(...position);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotation) {
mesh.rotation.set(...options.rotation);
}
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
color,
radialSegments = 8,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
radialSegments
),
options.material || standardMaterial(color)
);
mesh.position.set(...position);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCone(parent, radius, height, position, color, segments = 4) {
const mesh = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, segments),
standardMaterial(color)
);
mesh.position.set(...position);
mesh.rotation.y = Math.PI / 4;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Environment
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
standardMaterial(0x0b2025)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.39;
ground.receiveShadow = true;
scene.add(ground);
function addLowPolyTree(x, z, height, color) {
const tree = new THREE.Group();
tree.position.set(x, -0.36, z);
addCylinder(
tree,
0.09,
0.13,
height * 0.38,
[0, height * 0.19, 0],
0x4f3b32,
6
);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(height * 0.29, height * 0.7, 6),
standardMaterial(color)
);
crown.position.y = height * 0.58;
crown.castShadow = true;
tree.add(crown);
scene.add(tree);
}
[
[-13, -5, 3.4, 0x214c46],
[-11.5, -9, 2.5, 0x2d5c50],
[13, -6, 3.7, 0x214c46],
[11, -10, 2.8, 0x315e51],
[-15, 5, 2.2, 0x294f48],
[15, 4, 2.6, 0x294f48]
].forEach(args => addLowPolyTree(...args));
for (let i = 0; i < 7; i++) {
const mountain = new THREE.Mesh(
new THREE.ConeGeometry(
3.5 + (i % 3) * 0.8,
5 + (i % 2) * 2,
5
),
standardMaterial(i % 2 ? 0x102b32 : 0x0d252c)
);
mountain.position.set(-16 + i * 5.3, 1.2, -23 - (i % 2) * 2);
mountain.rotation.y = i * 0.8;
scene.add(mountain);
}
// -------------------------------------------------------------------------
// Diorama construction
// -------------------------------------------------------------------------
const groupPositions = [
{ x: -2.65, z: 0.35 },
{ x: -0.9, z: 1.35 },
{ x: 0.9, z: 0.35 },
{ x: 2.65, z: 1.35 }
];
const groupColors = [0x4f9c91, 0x5f8fa7, 0x8a7d9d, 0x7e9b68];
const interactiveMeshes = [];
const groupVisuals = [];
const worldLabels = [];
function addBlanketToken(parent, x, z, stackIndex) {
const group = new THREE.Group();
group.position.set(x, 0.1 + stackIndex * 0.105, z);
group.rotation.y = (stackIndex % 2) * 0.12;
addBox(group, [0.4, 0.105, 0.54], [0, 0, 0], 0xe8bb73);
addBox(
group,
[0.055, 0.12, 0.56],
[0, 0, 0],
0xa67a44
);
parent.add(group);
return group;
}
function addWaterToken(parent, x, z) {
const group = new THREE.Group();
group.position.set(x, 0.08, z);
addCylinder(
group,
0.15,
0.17,
0.38,
[0, 0.19, 0],
0x59c8e8,
8
);
addCylinder(
group,
0.105,
0.105,
0.055,
[0, 0.405, 0],
0x237e99,
8
);
addBox(
group,
[0.23, 0.045, 0.05],
[0, 0.32, 0],
0xc7f2ff
);
parent.add(group);
return group;
}
function addTransportToken(parent, x, z) {
const group = new THREE.Group();
group.position.set(x, 0.08, z);
// A compact seat symbol: base and upright back.
addBox(group, [0.24, 0.075, 0.23], [0, 0.04, 0], 0xf29a62);
addBox(
group,
[0.24, 0.25, 0.055],
[0, 0.16, -0.085],
0xf29a62
);
parent.add(group);
return group;
}
function addPerson(parent, x, z, color, phase) {
const person = new THREE.Group();
person.position.set(x, 0, z);
person.rotation.y = phase;
addCylinder(
person,
0.055,
0.07,
0.22,
[0, 0.14, 0],
color,
6
);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 6, 4),
standardMaterial(0xd5aa83)
);
head.position.y = 0.29;
head.castShadow = true;
person.add(head);
parent.add(person);
}
function addShelterBuilding(root) {
const building = new THREE.Group();
building.position.set(0, 0, -1.82);
addBox(
building,
[2.55, 1.38, 1.32],
[0, 0.7, 0],
0xc5b99d
);
addCone(
building,
1.86,
0.7,
[0, 1.73, 0],
0x397c78
);
addBox(
building,
[0.54, 0.86, 0.055],
[0.36, 0.43, 0.687],
0x263f43
);
addBox(
building,
[0.48, 0.35, 0.055],
[-0.68, 0.88, 0.687],
0x69a8ad
);
addBox(
building,
[0.48, 0.35, 0.055],
[0.68, 0.88, 0.687],
0x69a8ad
);
addBox(
building,
[2.72, 0.12, 0.14],
[0, 1.42, 0.7],
0x8e805f
);
root.add(building);
}
function addSupplyDepot(root) {
const depot = new THREE.Group();
depot.position.set(3.05, 0, -1.65);
addBox(depot, [1.35, 0.12, 1.15], [0, 0.06, 0], 0x735b3d);
addCylinder(depot, 0.04, 0.04, 1.8, [-0.55, 0.9, -0.45], 0x735b3d, 6);
addCylinder(depot, 0.04, 0.04, 1.8, [0.55, 0.9, -0.45], 0x735b3d, 6);
const awning = addBox(
depot,
[1.5, 0.1, 1.15],
[0, 1.82, -0.03],
0xd08b55
);
awning.rotation.x = -0.08;
// Compact physical indication of the stock.
for (let i = 0; i < 4; i++) {
addBox(
depot,
[0.22, 0.1, 0.32],
[-0.43 + i * 0.27, 0.22, 0.15],
0xe8bb73
);
}
for (let i = 0; i < 3; i++) {
addCylinder(
depot,
0.1,
0.12,
0.29,
[-0.4 + i * 0.4, 0.28, -0.3],
0x59c8e8,
8
);
}
for (let i = 0; i < 4; i++) {
addBox(
depot,
[0.15, 0.08, 0.16],
[-0.42 + i * 0.28, 0.18, 0.42],
0xf29a62
);
}
root.add(depot);
}
function createGroup(root, groupIndex, rule) {
const group = new THREE.Group();
const position = groupPositions[groupIndex];
group.position.set(position.x, 0, position.z);
const padMaterial = new THREE.MeshStandardMaterial({
color: 0x19363b,
roughness: 0.95,
flatShading: true,
emissive: 0x000000
});
const pad = new THREE.Mesh(
new THREE.CylinderGeometry(0.92, 0.98, 0.08, 12),
padMaterial
);
pad.position.y = 0.04;
pad.receiveShadow = true;
group.add(pad);
const ringMaterial = new THREE.MeshStandardMaterial({
color: 0x35565b,
roughness: 0.8,
emissive: 0x000000
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.78, 0.035, 6, 24),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.1;
group.add(ring);
const tentMaterial = new THREE.MeshStandardMaterial({
color: groupColors[groupIndex],
roughness: 0.9,
flatShading: true,
emissive: 0x000000
});
const tent = new THREE.Mesh(
new THREE.ConeGeometry(0.59, 0.95, 4),
tentMaterial
);
tent.position.set(0, 0.57, -0.08);
tent.rotation.y = Math.PI / 4;
tent.castShadow = true;
group.add(tent);
addBox(
group,
[0.035, 0.68, 0.035],
[0.44, 0.4, -0.27],
0xded2ae
);
const flag = new THREE.Mesh(
new THREE.BufferGeometry(),
new THREE.MeshBasicMaterial({
color: groupColors[groupIndex],
side: THREE.DoubleSide
})
);
flag.geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0.45, 0.72, -0.27,
0.78, 0.62, -0.27,
0.45, 0.52, -0.27
],
3
)
);
flag.geometry.computeVertexNormals();
group.add(flag);
// A few low-poly figures communicate the group setting.
const personCount = Math.min(groups[groupIndex].residents, 4);
for (let i = 0; i < personCount; i++) {
const angle = -2.65 + (i / Math.max(1, personCount - 1)) * 2.2;
addPerson(
group,
Math.sin(angle) * 0.73,
-0.13 + Math.cos(angle) * 0.38,
0x7d958f,
angle
);
}
const pallet = new THREE.Group();
pallet.position.set(0, 0, 0.63);
addBox(pallet, [1.04, 0.07, 0.73], [0, 0.035, 0], 0x725b42);
for (const resource of resourceOrder) {
const count = allocations[rule][resource][groupIndex];
const rowZ =
resource === "blankets"
? -0.21
: resource === "water"
? 0.02
: 0.24;
for (let i = 0; i < count; i++) {
const x = (i - (count - 1) / 2) * 0.36;
if (resource === "blankets") {
addBlanketToken(pallet, x, rowZ, 0);
} else if (resource === "water") {
addWaterToken(pallet, x, rowZ);
} else {
addTransportToken(pallet, x, rowZ);
}
}
}
group.add(pallet);
root.add(group);
group.traverse(object => {
if (object.isMesh) {
object.userData.groupIndex = groupIndex;
object.userData.rule = rule;
interactiveMeshes.push(object);
}
});
groupVisuals.push({
padMaterial,
ringMaterial,
tentMaterial
});
}
function addWorldLabel(html, className, worldPosition, onClick) {
const element = document.createElement("div");
element.className = `world-label ${className}`;
element.innerHTML = html;
if (onClick) {
element.addEventListener("click", onClick);
}
worldLayer.appendChild(element);
const label = {
element,
position: worldPosition.clone()
};
worldLabels.push(label);
return label;
}
function buildDiorama(rule, xPosition, title) {
const root = new THREE.Group();
root.position.x = xPosition;
addBox(
root,
[9.15, 0.34, 6.05],
[0, -0.19, 0.2],
0x173137
);
addBox(
root,
[8.72, 0.035, 5.62],
[0, 0.005, 0.2],
0x234147
);
addBox(
root,
[7.5, 0.025, 1.25],
[0, 0.04, 0.83],
0x294a4d
);
addShelterBuilding(root);
addSupplyDepot(root);
groups.forEach((_, index) => createGroup(root, index, rule));
scene.add(root);
addWorldLabel(
`<small>${rule === "equal" ? "Rule 1" : "Rule 2"}</small><strong>${title}</strong>`,
"rule-world-label",
new THREE.Vector3(xPosition, 2.42, -1.72)
);
groups.forEach((group, index) => {
const position = groupPositions[index];
const unmetHTML = resourceOrder
.map(resource => {
const count = unmet(rule, index, resource);
return `
<span title="${count} unmet ${resources[resource].plural}">
<i class="resource-dot ${resource}"></i>${count}
</span>
`;
})
.join("");
addWorldLabel(
`
<div class="group-label-main">
<strong>Group ${group.id}</strong>
<span>${group.residents} residents</span>
</div>
<div class="group-unmet" aria-label="Unmet requests">
${unmetHTML}
</div>
`,
"group-world-label",
new THREE.Vector3(
xPosition + position.x,
1.48,
position.z - 0.08
),
() => selectGroup(index)
);
});
return root;
}
buildDiorama("equal", -5.45, "Equal-household rounds");
buildDiorama("proportional", 5.45, "Resident-proportional split");
// -------------------------------------------------------------------------
// UI generation
// -------------------------------------------------------------------------
const inspector = document.querySelector("#inspector");
const tableBody = document.querySelector("#comparison-body");
let selectedGroup = 3;
function tripletMarkup(values, cssClass = "") {
return `
<span class="triplet ${cssClass}">
${resourceOrder
.map(
(resource, index) => `
<span>
<i class="resource-dot ${resource}"></i>${values[index]}
</span>
`
)
.join("")}
</span>
`;
}
function ruleAllocationLine(rule, index) {
return resourceOrder
.map(resource => {
const allocated = allocations[rule][resource][index];
const requested = groups[index].requests[resource];
return `<strong>${allocated}</strong>/${requested} ${resources[resource].label}`;
})
.join(" · ");
}
function ruleUnmetLine(rule, index) {
return resourceOrder
.map(resource => {
const count = unmet(rule, index, resource);
return `${count} ${resources[resource].plural}`;
})
.join(" · ");
}
function updateInspector() {
const group = groups[selectedGroup];
inspector.innerHTML = `
<div class="inspector-top">
<div class="group-name">
<span class="group-id">${group.id}</span>
<span>Group ${group.id}</span>
</div>
<span class="residents">${group.residents} residents</span>
</div>
<div class="request-line">
${resourceOrder
.map(resource => {
const count = group.requests[resource];
return `
<span class="request-chip">
<i class="resource-dot ${resource}"></i>
${count} ${resources[resource].label}
</span>
`;
})
.join("")}
</div>
<div class="inspector-rule">
<div class="inspector-rule-title">
<span>Rule 1 · Equal-household</span>
<span>allocated / requested</span>
</div>
<div class="allocation-line">${ruleAllocationLine("equal", selectedGroup)}</div>
<div class="unmet-line">Unmet: ${ruleUnmetLine("equal", selectedGroup)}</div>
</div>
<div class="inspector-rule">
<div class="inspector-rule-title">
<span>Rule 2 · Resident-proportional</span>
<span>allocated / requested</span>
</div>
<div class="allocation-line">
${ruleAllocationLine("proportional", selectedGroup)}
</div>
<div class="unmet-line">
Unmet: ${ruleUnmetLine("proportional", selectedGroup)}
</div>
</div>
<div class="inspector-footnote">
These are logistical request counts, not scores of people. Rule 2
uses resident count only as an allocation weight.
</div>
`;
}
function buildTable() {
tableBody.innerHTML = groups
.map((group, index) => {
const requested = resourceOrder.map(
resource => group.requests[resource]
);
const equalUnmet = resourceOrder.map(resource =>
unmet("equal", index, resource)
);
const proportionalUnmet = resourceOrder.map(resource =>
unmet("proportional", index, resource)
);
return `
<tr data-group="${index}" class="${index === selectedGroup ? "selected" : ""}">
<td>
<span class="table-group">
<span class="table-id">${group.id}</span>
Group ${group.id}
</span>
</td>
<td>${group.residents}</td>
<td>${tripletMarkup(requested)}</td>
<td>${tripletMarkup(equalUnmet)}</td>
<td>${tripletMarkup(proportionalUnmet)}</td>
</tr>
`;
})
.join("");
tableBody.querySelectorAll("tr").forEach(row => {
row.addEventListener("click", () => {
selectGroup(Number(row.dataset.group));
});
});
}
function selectGroup(index) {
selectedGroup = index;
groupVisuals.forEach((visual, visualIndex) => {
const selected = visualIndex === selectedGroup;
visual.padMaterial.emissive.setHex(
selected ? 0x123f3c : 0x000000
);
visual.ringMaterial.color.setHex(
selected ? 0x74d7cb : 0x35565b
);
visual.ringMaterial.emissive.setHex(
selected ? 0x163b38 : 0x000000
);
visual.tentMaterial.emissive.setHex(
selected ? 0x102d2b : 0x000000
);
});
worldLabels
.filter(label => label.element.classList.contains("group-world-label"))
.forEach((label, labelIndex) => {
label.element.classList.toggle(
"selected",
labelIndex === selectedGroup
);
});
tableBody.querySelectorAll("tr").forEach(row => {
row.classList.toggle(
"selected",
Number(row.dataset.group) === selectedGroup
);
});
updateInspector();
}
buildTable();
updateInspector();
// -------------------------------------------------------------------------
// Direct camera controls: no addons or examples are used.
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0.035,
pitch: 0.52,
radius: 22,
radiusGoal: 22,
target: new THREE.Vector3(0, 0.56, 0.2),
targetGoal: new THREE.Vector3(0, 0.56, 0.2)
};
function responsiveRadius(base) {
const aspect = window.innerWidth / window.innerHeight;
return aspect < 1.2 ? base * (1.2 / Math.max(aspect, 0.72)) : base;
}
function setView(view) {
if (view === "equal") {
cameraState.targetGoal.set(-5.45, 0.58, 0.25);
cameraState.radiusGoal = responsiveRadius(12.3);
} else if (view === "proportional") {
cameraState.targetGoal.set(5.45, 0.58, 0.25);
cameraState.radiusGoal = responsiveRadius(12.3);
} else {
cameraState.targetGoal.set(0, 0.56, 0.2);
cameraState.radiusGoal = responsiveRadius(22);
}
document.querySelectorAll("[data-view]").forEach(button => {
button.classList.toggle("active", button.dataset.view === view);
});
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
let pointerDown = false;
let pointerMoved = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousX = 0;
let previousY = 0;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = true;
pointerMoved = false;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerDown) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (
Math.abs(event.clientX - pointerStartX) > 4 ||
Math.abs(event.clientY - pointerStartY) > 4
) {
pointerMoved = true;
}
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.24,
0.94
);
previousX = event.clientX;
previousY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", event => {
pointerDown = false;
if (!pointerMoved) {
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;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactiveMeshes, false);
if (hits.length && hits[0].object.userData.groupIndex !== undefined) {
selectGroup(hits[0].object.userData.groupIndex);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radiusGoal = THREE.MathUtils.clamp(
cameraState.radiusGoal + event.deltaY * 0.012,
9,
34
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
setView("overview");
});
window.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") {
cameraState.yaw -= 0.08;
} else if (event.key === "ArrowRight") {
cameraState.yaw += 0.08;
} else if (event.key === "ArrowUp") {
cameraState.pitch = Math.min(
0.94,
cameraState.pitch + 0.05
);
} else if (event.key === "ArrowDown") {
cameraState.pitch = Math.max(
0.24,
cameraState.pitch - 0.05
);
} else if (event.key === "0") {
setView("overview");
}
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function updateWorldLabels() {
for (const label of worldLabels) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
cameraState.target.lerp(cameraState.targetGoal, 0.075);
cameraState.radius +=
(cameraState.radiusGoal - cameraState.radius) * 0.075;
const horizontalRadius =
cameraState.radius * Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x +
Math.sin(cameraState.yaw) * horizontalRadius,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.radius,
cameraState.target.z +
Math.cos(cameraState.yaw) * horizontalRadius
);
camera.lookAt(cameraState.target);
const selectedVisual = groupVisuals[selectedGroup];
if (selectedVisual) {
const pulse = 1 + Math.sin(elapsed * 2.5) * 0.025;
selectedVisual.ringMaterial.emissiveIntensity = 0.35 + pulse * 0.18;
}
updateWorldLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```