Prompt specification
Build or customize the Three.js 3D scene "Ballot box and privacy screen model" 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: Ballot box and privacy screen model
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ballot-box-and-privacy-screen-model-x2469
Scene Description Prompt:
A voxel ballot box and privacy screen evoke South Africa's 1994 election without invented ballot wording. One HTML scene using Three.js from cdnjs.
Working Three.js Starter (ballot-box-and-privacy-screen-model-x2469):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>South Africa, 1994 — Voxel Ballot Box</title>
<style>
:root {
--ink: #17221e;
--paper: #f4efe6;
--green: #087747;
--gold: #ffb612;
--red: #de3831;
--blue: #0077c8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d0c2;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card,
.date-card,
.toolbar,
.instructions {
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-card {
position: absolute;
top: clamp(18px, 4vw, 42px);
left: clamp(18px, 4vw, 48px);
width: min(410px, calc(100vw - 36px));
padding: 22px 24px 21px;
border: 1px solid rgba(23, 34, 30, 0.12);
border-radius: 18px;
background: rgba(244, 239, 230, 0.88);
box-shadow: 0 18px 50px rgba(42, 35, 25, 0.12);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: #315348;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.palette {
display: inline-flex;
gap: 3px;
}
.palette span {
width: 7px;
height: 7px;
border-radius: 1px;
}
.palette span:nth-child(1) { background: var(--red); }
.palette span:nth-child(2) { background: var(--blue); }
.palette span:nth-child(3) { background: var(--green); }
.palette span:nth-child(4) { background: var(--gold); }
.palette span:nth-child(5) { background: var(--ink); }
.palette span:nth-child(6) { background: white; }
h1 {
margin: 0;
font-size: clamp(30px, 5vw, 52px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.subtitle {
margin: 12px 0 0;
color: #51645c;
font-size: 14px;
line-height: 1.5;
}
.date-card {
position: absolute;
top: clamp(18px, 4vw, 42px);
right: clamp(18px, 4vw, 48px);
min-width: 188px;
padding: 16px 18px;
border: 1px solid rgba(23, 34, 30, 0.12);
border-radius: 15px;
background: rgba(23, 34, 30, 0.88);
color: var(--paper);
box-shadow: 0 14px 38px rgba(42, 35, 25, 0.16);
text-align: right;
}
.date-card strong {
display: block;
margin-bottom: 5px;
color: var(--gold);
font-size: 15px;
letter-spacing: 0.04em;
}
.date-card span {
color: rgba(244, 239, 230, 0.72);
font-size: 12px;
}
.toolbar {
position: absolute;
right: clamp(18px, 4vw, 48px);
bottom: clamp(18px, 4vw, 36px);
display: flex;
gap: 8px;
padding: 7px;
border: 1px solid rgba(23, 34, 30, 0.12);
border-radius: 13px;
background: rgba(244, 239, 230, 0.82);
pointer-events: auto;
}
button {
min-height: 38px;
padding: 0 14px;
border: 0;
border-radius: 9px;
background: rgba(23, 34, 30, 0.08);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
background 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(23, 34, 30, 0.15);
transform: translateY(-1px);
}
button:focus-visible {
outline: 3px solid rgba(0, 119, 200, 0.45);
outline-offset: 2px;
}
.instructions {
position: absolute;
left: clamp(18px, 4vw, 48px);
bottom: clamp(18px, 4vw, 36px);
padding: 10px 13px;
border: 1px solid rgba(23, 34, 30, 0.1);
border-radius: 10px;
background: rgba(244, 239, 230, 0.72);
color: #53665e;
font-size: 11px;
letter-spacing: 0.015em;
}
.loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #d8d0c2;
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.date-card {
display: none;
}
.title-card {
padding: 17px 19px;
border-radius: 15px;
}
.subtitle {
max-width: 270px;
font-size: 12px;
}
.instructions {
display: none;
}
.toolbar {
right: 14px;
bottom: 14px;
}
button {
min-height: 36px;
padding: 0 11px;
font-size: 11px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<section class="title-card" aria-label="Scene title">
<div class="eyebrow">
<span class="palette" aria-hidden="true">
<span></span><span></span><span></span>
<span></span><span></span><span></span>
</span>
Civic memory
</div>
<h1>South Africa, 1994</h1>
<p class="subtitle">Voxel ballot box and privacy screen</p>
</section>
<aside class="date-card" aria-label="Historical date">
<strong>27 April 1994</strong>
<span>First democratic election</span>
</aside>
<div class="instructions">
Drag to orbit · Scroll to zoom · Arrow keys to move · R to reset
</div>
<nav class="toolbar" aria-label="Scene controls">
<button id="reset-view" type="button">Reset view</button>
<button id="toggle-orbit" type="button" aria-pressed="true">
Auto orbit: on
</button>
</nav>
</div>
<div class="loading" id="loading">Building the scene</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const host = document.getElementById("scene");
const loading = document.getElementById("loading");
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d0c2);
scene.fog = new THREE.Fog(0xd8d0c2, 20, 42);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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;
renderer.domElement.setAttribute(
"aria-label",
"A voxel-style ballot box and opaque voting privacy screen."
);
renderer.domElement.setAttribute("tabindex", "0");
host.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(-0.55, 2.15, 0.05);
const initialView = {
yaw: 0.64,
pitch: 0.48,
radius: 15.8
};
let yaw = initialView.yaw;
let pitch = initialView.pitch;
let radius = initialView.radius;
let autoOrbit = true;
function applyCamera() {
const horizontal = Math.cos(pitch);
camera.position.set(
cameraTarget.x + Math.sin(yaw) * horizontal * radius,
cameraTarget.y + Math.sin(pitch) * radius,
cameraTarget.z + Math.cos(yaw) * horizontal * radius
);
camera.lookAt(cameraTarget);
}
applyCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xfff7e8,
0x746b5d,
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedcf, 3.1);
sun.position.set(7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8ec6df, 0.7);
fill.position.set(-9, 7, -6);
scene.add(fill);
// -------------------------------------------------------------------------
// Shared voxel construction helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function block(
parent,
size,
position,
color,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material(color));
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
const palette = {
red: 0xde3831,
blue: 0x0077c8,
green: 0x087747,
gold: 0xffb612,
black: 0x101615,
white: 0xf7f2e8
};
// -------------------------------------------------------------------------
// Ground and civic plinth
// -------------------------------------------------------------------------
const world = new THREE.Group();
scene.add(world);
block(
world,
[80, 0.25, 80],
[0, -0.68, 0],
0xc9c0b0,
false,
true
);
block(
world,
[19.7, 0.5, 13.2],
[0, -0.18, 0],
0xaaa18f,
true,
true
);
const tileColors = [
0xd1c8b8,
0xcdc3b2,
0xd6cdbd,
0xc8bead,
0xd9d0c1
];
for (let x = -6; x <= 6; x++) {
for (let z = -4; z <= 4; z++) {
const color = tileColors[(x * 7 + z * 3 + 20) % tileColors.length];
block(
world,
[1.39, 0.09, 1.32],
[x * 1.47, 0.105, z * 1.4],
color,
false,
true
);
}
}
// A restrained voxel colonnade in the distance.
const architecture = new THREE.Group();
architecture.position.set(-0.5, 0, -8.2);
world.add(architecture);
for (let i = -3; i <= 3; i++) {
block(
architecture,
[1.05, 5.4, 1.15],
[i * 3.05, 2.72, 0],
0xb9b09f
);
block(
architecture,
[1.28, 0.34, 1.35],
[i * 3.05, 0.35, 0],
0xa79d8c
);
}
block(
architecture,
[20.1, 0.72, 1.25],
[0, 5.25, 0],
0xbeb5a4
);
// -------------------------------------------------------------------------
// Privacy screen: three opaque, inward-angled voxel panels
// -------------------------------------------------------------------------
const screen = new THREE.Group();
world.add(screen);
function addPrivacyPanel(x, z, rotation, width, phase = 0) {
const panel = new THREE.Group();
panel.position.set(x, 0.2, z);
panel.rotation.y = rotation;
screen.add(panel);
// Opaque backing ensures complete privacy.
block(
panel,
[width - 0.2, 4.38, 0.16],
[0, 2.7, 0],
0x244f43
);
// Frame.
for (const side of [-1, 1]) {
block(
panel,
[0.14, 4.62, 0.25],
[side * (width * 0.5 - 0.07), 2.7, 0],
0x17231f
);
}
block(
panel,
[width, 0.16, 0.26],
[0, 4.96, 0],
0x17231f
);
block(
panel,
[width, 0.14, 0.24],
[0, 0.48, 0],
0x17231f
);
// Subtle voxel relief across the opaque face.
const tileWidth = (width - 0.38) / 3;
const panelColors = [0x2b5b4c, 0x285546, 0x2e6252];
for (let row = 0; row < 5; row++) {
for (let column = 0; column < 3; column++) {
const colorIndex =
(row * 3 + column + phase) % panelColors.length;
block(
panel,
[tileWidth - 0.025, 0.72, 0.035],
[
-tileWidth + column * tileWidth,
0.74 + row * 0.8 + 0.36,
0.097
],
panelColors[colorIndex]
);
}
}
// A restrained South African color rhythm along the upper edge.
const stripColors = [
palette.black,
palette.gold,
palette.red,
palette.white,
palette.blue,
palette.green
];
const usable = width - 0.42;
const segment = usable / stripColors.length;
stripColors.forEach((color, index) => {
block(
panel,
[segment - 0.025, 0.14, 0.075],
[
-usable * 0.5 + segment * (index + 0.5),
4.7,
0.13
],
color
);
});
// Feet.
for (const side of [-1, 1]) {
block(
panel,
[0.34, 0.25, 0.7],
[side * (width * 0.5 - 0.12), 0.16, 0.2],
0x17231f
);
}
}
addPrivacyPanel(-4.68, -0.18, 0.52, 2.36, 0);
addPrivacyPanel(-2.55, -0.88, 0.0, 2.66, 1);
addPrivacyPanel(-0.42, -0.18, -0.52, 2.36, 2);
// A small interior desk and stool, mostly concealed by the screen.
block(
screen,
[2.2, 0.18, 1.05],
[-2.55, 1.45, -1.08],
0x8b7657
);
block(
screen,
[0.18, 1.25, 0.18],
[-2.55, 0.78, -1.08],
0x34453e
);
block(
screen,
[0.8, 0.16, 0.72],
[-2.55, 0.53, -1.65],
0x34453e
);
block(
screen,
[0.14, 0.45, 0.14],
[-2.55, 0.27, -1.65],
0x34453e
);
// -------------------------------------------------------------------------
// Voxel ballot box
// -------------------------------------------------------------------------
const ballotBox = new THREE.Group();
ballotBox.position.set(2.7, 0.2, 1.05);
world.add(ballotBox);
block(
ballotBox,
[2.34, 0.36, 1.82],
[0, 0.18, 0],
0x101615
);
block(
ballotBox,
[2.08, 2.15, 1.55],
[0, 1.38, 0],
0x1a2521
);
block(
ballotBox,
[2.38, 0.34, 1.83],
[0, 2.62, 0],
palette.green
);
block(
ballotBox,
[2.16, 0.08, 1.61],
[0, 2.43, 0],
palette.black
);
// Gold-edged ballot slot.
block(
ballotBox,
[1.25, 0.055, 0.26],
[0, 2.805, 0.05],
0x050706
);
for (const side of [-1, 1]) {
block(
ballotBox,
[1.46, 0.055, 0.055],
[0, 2.835, 0.05 + side * 0.17],
palette.gold
);
block(
ballotBox,
[0.055, 0.055, 0.34],
[side * 0.755, 2.835, 0.05],
palette.gold
);
}
// Simplified, low-resolution South African flag motif in voxels.
const flagPattern = [
"RRRRRRRRRRR",
"RRRRRRRRRRR",
"GGGGGBBBGGG",
"GGGBBBBBGGG",
"GGBBBBBBBGG",
"GGGBBBBBGGG",
"BBBBBBBBBBB",
"BBBBBBBBBBB"
];
const flagColors = {
R: palette.red,
G: palette.green,
B: palette.black
};
block(
ballotBox,
[1.7, 1.29, 0.055],
[0, 1.4, 0.805],
palette.gold
);
const flagCell = 0.137;
const flagWidth = flagPattern[0].length * flagCell;
const flagHeight = flagPattern.length * flagCell;
const flagStartX = -flagWidth * 0.5 + flagCell * 0.5;
const flagStartY = 1.4 - flagHeight * 0.5 + flagCell * 0.5;
flagPattern.forEach((row, rowIndex) => {
[...row].forEach((letter, columnIndex) => {
block(
ballotBox,
[flagCell - 0.009, flagCell - 0.009, 0.035],
[
flagStartX + columnIndex * flagCell,
flagStartY + rowIndex * flagCell,
0.85
],
flagColors[letter]
);
});
});
// Small indicator, with no political or ballot wording.
const indicatorMaterial = new THREE.MeshStandardMaterial({
color: 0x2e78d0,
emissive: 0x123c76,
emissiveIntensity: 0.55,
roughness: 0.5
});
const indicator = new THREE.Mesh(unitBox, indicatorMaterial);
indicator.scale.set(0.085, 0.085, 0.045);
indicator.position.set(0.73, 2.34, 0.79);
ballotBox.add(indicator);
// Completely blank ballot: no wording, marks, names, or symbols.
const blankBallot = new THREE.Group();
blankBallot.position.set(0, 2.865, 0.29);
ballotBox.add(blankBallot);
block(
blankBallot,
[0.78, 0.018, 0.52],
[0, 0, 0],
palette.white,
false,
true
);
// -------------------------------------------------------------------------
// Small civic details
// -------------------------------------------------------------------------
const accentGroup = new THREE.Group();
accentGroup.position.set(7.1, 0.2, -2.9);
world.add(accentGroup);
const accentColors = [
palette.red,
palette.blue,
palette.green,
palette.gold,
palette.black,
palette.white
];
accentColors.forEach((color, index) => {
block(
accentGroup,
[0.42, 0.42 + (index % 2) * 0.42, 0.42],
[index * 0.48, 0.25 + (index % 2) * 0.21, 0],
color
);
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, pinch, keyboard, reset
// -------------------------------------------------------------------------
const pointers = new Map();
let pinchDistance = 0;
let lastX = 0;
let lastY = 0;
const canvas = renderer.domElement;
function setAutoOrbit(value) {
autoOrbit = value;
const button = document.getElementById("toggle-orbit");
button.textContent = `Auto orbit: ${value ? "on" : "off"}`;
button.setAttribute("aria-pressed", String(value));
}
function currentPinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function resetView() {
yaw = initialView.yaw;
pitch = initialView.pitch;
radius = initialView.radius;
applyCamera();
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
lastX = event.clientX;
lastY = event.clientY;
pinchDistance = currentPinchDistance();
setAutoOrbit(false);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2) {
const distance = currentPinchDistance();
if (pinchDistance > 0 && distance > 0) {
radius = THREE.MathUtils.clamp(
radius * (pinchDistance / distance),
8,
25
);
}
pinchDistance = distance;
applyCamera();
return;
}
const deltaX = event.clientX - lastX;
const deltaY = event.clientY - lastY;
yaw -= deltaX * 0.006;
pitch = THREE.MathUtils.clamp(pitch + deltaY * 0.005, 0.18, 1.12);
lastX = event.clientX;
lastY = event.clientY;
applyCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
pinchDistance = currentPinchDistance();
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
setAutoOrbit(false);
radius = THREE.MathUtils.clamp(
radius + event.deltaY * 0.012,
8,
25
);
applyCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
let handled = true;
switch (event.key.toLowerCase()) {
case "arrowleft":
yaw += 0.08;
setAutoOrbit(false);
break;
case "arrowright":
yaw -= 0.08;
setAutoOrbit(false);
break;
case "arrowup":
pitch = THREE.MathUtils.clamp(pitch + 0.06, 0.18, 1.12);
setAutoOrbit(false);
break;
case "arrowdown":
pitch = THREE.MathUtils.clamp(pitch - 0.06, 0.18, 1.12);
setAutoOrbit(false);
break;
case "+":
case "=":
radius = THREE.MathUtils.clamp(radius - 0.8, 8, 25);
setAutoOrbit(false);
break;
case "-":
case "_":
radius = THREE.MathUtils.clamp(radius + 0.8, 8, 25);
setAutoOrbit(false);
break;
case "r":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
applyCamera();
}
});
document.getElementById("reset-view").addEventListener("click", resetView);
document.getElementById("toggle-orbit").addEventListener("click", () => {
setAutoOrbit(!autoOrbit);
});
// -------------------------------------------------------------------------
// Animation and resize
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (autoOrbit) {
yaw += delta * 0.045;
applyCamera();
}
// The unmarked ballot settles into the slot once.
const dropProgress = THREE.MathUtils.clamp(
(elapsed - 0.65) / 1.65,
0,
1
);
const eased = 1 - Math.pow(1 - dropProgress, 3);
blankBallot.position.z = THREE.MathUtils.lerp(
0.29,
-0.025,
eased
);
blankBallot.position.y = THREE.MathUtils.lerp(
2.865,
2.81,
eased
);
indicatorMaterial.emissiveIntensity =
0.45 + Math.sin(elapsed * 2.1) * 0.1;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
loading.remove();
animate();
</script>
</body>
</html>
```