Prompt specification
Build or customize the Three.js 3D scene "Announcement board and speaker pair" 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: Announcement board and speaker pair
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/announcement-board-and-speaker-pair-x0409
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring captioned public announcements. Build a small public information panel beside a speaker, showing the same simple event through a pictogram and text; keep both outputs visible together. Voxel style.
Working Three.js Starter (announcement-board-and-speaker-pair-x0409):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Riverside Public Notice</title>
<style>
:root {
--ink: #172538;
--ink-dark: #0d1520;
--paper: #fff6dc;
--paper-dark: #e8d9b5;
--yellow: #f4bd42;
--teal: #2f8f87;
--blue: #326c8d;
--white: #fffdf7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b7d9df;
color: var(--ink);
font-family: "Courier New", Courier, monospace;
}
button {
font: inherit;
}
#scene-wrap {
position: fixed;
inset: 0;
}
#scene-wrap canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
outline: none;
touch-action: none;
}
#scene-wrap canvas:active {
cursor: grabbing;
}
.brand {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
padding: 13px 16px 12px;
background: var(--ink);
color: var(--white);
border: 3px solid var(--ink-dark);
box-shadow: 6px 6px 0 var(--yellow);
pointer-events: none;
}
.brand-kicker {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 4px;
color: var(--yellow);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live-dot {
width: 9px;
height: 9px;
background: var(--yellow);
box-shadow: 0 0 0 3px rgba(244, 189, 66, 0.18);
}
.brand h1 {
margin: 0;
font-size: clamp(17px, 2vw, 24px);
line-height: 1.05;
letter-spacing: -0.04em;
text-transform: uppercase;
}
.brand p {
margin: 7px 0 0;
color: #cfdae2;
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#controls {
position: fixed;
z-index: 20;
top: 20px;
right: 20px;
width: 330px;
padding: 13px;
background: var(--paper);
border: 3px solid var(--ink-dark);
box-shadow: 6px 6px 0 var(--ink);
}
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.control-heading strong {
font-size: 12px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#reset-view {
padding: 5px 7px;
color: var(--ink);
background: transparent;
border: 2px solid var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 700;
text-transform: uppercase;
}
#reset-view:hover,
#reset-view:focus-visible {
color: var(--white);
background: var(--ink);
outline: none;
}
#event-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-bottom: 10px;
}
.event-button {
min-width: 0;
padding: 9px 5px;
overflow: hidden;
color: var(--ink);
background: var(--paper-dark);
border: 2px solid var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
}
.event-button:hover,
.event-button:focus-visible {
outline: 3px solid var(--yellow);
outline-offset: 1px;
}
.event-button[aria-pressed="true"] {
color: var(--white);
background: var(--teal);
}
#announce {
display: flex;
width: 100%;
min-height: 46px;
align-items: center;
justify-content: center;
gap: 10px;
padding: 10px;
color: var(--ink-dark);
background: var(--yellow);
border: 3px solid var(--ink-dark);
box-shadow: 4px 4px 0 var(--ink);
cursor: pointer;
font-weight: 700;
text-transform: uppercase;
}
#announce:hover,
#announce:focus-visible {
background: #ffd46e;
outline: 3px solid var(--white);
outline-offset: 2px;
}
#announce:active,
#announce.is-speaking {
transform: translate(2px, 2px);
box-shadow: 2px 2px 0 var(--ink);
}
.speaker-icon {
position: relative;
display: inline-block;
width: 18px;
height: 22px;
background: currentColor;
clip-path: polygon(
30% 0, 70% 0, 70% 42%, 100% 42%, 100% 66%,
70% 66%, 70% 100%, 30% 100%, 30% 66%, 0 66%,
0 42%, 30% 42%
);
}
#status {
margin: 11px 2px 0;
color: #526170;
font-size: 10px;
line-height: 1.4;
}
#caption {
position: fixed;
z-index: 30;
left: 50%;
bottom: 22px;
display: grid;
width: min(780px, calc(100% - 32px));
min-height: 98px;
grid-template-columns: 118px 1fr;
overflow: hidden;
transform: translateX(-50%);
background: var(--ink);
border: 3px solid var(--ink-dark);
box-shadow: 8px 8px 0 var(--yellow);
color: var(--white);
pointer-events: none;
}
.caption-label {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
padding: 12px;
color: var(--ink-dark);
background: var(--yellow);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.09em;
text-align: center;
text-transform: uppercase;
}
.caption-bars {
display: flex;
height: 24px;
align-items: center;
gap: 4px;
}
.caption-bars i {
display: block;
width: 4px;
height: 10px;
background: var(--ink-dark);
}
.caption-bars i:nth-child(2) {
height: 22px;
}
.caption-bars i:nth-child(3) {
height: 16px;
}
.caption-bars i:nth-child(4) {
height: 7px;
}
#caption-text {
align-self: center;
margin: 0;
padding: 17px 20px;
font-size: clamp(15px, 2.1vw, 21px);
font-weight: 700;
line-height: 1.35;
}
#caption-text.is-speaking::after {
display: inline-block;
width: 9px;
height: 9px;
margin-left: 7px;
background: var(--yellow);
content: "";
animation: blink 0.7s steps(1) infinite;
vertical-align: 2px;
}
.scene-help {
position: fixed;
z-index: 5;
right: 20px;
bottom: 24px;
padding: 8px 10px;
color: var(--ink);
background: rgba(255, 246, 220, 0.88);
border: 2px solid var(--ink);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #b7d9df;
color: var(--ink);
font-size: 14px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.sr-only {
position: absolute !important;
width: 1px !important;
height: 1px !important;
padding: 0 !important;
overflow: hidden !important;
clip: rect(0, 0, 0, 0) !important;
white-space: nowrap !important;
border: 0 !important;
}
@keyframes blink {
50% {
opacity: 0;
}
}
@media (max-width: 760px) {
.brand {
top: 12px;
left: 12px;
padding: 10px 12px;
box-shadow: 4px 4px 0 var(--yellow);
}
.brand p {
display: none;
}
#controls {
top: auto;
right: 12px;
bottom: 146px;
width: min(330px, calc(100% - 24px));
padding: 10px;
}
.control-heading {
margin-bottom: 7px;
}
#event-tabs {
margin-bottom: 8px;
}
#status {
display: none;
}
#caption {
bottom: 12px;
min-height: 116px;
grid-template-columns: 74px 1fr;
box-shadow: 5px 5px 0 var(--yellow);
}
.caption-label {
padding: 8px 5px;
font-size: 9px;
}
#caption-text {
padding: 14px;
font-size: 16px;
}
.scene-help {
display: none;
}
}
@media (max-width: 430px) {
.brand h1 {
max-width: 185px;
font-size: 16px;
}
.brand-kicker {
font-size: 9px;
}
#caption {
grid-template-columns: 60px 1fr;
}
.caption-label {
font-size: 8px;
}
.caption-bars {
transform: scale(0.8);
}
}
@media (prefers-reduced-motion: reduce) {
#caption-text.is-speaking::after {
animation: none;
}
}
</style>
</head>
<body>
<main id="scene-wrap" aria-label="Interactive voxel public announcement plaza"></main>
<header class="brand" aria-label="Scene title">
<div class="brand-kicker">
<span class="live-dot"></span>
Civic information system
</div>
<h1>Riverside Plaza</h1>
<p>Visual notice · live caption · spoken announcement</p>
</header>
<section id="controls" aria-label="Announcement controls">
<div class="control-heading">
<strong>Announcement queue</strong>
<button id="reset-view" type="button">Reset view</button>
</div>
<nav id="event-tabs" aria-label="Choose an announcement"></nav>
<button id="announce" type="button">
<span class="speaker-icon" aria-hidden="true"></span>
<span id="announce-label">Announce message</span>
</button>
<p id="status">Ready · the panel and caption show the same event.</p>
</section>
<aside id="caption" aria-label="Live visual caption">
<div class="caption-label">
<span class="caption-bars" aria-hidden="true">
<i></i><i></i><i></i><i></i>
</span>
<span id="caption-label">Live caption</span>
</div>
<p id="caption-text"></p>
</aside>
<div class="scene-help">Drag to orbit · scroll to zoom · arrows to look</div>
<p id="announcer" class="sr-only" aria-live="polite" aria-atomic="true"></p>
<div id="loading">Building the plaza…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneWrap = document.getElementById("scene-wrap");
const loading = document.getElementById("loading");
const events = [
{
id: "cleanup",
tab: "Clean-up",
titleLines: ["RIVERSIDE", "CLEAN-UP"],
dateNumber: "24",
month: "AUG",
time: "SAT · 10:00 AM",
where: "SOUTH GATE · RIVERSIDE PARK",
note: "BAGS PROVIDED · BRING WATER",
symbol: "leaf",
spoken:
"Attention please. The Riverside clean-up begins Saturday at ten in the morning. Meet at the south gate of Riverside Park."
},
{
id: "market",
tab: "Market",
titleLines: ["FRIDAY", "NIGHT MARKET"],
dateNumber: "07",
month: "SEP",
time: "FRI · 6:00 PM",
where: "EAST SQUARE · RIVERSIDE PLAZA",
note: "LOCAL FOOD · LIVE MUSIC · FREE ENTRY",
symbol: "market",
spoken:
"Attention please. The Friday night market begins at six in the evening in East Square. Local food, live music, and free entry."
},
{
id: "repair",
tab: "Repair",
titleLines: ["FREE REPAIR", "WORKSHOP"],
dateNumber: "12",
month: "SEP",
time: "TUE · 4:30 PM",
where: "CIVIC HALL · COMMUNITY ROOM",
note: "BRING ONE ITEM · LIMITED PLACES",
symbol: "tool",
spoken:
"Attention please. The free repair workshop is on Tuesday at four thirty in the afternoon in the Civic Hall community room. Please bring one item."
}
];
const captionText = document.getElementById("caption-text");
const captionLabel = document.getElementById("caption-label");
const announcer = document.getElementById("announcer");
const announceButton = document.getElementById("announce");
const announceLabel = document.getElementById("announce-label");
const status = document.getElementById("status");
const eventTabs = document.getElementById("event-tabs");
let currentEvent = events[0];
let speaking = false;
let captionFrame = 0;
let fallbackTimer = 0;
// ------------------------------------------------------------------
// Renderer, camera, and lighting
// ------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Voxel plaza. Drag to orbit, scroll to zoom, or use the arrow keys."
);
sceneWrap.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xb7d9df);
scene.fog = new THREE.Fog(0xb7d9df, 24, 48);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
yaw: 0.38,
pitch: 0.48,
zoom: 1,
target: new THREE.Vector3(-0.65, 1.55, 0)
};
const hemisphere = new THREE.HemisphereLight(0xeaf8ff, 0x607d68, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0ca, 3.1);
sun.position.set(8, 13, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x91c9ff, 0.8);
fill.position.set(-9, 7, 4);
scene.add(fill);
// ------------------------------------------------------------------
// Voxel construction helpers
// ------------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const edgeGeometry = new THREE.EdgesGeometry(cubeGeometry);
const materialCache = new Map();
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x172538,
transparent: true,
opacity: 0.72
});
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0,
flatShading: true
})
);
}
return materialCache.get(color);
}
function voxel(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(cubeGeometry, material(color));
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotation) {
mesh.rotation.set(
options.rotation[0] || 0,
options.rotation[1] || 0,
options.rotation[2] || 0
);
}
if (options.outline) {
mesh.add(new THREE.LineSegments(edgeGeometry, edgeMaterial));
}
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------------
// Plaza environment
// ------------------------------------------------------------------
voxel(scene, [24, 0.65, 18], [0, -0.38, 0], 0x83b9a9);
voxel(scene, [11.5, 0.3, 7.4], [-0.65, 0.02, 0.1], 0xe4d6b5);
voxel(scene, [7.1, 0.18, 4.1], [-3.1, 0.24, 0.2], 0xf3e8cd);
// Tiled plaza lines.
for (let x = -5.5; x <= 5.5; x += 1.1) {
voxel(
scene,
[0.035, 0.015, 7.1],
[x, 0.19, 0.1],
0xc8b995,
{ castShadow: false }
);
}
for (let z = -3.2; z <= 3.2; z += 1.1) {
voxel(
scene,
[11.2, 0.015, 0.035],
[-0.65, 0.19, z],
0xc8b995,
{ castShadow: false }
);
}
// Yellow tactile squares leading toward the speaker.
for (let i = 0; i < 7; i++) {
voxel(
scene,
[0.32, 0.035, 0.32],
[-5.6 + i * 0.48, 0.2, 2.05],
0xf4bd42,
{ castShadow: false }
);
}
// Civic building in the background.
voxel(scene, [12.4, 3.5, 1.6], [0.2, 1.72, -7.45], 0xf2e6c8, {
outline: true
});
voxel(scene, [12.9, 0.38, 1.95], [0.2, 3.65, -7.45], 0x376b78, {
outline: true
});
voxel(scene, [2.25, 2.45, 0.24], [0.2, 1.2, -6.55], 0x24485c, {
outline: true
});
for (const x of [-3.8, -2.4, 2.8, 4.2]) {
voxel(scene, [0.92, 1.15, 0.18], [x, 2.05, -6.54], 0x84c3d1, {
outline: true
});
voxel(scene, [0.08, 1.16, 0.08], [x, 2.05, -6.42], 0xead9b4, {
castShadow: false
});
}
// Civic hall sign.
voxel(scene, [3.8, 0.55, 0.16], [0.2, 3.1, -6.51], 0x172538);
voxel(scene, [3.3, 0.09, 0.08], [0.2, 3.1, -6.4], 0xf4bd42, {
castShadow: false
});
function makeTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
voxel(tree, [0.48, 2.5, 0.48], [0, 1.1, 0], 0x785a3c, {
outline: true
});
voxel(tree, [2.1, 1.15, 1.8], [0, 2.6, 0], 0x3e8a62, {
outline: true
});
voxel(tree, [1.45, 1.05, 1.45], [-0.55, 3.3, 0.1], 0x55a96e, {
outline: true
});
voxel(tree, [1.35, 1.05, 1.35], [0.65, 3.25, -0.15], 0x4b9b68, {
outline: true
});
voxel(tree, [0.85, 0.8, 0.85], [0.1, 4.02, 0.05], 0x69b777, {
outline: true
});
voxel(tree, [2.1, 0.45, 2.1], [0, 0.05, 0], 0x6e9781);
}
makeTree(-8.3, -4.6, 1.15);
makeTree(8.2, -4.3, 1.05);
makeTree(8.6, 3.7, 0.9);
makeTree(-8.7, 3.2, 0.82);
// Bench on the right.
voxel(scene, [2.8, 0.25, 0.8], [6.4, 0.85, -0.8], 0x9a6945, {
outline: true
});
voxel(scene, [2.8, 0.85, 0.2], [6.4, 1.25, -1.1], 0x9a6945, {
outline: true
});
voxel(scene, [0.28, 0.8, 0.65], [5.25, 0.45, -0.8], 0x314657);
voxel(scene, [0.28, 0.8, 0.65], [7.55, 0.45, -0.8], 0x314657);
// Streetlamp.
voxel(scene, [0.22, 5.1, 0.22], [-7.0, 2.45, -0.8], 0x334b5d);
voxel(scene, [1.05, 0.2, 0.75], [-7.0, 4.92, -0.8], 0x334b5d);
voxel(scene, [0.65, 0.16, 0.5], [-7.0, 4.77, -0.8], 0xffe49a);
// ------------------------------------------------------------------
// Speaker and podium
// ------------------------------------------------------------------
const speaker = new THREE.Group();
speaker.position.set(-3.25, 0.3, 0.2);
scene.add(speaker);
// Legs and shoes.
voxel(speaker, [0.42, 0.9, 0.42], [-0.23, 0.52, -0.22], 0x263b50, {
outline: true
});
voxel(speaker, [0.42, 0.9, 0.42], [0.23, 0.52, -0.22], 0x263b50, {
outline: true
});
voxel(speaker, [0.5, 0.2, 0.66], [-0.23, 0.1, -0.1], 0x172538, {
outline: true
});
voxel(speaker, [0.5, 0.2, 0.66], [0.23, 0.1, -0.1], 0x172538, {
outline: true
});
// Torso and jacket.
voxel(speaker, [1.02, 1.12, 0.6], [0, 1.5, -0.22], 0xe78d42, {
outline: true
});
voxel(speaker, [0.3, 0.96, 0.64], [0, 1.52, -0.17], 0xf5eee0, {
outline: true
});
voxel(speaker, [0.35, 0.32, 0.15], [0, 2.12, -0.1], 0xb76d37);
// Left arm.
const leftArm = voxel(
speaker,
[0.32, 0.95, 0.38],
[-0.66, 1.47, -0.12],
0xe78d42,
{ outline: true, rotation: [0, 0, -0.08] }
);
voxel(speaker, [0.34, 0.3, 0.36], [-0.73, 0.96, -0.08], 0xd69a72);
// Right arm, posed toward the microphone.
const rightArm = voxel(
speaker,
[0.32, 0.9, 0.38],
[0.66, 1.56, -0.05],
0xe78d42,
{ outline: true, rotation: [0, 0, -0.3] }
);
voxel(speaker, [0.34, 0.28, 0.36], [0.78, 1.13, 0.1], 0xd69a72);
// Neck and head.
voxel(speaker, [0.34, 0.28, 0.34], [0, 2.18, -0.22], 0xd69a72);
voxel(speaker, [0.72, 0.72, 0.68], [0, 2.57, -0.22], 0xdba178, {
outline: true
});
// Hair.
voxel(speaker, [0.79, 0.23, 0.73], [0, 2.93, -0.24], 0x3d302c, {
outline: true
});
voxel(speaker, [0.18, 0.45, 0.68], [-0.3, 2.68, -0.26], 0x3d302c);
voxel(speaker, [0.18, 0.45, 0.68], [0.3, 2.68, -0.26], 0x3d302c);
// Eyes and nose.
voxel(speaker, [0.09, 0.1, 0.055], [-0.15, 2.62, 0.135], 0x172538, {
castShadow: false
});
voxel(speaker, [0.09, 0.1, 0.055], [0.15, 2.62, 0.135], 0x172538, {
castShadow: false
});
voxel(speaker, [0.11, 0.12, 0.1], [0, 2.5, 0.16], 0xc88863);
// Animated mouth.
const mouth = voxel(
speaker,
[0.25, 0.09, 0.055],
[0, 2.38, 0.145],
0x6d342f,
{ castShadow: false }
);
// Podium.
voxel(speaker, [2.05, 0.2, 1.25], [0, 0.1, 0.7], 0x263d50, {
outline: true
});
voxel(speaker, [1.14, 1.1, 0.72], [0, 0.68, 0.66], 0xf4bd42, {
outline: true
});
voxel(speaker, [1.82, 0.2, 1.03], [0, 1.3, 0.68], 0x263d50, {
outline: true
});
voxel(speaker, [0.9, 0.22, 0.06], [0, 0.85, 1.04], 0xfff1c6);
// Microphone.
voxel(speaker, [0.08, 1.18, 0.08], [0.54, 1.94, 0.68], 0x263d50);
voxel(speaker, [0.36, 0.17, 0.18], [0.54, 2.48, 0.68], 0x172538, {
outline: true
});
// Small speech indicator blocks.
const pulseMaterials = [];
const pulseBlocks = [];
for (let i = 0; i < 3; i++) {
const pulseMaterial = new THREE.MeshBasicMaterial({
color: 0xf4bd42,
transparent: true,
opacity: 0.25
});
pulseMaterials.push(pulseMaterial);
const pulse = new THREE.Mesh(cubeGeometry, pulseMaterial);
pulse.scale.set(0.13, 0.13, 0.13);
pulse.position.set(0.88 + i * 0.23, 2.65 + i * 0.12, 0.68);
speaker.add(pulse);
pulseBlocks.push(pulse);
}
// ------------------------------------------------------------------
// Public information panel with procedural canvas texture
// ------------------------------------------------------------------
const panelGroup = new THREE.Group();
panelGroup.position.set(1.05, 0.25, 0.05);
scene.add(panelGroup);
voxel(panelGroup, [0.34, 2.75, 0.34], [-1.45, 1.36, 0], 0x2e4a5c, {
outline: true
});
voxel(panelGroup, [0.34, 2.75, 0.34], [1.45, 1.36, 0], 0x2e4a5c, {
outline: true
});
voxel(panelGroup, [3.4, 0.26, 0.65], [0, 0.13, 0], 0x2e4a5c, {
outline: true
});
voxel(panelGroup, [4.55, 3.35, 0.26], [0, 3.52, 0], 0x172538, {
outline: true
});
const panelCanvas = document.createElement("canvas");
panelCanvas.width = 640;
panelCanvas.height = 480;
const panelContext = panelCanvas.getContext("2d");
panelContext.imageSmoothingEnabled = false;
const panelTexture = new THREE.CanvasTexture(panelCanvas);
panelTexture.colorSpace = THREE.SRGBColorSpace;
panelTexture.magFilter = THREE.NearestFilter;
panelTexture.minFilter = THREE.LinearMipmapLinearFilter;
const panelFace = new THREE.Mesh(
new THREE.PlaneGeometry(4.08, 3.06),
new THREE.MeshBasicMaterial({ map: panelTexture })
);
panelFace.position.set(0, 3.52, 0.145);
panelGroup.add(panelFace);
// Small "information" blocks above the panel.
voxel(panelGroup, [1.15, 0.26, 0.24], [0, 5.35, 0], 0xf4bd42, {
outline: true
});
const pixelIcons = {
leaf: [
"00011000",
"00111100",
"01111110",
"01111110",
"00111100",
"00011000",
"00001100",
"00000100"
],
market: [
"11111111",
"10011001",
"00011000",
"01111110",
"01001010",
"01111110",
"01000010",
"01000010"
],
tool: [
"11000110",
"01111100",
"00111000",
"00111000",
"00111000",
"00111000",
"11111100",
"11111110"
]
};
function drawPixelIcon(context, name, x, y, cellSize, color) {
const pixels = pixelIcons[name];
context.fillStyle = color;
for (let row = 0; row < pixels.length; row++) {
for (let column = 0; column < pixels[row].length; column++) {
if (pixels[row][column] === "1") {
context.fillRect(
x + column * cellSize,
y + row * cellSize,
cellSize,
cellSize
);
}
}
}
}
function drawCalendar(event) {
const context = panelContext;
const x = 34;
const y = 132;
const width = 178;
const height = 222;
// Pixel-style shadow.
context.fillStyle = "#c6b995";
context.fillRect(x + 9, y + 9, width, height);
context.fillStyle = "#fffdf7";
context.fillRect(x, y, width, height);
context.fillStyle = "#172538";
context.fillRect(x, y, width, 48);
context.fillRect(x, y, 9, height);
context.fillRect(x + width - 9, y, 9, height);
context.fillRect(x, y + height - 9, width, 9);
context.fillStyle = "#f4bd42";
context.fillRect(x + 9, y + 39, width - 18, 9);
// Calendar rings.
context.fillRect(x + 30, y - 12, 14, 30);
context.fillRect(x + width - 44, y - 12, 14, 30);
context.fillStyle = "#172538";
context.font = "700 74px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(event.dateNumber, x + width / 2, y + 104);
context.fillStyle = "#2f8f87";
context.font = "700 22px monospace";
context.fillText(event.month, x + width / 2, y + 153);
drawPixelIcon(context, event.symbol, x + 59, y + 174, 7, "#2f8f87");
}
function drawPanel(event) {
const context = panelContext;
context.fillStyle = "#fff6dc";
context.fillRect(0, 0, 640, 480);
context.fillStyle = "#172538";
context.fillRect(0, 0, 640, 91);
context.fillStyle = "#f4bd42";
context.fillRect(0, 82, 640, 9);
context.fillStyle = "#fff6dc";
context.font = "700 35px monospace";
context.textAlign = "left";
context.textBaseline = "top";
context.fillText("PUBLIC NOTICE", 28, 25);
context.textAlign = "right";
context.font = "700 16px monospace";
context.fillStyle = "#f4bd42";
context.fillText("CIVIC INFO", 610, 34);
drawCalendar(event);
context.textAlign = "left";
context.textBaseline = "top";
context.fillStyle = "#172538";
context.font = "700 39px monospace";
context.fillText(event.titleLines[0], 235, 126);
context.fillText(event.titleLines[1], 235, 174);
context.fillStyle = "#2f8f87";
context.font = "700 25px monospace";
context.fillText(event.time, 235, 270);
context.fillStyle = "#172538";
context.font = "700 18px monospace";
context.fillText(event.where, 235, 316);
context.fillStyle = "#6a7379";
context.font = "700 15px monospace";
context.fillText(event.note, 235, 377);
context.fillStyle = "#f4bd42";
context.fillRect(28, 438, 584, 13);
panelTexture.needsUpdate = true;
}
drawPanel(currentEvent);
// ------------------------------------------------------------------
// Camera controls, implemented directly without addons
// ------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const portraitFactor = Math.max(1, Math.min(1.75, 0.95 / aspect));
const distance = (14 / cameraState.zoom) * portraitFactor;
const horizontalDistance = Math.cos(cameraState.pitch) * distance;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontalDistance,
cameraState.target.y + Math.sin(cameraState.pitch) * distance,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontalDistance
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.yaw = 0.38;
cameraState.pitch = 0.48;
cameraState.zoom = 1;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.005,
0.22,
0.88
);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.55
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.yaw -= 0.08;
break;
case "ArrowRight":
cameraState.yaw += 0.08;
break;
case "ArrowUp":
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + 0.06,
0.22,
0.88
);
break;
case "ArrowDown":
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch - 0.06,
0.22,
0.88
);
break;
case "+":
case "=":
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom + 0.08,
0.72,
1.55
);
break;
case "-":
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom - 0.08,
0.72,
1.55
);
break;
case "0":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
document.getElementById("reset-view").addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
updateCamera();
});
// ------------------------------------------------------------------
// Announcement controls, speech, and synchronized visual captions
// ------------------------------------------------------------------
function setSpeaking(value) {
speaking = value;
announceButton.classList.toggle("is-speaking", value);
captionText.classList.toggle("is-speaking", value);
announceLabel.textContent = value ? "Stop announcement" : "Announce message";
}
function stopCaptionSequence() {
cancelAnimationFrame(captionFrame);
captionFrame = 0;
window.clearTimeout(fallbackTimer);
}
function startCaptionSequence(event) {
stopCaptionSequence();
const words = event.spoken.split(" ");
const duration = Math.max(4200, words.length * 365);
const started = performance.now();
function updateCaption(now) {
const progress = Math.min(1, (now - started) / duration);
const visibleWords = Math.max(
1,
Math.ceil(progress * words.length)
);
captionText.textContent = words.slice(0, visibleWords).join(" ");
if (progress < 1) {
captionFrame = requestAnimationFrame(updateCaption);
} else {
captionText.textContent = event.spoken;
announcer.textContent = event.spoken;
}
}
captionFrame = requestAnimationFrame(updateCaption);
}
function stopAnnouncement() {
stopCaptionSequence();
if ("speechSynthesis" in window) {
window.speechSynthesis.cancel();
}
setSpeaking(false);
status.textContent = "Stopped · captions remain visible.";
captionText.textContent = currentEvent.spoken;
}
function announceCurrentEvent() {
if (speaking) {
stopAnnouncement();
return;
}
if ("speechSynthesis" in window) {
window.speechSynthesis.cancel();
const utterance = new SpeechSynthesisUtterance(currentEvent.spoken);
utterance.rate = 0.92;
utterance.pitch = 0.94;
utterance.volume = 1;
utterance.onstart = () => {
setSpeaking(true);
status.textContent = "Announcing · visual panel and caption are synchronized.";
};
utterance.onend = () => {
setSpeaking(false);
status.textContent = "Complete · panel and caption show the same event.";
captionText.textContent = currentEvent.spoken;
announcer.textContent = currentEvent.spoken;
};
utterance.onerror = () => {
setSpeaking(false);
status.textContent = "Audio unavailable · the visual caption is still active.";
};
setSpeaking(true);
status.textContent = "Preparing spoken announcement…";
startCaptionSequence(currentEvent);
window.speechSynthesis.speak(utterance);
} else {
setSpeaking(true);
status.textContent = "Captions only · this browser does not provide speech audio.";
startCaptionSequence(currentEvent);
fallbackTimer = window.setTimeout(() => {
setSpeaking(false);
captionText.textContent = currentEvent.spoken;
announcer.textContent = currentEvent.spoken;
status.textContent = "Complete · panel and caption show the same event.";
}, Math.max(4200, currentEvent.spoken.split(" ").length * 365));
}
}
function selectEvent(event) {
if (speaking) {
stopAnnouncement();
}
currentEvent = event;
drawPanel(currentEvent);
captionText.textContent = event.spoken;
captionText.classList.remove("is-speaking");
captionLabel.textContent = `Caption · ${event.tab}`;
announcer.textContent = event.spoken;
status.textContent = "Ready · the panel and caption show the same event.";
for (const button of eventTabs.querySelectorAll("button")) {
button.setAttribute(
"aria-pressed",
String(button.dataset.event === event.id)
);
}
}
for (const event of events) {
const button = document.createElement("button");
button.type = "button";
button.className = "event-button";
button.dataset.event = event.id;
button.textContent = event.tab;
button.setAttribute("aria-pressed", String(event === currentEvent));
button.addEventListener("click", () => selectEvent(event));
eventTabs.appendChild(button);
}
announceButton.addEventListener("click", announceCurrentEvent);
selectEvent(currentEvent);
updateCamera();
// ------------------------------------------------------------------
// Animation
// ------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (speaking) {
const mouthHeight = 0.08 + (Math.sin(elapsed * 28) + 1) * 0.09;
mouth.scale.y = mouthHeight;
rightArm.rotation.z = -0.3 + Math.sin(elapsed * 5) * 0.06;
leftArm.rotation.z = -0.08 + Math.sin(elapsed * 4 + 1) * 0.04;
} else {
mouth.scale.y = 0.09;
rightArm.rotation.z = -0.3;
leftArm.rotation.z = -0.08;
}
pulseBlocks.forEach((block, index) => {
const phase = (elapsed * 2.2 + index * 0.24) % 1;
const activeOpacity = speaking ? 0.95 - phase * 0.75 : 0.2;
const scale = speaking ? 1 + phase * 0.7 : 1;
pulseMaterials[index].opacity = activeOpacity;
block.scale.setScalar(0.13 * scale);
});
renderer.render(scene, camera);
}
loading.remove();
animate();
</script>
</body>
</html>
```