Prompt specification
Build or customize the Three.js 3D scene "Queue ticket sequence dispenser" 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: Queue ticket sequence dispenser
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/queue-ticket-sequence-dispenser-x0453
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing service queues and numbered tickets. Model a dispenser with a numbered ticket emerging and three separate waiting tokens; display consecutive numbers clearly so their ordering is visually unambiguous. Stylized solid forms.
Working Three.js Starter (queue-ticket-sequence-dispenser-x0453):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Numbered Service Queue</title>
<style>
:root {
--ink: #19343d;
--muted: #66777b;
--paper: #fffaf0;
--coral: #ef6b5b;
--amber: #e7aa39;
--teal: #278d80;
--line: rgba(25, 52, 61, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7ebe5;
color: var(--ink);
font-family: Arial, Helvetica, sans-serif;
}
#app,
canvas {
width: 100%;
height: 100%;
}
canvas {
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
canvas.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.brand {
position: absolute;
top: 28px;
left: 30px;
display: flex;
align-items: center;
gap: 14px;
}
.brand-mark {
display: grid;
width: 48px;
height: 48px;
place-items: center;
border-radius: 14px;
background: var(--ink);
color: var(--paper);
font-size: 24px;
font-weight: 900;
box-shadow: 0 9px 25px rgba(25, 52, 61, 0.18);
}
.brand-copy {
padding: 9px 14px 10px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 250, 240, 0.94);
box-shadow: 0 9px 25px rgba(25, 52, 61, 0.09);
}
.brand-copy strong {
display: block;
font-size: 14px;
letter-spacing: 0.12em;
}
.brand-copy span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 12px;
}
.sequence {
position: absolute;
left: 50%;
bottom: 28px;
display: flex;
align-items: center;
gap: 9px;
max-width: calc(100vw - 24px);
padding: 10px;
overflow-x: auto;
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 19px;
background: rgba(255, 250, 240, 0.96);
box-shadow: 0 14px 38px rgba(25, 52, 61, 0.14);
scrollbar-width: none;
}
.sequence::-webkit-scrollbar {
display: none;
}
.ticket-card {
min-width: 104px;
padding: 10px 13px 11px;
border: 2px solid transparent;
border-radius: 13px;
background: #f3f0e7;
text-align: center;
}
.ticket-card span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
}
.ticket-card strong {
display: block;
font-size: 24px;
line-height: 1;
}
.ticket-card.next {
border-color: var(--coral);
background: #fff0eb;
color: var(--coral);
}
.ticket-card.second {
border-color: var(--amber);
background: #fff7df;
color: #a86c08;
}
.ticket-card.third {
border-color: var(--teal);
background: #e6f5f0;
color: var(--teal);
}
.ticket-card.issuing {
border-color: var(--ink);
background: var(--ink);
color: var(--paper);
}
.ticket-card.issuing span {
color: #bfd0d3;
}
.seq-arrow {
flex: 0 0 auto;
color: #8b999c;
font-size: 21px;
font-weight: 900;
}
.help {
position: absolute;
right: 28px;
top: 30px;
display: flex;
align-items: center;
gap: 10px;
}
.hint {
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 250, 240, 0.9);
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.03em;
}
#reset {
pointer-events: auto;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--paper);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 800;
cursor: pointer;
box-shadow: 0 7px 18px rgba(25, 52, 61, 0.09);
}
#reset:hover {
background: #fff;
transform: translateY(-1px);
}
@media (max-width: 760px) {
.brand {
top: 16px;
left: 16px;
}
.brand-mark {
width: 42px;
height: 42px;
border-radius: 12px;
}
.brand-copy {
padding: 8px 11px;
}
.brand-copy span {
display: none;
}
.help {
top: 16px;
right: 16px;
}
.hint {
display: none;
}
.sequence {
bottom: 14px;
gap: 6px;
padding: 7px;
border-radius: 15px;
}
.ticket-card {
min-width: 84px;
padding: 8px 9px;
}
.ticket-card strong {
font-size: 20px;
}
.seq-arrow {
font-size: 17px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="hud">
<div class="brand">
<div class="brand-mark">#</div>
<div class="brand-copy">
<strong>SERVICE QUEUE</strong>
<span>Wait in order toward the counter.</span>
</div>
</div>
<div class="sequence" aria-label="Queue order: 101, 102, 103. Ticket 104 is emerging.">
<div class="ticket-card next">
<span>NEXT</span>
<strong>#101</strong>
</div>
<div class="seq-arrow">→</div>
<div class="ticket-card second">
<span>WAITING</span>
<strong>#102</strong>
</div>
<div class="seq-arrow">→</div>
<div class="ticket-card third">
<span>WAITING</span>
<strong>#103</strong>
</div>
<div class="seq-arrow">→</div>
<div class="ticket-card issuing">
<span>ISSUING</span>
<strong>#104</strong>
</div>
</div>
<div class="help">
<div class="hint">Drag to orbit · Scroll or pinch to zoom</div>
<button id="reset" type="button">Reset view</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.querySelector("#app");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7ebe5);
scene.fog = new THREE.Fog(0xe7ebe5, 23, 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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional service queue with tickets 101, 102, 103 and ticket 104 emerging from a dispenser."
);
app.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(
-10,
10,
6,
-6,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 1.15, -0.65);
const defaultView = {
theta: 0.60,
phi: 0.94,
zoom: 1
};
const view = {
theta: defaultView.theta,
phi: defaultView.phi,
zoom: defaultView.zoom,
targetTheta: defaultView.theta,
targetPhi: defaultView.phi,
targetZoom: defaultView.zoom
};
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const horizontalView = 16.8;
const verticalView = Math.max(10.2, horizontalView / aspect);
camera.left = -verticalView * aspect / 2;
camera.right = verticalView * aspect / 2;
camera.top = verticalView / 2;
camera.bottom = -verticalView / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
const hemi = new THREE.HemisphereLight(0xffffff, 0x80928d, 2.05);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff4dc, 3.2);
key.position.set(-7, 13, 10);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -13;
key.shadow.camera.right = 13;
key.shadow.camera.top = 13;
key.shadow.camera.bottom = -13;
key.shadow.camera.near = 1;
key.shadow.camera.far = 35;
key.shadow.bias = -0.00025;
scene.add(key);
const fill = new THREE.DirectionalLight(0xcce8ef, 1.1);
fill.position.set(9, 7, -6);
scene.add(fill);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
const MAT = {
floor: material(0xdce3db),
floorEdge: material(0xcbd5cb),
wall: material(0xe3e8e1),
wallTrim: material(0xbac9c0),
ink: material(0x19343d),
inkSoft: material(0x294952),
cream: material(0xfff8e9),
coral: material(0xef6b5b),
amber: material(0xe7aa39),
teal: material(0x278d80),
dark: material(0x15272c),
screen: material(0x0c292d, { emissive: 0x12383b, emissiveIntensity: 0.35 }),
green: material(0x65c69c),
metal: material(0x9daaa5, { metalness: 0.3, roughness: 0.48 })
};
function addMesh(parent, geometry, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, w, h, d, mat, x = 0, y = 0, z = 0) {
return addMesh(parent, new THREE.BoxGeometry(w, h, d), mat, x, y, z);
}
function addCylinder(parent, radius, height, mat, x = 0, y = 0, z = 0, segments = 32) {
return addMesh(
parent,
new THREE.CylinderGeometry(radius, radius, height, segments),
mat,
x,
y,
z
);
}
function addBarBetween(parent, from, to, radius, mat) {
const direction = new THREE.Vector3().subVectors(to, from);
const length = direction.length();
const mesh = addMesh(
parent,
new THREE.CylinderGeometry(radius, radius, length, 12),
mat
);
mesh.position.copy(from).add(to).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function roundRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeSignTexture({
kicker = "",
title = "",
sub = "",
background = "#19343d",
accent = "#ef6b5b"
} = {}) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 320;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 22, canvas.height);
if (kicker) {
ctx.fillStyle = accent;
ctx.font = "800 34px Arial";
ctx.textAlign = "left";
ctx.textBaseline = "alphabetic";
ctx.fillText(kicker.toUpperCase(), 68, 70);
}
ctx.fillStyle = "#fffaf0";
ctx.font = "900 112px Arial";
ctx.fillText(title, 62, kicker ? 190 : 174);
if (sub) {
ctx.fillStyle = "#bfd0d3";
ctx.font = "700 27px Arial";
ctx.fillText(sub, 67, 250);
}
return makeTexture(canvas);
}
function makeNumberSprite(number, color) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 256, 256);
ctx.shadowColor = "rgba(25, 52, 61, 0.18)";
ctx.shadowBlur = 14;
ctx.shadowOffsetY = 6;
ctx.beginPath();
ctx.arc(128, 128, 108, 0, Math.PI * 2);
ctx.fillStyle = "#fffaf0";
ctx.fill();
ctx.shadowColor = "transparent";
ctx.lineWidth = 12;
ctx.strokeStyle = color;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "900 72px Arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(`#${number}`, 128, 137);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: makeTexture(canvas),
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(1.18, 1.18, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeTicketTexture(number) {
const canvas = document.createElement("canvas");
canvas.width = 300;
canvas.height = 440;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#fff8e9";
ctx.fillRect(0, 0, 300, 440);
ctx.strokeStyle = "#ef6b5b";
ctx.lineWidth = 12;
roundRect(ctx, 12, 12, 276, 416, 24);
ctx.stroke();
ctx.textAlign = "center";
ctx.fillStyle = "#ef6b5b";
ctx.font = "800 25px Arial";
ctx.fillText("SERVICE TICKET", 150, 62);
ctx.strokeStyle = "#d8cbb7";
ctx.lineWidth = 3;
ctx.setLineDash([10, 10]);
ctx.beginPath();
ctx.moveTo(35, 92);
ctx.lineTo(265, 92);
ctx.stroke();
ctx.setLineDash([]);
ctx.fillStyle = "#19343d";
ctx.font = "900 92px Arial";
ctx.fillText(`#${number}`, 150, 235);
ctx.fillStyle = "#ef6b5b";
ctx.font = "900 29px Arial";
ctx.fillText("NOW ISSUING", 150, 310);
ctx.fillStyle = "#738184";
ctx.font = "700 19px Arial";
ctx.fillText("PLEASE WAIT FOR YOUR NUMBER", 150, 365);
return makeTexture(canvas);
}
function addSignPlane(parent, texture, width, height, x, y, z) {
const plane = addMesh(
parent,
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
}),
x,
y,
z
);
plane.castShadow = false;
return plane;
}
// Floor and back wall.
addBox(scene, 19, 0.18, 14, MAT.floorEdge, 0, -0.14, -0.4);
addBox(scene, 18.8, 0.08, 13.8, MAT.floor, 0, -0.01, -0.4);
addBox(scene, 18.8, 6.2, 0.28, MAT.wall, 0, 3.05, -5.78);
addBox(scene, 18.8, 0.42, 0.38, MAT.wallTrim, 0, 0.18, -5.58);
addBox(scene, 18.8, 0.12, 0.4, MAT.coral, 0, 4.98, -5.57);
// Service counter.
const counter = new THREE.Group();
scene.add(counter);
addBox(counter, 7.4, 1.9, 1.5, MAT.ink, -1.2, 0.95, -4.2);
addBox(counter, 7.72, 0.24, 1.78, MAT.cream, -1.2, 2.02, -4.2);
addBox(counter, 7.35, 0.12, 0.12, MAT.coral, -1.2, 1.64, -3.425);
addSignPlane(
counter,
makeSignTexture({
kicker: "Customer care",
title: "SERVICE",
sub: "PLEASE HAVE YOUR TICKET READY",
background: "#294952",
accent: "#e7aa39"
}),
4.3,
1.12,
-1.2,
0.95,
-3.42
);
// Large queue board on the wall.
addBox(scene, 6.8, 1.68, 0.16, MAT.cream, -1.2, 3.76, -5.55);
addSignPlane(
scene,
makeSignTexture({
kicker: "Next ticket",
title: "#101",
sub: "ALL GUESTS PLEASE WATCH THE QUEUE DISPLAY",
background: "#19343d",
accent: "#ef6b5b"
}),
6.55,
1.48,
-1.2,
3.76,
-5.455
);
// Small counter monitor.
const monitor = new THREE.Group();
monitor.position.set(1.1, 2.1, -4.37);
scene.add(monitor);
addBox(monitor, 0.55, 0.08, 0.42, MAT.ink, 0, 0.06, 0);
addCylinder(monitor, 0.055, 0.42, MAT.metal, 0, 0.29, 0);
addBox(monitor, 1.22, 0.72, 0.14, MAT.ink, 0, 0.78, 0);
addBox(monitor, 1.05, 0.55, 0.02, MAT.green, 0, 0.78, 0.081);
// Desk bell.
addCylinder(scene, 0.24, 0.07, MAT.ink, -3.55, 2.17, -3.93);
const bellDome = addMesh(
scene,
new THREE.SphereGeometry(0.21, 24, 12),
MAT.metal,
-3.55,
2.25,
-3.93
);
bellDome.scale.y = 0.58;
// Queue lane markings.
for (let z = -2.75; z <= 3.45; z += 0.72) {
addBox(scene, 0.07, 0.025, 0.32, MAT.wallTrim, -2.48, 0.055, z);
addBox(scene, 0.07, 0.025, 0.32, MAT.wallTrim, 0.02, 0.055, z);
}
function addFloorArrow(x, z) {
const tip = new THREE.Vector3(x, 0.071, z - 0.24);
const left = new THREE.Vector3(x - 0.28, 0.071, z + 0.18);
const right = new THREE.Vector3(x + 0.28, 0.071, z + 0.18);
const barGeometry = new THREE.BoxGeometry(0.075, 0.025, 1);
const arrowMaterial = MAT.teal;
const leftBar = addMesh(scene, barGeometry, arrowMaterial);
const rightBar = addMesh(scene, barGeometry, arrowMaterial);
for (const [bar, end] of [
[leftBar, left],
[rightBar, right]
]) {
const direction = new THREE.Vector3().subVectors(end, tip);
bar.position.copy(tip).add(end).multiplyScalar(0.5);
bar.rotation.y = Math.atan2(direction.x, direction.z);
}
}
addFloorArrow(-1.25, -2.45);
addFloorArrow(-1.25, -0.35);
addFloorArrow(-1.25, 1.75);
// Queue stanchions and solid rope.
const postXs = 0.52;
const postZs = [-2.7, 0.15, 3.0];
for (const z of postZs) {
addCylinder(scene, 0.19, 0.08, MAT.ink, postXs, 0.09, z);
addCylinder(scene, 0.052, 1.05, MAT.ink, postXs, 0.63, z);
addMesh(
scene,
new THREE.SphereGeometry(0.09, 16, 10),
MAT.coral,
postXs,
1.18,
z
);
}
addBarBetween(
scene,
new THREE.Vector3(postXs, 1.06, postZs[0]),
new THREE.Vector3(postXs, 1.06, postZs[1]),
0.035,
MAT.coral
);
addBarBetween(
scene,
new THREE.Vector3(postXs, 1.06, postZs[1]),
new THREE.Vector3(postXs, 1.06, postZs[2]),
0.035,
MAT.coral
);
// Three separate numbered waiting tokens.
const tokenSpecs = [
{ number: 101, z: -1.65, color: "#ef6b5b", mat: MAT.coral },
{ number: 102, z: 0.45, color: "#e7aa39", mat: MAT.amber },
{ number: 103, z: 2.55, color: "#278d80", mat: MAT.teal }
];
let nextPulseRing;
for (const spec of tokenSpecs) {
const token = new THREE.Group();
token.position.set(-1.25, 0, spec.z);
scene.add(token);
addCylinder(token, 0.70, 0.25, spec.mat, 0, 0.16, 0, 40);
addCylinder(token, 0.54, 0.09, MAT.cream, 0, 0.33, 0, 40);
const rim = addMesh(
token,
new THREE.TorusGeometry(0.49, 0.032, 10, 40),
spec.mat,
0,
0.385,
0
);
rim.rotation.x = Math.PI / 2;
addCylinder(token, 0.035, 0.67, MAT.ink, 0, 0.69, 0, 16);
const badge = makeNumberSprite(spec.number, spec.color);
badge.position.set(0, 1.29, 0);
token.add(badge);
if (spec.number === 101) {
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0xef6b5b,
transparent: true,
opacity: 0.52,
side: THREE.DoubleSide,
toneMapped: false
});
nextPulseRing = addMesh(
scene,
new THREE.RingGeometry(0.82, 0.90, 64),
ringMaterial,
-1.25,
0.075,
spec.z
);
nextPulseRing.rotation.x = -Math.PI / 2;
nextPulseRing.castShadow = false;
nextPulseRing.receiveShadow = false;
}
}
// Ticket dispenser.
const dispenser = new THREE.Group();
dispenser.position.set(4.65, 0, -0.25);
scene.add(dispenser);
addBox(dispenser, 2.42, 0.22, 1.68, MAT.ink, 0, 0.11, 0);
addBox(dispenser, 2.10, 3.20, 1.40, MAT.inkSoft, 0, 1.82, 0);
addBox(dispenser, 2.24, 0.22, 1.54, MAT.cream, 0, 3.43, 0);
addBox(dispenser, 2.16, 0.12, 1.46, MAT.coral, 0, 3.23, 0);
addSignPlane(
dispenser,
makeSignTexture({
kicker: "Take one",
title: "TICKETS",
background: "#294952",
accent: "#e7aa39"
}),
1.78,
0.57,
0,
2.84,
0.706
);
// Dark dispensing slot.
addBox(dispenser, 1.46, 0.19, 0.075, MAT.dark, 0, 2.13, 0.713);
addBox(dispenser, 1.22, 0.065, 0.085, MAT.metal, 0, 2.03, 0.72);
// Dispenser screen.
addBox(dispenser, 1.68, 1.02, 0.08, MAT.dark, 0, 1.04, 0.716);
addSignPlane(
dispenser,
makeSignTexture({
kicker: "Now issuing",
title: "#104",
sub: "PLEASE TAKE YOUR TICKET",
background: "#0c292d",
accent: "#ef6b5b"
}),
1.53,
0.88,
0,
1.04,
0.762
);
// Small ticket button.
addCylinder(dispenser, 0.13, 0.09, MAT.coral, 0, 0.40, 0.75, 24);
const button = dispenser.children[dispenser.children.length - 1];
button.rotation.x = Math.PI / 2;
// The physical ticket emerging from the slot.
const ticketGroup = new THREE.Group();
ticketGroup.position.set(0, 2.13, 1.12);
ticketGroup.rotation.x = -0.075;
dispenser.add(ticketGroup);
addBox(ticketGroup, 1.05, 0.075, 1.55, MAT.cream, 0, 0, 0);
const ticketTop = addMesh(
ticketGroup,
new THREE.PlaneGeometry(1.02, 1.52),
new THREE.MeshStandardMaterial({
map: makeTicketTexture(104),
roughness: 0.9,
metalness: 0
}),
0,
0.041,
0
);
ticketTop.rotation.x = -Math.PI / 2;
ticketTop.castShadow = false;
// Custom camera controls: orbit, wheel zoom, touch pinch and keyboard.
const pointers = new Map();
let pinchDistance = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
renderer.domElement.classList.add("dragging");
}
pinchDistance = null;
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
view.targetTheta -= dx * 0.006;
view.targetPhi = THREE.MathUtils.clamp(
view.targetPhi + dy * 0.005,
0.42,
1.32
);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance) {
view.targetZoom = THREE.MathUtils.clamp(
view.targetZoom * (distance / pinchDistance),
0.72,
1.8
);
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = null;
if (pointers.size === 0) {
renderer.domElement.classList.remove("dragging");
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.targetZoom = THREE.MathUtils.clamp(
view.targetZoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.8
);
},
{ passive: false }
);
function resetView() {
view.targetTheta = defaultView.theta;
view.targetPhi = defaultView.phi;
view.targetZoom = defaultView.zoom;
}
document.querySelector("#reset").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
view.targetTheta += 0.12;
} else if (event.key === "ArrowRight") {
view.targetTheta -= 0.12;
} else if (event.key === "ArrowUp") {
view.targetPhi = Math.max(0.42, view.targetPhi - 0.08);
} else if (event.key === "ArrowDown") {
view.targetPhi = Math.min(1.32, view.targetPhi + 0.08);
} else if (event.key === "+" || event.key === "=") {
view.targetZoom = Math.min(1.8, view.targetZoom * 1.1);
} else if (event.key === "-") {
view.targetZoom = Math.max(0.72, view.targetZoom / 1.1);
} else if (event.key === "0") {
resetView();
}
});
const reduceMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const smoothing = 0.12;
view.theta = THREE.MathUtils.lerp(
view.theta,
view.targetTheta,
smoothing
);
view.phi = THREE.MathUtils.lerp(
view.phi,
view.targetPhi,
smoothing
);
view.zoom = THREE.MathUtils.lerp(
view.zoom,
view.targetZoom,
smoothing
);
const radius = 20;
const sinPhi = Math.sin(view.phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(view.theta),
cameraTarget.y + radius * Math.cos(view.phi),
cameraTarget.z + radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(cameraTarget);
camera.zoom = view.zoom;
camera.updateProjectionMatrix();
if (!reduceMotion) {
ticketGroup.position.z =
1.12 + Math.sin(elapsed * 1.55) * 0.045;
ticketGroup.rotation.x =
-0.075 + Math.sin(elapsed * 1.55) * 0.012;
const pulse = 1 + (Math.sin(elapsed * 2.5) + 1) * 0.055;
nextPulseRing.scale.setScalar(pulse);
nextPulseRing.material.opacity = 0.48 - (pulse - 1) * 2.1;
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```