Prompt specification
Build or customize the Three.js 3D scene "Four Flow Tokens Around a Home" 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: Four Flow Tokens Around a Home
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/four-flow-tokens-around-a-home-x3125
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows circular flows of work, goods, and resources in a local economy. Place distinct labor, goods, payment, and waste tokens around a simple house. Use separate paths and symbols so physical and financial flows remain distinguishable. Stylized solid forms.
Working Three.js Starter (four-flow-tokens-around-a-home-x3125):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Circular Local Economy</title>
<style>
:root {
--ink: #24332f;
--muted: #6e7974;
--panel: rgba(255, 255, 255, 0.88);
--border: rgba(35, 51, 47, 0.12);
--labor: #10998a;
--goods: #e4a13b;
--payment: #7658d8;
--waste: #df6c61;
--resource: #719b55;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9eee7;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
top: 22px;
left: 22px;
z-index: 10;
width: min(360px, calc(100vw - 44px));
padding: 22px;
border: 1px solid var(--border);
border-radius: 22px;
background: var(--panel);
box-shadow:
0 18px 55px rgba(48, 67, 59, 0.14),
inset 0 1px 0 rgba(255, 255, 255, 0.8);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 12px;
color: #527269;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #3aa87a;
box-shadow: 0 0 0 5px rgba(58, 168, 122, 0.12);
}
h1 {
margin: 0;
max-width: 290px;
font-size: clamp(29px, 3vw, 40px);
line-height: 0.98;
letter-spacing: -0.055em;
}
.intro {
margin: 14px 0 19px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
padding-top: 17px;
border-top: 1px solid var(--border);
}
.legend-item {
display: flex;
align-items: center;
gap: 10px;
min-width: 0;
padding: 9px;
border: 1px solid rgba(35, 51, 47, 0.07);
border-radius: 13px;
background: rgba(255, 255, 255, 0.54);
}
.legend-item b {
display: block;
font-size: 12px;
line-height: 1.1;
}
.legend-item small {
display: block;
margin-top: 3px;
overflow: hidden;
color: var(--muted);
font-size: 9px;
line-height: 1.2;
text-overflow: ellipsis;
white-space: nowrap;
}
.token-icon {
position: relative;
display: inline-block;
flex: 0 0 30px;
width: 30px;
height: 30px;
border-radius: 9px;
background: rgba(35, 51, 47, 0.05);
}
.token-icon::after {
position: absolute;
inset: 7px;
content: "";
}
.token-icon.labor::after {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--labor);
box-shadow: 0 8px 0 -2px var(--labor);
}
.token-icon.goods::after {
inset: 8px 6px;
border-radius: 2px;
background: var(--goods);
transform: rotate(-5deg);
}
.token-icon.payment::after {
inset: 7px;
border: 3px solid var(--payment);
border-radius: 50%;
background: rgba(118, 88, 216, 0.12);
}
.token-icon.waste::after {
inset: 7px 8px 6px;
border-radius: 3px 3px 6px 6px;
background: var(--waste);
}
.token-icon.resource::after {
inset: 7px;
border-radius: 5px;
background: var(--resource);
transform: rotate(45deg) scale(0.72);
}
.route-note {
display: flex;
align-items: center;
gap: 9px;
margin: 13px 1px 0;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.route-note::before {
flex: 0 0 29px;
height: 3px;
content: "";
border-radius: 4px;
background: repeating-linear-gradient(
90deg,
var(--payment) 0 6px,
transparent 6px 10px
);
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 18px;
}
button {
min-height: 36px;
padding: 0 13px;
border: 1px solid var(--border);
border-radius: 11px;
background: rgba(255, 255, 255, 0.82);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
button:hover {
border-color: rgba(35, 51, 47, 0.25);
background: white;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
button.primary {
border-color: #294b41;
background: #294b41;
color: white;
}
button.primary:hover {
background: #365d51;
}
.hint {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 10;
padding: 10px 13px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(255, 255, 255, 0.76);
color: #66736e;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
pointer-events: none;
}
.loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #e9eee7;
color: #527269;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 16px;
border-radius: 18px;
}
h1 {
max-width: none;
font-size: 27px;
}
.intro {
margin: 9px 0 12px;
font-size: 11px;
}
.legend {
grid-template-columns: repeat(5, minmax(52px, 1fr));
gap: 5px;
padding-top: 12px;
}
.legend-item {
justify-content: center;
padding: 6px 4px;
}
.legend-item > div {
display: none;
}
.route-note {
display: none;
}
.actions {
margin-top: 11px;
}
button {
min-height: 32px;
padding: 0 10px;
font-size: 10px;
}
.hint {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section class="panel" aria-label="Circular economy information">
<div class="eyebrow">
<span class="live-dot"></span>
Local exchange / live model
</div>
<h1>Circular Local Economy</h1>
<p class="intro">
Work, goods, money, and materials circulate around a neighborhood home.
Solid routes carry physical things; the raised coin-bead route carries payment.
</p>
<div class="legend">
<div class="legend-item">
<span class="token-icon labor"></span>
<div><b>Labor</b><small>People & work</small></div>
</div>
<div class="legend-item">
<span class="token-icon goods"></span>
<div><b>Goods</b><small>Physical products</small></div>
</div>
<div class="legend-item">
<span class="token-icon payment"></span>
<div><b>Payment</b><small>Financial flow</small></div>
</div>
<div class="legend-item">
<span class="token-icon waste"></span>
<div><b>Waste</b><small>Used materials</small></div>
</div>
<div class="legend-item">
<span class="token-icon resource"></span>
<div><b>Resources</b><small>Recovered inputs</small></div>
</div>
</div>
<div class="route-note">
Raised, separated coin markers represent financial movement rather than physical goods.
</div>
<div class="actions">
<button id="motionButton" class="primary" type="button">Pause flows</button>
<button id="orbitButton" type="button" aria-pressed="true">Orbit on</button>
<button id="resetButton" type="button">Reset view</button>
</div>
</section>
<div class="hint">Drag to orbit · Scroll or pinch to zoom · Arrow keys also work</div>
<div id="loading" class="loading">Building the local loop…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
loading.textContent = "WebGL is not available in this browser.";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D diagram of a circular local economy"
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9eee7);
scene.fog = new THREE.Fog(0xe9eee7, 27, 48);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 1.1, 0);
const initialView = {
azimuth: 0.72,
polar: 0.93,
radius: window.innerWidth < 700 ? 29 : 24.5
};
const view = { ...initialView };
const hemisphere = new THREE.HemisphereLight(0xf9fff7, 0x87958b, 2.35);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff5df, 3.1);
sun.position.set(9, 16, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0005;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xb8d8ff, 0.8);
rim.position.set(-10, 7, -8);
scene.add(rim);
const COLORS = {
labor: 0x10998a,
goods: 0xe4a13b,
payment: 0x7658d8,
waste: 0xdf6c61,
resource: 0x719b55
};
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0,
...options
});
}
const materials = {
ground: standard(0xe5e3d3, { roughness: 0.95 }),
groundTop: standard(0xece9dc, { roughness: 0.94 }),
groundRing: standard(0xc5c8b8, { roughness: 0.95 }),
wall: standard(0xf4efe2),
wallShade: standard(0xe5ddca),
roof: standard(0xb96049, { roughness: 0.8 }),
foundation: standard(0xaaa995),
door: standard(0x785840),
window: standard(0x91c4c8, {
roughness: 0.28,
metalness: 0.12
}),
windowFrame: standard(0xffffff),
wood: standard(0x806449),
leaf: standard(0x78966d),
leafLight: standard(0x91aa78),
dark: standard(0x34473f)
};
function mesh(geometry, material, parent = scene) {
const object = new THREE.Mesh(geometry, material);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(width, height, depth, material, parent, x, y, z) {
const object = mesh(
new THREE.BoxGeometry(width, height, depth),
material,
parent
);
object.position.set(x, y, z);
return object;
}
function cylinder(
topRadius,
bottomRadius,
height,
material,
parent,
x,
y,
z,
segments = 40
) {
const object = mesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
material,
parent
);
object.position.set(x, y, z);
return object;
}
function torus(radius, tube, material, parent, x, y, z, horizontal = true) {
const object = mesh(
new THREE.TorusGeometry(radius, tube, 10, 64),
material,
parent
);
object.position.set(x, y, z);
if (horizontal) object.rotation.x = Math.PI / 2;
return object;
}
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 makeLabel(text, color, scaleX = 2.65, scaleY = 0.66) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
ctx.shadowColor = "rgba(30, 45, 39, 0.14)";
ctx.shadowBlur = 12;
ctx.shadowOffsetY = 5;
ctx.fillStyle = "rgba(255,255,255,0.94)";
roundedRect(ctx, 12, 16, 488, 94, 28);
ctx.fill();
ctx.shadowColor = "transparent";
ctx.strokeStyle = color;
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = color;
ctx.beginPath();
ctx.arc(65, 63, 13, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#2b3c36";
ctx.font = "750 38px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 282, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(scaleX, scaleY, 1);
sprite.renderOrder = 20;
return sprite;
}
// Ground and subtle circular planning rings.
const base = cylinder(
13.6,
14,
0.42,
materials.ground,
scene,
0,
-0.25,
0,
96
);
base.receiveShadow = true;
const topDisk = mesh(
new THREE.CircleGeometry(13.58, 96),
materials.groundTop,
scene
);
topDisk.rotation.x = -Math.PI / 2;
topDisk.position.y = -0.025;
topDisk.castShadow = false;
[4.4, 8.8, 13.2].forEach((radius, index) => {
const ring = torus(
radius,
index === 2 ? 0.035 : 0.022,
materials.groundRing,
scene,
0,
0.006 + index * 0.001,
0
);
ring.castShadow = false;
});
// Central home.
const house = new THREE.Group();
scene.add(house);
box(4.8, 0.3, 4.15, materials.foundation, house, 0, 0.15, 0);
box(4.2, 2.8, 3.5, materials.wall, house, 0, 1.7, 0);
const roof = mesh(
new THREE.ConeGeometry(3.55, 1.75, 4),
materials.roof,
house
);
roof.position.set(0, 3.92, 0);
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.94;
box(0.55, 1.25, 0.55, materials.roof, house, 1.15, 4.25, -0.45);
box(0.92, 1.75, 0.14, materials.door, house, 0, 1.18, 1.8);
const knob = mesh(
new THREE.SphereGeometry(0.065, 16, 12),
standard(0xe2b85e, { metalness: 0.65, roughness: 0.28 }),
house
);
knob.position.set(0.29, 1.18, 1.89);
function frontWindow(x) {
box(0.88, 0.88, 0.11, materials.windowFrame, house, x, 1.85, 1.8);
box(0.67, 0.67, 0.13, materials.window, house, x, 1.85, 1.87);
box(0.055, 0.7, 0.15, materials.windowFrame, house, x, 1.85, 1.89);
box(0.7, 0.055, 0.15, materials.windowFrame, house, x, 1.85, 1.89);
}
frontWindow(-1.28);
frontWindow(1.28);
const sideWindow = new THREE.Group();
sideWindow.position.set(2.12, 1.85, 0);
sideWindow.rotation.y = Math.PI / 2;
house.add(sideWindow);
box(0.9, 0.9, 0.11, materials.windowFrame, sideWindow, 0, 0, 0);
box(0.68, 0.68, 0.13, materials.window, sideWindow, 0, 0, 0.07);
box(0.055, 0.71, 0.15, materials.windowFrame, sideWindow, 0, 0, 0.09);
box(0.71, 0.055, 0.15, materials.windowFrame, sideWindow, 0, 0, 0.09);
const homeLabel = makeLabel("LOCAL HOME", "#49675d", 2.7, 0.68);
homeLabel.position.set(0, 5.25, 0);
scene.add(homeLabel);
// Reusable stylized token models.
function makeWorker(scale = 1) {
const group = new THREE.Group();
const shirt = standard(COLORS.labor);
const skin = standard(0xf0bd96);
const trousers = standard(0x36515a);
const body = mesh(
new THREE.CapsuleGeometry(0.18, 0.34, 5, 10),
shirt,
group
);
body.position.y = 0.56;
const head = mesh(new THREE.SphereGeometry(0.2, 20, 14), skin, group);
head.position.y = 1.05;
[-0.1, 0.1].forEach((x) => {
const leg = mesh(
new THREE.CapsuleGeometry(0.065, 0.22, 3, 8),
trousers,
group
);
leg.position.set(x, 0.2, 0);
});
[-0.28, 0.28].forEach((x) => {
const arm = mesh(
new THREE.CapsuleGeometry(0.055, 0.24, 3, 8),
shirt,
group
);
arm.position.set(x, 0.56, 0);
arm.rotation.z = x > 0 ? -0.16 : 0.16;
});
group.scale.setScalar(scale);
return group;
}
function makeCrate(scale = 1) {
const group = new THREE.Group();
const crate = standard(0xc88b48);
const band = standard(0xf0c98e);
box(0.72, 0.65, 0.72, crate, group, 0, 0.325, 0);
box(0.11, 0.68, 0.74, band, group, 0, 0.33, 0);
box(0.74, 0.08, 0.74, band, group, 0, 0.64, 0);
group.scale.setScalar(scale);
return group;
}
function makeCoin(scale = 1) {
const group = new THREE.Group();
const coin = standard(0xb19bea, {
metalness: 0.6,
roughness: 0.24
});
const rim = standard(0xe4c579, {
metalness: 0.72,
roughness: 0.2
});
cylinder(0.38, 0.38, 0.09, coin, group, 0, 0.045, 0, 32);
torus(0.29, 0.035, rim, group, 0, 0.095, 0);
box(0.32, 0.025, 0.07, rim, group, 0, 0.11, 0);
group.scale.setScalar(scale);
return group;
}
function makeStandingCoin(scale = 1) {
const group = new THREE.Group();
const coin = standard(0xb19bea, {
metalness: 0.62,
roughness: 0.25
});
const rim = standard(0xe4c579, {
metalness: 0.75,
roughness: 0.2
});
cylinder(0.58, 0.68, 0.12, materials.dark, group, 0, 0.06, 0);
const disk = cylinder(
0.58,
0.58,
0.12,
coin,
group,
0,
0.75,
0,
40
);
disk.rotation.x = Math.PI / 2;
const edge = torus(0.48, 0.045, rim, group, 0, 0.75, 0.07, false);
edge.position.z = 0.07;
box(0.42, 0.08, 0.055, rim, group, 0, 0.75, 0.11);
group.scale.setScalar(scale);
return group;
}
function makeBin(scale = 1) {
const group = new THREE.Group();
const bin = standard(COLORS.waste);
const lid = standard(0xa94e49);
const band = standard(0xf4c5ae);
cylinder(
0.36,
0.28,
0.68,
bin,
group,
0,
0.34,
0,
32
);
cylinder(0.4, 0.4, 0.09, lid, group, 0, 0.72, 0, 32);
torus(0.31, 0.025, band, group, 0, 0.24, 0);
torus(0.34, 0.025, band, group, 0, 0.51, 0);
group.scale.setScalar(scale);
return group;
}
function makeGem(scale = 1) {
const group = new THREE.Group();
const gem = mesh(
new THREE.OctahedronGeometry(0.36, 0),
standard(COLORS.resource, {
roughness: 0.38,
metalness: 0.08
}),
group
);
gem.position.y = 0.36;
gem.scale.set(0.82, 1.2, 0.82);
group.scale.setScalar(scale);
return group;
}
function addStation(name, x, z, color, icon) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
cylinder(
1.18,
1.28,
0.24,
standard(0xd7d7c9),
group,
0,
0.12,
0,
48
);
const ring = torus(
1.2,
0.035,
standard(color),
group,
0,
0.25,
0
);
ring.castShadow = false;
icon.position.y = 0.25;
group.add(icon);
const label = makeLabel(name, `#${new THREE.Color(color).getHexString()}`, 2.6, 0.65);
label.position.set(0, 2.25, 0);
group.add(label);
return group;
}
addStation("COMMUNITY", -7, -2.8, COLORS.labor, makeWorker(1.3));
addStation("MARKET", 7, -2.8, COLORS.goods, makeCrate(1.6));
addStation("LOCAL BANK", 7, 4.2, COLORS.payment, makeStandingCoin(1.15));
addStation("RECOVERY", -7, 4.2, COLORS.waste, makeBin(1.35));
// Low-poly perimeter vegetation.
function makeTree(x, z, scale, light = false) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(
0.13,
0.18,
1.15,
materials.wood,
group,
0,
0.58,
0,
9
);
const crown = mesh(
new THREE.ConeGeometry(0.9, 2.1, 7),
light ? materials.leafLight : materials.leaf,
group
);
crown.position.y = 1.7;
crown.rotation.y = 0.3;
const top = mesh(
new THREE.ConeGeometry(0.68, 1.55, 7),
light ? materials.leaf : materials.leafLight,
group
);
top.position.y = 2.55;
top.rotation.y = -0.22;
return group;
}
[
[-11.4, -7.2, 1.05],
[-4.4, -12, 0.92],
[4.2, -12, 1.08],
[11.2, -7.2, 0.9],
[12, 6.8, 1.02],
[5.1, 12, 0.86],
[-3.8, 12, 1.05],
[-12.1, 8.3, 0.8]
].forEach((entry, index) => {
makeTree(entry[0], entry[1], entry[2], index % 2 === 0);
});
const flows = [];
function createFlow(definition) {
const curve = new THREE.CatmullRomCurve3(
definition.points.map((point) => new THREE.Vector3(...point)),
false,
"catmullrom",
0.45
);
const color = COLORS[definition.type];
if (definition.type === "payment") {
// A financial route is intentionally different: raised, separated
// coin markers instead of a continuous physical tube.
const coinMaterial = standard(color, {
metalness: 0.58,
roughness: 0.25,
emissive: color,
emissiveIntensity: 0.08
});
const dashCount = 29;
for (let i = 0; i < dashCount; i++) {
const t = i / (dashCount - 1);
const point = curve.getPointAt(t);
const dash = cylinder(
0.115,
0.115,
0.038,
coinMaterial,
scene,
point.x,
point.y,
point.z,
20
);
dash.castShadow = false;
}
} else {
const pathMaterial = standard(color, {
roughness: 0.48,
emissive: color,
emissiveIntensity: 0.08
});
const tube = mesh(
new THREE.TubeGeometry(curve, 100, 0.085, 9, false),
pathMaterial
);
tube.castShadow = true;
}
const arrowPoint = curve.getPointAt(0.82);
const arrowTangent = curve.getTangentAt(0.82).normalize();
const arrow = mesh(
new THREE.ConeGeometry(0.23, 0.58, 14),
standard(color, {
roughness: 0.4,
emissive: color,
emissiveIntensity: 0.06
})
);
arrow.position.copy(arrowPoint);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
arrowTangent
);
const movingTokens = [];
for (let i = 0; i < definition.count; i++) {
const token = definition.tokenFactory();
token.userData.flowType = definition.type;
scene.add(token);
movingTokens.push(token);
}
if (definition.label) {
const labelPoint = curve.getPointAt(definition.labelT);
const label = makeLabel(
definition.label,
`#${new THREE.Color(color).getHexString()}`,
2.05,
0.52
);
label.position.copy(labelPoint);
label.position.y += definition.labelLift ?? 0.58;
scene.add(label);
}
flows.push({
...definition,
curve,
movingTokens
});
}
createFlow({
type: "labor",
label: "LABOR",
labelT: 0.51,
count: 3,
speed: 0.065,
offset: 0.08,
tokenFactory: () => makeWorker(0.58),
points: [
[-6.15, 0.58, -2.65],
[-5.2, 0.52, -2.35],
[-4.3, 0.46, -1.65],
[-3.35, 0.48, -1.05],
[-2.15, 0.53, -0.7]
]
});
createFlow({
type: "goods",
label: "GOODS",
labelT: 0.5,
count: 3,
speed: 0.057,
offset: 0.24,
tokenFactory: () => makeCrate(0.68),
points: [
[2.1, 0.54, -0.55],
[3.25, 0.49, -0.85],
[4.55, 0.55, -1.45],
[5.55, 0.51, -2.05],
[6.15, 0.58, -2.65]
]
});
createFlow({
type: "payment",
label: "PAYMENT",
labelT: 0.36,
labelLift: 0.7,
count: 3,
speed: 0.045,
offset: 0.42,
tokenFactory: () => makeCoin(0.78),
points: [
[6.15, 1.02, -2.55],
[7.65, 1.18, -1.25],
[8.0, 1.22, 1.65],
[7.0, 1.14, 3.75],
[5.55, 1.12, 4.45],
[3.55, 1.12, 3.2],
[2.0, 0.78, 1.4]
]
});
createFlow({
type: "waste",
label: "WASTE",
labelT: 0.5,
count: 2,
speed: 0.048,
offset: 0.16,
tokenFactory: () => makeBin(0.64),
points: [
[-1.85, 0.54, 1.25],
[-3.05, 0.48, 1.85],
[-4.55, 0.5, 2.65],
[-5.55, 0.52, 3.55],
[-6.2, 0.58, 4.05]
]
});
createFlow({
type: "resource",
label: "RESOURCES",
labelT: 0.49,
count: 3,
speed: 0.04,
offset: 0.05,
tokenFactory: () => makeGem(0.85),
points: [
[-7.25, 0.62, 4.85],
[-9.45, 0.6, 3.0],
[-9.85, 0.54, 0.3],
[-9.0, 0.55, -3.45],
[-7.65, 0.6, -4.2],
[-6.35, 0.6, -2.95]
]
});
// Custom camera controls implemented without camera-control addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let activePointerId = null;
const pinchDistance = new Map();
function clampView() {
view.polar = THREE.MathUtils.clamp(view.polar, 0.5, 1.35);
view.radius = THREE.MathUtils.clamp(view.radius, 16, 38);
}
function updateCamera() {
const sinPolar = Math.sin(view.polar);
camera.position.set(
target.x + view.radius * sinPolar * Math.sin(view.azimuth),
target.y + view.radius * Math.cos(view.polar),
target.z + view.radius * sinPolar * Math.cos(view.azimuth)
);
camera.lookAt(target);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.pointerType === "touch") {
pinchDistance.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
}
if (activePointerId === null) {
activePointerId = event.pointerId;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pinchDistance.has(event.pointerId)) {
pinchDistance.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
const points = [...pinchDistance.values()];
if (points.length === 2) {
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (view.lastPinchDistance) {
view.radius *= view.lastPinchDistance / distance;
clampView();
}
view.lastPinchDistance = distance;
}
return;
}
if (!dragging || event.pointerId !== activePointerId) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
view.azimuth -= dx * 0.005;
view.polar -= dy * 0.0045;
clampView();
});
function releasePointer(event) {
pinchDistance.delete(event.pointerId);
if (event.pointerId === activePointerId) {
dragging = false;
activePointerId = null;
renderer.domElement.classList.remove("dragging");
}
if (pinchDistance.size < 2) {
view.lastPinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius *= Math.exp(event.deltaY * 0.001);
clampView();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
Object.assign(view, initialView);
});
window.addEventListener("keydown", (event) => {
if (["BUTTON", "INPUT", "TEXTAREA"].includes(document.activeElement?.tagName)) {
return;
}
if (event.key === "ArrowLeft") view.azimuth += 0.09;
if (event.key === "ArrowRight") view.azimuth -= 0.09;
if (event.key === "ArrowUp") view.polar -= 0.07;
if (event.key === "ArrowDown") view.polar += 0.07;
if (event.key === "+" || event.key === "=") view.radius -= 1;
if (event.key === "-") view.radius += 1;
clampView();
});
const motionButton = document.getElementById("motionButton");
const orbitButton = document.getElementById("orbitButton");
const resetButton = document.getElementById("resetButton");
let flowsRunning = true;
let orbitEnabled = true;
motionButton.addEventListener("click", () => {
flowsRunning = !flowsRunning;
motionButton.textContent = flowsRunning ? "Pause flows" : "Resume flows";
});
orbitButton.addEventListener("click", () => {
orbitEnabled = !orbitEnabled;
orbitButton.textContent = orbitEnabled ? "Orbit on" : "Orbit off";
orbitButton.setAttribute("aria-pressed", String(orbitEnabled));
});
resetButton.addEventListener("click", () => {
Object.assign(view, initialView);
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
let elapsed = 0;
let firstFrame = true;
function animateFlowTokens(time) {
for (const flow of flows) {
flow.movingTokens.forEach((token, index) => {
const t =
(time * flow.speed + index / flow.movingTokens.length + flow.offset) %
1;
const point = flow.curve.getPointAt(t);
const tangent = flow.curve.getTangentAt(t);
token.position.copy(point);
token.position.y += 0.015;
if (
flow.type === "labor" ||
flow.type === "goods" ||
flow.type === "waste"
) {
token.rotation.y = Math.atan2(tangent.x, tangent.z);
if (flow.type === "goods") {
token.rotation.z = Math.sin(time * 3 + index) * 0.045;
}
} else if (flow.type === "payment") {
token.rotation.y = time * 2.4 + index;
token.position.y += Math.sin(time * 4 + index) * 0.025;
} else if (flow.type === "resource") {
token.rotation.y = time * 2.8 + index;
token.rotation.x = time * 1.7;
token.position.y += Math.sin(time * 4 + index) * 0.04;
}
});
}
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (flowsRunning) elapsed += delta;
if (orbitEnabled && !dragging) {
view.azimuth += delta * 0.035;
}
clampView();
updateCamera();
animateFlowTokens(elapsed);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
}
}
updateCamera();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```