Prompt specification
Build or customize the Three.js 3D scene "One service desk queue cycle" 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: One service desk queue cycle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/one-service-desk-queue-cycle-x0454
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows service queues and numbered tickets. Animate a visitor taking a ticket, waiting, and approaching only when that number appears; the next number advances after the visible service interaction finishes. Voxel style.
Working Three.js Starter (one-service-desk-queue-cycle-x0454):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Service Hall</title>
<style>
:root {
--ink: #22323a;
--panel: rgba(248, 247, 238, 0.94);
--teal: #22b8aa;
--coral: #ff6b5e;
--yellow: #ffc857;
--purple: #8d76c9;
--line: rgba(34, 50, 58, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d4e3e1;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
"Liberation Mono", monospace;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.brand {
position: fixed;
top: 24px;
left: 24px;
z-index: 5;
pointer-events: none;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: clamp(18px, 2.2vw, 30px);
line-height: 0.95;
letter-spacing: -0.06em;
text-shadow: 3px 3px 0 rgba(255, 255, 255, 0.65);
}
.brand p {
margin: 9px 0 0;
padding: 6px 9px;
display: inline-block;
background: var(--ink);
color: #fff9e9;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
box-shadow: 4px 4px 0 rgba(34, 50, 58, 0.2);
}
.monitor {
position: fixed;
top: 22px;
right: 22px;
z-index: 5;
width: min(330px, calc(100vw - 44px));
padding: 16px;
border: 2px solid var(--ink);
background: var(--panel);
box-shadow: 7px 7px 0 rgba(34, 50, 58, 0.18);
backdrop-filter: blur(8px);
}
.monitor-title {
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 10px;
border-bottom: 2px solid var(--ink);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.1em;
}
.live {
display: flex;
align-items: center;
gap: 6px;
color: #168d7f;
}
.live::before {
content: "";
width: 8px;
height: 8px;
background: var(--teal);
box-shadow: 0 0 0 3px rgba(34, 184, 170, 0.18);
animation: blink 1.2s steps(2, end) infinite;
}
@keyframes blink {
50% {
opacity: 0.35;
}
}
.ticket-row {
display: grid;
grid-template-columns: 1fr auto;
align-items: end;
gap: 12px;
padding: 14px 0 10px;
}
.label {
display: block;
margin-bottom: 5px;
color: #617077;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
}
.number {
min-width: 86px;
text-align: right;
font-size: 42px;
line-height: 0.9;
font-weight: 900;
letter-spacing: -0.08em;
}
.divider {
height: 2px;
margin: 3px 0 12px;
background: var(--line);
}
.status {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
font-size: 11px;
font-weight: 900;
text-transform: uppercase;
}
.status span:last-child {
text-align: right;
}
.progress {
height: 10px;
margin-top: 12px;
border: 2px solid var(--ink);
background: #d9ded8;
overflow: hidden;
}
.progress-fill {
width: 0;
height: 100%;
background: var(--teal);
transition: width 0.08s linear;
}
.legend {
position: fixed;
left: 24px;
bottom: 22px;
z-index: 5;
display: flex;
gap: 14px;
align-items: center;
padding: 9px 12px;
border: 2px solid var(--ink);
background: rgba(248, 247, 238, 0.9);
box-shadow: 4px 4px 0 rgba(34, 50, 58, 0.16);
font-size: 10px;
font-weight: 800;
pointer-events: none;
}
.swatch {
display: inline-block;
width: 10px;
height: 10px;
margin-right: 5px;
vertical-align: -1px;
}
.controls {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 6;
display: flex;
gap: 8px;
}
button {
border: 2px solid var(--ink);
border-radius: 0;
padding: 10px 13px;
background: #fff9e9;
color: var(--ink);
box-shadow: 4px 4px 0 rgba(34, 50, 58, 0.18);
font: 800 10px ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
monospace;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
}
button:hover {
transform: translate(1px, 1px);
box-shadow: 3px 3px 0 rgba(34, 50, 58, 0.18);
}
button:active {
transform: translate(3px, 3px);
box-shadow: 1px 1px 0 rgba(34, 50, 58, 0.18);
}
.hint {
position: fixed;
left: 50%;
bottom: 25px;
z-index: 4;
transform: translateX(-50%);
color: rgba(34, 50, 58, 0.68);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 700px) {
.brand {
top: 14px;
left: 14px;
}
.brand h1 {
font-size: 18px;
}
.brand p {
display: none;
}
.monitor {
top: auto;
right: 14px;
bottom: 68px;
width: min(300px, calc(100vw - 28px));
padding: 12px;
}
.number {
font-size: 34px;
}
.legend {
left: 14px;
bottom: 14px;
max-width: calc(100vw - 180px);
overflow: hidden;
}
.controls {
right: 14px;
bottom: 14px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="brand">
<h1>Voxel<br />Service Hall</h1>
<p>LIVE QUEUE / DESKS A–C</p>
</header>
<aside class="monitor" aria-live="polite">
<div class="monitor-title">
<span>QUEUE MONITOR</span>
<span class="live">LIVE</span>
</div>
<div class="ticket-row">
<div>
<span class="label">VISITOR TICKET</span>
<span style="font-size:11px;font-weight:800">CORAL JACKET</span>
</div>
<strong class="number" id="ticket-number">—</strong>
</div>
<div class="divider"></div>
<div class="status">
<span>Desk A</span>
<span id="status-text">Walking to kiosk</span>
</div>
<div class="status" style="margin-top:8px">
<span>Now serving</span>
<strong id="called-number">—</strong>
</div>
<div class="progress">
<div class="progress-fill" id="progress-fill"></div>
</div>
</aside>
<div class="legend">
<span><i class="swatch" style="background:#ff6b5e"></i>VISITOR</span>
<span><i class="swatch" style="background:#22b8aa"></i>ACTIVE DESK</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div class="controls">
<button id="pause-button" type="button">Pause</button>
<button id="camera-button" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, and orthographic camera
// ------------------------------------------------------------
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd4e3e1);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const cameraState = {
yaw: 0.67,
pitch: 0.72,
zoom: 1,
target: new THREE.Vector3(0, 0.55, -0.25)
};
function updateCamera() {
const { yaw, pitch, zoom, target } = cameraState;
const radius = 27;
camera.position.set(
target.x + Math.sin(yaw) * Math.cos(pitch) * radius,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * Math.cos(pitch) * radius
);
camera.lookAt(target);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const frustumHeight = Math.max(16, 24 / aspect);
camera.left = (-frustumHeight * aspect) / 2;
camera.right = (frustumHeight * aspect) / 2;
camera.top = frustumHeight / 2;
camera.bottom = -frustumHeight / 2;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// Direct camera controls: no addons or examples are used.
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.35,
1.12
);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * (event.deltaY > 0 ? 0.91 : 1.1),
0.7,
1.8
);
updateCamera();
},
{ passive: false }
);
document.querySelector("#camera-button").addEventListener("click", () => {
cameraState.yaw = 0.67;
cameraState.pitch = 0.72;
cameraState.zoom = 1;
updateCamera();
});
// ------------------------------------------------------------
// Lighting and reusable voxel materials
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xf8fff8, 0x71817b, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4d6, 3.1);
sun.position.set(8, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.normalBias = 0.025;
scene.add(sun);
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.82,
metalness: 0.02,
flatShading: true
})
);
}
return materialCache.get(color);
}
function cube(parent, size, position, color, cast = true, receive = true) {
const mesh = new THREE.Mesh(
unitBox,
color && color.isMaterial ? color : material(color)
);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function group(parent, position = [0, 0, 0]) {
const object = new THREE.Group();
object.position.set(position[0], position[1], position[2]);
parent.add(object);
return object;
}
// ------------------------------------------------------------
// Pixel-style text built from cubes
// ------------------------------------------------------------
const pixelPatterns = {
A: ["01110", "10001", "10001", "11111", "10001", "10001", "10001"],
B: ["11110", "10001", "10001", "11110", "10001", "10001", "11110"],
C: ["01111", "10000", "10000", "10000", "10000", "10000", "01111"],
E: ["11111", "10000", "10000", "11110", "10000", "10000", "11111"],
H: ["10001", "10001", "10001", "11111", "10001", "10001", "10001"],
I: ["11111", "00100", "00100", "00100", "00100", "00100", "11111"],
K: ["10001", "10010", "10100", "11000", "10100", "10010", "10001"],
L: ["10000", "10000", "10000", "10000", "10000", "10000", "11111"],
R: ["11110", "10001", "10001", "11110", "10100", "10010", "10001"],
S: ["01111", "10000", "10000", "01110", "00001", "00001", "11110"],
T: ["11111", "00100", "00100", "00100", "00100", "00100", "00100"],
V: ["10001", "10001", "10001", "10001", "10001", "01010", "00100"],
" ": ["00000", "00000", "00000", "00000", "00000", "00000", "00000"]
};
function pixelText(text, pixelSize, color) {
const textGroup = group(scene);
const width = text.length * 6 * pixelSize;
[...text.toUpperCase()].forEach((character, characterIndex) => {
const pattern = pixelPatterns[character] || pixelPatterns[" "];
pattern.forEach((row, rowIndex) => {
[...row].forEach((cell, columnIndex) => {
if (cell !== "1") return;
const x =
-width / 2 +
characterIndex * 6 * pixelSize +
columnIndex * pixelSize +
pixelSize / 2;
const y = (3 - rowIndex) * pixelSize;
cube(
textGroup,
[pixelSize * 0.86, pixelSize * 0.86, 0.09],
[x, y, 0],
color,
false,
false
);
});
});
});
return textGroup;
}
// ------------------------------------------------------------
// Seven-segment displays made from voxel bars
// ------------------------------------------------------------
function createSevenSegmentDisplay(options = {}) {
const {
digits = 2,
height = 0.7,
digitWidth = 0.36,
color = "#67f5df",
frameColor = "#26343b",
ghostColor = "#405158",
emissiveIntensity = 0.8
} = options;
const display = group(scene);
const thickness = height * 0.095;
const gap = height * 0.22;
const advance = digitWidth + gap;
const totalWidth = digits * advance - gap;
cube(
display,
[totalWidth + height * 0.32, height * 1.25, 0.16],
[0, 0, -0.08],
frameColor
);
const ghostMaterial = new THREE.MeshStandardMaterial({
color: ghostColor,
roughness: 0.9,
metalness: 0
});
const litMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity,
roughness: 0.45,
metalness: 0
});
const segmentDefinitions = {
a: [digitWidth, thickness, 0, height / 2],
b: [thickness, height / 2 - thickness, digitWidth / 2, height / 4],
c: [thickness, height / 2 - thickness, digitWidth / 2, -height / 4],
d: [digitWidth, thickness, 0, -height / 2],
e: [thickness, height / 2 - thickness, -digitWidth / 2, -height / 4],
f: [thickness, height / 2 - thickness, -digitWidth / 2, height / 4],
g: [digitWidth, thickness, 0, 0]
};
const digitMaps = {
0: "abcdef",
1: "bc",
2: "abdeg",
3: "abcdg",
4: "bcfg",
5: "acdfg",
6: "acdefg",
7: "abc",
8: "abcdefg",
9: "abcdfg"
};
const litSegments = [];
for (let digitIndex = 0; digitIndex < digits; digitIndex++) {
const centerX = -totalWidth / 2 + advance * (digitIndex + 0.5);
Object.entries(segmentDefinitions).forEach(([name, definition]) => {
const [width, segmentHeight, offsetX, offsetY] = definition;
cube(
display,
[width, segmentHeight, 0.055],
[centerX + offsetX, offsetY, 0.025],
ghostMaterial,
false,
false
);
const lit = cube(
display,
[width, segmentHeight, 0.065],
[centerX + offsetX, offsetY, 0.045],
litMaterial,
false,
false
);
lit.visible = false;
litSegments.push({ mesh: lit, digitIndex, segmentName: name });
});
}
let currentNumber = null;
let pulseAmount = 0;
function setNumber(number) {
currentNumber = number;
const text =
number === null
? ""
: String(number).padStart(digits, "0").slice(-digits);
litSegments.forEach(({ mesh, digitIndex, segmentName }) => {
const character = text[digitIndex];
mesh.visible =
character !== undefined &&
digitMaps[character].includes(segmentName);
});
}
function pulse() {
pulseAmount = 1;
}
return {
group: display,
setNumber,
pulse,
get currentNumber() {
return currentNumber;
},
pulseAmount,
baseScale: 1
};
}
function createTicketDisplay() {
const display = createSevenSegmentDisplay({
digits: 2,
height: 0.42,
digitWidth: 0.23,
color: "#26343b",
frameColor: "#fff7df",
ghostColor: "#d8d0bd",
emissiveIntensity: 0.04
});
display.baseScale = 0.95;
display.group.scale.setScalar(display.baseScale);
return display;
}
// ------------------------------------------------------------
// Block people
// ------------------------------------------------------------
const people = [];
function createPerson({
shirt = "#ff6b5e",
pants = "#344852",
skin = "#d99a72",
hair = "#3b302b",
scale = 0.9
} = {}) {
const root = group(scene);
root.scale.setScalar(scale);
const legLeft = group(root, [-0.19, 0.68, 0]);
const legRight = group(root, [0.19, 0.68, 0]);
cube(legLeft, [0.25, 0.58, 0.28], [0, -0.29, 0], pants);
cube(legRight, [0.25, 0.58, 0.28], [0, -0.29, 0], pants);
cube(root, [0.72, 0.8, 0.42], [0, 1.12, 0], shirt);
cube(root, [0.58, 0.58, 0.56], [0, 1.82, 0], skin);
cube(root, [0.61, 0.16, 0.59], [0, 2.07, -0.015], hair);
cube(root, [0.12, 0.08, 0.05], [-0.15, 1.86, 0.295], "#26343b", false, false);
cube(root, [0.12, 0.08, 0.05], [0.15, 1.86, 0.295], "#26343b", false, false);
const armLeft = group(root, [-0.48, 1.43, 0]);
const armRight = group(root, [0.48, 1.43, 0]);
cube(armLeft, [0.21, 0.61, 0.24], [0, -0.27, 0], shirt);
cube(armRight, [0.21, 0.61, 0.24], [0, -0.27, 0], shirt);
cube(armLeft, [0.2, 0.16, 0.22], [0, -0.62, 0], skin);
cube(armRight, [0.2, 0.16, 0.22], [0, -0.62, 0], skin);
const person = {
root,
legLeft,
legRight,
armLeft,
armRight,
walkPhase: Math.random() * 10,
moving: false,
reach: 0
};
people.push(person);
return person;
}
function updatePerson(person, time, dt) {
person.walkPhase += dt * (person.moving ? 10 : 2.2);
const swing = person.moving
? Math.sin(person.walkPhase) * 0.58
: Math.sin(time * 1.6 + person.walkPhase) * 0.025;
person.legLeft.rotation.x = swing;
person.legRight.rotation.x = -swing;
person.armLeft.rotation.x = -person.reach + swing * 0.55;
person.armRight.rotation.x = -person.reach - swing * 0.55;
}
function turnPerson(person, dx, dz, dt) {
if (Math.abs(dx) + Math.abs(dz) < 0.0001) return;
const targetAngle = Math.atan2(dx, dz);
const difference = Math.atan2(
Math.sin(targetAngle - person.root.rotation.y),
Math.cos(targetAngle - person.root.rotation.y)
);
person.root.rotation.y += difference * Math.min(1, dt * 12);
}
function movePerson(person, target, speed, dt) {
const dx = target.x - person.root.position.x;
const dz = target.z - person.root.position.z;
const distance = Math.hypot(dx, dz);
if (distance < 0.04) {
person.moving = false;
return true;
}
const step = Math.min(distance, speed * dt);
person.root.position.x += (dx / distance) * step;
person.root.position.z += (dz / distance) * step;
person.moving = true;
turnPerson(person, dx, dz, dt);
return false;
}
// ------------------------------------------------------------
// Service hall environment
// ------------------------------------------------------------
cube(scene, [22, 0.5, 16], [0, -0.35, 0], "#e7ece3");
cube(scene, [22, 5.5, 0.42], [0, 2.55, -6.55], "#dbe5df");
cube(scene, [0.42, 4.2, 10.5], [-10.7, 1.8, -1.1], "#d2dfd9");
// Floor grid.
for (let x = -9; x <= 9; x += 2.25) {
cube(scene, [0.025, 0.018, 14.8], [x, -0.085, 0], "#cbd5ce", false, false);
}
for (let z = -6; z <= 6; z += 2) {
cube(scene, [20.8, 0.018, 0.025], [0, -0.084, z], "#cbd5ce", false, false);
}
// Entrance path.
cube(scene, [3.2, 0.025, 4.2], [-7.2, -0.065, 5.1], "#c9e5dc", false, false);
// Wall windows.
[-7.4, -2.5, 2.4, 7.3].forEach((x, index) => {
const windowColor = index % 2 === 0 ? "#8bc8cf" : "#9bd1d4";
cube(scene, [3.25, 1.8, 0.12], [x, 3.15, -6.28], windowColor, false, false);
cube(scene, [3.5, 0.12, 0.16], [x, 2.18, -6.17], "#f6f4e9", false, false);
cube(scene, [3.5, 0.12, 0.16], [x, 4.12, -6.17], "#f6f4e9", false, false);
cube(scene, [0.12, 2.05, 0.16], [x - 1.7, 3.15, -6.17], "#f6f4e9", false, false);
cube(scene, [0.12, 2.05, 0.16], [x + 1.7, 3.15, -6.17], "#f6f4e9", false, false);
cube(scene, [0.1, 1.9, 0.16], [x, 3.15, -6.15], "#f6f4e9", false, false);
});
cube(scene, [10.5, 1.25, 0.22], [0, 4.8, -6.15], "#26343b", false, false);
const hallText = pixelText("SERVICE HALL", 0.105, "#fff5d9");
hallText.position.set(0, 4.8, -5.99);
// Voxel planters.
function addPlanter(x, z) {
cube(scene, [0.8, 0.7, 0.8], [x, 0.3, z], "#d78967");
cube(scene, [1.05, 0.15, 1.05], [x, 0.7, z], "#e5a27d");
cube(scene, [0.22, 1.1, 0.22], [x, 1.2, z], "#4f7554");
cube(scene, [0.7, 0.65, 0.65], [x - 0.24, 1.38, z], "#609567");
cube(scene, [0.62, 0.55, 0.6], [x + 0.28, 1.15, z + 0.06], "#78a66f");
}
addPlanter(-9.2, -5.3);
addPlanter(9.2, -5.3);
addPlanter(8.9, 5.7);
// ------------------------------------------------------------
// Ticket kiosk
// ------------------------------------------------------------
const kioskPosition = { x: -7.3, z: 3.25 };
const kioskStand = { x: -7.3, z: 4.35 };
cube(scene, [1.55, 2.1, 1.1], [kioskPosition.x, 1.02, kioskPosition.z], "#344852");
cube(scene, [1.65, 0.18, 1.2], [kioskPosition.x, 2.15, kioskPosition.z], "#f7f1df");
cube(scene, [1.22, 0.72, 0.12], [kioskPosition.x, 1.65, kioskPosition.z + 0.6], "#17262d");
cube(scene, [0.94, 0.48, 0.07], [kioskPosition.x, 1.65, kioskPosition.z + 0.68], "#39c9b5", false, false);
cube(scene, [0.82, 0.1, 0.12], [kioskPosition.x, 1.03, kioskPosition.z + 0.6], "#111d23");
const kioskSign = pixelText("TICKETS", 0.055, "#26343b");
kioskSign.position.set(kioskPosition.x, 2.67, kioskPosition.z - 0.05);
cube(scene, [2.7, 0.72, 0.12], [kioskPosition.x, 2.67, kioskPosition.z - 0.14], "#f7f1df");
const kioskTicket = cube(
scene,
[0.5, 0.08, 0.32],
[kioskPosition.x, 1.05, kioskPosition.z + 0.7],
"#fff8df"
);
kioskTicket.visible = false;
// ------------------------------------------------------------
// Service desks and queues
// ------------------------------------------------------------
function buildStation(x, letter, accent, initialNumber) {
const queueMaterial = new THREE.MeshStandardMaterial({
color: accent,
transparent: true,
opacity: 0.25,
roughness: 1,
depthWrite: false
});
cube(scene, [3.35, 1.25, 1.2], [x, 0.58, -2.45], "#f5f1e5");
cube(scene, [3.65, 0.18, 1.42], [x, 1.3, -2.45], "#fff9e9");
cube(scene, [3.0, 0.18, 0.08], [x, 0.78, -1.81], accent);
cube(scene, [0.72, 0.55, 0.15], [x + 0.95, 1.7, -2.48], "#26343b");
cube(scene, [0.58, 0.4, 0.08], [x + 0.95, 1.72, -2.37], "#69d8ca", false, false);
cube(scene, [3.0, 1.15, 0.18], [x, 3.28, -3.2], "#26343b");
const letterText = pixelText(letter, 0.12, accent);
letterText.position.set(x - 1.08, 3.28, -3.07);
const board = createSevenSegmentDisplay({
digits: 2,
height: 0.7,
digitWidth: 0.36,
color: accent,
frameColor: "#17262d",
ghostColor: "#405158",
emissiveIntensity: 0.95
});
board.group.position.set(x + 0.4, 3.28, -3.04);
board.setNumber(initialNumber);
// Queue mat and numbered position cubes.
cube(scene, [2.2, 0.025, 3.6], [x, -0.06, 1.1], queueMaterial, false, false);
[0.35, 1.3, 2.25].forEach((z, index) => {
cube(scene, [0.42, 0.035, 0.42], [x, -0.035, z], accent, false, false);
cube(scene, [0.16, 0.045, 0.16], [x, -0.015, z], "#fff9e9", false, false);
});
// Queue rails.
[-1.18, 1.18].forEach(offset => {
[0.0, 1.45, 2.9].forEach(z => {
cube(scene, [0.11, 0.95, 0.11], [x + offset, 0.38, z], "#344852");
cube(scene, [0.24, 0.09, 0.24], [x + offset, 0.02, z], "#26343b");
cube(scene, [0.18, 0.18, 0.18], [x + offset, 0.9, z], accent);
});
cube(scene, [0.075, 0.13, 2.9], [x + offset, 0.79, 1.45], accent);
});
const employee = createPerson({
shirt: "#40515a",
pants: "#28373f",
skin: "#c98c69",
hair: "#292522",
scale: 0.86
});
employee.root.position.set(x, 0, -3.62);
employee.root.rotation.y = 0;
return {
x,
letter,
accent,
board,
employee,
queueSpot: { x, z: 0.7 },
counterSpot: { x, z: -1.18 }
};
}
const stationA = buildStation(0, "A", "#39d2bd", null);
const stationB = buildStation(-4.8, "B", "#ffc857", 42);
const stationC = buildStation(4.8, "C", "#a98be0", 63);
const stations = [stationA, stationB, stationC];
// ------------------------------------------------------------
// Main visitor state machine
// ------------------------------------------------------------
const mainVisitor = createPerson({
shirt: "#ff6b5e",
pants: "#344852",
skin: "#d99a72",
hair: "#49342d",
scale: 0.94
});
mainVisitor.root.position.set(-8.5, 0, 5.85);
const mainTicketDisplay = createTicketDisplay();
mainTicketDisplay.setNumber(null);
mainTicketDisplay.group.visible = false;
const mainServiceItem = cube(
scene,
[0.46, 0.35, 0.4],
[0, 1.5, -2.3],
"#ffc857"
);
mainServiceItem.visible = false;
const ticketNumberElement = document.querySelector("#ticket-number");
const calledNumberElement = document.querySelector("#called-number");
const statusElement = document.querySelector("#status-text");
const progressElement = document.querySelector("#progress-fill");
let callNumber = 27;
let heldTicket = null;
let mainState = "walking";
let mainStateElapsed = 0;
let mainPath = [];
let mainPathIndex = 1;
let mainEndState = "";
let paused = false;
function setMainState(nextState) {
mainState = nextState;
mainStateElapsed = 0;
if (nextState === "walking") {
statusElement.textContent = "Walking";
} else if (nextState === "printing") {
statusElement.textContent = "Taking ticket";
mainVisitor.root.rotation.y = Math.PI;
kioskTicket.visible = true;
} else if (nextState === "waiting") {
statusElement.textContent = "Waiting in queue";
mainVisitor.root.rotation.y = Math.PI;
} else if (nextState === "service") {
statusElement.textContent = "Service interaction";
mainServiceItem.visible = true;
}
}
function walkMain(points, endState) {
mainPath = points.map(point => ({ x: point.x, z: point.z }));
mainPathIndex = 1;
mainEndState = endState;
setMainState("walking");
}
function updateMain(dt) {
mainStateElapsed += dt;
if (mainState === "walking") {
if (mainPathIndex >= mainPath.length) {
setMainState(mainEndState);
return;
}
const target = mainPath[mainPathIndex];
const arrived = movePerson(mainVisitor, target, 2.05, dt);
if (arrived) {
mainPathIndex++;
}
} else if (mainState === "printing") {
const t = THREE.MathUtils.clamp(mainStateElapsed / 1.2, 0, 1);
const eased = 1 - Math.pow(1 - t, 3);
kioskTicket.position.y = 1.05 + eased * 0.55;
kioskTicket.position.z = kioskPosition.z + 0.7 + eased * 0.42;
if (mainStateElapsed >= 1.2) {
kioskTicket.visible = false;
heldTicket = callNumber;
mainTicketDisplay.setNumber(heldTicket);
mainTicketDisplay.group.visible = true;
mainTicketDisplay.pulse();
// The first number appears exactly as the ticket is printed.
if (stationA.board.currentNumber === null) {
stationA.board.setNumber(callNumber);
stationA.board.pulse();
}
walkMain(
[
{ x: kioskStand.x, z: kioskStand.z },
{ x: -5.7, z: 3.05 },
{ x: -2.0, z: 3.75 },
{ x: 0, z: 2.75 },
stationA.queueSpot
],
"waiting"
);
}
} else if (mainState === "waiting") {
// The visitor approaches only after the held ticket matches
// the number currently shown on the desk.
if (
mainStateElapsed >= 1.45 &&
stationA.board.currentNumber === heldTicket
) {
stationA.board.pulse();
walkMain(
[
stationA.queueSpot,
{ x: 0, z: -0.25 },
stationA.counterSpot
],
"service"
);
}
} else if (mainState === "service") {
const duration = 4.2;
const t = THREE.MathUtils.clamp(mainStateElapsed / duration, 0, 1);
let z;
if (t < 0.25) {
const u = t / 0.25;
z = THREE.MathUtils.lerp(-3.23, -2.24, u);
} else if (t < 0.53) {
const u = (t - 0.25) / 0.28;
z = THREE.MathUtils.lerp(-2.24, -1.52, u);
} else if (t < 0.77) {
const u = (t - 0.53) / 0.24;
z = THREE.MathUtils.lerp(-1.52, -2.24, u);
} else {
const u = (t - 0.77) / 0.23;
z = THREE.MathUtils.lerp(-2.24, -3.23, u);
}
mainServiceItem.position.set(0, 1.48 + Math.sin(t * Math.PI) * 0.15, z);
mainVisitor.reach = Math.sin(t * Math.PI) * 0.9;
stationA.employee.reach = Math.sin(t * Math.PI) * 0.85;
progressElement.style.width = `${t * 100}%`;
if (mainStateElapsed >= duration) {
// Advance the number only after the visible interaction ends.
callNumber = callNumber >= 99 ? 1 : callNumber + 1;
stationA.board.setNumber(callNumber);
stationA.board.pulse();
mainServiceItem.visible = false;
mainVisitor.reach = 0;
stationA.employee.reach = 0;
progressElement.style.width = "0%";
walkMain(
[
stationA.counterSpot,
{ x: 0.8, z: -0.4 },
{ x: 1.8, z: 1.6 },
{ x: -1.8, z: 3.7 },
{ x: -6.2, z: 4.1 },
kioskStand
],
"printing"
);
}
}
ticketNumberElement.textContent =
heldTicket === null ? "—" : String(heldTicket).padStart(2, "0");
calledNumberElement.textContent =
stationA.board.currentNumber === null
? "—"
: String(stationA.board.currentNumber).padStart(2, "0");
}
walkMain(
[
{ x: -8.5, z: 5.85 },
kioskStand
],
"printing"
);
// ------------------------------------------------------------
// Ambient queues at desks B and C
// ------------------------------------------------------------
const ambientQueues = [];
function createAmbientQueue(station, initialNumber, customerColors) {
const serving = createPerson({
shirt: customerColors[0],
pants: "#3b4d57",
skin: "#c98c69",
hair: "#342b27",
scale: 0.86
});
const waiting = createPerson({
shirt: customerColors[1],
pants: "#3b4d57",
skin: "#dfa77e",
hair: "#49372f",
scale: 0.86
});
serving.root.position.set(station.counterSpot.x, 0, station.counterSpot.z);
waiting.root.position.set(station.queueSpot.x, 0, station.queueSpot.z);
serving.root.rotation.y = Math.PI;
waiting.root.rotation.y = Math.PI;
const servingTicket = createTicketDisplay();
const waitingTicket = createTicketDisplay();
servingTicket.setNumber(initialNumber);
waitingTicket.setNumber(initialNumber + 1);
const item = cube(
scene,
[0.4, 0.31, 0.36],
[station.x, 1.5, -2.3],
station.accent
);
item.visible = false;
ambientQueues.push({
station,
number: initialNumber,
serving,
waiting,
retired: null,
servingTicket,
waitingTicket,
item,
state: "service",
elapsed: 0,
duration: 3.4
});
}
createAmbientQueue(stationB, 42, ["#4f88c6", "#ef9b58"]);
createAmbientQueue(stationC, 63, ["#8a70c7", "#4e9f91"]);
function updateAmbientQueue(queue, dt) {
queue.elapsed += dt;
if (queue.state === "service") {
const t = THREE.MathUtils.clamp(queue.elapsed / queue.duration, 0, 1);
let z;
if (t < 0.3) {
const u = t / 0.3;
z = THREE.MathUtils.lerp(-3.2, -2.25, u);
} else if (t < 0.58) {
const u = (t - 0.3) / 0.28;
z = THREE.MathUtils.lerp(-2.25, -1.52, u);
} else if (t < 0.82) {
const u = (t - 0.58) / 0.24;
z = THREE.MathUtils.lerp(-1.52, -2.25, u);
} else {
const u = (t - 0.82) / 0.18;
z = THREE.MathUtils.lerp(-2.25, -3.2, u);
}
queue.item.visible = true;
queue.item.position.set(
queue.station.x,
1.48 + Math.sin(t * Math.PI) * 0.13,
z
);
queue.serving.reach = Math.sin(t * Math.PI) * 0.85;
queue.station.employee.reach = Math.sin(t * Math.PI) * 0.8;
if (queue.elapsed >= queue.duration) {
queue.item.visible = false;
queue.serving.reach = 0;
queue.station.employee.reach = 0;
// The next displayed ticket appears only after service.
queue.number = queue.number >= 99 ? 1 : queue.number + 1;
queue.station.board.setNumber(queue.number);
queue.station.board.pulse();
queue.waitingTicket.setNumber(queue.number);
queue.waitingTicket.pulse();
queue.retired = queue.serving;
queue.retired.root.visible = false;
queue.state = "approaching";
queue.elapsed = 0;
}
} else if (queue.state === "approaching") {
const arrived = movePerson(
queue.waiting,
queue.station.counterSpot,
1.7,
dt
);
if (arrived) {
queue.serving = queue.waiting;
queue.waiting = queue.retired;
queue.waiting.root.visible = true;
queue.waiting.root.position.set(
queue.station.queueSpot.x,
0,
queue.station.queueSpot.z
);
queue.waiting.root.rotation.y = Math.PI;
queue.waitingTicket.setNumber(queue.number + 1);
queue.waitingTicket.pulse();
queue.state = "service";
queue.elapsed = 0;
}
}
}
// ------------------------------------------------------------
// Ticket cards remain readable from every camera angle
// ------------------------------------------------------------
const ticketCards = [
{ display: mainTicketDisplay, owner: mainVisitor },
...ambientQueues.flatMap(queue => [
{ display: queue.servingTicket, owner: queue.serving },
{ display: queue.waitingTicket, owner: queue.waiting }
])
];
const ticketWorldPosition = new THREE.Vector3();
function updateTicketCards() {
ticketCards.forEach(({ display, owner }) => {
const visible = owner.root.visible;
display.group.visible = visible;
if (!visible) return;
owner.root.updateMatrixWorld(true);
ticketWorldPosition.set(0, 2.57, 0.12);
ticketWorldPosition.applyMatrix4(owner.root.matrixWorld);
display.group.position.copy(ticketWorldPosition);
display.group.quaternion.copy(camera.quaternion);
});
}
function updateDisplays(dt, time) {
const allDisplays = [
...stations.map(station => station.board),
...ticketCards.map(card => card.display)
];
allDisplays.forEach(display => {
display.pulseAmount = Math.max(0, display.pulseAmount - dt * 1.25);
const wobble =
Math.sin(time * 18) * 0.045 * display.pulseAmount;
display.group.scale.setScalar(
display.baseScale * (1 + wobble)
);
});
}
// ------------------------------------------------------------
// Pause control and animation loop
// ------------------------------------------------------------
const pauseButton = document.querySelector("#pause-button");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
const clock = new THREE.Clock();
let elapsed = 0;
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) {
elapsed += dt;
updateMain(dt);
ambientQueues.forEach(queue => updateAmbientQueue(queue, dt));
people.forEach(person => updatePerson(person, elapsed, dt));
updateDisplays(dt, elapsed);
}
updateCamera();
updateTicketCards();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```