Prompt specification
Build or customize the Three.js 3D scene "Street florist wrapping corner" 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: Street florist wrapping corner
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/street-florist-wrapping-corner-x0499
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: street florist wrapping corner. Build a florist stall with buckets, wrapping paper, ribbon, and finished bouquets; animate selection, arrangement, and wrapping while every chosen stem remains traceable. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (street-florist-wrapping-corner-x0499):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stem & Leaf — Street Florist</title>
<style>
:root {
--ink: #173f35;
--ink-soft: #527267;
--paper: #fffaf0;
--paper-strong: #fffdf7;
--coral: #e96f65;
--gold: #e7b84d;
--line: rgba(23, 63, 53, 0.14);
--shadow: 0 18px 50px rgba(32, 50, 43, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9dfd8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button { font: inherit; }
#viewport,
#viewport canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#viewport canvas {
touch-action: none;
cursor: grab;
outline: none;
}
#viewport canvas.dragging { cursor: grabbing; }
.brand {
position: fixed;
z-index: 5;
top: 24px;
left: 26px;
display: flex;
align-items: center;
gap: 13px;
pointer-events: none;
user-select: none;
filter: drop-shadow(0 2px 10px rgba(255,255,255,.5));
}
.brand-mark {
width: 48px;
height: 48px;
display: grid;
place-items: center;
border-radius: 15px;
background: var(--ink);
color: var(--paper);
font-family: Georgia, serif;
font-size: 29px;
box-shadow: var(--shadow);
}
.brand h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 25px;
line-height: 1;
letter-spacing: -.03em;
font-weight: 700;
}
.brand p {
margin: 6px 0 0;
color: var(--ink-soft);
font-size: 10px;
font-weight: 800;
letter-spacing: .17em;
text-transform: uppercase;
}
#reset-view {
position: fixed;
z-index: 8;
top: 24px;
right: 342px;
width: 40px;
height: 40px;
border: 1px solid var(--line);
border-radius: 12px;
color: var(--ink);
background: rgba(255, 250, 240, .84);
backdrop-filter: blur(12px);
box-shadow: 0 8px 22px rgba(32, 50, 43, .1);
cursor: pointer;
transition: transform .18s ease, background .18s ease;
}
#reset-view:hover {
transform: translateY(-2px);
background: var(--paper-strong);
}
.panel {
position: fixed;
z-index: 6;
background: rgba(255, 250, 240, .9);
border: 1px solid rgba(255,255,255,.7);
box-shadow: var(--shadow);
backdrop-filter: blur(16px) saturate(1.1);
}
#ledger {
top: 22px;
right: 22px;
width: 300px;
padding: 18px;
border-radius: 20px;
max-height: calc(100vh - 44px);
overflow: auto;
scrollbar-width: thin;
}
.eyebrow {
margin: 0;
color: var(--ink-soft);
font-size: 9px;
font-weight: 900;
letter-spacing: .18em;
text-transform: uppercase;
}
.ledger-heading {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
}
.ledger-heading h2 {
margin: 4px 0 0;
font-family: Georgia, serif;
font-size: 22px;
letter-spacing: -.025em;
}
#stem-count {
min-width: 31px;
height: 27px;
display: grid;
place-items: center;
padding: 0 8px;
border-radius: 9px;
background: var(--ink);
color: var(--paper);
font-size: 12px;
font-weight: 900;
}
#ledger-list {
display: grid;
gap: 7px;
max-height: 265px;
overflow: auto;
padding-right: 2px;
}
.empty-ledger {
padding: 16px 13px;
border: 1px dashed rgba(23,63,53,.22);
border-radius: 13px;
color: var(--ink-soft);
font-size: 12px;
line-height: 1.55;
background: rgba(255,255,255,.3);
}
.stem-row {
display: grid;
grid-template-columns: 40px 10px 1fr;
align-items: center;
gap: 9px;
min-height: 43px;
padding: 7px 9px;
border-radius: 11px;
border: 1px solid transparent;
background: rgba(255,255,255,.48);
cursor: pointer;
transition: background .16s ease, border-color .16s ease, transform .16s ease;
}
.stem-row:hover {
transform: translateX(-2px);
background: var(--paper-strong);
border-color: var(--line);
}
.stem-id {
font-size: 10px;
font-weight: 900;
letter-spacing: .08em;
color: var(--ink);
}
.stem-dot {
width: 10px;
height: 10px;
border-radius: 3px;
box-shadow: 0 0 0 3px rgba(255,255,255,.65);
}
.stem-name {
font-size: 11px;
font-weight: 750;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.divider {
height: 1px;
background: var(--line);
margin: 16px 0 13px;
}
#quick-pick {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.pick-button {
display: flex;
align-items: center;
gap: 7px;
min-height: 35px;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 10px;
color: var(--ink);
background: rgba(255,255,255,.52);
font-size: 10px;
font-weight: 800;
cursor: pointer;
transition: transform .16s ease, background .16s ease;
}
.pick-button:hover:not(:disabled) {
transform: translateY(-1px);
background: var(--paper-strong);
}
.pick-button:disabled {
cursor: default;
opacity: .48;
}
.pick-swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 3px;
}
.ledger-note {
margin: 12px 0 0;
color: var(--ink-soft);
font-size: 10px;
line-height: 1.45;
}
#scene-hint {
position: fixed;
z-index: 5;
left: 26px;
bottom: 27px;
max-width: 270px;
color: rgba(23,63,53,.77);
font-size: 10px;
font-weight: 750;
line-height: 1.5;
pointer-events: none;
text-shadow: 0 1px 5px rgba(255,255,255,.8);
}
#scene-hint strong {
display: block;
margin-bottom: 2px;
color: var(--ink);
font-size: 11px;
}
#dock {
position: fixed;
z-index: 7;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
display: flex;
align-items: stretch;
gap: 8px;
padding: 8px;
border-radius: 20px;
background: rgba(255, 250, 240, .93);
border: 1px solid rgba(255,255,255,.75);
box-shadow: 0 20px 55px rgba(29,49,41,.2);
backdrop-filter: blur(18px) saturate(1.1);
}
.stage {
min-width: 132px;
display: grid;
grid-template-columns: 26px 1fr;
align-items: center;
gap: 7px;
padding: 10px 14px;
border: 0;
border-radius: 13px;
color: var(--ink-soft);
background: transparent;
cursor: pointer;
text-align: left;
transition: color .2s ease, background .2s ease, transform .2s ease;
}
.stage:hover { background: rgba(23,63,53,.05); }
.stage.active {
color: var(--paper);
background: var(--ink);
transform: translateY(-1px);
}
.stage-number {
width: 25px;
height: 25px;
display: grid;
place-items: center;
border: 1px solid currentColor;
border-radius: 8px;
font-size: 10px;
font-weight: 900;
opacity: .8;
}
.stage-copy strong {
display: block;
font-family: Georgia, serif;
font-size: 14px;
line-height: 1.1;
}
.stage-copy small {
display: block;
margin-top: 3px;
font-size: 8px;
font-weight: 800;
letter-spacing: .09em;
text-transform: uppercase;
opacity: .62;
}
#primary-action {
min-width: 154px;
padding: 0 19px;
border: 0;
border-radius: 13px;
color: #fff;
background: var(--coral);
box-shadow: 0 8px 18px rgba(233,111,101,.25);
font-size: 11px;
font-weight: 900;
cursor: pointer;
transition: transform .18s ease, background .18s ease;
}
#primary-action:hover {
transform: translateY(-2px);
background: #df5e57;
}
#tooltip {
position: fixed;
z-index: 10;
display: none;
pointer-events: none;
padding: 8px 10px;
border-radius: 9px;
color: var(--paper);
background: rgba(23,63,53,.93);
box-shadow: 0 8px 20px rgba(23,63,53,.2);
font-size: 10px;
font-weight: 800;
white-space: nowrap;
}
#toast {
position: fixed;
z-index: 12;
top: 88px;
left: 50%;
transform: translate(-50%, -12px);
max-width: min(430px, calc(100vw - 32px));
padding: 11px 16px;
border-radius: 12px;
color: var(--paper);
background: rgba(23,63,53,.94);
box-shadow: 0 12px 32px rgba(23,63,53,.2);
font-size: 11px;
font-weight: 750;
opacity: 0;
pointer-events: none;
transition: opacity .2s ease, transform .2s ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #f3efe3;
transition: opacity .5s ease;
}
#loading.hide {
opacity: 0;
pointer-events: none;
}
.loading-card {
text-align: center;
color: var(--ink);
}
.loading-flower {
width: 36px;
height: 36px;
margin: 0 auto 15px;
border: 7px dotted var(--coral);
border-radius: 50%;
animation: turn 2s linear infinite;
}
.loading-card strong {
display: block;
font-family: Georgia, serif;
font-size: 22px;
}
.loading-card small {
display: block;
margin-top: 7px;
color: var(--ink-soft);
font-size: 10px;
font-weight: 800;
letter-spacing: .12em;
text-transform: uppercase;
}
@keyframes turn { to { transform: rotate(360deg); } }
@media (max-width: 900px) {
#ledger { width: 245px; }
#reset-view { right: 282px; }
.stage { min-width: 105px; padding: 9px 10px; }
.stage-copy small { display: none; }
#primary-action { min-width: 125px; }
#scene-hint { display: none; }
}
@media (max-width: 650px) {
.brand { top: 14px; left: 14px; }
.brand h1 { font-size: 20px; }
.brand p { display: none; }
.brand-mark { width: 42px; height: 42px; }
#ledger {
top: 66px;
right: 12px;
width: 205px;
max-height: 42vh;
padding: 13px;
border-radius: 16px;
}
.ledger-heading h2 { font-size: 18px; }
#ledger-list { max-height: 130px; }
#quick-pick { grid-template-columns: 1fr; }
.ledger-note { display: none; }
#reset-view {
top: 14px;
right: 14px;
width: 38px;
height: 38px;
}
#dock {
width: calc(100% - 20px);
bottom: 10px;
gap: 4px;
padding: 6px;
border-radius: 16px;
}
.stage {
min-width: 0;
flex: 1;
display: block;
padding: 9px 7px;
text-align: center;
}
.stage-number { display: none; }
.stage-copy strong { font-size: 12px; }
#primary-action {
min-width: 100px;
padding: 0 11px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<header class="brand">
<div class="brand-mark">✿</div>
<div>
<h1>Stem & Leaf</h1>
<p>Street florist · wrapping corner</p>
</div>
</header>
<button id="reset-view" title="Reset camera" aria-label="Reset camera">↺</button>
<aside id="ledger" class="panel">
<div class="ledger-heading">
<div>
<p class="eyebrow">Live traceability</p>
<h2>Stem ledger</h2>
</div>
<div id="stem-count">0</div>
</div>
<div id="ledger-list">
<div class="empty-ledger">
Pick a flower at the stall. Each selected stem keeps its own ID, color, and position throughout the bouquet.
</div>
</div>
<div class="divider"></div>
<p class="eyebrow">Quick pick</p>
<div id="quick-pick" style="margin-top:9px"></div>
<p class="ledger-note">
IDs remain above the flower heads after wrapping. Hover a ledger row to highlight its stem.
</p>
</aside>
<div id="scene-hint">
<strong>Make a bouquet</strong>
Click a flower head to select it. Drag to orbit and scroll to zoom.
</div>
<nav id="dock" class="panel" aria-label="Bouquet workflow">
<button class="stage active" data-mode="select">
<span class="stage-number">1</span>
<span class="stage-copy">
<strong>Select</strong>
<small>Pick from buckets</small>
</span>
</button>
<button class="stage" data-mode="arrange">
<span class="stage-number">2</span>
<span class="stage-copy">
<strong>Arrange</strong>
<small>Shape the stems</small>
</span>
</button>
<button class="stage" data-mode="wrap">
<span class="stage-number">3</span>
<span class="stage-copy">
<strong>Wrap</strong>
<small>Fold & tie</small>
</span>
</button>
<button id="primary-action">Add a stem</button>
</nav>
<div id="tooltip"></div>
<div id="toast" role="status" aria-live="polite"></div>
<div id="loading">
<div class="loading-card">
<div class="loading-flower"></div>
<strong>Opening the corner</strong>
<small>Watering the voxel stems</small>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const tooltip = document.getElementById("tooltip");
const toastElement = document.getElementById("toast");
const ledgerList = document.getElementById("ledger-list");
const stemCount = document.getElementById("stem-count");
const quickPick = document.getElementById("quick-pick");
const primaryAction = document.getElementById("primary-action");
const stageButtons = [...document.querySelectorAll(".stage")];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9dfd8);
scene.fog = new THREE.Fog(0xd9dfd8, 24, 48);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
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.12;
renderer.domElement.setAttribute("aria-label", "Interactive voxel florist scene");
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff5df, 0x6a8176, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc4, 3.4);
sun.position.set(-8, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xb8d9e8, 1.0);
rim.position.set(12, 8, -12);
scene.add(rim);
const materials = new Map();
function material(color, options = {}) {
const key = `${color}_${JSON.stringify(options)}`;
if (!materials.has(key)) {
materials.set(key, new THREE.MeshStandardMaterial({
color,
roughness: 0.83,
metalness: 0,
...options
}));
}
return materials.get(key);
}
function box(parent, width, height, depth, x, y, z, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function group(parent, x = 0, y = 0, z = 0) {
const result = new THREE.Group();
result.position.set(x, y, z);
parent?.add(result);
return result;
}
function makeTextTexture(title, subtitle = "", background = "#173f35", foreground = "#fffaf0") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = `700 ${subtitle ? 78 : 92}px Georgia`;
ctx.fillText(title, 512, subtitle ? 103 : 132);
if (subtitle) {
ctx.globalAlpha = 0.72;
ctx.font = "700 28px system-ui";
ctx.fillText(subtitle, 512, 186);
ctx.globalAlpha = 1;
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function textPanel(parent, title, subtitle, width, height, x, y, z, bg, fg) {
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: makeTextTexture(title, subtitle, bg, fg),
transparent: false
})
);
mesh.position.set(x, y, z);
parent.add(mesh);
return mesh;
}
function cssColor(hex) {
return `#${new THREE.Color(hex).getHexString()}`;
}
let seed = 437;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const species = [
{ key: "rose", name: "Market rose", bucket: "ROSES", color: 0xe76877, center: 0xf3b05d },
{ key: "tulip", name: "Golden tulip", bucket: "TULIPS", color: 0xe9b743, center: 0xf4d46b },
{ key: "daisy", name: "White daisy", bucket: "DAISIES", color: 0xf8f3dc, center: 0xe8b84f },
{ key: "lilac", name: "Purple lilac", bucket: "LILAC", color: 0x9b79ba, center: 0xd4a9dd }
];
const stems = [];
const chosenStems = [];
const stemHeads = [];
let nextStemNumber = 1;
let currentMode = "select";
let toastTimer = 0;
const workCenter = new THREE.Vector3(2.25, 1.45, 0.48);
function buildEnvironment() {
box(scene, 29, 0.34, 23, 0, -0.25, 0, 0xd8d0bd);
const tileColors = [0xded6c3, 0xe4ddcb, 0xd9d0bc, 0xe1dac8];
for (let x = 0; x < 6; x++) {
for (let z = 0; z < 5; z++) {
const tile = box(
scene,
1.94, 0.025, 1.94,
-5.1 + x * 2,
-0.065,
-4.2 + z * 2,
tileColors[(x + z * 2) % tileColors.length],
{ castShadow: false }
);
tile.receiveShadow = true;
}
}
box(scene, 6.1, 0.18, 24, 10.1, -0.27, 0, 0x566160);
box(scene, 25, 0.18, 6.2, -0.3, -0.27, -10.2, 0x566160);
box(scene, 0.24, 0.25, 15.1, 6.95, 0.02, -0.2, 0xf0eadb);
box(scene, 16.2, 0.25, 0.24, -0.8, 0.02, -6.95, 0xf0eadb);
box(scene, 5.9, 0.25, 0.24, 10.1, 0.02, -6.95, 0xf0eadb);
for (let z = -4.5; z < 7; z += 2.2) {
box(scene, 0.12, 0.025, 1.05, 10.1, -0.165, z, 0xe8d9a5, { castShadow: false });
}
for (let x = -8; x < 7; x += 2.35) {
box(scene, 1.05, 0.025, 0.12, x, -0.165, -10.2, 0xe8d9a5, { castShadow: false });
}
for (let x = 8.05; x < 12.5; x += 0.72) {
box(scene, 0.38, 0.026, 3.1, x, -0.16, 4.2, 0xf5efe2, { castShadow: false });
}
box(scene, 13.2, 7.2, 2.6, -4.1, 3.55, -6.1, 0xc98270);
box(scene, 13.45, 0.28, 2.78, -4.1, 7.18, -6.1, 0xefd8bd);
box(scene, 8.7, 0.22, 0.25, -4.1, 4.8, -4.75, 0xe4b99a);
for (const x of [-8.4, -0.4]) {
box(scene, 2.0, 2.1, 0.12, x, 4.2, -4.73, 0x325c53);
box(scene, 1.66, 1.75, 0.08, x, 4.2, -4.64, 0xa9c9c8, {
emissive: 0x789999,
emissiveIntensity: 0.12
});
box(scene, 0.08, 1.78, 0.11, x, 4.2, -4.56, 0x325c53);
box(scene, 1.7, 0.08, 0.11, x, 4.2, -4.55, 0x325c53);
}
textPanel(
scene,
"STEM & LEAF",
"FRESH BLOOMS · WRAPPED BY HAND",
6.7, 1.18,
-4.15, 5.86, -4.67,
"#173f35",
"#fffaf0"
);
const lamp = group(scene, 6.25, 0, -3.6);
box(lamp, 0.18, 4.8, 0.18, 0, 2.4, 0, 0x254d43);
box(lamp, 0.72, 0.12, 0.12, 0, 4.72, 0, 0x254d43);
box(lamp, 0.58, 0.45, 0.58, 0.42, 4.45, 0, 0xf6d88b, {
emissive: 0xe8b65e,
emissiveIntensity: 0.22
});
box(lamp, 0.72, 0.12, 0.72, 0.42, 4.74, 0, 0x254d43);
const tree = group(scene, 6.0, 0, 4.65);
box(tree, 1.55, 0.45, 1.55, 0, 0.2, 0, 0x8e6c53);
box(tree, 0.42, 2.3, 0.42, 0, 1.35, 0, 0x76543f);
box(tree, 2.25, 1.45, 1.8, 0, 3.0, 0, 0x688c65);
box(tree, 1.65, 1.1, 2.15, -0.4, 3.65, 0.15, 0x789a6e);
box(tree, 1.6, 1.25, 1.45, 0.7, 3.35, -0.25, 0x557d5c);
box(tree, 1.25, 0.9, 1.25, 0.15, 4.3, 0.2, 0x8ba879);
const bench = group(scene, -1.0, 0, 4.55);
box(bench, 2.8, 0.17, 0.72, 0, 0.72, 0, 0x9b654b);
box(bench, 2.8, 0.72, 0.15, 0, 1.18, -0.29, 0x9b654b);
box(bench, 0.17, 0.72, 0.58, -1.02, 0.34, 0, 0x35564d);
box(bench, 0.17, 0.72, 0.58, 1.02, 0.34, 0, 0x35564d);
for (let i = 0; i < 3; i++) {
const crate = group(scene, -7.9, i * 0.48, 2.7);
box(crate, 1.25, 0.16, 1.05, 0, 0.08, 0, 0xa56c45);
box(crate, 1.25, 0.38, 0.12, 0, 0.3, -0.46, 0xa56c45);
box(crate, 1.25, 0.38, 0.12, 0, 0.3, 0.46, 0xa56c45);
box(crate, 0.12, 0.38, 1.05, -0.56, 0.3, 0, 0xa56c45);
box(crate, 0.12, 0.38, 1.05, 0.56, 0.3, 0, 0xa56c45);
}
}
function buildStall() {
const stall = group(scene);
box(stall, 7.9, 1.25, 1.85, -4.25, 0.625, -3.37, 0x315c4e);
box(stall, 8.15, 0.19, 2.05, -4.25, 1.35, -3.37, 0xe8d9bd);
for (let x = -7.8; x < -0.4; x += 0.55) {
box(stall, 0.08, 0.92, 0.06, x, 0.6, -2.42, 0x244b40);
}
box(stall, 7.4, 0.13, 0.56, -4.25, 2.12, -4.25, 0xb88455);
for (const x of [-7.9, -0.55]) {
box(stall, 0.16, 4.55, 0.16, x, 2.27, -1.72, 0x244b40);
}
box(stall, 7.8, 0.18, 0.2, -4.25, 4.58, -1.75, 0x244b40);
const stripeColors = [0xf6e8cc, 0xe76f64];
for (let i = 0; i < 10; i++) {
const stripe = box(
stall,
0.79, 0.13, 3.6,
-7.78 + i * 0.785,
4.52,
-3.1,
stripeColors[i % 2]
);
stripe.rotation.x = -0.06;
}
box(stall, 7.6, 0.15, 0.15, -4.25, 4.23, -1.28, 0xe8d2ac);
const shelf = group(scene, -4.25, 0, -4.36);
box(shelf, 6.9, 0.12, 0.65, 0, 2.62, 0, 0x8c6045);
box(shelf, 6.9, 0.12, 0.65, 0, 3.5, 0, 0x8c6045);
for (const x of [-6.8, -5.9, -3.0, -2.1, -1.2]) {
box(shelf, 0.32, 0.44, 0.32, x, 2.9, 0, 0xd8b56e);
box(shelf, 0.22, 0.32, 0.22, x, 3.75, 0, 0xb97567);
}
const chalkboard = group(scene, 0.42, 0, -2.37);
box(chalkboard, 1.5, 1.18, 0.12, 0, 1.2, 0, 0x6d4e38);
box(chalkboard, 1.28, 0.94, 0.04, 0, 1.2, 0.08, 0x264a40);
textPanel(
chalkboard,
"TODAY",
"BOUQUETS 8–18",
1.08, 0.58,
0, 1.27, 0.112,
"#264a40",
"#fff7dc"
);
}
function buildWorkTable() {
const table = group(scene);
box(table, 4.65, 0.18, 2.75, 2.3, 1.34, 0.48, 0xb88458);
box(table, 4.42, 0.07, 2.52, 2.3, 1.465, 0.48, 0x6b907b);
for (const x of [0.38, 4.22]) {
for (const z of [-0.58, 1.54]) {
box(table, 0.18, 1.28, 0.18, x, 0.64, z, 0x31564b);
}
}
box(table, 4.22, 0.13, 2.3, 2.3, 0.42, 0.48, 0x31564b);
for (let i = 0; i < 5; i++) {
const sheet = box(
table,
1.32, 0.026, 1.06,
3.62,
1.515 + i * 0.025,
-0.18,
i % 2 ? 0xd8b37d : 0xe5c692
);
sheet.rotation.y = (i - 2) * 0.025;
}
box(table, 0.55, 0.42, 0.55, 4.0, 1.7, 1.27, 0xe36f67);
box(table, 0.7, 0.09, 0.7, 4.0, 1.94, 1.27, 0x9d3f42);
box(table, 0.18, 0.04, 1.12, 4.05, 1.985, 1.27, 0xf0a39a);
box(table, 1.05, 0.04, 0.15, 4.05, 2.02, 1.27, 0xf0a39a);
box(table, 0.08, 0.05, 0.78, 1.08, 1.5, 1.23, 0x394f4a);
box(table, 0.08, 0.05, 0.78, 0.86, 1.5, 1.23, 0x394f4a);
box(table, 0.08, 0.05, 0.18, 0.97, 1.5, 1.0, 0x9f6250);
box(table, 0.08, 0.05, 0.18, 0.97, 1.5, 1.48, 0x9f6250);
const bouquetStand = group(scene, 5.05, 0, -2.4);
box(bouquetStand, 1.55, 1.28, 1.25, 0, 0.64, 0, 0x31564b);
box(bouquetStand, 1.72, 0.12, 1.4, 0, 1.34, 0, 0xb88458);
}
function createBucket(spec, x, z) {
const bucket = group(scene, x, 1.46, z);
box(bucket, 0.92, 0.12, 0.92, 0, 0.07, 0, 0x8b9b8c);
box(bucket, 0.92, 0.68, 0.1, 0, 0.36, -0.42, 0xaab7a8);
box(bucket, 0.92, 0.68, 0.1, 0, 0.36, 0.42, 0xaab7a8);
box(bucket, 0.1, 0.68, 0.84, -0.42, 0.36, 0, 0xaab7a8);
box(bucket, 0.1, 0.68, 0.84, 0.42, 0.36, 0, 0xaab7a8);
box(bucket, 0.77, 0.035, 0.77, 0, 0.12, 0, 0x455d52);
box(bucket, 1.01, 0.11, 0.12, 0, 0.72, -0.43, 0x819487);
box(bucket, 1.01, 0.11, 0.12, 0, 0.72, 0.43, 0x819487);
box(bucket, 0.12, 0.11, 0.86, -0.43, 0.72, 0, 0x819487);
box(bucket, 0.12, 0.11, 0.86, 0.43, 0.72, 0, 0x819487);
textPanel(
bucket,
spec.bucket,
"",
0.68, 0.25,
0, 0.4, 0.478,
"#f4ead4",
"#31564b"
);
return bucket;
}
function makeFlowerHead(spec, height) {
const head = group();
head.position.y = height;
if (spec.key === "rose") {
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const petal = box(
head,
0.31, 0.19, 0.22,
Math.cos(angle) * 0.16,
Math.sin(angle) * 0.06,
Math.sin(angle) * 0.16,
spec.color
);
petal.rotation.y = -angle;
petal.rotation.z = Math.sin(angle) * 0.16;
}
box(head, 0.25, 0.18, 0.25, 0, 0.045, 0, spec.center);
}
if (spec.key === "tulip") {
box(head, 0.25, 0.43, 0.25, -0.13, 0.05, 0, spec.color);
box(head, 0.25, 0.5, 0.25, 0.13, 0.03, 0, spec.color);
box(head, 0.24, 0.45, 0.25, 0, 0.12, -0.12, 0xf0c658);
box(head, 0.22, 0.14, 0.22, 0, 0.19, 0.11, spec.center);
}
if (spec.key === "daisy") {
for (let i = 0; i < 9; i++) {
const angle = (i / 9) * Math.PI * 2;
const petal = box(
head,
0.29, 0.075, 0.15,
Math.cos(angle) * 0.2,
0,
Math.sin(angle) * 0.2,
spec.color
);
petal.rotation.y = -angle;
}
box(head, 0.19, 0.12, 0.19, 0, 0.035, 0, spec.center);
}
if (spec.key === "lilac") {
for (let i = 0; i < 11; i++) {
const angle = (i / 11) * Math.PI * 2;
const y = (i % 3) * 0.12;
const radius = 0.15 + (i % 2) * 0.035;
box(
head,
0.17, 0.17, 0.17,
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius,
i % 3 === 0 ? 0xb594ca : spec.color
);
}
box(head, 0.18, 0.2, 0.18, 0, 0.2, 0, 0xd4b2dd);
}
return head;
}
function createStem(spec, bucketX, bucketZ, index) {
const stemGroup = group();
const height = 1.72 + random() * 0.27;
box(stemGroup, 0.065, height, 0.065, 0, height / 2, 0, 0x3d7750);
const leafA = box(stemGroup, 0.33, 0.07, 0.16, 0.19, height * 0.43, 0, 0x5d9563);
leafA.rotation.z = -0.52;
const leafB = box(stemGroup, 0.31, 0.07, 0.15, -0.17, height * 0.62, 0, 0x4f8858);
leafB.rotation.z = 0.58;
const head = makeFlowerHead(spec, height);
stemGroup.add(head);
const x = bucketX + (index % 2 === 0 ? -0.17 : 0.17) + (random() - 0.5) * 0.08;
const z = bucketZ + (index < 2 ? -0.14 : 0.14) + (random() - 0.5) * 0.08;
stemGroup.position.set(x, 2.17, z);
stemGroup.rotation.z = (random() - 0.5) * 0.06;
stemGroup.rotation.x = (random() - 0.5) * 0.05;
const traceGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.04, 0),
new THREE.Vector3(0, height, 0)
]);
const traceLine = new THREE.Line(
traceGeometry,
new THREE.LineBasicMaterial({
color: spec.color,
transparent: true,
opacity: 0.86,
depthWrite: false
})
);
traceLine.visible = false;
stemGroup.add(traceLine);
const beacon = group(stemGroup, 0, 0.045, 0);
for (let i = 0; i < 4; i++) {
const angle = i * Math.PI / 2;
box(
beacon,
0.12, 0.06, 0.12,
Math.cos(angle) * 0.16,
0,
Math.sin(angle) * 0.16,
spec.color,
{ emissive: spec.color, emissiveIntensity: 0.12 }
);
}
beacon.visible = false;
const stem = {
group: stemGroup,
head,
spec,
height,
index,
chosen: false,
id: null,
traceLine,
beacon,
label: null,
phase: random() * Math.PI * 2
};
head.traverse(child => {
child.userData.stemRef = stem;
});
stems.push(stem);
stemHeads.push(head);
scene.add(stemGroup);
return stem;
}
function buildBucketsAndStems() {
const positions = [-6.75, -5.35, -3.95, -2.55];
species.forEach((spec, speciesIndex) => {
createBucket(spec, positions[speciesIndex], -3.33);
for (let i = 0; i < 4; i++) {
createStem(spec, positions[speciesIndex], -3.33, i);
}
});
}
function decorativeBloom(parent, spec, x, y, z, scale = 1) {
const bloom = group(parent, x, y, z);
const head = makeFlowerHead(spec, 0);
head.scale.setScalar(scale);
bloom.add(head);
return bloom;
}
function createFinishedBouquet(parent, x, y, z, spec, scale = 1) {
const bouquet = group(parent, x, y, z);
bouquet.scale.setScalar(scale);
box(bouquet, 1.05, 0.42, 1.05, 0, 0.2, 0, 0xd2ad77);
box(bouquet, 0.84, 0.43, 0.84, 0, 0.6, 0, 0xe1bd85);
box(bouquet, 0.61, 0.42, 0.61, 0, 1.0, 0, 0xecd09a);
box(bouquet, 1.11, 0.14, 1.1, 0, 0.4, 0, 0xe46f67);
box(bouquet, 0.9, 0.13, 0.9, 0, 0.8, 0, 0xe46f67);
box(bouquet, 0.16, 0.75, 0.16, 0, 0.85, 0.57, 0x9f3f42);
decorativeBloom(bouquet, species[0], -0.2, 1.48, -0.05, 0.9);
decorativeBloom(bouquet, species[2], 0.18, 1.42, 0.08, 0.8);
decorativeBloom(bouquet, species[1], 0, 1.65, -0.16, 0.72);
return bouquet;
}
function buildFinishedBouquets() {
const shelf = group(scene, -4.25, 0, -4.36);
createFinishedBouquet(shelf, -0.4, 2.68, 0.03, species[0], 0.7);
createFinishedBouquet(shelf, 0.7, 2.68, 0.04, species[2], 0.64);
const display = group(scene, 5.05, 0, -2.4);
createFinishedBouquet(display, -0.34, 1.4, 0.05, species[1], 0.85);
createFinishedBouquet(display, 0.38, 1.4, 0.08, species[3], 0.78);
}
const tweens = new Set();
function cancelTween(tag) {
for (const tween of tweens) {
if (tween.tag === tag) tweens.delete(tween);
}
}
function startTween(duration, onUpdate, onComplete = null, tag = null, delay = 0) {
if (tag) cancelTween(tag);
const tween = {
start: performance.now(),
duration,
delay,
onUpdate,
onComplete,
tag
};
tweens.add(tween);
return tween;
}
function updateTweens(now) {
for (const tween of [...tweens]) {
const elapsed = now - tween.start - tween.delay;
if (elapsed < 0) continue;
const progress = Math.min(elapsed / tween.duration, 1);
const eased = 1 - Math.pow(1 - progress, 3);
tween.onUpdate(eased, progress);
if (progress >= 1) {
tweens.delete(tween);
if (tween.onComplete) tween.onComplete();
}
}
}
function animateStemTo(stem, target, targetRotation, duration = 850, arc = 1.05, delay = 0) {
const from = stem.group.position.clone();
const fromRotation = stem.group.rotation.clone();
startTween(
duration,
eased => {
stem.group.position.x = THREE.MathUtils.lerp(from.x, target.x, eased);
stem.group.position.y = THREE.MathUtils.lerp(from.y, target.y, eased)
+ Math.sin(eased * Math.PI) * arc;
stem.group.position.z = THREE.MathUtils.lerp(from.z, target.z, eased);
stem.group.rotation.x = THREE.MathUtils.lerp(
fromRotation.x, targetRotation.x, eased
);
stem.group.rotation.y = THREE.MathUtils.lerp(
fromRotation.y, targetRotation.y, eased
);
stem.group.rotation.z = THREE.MathUtils.lerp(
fromRotation.z, targetRotation.z, eased
);
},
() => {
stem.group.position.copy(target);
stem.group.rotation.copy(targetRotation);
},
`stem-${stem.index}`,
delay
);
}
function makeIdSprite(id, color) {
const canvas = document.createElement("canvas");
canvas.width = 192;
canvas.height = 96;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(23, 63, 53, .94)";
ctx.fillRect(4, 4, 184, 88);
ctx.strokeStyle = cssColor(color);
ctx.lineWidth = 8;
ctx.strokeRect(8, 8, 176, 80);
ctx.fillStyle = "#fffaf0";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 42px system-ui";
ctx.fillText(id, 96, 50);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.position.y = 2.58;
sprite.scale.set(0.48, 0.24, 1);
sprite.renderOrder = 100;
return sprite;
}
function chooseStem(stem) {
if (stem.chosen) {
focusStem(stem);
return;
}
if (currentMode !== "select") {
setMode("select");
}
stem.chosen = true;
stem.id = `S-${String(nextStemNumber++).padStart(2, "0")}`;
stem.traceLine.visible = true;
stem.beacon.visible = true;
stem.label = makeIdSprite(stem.id, stem.spec.color);
stem.group.add(stem.label);
chosenStems.push(stem);
const index = chosenStems.length - 1;
const target = new THREE.Vector3(
1.0 + (index % 4) * 0.58,
1.48,
0.72 + (Math.floor(index / 4) % 2) * 0.38
);
animateStemTo(
stem,
target,
new THREE.Euler(0, 0, (random() - 0.5) * 0.08),
950,
1.35
);
renderLedger();
showToast(`${stem.id} · ${stem.spec.name} selected and carried to the work table.`);
}
function focusStem(stem) {
stem.beacon.scale.setScalar(1.6);
stem.label.scale.set(0.62, 0.31, 1);
stem.label.material.opacity = 1;
setTimeout(() => {
if (!stem.beacon.userData.hovered) stem.beacon.scale.setScalar(1);
if (!stem.label.userData.hovered) stem.label.scale.set(0.48, 0.24, 1);
}, 850);
}
function arrangementTargets() {
const count = chosenStems.length;
return chosenStems.map((stem, index) => {
const fraction = count === 1 ? 0.5 : index / (count - 1);
const angle = (fraction - 0.5) * 1.28;
const target = new THREE.Vector3(
workCenter.x + Math.sin(angle) * 0.95,
workCenter.y,
workCenter.z + (index % 2 === 0 ? -0.1 : 0.13)
);
const rotation = new THREE.Euler(
(index % 2 === 0 ? -1 : 1) * 0.025,
0,
-Math.sin(angle) * 0.1
);
return { stem, target, rotation };
});
}
function arrangeSelected(delay = 0) {
if (!chosenStems.length) {
showToast("Select at least one stem before arranging.");
return;
}
arrangementTargets().forEach(({ stem, target, rotation }) => {
animateStemTo(stem, target, rotation, 900, 0.42, delay);
});
}
const paperGroup = new THREE.Group();
const ribbonGroup = new THREE.Group();
const paperHinges = [];
scene.add(paperGroup, ribbonGroup);
function buildWrappingAssembly() {
const kraft = material(0xd9b47d);
const kraftLight = material(0xe7c895);
const ribbonMaterial = material(0xd95859);
const ribbonLight = material(0xf08a79);
function hinge(position, axis, open, final) {
const h = group(paperGroup, position.x, position.y, position.z);
h.userData.axis = axis;
h.userData.open = open;
h.userData.final = final;
h.rotation[axis] = open;
paperHinges.push(h);
return h;
}
const back = hinge(
new THREE.Vector3(workCenter.x, 1.47, workCenter.z - 0.69),
"x", -1.23, 0
);
box(back, 1.72, 1.38, 0.045, 0, 0.69, 0, kraft);
box(back, 1.42, 0.1, 0.055, 0, 1.34, 0.01, kraftLight);
const front = hinge(
new THREE.Vector3(workCenter.x, 1.47, workCenter.z + 0.69),
"x", 1.23, 0
);
box(front, 1.72, 1.38, 0.045, 0, 0.69, 0, kraftLight);
box(front, 1.42, 0.1, 0.055, 0, 1.34, 0.01, kraft);
const left = hinge(
new THREE.Vector3(workCenter.x - 0.76, 1.47, workCenter.z),
"y", 1.23, -0.03
);
box(left, 1.45, 1.38, 0.045, 0.68, 0.69, 0, kraft);
const right = hinge(
new THREE.Vector3(workCenter.x + 0.76, 1.47, workCenter.z),
"y", -1.23, 0.03
);
box(right, 1.45, 1.38, 0.045, -0.68, 0.69, 0, kraftLight);
paperGroup.visible = false;
ribbonGroup.position.set(workCenter.x, 1.47, workCenter.z);
box(ribbonGroup, 1.54, 0.13, 0.07, 0, 0.72, 0.73, ribbonMaterial);
box(ribbonGroup, 0.14, 1.35, 0.08, 0, 0.68, 0.77, ribbonMaterial);
box(ribbonGroup, 0.07, 0.13, 1.5, -0.77, 0.72, 0, ribbonMaterial);
box(ribbonGroup, 0.07, 0.13, 1.5, 0.77, 0.72, 0, ribbonMaterial);
box(ribbonGroup, 0.27, 0.25, 0.24, 0, 0.72, 0.81, ribbonLight);
box(ribbonGroup, 0.13, 0.45, 0.06, -0.11, 0.31, 0.8, ribbonMaterial);
box(ribbonGroup, 0.13, 0.5, 0.06, 0.12, 0.28, 0.8, ribbonMaterial);
ribbonGroup.visible = false;
}
let wrapTimeout = 0;
function startWrapping() {
if (!chosenStems.length) {
showToast("Choose some stems before wrapping.");
return;
}
clearTimeout(wrapTimeout);
setMode("wrap");
paperGroup.visible = false;
ribbonGroup.visible = false;
arrangeSelected(0);
wrapTimeout = setTimeout(() => {
paperGroup.visible = true;
paperHinges.forEach((hinge, index) => {
const axis = hinge.userData.axis;
hinge.rotation[axis] = hinge.userData.open;
startTween(
920,
eased => {
hinge.rotation[axis] = THREE.MathUtils.lerp(
hinge.userData.open,
hinge.userData.final,
eased
);
},
null,
`paper-${index}`,
index * 85
);
});
ribbonGroup.visible = true;
ribbonGroup.scale.setScalar(0.001);
startTween(
430,
eased => {
const scale = 0.001 + eased * 0.999;
ribbonGroup.scale.set(scale, scale, scale);
},
() => {
showToast(`${chosenStems.length} stem${chosenStems.length === 1 ? "" : "s"} wrapped. Every ID is still traceable.`);
},
"ribbon",
1250
);
}, 520);
}
function setMode(mode) {
currentMode = mode;
stageButtons.forEach(button => {
button.classList.toggle("active", button.dataset.mode === mode);
});
if (mode === "select") {
paperGroup.visible = false;
ribbonGroup.visible = false;
primaryAction.textContent = "Add a stem";
} else if (mode === "arrange") {
paperGroup.visible = false;
ribbonGroup.visible = false;
primaryAction.textContent = "Arrange stems";
} else {
primaryAction.textContent = "Wrap bouquet";
}
}
function renderLedger() {
stemCount.textContent = chosenStems.length;
if (!chosenStems.length) {
ledgerList.innerHTML = `
<div class="empty-ledger">
Pick a flower at the stall. Each selected stem keeps its own ID,
color, and position throughout the bouquet.
</div>
`;
} else {
ledgerList.innerHTML = chosenStems.map(stem => `
<div class="stem-row" data-stem-index="${stem.index}" tabindex="0">
<span class="stem-id">${stem.id}</span>
<span class="stem-dot" style="background:${cssColor(stem.spec.color)}"></span>
<span class="stem-name">${stem.spec.name}</span>
</div>
`).join("");
ledgerList.querySelectorAll(".stem-row").forEach(row => {
const stem = stems[Number(row.dataset.stemIndex)];
const enter = () => {
stem.beacon.userData.hovered = true;
stem.label.userData.hovered = true;
stem.beacon.scale.setScalar(1.6);
stem.label.scale.set(0.62, 0.31, 1);
stem.traceLine.material.opacity = 1;
};
const leave = () => {
stem.beacon.userData.hovered = false;
stem.label.userData.hovered = false;
stem.beacon.scale.setScalar(1);
stem.label.scale.set(0.48, 0.24, 1);
stem.traceLine.material.opacity = 0.86;
};
row.addEventListener("mouseenter", enter);
row.addEventListener("mouseleave", leave);
row.addEventListener("focus", enter);
row.addEventListener("blur", leave);
row.addEventListener("click", () => focusStem(stem));
row.addEventListener("keydown", event => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
focusStem(stem);
}
});
});
}
renderQuickPick();
}
function renderQuickPick() {
quickPick.innerHTML = species.map(spec => {
const available = stems.some(stem => stem.spec.key === spec.key && !stem.chosen);
return `
<button class="pick-button" data-species="${spec.key}" ${available ? "" : "disabled"}>
<span class="pick-swatch" style="background:${cssColor(spec.color)}"></span>
<span>${available ? spec.name.replace("Market ", "").replace("Golden ", "").replace("White ", "").replace("Purple ", "") : `${spec.name} ✓`}</span>
</button>
`;
}).join("");
quickPick.querySelectorAll(".pick-button").forEach(button => {
button.addEventListener("click", () => {
const spec = species.find(item => item.key === button.dataset.species);
const stem = stems.find(item => item.spec.key === spec.key && !item.chosen);
if (stem) chooseStem(stem);
});
});
}
function showToast(message) {
clearTimeout(toastTimer);
toastElement.textContent = message;
toastElement.classList.add("show");
toastTimer = setTimeout(() => toastElement.classList.remove("show"), 3100);
}
buildEnvironment();
buildStall();
buildWorkTable();
buildBucketsAndStems();
buildFinishedBouquets();
buildWrappingAssembly();
renderLedger();
stageButtons.forEach(button => {
button.addEventListener("click", () => {
const mode = button.dataset.mode;
setMode(mode);
if (mode === "arrange") {
arrangeSelected();
if (chosenStems.length) {
showToast("Arranging the selected stems. Watch each ID follow its flower.");
}
}
if (mode === "wrap") {
startWrapping();
}
});
});
primaryAction.addEventListener("click", () => {
if (currentMode === "select") {
const stem = stems.find(item => !item.chosen);
if (stem) chooseStem(stem);
else showToast("Every stem in the buckets has already joined the bouquet.");
} else if (currentMode === "arrange") {
arrangeSelected();
} else {
startWrapping();
}
});
// Direct orthographic orbit and zoom controls.
const cameraTarget = new THREE.Vector3(-0.45, 1.75, -0.55);
const cameraState = {
theta: 0.72,
phi: 0.86,
radius: 23,
zoom: 1
};
function updateCamera() {
const horizontal = Math.sin(cameraState.phi) * cameraState.radius;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraState.theta),
cameraTarget.y + Math.cos(cameraState.phi) * cameraState.radius,
cameraTarget.z + horizontal * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = 6.8;
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
updateCamera();
}
window.addEventListener("resize", resize);
resize();
document.getElementById("reset-view").addEventListener("click", () => {
cameraState.theta = 0.72;
cameraState.phi = 0.86;
cameraState.radius = 23;
cameraState.zoom = 1;
updateCamera();
showToast("Camera reset to the wrapping corner.");
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let previousX = 0;
let previousY = 0;
function pickStem(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(stemHeads, true);
for (const hit of hits) {
if (hit.object.userData.stemRef) return hit.object.userData.stemRef;
}
return null;
}
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0 && event.button !== 2) return;
pointerDown = true;
pointerMoved = false;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
pointerMoved = true;
renderer.domElement.classList.add("dragging");
}
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
1.22
);
updateCamera();
return;
}
const stem = pickStem(event.clientX, event.clientY);
if (stem) {
tooltip.style.display = "block";
tooltip.style.left = `${Math.min(event.clientX + 13, window.innerWidth - 205)}px`;
tooltip.style.top = `${Math.max(12, event.clientY - 38)}px`;
tooltip.textContent = stem.chosen
? `${stem.id} · ${stem.spec.name} · selected`
: `${stem.spec.name} · click to select`;
renderer.domElement.style.cursor = "pointer";
} else {
tooltip.style.display = "none";
renderer.domElement.style.cursor = "grab";
}
});
renderer.domElement.addEventListener("pointerup", event => {
if (pointerDown && !pointerMoved) {
const stem = pickStem(event.clientX, event.clientY);
if (stem) chooseStem(stem);
}
pointerDown = false;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener("pointerleave", () => {
tooltip.style.display = "none";
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom - event.deltaY * 0.0009,
0.62,
1.8
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
const clock = new THREE.Clock();
function animate(now) {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateTweens(now);
stems.forEach(stem => {
stem.head.rotation.z = Math.sin(elapsed * 0.85 + stem.phase) * 0.025;
stem.head.rotation.x = Math.cos(elapsed * 0.72 + stem.phase) * 0.018;
});
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
setTimeout(() => {
document.getElementById("loading").classList.add("hide");
showToast("Welcome to Stem & Leaf. Click a flower head to begin your bouquet.");
}, 450);
</script>
</body>
</html>
```