Prompt specification
Build or customize the Three.js 3D scene "Courtyard planning meeting" 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: Courtyard planning meeting
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/courtyard-planning-meeting-x3851
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a community decision about a shared project. Compose neighbors around a model courtyard with garden, seating, and play-area proposals; participants inspect options before placing their tokens on the shared decision board. Stylized solid forms.
Working Three.js Starter (courtyard-planning-meeting-x3851):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Courtyard Commons — Community Decision</title>
<style>
:root {
--ink: #20352f;
--muted: #68766f;
--paper: #f7f3e9;
--panel: rgba(250, 247, 239, 0.91);
--green: #5f9b72;
--orange: #df8d55;
--blue: #668db8;
--gold: #e6b85c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e1d3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
background: var(--panel);
border: 1px solid rgba(39, 65, 56, 0.13);
box-shadow: 0 14px 42px rgba(45, 55, 46, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
header {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
}
.title-block {
padding: 16px 19px 15px;
border-radius: 18px;
max-width: 430px;
}
.eyebrow {
margin-bottom: 6px;
color: #77847c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.4vw, 31px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.toolbar {
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 0;
font: inherit;
cursor: pointer;
}
.tool-button {
min-height: 42px;
padding: 0 15px;
border-radius: 13px;
color: var(--ink);
background: rgba(250, 247, 239, 0.92);
border: 1px solid rgba(39, 65, 56, 0.13);
box-shadow: 0 8px 25px rgba(45, 55, 46, 0.1);
font-size: 12px;
font-weight: 750;
transition: transform 160ms ease, background 160ms ease;
}
.tool-button:hover {
transform: translateY(-2px);
background: #fffdf7;
}
.tool-button.primary {
background: var(--ink);
color: white;
}
.options {
position: absolute;
left: 24px;
top: 50%;
width: 230px;
transform: translateY(-43%);
padding: 13px;
border-radius: 20px;
pointer-events: auto;
}
.section-label {
padding: 4px 7px 11px;
color: #78857e;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.option-card {
width: 100%;
display: grid;
grid-template-columns: 36px 1fr 25px;
align-items: center;
gap: 10px;
margin: 7px 0;
padding: 12px 10px;
text-align: left;
color: var(--ink);
background: transparent;
border: 1px solid transparent;
border-radius: 14px;
transition: background 160ms ease, border-color 160ms ease,
transform 160ms ease;
}
.option-card:hover {
background: rgba(255, 255, 255, 0.65);
transform: translateX(2px);
}
.option-card.selected {
background: white;
border-color: rgba(37, 67, 56, 0.16);
box-shadow: 0 8px 24px rgba(45, 55, 46, 0.09);
}
.swatch {
width: 34px;
height: 34px;
border-radius: 11px;
display: grid;
place-items: center;
color: white;
font-size: 16px;
font-weight: 900;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}
.garden {
background: var(--green);
}
.seating {
background: var(--orange);
}
.play {
background: var(--blue);
}
.option-name {
font-size: 13px;
font-weight: 820;
}
.option-note {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.25;
}
.count {
width: 24px;
height: 24px;
display: grid;
place-items: center;
border-radius: 50%;
color: #68766f;
background: #ece9e0;
font-size: 11px;
font-weight: 850;
}
.status {
position: absolute;
right: 24px;
bottom: 24px;
width: 292px;
padding: 15px 17px;
border-radius: 17px;
}
.status-row {
display: flex;
align-items: center;
gap: 10px;
}
.pulse {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 0 rgba(230, 184, 92, 0.55);
animation: pulse 1.8s infinite;
}
@keyframes pulse {
70% {
box-shadow: 0 0 0 8px rgba(230, 184, 92, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(230, 184, 92, 0);
}
}
#statusText {
font-size: 12px;
font-weight: 800;
line-height: 1.35;
}
#statusDetail {
margin: 7px 0 0 19px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.prompt {
position: absolute;
left: 50%;
bottom: 24px;
transform: translateX(-50%);
max-width: min(500px, calc(100vw - 680px));
padding: 13px 18px;
border-radius: 16px;
text-align: center;
color: #617068;
font-size: 11px;
line-height: 1.45;
}
.prompt strong {
color: var(--ink);
}
.hint {
position: absolute;
right: 24px;
top: 88px;
padding: 9px 12px;
border-radius: 11px;
color: #78857e;
font-size: 10px;
font-weight: 700;
background: rgba(250, 247, 239, 0.72);
}
.mobile-note {
display: none;
}
@media (max-width: 820px) {
header {
top: 12px;
left: 12px;
right: 12px;
}
.title-block {
max-width: calc(100vw - 125px);
padding: 12px 14px;
}
.subtitle {
display: none;
}
.toolbar {
flex-direction: column;
}
.tool-button {
min-height: 36px;
padding: 0 12px;
font-size: 10px;
}
.options {
left: 12px;
top: auto;
bottom: 98px;
width: calc(100vw - 24px);
transform: none;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
padding: 8px;
}
.section-label,
.option-note {
display: none;
}
.option-card {
display: flex;
flex-direction: column;
gap: 5px;
margin: 0;
padding: 9px 5px;
text-align: center;
}
.option-name {
font-size: 10px;
}
.count {
width: 19px;
height: 19px;
font-size: 9px;
}
.swatch {
width: 29px;
height: 29px;
border-radius: 9px;
}
.status {
right: 12px;
bottom: 12px;
width: 220px;
padding: 10px 12px;
}
.prompt {
display: none;
}
.hint {
display: none;
}
.mobile-note {
display: block;
}
}
</style>
</head>
<body>
<div class="ui">
<header>
<div class="title-block panel">
<div class="eyebrow">Neighborhood Meeting · Model Review</div>
<h1>Courtyard Commons</h1>
<p class="subtitle">
Neighbors are comparing a shared garden, a seating terrace, and a play area.
Inspect the model, then add your token to the decision board.
</p>
</div>
<div class="toolbar">
<button class="tool-button primary" id="boardButton">View board</button>
<button class="tool-button" id="resetCamera">Reset view</button>
<button class="tool-button" id="replayButton">Replay walk-through</button>
</div>
</header>
<nav class="options panel" aria-label="Courtyard proposals">
<div class="section-label">Choose a proposal</div>
<button class="option-card" data-option="garden">
<span class="swatch garden">G</span>
<span>
<span class="option-name">Garden</span>
<span class="option-note">Shade, planting & habitat</span>
</span>
<span class="count" data-count="garden">0</span>
</button>
<button class="option-card" data-option="seating">
<span class="swatch seating">S</span>
<span>
<span class="option-name">Seating</span>
<span class="option-note">Tables, benches & gathering</span>
</span>
<span class="count" data-count="seating">0</span>
</button>
<button class="option-card" data-option="play">
<span class="swatch play">P</span>
<span>
<span class="option-name">Play area</span>
<span class="option-note">Slides, swings & movement</span>
</span>
<span class="count" data-count="play">0</span>
</button>
</nav>
<div class="hint panel">Drag to orbit · Scroll to zoom · Tap a proposal or board slot</div>
<div class="prompt panel" id="prompt">
<strong>Inspect a proposal.</strong> Select a card, then open the board and choose a colored slot.
</div>
<div class="status panel">
<div class="status-row">
<span class="pulse"></span>
<span id="statusText">Neighbors are inspecting the model</span>
</div>
<p id="statusDetail">Each resident will place one token after reviewing their proposal.</p>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------- Scene ----------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e1d3);
scene.fog = new THREE.Fog(0xe8e1d3, 15, 30);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const defaultTarget = new THREE.Vector3(0, 0.85, 0);
const currentTarget = defaultTarget.clone();
const desiredTarget = defaultTarget.clone();
let desiredRadius = 13.2;
let currentRadius = 15.5;
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
camera.position.set(8.8, 7.2, 10.5);
camera.lookAt(currentTarget);
scene.add(new THREE.HemisphereLight(0xfff8e8, 0x789181, 2.05));
const sun = new THREE.DirectionalLight(0xfff1d3, 3.2);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d9ef, 0.8);
fill.position.set(8, 5, -8);
scene.add(fill);
const colors = {
ground: 0xe5ddcc,
groundEdge: 0xc8bba5,
cream: 0xf3ead7,
path: 0xd8cbb7,
dark: 0x29453c,
green: 0x5f9b72,
greenDark: 0x3d7655,
orange: 0xdf8d55,
orangeDark: 0xa75f38,
blue: 0x668db8,
blueDark: 0x416c96,
wood: 0xa9784f,
woodDark: 0x785039,
white: 0xfffaf0
};
function material(color, roughness = 0.86) {
return new THREE.MeshStandardMaterial({ color, roughness });
}
const materials = {
ground: material(colors.ground),
groundEdge: material(colors.groundEdge),
cream: material(colors.cream),
path: material(colors.path),
dark: material(colors.dark),
green: material(colors.green),
greenDark: material(colors.greenDark),
orange: material(colors.orange),
orangeDark: material(colors.orangeDark),
blue: material(colors.blue),
blueDark: material(colors.blueDark),
wood: material(colors.wood),
woodDark: material(colors.woodDark),
white: material(colors.white)
};
function addMesh(geometry, mat, parent = scene) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(parent, w, h, d, mat, x = 0, y = 0, z = 0) {
const mesh = addMesh(new THREE.BoxGeometry(w, h, d), mat, parent);
mesh.position.set(x, y, z);
return mesh;
}
function cylinder(parent, rt, rb, h, mat, x = 0, y = 0, z = 0, segments = 24) {
const mesh = addMesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat,
parent
);
mesh.position.set(x, y, z);
return mesh;
}
function sphere(parent, radius, mat, x = 0, y = 0, z = 0, segments = 18) {
const mesh = addMesh(
new THREE.SphereGeometry(radius, segments, Math.max(10, segments / 2)),
mat,
parent
);
mesh.position.set(x, y, z);
return mesh;
}
function textSprite(text, color = "#29453c", background = "rgba(255,250,240,0.9)") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 144;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.beginPath();
ctx.roundRect(4, 4, 504, 136, 26);
ctx.fill();
ctx.strokeStyle = "rgba(41,69,60,0.13)";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "800 45px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 73);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(1.35, 0.38, 1);
return sprite;
}
// ---------- Ground and neighborhood context ----------
const platform = addMesh(
new THREE.CylinderGeometry(7.2, 7.45, 0.36, 72),
materials.groundEdge
);
platform.position.y = -0.2;
const ground = addMesh(
new THREE.CylinderGeometry(7.05, 7.05, 0.08, 72),
materials.ground
);
ground.position.y = 0;
const pathRing = addMesh(
new THREE.TorusGeometry(5.7, 0.23, 10, 90),
materials.path
);
pathRing.rotation.x = Math.PI / 2;
pathRing.position.y = 0.08;
// Soft neighborhood buildings behind the courtyard.
function makeHouse(x, z, w, h, d, wallColor, roofColor) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(group, w, h, d, material(wallColor), 0, h / 2, 0);
const roof = addMesh(
new THREE.ConeGeometry(Math.max(w, d) * 0.72, 1.05, 4),
material(roofColor),
group
);
roof.position.y = h + 0.48;
roof.rotation.y = Math.PI / 4;
roof.scale.z = d / w;
box(group, 0.42, 0.85, 0.07, materials.dark, 0, 0.43, d / 2 + 0.04);
box(group, 0.55, 0.48, 0.06, material(0xbad1cf), -w * 0.27, h * 0.62, d / 2 + 0.04);
box(group, 0.55, 0.48, 0.06, material(0xbad1cf), w * 0.27, h * 0.62, d / 2 + 0.04);
}
makeHouse(-5.6, -5.1, 1.7, 2.3, 1.5, 0xd4b49a, 0x916e5a);
makeHouse(-3.25, -6.15, 2.1, 2.8, 1.6, 0xc7c5ae, 0x6e8176);
makeHouse(0, -6.45, 2.4, 3.0, 1.8, 0xe0c9aa, 0xa56d57);
makeHouse(3.45, -6.0, 2.0, 2.55, 1.7, 0xb8c8c0, 0x667d74);
makeHouse(5.8, -4.8, 1.6, 2.15, 1.4, 0xd7b99e, 0x8b6f5e);
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(group, 0.09, 0.13, 1.1, materials.woodDark, 0, 0.55, 0, 10);
sphere(group, 0.58, materials.green, 0, 1.32, 0);
sphere(group, 0.38, materials.greenDark, -0.28, 1.18, 0.12);
sphere(group, 0.34, material(0x7eae83), 0.3, 1.25, -0.08);
}
makeTree(-5.8, 1.8, 1.12);
makeTree(-5.4, -1.5, 0.95);
makeTree(5.8, 0.3, 1.05);
makeTree(5.25, -2.65, 0.82);
makeTree(-1.8, -5.35, 0.76);
makeTree(2.1, -5.3, 0.8);
// Benches around the community platform.
function makeBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
box(group, 1.65, 0.12, 0.48, materials.wood, 0, 0.48, 0);
box(group, 1.65, 0.42, 0.1, materials.wood, 0, 0.75, -0.21);
box(group, 0.12, 0.45, 0.38, materials.dark, -0.62, 0.22, 0);
box(group, 0.12, 0.45, 0.38, materials.dark, 0.62, 0.22, 0);
}
makeBench(-4.2, 3.65, 0.1);
makeBench(2.15, 4.75, -0.2);
// ---------- Central courtyard model ----------
const model = new THREE.Group();
model.position.set(-0.65, 0, -0.4);
scene.add(model);
const modelBase = addMesh(
new THREE.CylinderGeometry(3.18, 3.28, 0.24, 64),
materials.cream,
model
);
modelBase.position.y = 0.12;
const modelTop = addMesh(
new THREE.CylinderGeometry(3.03, 3.03, 0.06, 64),
material(0xe6ddca),
model
);
modelTop.position.y = 0.27;
// Crossing paths inside the model.
box(model, 5.6, 0.045, 0.48, materials.path, 0, 0.32, 0);
box(model, 0.48, 0.047, 5.55, materials.path, 0, 0.325, 0);
const optionGroups = {};
const optionCenters = {};
const pickables = [];
function registerOptionPickables(group, option) {
group.traverse((child) => {
if (child.isMesh) {
child.userData.option = option;
pickables.push(child);
}
});
}
// Garden proposal.
const garden = new THREE.Group();
garden.position.set(-1.68, 0, -0.12);
model.add(garden);
optionGroups.garden = garden;
box(garden, 1.48, 0.1, 1.55, material(0x7f9f6d), 0, 0.37, 0);
box(garden, 1.62, 0.12, 0.09, materials.woodDark, 0, 0.4, 0.82);
box(garden, 1.62, 0.12, 0.09, materials.woodDark, 0, 0.4, -0.82);
box(garden, 0.09, 0.12, 1.62, materials.woodDark, 0.78, 0.4, 0);
box(garden, 0.09, 0.12, 1.62, materials.woodDark, -0.78, 0.4, 0);
function miniatureTree(parent, x, z, s = 1) {
const group = new THREE.Group();
group.position.set(x, 0.39, z);
group.scale.setScalar(s);
parent.add(group);
cylinder(group, 0.045, 0.065, 0.42, materials.woodDark, 0, 0.21, 0, 8);
sphere(group, 0.29, materials.green, 0, 0.55, 0, 12);
sphere(group, 0.19, materials.greenDark, -0.13, 0.47, 0.06, 10);
}
miniatureTree(garden, -0.38, -0.28, 1.0);
miniatureTree(garden, 0.36, -0.36, 0.82);
miniatureTree(garden, 0.42, 0.38, 0.68);
const bed = box(garden, 0.64, 0.18, 0.34, materials.wood, -0.25, 0.47, 0.48);
for (let i = 0; i < 5; i++) {
const flower = sphere(
garden,
0.055,
material(i % 2 ? colors.orange : colors.white),
-0.48 + i * 0.115,
0.61,
0.48,
8
);
flower.scale.y = 1.3;
}
// Seating proposal.
const seating = new THREE.Group();
seating.position.set(0, 0, 0.12);
model.add(seating);
optionGroups.seating = seating;
const deck = addMesh(
new THREE.CylinderGeometry(0.78, 0.78, 0.1, 36),
material(0xcfa77c),
seating
);
deck.position.y = 0.38;
box(seating, 1.15, 0.12, 0.35, materials.wood, 0, 0.72, -0.42);
box(seating, 1.15, 0.34, 0.09, materials.wood, 0, 0.91, -0.56);
box(seating, 0.1, 0.34, 0.3, materials.dark, -0.46, 0.53, -0.42);
box(seating, 0.1, 0.34, 0.3, materials.dark, 0.46, 0.53, -0.42);
cylinder(seating, 0.29, 0.29, 0.09, materials.cream, 0.12, 0.69, 0.15, 24);
cylinder(seating, 0.065, 0.09, 0.32, materials.dark, 0.12, 0.53, 0.15, 12);
cylinder(seating, 0.18, 0.22, 0.08, materials.dark, 0.12, 0.36, 0.15, 18);
// Play proposal.
const play = new THREE.Group();
play.position.set(1.68, 0, -0.12);
model.add(play);
optionGroups.play = play;
box(play, 1.55, 0.1, 1.55, material(0x91acc5), 0, 0.37, 0);
// Slide.
box(play, 0.62, 0.12, 0.66, materials.blue, -0.35, 0.86, -0.28);
box(play, 0.08, 0.65, 0.08, materials.blueDark, -0.63, 0.63, -0.52);
box(play, 0.08, 0.65, 0.08, materials.blueDark, -0.07, 0.63, -0.52);
const slideRamp = box(
play,
0.5,
0.07,
1.1,
material(0xe2b85e),
-0.35,
0.61,
0.14
);
slideRamp.rotation.x = -0.54;
// Swing frame.
box(play, 0.08, 1.05, 0.08, materials.dark, 0.38, 0.89, -0.35);
box(play, 0.08, 1.05, 0.08, materials.dark, 0.78, 0.89, -0.35);
box(play, 0.48, 0.08, 0.08, materials.dark, 0.58, 1.38, -0.35);
box(play, 0.035, 0.55, 0.035, materials.cream, 0.48, 1.08, -0.35);
box(play, 0.035, 0.55, 0.035, materials.cream, 0.68, 1.08, -0.35);
box(play, 0.3, 0.07, 0.16, materials.orange, 0.58, 0.8, -0.35);
// Small block forms.
box(play, 0.24, 0.24, 0.24, materials.orange, 0.2, 0.53, 0.42);
box(play, 0.18, 0.18, 0.18, materials.green, 0.5, 0.5, 0.48);
registerOptionPickables(garden, "garden");
registerOptionPickables(seating, "seating");
registerOptionPickables(play, "play");
const gardenLabel = textSprite("GARDEN");
gardenLabel.position.set(0, 1.22, 0);
garden.add(gardenLabel);
const seatingLabel = textSprite("SEATING");
seatingLabel.position.set(0, 1.2, 0);
seating.add(seatingLabel);
const playLabel = textSprite("PLAY AREA");
playLabel.position.set(0, 1.62, 0);
play.add(playLabel);
const modelLabel = textSprite("COURTYARD MODEL", "#53645c", "rgba(248,244,233,0.92)");
modelLabel.position.set(-0.65, 0.68, 3.08);
modelLabel.scale.set(1.6, 0.45, 1);
scene.add(modelLabel);
// ---------- Shared decision board ----------
const board = new THREE.Group();
board.position.set(4.1, 0, 2.35);
board.rotation.y = -0.23;
scene.add(board);
box(board, 3.72, 2.28, 0.18, materials.woodDark, 0, 1.76, 0);
box(board, 0.17, 1.65, 0.17, materials.dark, -1.38, 0.8, 0);
box(board, 0.17, 1.65, 0.17, materials.dark, 1.38, 0.8, 0);
box(board, 2.9, 0.1, 0.35, materials.dark, 0, 0.08, 0);
function makeBoardTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 640;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f6f0df";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "#29453c";
ctx.fillRect(0, 0, canvas.width, 112);
ctx.fillStyle = "#fffaf0";
ctx.font = "800 52px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.fillText("SHARED DECISION", 512, 72);
const columns = [
{ x: 170, label: "GARDEN", color: "#5f9b72" },
{ x: 512, label: "SEATING", color: "#df8d55" },
{ x: 854, label: "PLAY", color: "#668db8" }
];
for (const col of columns) {
ctx.fillStyle = col.color;
ctx.beginPath();
ctx.arc(col.x, 220, 52, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#29453c";
ctx.font = "800 31px system-ui, sans-serif";
ctx.fillText(col.label, col.x, 318);
ctx.strokeStyle = "rgba(41,69,60,0.13)";
ctx.lineWidth = 4;
ctx.strokeRect(col.x - 122, 349, 244, 190);
}
ctx.fillStyle = "#748078";
ctx.font = "600 22px system-ui, sans-serif";
ctx.fillText("PLACE YOUR TOKEN BELOW THE PROPOSAL YOU SUPPORT", 512, 590);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const boardFace = addMesh(
new THREE.PlaneGeometry(3.5, 2.08),
new THREE.MeshStandardMaterial({
map: makeBoardTexture(),
roughness: 0.9
}),
board
);
boardFace.position.set(0, 1.76, 0.101);
boardFace.castShadow = false;
const slotOptions = ["garden", "seating", "play"];
const slotXs = [-1.13, 0, 1.13];
const socketMeshes = [];
const tokenMeshes = [];
function makeToken(color) {
const group = new THREE.Group();
const token = addMesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.055, 24),
material(color, 0.55),
group
);
token.rotation.x = Math.PI / 2;
const inset = addMesh(
new THREE.CylinderGeometry(0.073, 0.073, 0.058, 20),
material(colors.white, 0.72),
group
);
inset.rotation.x = Math.PI / 2;
inset.position.z = 0.002;
board.add(group);
group.visible = false;
return group;
}
slotOptions.forEach((option, i) => {
const socket = addMesh(
new THREE.CylinderGeometry(0.18, 0.18, 0.055, 28),
material(0x384d45, 0.72),
board
);
socket.rotation.x = Math.PI / 2;
socket.position.set(slotXs[i], 0.08, 0.14);
socket.userData.slot = option;
socketMeshes.push(socket);
pickables.push(socket);
});
const residentTokens = [
makeToken(colors.green),
makeToken(colors.orange),
makeToken(colors.blue)
];
let userToken = null;
function positionToken(token, option, index) {
const i = slotOptions.indexOf(option);
token.position.set(
slotXs[i] + (index % 2 ? 0.035 : -0.035),
0.08 + (index > 1 ? 0.09 : 0),
0.24 + index * 0.035
);
}
// ---------- Stylized neighbors ----------
function makePerson(shirtColor, skinColor, hairColor) {
const group = new THREE.Group();
const shirt = material(shirtColor);
const skin = material(skinColor);
const hair = material(hairColor);
const trousers = material(0x3c4f4b);
cylinder(group, 0.17, 0.23, 0.55, shirt, 0, 0.78, 0, 12);
sphere(group, 0.18, skin, 0, 1.23, 0, 14);
const hairCap = sphere(group, 0.182, hair, 0, 1.32, -0.025, 14);
hairCap.scale.set(1, 0.55, 1);
sphere(group, 0.035, skin, 0, 1.21, 0.165, 8);
const leftArm = cylinder(group, 0.055, 0.065, 0.48, shirt, -0.25, 0.76, 0, 10);
const rightArm = cylinder(group, 0.055, 0.065, 0.48, shirt, 0.25, 0.76, 0, 10);
leftArm.rotation.z = -0.13;
rightArm.rotation.z = 0.13;
cylinder(group, 0.065, 0.075, 0.46, trousers, -0.105, 0.25, 0, 10);
cylinder(group, 0.065, 0.075, 0.46, trousers, 0.105, 0.25, 0, 10);
box(group, 0.14, 0.09, 0.25, materials.dark, -0.105, 0.06, 0.055);
box(group, 0.14, 0.09, 0.25, materials.dark, 0.105, 0.06, 0.055);
scene.add(group);
return group;
}
board.updateMatrixWorld(true);
const gardenStand = model.localToWorld(new THREE.Vector3(-1.68, 0.3, 1.25));
const seatingStand = model.localToWorld(new THREE.Vector3(0, 0.3, 1.45));
const playStand = model.localToWorld(new THREE.Vector3(1.68, 0.3, 1.2));
const boardStands = slotXs.map((x) =>
board.localToWorld(new THREE.Vector3(x, 0, 1.34))
);
const residents = [
{
name: "Maya",
option: "garden",
inspect: gardenStand,
inspectTarget: model.localToWorld(new THREE.Vector3(-1.68, 0.5, -0.12)),
stand: boardStands[0],
root: makePerson(0x5f9b72, 0x8b563b, 0x28231f)
},
{
name: "Jonah",
option: "seating",
inspect: seatingStand,
inspectTarget: model.localToWorld(new THREE.Vector3(0, 0.5, 0.12)),
stand: boardStands[1],
root: makePerson(0xdf8d55, 0xe0aa7e, 0x7b4a2c)
},
{
name: "Leila",
option: "play",
inspect: playStand,
inspectTarget: model.localToWorld(new THREE.Vector3(1.68, 0.5, -0.12)),
stand: boardStands[2],
root: makePerson(0x668db8, 0xb97853, 0x352a27)
}
];
function angleTo(from, to) {
return Math.atan2(to.x - from.x, to.z - from.z);
}
function shortestAngle(current, target) {
let delta = (target - current + Math.PI) % (Math.PI * 2) - Math.PI;
if (delta < -Math.PI) delta += Math.PI * 2;
return current + delta;
}
function smoothstep(t) {
t = THREE.MathUtils.clamp(t, 0, 1);
return t * t * (3 - 2 * t);
}
let walkTime = 0;
let selectedOption = null;
function resetResidentTokens() {
walkTime = 0;
residentTokens.forEach((token) => {
token.visible = false;
});
}
function updateResidents(dt) {
walkTime += dt;
residents.forEach((resident, i) => {
const root = resident.root;
const inspectEnd = 4 + i * 0.72;
const walkEnd = 6.15 + i * 0.72;
const placeTime = 7.15 + i * 0.72;
let targetPosition;
let targetRotation;
if (walkTime < inspectEnd) {
targetPosition = resident.inspect.clone();
targetRotation = angleTo(targetPosition, resident.inspectTarget);
targetPosition.y += Math.sin(walkTime * 1.8 + i) * 0.012;
} else if (walkTime < walkEnd) {
const t = smoothstep((walkTime - inspectEnd) / (walkEnd - inspectEnd));
targetPosition = resident.inspect.clone().lerp(resident.stand, t);
targetRotation = angleTo(resident.inspect, resident.stand);
targetPosition.y += Math.abs(Math.sin(t * Math.PI * 5)) * 0.055;
} else {
targetPosition = resident.stand.clone();
targetRotation = angleTo(resident.stand, board.position);
targetPosition.y += Math.sin(walkTime * 1.7 + i) * 0.008;
}
root.position.lerp(targetPosition, 1 - Math.exp(-dt * 7));
root.rotation.y = shortestAngle(root.rotation.y, targetRotation);
const token = residentTokens[i];
if (walkTime >= placeTime) {
if (!token.visible) {
positionToken(token, resident.option, 0);
token.visible = true;
}
}
});
}
// ---------- Voting and UI ----------
const cards = [...document.querySelectorAll(".option-card")];
const prompt = document.getElementById("prompt");
const statusText = document.getElementById("statusText");
const statusDetail = document.getElementById("statusDetail");
function residentVoteCount(option) {
return residents.filter((resident, i) => {
return resident.option === option && walkTime >= 7.15 + i * 0.72;
}).length;
}
function updateCounts() {
slotOptions.forEach((option) => {
const total = residentVoteCount(option) + (userToken?.userData.option === option ? 1 : 0);
document.querySelector(`[data-count="${option}"]`).textContent = total;
});
}
function selectOption(option) {
selectedOption = option;
cards.forEach((card) => {
card.classList.toggle("selected", card.dataset.option === option);
});
const center = optionGroups[option].getWorldPosition(new THREE.Vector3());
desiredTarget.set(center.x, 0.85, center.z);
desiredRadius = 8.4;
prompt.innerHTML = `<strong>${option[0].toUpperCase() + option.slice(1)} selected.</strong> Inspect the model, then choose “View board” and tap its colored slot.`;
}
cards.forEach((card) => {
card.addEventListener("click", () => selectOption(card.dataset.option));
});
function focusBoard() {
const center = board.getWorldPosition(new THREE.Vector3());
desiredTarget.set(center.x, 1.45, center.z);
desiredRadius = 7.1;
prompt.innerHTML = `<strong>Decision board.</strong> Tap a colored socket to place your token${
userToken ? "." : " — you have not voted yet."
}`;
}
document.getElementById("boardButton").addEventListener("click", focusBoard);
document.getElementById("resetCamera").addEventListener("click", () => {
desiredTarget.copy(defaultTarget);
desiredRadius = 13.2;
});
document.getElementById("replayButton").addEventListener("click", () => {
resetResidentTokens();
residents.forEach((resident) => {
resident.root.position.copy(resident.inspect);
});
statusText.textContent = "Neighbors are inspecting the model";
statusDetail.textContent = "The walk-through has restarted from the proposal review.";
});
function placeUserToken(option) {
if (userToken) {
board.remove(userToken);
}
userToken = makeToken(colors.dark);
userToken.userData.option = option;
userToken.visible = true;
const count = residentVoteCount(option);
positionToken(userToken, option, count);
prompt.innerHTML = `<strong>Your token is on the ${option} proposal.</strong> The neighbors' tokens show the choices they support.`;
statusText.textContent = "Your vote has been recorded";
statusDetail.textContent = "All voices are now represented on the shared board.";
updateCounts();
}
// ---------- Custom camera controls ----------
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let dragging = false;
let pointerMoved = false;
let activePointer = null;
let previousX = 0;
let previousY = 0;
const pointers = new Map();
let pinchDistance = 0;
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
activePointer = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
dragging = true;
pointerMoved = false;
renderer.domElement.setPointerCapture(event.pointerId);
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * (pinchDistance / Math.max(distance, 1)),
5.7,
19
);
}
pinchDistance = distance;
pointerMoved = true;
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (Math.abs(dx) + Math.abs(dy) > 3) pointerMoved = true;
if (dragging && pointerMoved) {
const offset = camera.position.clone().sub(currentTarget);
spherical.setFromVector3(offset);
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(spherical.phi - dy * 0.005, 0.48, 1.36);
offset.setFromSpherical(spherical);
camera.position.copy(currentTarget).add(offset);
currentRadius = offset.length();
desiredRadius = currentRadius;
desiredTarget.copy(currentTarget);
}
previousX = event.clientX;
previousY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
if (!pointerMoved && activePointer === event.pointerId) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (hits.length) {
const hit = hits[0].object;
if (hit.userData.slot) {
placeUserToken(hit.userData.slot);
} else if (hit.userData.option) {
selectOption(hit.userData.option);
}
}
}
if (pointers.size === 0) dragging = false;
activePointer = null;
});
renderer.domElement.addEventListener("pointercancel", (event) => {
pointers.delete(event.pointerId);
dragging = false;
activePointer = null;
pinchDistance = 0;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * Math.exp(event.deltaY * 0.001),
5.7,
19
);
},
{ passive: false }
);
// ---------- Animation ----------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
updateResidents(dt);
currentTarget.lerp(desiredTarget, 1 - Math.exp(-dt * 4.2));
currentRadius = THREE.MathUtils.lerp(
currentRadius,
desiredRadius,
1 - Math.exp(-dt * 5.5)
);
const offset = camera.position.clone().sub(currentTarget);
spherical.setFromVector3(offset);
spherical.radius = currentRadius;
offset.setFromSpherical(spherical);
camera.position.copy(currentTarget).add(offset);
camera.lookAt(currentTarget);
if (walkTime < 4.2) {
statusText.textContent = "Neighbors are inspecting the model";
statusDetail.textContent = "Each resident is reviewing the details before voting.";
} else if (walkTime < 7.15) {
statusText.textContent = "Residents are heading to the board";
statusDetail.textContent = "Inspection is complete; their tokens are about to be placed.";
} else if (walkTime < 9.4) {
statusText.textContent = "Resident votes are being recorded";
statusDetail.textContent = "Each proposal now has a token from a neighbor.";
} else if (!userToken) {
statusText.textContent = "Your turn to place a token";
statusDetail.textContent = "Open the decision board and select a proposal.";
}
updateCounts();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
</script>
</body>
</html>
```