Prompt specification
Build or customize the Three.js 3D scene "Shared-project choice-token board" 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: Shared-project choice-token board
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shared-project-choice-token-board-x3849
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a community decision about a shared project. Display three neighborhood project models beside voting tokens and clear option symbols; separate each person's token from the final tally so aggregation remains visible. Stylized solid forms.
Working Three.js Starter (shared-project-choice-token-board-x3849):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Neighborhood Commons — Community Vote</title>
<style>
:root {
--ink: #26343b;
--muted: #667176;
--paper: #f5f0e7;
--green: #2f9d73;
--blue: #4384d8;
--orange: #ec8b45;
--border: rgba(38, 52, 59, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e3d9;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hero {
position: fixed;
top: 24px;
left: 28px;
z-index: 5;
width: min(430px, calc(100vw - 56px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
padding: 7px 11px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(245, 240, 231, 0.82);
backdrop-filter: blur(12px);
color: #506066;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(47, 157, 115, 0.13);
}
h1 {
max-width: 420px;
margin: 0;
font-size: clamp(29px, 4vw, 54px);
line-height: 0.98;
letter-spacing: -0.055em;
}
.hero p {
max-width: 385px;
margin: 14px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.view-tools {
position: fixed;
top: 24px;
right: 24px;
z-index: 7;
display: flex;
align-items: center;
gap: 10px;
}
.view-help,
#resetView {
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(245, 240, 231, 0.84);
backdrop-filter: blur(12px);
color: #526066;
font: inherit;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.02em;
}
.view-help {
padding: 10px 14px;
}
#resetView {
padding: 9px 13px;
cursor: pointer;
}
#resetView:hover {
background: #fffaf1;
color: var(--ink);
}
.vote-panel {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 8;
width: min(930px, calc(100vw - 32px));
transform: translateX(-50%);
display: grid;
grid-template-columns: 165px 1fr 130px;
align-items: stretch;
gap: 12px;
padding: 12px;
border: 1px solid rgba(38, 52, 59, 0.15);
border-radius: 22px;
background: rgba(248, 244, 237, 0.92);
box-shadow: 0 18px 60px rgba(47, 54, 53, 0.18);
backdrop-filter: blur(18px);
}
.panel-intro {
display: flex;
flex-direction: column;
justify-content: center;
padding: 4px 8px 4px 10px;
}
.panel-intro span {
color: #899095;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.panel-intro strong {
margin-top: 5px;
font-size: 17px;
line-height: 1.15;
letter-spacing: -0.025em;
}
.options {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
}
.option {
display: flex;
align-items: center;
gap: 10px;
min-width: 0;
padding: 9px 11px;
border: 1px solid transparent;
border-radius: 14px;
background: #ece7de;
color: var(--ink);
text-align: left;
cursor: pointer;
transition:
transform 160ms ease,
background 160ms ease,
border-color 160ms ease,
box-shadow 160ms ease;
}
.option:hover {
transform: translateY(-2px);
background: #f4efe6;
}
.option[aria-pressed="true"] {
border-color: var(--accent);
background: white;
box-shadow: 0 5px 16px rgba(38, 52, 59, 0.1);
}
.option-symbol {
flex: 0 0 auto;
display: grid;
place-items: center;
width: 36px;
height: 36px;
border-radius: 11px;
background: var(--accent);
color: white;
font-size: 20px;
font-weight: 900;
line-height: 1;
}
.option-copy {
min-width: 0;
}
.option-copy b {
display: block;
overflow: hidden;
font-size: 13px;
line-height: 1.2;
text-overflow: ellipsis;
white-space: nowrap;
}
.option-copy small {
display: block;
overflow: hidden;
margin-top: 3px;
color: #7a8286;
font-size: 10px;
line-height: 1.2;
text-overflow: ellipsis;
white-space: nowrap;
}
#castVote {
border: 0;
border-radius: 15px;
background: var(--ink);
color: white;
font: inherit;
font-size: 13px;
font-weight: 800;
cursor: pointer;
transition:
transform 160ms ease,
background 160ms ease;
}
#castVote:hover {
transform: translateY(-2px);
background: #172329;
}
#status {
position: fixed;
left: 50%;
bottom: 133px;
z-index: 7;
width: max-content;
max-width: min(760px, calc(100vw - 32px));
transform: translateX(-50%);
padding: 8px 13px;
border-radius: 999px;
background: rgba(38, 52, 59, 0.9);
color: #f9f5ed;
box-shadow: 0 8px 24px rgba(38, 52, 59, 0.16);
font-size: 11px;
font-weight: 650;
text-align: center;
pointer-events: none;
}
@media (max-width: 780px) {
.hero {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
max-width: 330px;
font-size: 35px;
}
.hero p {
display: none;
}
.view-tools {
top: auto;
right: 16px;
bottom: 188px;
}
.view-help {
display: none;
}
.vote-panel {
bottom: 12px;
grid-template-columns: 1fr;
gap: 8px;
padding: 10px;
border-radius: 18px;
}
.panel-intro {
display: none;
}
.option {
padding: 8px;
}
.option-copy small {
display: none;
}
.option-symbol {
width: 32px;
height: 32px;
}
#castVote {
min-height: 42px;
}
#status {
bottom: 162px;
border-radius: 13px;
white-space: normal;
}
}
</style>
</head>
<body>
<div id="viewport" aria-label="Interactive 3D neighborhood voting scene"></div>
<header class="hero">
<div class="eyebrow">Neighborhood meeting · Open vote</div>
<h1>What should we build together?</h1>
<p>
Three shared-project models, three separate trays of individual tokens,
and one independently aggregated final tally.
</p>
</header>
<div class="view-tools">
<div class="view-help">Drag to orbit · Scroll to zoom</div>
<button id="resetView" type="button">Reset view</button>
</div>
<div id="status" role="status" aria-live="polite">
Choose a project and cast a token.
</div>
<section class="vote-panel" aria-label="Cast a community vote">
<div class="panel-intro">
<span>Your token</span>
<strong>Choose one shared project</strong>
</div>
<div class="options">
<button
class="option"
type="button"
data-option="0"
aria-pressed="true"
style="--accent: var(--green)"
>
<span class="option-symbol" aria-hidden="true">✓</span>
<span class="option-copy">
<b>Pocket garden</b>
<small>Shade, seating, native plants</small>
</span>
</button>
<button
class="option"
type="button"
data-option="1"
aria-pressed="false"
style="--accent: var(--blue)"
>
<span class="option-symbol" aria-hidden="true">◆</span>
<span class="option-copy">
<b>Community mural</b>
<small>Artwork on the shared wall</small>
</span>
</button>
<button
class="option"
type="button"
data-option="2"
aria-pressed="false"
style="--accent: var(--orange)"
>
<span class="option-symbol" aria-hidden="true">★</span>
<span class="option-copy">
<b>Tool library</b>
<small>Shared equipment for everyone</small>
</span>
</button>
</div>
<button id="castVote" type="button">Cast token →</button>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.querySelector("#viewport");
const statusEl = document.querySelector("#status");
const castButton = document.querySelector("#castVote");
const optionButtons = [...document.querySelectorAll(".option")];
const resetButton = document.querySelector("#resetView");
const ACCENTS = [0x2f9d73, 0x4384d8, 0xec8b45];
const ACCENT_CSS = ["#2f9d73", "#4384d8", "#ec8b45"];
const ACCENT_LIGHT = ["#dff2e9", "#e1ebfb", "#fbe7d7"];
const PROJECT_NAMES = ["Pocket garden", "Community mural", "Tool library"];
const PROJECT_X = [-5.1, -2.2, 0.7];
const TRAY_Z = 2.8;
const BOARD_X = 4.7;
const personalCounts = [4, 3, 2];
const finalCounts = [4, 3, 2];
let selectedOption = 0;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e3d9);
const camera = new THREE.PerspectiveCamera(44, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff7e9, 0x71848a, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d7, 3.1);
sun.position.set(-4, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xcde5f2, 0.8);
fill.position.set(8, 5, -5);
scene.add(fill);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.74,
metalness: 0,
flatShading: false,
...options
});
}
const materials = {
ground: standardMaterial(0xe6dfd4),
platform: standardMaterial(0xeee8dd),
podium: standardMaterial(0xd8cbb8),
cream: standardMaterial(0xf6f0e4),
soil: standardMaterial(0x59463b),
wood: standardMaterial(0xb87c4d),
darkWood: standardMaterial(0x744a35),
leaf: standardMaterial(0x4c9b69),
leafLight: standardMaterial(0x74b878),
trunk: standardMaterial(0x8b5d3d),
white: standardMaterial(0xfaf7ef),
blue: standardMaterial(ACCENTS[1]),
orange: standardMaterial(ACCENTS[2]),
green: standardMaterial(ACCENTS[0]),
navy: standardMaterial(0x2d4149),
wall: standardMaterial(0xf4eee2),
yellow: standardMaterial(0xf0b74d),
red: standardMaterial(0xd76b58)
};
function addMesh(parent, geometry, material, position = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, size, position, material) {
return addMesh(
parent,
new THREE.BoxGeometry(...size),
material,
position
);
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
material,
segments = 32
) {
return addMesh(
parent,
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material,
position
);
}
function makeTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function textPlane(
text,
width,
height,
{
color = "#26343b",
background = null,
fontSize = 68,
fontWeight = 800
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
if (background) {
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
ctx.fillStyle = color;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = `${fontWeight} ${fontSize}px Arial, sans-serif`;
ctx.fillText(text, 512, 132, 970);
const material = new THREE.MeshBasicMaterial({
map: makeTexture(canvas),
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
return new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
}
function countPlane(index, count) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 320;
const ctx = canvas.getContext("2d");
ctx.fillStyle = ACCENT_LIGHT[index];
ctx.fillRect(0, 0, 512, 320);
ctx.fillStyle = ACCENT_CSS[index];
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 142px Arial, sans-serif";
ctx.fillText(String(count), 256, 125);
ctx.font = "800 43px Arial, sans-serif";
ctx.fillText("VOTES", 256, 238);
return new THREE.Mesh(
new THREE.PlaneGeometry(0.78, 0.49),
new THREE.MeshBasicMaterial({
map: makeTexture(canvas),
transparent: true,
depthWrite: false
})
);
}
function makeCheck(material) {
const group = new THREE.Group();
function segment(a, b) {
const dx = b[0] - a[0];
const dy = b[1] - a[1];
const length = Math.hypot(dx, dy);
const piece = addMesh(
group,
new THREE.BoxGeometry(length, 0.13, 0.13),
material
);
piece.position.set(
(a[0] + b[0]) / 2,
(a[1] + b[1]) / 2,
0
);
piece.rotation.z = Math.atan2(dy, dx);
}
segment([-0.29, -0.03], [-0.08, -0.24]);
segment([-0.08, -0.24], [0.31, 0.28]);
addMesh(
group,
new THREE.SphereGeometry(0.07, 16, 12),
material,
[-0.08, -0.24, 0]
);
return group;
}
function makeDiamond(material) {
const group = new THREE.Group();
const diamond = addMesh(
group,
new THREE.BoxGeometry(0.56, 0.56, 0.13),
material
);
diamond.rotation.z = Math.PI / 4;
return group;
}
function makeStar(material) {
const group = new THREE.Group();
const shape = new THREE.Shape();
for (let i = 0; i < 10; i++) {
const radius = i % 2 === 0 ? 0.47 : 0.21;
const angle = -Math.PI / 2 + (i * Math.PI) / 5;
const x = Math.cos(angle) * radius;
const y = Math.sin(angle) * radius;
if (i === 0) shape.moveTo(x, y);
else shape.lineTo(x, y);
}
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.13,
steps: 1,
bevelEnabled: true,
bevelThickness: 0.025,
bevelSize: 0.025,
bevelSegments: 1
});
geometry.center();
addMesh(group, geometry, material);
return group;
}
function makeSymbol(index, material, scale = 1) {
const symbol =
index === 0
? makeCheck(material)
: index === 1
? makeDiamond(material)
: makeStar(material);
symbol.scale.setScalar(scale);
return symbol;
}
// Ground and raised display platform.
const ground = addMesh(
scene,
new THREE.PlaneGeometry(80, 80),
materials.ground,
[0, -0.31, 0]
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
const platform = addMesh(
scene,
new THREE.CylinderGeometry(5.9, 6.05, 0.25, 64),
materials.platform,
[-0.4, -0.15, 0.55]
);
platform.scale.x = 1.25;
platform.castShadow = false;
const zoneModels = textPlane(
"THREE PROJECT MODELS",
4.2,
0.42,
{ color: "#788287", fontSize: 54 }
);
zoneModels.position.set(-2.2, -0.01, -1.9);
zoneModels.rotation.x = -Math.PI / 2;
scene.add(zoneModels);
const zoneTokens = textPlane(
"INDIVIDUAL TOKENS",
4.0,
0.42,
{ color: "#788287", fontSize: 54 }
);
zoneTokens.position.set(-2.2, -0.005, 4.05);
zoneTokens.rotation.x = -Math.PI / 2;
scene.add(zoneTokens);
// A dotted floor divider keeps the personal and aggregate areas distinct.
for (let i = 0; i < 11; i++) {
addBox(
scene,
[0.055, 0.025, 0.28],
[2.47, -0.005, -1.45 + i * 0.49],
standardMaterial(0xb7aa98)
);
}
const projectRoots = [];
const markerGroups = [];
function createGarden(root) {
const planter = addBox(
root,
[1.58, 0.48, 0.82],
[-0.28, 0.61, -0.15],
materials.wood
);
addBox(
root,
[1.4, 0.06, 0.64],
[-0.28, 0.87, -0.15],
materials.soil
);
addCylinder(
root,
0.12,
0.16,
1.05,
[-0.52, 1.28, -0.2],
materials.trunk
);
const crownA = addMesh(
root,
new THREE.SphereGeometry(0.58, 20, 16),
materials.leaf,
[-0.52, 2.02, -0.2]
);
crownA.scale.set(1, 0.92, 0.95);
const crownB = addMesh(
root,
new THREE.SphereGeometry(0.43, 20, 16),
materials.leafLight,
[-0.82, 1.89, -0.04]
);
crownB.scale.set(1, 0.95, 0.9);
const crownC = addMesh(
root,
new THREE.SphereGeometry(0.4, 20, 16),
materials.leaf,
[-0.22, 1.88, -0.05]
);
// Bench.
addBox(
root,
[0.82, 0.12, 0.32],
[0.68, 0.72, 0.37],
materials.darkWood
);
addBox(
root,
[0.82, 0.42, 0.1],
[0.68, 0.98, 0.2],
materials.wood
);
[-0.27, 0.27].forEach((x) => {
addBox(
root,
[0.09, 0.44, 0.09],
[0.68 + x, 0.48, 0.37],
materials.navy
);
});
// Small flowers.
[
[-0.85, 0.96, 0.08],
[-0.38, 0.97, 0.11],
[0.1, 0.96, 0.08]
].forEach((position, i) => {
addCylinder(
root,
0.025,
0.025,
0.22,
position,
materials.leaf,
10
);
addMesh(
root,
new THREE.SphereGeometry(0.09, 12, 10),
i === 1 ? materials.yellow : materials.red,
[position[0], position[1] + 0.13, position[2]]
);
});
}
function createMural(root) {
addBox(
root,
[2.12, 1.58, 0.18],
[0, 1.16, -0.43],
materials.wall
);
addBox(
root,
[0.62, 1.08, 0.06],
[-0.63, 1.2, -0.31],
materials.blue
);
addBox(
root,
[0.88, 0.5, 0.07],
[0.23, 0.79, -0.3],
materials.green
);
addBox(
root,
[0.58, 0.28, 0.07],
[0.58, 1.28, -0.3],
materials.orange
);
const sun = addCylinder(
root,
0.22,
0.22,
0.08,
[0.66, 1.75, -0.28],
materials.yellow,
28
);
sun.rotation.x = Math.PI / 2;
// Simple painted house.
addBox(
root,
[0.48, 0.42, 0.07],
[-0.65, 0.78, -0.24],
materials.cream
);
const roof = addMesh(
root,
new THREE.ConeGeometry(0.4, 0.3, 4),
materials.red,
[-0.65, 1.1, -0.24]
);
roof.rotation.y = Math.PI / 4;
addBox(
root,
[0.13, 0.22, 0.07],
[-0.65, 0.71, -0.19],
materials.darkWood
);
// Paint cans at the base.
addCylinder(
root,
0.13,
0.13,
0.22,
[0.82, 0.42, 0.38],
materials.blue
);
addCylinder(
root,
0.11,
0.11,
0.18,
[1.04, 0.4, 0.22],
materials.orange
);
}
function createToolLibrary(root) {
addBox(
root,
[1.78, 1.28, 1.15],
[0, 1.0, -0.12],
standardMaterial(0x718b94)
);
const roofLeft = addBox(
root,
[1.12, 0.13, 1.42],
[-0.43, 1.78, -0.1],
materials.navy
);
roofLeft.rotation.z = 0.52;
const roofRight = addBox(
root,
[1.12, 0.13, 1.42],
[0.43, 1.78, -0.1],
materials.navy
);
roofRight.rotation.z = -0.52;
addBox(
root,
[0.64, 1.02, 0.07],
[-0.12, 0.83, 0.49],
materials.darkWood
);
addBox(
root,
[0.38, 0.38, 0.06],
[0.58, 1.22, 0.49],
materials.yellow
);
// Crossed tools on the door.
const toolA = addBox(
root,
[0.06, 0.68, 0.04],
[-0.27, 0.91, 0.54],
materials.orange
);
toolA.rotation.z = -0.35;
const toolB = addBox(
root,
[0.06, 0.68, 0.04],
[0.02, 0.91, 0.54],
materials.cream
);
toolB.rotation.z = 0.35;
addBox(
root,
[0.82, 0.1, 0.28],
[0.56, 0.45, 0.61],
materials.wood
);
addBox(
root,
[0.08, 0.34, 0.08],
[0.25, 0.28, 0.61],
materials.navy
);
addBox(
root,
[0.08, 0.34, 0.08],
[0.85, 0.28, 0.61],
materials.navy
);
}
const builders = [createGarden, createMural, createToolLibrary];
for (let i = 0; i < 3; i++) {
const root = new THREE.Group();
root.position.x = PROJECT_X[i];
scene.add(root);
projectRoots.push(root);
addBox(
root,
[2.58, 0.3, 2.65],
[0, 0.15, 0],
materials.podium
);
builders[i](root);
// Vertical option marker.
addCylinder(
root,
0.055,
0.065,
1.7,
[0, 1.2, 1.32],
materials.navy,
16
);
const marker = new THREE.Group();
marker.position.set(0, 2.24, 1.32);
root.add(marker);
const disk = addCylinder(
marker,
0.47,
0.47,
0.12,
[0, 0, 0],
materials.cream,
36
);
disk.rotation.x = Math.PI / 2;
const symbol = makeSymbol(
i,
standardMaterial(ACCENTS[i]),
0.9
);
symbol.position.z = 0.08;
marker.add(symbol);
markerGroups.push(marker);
// Project name plaque.
addBox(
root,
[1.88, 0.35, 0.08],
[0, 0.32, 1.37],
materials.cream
);
const name = textPlane(
PROJECT_NAMES[i].toUpperCase(),
1.72,
0.24,
{
color: ACCENT_CSS[i],
fontSize: 54
}
);
name.position.set(0, 0.32, 1.42);
root.add(name);
}
// Individual token trays.
const tokenEntries = [[], [], []];
const trayLabels = [];
function createToken(index) {
const group = new THREE.Group();
const discMaterial = standardMaterial(ACCENTS[index]);
addCylinder(
group,
0.18,
0.18,
0.09,
[0, 0, 0],
discMaterial,
30
);
addCylinder(
group,
0.15,
0.15,
0.012,
[0, 0.051, 0],
materials.cream,
30
);
const symbol = makeSymbol(
index,
standardMaterial(0xffffff),
0.31
);
symbol.rotation.x = -Math.PI / 2;
symbol.position.y = 0.066;
group.add(symbol);
return group;
}
function layoutTokens(index) {
const count = personalCounts[index];
const rows = Math.max(1, Math.ceil(count / 4));
tokenEntries[index].forEach((entry, tokenIndex) => {
const column = tokenIndex % 4;
const row = Math.floor(tokenIndex / 4);
const itemsOnRow = Math.min(
4,
count - row * 4
);
const x =
PROJECT_X[index] +
(column - (itemsOnRow - 1) / 2) * 0.41;
const z =
TRAY_Z + (row - (rows - 1) / 2) * 0.3;
entry.target.set(x, 0.225, z);
});
}
function updateTrayLabel(index) {
const label = trayLabels[index];
const oldMap = label.material.map;
const replacement = textPlane(
`${personalCounts[index]} TOKENS`,
1.25,
0.2,
{
color: ACCENT_CSS[index],
fontSize: 48
}
);
label.material.map = replacement.material.map;
label.material.needsUpdate = true;
replacement.material.dispose();
oldMap.dispose();
}
for (let i = 0; i < 3; i++) {
addBox(
scene,
[1.95, 0.12, 0.92],
[PROJECT_X[i], 0.09, TRAY_Z],
standardMaterial(0xd7cbb8)
);
const label = textPlane(
`${personalCounts[i]} TOKENS`,
1.25,
0.2,
{
color: ACCENT_CSS[i],
fontSize: 48
}
);
label.position.set(PROJECT_X[i], 0.16, TRAY_Z + 0.47);
scene.add(label);
trayLabels.push(label);
for (let j = 0; j < personalCounts[i]; j++) {
const token = createToken(i);
scene.add(token);
tokenEntries[i].push({
group: token,
target: new THREE.Vector3()
});
}
layoutTokens(i);
tokenEntries[i].forEach((entry) => {
entry.group.position.copy(entry.target);
});
}
// Separate aggregate board.
const tallyBoard = new THREE.Group();
tallyBoard.position.set(BOARD_X, 0, 0);
scene.add(tallyBoard);
addBox(
tallyBoard,
[3.55, 3.35, 0.28],
[0, 1.86, 0],
materials.navy
);
[-1.25, 1.25].forEach((x) => {
addBox(
tallyBoard,
[0.18, 0.72, 0.22],
[x, 0.2, -0.02],
materials.darkWood
);
});
const tallyTitle = textPlane(
"FINAL TALLY",
2.7,
0.48,
{
color: "#ffffff",
fontSize: 74
}
);
tallyTitle.position.set(0, 3.27, 0.17);
tallyBoard.add(tallyTitle);
const tallySubtitle = textPlane(
"AGGREGATED COMMUNITY COUNT",
2.65,
0.22,
{
color: "#aec1c7",
fontSize: 35
}
);
tallySubtitle.position.set(0, 2.9, 0.17);
tallyBoard.add(tallySubtitle);
const rowY = [2.48, 1.7, 0.92];
const countMeshes = [];
const countPanels = [];
for (let i = 0; i < 3; i++) {
addBox(
tallyBoard,
[3.12, 0.62, 0.13],
[0, rowY[i], 0.19],
materials.cream
);
const symbol = makeSymbol(
i,
standardMaterial(ACCENTS[i]),
0.57
);
symbol.position.set(-1.24, rowY[i], 0.29);
tallyBoard.add(symbol);
const name = textPlane(
PROJECT_NAMES[i].toUpperCase(),
1.65,
0.22,
{
color: "#536168",
fontSize: 43
}
);
name.position.set(-0.29, rowY[i], 0.28);
tallyBoard.add(name);
const countPanel = addBox(
tallyBoard,
[0.82, 0.5, 0.08],
[1.03, rowY[i], 0.3],
standardMaterial(ACCENT_LIGHT[i])
);
countPanels.push(countPanel);
const count = countPlane(i, finalCounts[i]);
count.position.set(1.03, rowY[i], 0.35);
tallyBoard.add(count);
countMeshes.push(count);
}
const aggregationNote = textPlane(
"PERSONAL TOKENS REMAIN IN THEIR TRAYS",
3.0,
0.18,
{
color: "#aec1c7",
fontSize: 28
}
);
aggregationNote.position.set(0, 0.4, 0.17);
tallyBoard.add(aggregationNote);
function replaceCount(index, count) {
const mesh = countMeshes[index];
const oldMap = mesh.material.map;
const replacement = countPlane(index, count);
mesh.material.map = replacement.material.map;
mesh.material.needsUpdate = true;
replacement.material.dispose();
oldMap.dispose();
countPanels[index].scale.set(1.12, 1.12, 1);
}
// Camera controls implemented directly with Three.js core.
const target = new THREE.Vector3(-0.25, 1.0, 0.45);
let radius = 17.5;
let theta = 0;
let phi = 1.08;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
let userAdjustedZoom = false;
function fittedRadius() {
const aspect = window.innerWidth / window.innerHeight;
return Math.max(17.5, 15.8 / aspect);
}
function updateCamera() {
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
radius = fittedRadius();
theta = 0;
phi = 1.08;
userAdjustedZoom = false;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
theta -= dx * 0.005;
phi = THREE.MathUtils.clamp(phi - dy * 0.005, 0.48, 1.4);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
10,
38
);
userAdjustedZoom = true;
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
resetButton.addEventListener("click", resetCamera);
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
if (!userAdjustedZoom) {
radius = fittedRadius();
updateCamera();
}
}
window.addEventListener("resize", resize);
resize();
resetCamera();
// Voting behavior and token-to-tally animation.
const flights = [];
function leaderDescription() {
const max = Math.max(...finalCounts);
const leaders = finalCounts
.map((count, index) => ({ count, index }))
.filter((entry) => entry.count === max);
if (leaders.length > 1) {
return `${leaders
.map((entry) => PROJECT_NAMES[entry.index])
.join(" and ")} are tied at ${max} votes.`;
}
return `${PROJECT_NAMES[leaders[0].index]} leads with ${max} votes.`;
}
function selectOption(index) {
selectedOption = index;
optionButtons.forEach((button, buttonIndex) => {
button.setAttribute(
"aria-pressed",
String(buttonIndex === index)
);
});
statusEl.textContent =
`${PROJECT_NAMES[index]} selected. Cast a token to add it to the personal tray.`;
}
optionButtons.forEach((button, index) => {
button.addEventListener("click", () => selectOption(index));
});
window.addEventListener("keydown", (event) => {
if (event.key === "1") selectOption(0);
if (event.key === "2") selectOption(1);
if (event.key === "3") selectOption(2);
if (event.key.toLowerCase() === "r") resetCamera();
});
castButton.addEventListener("click", () => {
const index = selectedOption;
// The personal token is added immediately and stays in its own tray.
personalCounts[index] += 1;
const personalToken = createToken(index);
scene.add(personalToken);
tokenEntries[index].push({
group: personalToken,
target: new THREE.Vector3()
});
layoutTokens(index);
updateTrayLabel(index);
const targetPosition = tokenEntries[index].at(-1).target.clone();
personalToken.position.set(
targetPosition.x,
targetPosition.y + 0.8,
targetPosition.z
);
personalToken.scale.setScalar(0.05);
// A copy travels to the aggregate board. The personal token is not moved.
const aggregateToken = personalToken.clone(true);
aggregateToken.scale.setScalar(1);
aggregateToken.position.copy(targetPosition);
scene.add(aggregateToken);
const end = new THREE.Vector3(
BOARD_X + 1.03,
rowY[index],
0.47
);
const control = targetPosition.clone().lerp(end, 0.48);
control.y += 2.3;
control.z += 0.35;
flights.push({
group: aggregateToken,
start: targetPosition.clone(),
control,
end,
index,
elapsed: 0,
duration: 1.25
});
statusEl.textContent =
`Your ${PROJECT_NAMES[index].toLowerCase()} token is now in the individual tray. The final tally will update separately.`;
castButton.textContent = "Cast another →";
});
const clock = new THREE.Clock();
function animate() {
const frameDelta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
// Gentle floating of the three option markers.
markerGroups.forEach((marker, index) => {
const selectedScale = index === selectedOption ? 1.08 : 1;
const pulse = index === selectedOption
? Math.sin(elapsed * 3.2) * 0.025
: 0;
const scale = selectedScale + pulse;
marker.scale.setScalar(scale);
});
// Personal tokens settle into their individual trays.
tokenEntries.forEach((entries) => {
entries.forEach((entry) => {
entry.group.position.lerp(entry.target, 0.11);
entry.group.scale.lerp(
new THREE.Vector3(1, 1, 1),
0.12
);
});
});
// Aggregate copies travel independently and disappear into the tally.
for (let i = flights.length - 1; i >= 0; i--) {
const flight = flights[i];
flight.elapsed += frameDelta;
const t = Math.min(flight.elapsed / flight.duration, 1);
const eased = t * t * (3 - 2 * t);
const inverse = 1 - eased;
flight.group.position.set(
inverse * inverse * flight.start.x +
2 * inverse * eased * flight.control.x +
eased * eased * flight.end.x,
inverse * inverse * flight.start.y +
2 * inverse * eased * flight.control.y +
eased * eased * flight.end.y,
inverse * inverse * flight.start.z +
2 * inverse * eased * flight.control.z +
eased * eased * flight.end.z
);
flight.group.rotation.y = eased * Math.PI * 3;
if (t > 0.76) {
const shrink = 1 - (t - 0.76) / 0.24;
flight.group.scale.setScalar(Math.max(0.05, shrink));
}
if (t >= 1) {
finalCounts[flight.index] += 1;
replaceCount(flight.index, finalCounts[flight.index]);
scene.remove(flight.group);
flights.splice(i, 1);
statusEl.textContent =
`Final tally updated: ${leaderDescription()} ` +
`Your personal token remains visible in its separate tray.`;
}
}
// Soft pulse on updated count panels.
countPanels.forEach((panel) => {
panel.scale.lerp(new THREE.Vector3(1, 1, 1), 0.1);
});
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
selectOption(0);
statusEl.textContent =
"Current result: Pocket garden leads. Personal tokens and the final tally are displayed separately.";
</script>
</body>
</html>
```