Prompt specification
Build or customize the Three.js 3D scene "Shopfront with service and customer routes" 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: Shopfront with service and customer routes
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shopfront-with-service-and-customer-routes-x2210
Scene Description Prompt:
A low-poly shop separates customer and delivery routes until they reach the service counter. Make one HTML file using Three.js from cdnjs.
Working Three.js Starter (shopfront-with-service-and-customer-routes-x2210):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Two Ways, One Counter</title>
<style>
:root {
--ink: #24313a;
--muted: #6d777d;
--panel: rgba(255, 255, 255, 0.9);
--customer: #159f91;
--delivery: #ed7b32;
--border: rgba(36, 49, 58, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e4da;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.intro {
position: absolute;
top: 22px;
left: 22px;
width: min(340px, calc(100vw - 44px));
padding: 20px 21px 18px;
border: 1px solid var(--border);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 18px 45px rgba(50, 57, 59, 0.12);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.eyebrow {
margin-bottom: 7px;
color: #8b7654;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 34px);
line-height: 1.04;
letter-spacing: -0.045em;
}
.intro p {
margin: 11px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
display: grid;
gap: 8px;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: #4d5960;
font-size: 12px;
font-weight: 650;
}
.swatch {
width: 23px;
height: 8px;
flex: 0 0 auto;
border-radius: 999px;
}
.swatch.customer {
background: var(--customer);
}
.swatch.delivery {
background: var(--delivery);
}
.controls {
position: absolute;
right: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
max-width: min(660px, calc(100vw - 44px));
pointer-events: auto;
}
.control-group {
display: flex;
flex-wrap: wrap;
gap: 5px;
padding: 5px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 12px 32px rgba(50, 57, 59, 0.1);
backdrop-filter: blur(16px);
}
button {
appearance: none;
border: 0;
border-radius: 10px;
padding: 9px 12px;
background: transparent;
color: #5d686e;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
button:hover {
background: #f0f2ef;
color: var(--ink);
}
button:active {
transform: translateY(1px);
}
button.active {
background: var(--ink);
color: white;
}
button[data-route="customer"].active {
background: var(--customer);
}
button[data-route="delivery"].active {
background: var(--delivery);
}
.hint {
position: absolute;
left: 22px;
bottom: 22px;
padding: 10px 13px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(255, 255, 255, 0.78);
color: #6d777d;
font-size: 11px;
font-weight: 650;
backdrop-filter: blur(12px);
}
.key {
display: inline-block;
margin: 0 2px;
color: #344149;
font-weight: 850;
}
@media (max-width: 700px) {
.intro {
top: 12px;
left: 12px;
width: min(300px, calc(100vw - 24px));
padding: 15px;
}
.intro p {
display: none;
}
.legend {
margin-top: 12px;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
max-width: none;
justify-content: center;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div class="ui">
<section class="intro">
<div class="eyebrow">Low-poly retail study</div>
<h1>Two Ways,<br />One Counter.</h1>
<p>
Customer and delivery arrivals remain physically separated through
separate entrances and aisles, meeting only at the service counter.
</p>
<div class="legend" aria-label="Route legend">
<div class="legend-item">
<span class="swatch customer"></span>
Customer shopping route
</div>
<div class="legend-item">
<span class="swatch delivery"></span>
Delivery and collection route
</div>
</div>
</section>
<div class="controls">
<div class="control-group" aria-label="Route visibility">
<button class="route-button active" data-route="all">All routes</button>
<button class="route-button" data-route="customer">Customer</button>
<button class="route-button" data-route="delivery">Delivery</button>
</div>
<div class="control-group" aria-label="Scene controls">
<button id="animateButton" class="active">Pause motion</button>
<button id="counterButton">Counter view</button>
<button id="resetButton">Reset view</button>
</div>
</div>
<div class="hint">
<span class="key">Drag</span> to orbit ·
<span class="key">Scroll / pinch</span> to zoom
</div>
</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 renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e4da);
scene.fog = new THREE.Fog(0xe8e4da, 29, 55);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const clock = new THREE.Clock();
const hemisphere = new THREE.HemisphereLight(0xfff9eb, 0x8fa3a0, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2d9, 3.2);
sun.position.set(-6, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0003;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8e7ee, 0.75);
fill.position.set(9, 7, -8);
scene.add(fill);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
function addBox(
parent,
width,
height,
depth,
color,
x = 0,
y = 0,
z = 0,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
standard(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
color,
x = 0,
y = 0,
z = 0,
radialSegments = 8,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
radialSegments
),
standard(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Architecture
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(120, 120),
standard(0xe8e4da)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.55;
ground.receiveShadow = true;
scene.add(ground);
const shop = new THREE.Group();
scene.add(shop);
addBox(shop, 15.4, 0.5, 11.4, 0xc5bda9, 0, -0.29, 0);
addBox(shop, 14.6, 0.12, 10.6, 0xf4f0e7, 0, 0.02, 0);
// Back and left walls; front and right sides are cut away for visibility.
addBox(shop, 14.75, 3.85, 0.24, 0xe9dfcf, 0, 1.92, -5.12);
addBox(shop, 0.24, 3.85, 10.55, 0xe2d7c5, -7.25, 1.92, -0.08);
// Wall trim.
addBox(shop, 14.55, 0.16, 0.08, 0xbcae98, 0, 0.45, -4.97);
addBox(shop, 0.08, 0.16, 10.2, 0xbcae98, -7.10, 0.45, -0.08);
// Colored floor zones.
const customerZone = addBox(
shop,
6.72,
0.018,
9.75,
0x37b7a8,
-3.68,
0.091,
-0.08,
{ transparent: true, opacity: 0.105, depthWrite: false }
);
const deliveryZone = addBox(
shop,
6.85,
0.018,
9.75,
0xf09a5a,
3.77,
0.092,
-0.08,
{ transparent: true, opacity: 0.115, depthWrite: false }
);
// Central divider.
const divider = new THREE.Group();
shop.add(divider);
addBox(divider, 0.22, 1.35, 6.0, 0xf0e9dc, 0, 0.68, 0.60);
addBox(divider, 0.28, 0.12, 6.06, 0xc5b69d, 0, 1.40, 0.60);
addBox(divider, 0.045, 1.02, 5.84, 0x159f91, -0.128, 0.73, 0.60);
addBox(divider, 0.045, 1.02, 5.84, 0xed7b32, 0.128, 0.73, 0.60);
// Delivery dock outside the cutaway wall.
addBox(shop, 1.5, 0.24, 3.5, 0xaeb5ad, 8.03, -0.06, 3.55);
addBox(shop, 0.18, 0.26, 3.15, 0x798782, 8.55, 0.08, 3.55);
// -------------------------------------------------------------------------
// Text and sign helpers
// -------------------------------------------------------------------------
function roundedRect(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 createLabelTexture(title, subtitle, background, foreground) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 8, 1008, 240, 30);
ctx.fillStyle = background;
ctx.fill();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
if (subtitle) {
ctx.font = "800 76px system-ui, sans-serif";
ctx.fillText(title, 512, 100);
ctx.globalAlpha = 0.78;
ctx.font = "600 30px system-ui, sans-serif";
ctx.fillText(subtitle, 512, 172);
} else {
ctx.font = "800 78px system-ui, sans-serif";
ctx.fillText(title, 512, 132);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function addBillboard(
title,
subtitle,
background,
foreground,
x,
y,
z,
width = 3.3
) {
const texture = createLabelTexture(
title,
subtitle,
background,
foreground
);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.position.set(x, y, z);
sprite.scale.set(width, width * 0.25, 1);
scene.add(sprite);
return sprite;
}
function addWallSign(
title,
subtitle,
background,
foreground,
x,
y,
z,
width,
height
) {
const texture = createLabelTexture(
title,
subtitle,
background,
foreground
);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
toneMapped: false
})
);
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
function addFloorLabel(text, x, z, color, width = 2.2) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "800 62px system-ui, sans-serif";
ctx.fillStyle = color;
ctx.fillText(text, 384, 96);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, width * 0.25),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, 0.115, z);
scene.add(mesh);
return mesh;
}
addWallSign(
"SERVICE COUNTER",
"ONE COUNTER · TWO ARRIVAL ROUTES",
"#263740",
"#fffaf0",
0,
2.82,
-4.965,
5.8,
1.12
);
// Decorative back-wall windows.
for (const x of [-5.0, 5.0]) {
addBox(shop, 2.25, 1.5, 0.12, 0xb7c8c5, x, 2.15, -4.94);
addBox(shop, 1.96, 1.23, 0.06, 0x9fc4c8, x, 2.15, -4.85);
addBox(shop, 0.07, 1.3, 0.08, 0xf3eee3, x, 2.15, -4.80);
addBox(shop, 2.05, 0.07, 0.08, 0xf3eee3, x, 2.15, -4.80);
}
// Left-wall brand plaque.
const brand = addWallSign(
"NORTH & PINE",
"MARKET",
"#263740",
"#f7efdf",
-7.105,
2.65,
-0.25,
3.8,
0.95
);
brand.rotation.y = Math.PI / 2;
// -------------------------------------------------------------------------
// Entrances
// -------------------------------------------------------------------------
// Customer entrance: front-facing arch.
addBox(shop, 0.16, 2.45, 0.16, 0x159f91, -6.08, 1.22, 4.82);
addBox(shop, 0.16, 2.45, 0.16, 0x159f91, -4.12, 1.22, 4.82);
addBox(shop, 2.12, 0.16, 0.16, 0x159f91, -5.10, 2.44, 4.82);
addBillboard(
"CUSTOMERS",
"SHOPPING ENTRANCE",
"#159f91",
"#ffffff",
-5.10,
2.72,
4.76,
3.3
);
// Delivery entrance: side-facing gate.
addBox(shop, 0.16, 2.45, 0.16, 0xed7b32, 6.68, 1.22, 2.36);
addBox(shop, 0.16, 2.45, 0.16, 0xed7b32, 6.68, 1.22, 4.76);
addBox(shop, 0.16, 0.16, 2.56, 0xed7b32, 6.68, 2.44, 3.56);
addBillboard(
"DELIVERIES",
"COLLECTION & DROP-OFF",
"#ed7b32",
"#ffffff",
6.90,
2.74,
3.56,
3.45
);
addFloorLabel("CUSTOMERS", -4.85, 3.72, "#159f91", 2.55);
addFloorLabel("DELIVERIES", 4.52, 4.42, "#ed7b32", 2.65);
// -------------------------------------------------------------------------
// Service counter
// -------------------------------------------------------------------------
const counter = new THREE.Group();
shop.add(counter);
addBox(counter, 6.2, 1.45, 1.45, 0x304c55, 0, 0.73, -3.48);
addBox(counter, 6.38, 0.18, 1.63, 0xd4a66f, 0, 1.54, -3.48);
addBox(counter, 2.85, 1.03, 0.055, 0x159f91, -1.55, 0.88, -2.735);
addBox(counter, 2.85, 1.03, 0.055, 0xed7b32, 1.55, 0.88, -2.735);
addWallSign(
"PICK-UP",
"",
"#159f91",
"#ffffff",
-1.55,
0.93,
-2.697,
1.38,
0.35
);
addWallSign(
"DROP-OFF",
"",
"#ed7b32",
"#ffffff",
1.55,
0.93,
-2.697,
1.38,
0.35
);
// Register.
addBox(counter, 0.62, 0.12, 0.46, 0x263740, -1.95, 1.72, -3.40);
const registerScreen = addBox(
counter,
0.66,
0.44,
0.09,
0x7ac2c0,
-1.95,
2.02,
-3.53
);
registerScreen.rotation.x = -0.22;
addBox(counter, 0.4, 0.13, 0.32, 0x263740, -2.72, 1.69, -3.32);
// Parcels and a service bell.
addBox(counter, 0.75, 0.42, 0.55, 0xc98a52, 1.65, 1.83, -3.47);
addBox(counter, 0.62, 0.32, 0.48, 0xe1b779, 1.67, 2.19, -3.47);
addBox(counter, 0.08, 0.44, 0.57, 0xf1dfbd, 1.67, 2.19, -3.47);
addCylinder(counter, 0.15, 0.17, 0.08, 0xd2a85f, 0.35, 1.69, -3.16, 10);
const bell = new THREE.Mesh(
new THREE.SphereGeometry(0.14, 10, 6, 0, Math.PI * 2, 0, Math.PI / 2),
standard(0xe8b968)
);
bell.position.set(0.35, 1.73, -3.16);
bell.castShadow = true;
counter.add(bell);
// -------------------------------------------------------------------------
// Shelves and products
// -------------------------------------------------------------------------
const productColors = [
0xdd7858,
0xe7b84d,
0x68a77c,
0x6e9eb8,
0x9c78a8,
0xe18b9d,
0xd8c28b
];
function addShelf(x, z, rotation, width = 3.0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
shop.add(group);
addBox(group, width, 0.12, 0.72, 0x8e7356, 0, 0.18, 0);
addBox(group, width, 0.12, 0.72, 0x9b8062, 0, 0.78, 0);
addBox(group, width, 0.12, 0.72, 0x8e7356, 0, 1.38, 0);
addBox(group, width, 0.12, 0.72, 0x9b8062, 0, 1.98, 0);
addBox(group, 0.12, 2.12, 0.72, 0x80684f, -width / 2 + 0.06, 1.06, 0);
addBox(group, 0.12, 2.12, 0.72, 0x80684f, width / 2 - 0.06, 1.06, 0);
const levels = [0.24, 0.84, 1.44, 2.04];
const rows = [0, 1, 2];
levels.forEach((level, levelIndex) => {
if (levelIndex === levels.length - 1) return;
rows.forEach((row) => {
const count = Math.max(3, Math.floor(width / 0.48));
for (let i = 0; i < count; i++) {
const productWidth = 0.22 + ((i + levelIndex) % 3) * 0.035;
const productHeight =
0.25 + ((i + row + levelIndex) % 3) * 0.055;
const color =
productColors[
(i * 3 + row * 2 + levelIndex) % productColors.length
];
addBox(
group,
productWidth,
productHeight,
0.25,
color,
-width / 2 + 0.32 + i * ((width - 0.55) / count),
level + productHeight / 2,
(row - 1) * 0.22
);
}
});
});
return group;
}
addShelf(-6.35, -0.55, Math.PI / 2, 3.45);
addShelf(-1.80, 0.75, 0, 2.50);
// Produce display table.
const produce = new THREE.Group();
produce.position.set(-2.0, 0, 2.75);
shop.add(produce);
addBox(produce, 2.2, 0.18, 0.9, 0x8b7458, 0, 0.88, 0);
addBox(produce, 0.12, 0.82, 0.12, 0x7a674f, -0.85, 0.42, 0);
addBox(produce, 0.12, 0.82, 0.12, 0x7a674f, 0.85, 0.42, 0);
const produceColors = [0xe7a843, 0xd7684c, 0x75a85c, 0xe0c454];
for (let i = 0; i < 16; i++) {
const fruit = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.12, 1),
standard(produceColors[i % produceColors.length])
);
fruit.position.set(
-0.82 + (i % 8) * 0.235,
1.04 + (i % 2) * 0.07,
(i < 8 ? -0.19 : 0.19)
);
fruit.castShadow = true;
produce.add(fruit);
}
// -------------------------------------------------------------------------
// Plants
// -------------------------------------------------------------------------
function addPlant(x, z, scale = 1) {
const plant = new THREE.Group();
plant.position.set(x, 0, z);
plant.scale.setScalar(scale);
shop.add(plant);
addCylinder(plant, 0.32, 0.40, 0.48, 0xc98860, 0, 0.24, 0, 7);
addCylinder(plant, 0.045, 0.065, 1.1, 0x6e7752, 0, 0.93, 0, 6);
const leafColors = [0x668e62, 0x7da16d, 0x537b59];
for (let i = 0; i < 6; i++) {
const leaf = new THREE.Mesh(
new THREE.ConeGeometry(0.27, 0.78, 5),
standard(leafColors[i % leafColors.length])
);
const angle = (i / 6) * Math.PI * 2;
leaf.position.set(
Math.cos(angle) * 0.22,
1.05 + (i % 2) * 0.16,
Math.sin(angle) * 0.22
);
leaf.rotation.z = Math.cos(angle) * 0.55;
leaf.rotation.x = Math.sin(angle) * 0.55;
leaf.castShadow = true;
plant.add(leaf);
}
}
addPlant(-6.25, 3.55, 1.15);
addPlant(6.15, -1.85, 1.0);
addPlant(-6.20, -3.25, 0.85);
// -------------------------------------------------------------------------
// Low-poly people and delivery cart
// -------------------------------------------------------------------------
function addPerson({
x,
z,
shirt,
skin = 0xc98e65,
hair = 0x3b302b,
rotation = 0,
cap = null
}) {
const person = new THREE.Group();
person.position.set(x, 0, z);
person.rotation.y = rotation;
shop.add(person);
addBox(person, 0.19, 0.55, 0.22, 0x344854, -0.14, 0.29, 0);
addBox(person, 0.19, 0.55, 0.22, 0x344854, 0.14, 0.29, 0);
addBox(person, 0.56, 0.62, 0.34, shirt, 0, 0.88, 0);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.235, 1),
standard(skin)
);
head.position.set(0, 1.42, 0);
head.castShadow = true;
person.add(head);
const hairMesh = new THREE.Mesh(
new THREE.SphereGeometry(0.245, 8, 5, 0, Math.PI * 2, 0, Math.PI * 0.56),
standard(hair)
);
hairMesh.position.set(0, 1.44, 0.015);
hairMesh.castShadow = true;
person.add(hairMesh);
addBox(person, 0.17, 0.42, 0.18, shirt, -0.37, 0.87, 0);
addBox(person, 0.17, 0.42, 0.18, shirt, 0.37, 0.87, 0);
addBox(person, 0.055, 0.05, 0.035, 0x283239, -0.08, 1.45, -0.215);
addBox(person, 0.055, 0.05, 0.035, 0x283239, 0.08, 1.45, -0.215);
if (cap) {
addBox(person, 0.49, 0.12, 0.40, cap, 0, 1.64, 0);
addBox(person, 0.42, 0.055, 0.18, cap, 0, 1.58, -0.24);
}
return person;
}
addPerson({
x: -3.92,
z: 1.45,
shirt: 0x4f8f91,
skin: 0xc78d66,
hair: 0x302b29
});
addPerson({
x: 4.05,
z: 1.15,
shirt: 0xe98a42,
skin: 0x8f6045,
hair: 0x262628,
cap: 0xd96e2a
});
addPerson({
x: 0.05,
z: -4.05,
shirt: 0x415b68,
skin: 0xd7a27c,
hair: 0x4a342c,
rotation: Math.PI
});
// Customer basket.
const basket = new THREE.Group();
basket.position.set(-3.35, 0.53, 1.42);
basket.rotation.z = -0.12;
shop.add(basket);
addBox(basket, 0.42, 0.29, 0.29, 0xd7a64f, 0, 0, 0);
const basketHandle = new THREE.Mesh(
new THREE.TorusGeometry(0.18, 0.025, 6, 12, Math.PI),
standard(0x8c6b3e)
);
basketHandle.position.y = 0.14;
basket.add(basketHandle);
// Delivery cart.
const cart = new THREE.Group();
cart.position.set(5.55, 0, 2.48);
cart.rotation.y = -0.22;
shop.add(cart);
addBox(cart, 0.88, 0.12, 0.64, 0x53666c, 0, 0.28, 0);
addBox(cart, 0.88, 0.50, 0.08, 0x647b80, 0, 0.57, -0.28);
addBox(cart, 0.08, 0.50, 0.56, 0x647b80, -0.40, 0.57, 0);
addBox(cart, 0.08, 0.50, 0.56, 0x647b80, 0.40, 0.57, 0);
addBox(cart, 0.07, 0.85, 0.07, 0x354a51, -0.36, 0.72, 0.28);
addBox(cart, 0.07, 0.85, 0.07, 0x354a51, 0.36, 0.72, 0.28);
addBox(cart, 0.80, 0.07, 0.07, 0x354a51, 0, 1.13, 0.28);
for (const wheelX of [-0.31, 0.31]) {
for (const wheelZ of [-0.21, 0.21]) {
const wheel = addCylinder(
cart,
0.13,
0.13,
0.08,
0x29383d,
wheelX,
0.13,
wheelZ,
10
);
wheel.rotation.z = Math.PI / 2;
}
}
addBox(cart, 0.64, 0.48, 0.48, 0xd99852, 0, 0.58, 0);
addBox(cart, 0.08, 0.50, 0.50, 0xf2d6a4, 0, 0.58, 0);
// -------------------------------------------------------------------------
// Curved routes
// -------------------------------------------------------------------------
const routeDefinitions = {
customer: {
color: 0x159f91,
light: 0x75d7ca,
points: [
new THREE.Vector3(-5.10, 0.16, 4.42),
new THREE.Vector3(-5.05, 0.16, 2.72),
new THREE.Vector3(-4.35, 0.16, 0.50),
new THREE.Vector3(-3.15, 0.16, -1.13),
new THREE.Vector3(-1.22, 0.16, -2.34)
]
},
delivery: {
color: 0xed7b32,
light: 0xffbb83,
points: [
new THREE.Vector3(8.35, 0.16, 3.55),
new THREE.Vector3(6.48, 0.16, 3.55),
new THREE.Vector3(4.62, 0.16, 2.04),
new THREE.Vector3(3.25, 0.16, 0.05),
new THREE.Vector3(1.22, 0.16, -2.34)
]
}
};
const routeGroups = {};
const routeCurves = {};
const routeMarkers = {};
const upAxis = new THREE.Vector3(0, 1, 0);
function buildRoute(key, definition) {
const group = new THREE.Group();
scene.add(group);
const curve = new THREE.CatmullRomCurve3(
definition.points,
false,
"catmullrom",
0.18
);
routeCurves[key] = curve;
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 72, 0.105, 6, false),
standard(definition.color, {
emissive: definition.color,
emissiveIntensity: 0.18
})
);
tube.castShadow = true;
tube.receiveShadow = true;
group.add(tube);
// Direction arrows.
for (let i = 0; i < 7; i++) {
const t = 0.08 + i * 0.125;
const position = curve.getPointAt(t);
const tangent = curve.getTangentAt(t).normalize();
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.20, 0.48, 3),
standard(definition.light)
);
arrow.position.copy(position);
arrow.position.y = 0.23;
arrow.quaternion.setFromUnitVectors(upAxis, tangent);
arrow.castShadow = true;
group.add(arrow);
}
// Counter arrival ring.
const end = curve.getPointAt(1);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.07, 6, 24),
standard(definition.color, {
emissive: definition.color,
emissiveIntensity: 0.12
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.copy(end);
ring.position.y = 0.17;
ring.castShadow = true;
group.add(ring);
// Moving route token.
let marker;
if (key === "customer") {
marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.19),
standard(0x6be0d0, {
emissive: 0x2eb9aa,
emissiveIntensity: 0.35
})
);
} else {
marker = addBox(
group,
0.34,
0.31,
0.34,
0xffa05a,
0,
0,
0,
{ emissive: 0x9d4318, emissiveIntensity: 0.18 }
);
}
marker.castShadow = true;
group.add(marker);
routeMarkers[key] = marker;
routeGroups[key] = group;
}
buildRoute("customer", routeDefinitions.customer);
buildRoute("delivery", routeDefinitions.delivery);
// -------------------------------------------------------------------------
// Custom camera controls
// -------------------------------------------------------------------------
const defaultView = {
target: new THREE.Vector3(0.25, 0.85, -0.15),
radius: 21.0,
theta: 0.66,
phi: 0.88
};
const cameraGoal = {
target: defaultView.target.clone(),
radius: defaultView.radius,
theta: defaultView.theta,
phi: defaultView.phi
};
const cameraCurrent = {
target: defaultView.target.clone(),
radius: defaultView.radius,
theta: defaultView.theta,
phi: defaultView.phi
};
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function updateCamera() {
const sinPhi = Math.sin(cameraCurrent.phi);
camera.position.set(
cameraCurrent.target.x +
cameraCurrent.radius * sinPhi * Math.sin(cameraCurrent.theta),
cameraCurrent.target.y + cameraCurrent.radius * Math.cos(cameraCurrent.phi),
cameraCurrent.target.z +
cameraCurrent.radius * sinPhi * Math.cos(cameraCurrent.theta)
);
camera.lookAt(cameraCurrent.target);
}
updateCamera();
const canvas = renderer.domElement;
const pointers = new Map();
let pinchDistance = 0;
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
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
pinchDistance = currentPinchDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size === 1) {
cameraGoal.theta -= dx * 0.006;
cameraGoal.phi = clamp(
cameraGoal.phi + dy * 0.005,
0.34,
1.36
);
} else if (pointers.size === 2) {
const newDistance = currentPinchDistance();
if (pinchDistance > 0 && newDistance > 0) {
cameraGoal.radius = clamp(
cameraGoal.radius * (pinchDistance / newDistance),
10,
33
);
}
pinchDistance = newDistance;
}
});
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();
cameraGoal.radius = clamp(
cameraGoal.radius * Math.exp(event.deltaY * 0.001),
10,
33
);
},
{ passive: false }
);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
function setCameraView(target, radius, theta, phi) {
cameraGoal.target.copy(target);
cameraGoal.radius = radius;
cameraGoal.theta = theta;
cameraGoal.phi = phi;
}
resetButton.addEventListener("click", () => {
setCameraView(
defaultView.target,
defaultView.radius,
defaultView.theta,
defaultView.phi
);
});
counterButton.addEventListener("click", () => {
setCameraView(
new THREE.Vector3(0, 1.05, -2.25),
13.5,
0.50,
0.78
);
});
// -------------------------------------------------------------------------
// UI behavior
// -------------------------------------------------------------------------
const routeButtons = [...document.querySelectorAll(".route-button")];
routeButtons.forEach((button) => {
button.addEventListener("click", () => {
const mode = button.dataset.route;
routeButtons.forEach((item) => {
item.classList.toggle("active", item === button);
});
routeGroups.customer.visible =
mode === "all" || mode === "customer";
routeGroups.delivery.visible =
mode === "all" || mode === "delivery";
});
});
let routesAnimated = true;
animateButton.addEventListener("click", () => {
routesAnimated = !routesAnimated;
animateButton.textContent = routesAnimated
? "Pause motion"
: "Animate routes";
animateButton.classList.toggle("active", routesAnimated);
});
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const smoothing = 1 - Math.pow(0.001, 0.016);
cameraCurrent.target.lerp(cameraGoal.target, smoothing);
cameraCurrent.radius +=
(cameraGoal.radius - cameraCurrent.radius) * smoothing;
cameraCurrent.theta +=
(cameraGoal.theta - cameraCurrent.theta) * smoothing;
cameraCurrent.phi +=
(cameraGoal.phi - cameraCurrent.phi) * smoothing;
updateCamera();
if (routesAnimated) {
const customerT = (elapsed * 0.065 + 0.12) % 1;
const deliveryT = (elapsed * 0.055 + 0.56) % 1;
const customerPosition =
routeCurves.customer.getPointAt(customerT);
customerPosition.y = 0.36;
routeMarkers.customer.position.copy(customerPosition);
routeMarkers.customer.rotation.y = elapsed * 1.2;
const deliveryPosition =
routeCurves.delivery.getPointAt(deliveryT);
deliveryPosition.y = 0.33;
routeMarkers.delivery.position.copy(deliveryPosition);
routeMarkers.delivery.rotation.y = elapsed * 0.8;
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```