Prompt specification
Build or customize the Three.js 3D scene "Flower-order composition puzzle" 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: Flower-order composition puzzle
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/flower-order-composition-puzzle-x0500
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: flower-order composition puzzle. Create customer request cards specifying counts and height relationships; users assemble bouquets from finite stem stock, with feedback checking quantities and geometry instead of subjective beauty scores.
Working Three.js Starter (flower-order-composition-puzzle-x0500):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stem & Order — Floral Composition Puzzle</title>
<style>
:root {
--paper: #f5f1e8;
--paper-deep: #e9e2d4;
--panel: #fffdf8;
--ink: #19342c;
--muted: #6f7b73;
--line: #dcd5c8;
--green: #285c48;
--green-light: #dce9df;
--coral: #dc6b58;
--gold: #e6b84e;
--purple: #9271b2;
--shadow: 0 14px 36px rgba(38, 47, 39, 0.09);
--radius: 16px;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
color: var(--ink);
background: var(--paper);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button {
font: inherit;
}
button:focus-visible {
outline: 3px solid rgba(220, 107, 88, 0.45);
outline-offset: 2px;
}
.app-header {
height: 70px;
padding: 0 22px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
background: var(--panel);
border-bottom: 1px solid var(--line);
position: relative;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 38px;
height: 38px;
position: relative;
flex: 0 0 auto;
}
.brand-mark span {
position: absolute;
width: 17px;
height: 11px;
border-radius: 80% 20% 70% 30%;
background: var(--green);
left: 10px;
top: 2px;
transform-origin: 8px 17px;
}
.brand-mark span:nth-child(2) { transform: rotate(72deg); }
.brand-mark span:nth-child(3) { transform: rotate(144deg); }
.brand-mark span:nth-child(4) { transform: rotate(216deg); }
.brand-mark span:nth-child(5) { transform: rotate(288deg); }
.brand-mark::after {
content: "";
position: absolute;
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--gold);
left: 14px;
top: 14px;
border: 2px solid var(--panel);
z-index: 2;
}
.brand h1 {
margin: 0;
font-size: 17px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.brand p {
margin: 2px 0 0;
color: var(--muted);
font-size: 12px;
}
.header-note {
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 999px;
color: var(--muted);
font-size: 12px;
white-space: nowrap;
}
.app-layout {
height: calc(100vh - 70px);
display: grid;
grid-template-columns: 292px minmax(420px, 1fr) 360px;
min-height: 0;
}
.orders-panel,
.workspace {
min-height: 0;
overflow: auto;
background: var(--panel);
}
.orders-panel {
border-right: 1px solid var(--line);
padding: 20px 16px 28px;
}
.workspace {
border-left: 1px solid var(--line);
padding: 18px;
}
.eyebrow {
color: var(--coral);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel-heading {
margin: 5px 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 500;
line-height: 1.05;
}
.panel-copy {
color: var(--muted);
font-size: 12px;
line-height: 1.5;
margin: 0 0 17px;
}
.order-list {
display: grid;
gap: 12px;
}
.order-card {
width: 100%;
padding: 15px;
text-align: left;
color: var(--ink);
background: #faf7f0;
border: 1px solid var(--line);
border-radius: var(--radius);
cursor: pointer;
transition:
transform 150ms ease,
border-color 150ms ease,
box-shadow 150ms ease;
}
.order-card:hover {
transform: translateY(-2px);
border-color: #b9c8bd;
box-shadow: var(--shadow);
}
.order-card.active {
background: #eef4ee;
border: 1.5px solid var(--green);
box-shadow: 0 8px 22px rgba(40, 92, 72, 0.12);
}
.order-card-top {
display: flex;
justify-content: space-between;
gap: 10px;
align-items: flex-start;
}
.order-card h3 {
margin: 4px 0 2px;
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
font-weight: 600;
}
.order-code {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
white-space: nowrap;
}
.customer {
color: var(--muted);
font-size: 11px;
}
.mix-pills {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin: 12px 0 11px;
}
.mix-pill {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 4px 7px;
border-radius: 999px;
background: var(--panel);
border: 1px solid var(--line);
font-size: 10px;
font-weight: 700;
}
.mini-bloom {
width: 8px;
height: 8px;
border-radius: 50% 20% 50% 20%;
background: var(--flower-color);
transform: rotate(30deg);
}
.relation-title {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--green);
margin: 0 0 5px;
}
.relation-list {
margin: 0;
padding-left: 17px;
color: #4f5c54;
font-size: 11px;
line-height: 1.48;
}
.relation-list li + li {
margin-top: 5px;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e9eadf;
}
#canvasHost {
position: absolute;
inset: 0;
}
#canvasHost canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.stage-top {
position: absolute;
z-index: 2;
top: 18px;
left: 18px;
right: 18px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
pointer-events: none;
}
.stage-title {
padding: 11px 13px;
border: 1px solid rgba(255, 255, 255, 0.6);
background: rgba(255, 253, 248, 0.83);
backdrop-filter: blur(9px);
border-radius: 12px;
box-shadow: 0 7px 24px rgba(33, 47, 38, 0.08);
}
.stage-title strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
font-weight: 600;
}
.stage-title span {
display: block;
color: var(--muted);
font-size: 10px;
margin-top: 3px;
}
.counter-badge {
padding: 9px 12px;
border-radius: 999px;
color: var(--panel);
background: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
box-shadow: 0 7px 20px rgba(25, 52, 44, 0.16);
white-space: nowrap;
}
.stage-tools {
position: absolute;
z-index: 3;
top: 82px;
right: 18px;
display: flex;
gap: 6px;
}
.icon-button {
border: 1px solid rgba(255, 255, 255, 0.65);
background: rgba(255, 253, 248, 0.84);
color: var(--ink);
border-radius: 9px;
padding: 7px 9px;
font-size: 10px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(8px);
}
.icon-button:hover {
background: white;
}
.stage-bottom {
position: absolute;
z-index: 3;
left: 18px;
right: 18px;
bottom: 18px;
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 12px;
pointer-events: none;
}
.camera-hint,
.selected-stem {
border: 1px solid rgba(255, 255, 255, 0.62);
background: rgba(255, 253, 248, 0.86);
backdrop-filter: blur(9px);
border-radius: 11px;
box-shadow: 0 7px 24px rgba(33, 47, 38, 0.08);
}
.camera-hint {
padding: 8px 10px;
color: var(--muted);
font-size: 10px;
}
.selected-stem {
min-width: 205px;
max-width: 280px;
padding: 9px 10px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
pointer-events: auto;
}
.selected-stem strong {
display: block;
font-size: 11px;
}
.selected-stem span {
display: block;
color: var(--muted);
font-size: 10px;
margin-top: 2px;
}
.remove-button {
border: 0;
background: transparent;
color: var(--coral);
font-size: 18px;
cursor: pointer;
padding: 3px 6px;
}
.workspace-section {
padding-bottom: 18px;
margin-bottom: 18px;
border-bottom: 1px solid var(--line);
}
.workspace-section:last-child {
border-bottom: 0;
margin-bottom: 0;
}
.section-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.section-heading h2 {
margin: 0;
font-size: 15px;
letter-spacing: 0.01em;
}
.section-heading p {
margin: 3px 0 0;
color: var(--muted);
font-size: 10px;
}
.stock-count {
color: var(--green);
background: var(--green-light);
padding: 4px 7px;
border-radius: 999px;
font-size: 9px;
font-weight: 800;
white-space: nowrap;
}
.stock-list {
display: grid;
gap: 7px;
}
.stock-row {
display: grid;
grid-template-columns: 34px minmax(0, 1fr) auto;
align-items: center;
gap: 9px;
padding: 9px;
background: #faf7f0;
border: 1px solid var(--line);
border-radius: 11px;
}
.flower-swatch {
width: 30px;
height: 30px;
display: grid;
place-items: center;
border-radius: 10px;
background: color-mix(in srgb, var(--flower-color) 24%, white);
}
.flower-swatch::before {
content: "";
width: 16px;
height: 12px;
border-radius: 80% 20% 70% 30%;
background: var(--flower-color);
transform: rotate(30deg);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--flower-color) 18%, transparent);
}
.stock-name {
font-size: 11px;
font-weight: 800;
}
.stock-meta {
color: var(--muted);
font-size: 9px;
margin-top: 2px;
}
.add-button {
width: 31px;
height: 31px;
border: 0;
border-radius: 9px;
color: white;
background: var(--green);
cursor: pointer;
font-size: 19px;
line-height: 1;
}
.add-button:hover:not(:disabled) {
background: #1d4938;
}
.add-button:disabled {
background: #d9d8d1;
color: #9a9c96;
cursor: not-allowed;
}
.text-button {
padding: 4px 7px;
border: 0;
background: transparent;
color: var(--coral);
font-size: 10px;
font-weight: 800;
cursor: pointer;
}
.arrangement-list {
display: grid;
gap: 5px;
max-height: 150px;
overflow: auto;
}
.arrangement-item {
display: flex;
border: 1px solid var(--line);
border-radius: 9px;
overflow: hidden;
background: #faf7f0;
}
.arrangement-item.selected {
border-color: var(--coral);
background: #fff2ed;
}
.arrangement-select {
flex: 1;
min-width: 0;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 7px 9px;
border: 0;
background: transparent;
color: var(--ink);
text-align: left;
cursor: pointer;
font-size: 10px;
}
.arrangement-height {
font-weight: 900;
color: var(--green);
}
.arrangement-item .remove-button {
width: 29px;
border-left: 1px solid var(--line);
}
.empty-state {
padding: 16px 12px;
text-align: center;
color: var(--muted);
background: #faf7f0;
border: 1px dashed #cfc8bb;
border-radius: 10px;
font-size: 10px;
line-height: 1.5;
}
.check-button {
width: 100%;
border: 0;
border-radius: 10px;
padding: 11px 14px;
color: white;
background: var(--coral);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.04em;
cursor: pointer;
box-shadow: 0 6px 16px rgba(220, 107, 88, 0.2);
}
.check-button:hover {
background: #c95e4c;
}
.feedback {
margin-top: 10px;
border: 1px solid var(--line);
border-radius: 11px;
overflow: hidden;
background: #faf7f0;
}
.feedback.neutral {
padding: 13px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.feedback-status {
padding: 10px 11px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
font-size: 11px;
font-weight: 900;
}
.feedback-status.pass {
color: #246342;
background: #e4f1e7;
}
.feedback-status.fail {
color: #9b4437;
background: #f8e6e1;
}
.check-row {
display: grid;
grid-template-columns: 21px minmax(0, 1fr);
gap: 7px;
padding: 9px 10px;
border-top: 1px solid var(--line);
}
.check-icon {
width: 17px;
height: 17px;
display: grid;
place-items: center;
border-radius: 50%;
color: white;
font-size: 10px;
font-weight: 900;
}
.check-icon.pass {
background: #448b62;
}
.check-icon.fail {
background: var(--coral);
}
.check-name {
font-size: 10px;
font-weight: 800;
}
.check-detail {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.progress-track {
height: 5px;
margin-top: 9px;
overflow: hidden;
border-radius: 999px;
background: #dedbd2;
}
.progress-fill {
height: 100%;
width: 0;
border-radius: inherit;
background: var(--coral);
transition: width 180ms ease;
}
.score-note {
margin: 9px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
@media (max-width: 1120px) {
body {
overflow: auto;
}
.app-layout {
height: auto;
min-height: calc(100vh - 70px);
grid-template-columns: 280px minmax(430px, 1fr);
}
.orders-panel,
.stage {
height: calc(100vh - 70px);
}
.workspace {
grid-column: 1 / -1;
display: grid;
grid-template-columns: 1.1fr 0.9fr 1.1fr;
gap: 18px;
border-left: 0;
border-top: 1px solid var(--line);
overflow: visible;
}
.workspace-section {
margin: 0;
padding: 0 0 15px;
}
}
@media (max-width: 760px) {
.app-header {
height: 64px;
padding: 0 13px;
}
.brand p,
.header-note {
display: none;
}
.brand h1 {
font-size: 14px;
}
.app-layout {
display: block;
}
.orders-panel {
height: auto;
max-height: 330px;
border-right: 0;
border-bottom: 1px solid var(--line);
}
.order-list {
grid-template-columns: repeat(3, minmax(220px, 1fr));
overflow-x: auto;
padding-bottom: 4px;
}
.stage {
height: 58vh;
min-height: 460px;
}
.workspace {
display: block;
padding: 16px;
}
.workspace-section {
padding-bottom: 17px;
margin-bottom: 17px;
}
.camera-hint {
display: none;
}
.stage-bottom {
justify-content: flex-end;
}
}
</style>
</head>
<body>
<header class="app-header">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span><span></span><span></span>
</div>
<div>
<h1>Stem & Order</h1>
<p>Floral composition workshop</p>
</div>
</div>
<div class="header-note">Deterministic checks · no aesthetic score</div>
</header>
<main class="app-layout">
<aside class="orders-panel">
<div class="eyebrow">Incoming requests</div>
<h2 class="panel-heading">Build to the brief.</h2>
<p class="panel-copy">
Choose a customer request, then use the finite stem stock to build a bouquet.
Counts and height relationships must all match.
</p>
<div id="orderList" class="order-list"></div>
</aside>
<section id="stage" class="stage" aria-label="Three-dimensional bouquet workspace">
<div id="canvasHost"></div>
<div class="stage-top">
<div class="stage-title">
<strong id="stageOrderTitle">Bouquet workbench</strong>
<span id="stageOrderSubtitle">Select a request to begin</span>
</div>
<div id="counterBadge" class="counter-badge">0 / 0 stems</div>
</div>
<div class="stage-tools">
<button id="toggleTags" class="icon-button" type="button">Height tags: on</button>
<button id="resetCamera" class="icon-button" type="button">Reset view</button>
</div>
<div class="stage-bottom">
<div class="camera-hint">
Drag to orbit · Scroll to zoom · Click a flower to select it
</div>
<div class="selected-stem">
<div>
<strong id="selectedName">No stem selected</strong>
<span id="selectedMeta">Choose a stem from the bouquet</span>
</div>
<button
id="selectedRemove"
class="remove-button"
type="button"
title="Remove selected stem"
aria-label="Remove selected stem"
disabled
>
×
</button>
</div>
</div>
</section>
<aside class="workspace">
<section class="workspace-section">
<div class="section-heading">
<div>
<h2>Finite stem stock</h2>
<p>Each size has a fixed height.</p>
</div>
<span id="stockCount" class="stock-count">0 left</span>
</div>
<div id="stockList" class="stock-list"></div>
</section>
<section class="workspace-section">
<div class="section-heading">
<div>
<h2>Arrangement</h2>
<p id="arrangementMeta">0 stems placed</p>
</div>
<button id="clearArrangement" class="text-button" type="button">Clear</button>
</div>
<div id="arrangementList" class="arrangement-list"></div>
</section>
<section class="workspace-section">
<div class="section-heading">
<div>
<h2>Request check</h2>
<p>Quantity and geometry only.</p>
</div>
</div>
<button id="checkButton" class="check-button" type="button">CHECK BOUQUET</button>
<div class="progress-track" aria-hidden="true">
<div id="progressFill" class="progress-fill"></div>
</div>
<div id="feedback" class="feedback neutral" aria-live="polite">
Add stems from the stock, then run the request check.
</div>
<p class="score-note">
There is no beauty rating. A request passes only when every quantity and
height rule passes.
</p>
</section>
</aside>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const species = {
daisy: {
name: "Daisy",
color: "#f7f3df",
accent: "#e6b84e"
},
tulip: {
name: "Tulip",
color: "#dc6b58",
accent: "#b94e42"
},
aster: {
name: "Aster",
color: "#9271b2",
accent: "#e7b84c"
},
lily: {
name: "Lily",
color: "#f1c78a",
accent: "#8b4b62"
}
};
const stock = [
{ id: "d4", type: "daisy", height: 4, qty: 2, size: "Short" },
{ id: "d5", type: "daisy", height: 5, qty: 2, size: "Medium" },
{ id: "d6", type: "daisy", height: 6, qty: 2, size: "Tall" },
{ id: "t6", type: "tulip", height: 6, qty: 2, size: "Short" },
{ id: "t7", type: "tulip", height: 7, qty: 2, size: "Medium" },
{ id: "t8", type: "tulip", height: 8, qty: 2, size: "Tall" },
{ id: "a5", type: "aster", height: 5, qty: 2, size: "Short" },
{ id: "a6", type: "aster", height: 6, qty: 2, size: "Tall" },
{ id: "l7", type: "lily", height: 7, qty: 2, size: "Short" },
{ id: "l8", type: "lily", height: 8, qty: 2, size: "Medium" },
{ id: "l9", type: "lily", height: 9, qty: 2, size: "Tall" }
];
const orders = [
{
code: "REQ–104",
customer: "Mira · Fern & Co.",
title: "A Small Hello",
total: 5,
mix: { daisy: 3, tulip: 2 },
relations: [
"Both tulips have exactly the same height.",
"The three daisies use at least two different heights.",
"The tallest tulip is at least 2 units above the shortest daisy."
],
checks(stems) {
const daisies = stems.filter(s => s.type === "daisy");
const tulips = stems.filter(s => s.type === "tulip");
const tulipEqual =
tulips.length === 2 &&
tulips.every(s => s.height === tulips[0].height);
const distinctDaisies =
new Set(daisies.map(s => s.height)).size >= 2;
const gap =
daisies.length && tulips.length
? Math.max(...tulips.map(s => s.height)) -
Math.min(...daisies.map(s => s.height))
: null;
return [
{
label: "Tulip pair",
expected: "Equal heights",
actual: formatHeights(tulips),
pass: tulipEqual
},
{
label: "Daisy tiers",
expected: "At least 2 distinct heights",
actual: formatHeights(daisies),
pass: distinctDaisies
},
{
label: "Tall-to-short gap",
expected: "At least 2 units",
actual: gap === null ? "Not enough stems" : `${gap} units`,
pass: gap !== null && gap >= 2
}
];
}
},
{
code: "REQ–118",
customer: "Jon · Common Table",
title: "Sunset Count",
total: 6,
mix: { lily: 2, tulip: 2, aster: 2 },
relations: [
"Both lilies have exactly the same height.",
"Each lily is exactly 1 unit taller than every tulip.",
"Every aster is at least 2 units shorter than every tulip."
],
checks(stems) {
const lilies = stems.filter(s => s.type === "lily");
const tulips = stems.filter(s => s.type === "tulip");
const asters = stems.filter(s => s.type === "aster");
const lilyEqual =
lilies.length === 2 &&
lilies.every(s => s.height === lilies[0].height);
const lilyTulipGap =
lilies.length && tulips.length
? Math.min(...lilies.map(s => s.height)) -
Math.max(...tulips.map(s => s.height))
: null;
const asterGap =
asters.length && tulips.length
? Math.min(...tulips.map(s => s.height)) -
Math.max(...asters.map(s => s.height))
: null;
return [
{
label: "Lily pair",
expected: "Equal heights",
actual: formatHeights(lilies),
pass: lilyEqual
},
{
label: "Lily-to-tulip offset",
expected: "Exactly 1 unit",
actual:
lilyTulipGap === null
? "Not enough stems"
: `${lilyTulipGap} units`,
pass: lilyTulipGap === 1
},
{
label: "Aster clearance",
expected: "At least 2 units below every tulip",
actual:
asterGap === null
? "Not enough stems"
: `${asterGap} units`,
pass: asterGap !== null && asterGap >= 2
}
];
}
},
{
code: "REQ–127",
customer: "Avery · Field Notes",
title: "Wild Study",
total: 7,
mix: { daisy: 3, tulip: 2, lily: 2 },
relations: [
"Exactly one stem occupies the tallest height.",
"Both tulips have exactly the same height.",
"Both lilies stand above every daisy.",
"The daisy heights span exactly 2 units."
],
checks(stems) {
const daisies = stems.filter(s => s.type === "daisy");
const tulips = stems.filter(s => s.type === "tulip");
const lilies = stems.filter(s => s.type === "lily");
const maxHeight = stems.length
? Math.max(...stems.map(s => s.height))
: null;
const topCount = stems.filter(s => s.height === maxHeight).length;
const tulipEqual =
tulips.length === 2 &&
tulips.every(s => s.height === tulips[0].height);
const lilyDaisyGap =
lilies.length && daisies.length
? Math.min(...lilies.map(s => s.height)) -
Math.max(...daisies.map(s => s.height))
: null;
const daisySpan =
daisies.length > 1
? Math.max(...daisies.map(s => s.height)) -
Math.min(...daisies.map(s => s.height))
: null;
return [
{
label: "Unique tallest stem",
expected: "Only one stem at maximum height",
actual:
maxHeight === null
? "No stems"
: `${topCount} stem${topCount === 1 ? "" : "s"} at ${maxHeight}u`,
pass: stems.length > 0 && topCount === 1
},
{
label: "Tulip pair",
expected: "Equal heights",
actual: formatHeights(tulips),
pass: tulipEqual
},
{
label: "Lily clearance",
expected: "Every lily above every daisy",
actual:
lilyDaisyGap === null
? "Not enough stems"
: `${lilyDaisyGap} units above tallest daisy`,
pass: lilyDaisyGap !== null && lilyDaisyGap > 0
},
{
label: "Daisy height span",
expected: "Exactly 2 units",
actual:
daisySpan === null ? "Not enough stems" : `${daisySpan} units`,
pass: daisySpan === 2
}
];
}
}
];
function formatHeights(stems) {
if (!stems.length) return "—";
return stems.map(s => `${s.height}u`).join(" / ");
}
const orderList = document.getElementById("orderList");
const stockList = document.getElementById("stockList");
const arrangementList = document.getElementById("arrangementList");
const feedback = document.getElementById("feedback");
const stockCount = document.getElementById("stockCount");
const counterBadge = document.getElementById("counterBadge");
const progressFill = document.getElementById("progressFill");
const arrangementMeta = document.getElementById("arrangementMeta");
const selectedName = document.getElementById("selectedName");
const selectedMeta = document.getElementById("selectedMeta");
const selectedRemove = document.getElementById("selectedRemove");
const stageOrderTitle = document.getElementById("stageOrderTitle");
const stageOrderSubtitle = document.getElementById("stageOrderSubtitle");
let activeOrderIndex = 0;
let arrangement = [];
let selectedStemId = null;
let nextStemId = 1;
let hasChecked = false;
let tagsVisible = true;
const stockState = Object.fromEntries(stock.map(s => [s.id, s.qty]));
// ------------------------------------------------------------
// Three.js scene
// ------------------------------------------------------------
const host = document.getElementById("canvasHost");
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly bouquet. Drag to orbit and click flowers to select them."
);
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9eadf);
scene.fog = new THREE.Fog(0xe9eadf, 14, 28);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 80);
const cameraTarget = new THREE.Vector3(0, 1.75, 0);
const cameraState = {
theta: 0.52,
phi: 1.06,
radius: 9.5
};
function updateCamera() {
const { theta, phi, radius } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(phi) * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraState.theta = 0.52;
cameraState.phi = 1.06;
cameraState.radius = 9.5;
updateCamera();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff9e9, 0x718574, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3dc, 3.1);
keyLight.position.set(4.5, 9, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xb9d7ce, 1.2);
rimLight.position.set(-5, 4, -5);
scene.add(rimLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xd8d9ca,
roughness: 1,
flatShading: true
});
const floor = new THREE.Mesh(
new THREE.CircleGeometry(18, 48),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.18;
floor.receiveShadow = true;
scene.add(floor);
const tableMaterial = new THREE.MeshStandardMaterial({
color: 0xb8aa8d,
roughness: 0.92,
flatShading: true
});
const table = new THREE.Mesh(
new THREE.CylinderGeometry(2.35, 2.5, 0.3, 36),
tableMaterial
);
table.position.y = -0.15;
table.receiveShadow = true;
table.castShadow = true;
scene.add(table);
const tableTop = new THREE.Mesh(
new THREE.CylinderGeometry(2.33, 2.33, 0.035, 36),
new THREE.MeshStandardMaterial({
color: 0xc8b99a,
roughness: 0.85,
flatShading: true
})
);
tableTop.position.y = 0.015;
tableTop.receiveShadow = true;
scene.add(tableTop);
const bouquetRoot = new THREE.Group();
scene.add(bouquetRoot);
const stemsRoot = new THREE.Group();
const tagsRoot = new THREE.Group();
bouquetRoot.add(stemsRoot, tagsRoot);
const wrapMaterial = new THREE.MeshStandardMaterial({
color: 0xf3e8cf,
roughness: 0.95,
side: THREE.DoubleSide,
flatShading: true
});
const wrap = new THREE.Mesh(
new THREE.CylinderGeometry(0.52, 0.31, 0.96, 9, 1, true),
wrapMaterial
);
wrap.position.y = 0.59;
wrap.castShadow = true;
wrap.receiveShadow = true;
bouquetRoot.add(wrap);
const collar = new THREE.Mesh(
new THREE.ConeGeometry(0.5, 0.2, 9, 1, true),
wrapMaterial
);
collar.position.y = 1.05;
collar.rotation.x = Math.PI;
collar.castShadow = true;
bouquetRoot.add(collar);
const ribbon = new THREE.Mesh(
new THREE.TorusGeometry(0.345, 0.043, 6, 16),
new THREE.MeshStandardMaterial({
color: 0xbb5348,
roughness: 0.8,
flatShading: true
})
);
ribbon.rotation.x = Math.PI / 2;
ribbon.position.y = 0.65;
ribbon.castShadow = true;
bouquetRoot.add(ribbon);
const selectionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.39, 0.025, 6, 28),
new THREE.MeshBasicMaterial({
color: 0xe16d54,
depthTest: false
})
);
selectionRing.rotation.x = Math.PI / 2;
selectionRing.visible = false;
selectionRing.renderOrder = 20;
scene.add(selectionRing);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const headMeshes = [];
const stemMeshes = new Map();
const BASE_Y = 0.12;
const HEIGHT_SCALE = 0.43;
function standardMaterial(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...extra
});
}
function addMesh(parent, geometry, material) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createFlower(type) {
const group = new THREE.Group();
if (type === "daisy") {
const petalMaterial = standardMaterial(species.daisy.color);
const centerMaterial = standardMaterial(species.daisy.accent);
for (let i = 0; i < 10; i++) {
const angle = (i / 10) * Math.PI * 2;
const petal = addMesh(
group,
new THREE.SphereGeometry(0.12, 6, 4),
petalMaterial
);
petal.scale.set(1.8, 0.3, 0.72);
petal.position.set(Math.cos(angle) * 0.16, 0, Math.sin(angle) * 0.16);
petal.rotation.y = -angle;
}
addMesh(
group,
new THREE.SphereGeometry(0.14, 8, 5),
centerMaterial
);
}
if (type === "tulip") {
const petalMaterial = standardMaterial(species.tulip.color);
const innerMaterial = standardMaterial(species.tulip.accent);
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const petal = addMesh(
group,
new THREE.ConeGeometry(0.13, 0.38, 6),
petalMaterial
);
petal.position.set(
Math.cos(angle) * 0.11,
0.1 + (i % 2) * 0.025,
Math.sin(angle) * 0.11
);
petal.rotation.y = angle;
petal.rotation.z = Math.cos(angle) * 0.16;
petal.rotation.x = Math.sin(angle) * 0.16;
}
const center = addMesh(
group,
new THREE.SphereGeometry(0.16, 7, 5),
innerMaterial
);
center.scale.set(0.9, 1.2, 0.9);
center.position.y = 0.07;
}
if (type === "aster") {
const petalMaterial = standardMaterial(species.aster.color);
const centerMaterial = standardMaterial(species.aster.accent);
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const petal = addMesh(
group,
new THREE.SphereGeometry(0.095, 5, 3),
petalMaterial
);
petal.scale.set(1.8, 0.26, 0.62);
petal.position.set(Math.cos(angle) * 0.14, 0, Math.sin(angle) * 0.14);
petal.rotation.y = -angle;
}
addMesh(
group,
new THREE.CylinderGeometry(0.13, 0.13, 0.09, 9),
centerMaterial
);
}
if (type === "lily") {
const petalMaterial = standardMaterial(species.lily.color);
const centerMaterial = standardMaterial(species.lily.accent);
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const petal = addMesh(
group,
new THREE.SphereGeometry(0.13, 6, 4),
petalMaterial
);
petal.scale.set(0.8, 2.7, 0.62);
petal.position.set(
Math.cos(angle) * 0.1,
0.05,
Math.sin(angle) * 0.1
);
petal.rotation.y = -angle;
petal.rotation.z = Math.cos(angle) * 0.2;
}
const center = addMesh(
group,
new THREE.CylinderGeometry(0.09, 0.11, 0.11, 8),
centerMaterial
);
center.position.y = 0.02;
}
return group;
}
function makeHeightTag(text, color) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 64;
const context = canvas.getContext("2d");
context.fillStyle = "#fffdf8";
context.fillRect(0, 0, 128, 64);
context.fillStyle = color;
context.fillRect(0, 0, 7, 64);
context.fillStyle = "#19342c";
context.font = "800 32px system-ui";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 69, 32);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
depthTest: false,
transparent: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(0.48, 0.24, 1);
sprite.renderOrder = 15;
return sprite;
}
function disposeObject(object) {
object.traverse(child => {
if (child.geometry) child.geometry.dispose();
if (child.material) {
const materials = Array.isArray(child.material)
? child.material
: [child.material];
materials.forEach(material => {
if (material.map) material.map.dispose();
material.dispose();
});
}
});
}
function clearDynamicMeshes() {
[...stemsRoot.children].forEach(child => {
stemsRoot.remove(child);
disposeObject(child);
});
[...tagsRoot.children].forEach(child => {
tagsRoot.remove(child);
disposeObject(child);
});
headMeshes.length = 0;
stemMeshes.clear();
}
function createStem(stem, index) {
const group = new THREE.Group();
const goldenAngle = 2.3999632297;
const angle = index * goldenAngle + 0.38;
const radius = 0.17 + (index % 3) * 0.1;
group.position.set(
Math.cos(angle) * radius,
0,
Math.sin(angle) * radius
);
const length = stem.height * HEIGHT_SCALE;
const stemMaterial = standardMaterial(
index % 2 === 0 ? 0x416f4d : 0x315d42
);
const cylinder = addMesh(
group,
new THREE.CylinderGeometry(0.025, 0.035, length, 6),
stemMaterial
);
cylinder.position.y = BASE_Y + length / 2;
const leafMaterial = standardMaterial(0x5f8754);
const leafA = addMesh(
group,
new THREE.SphereGeometry(0.12, 5, 3),
leafMaterial
);
leafA.scale.set(1.25, 0.16, 0.48);
leafA.position.set(0.09, BASE_Y + length * 0.45, 0);
leafA.rotation.z = -0.42;
const leafB = addMesh(
group,
new THREE.SphereGeometry(0.1, 5, 3),
leafMaterial
);
leafB.scale.set(1.05, 0.15, 0.42);
leafB.position.set(-0.08, BASE_Y + length * 0.62, 0.015);
leafB.rotation.z = 0.48;
const head = createFlower(stem.type);
head.position.y = BASE_Y + length;
head.userData.stemId = stem.id;
head.traverse(child => {
if (child.isMesh) {
child.userData.stemId = stem.id;
headMeshes.push(child);
}
});
group.add(head);
stemsRoot.add(group);
const tag = makeHeightTag(
`${stem.height}u`,
species[stem.type].color
);
tag.position.set(
group.position.x + 0.29,
head.position.y + 0.35,
group.position.z
);
tagsRoot.add(tag);
stemMeshes.set(stem.id, { group, head });
}
function syncBouquet() {
clearDynamicMeshes();
arrangement.forEach(createStem);
updateSelectionRing();
}
function updateSelectionRing() {
const selected = arrangement.find(s => s.id === selectedStemId);
const meshData = selected ? stemMeshes.get(selected.id) : null;
if (!selected || !meshData) {
selectionRing.visible = false;
return;
}
selectionRing.visible = true;
selectionRing.position.set(
meshData.group.position.x,
meshData.head.position.y + 0.015,
meshData.group.position.z
);
}
// ------------------------------------------------------------
// Direct camera controls and raycasting
// ------------------------------------------------------------
let pointerDown = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerDown) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
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.68,
1.43
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
renderer.domElement.style.cursor = "grabbing";
return;
}
const hit = raycastHead(event);
renderer.domElement.style.cursor = hit ? "pointer" : "grab";
});
renderer.domElement.addEventListener("pointerup", event => {
pointerDown = false;
renderer.domElement.style.cursor = "grab";
if (!pointerMoved) {
const hit = raycastHead(event);
selectedStemId = hit ? hit.object.userData.stemId : null;
updateSelectionRing();
renderArrangement();
renderSelectedInfo();
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
pointerMoved = false;
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
7.2,
15
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
function raycastHead(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 intersections = raycaster.intersectObjects(headMeshes, false);
return intersections.length ? intersections[0] : null;
}
// ------------------------------------------------------------
// Puzzle logic
// ------------------------------------------------------------
function loadOrder(index) {
activeOrderIndex = index;
arrangement = [];
selectedStemId = null;
nextStemId = 1;
hasChecked = false;
stock.forEach(item => {
stockState[item.id] = item.qty;
});
syncBouquet();
renderOrders();
renderStock();
renderArrangement();
renderSelectedInfo();
renderFeedback();
updateStageInfo();
}
function addStem(stockId) {
if (stockState[stockId] <= 0) return;
const item = stock.find(s => s.id === stockId);
if (!item) return;
stockState[stockId] -= 1;
const stem = {
id: nextStemId++,
stockId: item.id,
type: item.type,
height: item.height
};
arrangement.push(stem);
selectedStemId = stem.id;
syncBouquet();
renderStock();
renderArrangement();
renderSelectedInfo();
updateStageInfo();
if (hasChecked) renderFeedback();
}
function removeStem(id) {
const index = arrangement.findIndex(s => s.id === id);
if (index === -1) return;
const stem = arrangement[index];
stockState[stem.stockId] += 1;
arrangement.splice(index, 1);
if (selectedStemId === id) selectedStemId = null;
syncBouquet();
renderStock();
renderArrangement();
renderSelectedInfo();
updateStageInfo();
if (hasChecked) renderFeedback();
}
function clearArrangement() {
arrangement.forEach(stem => {
stockState[stem.stockId] += 1;
});
arrangement = [];
selectedStemId = null;
syncBouquet();
renderStock();
renderArrangement();
renderSelectedInfo();
updateStageInfo();
if (hasChecked) renderFeedback();
}
function evaluateOrder() {
const order = orders[activeOrderIndex];
const actualMix = {};
Object.keys(order.mix).forEach(type => {
actualMix[type] = arrangement.filter(s => s.type === type).length;
});
const mixMatches = Object.entries(order.mix).every(
([type, count]) => actualMix[type] === count
);
const rows = [
{
label: "Stem quantity",
expected: `${order.total} stems`,
actual: `${arrangement.length} stems`,
pass: arrangement.length === order.total
},
{
label: "Species mix",
expected: formatMix(order.mix),
actual: formatMix(actualMix),
pass: mixMatches
},
...order.checks(arrangement)
];
return {
rows,
passed: rows.every(row => row.pass),
passedCount: rows.filter(row => row.pass).length,
totalChecks: rows.length
};
}
function formatMix(mix) {
return Object.entries(mix)
.map(([type, count]) => `${species[type].name} ${count}`)
.join(" · ");
}
// ------------------------------------------------------------
// Interface rendering
// ------------------------------------------------------------
function renderOrders() {
orderList.innerHTML = orders
.map((order, index) => {
const active = index === activeOrderIndex;
const mixPills = Object.entries(order.mix)
.map(
([type, count]) => `
<span class="mix-pill">
<span class="mini-bloom" style="--flower-color:${species[type].color}"></span>
${count} ${species[type].name}
</span>
`
)
.join("");
const relations = order.relations
.map(relation => `<li>${relation}</li>`)
.join("");
return `
<button
class="order-card ${active ? "active" : ""}"
type="button"
data-order="${index}"
aria-pressed="${active}"
>
<div class="order-card-top">
<div>
<div class="eyebrow">${order.title}</div>
<h3>${order.customer}</h3>
</div>
<span class="order-code">${order.code}</span>
</div>
<div class="mix-pills">${mixPills}</div>
<p class="relation-title">Height relationships</p>
<ul class="relation-list">${relations}</ul>
</button>
`;
})
.join("");
}
function renderStock() {
const order = orders[activeOrderIndex];
const relevantStock = stock.filter(item => order.mix[item.type]);
const total = relevantStock.reduce(
(sum, item) => sum + stockState[item.id],
0
);
stockCount.textContent = `${total} left`;
stockList.innerHTML = relevantStock
.map(item => {
const remaining = stockState[item.id];
const used = item.qty - remaining;
return `
<div class="stock-row">
<div
class="flower-swatch"
style="--flower-color:${species[item.type].color}"
aria-hidden="true"
></div>
<div>
<div class="stock-name">${species[item.type].name}</div>
<div class="stock-meta">
${item.size} · ${item.height} units ·
${remaining}/${item.qty} left${used ? ` · ${used} used` : ""}
</div>
</div>
<button
class="add-button"
type="button"
data-add="${item.id}"
aria-label="Add ${species[item.type].name}, ${item.size}, ${item.height} units"
${remaining <= 0 ? "disabled" : ""}
>
+
</button>
</div>
`;
})
.join("");
}
function renderArrangement() {
arrangementMeta.textContent = `${arrangement.length} stem${arrangement.length === 1 ? "" : "s"} placed`;
if (!arrangement.length) {
arrangementList.innerHTML = `
<div class="empty-state">
No stems yet.<br />
Add stock from the panel above.
</div>
`;
return;
}
arrangementList.innerHTML = arrangement
.map(stem => {
const selected = stem.id === selectedStemId;
return `
<div class="arrangement-item ${selected ? "selected" : ""}">
<button
class="arrangement-select"
type="button"
data-select="${stem.id}"
aria-label="Select ${species[stem.type].name}, height ${stem.height}"
>
<span>${species[stem.type].name}</span>
<span class="arrangement-height">${stem.height}u</span>
</button>
<button
class="remove-button"
type="button"
data-remove="${stem.id}"
aria-label="Remove ${species[stem.type].name}"
>
×
</button>
</div>
`;
})
.join("");
}
function renderSelectedInfo() {
const selected = arrangement.find(s => s.id === selectedStemId);
if (!selected) {
selectedName.textContent = "No stem selected";
selectedMeta.textContent = "Choose a stem from the bouquet";
selectedRemove.disabled = true;
return;
}
selectedName.textContent = `${species[selected.type].name} selected`;
selectedMeta.textContent = `${selected.height} units tall · stock ${selected.stockId.toUpperCase()}`;
selectedRemove.disabled = false;
}
function renderFeedback() {
if (!hasChecked) {
feedback.className = "feedback neutral";
feedback.innerHTML =
"Add stems from the stock, then run the request check.";
progressFill.style.width = "0%";
return;
}
const result = evaluateOrder();
const remaining = result.totalChecks - result.passedCount;
feedback.className = "feedback";
feedback.innerHTML = `
<div class="feedback-status ${result.passed ? "pass" : "fail"}">
<span>${result.passed ? "REQUEST MATCHED" : "KEEP ADJUSTING"}</span>
<span>${result.passedCount}/${result.totalChecks}</span>
</div>
${result.rows
.map(
row => `
<div class="check-row">
<div class="check-icon ${row.pass ? "pass" : "fail"}">
${row.pass ? "✓" : "×"}
</div>
<div>
<div class="check-name">${row.label}</div>
<div class="check-detail">
Required: ${row.expected}<br />
Actual: ${row.actual}
</div>
</div>
</div>
`
)
.join("")}
`;
progressFill.style.width = `${(result.passedCount / result.totalChecks) * 100}%`;
progressFill.style.background = result.passed ? "#448b62" : "#dc6b58";
if (remaining > 0) {
feedback.setAttribute(
"aria-label",
`${remaining} request checks still need attention.`
);
}
}
function updateStageInfo() {
const order = orders[activeOrderIndex];
stageOrderTitle.textContent = order.title;
stageOrderSubtitle.textContent = `${order.code} · ${order.customer}`;
counterBadge.textContent = `${arrangement.length} / ${order.total} stems`;
}
// ------------------------------------------------------------
// Events
// ------------------------------------------------------------
orderList.addEventListener("click", event => {
const card = event.target.closest("[data-order]");
if (!card) return;
loadOrder(Number(card.dataset.order));
});
stockList.addEventListener("click", event => {
const button = event.target.closest("[data-add]");
if (!button || button.disabled) return;
addStem(button.dataset.add);
});
arrangementList.addEventListener("click", event => {
const removeButton = event.target.closest("[data-remove]");
if (removeButton) {
removeStem(Number(removeButton.dataset.remove));
return;
}
const selectButton = event.target.closest("[data-select]");
if (selectButton) {
selectedStemId = Number(selectButton.dataset.select);
updateSelectionRing();
renderArrangement();
renderSelectedInfo();
}
});
selectedRemove.addEventListener("click", () => {
if (selectedStemId !== null) removeStem(selectedStemId);
});
document.getElementById("clearArrangement").addEventListener(
"click",
clearArrangement
);
document.getElementById("checkButton").addEventListener("click", () => {
hasChecked = true;
renderFeedback();
});
document.getElementById("resetCamera").addEventListener(
"click",
resetCamera
);
document.getElementById("toggleTags").addEventListener("click", event => {
tagsVisible = !tagsVisible;
tagsRoot.visible = tagsVisible;
event.currentTarget.textContent = `Height tags: ${tagsVisible ? "on" : "off"}`;
});
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
function resizeRenderer() {
const width = Math.max(host.clientWidth, 1);
const height = Math.max(host.clientHeight, 1);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(host);
resizeRenderer();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
if (selectionRing.visible) {
const pulse = 1 + Math.sin(clock.getElapsedTime() * 4) * 0.045;
selectionRing.scale.setScalar(pulse);
}
renderer.render(scene, camera);
}
loadOrder(0);
animate();
</script>
</body>
</html>
```