Prompt specification
Build or customize the Three.js 3D scene "Packaging-flow comparison game" 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: Packaging-flow comparison game
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/packaging-flow-comparison-game-x0528
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts refill shops. Create parallel shopping routes using disposable packages and reusable jars; track packaging units over repeated fictional trips while clearly separating those counts from full environmental-impact claims. Low-poly.
Working Three.js Starter (packaging-flow-comparison-game-x0528):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Refill Routes — A Fictional Packaging Ledger</title>
<style>
:root {
--ink: #20332f;
--muted: #68746f;
--paper: #f8f4e9;
--line: rgba(32, 51, 47, 0.15);
--coral: #e8795f;
--teal: #3f9586;
--gold: #d8a842;
--panel: rgba(250, 247, 239, 0.92);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e1d4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.masthead {
position: fixed;
top: 26px;
left: 28px;
z-index: 5;
width: min(390px, calc(100vw - 56px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #51645d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 3px;
border-radius: 4px;
background: var(--coral);
content: "";
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 54px);
font-weight: 850;
letter-spacing: -0.055em;
line-height: 0.95;
}
.masthead p {
max-width: 350px;
margin: 12px 0 0;
color: #53645e;
font-size: 14px;
line-height: 1.5;
}
.controls {
position: fixed;
top: 24px;
right: 24px;
z-index: 7;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 9px;
}
.control-row {
display: flex;
align-items: center;
gap: 6px;
padding: 6px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 13px;
background: rgba(248, 244, 233, 0.82);
box-shadow: 0 10px 28px rgba(45, 55, 48, 0.09);
backdrop-filter: blur(14px);
}
.control-label {
padding: 0 8px 0 5px;
color: #6b7771;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.control-row button {
min-height: 34px;
padding: 0 12px;
border: 0;
border-radius: 8px;
background: transparent;
color: var(--ink);
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
.control-row button:hover {
background: rgba(32, 51, 47, 0.08);
}
.control-row button:active {
transform: translateY(1px);
}
.control-row .primary {
background: var(--ink);
color: #fffaf0;
}
.control-row .primary:hover {
background: #345049;
}
.status {
min-height: 31px;
padding: 7px 11px;
border: 1px solid rgba(32, 51, 47, 0.12);
border-radius: 9px;
background: rgba(248, 244, 233, 0.85);
color: #53645e;
font-size: 11px;
font-weight: 650;
backdrop-filter: blur(12px);
}
.ledger {
position: fixed;
z-index: 6;
right: 24px;
bottom: 22px;
left: 24px;
display: grid;
grid-template-columns: 1.18fr 1fr;
gap: 0;
max-width: 1120px;
margin: 0 auto;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 20px 55px rgba(40, 51, 46, 0.16);
backdrop-filter: blur(18px);
}
.ledger-main {
padding: 18px 20px 17px;
border-right: 1px solid var(--line);
}
.ledger-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 14px;
}
.ledger-title {
margin: 0;
font-size: 13px;
font-weight: 850;
letter-spacing: -0.01em;
}
.ledger-subtitle {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.trip-chip {
flex: 0 0 auto;
padding: 7px 10px;
border-radius: 8px;
background: #e9e3d7;
color: #5a6862;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 9px;
margin-bottom: 14px;
}
.metric {
min-width: 0;
padding: 11px 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.46);
}
.metric span {
display: block;
overflow: hidden;
margin-bottom: 3px;
color: #6b7771;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.1em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.metric strong {
display: block;
font-size: 23px;
font-weight: 850;
letter-spacing: -0.04em;
line-height: 1;
}
.metric.total {
border-color: rgba(232, 121, 95, 0.35);
background: rgba(232, 121, 95, 0.09);
}
.route-table {
width: 100%;
border-collapse: collapse;
font-size: 10px;
}
.route-table th {
padding: 0 5px 7px;
color: #78827d;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.07em;
text-align: right;
text-transform: uppercase;
}
.route-table th:first-child,
.route-table td:first-child {
text-align: left;
}
.route-table td {
padding: 8px 5px;
border-top: 1px solid var(--line);
text-align: right;
vertical-align: middle;
}
.route-name {
display: flex;
align-items: center;
gap: 7px;
font-weight: 800;
}
.route-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--coral);
}
.route-dot.teal {
background: var(--teal);
}
.small-muted {
color: #77817c;
font-size: 9px;
}
.boundary {
padding: 17px 20px;
background: rgba(32, 51, 47, 0.055);
}
.boundary-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
font-size: 11px;
font-weight: 850;
}
.boundary-icon {
display: grid;
width: 20px;
height: 20px;
place-items: center;
border: 1px solid rgba(32, 51, 47, 0.25);
border-radius: 50%;
color: var(--ink);
font-size: 11px;
}
.boundary p {
margin: 0;
color: #5f6c66;
font-size: 10px;
line-height: 1.55;
}
.boundary p + p {
margin-top: 9px;
}
.boundary strong {
color: var(--ink);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 7px 14px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: #66736d;
font-size: 9px;
font-weight: 700;
}
.legend-swatch {
width: 15px;
height: 5px;
border-radius: 5px;
background: var(--coral);
}
.legend-swatch.teal {
background: var(--teal);
}
.camera-hint {
position: fixed;
right: 26px;
bottom: 246px;
z-index: 4;
padding: 6px 9px;
border-radius: 7px;
background: rgba(248, 244, 233, 0.7);
color: #68756e;
font-size: 9px;
font-weight: 750;
pointer-events: none;
backdrop-filter: blur(10px);
}
@media (max-width: 760px) {
.masthead {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
.masthead p {
display: none;
}
.controls {
top: 94px;
right: 14px;
left: 14px;
align-items: stretch;
}
.control-row {
justify-content: center;
flex-wrap: wrap;
}
.control-label {
display: none;
}
.control-row button {
padding: 0 10px;
}
.status {
text-align: center;
}
.ledger {
right: 10px;
bottom: 10px;
left: 10px;
grid-template-columns: 1fr;
max-height: 48vh;
overflow-y: auto;
border-radius: 14px;
}
.ledger-main {
padding: 14px;
border-right: 0;
border-bottom: 1px solid var(--line);
}
.boundary {
padding: 14px;
}
.metrics {
gap: 6px;
}
.metric {
padding: 9px;
}
.metric strong {
font-size: 20px;
}
.camera-hint {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Low-poly refill shop scene"></main>
<header class="masthead">
<div class="eyebrow">Field Note 04 · Packaging logistics</div>
<h1>Refill Routes</h1>
<p>
Two parallel shopping routes for the same eight fictional refills:
disposable packages versus reusable jars.
</p>
</header>
<nav class="controls" aria-label="Scene and trip controls">
<div class="control-row" aria-label="Camera views">
<span class="control-label">View</span>
<button type="button" data-view="overview">Overview</button>
<button type="button" data-view="disposable">Disposable</button>
<button type="button" data-view="reusable">Reusable</button>
</div>
<div class="control-row" aria-label="Fictional trip controls">
<span class="control-label">Trips</span>
<button type="button" class="primary" id="add-one">+ 1 trip</button>
<button type="button" id="add-five">+ 5 trips</button>
<button type="button" id="reset">Reset</button>
</div>
<div class="status" id="status" role="status" aria-live="polite">
Ready to record a fictional trip.
</div>
</nav>
<section class="ledger" aria-label="Fictional packaging-unit ledger">
<div class="ledger-main">
<div class="ledger-head">
<div>
<h2 class="ledger-title">Fictional trip ledger</h2>
<div class="ledger-subtitle">Eight refill items on every route</div>
</div>
<div class="trip-chip" id="trip-chip">Trip 00</div>
</div>
<div class="metrics">
<div class="metric">
<span>Trips recorded</span>
<strong id="trip-count">00</strong>
</div>
<div class="metric">
<span>Separate jar uses</span>
<strong id="jar-uses">00</strong>
</div>
<div class="metric total">
<span>Package units · both routes</span>
<strong id="package-total">00</strong>
</div>
</div>
<table class="route-table">
<thead>
<tr>
<th>Fictional route</th>
<th>Units / trip</th>
<th>Package total</th>
<th>Other tracked units</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<span class="route-name">
<span class="route-dot"></span>
Disposable
</span>
</td>
<td>8 packages</td>
<td id="disposable-total">00</td>
<td class="small-muted">—</td>
</tr>
<tr>
<td>
<span class="route-name">
<span class="route-dot teal"></span>
Reusable
</span>
</td>
<td>0 packages</td>
<td id="reusable-total">00</td>
<td class="small-muted">8 jar uses / trip</td>
</tr>
</tbody>
</table>
</div>
<aside class="boundary">
<div class="boundary-title">
<span class="boundary-icon">i</span>
What these numbers mean
</div>
<p>
<strong>Package units are transaction counts only.</strong>
They describe the fictional items counted in this scene. Reusable jar
uses are tracked separately and are not counted as package units.
</p>
<p>
This is <strong>not a lifecycle assessment</strong>. It does not model
production, transport, washing, refill losses, energy, water, carbon,
waste, or other impacts, and it does not calculate an overall
environmental score.
</p>
<div class="legend" aria-label="Route legend">
<div class="legend-item">
<span class="legend-swatch"></span>
Disposable route
</div>
<div class="legend-item">
<span class="legend-swatch teal"></span>
Reusable route
</div>
</div>
</aside>
</section>
<div class="camera-hint">Drag to orbit · Scroll to zoom</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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e1d4);
scene.fog = new THREE.Fog(0xe8e1d4, 25, 48);
const renderer = new THREE.WebGLRenderer({
antialias: true,
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;
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xfff9e9, 0x8a958b, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.3);
sun.position.set(-9, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.0003;
scene.add(sun);
const colors = {
ink: 0x20332f,
cream: 0xf5eddd,
paper: 0xfffaf0,
coral: 0xe8795f,
coralDark: 0xb9503f,
teal: 0x3f9586,
tealDark: 0x276e63,
gold: 0xd8a842,
wood: 0xb98a59,
woodDark: 0x79563b,
mint: 0x9fc9a3,
blue: 0x6c9eb9,
plum: 0x956f88,
leaf: 0x5f9472,
leafDark: 0x3d7054
};
function material(color, roughness = 0.86) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0,
flatShading: true
});
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
topRadius,
bottomRadius,
height,
color,
x = 0,
y = 0,
z = 0,
segments = 10
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
height,
segments
),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRectPath(ctx, x, y, w, h, radius) {
const r = Math.min(radius, w / 2, h / 2);
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 makePanel(title, main, footer, accent = "#e8795f") {
const canvas = document.createElement("canvas");
canvas.width = 720;
canvas.height = 340;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.renderOrder = 10;
function setText(nextTitle, nextMain, nextFooter) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.shadowColor = "rgba(30, 43, 37, 0.17)";
ctx.shadowBlur = 18;
ctx.shadowOffsetY = 8;
roundedRectPath(ctx, 12, 12, 696, 316, 24);
ctx.fillStyle = "rgba(255, 250, 240, 0.95)";
ctx.fill();
ctx.shadowColor = "transparent";
roundedRectPath(ctx, 12, 12, 13, 316, 7);
ctx.fillStyle = accent;
ctx.fill();
ctx.textAlign = "left";
ctx.textBaseline = "alphabetic";
ctx.fillStyle = "#596861";
ctx.font = "800 25px system-ui, sans-serif";
ctx.fillText(nextTitle.toUpperCase(), 52, 67);
ctx.fillStyle = "#20332f";
ctx.font = "850 47px system-ui, sans-serif";
ctx.fillText(nextMain, 52, 143);
ctx.strokeStyle = "rgba(32, 51, 47, 0.14)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(52, 187);
ctx.lineTo(668, 187);
ctx.stroke();
ctx.fillStyle = "#65726c";
ctx.font = "650 24px system-ui, sans-serif";
ctx.fillText(nextFooter, 52, 242);
ctx.fillStyle = "#87918c";
ctx.font = "700 18px system-ui, sans-serif";
ctx.fillText("FICTIONAL SCENARIO · NOT LIFECYCLE DATA", 52, 287);
texture.needsUpdate = true;
}
setText(title, main, footer);
return { sprite, setText };
}
function makeStaticSign(
title,
main,
footer,
accent,
position,
scale = new THREE.Vector2(4.6, 2.17)
) {
const panel = makePanel(title, main, footer, accent);
panel.sprite.position.copy(position);
panel.sprite.scale.copy(scale);
scene.add(panel.sprite);
return panel;
}
// Ground and street plinth.
box(scene, 32, 0.32, 28, 0xd9d0bd, 0, -0.18, 1.5);
box(scene, 25, 0.08, 20, 0xe5ddcd, 0, 0.02, 1);
// Small paving pattern.
for (let x = -10; x <= 10; x += 2) {
box(scene, 0.025, 0.012, 16, 0xd4cbb9, x, 0.075, 1);
}
for (let z = -6; z <= 10; z += 2) {
box(scene, 20, 0.012, 0.025, 0xd4cbb9, 0, 0.076, z);
}
// Refill shop.
const shop = new THREE.Group();
shop.position.set(0, 0, -3.8);
scene.add(shop);
box(shop, 8.2, 0.22, 4.5, 0xe7dcc6, 0, 0.12, 0);
box(shop, 8.2, 3.7, 0.2, 0xf4ead3, 0, 1.95, -2.15);
box(shop, 0.22, 3.7, 4.3, 0xe5d8bd, -4.0, 1.95, 0);
box(shop, 0.22, 3.7, 4.3, 0xe5d8bd, 4.0, 1.95, 0);
box(shop, 8.8, 0.32, 4.9, 0x39524a, 0, 3.95, -0.05);
// Front posts.
for (const x of [-3.45, 3.45]) {
box(shop, 0.22, 3.35, 0.22, 0x36574d, x, 1.75, 2.03);
}
// Striped low-poly awning.
const awningColors = [
0xf4ead3, 0xe8795f, 0xf4ead3, 0xe8795f,
0xf4ead3, 0xe8795f, 0xf4ead3, 0xe8795f,
0xf4ead3, 0xe8795f
];
for (let i = 0; i < awningColors.length; i++) {
const x = -4.05 + i * 0.9;
const awning = box(
shop,
0.9,
0.14,
1.75,
awningColors[i],
x,
3.35,
1.6
);
awning.rotation.x = -0.12;
}
// Back shelves.
for (const y of [0.75, 1.55, 2.35]) {
box(shop, 6.9, 0.12, 0.55, 0x9a744c, 0, y, -1.76);
}
for (const x of [-3.25, -1.6, 0, 1.6, 3.25]) {
box(shop, 0.11, 2.5, 0.48, 0x7f5c3d, x, 1.65, -1.88);
}
const productColors = [
colors.coral,
colors.gold,
colors.teal,
colors.blue,
colors.plum,
colors.mint
];
for (let row = 0; row < 3; row++) {
for (let i = 0; i < 11; i++) {
const x = -3.05 + i * 0.61;
const y = 0.96 + row * 0.8;
const color = productColors[(i + row * 2) % productColors.length];
const shape = (i + row) % 3;
if (shape === 0) {
cylinder(shop, 0.18, 0.18, 0.34, color, x, y, -1.58, 8);
cylinder(shop, 0.19, 0.19, 0.05, colors.ink, x, y + 0.19, -1.58, 8);
} else if (shape === 1) {
box(shop, 0.34, 0.42, 0.27, color, x, y, -1.57);
box(shop, 0.24, 0.06, 0.02, colors.paper, x, y, -1.425);
} else {
cylinder(shop, 0.15, 0.21, 0.36, color, x, y, -1.57, 7);
}
}
}
// Bulk refill dispensers.
const dispenserColors = [colors.gold, colors.teal, colors.coral];
for (let i = 0; i < 3; i++) {
const x = -1.7 + i * 1.7;
box(shop, 1.15, 1.5, 0.95, 0xd4c5a8, x, 0.9, -0.8);
cylinder(
shop,
0.38,
0.38,
0.95,
dispenserColors[i],
x,
1.5,
-0.73,
8
);
cylinder(shop, 0.42, 0.42, 0.11, colors.ink, x, 2.02, -0.73, 8);
box(shop, 0.3, 0.13, 0.16, colors.ink, x, 1.28, -0.34);
box(shop, 0.46, 0.22, 0.025, colors.paper, x, 1.67, -0.325);
}
// Checkout counter.
box(shop, 2.45, 1.05, 0.9, colors.wood, 0, 0.68, 1.25);
box(shop, 2.65, 0.16, 1.02, colors.woodDark, 0, 1.27, 1.25);
box(shop, 0.5, 0.12, 0.38, colors.ink, -0.5, 1.41, 1.22);
// A few jars and packages on the counter.
for (let i = 0; i < 3; i++) {
cylinder(shop, 0.13, 0.13, 0.28, colors.mint, 0.38 + i * 0.32, 1.49, 1.2, 8);
cylinder(shop, 0.14, 0.14, 0.04, colors.ink, 0.38 + i * 0.32, 1.65, 1.2, 8);
}
makeStaticSign(
"Refill market",
"BULK GOODS · REFILL STATION",
"FICTIONAL SHOPPING DISTRICT",
"#3f9586",
new THREE.Vector3(0, 4.75, -1.55),
new THREE.Vector2(5.4, 2.55)
);
// Route curves.
const routeHeight = 0.13;
const disposableCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.8, routeHeight, -1.25),
new THREE.Vector3(-2.9, routeHeight, -0.75),
new THREE.Vector3(-5.25, routeHeight, 1.3),
new THREE.Vector3(-4.65, routeHeight, 4.65),
new THREE.Vector3(-2.25, routeHeight, 6.2),
new THREE.Vector3(0, routeHeight, 6.85)
]);
const reusableCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0.8, routeHeight, -1.25),
new THREE.Vector3(2.9, routeHeight, -0.75),
new THREE.Vector3(5.25, routeHeight, 1.3),
new THREE.Vector3(4.65, routeHeight, 4.65),
new THREE.Vector3(2.25, routeHeight, 6.2),
new THREE.Vector3(0, routeHeight, 6.85)
]);
function makeRoute(curve, color) {
const points = curve.getPoints(50);
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
const segment = box(
scene,
1.18,
0.075,
length + 0.025,
color,
(a.x + b.x) / 2,
0.105,
(a.z + b.z) / 2
);
segment.rotation.y = Math.atan2(dx, dz);
segment.castShadow = false;
}
// Pale dashed center marks.
for (let i = 3; i < points.length - 2; i += 7) {
const p = points[i];
const q = points[i + 1];
const dx = q.x - p.x;
const dz = q.z - p.z;
const marker = box(
scene,
0.055,
0.018,
0.42,
0xf8f0df,
p.x,
0.155,
p.z
);
marker.rotation.y = Math.atan2(dx, dz);
marker.castShadow = false;
}
// Low-poly directional arrows.
for (const t of [0.28, 0.57, 0.82]) {
const p = curve.getPointAt(t);
const tangent = curve.getTangentAt(t);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.19, 0.48, 3),
material(0xf8f0df)
);
arrow.position.set(p.x, 0.23, p.z);
arrow.rotation.set(Math.PI / 2, 0, 0);
arrow.rotateOnWorldAxis(new THREE.Vector3(0, 1, 0), Math.atan2(tangent.x, tangent.z));
scene.add(arrow);
}
}
makeRoute(disposableCurve, colors.coral);
makeRoute(reusableCurve, colors.teal);
// Shared destination.
const home = new THREE.Group();
home.position.set(0, 0, 8.25);
scene.add(home);
box(home, 3.15, 2.15, 2.45, 0xf1e3c8, 0, 1.12, 0);
box(home, 0.18, 2.1, 2.45, 0xd9c8a8, -1.52, 1.1, 0);
const roof = new THREE.Mesh(
new THREE.ConeGeometry(2.45, 1.2, 4),
material(colors.coralDark)
);
roof.position.set(0, 2.75, 0);
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.86;
roof.castShadow = true;
home.add(roof);
box(home, 0.72, 1.25, 0.08, colors.tealDark, 0, 0.72, 1.25);
box(home, 0.88, 0.8, 0.08, 0xb8d6d5, -0.9, 1.32, 1.25);
box(home, 0.08, 0.82, 0.1, colors.paper, -0.9, 1.32, 1.31);
box(home, 0.9, 0.08, 0.1, colors.paper, -0.9, 1.32, 1.31);
box(home, 1.1, 0.12, 0.7, 0x9a744c, 0, 0.1, 1.48);
makeStaticSign(
"Shared destination",
"HOME",
"BOTH ROUTES END HERE",
"#d8a842",
new THREE.Vector3(0, 3.65, 8.0),
new THREE.Vector2(3.15, 1.49)
);
// Product displays beside the routes.
const disposableDisplay = new THREE.Group();
disposableDisplay.position.set(-7.25, 0, 3.8);
scene.add(disposableDisplay);
box(disposableDisplay, 2.2, 0.22, 1.6, 0xd2c3a7, 0, 0.14, 0);
const cartonColors = [colors.coral, colors.gold, colors.plum];
for (let i = 0; i < 3; i++) {
box(disposableDisplay, 0.42, 0.66, 0.34, cartonColors[i], -0.55 + i * 0.55, 0.58, 0);
box(disposableDisplay, 0.28, 0.09, 0.02, colors.paper, -0.55 + i * 0.55, 0.63, 0.18);
}
const reusableDisplay = new THREE.Group();
reusableDisplay.position.set(7.25, 0, 3.8);
scene.add(reusableDisplay);
box(reusableDisplay, 2.2, 0.22, 1.6, 0xd2c3a7, 0, 0.14, 0);
const jarColors = [colors.teal, colors.mint, colors.gold];
for (let i = 0; i < 3; i++) {
const x = -0.55 + i * 0.55;
cylinder(reusableDisplay, 0.19, 0.19, 0.47, jarColors[i], x, 0.49, 0, 8);
cylinder(reusableDisplay, 0.21, 0.21, 0.06, colors.ink, x, 0.76, 0, 8);
}
// Dynamic route count panels.
const disposablePanel = makeStaticSign(
"01 / Disposable route",
"0 PACKAGE UNITS",
"0 TRIPS · 8 UNITS PER TRIP",
"#e8795f",
new THREE.Vector3(-5.6, 2.25, 2.65),
new THREE.Vector2(3.65, 1.73)
);
const reusablePanel = makeStaticSign(
"02 / Reusable route",
"0 PACKAGE UNITS",
"0 TRIPS · JAR USES TRACKED SEPARATELY",
"#3f9586",
new THREE.Vector3(5.6, 2.25, 2.65),
new THREE.Vector2(3.65, 1.73)
);
// Route sign supports.
for (const x of [-5.6, 5.6]) {
box(scene, 0.11, 1.55, 0.11, colors.woodDark, x, 0.77, 2.65);
box(scene, 0.72, 0.1, 0.48, colors.woodDark, x, 0.07, 2.65);
}
function createTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
cylinder(tree, 0.16, 0.21, 1.55, colors.woodDark, 0, 0.78, 0, 7);
const crown = new THREE.Mesh(
new THREE.ConeGeometry(1.05, 2.2, 7),
material(colors.leaf)
);
crown.position.y = 2.12;
crown.castShadow = true;
tree.add(crown);
const crown2 = new THREE.Mesh(
new THREE.ConeGeometry(0.72, 1.5, 7),
material(colors.leafDark)
);
crown2.position.set(0.08, 2.82, -0.03);
crown2.castShadow = true;
tree.add(crown2);
}
createTree(-9.4, -2.8, 1.1);
createTree(9.6, -2.5, 1.15);
createTree(-10.2, 6.8, 0.9);
createTree(10.2, 7.0, 0.95);
// Low-poly planters.
for (const [x, z] of [[-4.2, -1.15], [4.2, -1.15]]) {
cylinder(scene, 0.35, 0.28, 0.42, colors.wood, x, 0.24, z, 7);
const plant = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.48, 0),
material(colors.leaf)
);
plant.position.set(x, 0.7, z);
plant.scale.y = 0.85;
plant.castShadow = true;
scene.add(plant);
}
// Reusable jar helper.
function addJar(parent, x, y, z, color = colors.teal) {
cylinder(parent, 0.13, 0.13, 0.29, color, x, y, z, 8);
cylinder(parent, 0.145, 0.145, 0.045, colors.ink, x, y + 0.17, z, 8);
}
function createActor(reusable) {
const group = new THREE.Group();
scene.add(group);
const accent = reusable ? colors.teal : colors.coral;
// Legs.
box(group, 0.14, 0.42, 0.16, colors.ink, -0.12, 0.25, 0);
box(group, 0.14, 0.42, 0.16, colors.ink, 0.12, 0.25, 0);
// Torso and arms.
box(group, 0.46, 0.58, 0.3, accent, 0, 0.75, 0);
box(group, 0.13, 0.47, 0.14, 0xd7a17e, -0.3, 0.76, 0.02);
box(group, 0.13, 0.47, 0.14, 0xd7a17e, 0.3, 0.76, 0.02);
// Head.
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.2, 8, 6),
material(0xe1b18a)
);
head.position.set(0, 1.23, 0);
head.castShadow = true;
group.add(head);
const hair = new THREE.Mesh(
new THREE.SphereGeometry(0.205, 8, 5, 0, Math.PI * 2, 0, Math.PI / 2),
material(colors.ink)
);
hair.position.set(0, 1.25, 0);
hair.castShadow = true;
group.add(hair);
if (reusable) {
// Basket with four jars.
box(group, 0.65, 0.25, 0.4, colors.wood, 0, 0.58, 0.38);
box(group, 0.08, 0.46, 0.08, colors.woodDark, -0.28, 0.85, 0.38);
box(group, 0.08, 0.46, 0.08, colors.woodDark, 0.28, 0.85, 0.38);
for (let i = 0; i < 4; i++) {
addJar(
group,
-0.19 + (i % 2) * 0.38,
0.82,
0.29 + Math.floor(i / 2) * 0.18,
i % 2 ? colors.gold : colors.mint
);
}
} else {
// Eight represented disposable packages.
for (let i = 0; i < 8; i++) {
const color = [colors.coral, colors.gold, colors.plum][i % 3];
box(
group,
0.21,
0.28,
0.18,
color,
-0.25 + (i % 2) * 0.5,
0.63 + Math.floor(i / 2) * 0.31,
-0.32
);
}
}
return group;
}
const disposableActor = createActor(false);
const reusableActor = createActor(true);
function placeActor(actor, curve) {
const p = curve.getPointAt(0);
const tangent = curve.getTangentAt(0);
actor.position.copy(p);
actor.rotation.y = Math.atan2(tangent.x, tangent.z);
}
placeActor(disposableActor, disposableCurve);
placeActor(reusableActor, reusableCurve);
// Manual orbit-style camera controls.
const cameraState = {
azimuth: 0.57,
polar: 0.93,
radius: 20.5,
target: new THREE.Vector3(0, 1.15, 1.25)
};
const cameraGoal = {
azimuth: cameraState.azimuth,
polar: cameraState.polar,
radius: cameraState.radius,
target: cameraState.target.clone()
};
function applyCamera() {
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.polar),
cameraState.target.z +
cameraState.radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
applyCamera();
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraGoal.azimuth -= dx * 0.006;
cameraGoal.polar = THREE.MathUtils.clamp(
cameraGoal.polar - dy * 0.005,
0.32,
1.28
);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraGoal.radius = THREE.MathUtils.clamp(
cameraGoal.radius + event.deltaY * 0.012,
9,
31
);
},
{ passive: false }
);
function setView(view) {
if (view === "disposable") {
cameraGoal.target.set(-2.4, 1.05, 1.6);
cameraGoal.azimuth = 0.38;
cameraGoal.polar = 1.02;
cameraGoal.radius = 13.7;
} else if (view === "reusable") {
cameraGoal.target.set(2.4, 1.05, 1.6);
cameraGoal.azimuth = 0.82;
cameraGoal.polar = 1.02;
cameraGoal.radius = 13.7;
} else {
cameraGoal.target.set(0, 1.15, 1.25);
cameraGoal.azimuth = 0.57;
cameraGoal.polar = 0.93;
cameraGoal.radius = 20.5;
}
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
setView(button.dataset.view);
});
});
// Fictional trip ledger.
const tripsPerRoute = 8;
const trips = { value: 0 };
let queuedTrips = 0;
let tripActive = false;
let tripStartTime = 0;
let runCounter = 0;
let activeRun = 0;
const tripDuration = 1800;
const tripCountElement = document.getElementById("trip-count");
const tripChipElement = document.getElementById("trip-chip");
const jarUsesElement = document.getElementById("jar-uses");
const packageTotalElement = document.getElementById("package-total");
const disposableTotalElement = document.getElementById("disposable-total");
const reusableTotalElement = document.getElementById("reusable-total");
const statusElement = document.getElementById("status");
function padded(number) {
return String(number).padStart(2, "0");
}
function updateLedger() {
const disposableUnits = trips.value * tripsPerRoute;
const reusableUnits = 0;
const jarUses = trips.value * tripsPerRoute;
const packageTotal = disposableUnits + reusableUnits;
tripCountElement.textContent = padded(trips.value);
tripChipElement.textContent = `Trip ${padded(trips.value)}`;
jarUsesElement.textContent = padded(jarUses);
packageTotalElement.textContent = padded(packageTotal);
disposableTotalElement.textContent = padded(disposableUnits);
reusableTotalElement.textContent = padded(reusableUnits);
disposablePanel.setText(
"01 / Disposable route",
`${disposableUnits} PACKAGE UNITS`,
`${trips.value} TRIP${trips.value === 1 ? "" : "S"} · 8 UNITS PER TRIP`
);
reusablePanel.setText(
"02 / Reusable route",
`${reusableUnits} PACKAGE UNITS`,
`${jarUses} JAR USES TRACKED SEPARATELY`
);
}
function requestTrips(count) {
queuedTrips += count;
if (!tripActive) beginTrip();
}
function beginTrip() {
if (queuedTrips <= 0) {
tripActive = false;
return;
}
tripActive = true;
activeRun = ++runCounter;
tripStartTime = performance.now();
const upcomingTrip = trips.value + 1;
statusElement.textContent =
`Recording fictional trip ${upcomingTrip} on both routes…`;
placeActor(disposableActor, disposableCurve);
placeActor(reusableActor, reusableCurve);
}
function finishTrip(run) {
if (run !== activeRun) return;
trips.value += 1;
queuedTrips = Math.max(0, queuedTrips - 1);
updateLedger();
if (queuedTrips > 0) {
statusElement.textContent =
`Trip ${trips.value} recorded. ${queuedTrips} remaining…`;
window.setTimeout(() => {
if (run === activeRun) beginTrip();
}, 220);
} else {
tripActive = false;
placeActor(disposableActor, disposableCurve);
placeActor(reusableActor, reusableCurve);
statusElement.textContent =
`${trips.value} fictional trip${trips.value === 1 ? "" : "s"} recorded. Counts only.`;
}
}
function resetLedger() {
queuedTrips = 0;
trips.value = 0;
tripActive = false;
activeRun = ++runCounter;
updateLedger();
placeActor(disposableActor, disposableCurve);
placeActor(reusableActor, reusableCurve);
statusElement.textContent = "Ledger reset. Ready for another fictional trip.";
}
document.getElementById("add-one").addEventListener("click", () => {
requestTrips(1);
});
document.getElementById("add-five").addEventListener("click", () => {
requestTrips(5);
});
document.getElementById("reset").addEventListener("click", resetLedger);
updateLedger();
// Animation loop.
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
// Smooth camera movement.
const smoothing = 1 - Math.pow(0.001, delta);
cameraState.azimuth +=
(cameraGoal.azimuth - cameraState.azimuth) * smoothing;
cameraState.polar +=
(cameraGoal.polar - cameraState.polar) * smoothing;
cameraState.radius +=
(cameraGoal.radius - cameraState.radius) * smoothing;
cameraState.target.lerp(cameraGoal.target, smoothing);
applyCamera();
if (tripActive) {
const progress = THREE.MathUtils.clamp(
(performance.now() - tripStartTime) / tripDuration,
0,
1
);
// A slight pause at the shop makes the parallel trip legible.
const eased =
progress < 0.16
? 0
: THREE.MathUtils.smoothstep(
(progress - 0.16) / 0.84,
0,
1
);
const disposablePosition =
disposableCurve.getPointAt(eased);
const reusablePosition = reusableCurve.getPointAt(eased);
const disposableTangent =
disposableCurve.getTangentAt(eased);
const reusableTangent = reusableCurve.getTangentAt(eased);
disposableActor.position.copy(disposablePosition);
reusableActor.position.copy(reusablePosition);
disposableActor.rotation.y = Math.atan2(
disposableTangent.x,
disposableTangent.z
);
reusableActor.rotation.y = Math.atan2(
reusableTangent.x,
reusableTangent.z
);
// Gentle walking bounce.
const bounce = Math.sin(elapsed * 13) * 0.035;
disposableActor.position.y += Math.abs(bounce);
reusableActor.position.y += Math.abs(Math.sin(elapsed * 13 + 1)) * 0.035;
if (progress >= 1) finishTrip(activeRun);
}
renderer.render(scene, camera);
}
animate();
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```