Prompt specification
Build or customize the Three.js 3D scene "Community seed-exchange table" 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: Community seed-exchange table
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/community-seed-exchange-table-x1103
Scene Description Prompt:
Use Three.js from cdnjs to compose seed packets, plant photographs represented as simple diagrams, sign-in cards, and visitors; exchanged packets retain origin labels while inventory changes visibly. Deliver one self-contained HTML file with stylized solid shapes.
Working Three.js Starter (community-seed-exchange-table-x1103):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Seed Exchange</title>
<style>
:root {
--ink: #24352e;
--green: #315747;
--cream: #f4ead6;
--paper: #fff8e9;
--gold: #e5b85c;
--terra: #c96f4b;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eadfc9;
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;
}
.brand, .inventory, .help, .status {
position: fixed;
z-index: 5;
pointer-events: none;
}
.brand {
top: 22px;
left: 24px;
max-width: 390px;
padding: 17px 20px 16px;
border: 1px solid rgba(36, 53, 46, .13);
border-left: 6px solid var(--terra);
border-radius: 8px 16px 16px 8px;
background: rgba(255, 248, 233, .92);
box-shadow: 0 10px 30px rgba(57, 47, 31, .12);
backdrop-filter: blur(8px);
}
.brand h1 {
margin: 0;
color: var(--green);
font-size: clamp(20px, 2.3vw, 34px);
line-height: .98;
letter-spacing: -.04em;
text-transform: uppercase;
}
.brand p {
margin: 8px 0 0;
max-width: 330px;
font-size: 12px;
line-height: 1.45;
color: #56645e;
}
.inventory {
top: 22px;
right: 24px;
width: 238px;
padding: 15px 16px 14px;
border: 1px solid rgba(36, 53, 46, .12);
border-radius: 14px;
background: rgba(255, 248, 233, .92);
box-shadow: 0 10px 30px rgba(57, 47, 31, .12);
backdrop-filter: blur(8px);
}
.inventory h2 {
margin: 0 0 10px;
color: var(--green);
font-size: 11px;
letter-spacing: .16em;
text-transform: uppercase;
}
.inventory-row {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 8px;
padding: 6px 0;
border-top: 1px solid rgba(36, 53, 46, .09);
font-size: 11px;
}
.inventory-row:first-of-type { border-top: 0; }
.inventory-row .swatch {
width: 9px;
height: 9px;
border-radius: 2px;
}
.inventory-row .name {
font-weight: 800;
letter-spacing: .045em;
text-transform: uppercase;
}
.inventory-row .origin {
display: block;
margin-top: 2px;
color: #718078;
font-size: 8px;
font-weight: 700;
letter-spacing: .08em;
}
.inventory-row b {
min-width: 23px;
padding: 3px 6px;
border-radius: 9px;
color: var(--paper);
background: var(--green);
text-align: center;
font-size: 11px;
}
.inventory-row.sold-out b { background: #a25d4d; }
.inventory small {
display: block;
margin-top: 10px;
color: var(--terra);
font-size: 8px;
font-weight: 900;
letter-spacing: .12em;
text-transform: uppercase;
}
.help {
left: 24px;
bottom: 66px;
padding: 9px 12px;
border-radius: 9px;
color: var(--paper);
background: rgba(36, 53, 46, .86);
box-shadow: 0 8px 24px rgba(36, 53, 46, .18);
font-size: 10px;
font-weight: 750;
letter-spacing: .035em;
}
.help span { color: #f4c86c; }
#reset {
position: fixed;
z-index: 7;
left: 24px;
bottom: 20px;
padding: 10px 14px;
border: 0;
border-radius: 9px;
color: var(--paper);
background: var(--terra);
box-shadow: 0 7px 20px rgba(111, 52, 35, .2);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 850;
letter-spacing: .08em;
text-transform: uppercase;
}
#reset:hover { background: #b96040; }
.status {
right: 24px;
bottom: 22px;
max-width: min(480px, calc(100vw - 48px));
padding: 12px 15px;
border: 1px solid rgba(36, 53, 46, .12);
border-radius: 10px;
color: var(--ink);
background: rgba(255, 248, 233, .94);
box-shadow: 0 8px 26px rgba(57, 47, 31, .13);
font-size: 11px;
line-height: 1.45;
}
.status strong { color: var(--terra); }
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: var(--green);
background: var(--cream);
font-size: 13px;
font-weight: 850;
letter-spacing: .14em;
text-transform: uppercase;
transition: opacity .35s ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 760px) {
.brand { top: 12px; left: 12px; max-width: 55vw; padding: 12px 13px; }
.brand p { display: none; }
.inventory { top: 12px; right: 12px; width: 175px; padding: 11px; }
.inventory-row { padding: 4px 0; font-size: 9px; }
.inventory small { display: none; }
.help { left: 12px; bottom: 56px; max-width: 48vw; }
#reset { left: 12px; bottom: 12px; }
.status { right: 12px; bottom: 12px; max-width: 50vw; }
}
</style>
</head>
<body>
<div id="loading">Preparing the seed table…</div>
<header class="brand">
<h1>The Seed<br>Exchange</h1>
<p>Take one packet, leave one packet. Every packet keeps the origin of the garden where its seeds were saved.</p>
</header>
<aside class="inventory">
<h2>Live inventory</h2>
<div id="inventory-list"></div>
<small>Origin labels never change</small>
</aside>
<div class="help"><span>Click a packet</span> to exchange · drag to orbit · scroll to zoom</div>
<button id="reset" type="button">Reset view</button>
<div class="status" id="status"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.getElementById("loading");
const statusEl = document.getElementById("status");
const inventoryList = document.getElementById("inventory-list");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeadfc9);
scene.fog = new THREE.Fog(0xeadfc9, 15, 29);
const camera = new THREE.PerspectiveCamera(38, innerWidth / innerHeight, 0.1, 80);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, 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 seed exchange counter");
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff5dc, 0x45624f, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.0);
sun.position.set(-5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7d8c4, 1.0);
fill.position.set(7, 5, -2);
scene.add(fill);
const palette = {
green: 0x315747,
deepGreen: 0x213f35,
cream: 0xf1e5ce,
paper: 0xfff8e9,
terra: 0xc96f4b,
gold: 0xe5b85c,
ink: 0x24352e,
wood: 0xb77c52,
sage: 0x789a73
};
const material = (color, roughness = 0.86) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness: 0 });
function addBox(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material(color, options.roughness ?? 0.86)
);
mesh.position.set(...position);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, rTop, rBottom, height, position, color, segments = 12) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rTop, rBottom, height, segments),
material(color)
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
const radius = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + w, y, x + w, y + h, radius);
ctx.arcTo(x + w, y + h, x, y + h, radius);
ctx.arcTo(x, y + h, x, y, radius);
ctx.arcTo(x, y, x + w, y, radius);
ctx.closePath();
}
function makeCanvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function drawBotanical(ctx, type, x, y, scale = 1) {
ctx.save();
ctx.translate(x, y);
ctx.scale(scale, scale);
ctx.lineCap = "round";
ctx.lineJoin = "round";
// Main stem
ctx.strokeStyle = "#3f754b";
ctx.lineWidth = 12;
ctx.beginPath();
ctx.moveTo(0, 120);
ctx.bezierCurveTo(-5, 45, 10, -35, 0, -112);
ctx.stroke();
// Leaves
const leaf = (lx, ly, angle, sx = 1) => {
ctx.save();
ctx.translate(lx, ly);
ctx.rotate(angle);
ctx.fillStyle = "#5f9155";
ctx.beginPath();
ctx.ellipse(0, 0, 49 * sx, 22, 0, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = "#3f754b";
ctx.lineWidth = 4;
ctx.beginPath();
ctx.moveTo(-40 * sx, 0);
ctx.lineTo(38 * sx, 0);
ctx.stroke();
ctx.restore();
};
leaf(-31, 31, -0.48);
leaf(31, 2, 0.48);
leaf(-28, -39, -0.58, 0.86);
leaf(31, -69, 0.5, 0.82);
if (type.kind === "sun") {
ctx.fillStyle = "#e7ad3d";
for (let i = 0; i < 12; i++) {
const a = (i / 12) * Math.PI * 2;
ctx.save();
ctx.translate(Math.cos(a) * 47, -112 + Math.sin(a) * 47);
ctx.rotate(a);
ctx.beginPath();
ctx.ellipse(0, 0, 25, 11, 0, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
}
ctx.fillStyle = "#68452c";
ctx.beginPath();
ctx.arc(0, -112, 31, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#89603a";
for (let i = 0; i < 12; i++) {
const a = i * 2.4;
ctx.beginPath();
ctx.arc(Math.cos(a) * 16, -112 + Math.sin(a) * 16, 4, 0, Math.PI * 2);
ctx.fill();
}
} else if (type.kind === "tomato") {
ctx.strokeStyle = "#477947";
ctx.lineWidth = 7;
ctx.beginPath();
ctx.moveTo(-62, -55);
ctx.quadraticCurveTo(0, -78, 58, -44);
ctx.stroke();
leaf(-62, -55, -0.2, 0.65);
leaf(58, -44, 0.55, 0.65);
ctx.fillStyle = "#d9543f";
ctx.beginPath();
ctx.arc(-24, -27, 38, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#e56c51";
ctx.beginPath();
ctx.arc(-34, -38, 11, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#477947";
ctx.beginPath();
ctx.moveTo(-24, -64);
ctx.lineTo(-7, -76);
ctx.lineTo(-10, -55);
ctx.closePath();
ctx.fill();
} else if (type.kind === "lavender") {
ctx.strokeStyle = "#4e7651";
ctx.lineWidth = 7;
for (const dx of [-30, 0, 30]) {
ctx.beginPath();
ctx.moveTo(dx * 0.45, 15);
ctx.quadraticCurveTo(dx, -40, dx, -112);
ctx.stroke();
for (let i = 0; i < 6; i++) {
ctx.fillStyle = i % 2 ? "#8f71a5" : "#75578d";
ctx.beginPath();
ctx.ellipse(dx, -87 - i * 15, 14, 10, 0, 0, Math.PI * 2);
ctx.fill();
}
}
} else {
ctx.strokeStyle = "#4b7c4d";
ctx.lineWidth = 7;
ctx.beginPath();
ctx.moveTo(-72, -76);
ctx.quadraticCurveTo(0, -103, 72, -62);
ctx.stroke();
leaf(-72, -76, -0.2, 0.6);
leaf(72, -62, 0.3, 0.6);
ctx.fillStyle = "#7f9b4c";
for (const p of [[-39, -41, -0.35], [2, -50, 0.15], [38, -31, 0.42]]) {
ctx.save();
ctx.translate(p[0], p[1]);
ctx.rotate(p[2]);
ctx.beginPath();
ctx.ellipse(0, 0, 14, 40, 0, 0, Math.PI * 2);
ctx.fill();
ctx.restore();
}
}
ctx.restore();
}
const types = [
{
key: "sun",
name: "Sunflower",
subtitle: "HELIANTHUS ANNUUS",
origin: "Rooftop A",
color: "#dca94a",
edge: "#9c7228",
ink: "#49391f",
kind: "sun",
count: 2,
x: -3.45
},
{
key: "tomato",
name: "Tomato",
subtitle: "SOLANUM LYCOPSERCUM",
origin: "Kitchen Garden",
color: "#c9684d",
edge: "#914836",
ink: "#472820",
kind: "tomato",
count: 3,
x: -1.35
},
{
key: "lavender",
name: "Lavender",
subtitle: "LAVANDULA ANGUSTIFOLIA",
origin: "Hillside B",
color: "#89729d",
edge: "#62506f",
ink: "#342a3e",
kind: "lavender",
count: 2,
x: 0.75
},
{
key: "bean",
name: "Bean",
subtitle: "PHASEOLUS VULGARIS",
origin: "Alley Garden",
color: "#77946b",
edge: "#536b4d",
ink: "#2f402d",
kind: "bean",
count: 0,
x: 2.85
}
];
function makePacketTexture(type) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 704;
const ctx = canvas.getContext("2d");
ctx.fillStyle = type.color;
ctx.fillRect(0, 0, 512, 704);
ctx.strokeStyle = "#fff4d7";
ctx.lineWidth = 12;
ctx.strokeRect(18, 18, 476, 668);
ctx.fillStyle = type.ink;
ctx.fillRect(28, 29, 456, 76);
ctx.fillStyle = "#fff4d7";
ctx.textAlign = "center";
ctx.font = "900 25px Arial";
ctx.fillText("COMMUNITY SEED LIBRARY", 256, 77);
ctx.fillStyle = type.ink;
ctx.textAlign = "center";
ctx.font = "900 52px Arial";
ctx.fillText(type.name.toUpperCase(), 256, 160, 420);
ctx.font = "700 18px Arial";
ctx.fillText(type.subtitle, 256, 194, 420);
ctx.fillStyle = "#f8f0dc";
roundedRect(ctx, 47, 220, 418, 305, 18);
ctx.fill();
ctx.strokeStyle = type.edge;
ctx.lineWidth = 6;
roundedRect(ctx, 47, 220, 418, 305, 18);
ctx.stroke();
drawBotanical(ctx, type, 256, 365, 0.79);
ctx.fillStyle = type.ink;
roundedRect(ctx, 35, 558, 442, 108, 12);
ctx.fill();
ctx.fillStyle = "#fff4d7";
ctx.font = "800 16px Arial";
ctx.fillText("ORIGIN", 256, 588);
ctx.font = "900 30px Arial";
ctx.fillText(type.origin.toUpperCase(), 256, 629, 400);
ctx.font = "700 13px Arial";
ctx.fillText("KEEP THIS LABEL WITH THE SEEDS", 256, 653);
return makeCanvasTexture(canvas);
}
function makeGuideTexture(type) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 512;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f7efdc";
ctx.fillRect(0, 0, 768, 512);
ctx.fillStyle = type.color;
ctx.fillRect(0, 0, 768, 78);
ctx.fillStyle = "#24352e";
ctx.textAlign = "left";
ctx.font = "900 34px Arial";
ctx.fillText(type.name.toUpperCase(), 34, 49);
ctx.textAlign = "right";
ctx.font = "800 17px Arial";
ctx.fillText("PLANT DIAGRAM", 732, 46);
ctx.fillStyle = "#fffaf0";
roundedRect(ctx, 28, 101, 400, 380, 16);
ctx.fill();
ctx.strokeStyle = type.edge;
ctx.lineWidth = 4;
roundedRect(ctx, 28, 101, 400, 380, 16);
ctx.stroke();
drawBotanical(ctx, type, 228, 284, 1.08);
ctx.fillStyle = "#526159";
ctx.font = "800 17px Arial";
ctx.fillText("PLANT ID", 462, 142);
ctx.font = "500 25px Arial";
ctx.fillText(type.subtitle, 462, 177, 270);
ctx.fillStyle = "#d9cfb8";
ctx.fillRect(462, 207, 260, 4);
ctx.fillRect(462, 286, 260, 4);
ctx.fillRect(462, 365, 260, 4);
ctx.fillStyle = "#526159";
ctx.font = "800 17px Arial";
ctx.fillText("GROW", 462, 242);
ctx.font = "500 20px Arial";
ctx.fillText("FULL SUN · RICH SOIL", 462, 270, 260);
ctx.fillText("SOW IN WARM SEASON", 462, 349, 260);
ctx.fillText("SAVE SEEDS EACH YEAR", 462, 428, 260);
return makeCanvasTexture(canvas);
}
function makeStockCanvas(type) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 256;
const ctx = canvas.getContext("2d");
type.stockCanvas = canvas;
type.stockTexture = makeCanvasTexture(canvas);
updateStockCanvas(type);
return type.stockTexture;
}
function updateStockCanvas(type) {
const ctx = type.stockCanvas.getContext("2d");
ctx.fillStyle = "#fff8e9";
ctx.fillRect(0, 0, 768, 256);
ctx.fillStyle = type.color;
ctx.fillRect(0, 0, 24, 256);
ctx.fillStyle = "#24352e";
ctx.textAlign = "left";
ctx.font = "900 37px Arial";
ctx.fillText(type.name.toUpperCase(), 52, 67, 445);
ctx.fillStyle = "#68756e";
ctx.font = "800 19px Arial";
ctx.fillText("ORIGIN · " + type.origin.toUpperCase(), 52, 104, 460);
ctx.strokeStyle = "#d9cfb8";
ctx.lineWidth = 5;
ctx.beginPath();
ctx.moveTo(52, 139);
ctx.lineTo(510, 139);
ctx.stroke();
ctx.fillStyle = type.count > 0 ? "#315747" : "#a25d4d";
ctx.textAlign = "right";
ctx.font = "900 106px Arial";
ctx.fillText(String(type.count), 700, 174);
ctx.font = "900 24px Arial";
ctx.fillText(type.count === 1 ? "PACKET" : "PACKETS", 705, 216);
ctx.textAlign = "left";
ctx.fillStyle = type.count > 0 ? "#68756e" : "#a25d4d";
ctx.font = "900 15px Arial";
ctx.fillText(type.count > 0 ? "READY TO SWAP" : "CURRENTLY SOLD OUT", 52, 211);
type.stockTexture.needsUpdate = true;
}
function makeWallSignTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1536;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#315747";
ctx.fillRect(0, 0, 1536, 256);
ctx.strokeStyle = "#e4b65a";
ctx.lineWidth = 9;
ctx.strokeRect(18, 18, 1500, 220);
ctx.textAlign = "center";
ctx.fillStyle = "#fff3d5";
ctx.font = "900 95px Arial";
ctx.fillText("THE SEED EXCHANGE", 768, 123);
ctx.fillStyle = "#e6c47d";
ctx.font = "800 28px Arial";
ctx.fillText("TAKE ONE · LEAVE ONE · KEEP THE ORIGIN", 768, 186);
return makeCanvasTexture(canvas);
}
function makeSignInTexture(name = "VISITOR SIGN-IN") {
const canvas = document.createElement("canvas");
canvas.width = 480;
canvas.height = 680;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#fffaf0";
ctx.fillRect(0, 0, 480, 680);
ctx.fillStyle = "#315747";
ctx.fillRect(0, 0, 480, 98);
ctx.textAlign = "center";
ctx.fillStyle = "#fff3d5";
ctx.font = "900 34px Arial";
ctx.fillText(name, 240, 61, 430);
ctx.textAlign = "left";
ctx.fillStyle = "#56645e";
ctx.font = "800 18px Arial";
ctx.fillText("NAME", 38, 142);
ctx.fillText("SEEDS BROUGHT", 38, 292);
ctx.fillText("SEEDS TAKEN", 38, 478);
ctx.strokeStyle = "#9aa39d";
ctx.lineWidth = 3;
[185, 338, 522].forEach(y => {
ctx.beginPath();
ctx.moveTo(38, y);
ctx.lineTo(438, y);
ctx.stroke();
});
ctx.fillStyle = "#315747";
ctx.font = "italic 22px Arial";
ctx.fillText("M. Rivera", 42, 173);
ctx.fillText("sunflower mix", 42, 326);
ctx.fillText("tomato & beans", 42, 510);
ctx.strokeStyle = "#c96f4b";
ctx.lineWidth = 7;
ctx.lineCap = "round";
ctx.beginPath();
ctx.moveTo(306, 318);
ctx.bezierCurveTo(340, 295, 355, 346, 390, 313);
ctx.stroke();
ctx.fillStyle = "#e5b85c";
ctx.beginPath();
ctx.arc(430, 640, 24, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#315747";
ctx.textAlign = "center";
ctx.font = "900 15px Arial";
ctx.fillText("TODAY", 430, 645);
return makeCanvasTexture(canvas);
}
types.forEach(type => {
type.texture = makePacketTexture(type);
makeStockCanvas(type);
});
// Room
const room = new THREE.Group();
scene.add(room);
addBox(room, [20, 0.18, 16], [0, -0.09, 0], 0xd8cbb3, { receiveShadow: true });
addBox(room, [20, 7, 0.22], [0, 3.4, -4.82], 0xe7dcc4);
addBox(room, [0.22, 7, 12], [-9.85, 3.4, 0], 0xdacfb7);
addBox(room, [0.22, 7, 12], [9.85, 3.4, 0], 0xdacfb7);
// Back-wall timber accents
for (let x = -8; x <= 8; x += 2) {
addBox(room, [0.08, 5.7, 0.06], [x, 3.25, -4.68], 0xcbb896, { castShadow: false });
}
const wallSign = new THREE.Mesh(
new THREE.PlaneGeometry(8.6, 1.44),
new THREE.MeshBasicMaterial({ map: makeWallSignTexture() })
);
wallSign.position.set(0, 4.95, -4.58);
room.add(wallSign);
function addGuide(type, x) {
addBox(room, [2.45, 1.9, 0.16], [x, 3.18, -4.55], palette.wood);
const panel = new THREE.Mesh(
new THREE.PlaneGeometry(2.26, 1.7),
new THREE.MeshBasicMaterial({ map: makeGuideTexture(type) })
);
panel.position.set(x, 3.18, -4.455);
room.add(panel);
}
addGuide(types[0], -3.05);
addGuide(types[1], 0);
addGuide(types[2], 3.05);
// Counter
const counter = new THREE.Group();
scene.add(counter);
addBox(counter, [10.1, 1.38, 2.48], [0, 0.69, 0], palette.green);
addBox(counter, [10.55, 0.18, 2.86], [0, 1.47, 0.04], 0xe8d9bd);
addBox(counter, [9.95, 0.12, 0.08], [0, 1.28, 1.275], palette.gold);
addBox(counter, [9.95, 0.12, 0.08], [0, 0.13, 1.275], palette.terra);
// Counter toe shadow and side panels
addBox(counter, [10.02, 0.12, 2.42], [0, 0.08, 0], palette.deepGreen);
for (const x of [-4.92, 4.92]) {
addBox(counter, [0.16, 1.25, 2.35], [x, 0.72, 0], palette.deepGreen);
}
const pickMeshes = [];
const displayPositions = [];
const displayPackets = [];
function createPacket(type, interactive = false) {
const group = new THREE.Group();
group.userData.type = type;
const front = new THREE.MeshStandardMaterial({
map: type.texture,
roughness: 0.82,
metalness: 0
});
const edge = material(type.edge, 0.9);
const back = material(type.edge, 0.95);
const packetMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.78, 1.12, 0.12),
[edge, edge, edge, edge, front, back]
);
packetMesh.castShadow = true;
packetMesh.receiveShadow = true;
packetMesh.userData.pickType = interactive ? type : null;
group.add(packetMesh);
const hoverBacking = new THREE.Mesh(
new THREE.BoxGeometry(0.88, 1.22, 0.035),
new THREE.MeshStandardMaterial({
color: 0xf1c55f,
roughness: 0.8,
emissive: 0x6b4a08,
emissiveIntensity: 0.25
})
);
hoverBacking.position.z = -0.09;
hoverBacking.visible = false;
group.add(hoverBacking);
group.userData.hoverBacking = hoverBacking;
// A small folded top detail emphasizes the packet as a solid object.
addBox(group, [0.63, 0.025, 0.018], [0, 0.46, 0.071], 0xf8e8c7, {
castShadow: false,
roughness: 1
});
if (interactive) pickMeshes.push(packetMesh);
return group;
}
types.forEach((type, typeIndex) => {
const positions = [
{ x: type.x, y: 2.16, z: 0.68, ry: -0.04 },
{ x: type.x - 0.27, y: 2.14, z: 0.35, ry: 0.04 },
{ x: type.x + 0.27, y: 2.14, z: 0.34, ry: -0.07 },
{ x: type.x - 0.12, y: 2.12, z: 0.08, ry: 0.08 },
{ x: type.x + 0.18, y: 2.12, z: 0.04, ry: -0.09 }
];
displayPositions[type.key] = positions;
const packets = [];
positions.forEach(position => {
const packet = createPacket(type, true);
packet.position.set(position.x, position.y, position.z);
packet.rotation.y = position.ry;
counter.add(packet);
packets.push(packet);
});
displayPackets[type.key] = packets;
const board = new THREE.Mesh(
new THREE.PlaneGeometry(1.94, 0.65),
new THREE.MeshStandardMaterial({
map: type.stockTexture,
roughness: 0.9,
emissive: 0x000000
})
);
board.position.set(type.x, 0.91, 1.285);
board.userData.pickType = type;
counter.add(board);
pickMeshes.push(board);
type.board = board;
});
function updateDisplayPackets() {
types.forEach(type => {
displayPackets[type.key].forEach((packet, index) => {
packet.visible = index < type.count;
});
});
}
function updateInventory() {
inventoryList.innerHTML = types.map(type => `
<div class="inventory-row ${type.count === 0 ? "sold-out" : ""}">
<span class="swatch" style="background:${type.color}"></span>
<span>
<span class="name">${type.name}</span>
<span class="origin">${type.origin}</span>
</span>
<b>${type.count}</b>
</div>
`).join("");
types.forEach(type => {
updateStockCanvas(type);
if (type.board) type.board.material.emissive.set(0x000000);
});
updateDisplayPackets();
}
// Sign-in cards and a pen
const signInTexture = makeSignInTexture();
for (let i = 0; i < 2; i++) {
const cardGroup = new THREE.Group();
cardGroup.position.set(4.48 + i * 0.05, 2.17, 0.28 - i * 0.15);
cardGroup.rotation.y = -0.12 + i * 0.08;
cardGroup.rotation.x = -0.03;
const card = new THREE.Mesh(
new THREE.BoxGeometry(0.76, 1.08, 0.045),
[
material(0xded1b5),
material(0xded1b5),
material(0xded1b5),
material(0xded1b5),
new THREE.MeshStandardMaterial({ map: signInTexture, roughness: 0.9 }),
material(0xded1b5)
]
);
card.castShadow = true;
cardGroup.add(card);
addBox(cardGroup, [0.25, 0.08, 0.08], [0, 0.53, 0.05], 0x9eaaa2);
counter.add(cardGroup);
}
const pen = addCylinder(counter, 0.035, 0.035, 0.85, [4.0, 1.59, 0.8], 0xc96f4b, 8);
pen.rotation.z = Math.PI / 2;
pen.rotation.y = 0.28;
// Small potted plant
function addPottedPlant(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 1.57, z);
group.scale.setScalar(scale);
addCylinder(group, 0.42, 0.31, 0.58, [0, 0.29, 0], 0xb96848, 10);
addCylinder(group, 0.45, 0.45, 0.09, [0, 0.55, 0], 0xd98b64, 10);
addCylinder(group, 0.025, 0.035, 1.35, [0, 1.18, 0], 0x4f774b, 8);
const leaves = [
[-0.25, 1.25, 0, -0.5], [0.25, 1.55, 0, 0.55],
[-0.22, 1.85, 0.05, -0.6], [0.18, 2.02, 0, 0.62],
[-0.08, 2.18, -0.02, -0.15]
];
leaves.forEach(([lx, ly, lz, rz]) => {
const leaf = new THREE.Mesh(
new THREE.SphereGeometry(0.24, 10, 7),
material(lz ? 0x638d5c : 0x769d68)
);
leaf.position.set(lx, ly, lz);
leaf.scale.set(0.55, 1.45, 0.28);
leaf.rotation.z = rz;
leaf.castShadow = true;
group.add(leaf);
});
counter.add(group);
return group;
}
addPottedPlant(-4.72, -0.45, 0.9);
// Stylized visitors
function createVisitor(shirtColor, skinColor, hairColor, position, rotation = 0, backpack = false) {
const root = new THREE.Group();
root.position.copy(position);
root.rotation.y = rotation;
const skin = material(skinColor);
const shirt = material(shirtColor);
const hair = material(hairColor);
const pants = material(0x344c5a);
addCylinder(root, 0.17, 0.14, 0.78, [-0.18, 0.48, 0], pants, 9);
addCylinder(root, 0.17, 0.14, 0.78, [0.18, 0.48, 0], pants, 9);
addBox(root, [0.31, 0.15, 0.48], [-0.18, 0.09, 0.09], 0x263833);
addBox(root, [0.31, 0.15, 0.48], [0.18, 0.09, 0.09], 0x263833);
addCylinder(root, 0.43, 0.53, 1.02, [0, 1.37, 0], shirtColor, 10);
addCylinder(root, 0.12, 0.12, 0.18, [0, 1.96, 0], skinColor, 10);
const head = new THREE.Mesh(new THREE.SphereGeometry(0.34, 16, 12), skin);
head.position.set(0, 2.22, 0);
head.castShadow = true;
root.add(head);
const hairCap = new THREE.Mesh(new THREE.SphereGeometry(0.35, 16, 10), hair);
hairCap.position.set(0, 2.31, -0.035);
hairCap.scale.set(1.02, 0.65, 1.02);
hairCap.castShadow = true;
root.add(hairCap);
const nose = new THREE.Mesh(new THREE.SphereGeometry(0.075, 10, 8), skin);
nose.position.set(0, 2.20, 0.32);
root.add(nose);
const leftArm = addCylinder(root, 0.105, 0.12, 0.75, [-0.49, 1.35, 0.03], shirtColor, 9);
leftArm.rotation.z = -0.20;
const rightArm = addCylinder(root, 0.105, 0.12, 0.75, [0.49, 1.35, 0.03], shirtColor, 9);
rightArm.rotation.z = 0.20;
const leftHand = new THREE.Mesh(new THREE.SphereGeometry(0.12, 10, 8), skin);
leftHand.position.set(-0.57, 0.98, 0.03);
root.add(leftHand);
const rightHand = new THREE.Mesh(new THREE.SphereGeometry(0.12, 10, 8), skin);
rightHand.position.set(0.57, 0.98, 0.03);
root.add(rightHand);
if (backpack) {
addBox(root, [0.68, 0.8, 0.28], [0, 1.45, -0.42], 0x9b6446);
addBox(root, [0.5, 0.25, 0.05], [0, 1.52, -0.575], 0xc99162);
addBox(root, [0.07, 0.8, 0.07], [-0.3, 1.55, 0.28], 0x6c4938);
addBox(root, [0.07, 0.8, 0.07], [0.3, 1.55, 0.28], 0x6c4938);
}
const hand = new THREE.Object3D();
hand.position.set(0.62, 1.32, 0.2);
hand.rotation.set(-0.14, 0.08, 0.04);
root.add(hand);
scene.add(root);
return { root, hand, baseY: position.y };
}
const mainVisitor = createVisitor(
0xc96f4b,
0xa96f4e,
0x2e2925,
new THREE.Vector3(1.35, 0, 3.45),
Math.PI,
true
);
const secondVisitor = createVisitor(
0x6f8c79,
0xd19a73,
0x4b382b,
new THREE.Vector3(-4.15, 0, 3.05),
2.62,
false
);
mainVisitor.hand.updateWorldMatrix(true, true);
let visitorPacket = createPacket(types[3], false);
mainVisitor.hand.add(visitorPacket);
visitorPacket.position.set(0, 0, 0);
visitorPacket.rotation.set(0, 0, 0);
// Exchange animation state
const animations = [];
let hoveredType = null;
function setStatus(message, emphasis = "") {
statusEl.innerHTML = emphasis ? `<strong>${emphasis}</strong> ${message}` : message;
}
function startExchange(type) {
if (animations.length) {
setStatus("Finish the current exchange before choosing another packet.");
return;
}
if (type.count <= 0) {
setStatus(`${type.name} is currently sold out. Choose another packet.`, "SOLD OUT ·");
return;
}
if (visitorPacket.userData.type.key === type.key) {
setStatus(`The visitor is already carrying ${type.name.toLowerCase()} from ${type.origin}.`, "TRY ANOTHER ·");
return;
}
const outgoing = createPacket(type, false);
const sourcePosition = new THREE.Vector3(type.x, 2.18, 0.72);
outgoing.position.copy(sourcePosition);
outgoing.rotation.y = -0.05;
scene.add(outgoing);
mainVisitor.hand.updateWorldMatrix(true, true);
const handPosition = new THREE.Vector3();
mainVisitor.hand.getWorldPosition(handPosition);
const incoming = visitorPacket;
let incomingType = null;
let incomingTarget = null;
if (incoming) {
incomingType = incoming.userData.type;
scene.attach(incoming);
incomingType.count += 1;
const slot = Math.min(incomingType.count - 1, displayPositions[incomingType.key].length - 1);
const targetPosition = displayPositions[incomingType.key][slot];
incomingTarget = new THREE.Vector3(targetPosition.x, targetPosition.y, targetPosition.z);
}
type.count -= 1;
updateInventory();
animations.push({
elapsed: 0,
duration: 1.55,
outgoing,
incoming,
incomingTarget,
sourcePosition,
handPosition,
type
});
setStatus(
`The visitor gives ${incomingType.name.toLowerCase()} from ${incomingType.origin} and receives ${type.name.toLowerCase()} from ${type.origin}.`,
"EXCHANGE ·"
);
}
function completeExchange(animation) {
if (animation.incoming) {
animation.incoming.removeFromParent();
animation.incoming.traverse(object => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material) ? object.material : [object.material];
materials.forEach(m => m.dispose());
}
});
}
mainVisitor.hand.add(animation.outgoing);
animation.outgoing.position.set(0, 0, 0);
animation.outgoing.rotation.set(0, 0, 0);
visitorPacket = animation.outgoing;
setStatus(
`${animation.type.name} from ${animation.type.origin} is now in the visitor’s hand. The packet’s origin label is unchanged.`,
"SWAP COMPLETE ·"
);
}
// Camera controls implemented directly, without addons.
const cameraState = {
target: new THREE.Vector3(0, 2.15, 0),
theta: 0.46,
phi: 1.02,
radius: 13.1
};
function updateCamera() {
const { target, theta, phi, radius } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.theta = 0.46;
cameraState.phi = 1.02;
cameraState.radius = 13.1;
updateCamera();
}
document.getElementById("reset").addEventListener("click", resetCamera);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let lastX = 0;
let lastY = 0;
function pickType(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickMeshes, false);
for (const hit of hits) {
const type = hit.object.userData.pickType;
if (type && type.count > 0) return type;
}
return null;
}
function updateHover(event) {
const next = pickType(event);
if (next === hoveredType) return;
hoveredType = next;
types.forEach(type => {
displayPackets[type.key].forEach(packet => {
packet.userData.hoverBacking.visible = type.key === hoveredType?.key;
});
type.board.material.emissive.set(
type.key === hoveredType?.key ? 0x5a4313 : 0x000000
);
type.board.material.emissiveIntensity = type.key === hoveredType?.key ? 0.55 : 0;
});
renderer.domElement.style.cursor = hoveredType ? "pointer" : "grab";
}
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = true;
pointerMoved = false;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.abs(dx) + Math.abs(dy) > 3) pointerMoved = true;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi + dy * 0.005, 0.56, 1.36);
lastX = event.clientX;
lastY = event.clientY;
updateCamera();
} else {
updateHover(event);
}
});
renderer.domElement.addEventListener("pointerup", event => {
pointerDown = false;
renderer.domElement.style.cursor = hoveredType ? "pointer" : "grab";
if (!pointerMoved) {
const type = pickType(event);
if (type) startExchange(type);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointerleave", () => {
hoveredType = null;
types.forEach(type => {
displayPackets[type.key].forEach(packet => packet.userData.hoverBacking.visible = false);
type.board.material.emissive.set(0x000000);
});
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
8.2,
18
);
updateCamera();
}, { passive: false });
addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") resetCamera();
if (event.key === "+" || event.key === "=") {
cameraState.radius = Math.max(8.2, cameraState.radius - 0.7);
updateCamera();
}
if (event.key === "-") {
cameraState.radius = Math.min(18, cameraState.radius + 0.7);
updateCamera();
}
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
updateInventory();
updateCamera();
setStatus(
"The visitor brought a bean packet from Alley Garden. Choose a packet to exchange; the counter counts update immediately.",
"WELCOME ·"
);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.04);
const time = clock.elapsedTime;
// Gentle visitor idle motion.
mainVisitor.root.position.y = mainVisitor.baseY + Math.sin(time * 1.7) * 0.012;
secondVisitor.root.position.y = secondVisitor.baseY + Math.sin(time * 1.35 + 1.2) * 0.015;
secondVisitor.root.rotation.y = 2.62 + Math.sin(time * 0.7) * 0.025;
for (let i = animations.length - 1; i >= 0; i--) {
const animation = animations[i];
animation.elapsed += dt;
const t = Math.min(animation.elapsed / animation.duration, 1);
const eased = t * t * (3 - 2 * t);
animation.outgoing.position.lerpVectors(
animation.sourcePosition,
animation.handPosition,
eased
);
animation.outgoing.position.y += Math.sin(Math.PI * t) * 1.18;
animation.outgoing.rotation.y = -0.05 + Math.sin(t * Math.PI) * 0.45;
if (animation.incoming && animation.incomingTarget) {
animation.incoming.position.lerpVectors(
animation.incoming.position,
animation.incomingTarget,
0
);
// Store the initial world position once, then interpolate from it.
if (!animation.incomingStart) {
animation.incomingStart = animation.incoming.position.clone();
}
animation.incoming.position.lerpVectors(
animation.incomingStart,
animation.incomingTarget,
eased
);
animation.incoming.position.y += Math.sin(Math.PI * t) * 1.1;
animation.incoming.rotation.y = Math.sin(t * Math.PI) * -0.5;
}
if (t >= 1) {
completeExchange(animation);
animations.splice(i, 1);
}
}
renderer.render(scene, camera);
}
animate();
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
</script>
</body>
</html>
```