Prompt specification
Build or customize the Three.js 3D scene "Numbered Waiting Tokens on a Bench" 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: Numbered Waiting Tokens on a Bench
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/numbered-waiting-tokens-on-a-bench-x3249
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing arrival order in a service queue. Place six numbered figures beside a single service window and ordered floor markers. The arrangement must clearly distinguish arrival order from physical distance to the desk. Stylized solid forms.
Working Three.js Starter (numbered-waiting-tokens-on-a-bench-x3249):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Arrival Order — Service Queue</title>
<style>
:root {
--ink: #263236;
--muted: #68777b;
--amber: #f1b94f;
--amber-dark: #a96f19;
--teal: #36a7a0;
--paper: rgba(250, 249, 244, 0.92);
--line: rgba(38, 50, 54, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eeece5;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.heading {
position: fixed;
top: 26px;
left: 28px;
z-index: 5;
pointer-events: none;
max-width: 410px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--amber-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(27px, 3.4vw, 45px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.key {
position: fixed;
top: 26px;
right: 26px;
z-index: 6;
width: min(330px, calc(100vw - 52px));
padding: 18px 19px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 14px 45px rgba(43, 51, 48, 0.11);
backdrop-filter: blur(12px);
}
.key h2 {
margin: 0 0 13px;
font-size: 13px;
letter-spacing: -0.01em;
}
.key-row {
display: flex;
align-items: center;
gap: 11px;
margin: 10px 0;
color: #536165;
font-size: 12px;
line-height: 1.35;
}
.symbol {
display: grid;
flex: 0 0 auto;
width: 32px;
height: 32px;
place-items: center;
border-radius: 50%;
font-size: 13px;
font-weight: 900;
}
.symbol.order {
color: #5d3c09;
background: var(--amber);
box-shadow: inset 0 0 0 2px rgba(117, 75, 13, 0.13);
}
.symbol.distance {
width: 42px;
height: 25px;
border-radius: 8px;
color: #176c69;
background: #e2f4f1;
border: 1px solid rgba(54, 167, 160, 0.4);
font-size: 10px;
}
.key-note {
margin: 14px 0 0;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #68777b;
font-size: 11px;
line-height: 1.55;
}
.key-note strong {
color: var(--ink);
}
.controls {
position: fixed;
left: 28px;
bottom: 24px;
z-index: 6;
display: flex;
align-items: center;
gap: 9px;
pointer-events: none;
}
.hint {
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 999px;
color: #627175;
background: rgba(250, 249, 244, 0.84);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
backdrop-filter: blur(10px);
}
button {
pointer-events: auto;
padding: 9px 13px;
border: 1px solid rgba(38, 50, 54, 0.16);
border-radius: 999px;
color: var(--ink);
background: rgba(250, 249, 244, 0.92);
font: inherit;
font-size: 10px;
font-weight: 800;
cursor: pointer;
box-shadow: 0 5px 18px rgba(43, 51, 48, 0.08);
}
button:hover {
background: #fff;
transform: translateY(-1px);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #667578;
background: #eeece5;
font-size: 13px;
font-weight: 700;
letter-spacing: 0.04em;
transition: opacity 0.4s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.heading {
top: 18px;
left: 18px;
max-width: calc(100vw - 36px);
}
h1 {
font-size: 29px;
}
.subtitle {
display: none;
}
.key {
top: auto;
right: 14px;
bottom: 14px;
width: min(310px, calc(100vw - 28px));
padding: 13px 14px;
}
.key h2 {
margin-bottom: 8px;
}
.key-row {
margin: 7px 0;
}
.key-note {
margin-top: 9px;
padding-top: 9px;
}
.controls {
left: 14px;
bottom: 220px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Building the service queue…</div>
<header class="heading">
<div class="eyebrow">Queue study / one service point</div>
<h1>Arrival order,<br />not just distance.</h1>
<p class="subtitle">
Six arrivals, one service window, and a deliberately zig-zagged queue.
</p>
</header>
<aside class="key" aria-label="Queue diagram key">
<h2>How to read the diagram</h2>
<div class="key-row">
<span class="symbol order">1–6</span>
<span><strong>Arrival order</strong> is shown by the amber numbers on people and floor markers.</span>
</div>
<div class="key-row">
<span class="symbol distance">3.9 m</span>
<span><strong>Physical proximity</strong> is shown by the teal distance labels and route.</span>
</div>
<p class="key-note">
The queue turns, so physical closeness is not the same as arrival order.
For example, <strong>4 arrived before 5</strong>, even though 5 is closer to the desk.
</p>
</aside>
<div class="controls">
<span class="hint">Drag to orbit · Scroll to zoom</span>
<button id="reset" 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 and scene
// -------------------------------------------------------------------------
const loading = document.getElementById("loading");
const resetButton = document.getElementById("reset");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeeece5);
scene.fog = new THREE.Fog(0xeeece5, 22, 42);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional service queue diagram"
);
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff9e9, 0x7d8a85, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3d7, 3.2);
keyLight.position.set(5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d9df, 1.25);
fillLight.position.set(-7, 5, -4);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...extra
});
const M = {
ground: material(0xdedbd2),
platform: material(0xf0eee7),
platformEdge: material(0xd7d3c8),
wall: material(0xd5d2c8),
frame: material(0xf7f4eb),
recess: material(0x34474a),
counter: material(0xe9e4d8),
counterFront: material(0xc8c1b2),
teal: material(0x36a7a0),
tealDark: material(0x247e79),
amber: material(0xf1b94f),
amberDark: material(0xa96f19),
dark: material(0x303a3c),
hair: material(0x303335),
shoes: material(0x34383a)
};
// -------------------------------------------------------------------------
// Procedural labels and textures
// -------------------------------------------------------------------------
function roundedRectPath(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function canvasTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
draw(ctx, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function numberBadgeTexture(number) {
return canvasTexture(256, 256, (ctx) => {
ctx.clearRect(0, 0, 256, 256);
ctx.fillStyle = "rgba(34, 39, 37, 0.15)";
ctx.beginPath();
ctx.arc(132, 136, 103, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#f1b94f";
ctx.beginPath();
ctx.arc(128, 126, 101, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = "#fff1c7";
ctx.lineWidth = 8;
ctx.beginPath();
ctx.arc(128, 126, 91, 0, Math.PI * 2);
ctx.stroke();
ctx.fillStyle = "#51380e";
ctx.font = "900 132px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(String(number), 128, 135);
});
}
function floorNumberTexture(number) {
return canvasTexture(256, 256, (ctx) => {
ctx.clearRect(0, 0, 256, 256);
ctx.fillStyle = "#51380e";
ctx.font = "900 176px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(String(number), 128, 137);
});
}
function distanceTexture(distance) {
return canvasTexture(320, 90, (ctx) => {
ctx.clearRect(0, 0, 320, 90);
roundedRectPath(ctx, 5, 5, 310, 80, 22);
ctx.fillStyle = "rgba(249, 250, 245, 0.96)";
ctx.fill();
ctx.strokeStyle = "#36a7a0";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = "#247e79";
ctx.font = "800 42px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(`≈ ${distance.toFixed(1)} m`, 160, 48);
});
}
function routeTexture() {
return canvasTexture(360, 80, (ctx) => {
ctx.clearRect(0, 0, 360, 80);
roundedRectPath(ctx, 4, 6, 352, 68, 18);
ctx.fillStyle = "rgba(226, 244, 241, 0.95)";
ctx.fill();
ctx.strokeStyle = "rgba(54, 167, 160, 0.7)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = "#247e79";
ctx.font = "800 28px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("PHYSICAL ROUTE TO DESK", 180, 42);
});
}
function deskTexture() {
return canvasTexture(360, 90, (ctx) => {
ctx.clearRect(0, 0, 360, 90);
roundedRectPath(ctx, 5, 5, 350, 80, 18);
ctx.fillStyle = "rgba(226, 244, 241, 0.97)";
ctx.fill();
ctx.strokeStyle = "#36a7a0";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = "#247e79";
ctx.font = "900 38px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("SERVICE DESK", 180, 47);
});
}
function serviceSignTexture() {
return canvasTexture(1024, 250, (ctx) => {
ctx.fillStyle = "#2f4144";
ctx.fillRect(0, 0, 1024, 250);
ctx.fillStyle = "#f1b94f";
roundedRectPath(ctx, 34, 35, 180, 180, 28);
ctx.fill();
ctx.fillStyle = "#51380e";
ctx.font = "900 132px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("1", 124, 132);
ctx.fillStyle = "#b9c8c7";
ctx.font = "800 27px Arial, sans-serif";
ctx.textAlign = "left";
ctx.fillText("SERVICE WINDOW 01", 255, 77);
ctx.fillStyle = "#ffffff";
ctx.font = "900 69px Arial, sans-serif";
ctx.fillText("NOW SERVING", 255, 151);
ctx.fillStyle = "#f1b94f";
ctx.font = "900 30px Arial, sans-serif";
ctx.fillText("ONE ACTIVE SERVICE POINT", 257, 204);
});
}
function makeSprite(texture, width, height) {
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(width, height, 1);
return sprite;
}
function addBox(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, args, position, mat) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(...args),
mat
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Ground and queue platform
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
M.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.14;
ground.receiveShadow = true;
scene.add(ground);
addBox(
scene,
[10.2, 0.14, 4.35],
[-0.15, -0.07, 0.25],
M.platform
);
addBox(
scene,
[10.28, 0.07, 4.43],
[-0.15, -0.12, 0.25],
M.platformEdge
);
// A narrow teal edge identifies the active queue route.
addBox(
scene,
[9.95, 0.025, 0.055],
[-0.25, 0.018, 2.38],
M.teal
);
// -------------------------------------------------------------------------
// Single service window
// -------------------------------------------------------------------------
const windowGroup = new THREE.Group();
scene.add(windowGroup);
// Back wall with a dark inset representing the one open window.
addBox(windowGroup, [4.65, 3.55, 0.24], [4.05, 1.7, -2.42], M.wall);
addBox(windowGroup, [2.72, 1.68, 0.12], [4.05, 1.77, -2.25], M.recess);
// Interior depth.
addBox(windowGroup, [2.58, 1.54, 0.1], [4.05, 1.76, -2.38], M.tealDark);
// Window frame.
addBox(windowGroup, [0.42, 2.95, 0.38], [2.73, 1.68, -2.15], M.frame);
addBox(windowGroup, [0.42, 2.95, 0.38], [5.37, 1.68, -2.15], M.frame);
addBox(windowGroup, [3.05, 0.38, 0.38], [4.05, 2.85, -2.15], M.frame);
// Counter and front panel.
addBox(windowGroup, [3.28, 0.25, 1.35], [4.05, 0.83, -1.55], M.counter);
addBox(windowGroup, [3.04, 0.72, 0.2], [4.05, 0.36, -1.86], M.counterFront);
addBox(windowGroup, [3.12, 0.055, 0.06], [4.05, 0.74, -0.86], M.teal);
// Service sign.
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(3.5, 0.85),
new THREE.MeshBasicMaterial({
map: serviceSignTexture()
})
);
sign.position.set(4.05, 3.05, -2.13);
windowGroup.add(sign);
// A small bell-like desk object, kept abstract and unnumbered.
const bellBase = addCylinder(
windowGroup,
[0.14, 0.18, 0.07, 20],
[4.96, 1.01, -1.34],
M.dark
);
bellBase.castShadow = true;
const servicePoint = new THREE.Vector3(3.55, 0.1, -0.72);
const deskRing = new THREE.Mesh(
new THREE.TorusGeometry(0.23, 0.027, 8, 32),
M.teal
);
deskRing.rotation.x = Math.PI / 2;
deskRing.position.copy(servicePoint);
deskRing.position.y = 0.075;
scene.add(deskRing);
const deskLabel = makeSprite(deskTexture(), 1.4, 0.35);
deskLabel.position.set(3.55, 0.38, -1.02);
scene.add(deskLabel);
// -------------------------------------------------------------------------
// Queue positions
//
// The path deliberately switches back. Position 5 is physically closer
// to the desk than position 4, despite having arrived later.
// -------------------------------------------------------------------------
const markerPositions = [
new THREE.Vector3(2.65, 0, -0.15),
new THREE.Vector3(1.45, 0, 0.45),
new THREE.Vector3(0.05, 0, -0.15),
new THREE.Vector3(-1.30, 0, 0.45),
new THREE.Vector3(-0.35, 0, 1.45),
new THREE.Vector3(-2.25, 0, 1.65)
];
const figureOffsets = [
new THREE.Vector3(0.34, 0, -0.45),
new THREE.Vector3(-0.38, 0, 0.16),
new THREE.Vector3(0.30, 0, -0.45),
new THREE.Vector3(-0.40, 0, -0.22),
new THREE.Vector3(0.38, 0, -0.35),
new THREE.Vector3(-0.35, 0, -0.25)
];
const shirtColors = [
0x59717b,
0xb66e51,
0x7b6e8c,
0x748963,
0xb08a4a,
0x60818a
];
const skinColors = [
0xd7a27d,
0x8f6047,
0xc98d67,
0xe0b18e,
0x9b684b,
0xd59b74
];
function createFigure(number, shirtColor, skinColor) {
const figure = new THREE.Group();
const shirt = material(shirtColor);
const skin = material(skinColor);
// Legs and shoes.
addCylinder(figure, [0.11, 0.12, 0.62, 8], [-0.13, 0.34, 0], M.dark);
addCylinder(figure, [0.11, 0.12, 0.62, 8], [0.13, 0.34, 0], M.dark);
addBox(figure, [0.20, 0.11, 0.31], [-0.13, 0.065, 0.06], M.shoes);
addBox(figure, [0.20, 0.11, 0.31], [0.13, 0.065, 0.06], M.shoes);
// Hips and faceted torso.
addCylinder(figure, [0.25, 0.27, 0.20, 8], [0, 0.70, 0], M.dark);
addCylinder(figure, [0.29, 0.34, 0.78, 8], [0, 1.15, 0], shirt);
// Neck and head.
addCylinder(figure, [0.10, 0.11, 0.13, 8], [0, 1.60, 0], skin);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.225, 12, 9),
skin
);
head.position.set(0, 1.80, 0);
head.castShadow = true;
figure.add(head);
// Solid, low-poly hair cap.
const hair = new THREE.Mesh(
new THREE.SphereGeometry(0.232, 12, 8, 0, Math.PI * 2, 0, Math.PI * 0.52),
M.hair
);
hair.position.set(0, 1.83, -0.015);
hair.scale.set(1.02, 0.75, 1.03);
hair.castShadow = true;
figure.add(hair);
// Arms and hands.
const leftArm = addCylinder(
figure,
[0.075, 0.09, 0.56, 7],
[-0.35, 1.10, 0.01],
shirt
);
leftArm.rotation.z = -0.13;
const rightArm = addCylinder(
figure,
[0.075, 0.09, 0.56, 7],
[0.35, 1.10, 0.01],
shirt
);
rightArm.rotation.z = 0.13;
const leftHand = new THREE.Mesh(
new THREE.SphereGeometry(0.09, 8, 6),
skin
);
leftHand.position.set(-0.39, 0.80, 0.02);
leftHand.castShadow = true;
figure.add(leftHand);
const rightHand = new THREE.Mesh(
new THREE.SphereGeometry(0.09, 8, 6),
skin
);
rightHand.position.set(0.39, 0.80, 0.02);
rightHand.castShadow = true;
figure.add(rightHand);
// Large numbered chest badge.
const badge = makeSprite(numberBadgeTexture(number), 0.57, 0.57);
badge.position.set(0, 1.20, 0.34);
badge.renderOrder = 4;
figure.add(badge);
return figure;
}
function createFloorMarker(arrivalNumber, position) {
const group = new THREE.Group();
group.position.copy(position);
const disc = addCylinder(
group,
[0.38, 0.38, 0.065, 36],
[0, 0.035, 0],
M.amber
);
disc.castShadow = false;
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.365, 0.025, 8, 36),
M.amberDark
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.072;
group.add(ring);
const number = new THREE.Mesh(
new THREE.PlaneGeometry(0.60, 0.60),
new THREE.MeshBasicMaterial({
map: floorNumberTexture(arrivalNumber),
transparent: true,
depthWrite: false
})
);
number.rotation.x = -Math.PI / 2;
number.position.y = 0.074;
number.renderOrder = 2;
group.add(number);
scene.add(group);
}
const metersPerUnit = 0.8;
markerPositions.forEach((position, index) => {
const number = index + 1;
createFloorMarker(number, position);
const figure = createFigure(
number,
shirtColors[index],
skinColors[index]
);
figure.position.copy(position).add(figureOffsets[index]);
figure.position.y = 0.02;
figure.rotation.y = Math.PI / 2;
scene.add(figure);
// Physical-distance label, placed radially away from the desk.
const away = position.clone().sub(servicePoint);
away.y = 0;
away.normalize();
const labelPosition = position.clone().addScaledVector(away, 0.85);
const directDistance = position.distanceTo(servicePoint) * metersPerUnit;
const distanceLabel = makeSprite(
distanceTexture(directDistance),
1.18,
0.33
);
distanceLabel.position.set(labelPosition.x, 0.37, labelPosition.z);
distanceLabel.renderOrder = 5;
scene.add(distanceLabel);
});
// -------------------------------------------------------------------------
// Physical route drawn as a crisp zig-zag on the floor
// -------------------------------------------------------------------------
function cylinderBetween(start, end, radius, mat) {
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 8),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function arrowBetween(start, end, mat) {
const direction = end.clone().sub(start).normalize();
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.095, 0.25, 10),
mat
);
arrow.position.copy(start).add(end).multiplyScalar(0.5);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
scene.add(arrow);
}
const routePoints = [servicePoint, ...markerPositions];
for (let i = 0; i < routePoints.length - 1; i++) {
const start = routePoints[i].clone();
const end = routePoints[i + 1].clone();
start.y = 0.075;
end.y = 0.075;
cylinderBetween(start, end, 0.027, M.teal);
}
// Arrows point toward the desk, not toward a particular arrival number.
for (let i = 0; i < markerPositions.length - 1; i++) {
const from = markerPositions[i + 1].clone();
const to = i === 0 ? servicePoint : markerPositions[i].clone();
from.y = 0.09;
to.y = 0.09;
arrowBetween(from, to, M.tealDark);
}
const routeLabel = makeSprite(routeTexture(), 2.05, 0.46);
routeLabel.position.set(1.25, 0.32, 1.87);
routeLabel.renderOrder = 5;
scene.add(routeLabel);
// -------------------------------------------------------------------------
// Custom camera controls
// -------------------------------------------------------------------------
const controls = {
theta: 0.65,
phi: 0.92,
radius: 14.6,
target: new THREE.Vector3(-0.15, 0.72, 0.25)
};
const defaultControls = {
theta: controls.theta,
phi: controls.phi,
radius: controls.radius
};
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const responsiveScale = Math.max(1, 0.95 / aspect);
const radius = controls.radius * responsiveScale;
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x + radius * sinPhi * Math.sin(controls.theta),
controls.target.y + radius * cosPhi,
controls.target.z + radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetView() {
controls.theta = defaultControls.theta;
controls.phi = defaultControls.phi;
controls.radius = defaultControls.radius;
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
let activePointerId = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
activePointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
controls.theta -= deltaX * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + deltaY * 0.005,
0.42,
1.38
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function stopDragging(event) {
if (event && activePointerId !== null) {
if (renderer.domElement.hasPointerCapture(activePointerId)) {
renderer.domElement.releasePointerCapture(activePointerId);
}
}
dragging = false;
activePointerId = null;
renderer.domElement.style.cursor = "grab";
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("lostpointercapture", stopDragging);
renderer.domElement.style.cursor = "grab";
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.012,
9.5,
20
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
resetButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
controls.theta += 0.09;
} else if (event.key === "ArrowRight") {
controls.theta -= 0.09;
} else if (event.key === "ArrowUp") {
controls.phi = Math.max(0.42, controls.phi - 0.06);
} else if (event.key === "ArrowDown") {
controls.phi = Math.min(1.38, controls.phi + 0.06);
} else if (event.key === "+" || event.key === "=") {
controls.radius = Math.max(9.5, controls.radius - 0.7);
} else if (event.key === "-") {
controls.radius = Math.min(20, controls.radius + 0.7);
} else {
return;
}
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
});
// -------------------------------------------------------------------------
// Render
// -------------------------------------------------------------------------
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(() => loading.classList.add("hidden"));
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```