Prompt specification
Build or customize the Three.js 3D scene "Fit-based stock selection 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: Fit-based stock selection puzzle
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/fit-based-stock-selection-puzzle-x0540
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: fit-based stock selection puzzle. Create an abstract shoe inventory with fictional dimensions and customer templates; users choose compatible forms by multiple constraints instead of relying on a single size number. Return one self-contained HTML file.
Working Three.js Starter (fit-based-stock-selection-puzzle-x0540):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#f2f0e9" />
<title>FORM / FIT — Inventory Selection Lab</title>
<style>
:root {
--paper: #f2f0e9;
--panel: #faf9f5;
--ink: #202724;
--muted: #6f7772;
--line: #d9d9d0;
--green: #477363;
--green-soft: #e1ebe4;
--yellow: #efc45f;
--coral: #d96f50;
--red: #b95d51;
--shadow: 0 18px 50px rgba(35, 44, 39, 0.09);
--radius: 18px;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
button:focus-visible,
input:focus-visible {
outline: 3px solid rgba(71, 115, 99, 0.28);
outline-offset: 2px;
}
.topbar {
height: 72px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(250, 249, 245, 0.94);
backdrop-filter: blur(14px);
position: relative;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 230px;
}
.brand-mark {
width: 38px;
height: 38px;
display: grid;
place-items: center;
background: var(--ink);
color: var(--paper);
clip-path: polygon(25% 7%, 75% 7%, 100% 50%, 75% 93%, 25% 93%, 0 50%);
font-weight: 900;
letter-spacing: -0.08em;
font-size: 16px;
}
.brand-name {
font-size: 17px;
font-weight: 850;
letter-spacing: 0.15em;
}
.brand-sub {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.topbar-center {
display: flex;
align-items: center;
gap: 12px;
color: var(--muted);
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.pulse-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 5px rgba(71, 115, 99, 0.12);
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
}
.stock-pill {
display: flex;
align-items: center;
gap: 8px;
border: 1px solid var(--line);
border-radius: 999px;
padding: 9px 13px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
background: white;
}
.stock-pill span {
color: var(--muted);
}
.ghost-button {
border: 1px solid var(--line);
background: transparent;
border-radius: 10px;
padding: 9px 12px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.05em;
cursor: pointer;
transition: 160ms ease;
}
.ghost-button:hover {
background: white;
border-color: #b7bbb4;
}
.workspace {
height: calc(100vh - 72px);
display: grid;
grid-template-columns: 310px minmax(420px, 1fr) 350px;
min-height: 0;
}
.panel {
min-height: 0;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: #c9cbc4 transparent;
background: var(--panel);
}
.panel-left {
border-right: 1px solid var(--line);
}
.panel-right {
border-left: 1px solid var(--line);
}
.section {
padding: 23px 22px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow strong {
color: var(--ink);
font-weight: 850;
}
.section h1,
.section h2,
.section h3,
.section p {
margin: 0;
}
.section-title {
font-size: 22px;
line-height: 1.15;
letter-spacing: -0.035em;
font-weight: 790;
}
.section-copy {
margin-top: 9px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.constraint-stack {
display: grid;
gap: 8px;
margin-top: 17px;
}
.constraint {
border: 1px solid var(--line);
border-radius: 12px;
background: white;
padding: 11px;
transition: 160ms ease;
}
.constraint.inactive {
opacity: 0.5;
background: #f4f3ee;
}
.constraint-head {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
}
.constraint-head input {
width: 15px;
height: 15px;
accent-color: var(--green);
cursor: pointer;
}
.constraint-name {
font-size: 12px;
font-weight: 800;
}
.constraint-unit {
margin-left: auto;
color: var(--muted);
font-size: 10px;
font-weight: 750;
text-transform: uppercase;
}
.range-inputs {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 7px;
}
.range-inputs input {
width: 100%;
min-width: 0;
border: 1px solid #dedfd8;
border-radius: 8px;
padding: 7px 8px;
background: #f8f7f2;
color: var(--ink);
font-size: 12px;
font-weight: 750;
}
.range-divider {
color: #a2a69f;
font-size: 11px;
}
.constraint-actions {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 12px;
}
.active-summary {
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.text-button {
border: 0;
padding: 0;
background: transparent;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
}
.inventory-head {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.inventory-head h2 {
font-size: 15px;
letter-spacing: -0.02em;
}
.inventory-count {
color: var(--muted);
font-size: 10px;
font-weight: 800;
text-transform: uppercase;
}
.inventory-list {
display: grid;
gap: 7px;
}
.stock-row {
width: 100%;
display: grid;
grid-template-columns: 34px 1fr auto;
align-items: center;
gap: 10px;
border: 1px solid transparent;
border-radius: 12px;
padding: 10px;
background: #f2f1eb;
text-align: left;
cursor: pointer;
transition: 150ms ease;
}
.stock-row:hover {
transform: translateX(2px);
background: #ecece5;
}
.stock-row.selected {
border-color: var(--ink);
background: white;
box-shadow: 0 7px 18px rgba(32, 39, 36, 0.07);
}
.stock-row.incompatible {
opacity: 0.52;
}
.stock-code {
display: grid;
place-items: center;
height: 34px;
border-radius: 9px;
background: var(--ink);
color: white;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.05em;
}
.stock-row.incompatible .stock-code {
background: #9da19b;
}
.stock-name {
font-size: 12px;
font-weight: 800;
}
.stock-meta {
margin-top: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.02em;
}
.fit-badge {
min-width: 33px;
padding: 5px 6px;
border-radius: 999px;
background: var(--green-soft);
color: var(--green);
text-align: center;
font-size: 9px;
font-weight: 900;
}
.fit-badge.fail {
background: #eee1dc;
color: var(--red);
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e9e8e0;
}
#scene-host,
#label-layer {
position: absolute;
inset: 0;
}
#scene-host canvas {
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene-host canvas:active {
cursor: grabbing;
}
#label-layer {
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
transform: translate(-50%, -100%);
display: flex;
align-items: center;
gap: 6px;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 8px;
background: rgba(250, 249, 245, 0.9);
box-shadow: 0 7px 18px rgba(30, 38, 34, 0.12);
backdrop-filter: blur(8px);
color: var(--ink);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.05em;
pointer-events: auto;
cursor: pointer;
white-space: nowrap;
transition: opacity 120ms ease;
}
.scene-label.selected {
border-color: var(--yellow);
box-shadow: 0 8px 22px rgba(30, 38, 34, 0.16);
}
.scene-label.incompatible {
opacity: 0.58;
}
.label-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
}
.scene-label.incompatible .label-dot {
background: #999e98;
}
.scene-label.selected .label-dot {
background: var(--coral);
}
.stage-heading {
position: absolute;
top: 23px;
left: 24px;
z-index: 3;
pointer-events: none;
}
.stage-kicker {
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.stage-heading h2 {
margin-top: 7px;
font-size: clamp(20px, 2.2vw, 30px);
line-height: 1;
letter-spacing: -0.045em;
}
.stage-help {
margin-top: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 650;
}
.stage-tools {
position: absolute;
top: 22px;
right: 20px;
z-index: 4;
display: flex;
gap: 7px;
}
.tool-button {
width: 36px;
height: 36px;
display: grid;
place-items: center;
border: 1px solid rgba(32, 39, 36, 0.14);
border-radius: 10px;
background: rgba(250, 249, 245, 0.88);
backdrop-filter: blur(8px);
cursor: pointer;
font-size: 16px;
font-weight: 800;
transition: 150ms ease;
}
.tool-button:hover {
background: white;
transform: translateY(-1px);
}
.stage-result {
position: absolute;
left: 24px;
bottom: 23px;
z-index: 3;
display: flex;
align-items: center;
gap: 12px;
border: 1px solid rgba(32, 39, 36, 0.12);
border-radius: 13px;
padding: 11px 13px;
background: rgba(250, 249, 245, 0.86);
backdrop-filter: blur(10px);
box-shadow: var(--shadow);
}
.result-number {
font-size: 23px;
font-weight: 850;
letter-spacing: -0.05em;
}
.result-copy {
color: var(--muted);
font-size: 9px;
font-weight: 800;
line-height: 1.35;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend {
position: absolute;
right: 21px;
bottom: 23px;
z-index: 3;
display: flex;
gap: 13px;
padding: 9px 11px;
border-radius: 10px;
background: rgba(250, 249, 245, 0.82);
backdrop-filter: blur(8px);
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
text-transform: uppercase;
}
.legend-swatch {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--green);
}
.legend-swatch.selected {
background: var(--coral);
}
.legend-swatch.out {
background: #a4a8a2;
}
.customer-list {
display: grid;
gap: 8px;
margin-top: 15px;
}
.customer-card {
width: 100%;
display: grid;
grid-template-columns: 38px 1fr auto;
align-items: center;
gap: 10px;
border: 1px solid var(--line);
border-radius: 13px;
padding: 10px;
background: white;
text-align: left;
cursor: pointer;
transition: 160ms ease;
}
.customer-card:hover {
border-color: #adb4ad;
transform: translateY(-1px);
}
.customer-card.active {
border-color: var(--ink);
box-shadow: 0 8px 20px rgba(32, 39, 36, 0.08);
}
.customer-avatar {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border-radius: 11px;
color: white;
background: var(--avatar);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.04em;
}
.customer-name {
font-size: 12px;
font-weight: 850;
}
.customer-note {
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.3;
}
.customer-check {
width: 19px;
height: 19px;
display: grid;
place-items: center;
border: 1px solid var(--line);
border-radius: 50%;
color: transparent;
font-size: 10px;
font-weight: 900;
}
.customer-card.active .customer-check {
border-color: var(--green);
background: var(--green);
color: white;
}
.profile-card {
display: grid;
grid-template-columns: 76px 1fr;
gap: 14px;
align-items: center;
margin-top: 15px;
border-radius: 15px;
padding: 14px;
background: #eeeee7;
}
.profile-visual {
position: relative;
display: grid;
place-items: center;
height: 106px;
border-radius: 12px;
overflow: hidden;
background: var(--profile-bg);
}
.profile-visual svg {
width: 64px;
height: 96px;
overflow: visible;
}
.profile-name {
font-size: 18px;
font-weight: 850;
letter-spacing: -0.03em;
}
.profile-role {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.profile-tags {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 11px;
}
.tag {
padding: 5px 7px;
border: 1px solid #d3d5ce;
border-radius: 999px;
background: rgba(255, 255, 255, 0.7);
color: #555e58;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.match-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.selected-code {
margin-top: 6px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.score-ring {
--score: 0;
--score-color: var(--green);
width: 66px;
height: 66px;
flex: 0 0 auto;
display: grid;
place-items: center;
border-radius: 50%;
background: conic-gradient(
var(--score-color) calc(var(--score) * 1%),
#dedfd8 0
);
position: relative;
}
.score-ring::before {
content: "";
position: absolute;
inset: 7px;
border-radius: 50%;
background: var(--panel);
}
.score-value {
position: relative;
z-index: 1;
font-size: 17px;
font-weight: 900;
letter-spacing: -0.04em;
}
.score-value small {
color: var(--muted);
font-size: 8px;
font-weight: 800;
}
.verdict {
margin-top: 14px;
padding: 10px 12px;
border-radius: 10px;
background: var(--green-soft);
color: var(--green);
font-size: 10px;
font-weight: 850;
line-height: 1.4;
}
.verdict.fail {
background: #eee1dc;
color: var(--red);
}
.metric-list {
display: grid;
gap: 14px;
margin-top: 17px;
}
.metric-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
}
.metric-name {
font-size: 10px;
font-weight: 850;
text-transform: uppercase;
letter-spacing: 0.06em;
}
.metric-value {
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.metric-value.good {
color: var(--green);
}
.metric-value.bad {
color: var(--red);
}
.metric-track {
position: relative;
height: 6px;
border-radius: 999px;
background: #e1e2db;
}
.metric-safe {
position: absolute;
top: 0;
height: 100%;
border-radius: 999px;
background: #b9cec1;
}
.metric-dot {
position: absolute;
top: 50%;
width: 10px;
height: 10px;
border: 2px solid white;
border-radius: 50%;
background: var(--green);
transform: translate(-50%, -50%);
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.22);
}
.metric-dot.bad {
background: var(--red);
}
.metric-inactive {
opacity: 0.38;
}
.primary-button {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
gap: 9px;
border: 0;
border-radius: 11px;
padding: 13px 16px;
background: var(--ink);
color: white;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.05em;
text-transform: uppercase;
cursor: pointer;
transition: 160ms ease;
}
.primary-button:hover:not(:disabled) {
background: #35413c;
transform: translateY(-1px);
}
.primary-button:disabled {
cursor: not-allowed;
opacity: 0.35;
}
.primary-button.chosen {
background: var(--green);
}
.shortcut-bar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 15px 22px;
}
.shortcut-copy {
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.shortcut-copy strong {
color: var(--ink);
}
dialog {
width: min(560px, calc(100vw - 32px));
border: 0;
border-radius: 20px;
padding: 0;
background: var(--panel);
color: var(--ink);
box-shadow: 0 30px 100px rgba(20, 28, 24, 0.32);
}
dialog::backdrop {
background: rgba(24, 30, 27, 0.42);
backdrop-filter: blur(4px);
}
.dialog-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: 21px 22px;
border-bottom: 1px solid var(--line);
}
.dialog-head h2 {
margin: 0;
font-size: 20px;
letter-spacing: -0.035em;
}
.dialog-close {
border: 0;
background: transparent;
font-size: 22px;
cursor: pointer;
}
.dialog-body {
padding: 18px 22px 22px;
}
.shortlist-row {
display: grid;
grid-template-columns: 1fr auto auto;
align-items: center;
gap: 12px;
padding: 13px 0;
border-bottom: 1px solid var(--line);
}
.shortlist-row strong {
display: block;
font-size: 12px;
}
.shortlist-row small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
}
.remove-button {
border: 1px solid var(--line);
border-radius: 8px;
background: white;
padding: 6px 8px;
cursor: pointer;
font-size: 9px;
font-weight: 800;
}
.dialog-actions {
display: flex;
justify-content: flex-end;
gap: 8px;
margin-top: 18px;
}
.toast {
position: fixed;
left: 50%;
bottom: 28px;
z-index: 30;
transform: translate(-50%, 20px);
padding: 12px 16px;
border-radius: 10px;
background: var(--ink);
color: white;
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 750;
opacity: 0;
pointer-events: none;
transition: 200ms ease;
}
.toast.show {
transform: translate(-50%, 0);
opacity: 1;
}
.webgl-error {
position: absolute;
inset: 0;
display: none;
place-items: center;
padding: 40px;
text-align: center;
color: var(--muted);
font-size: 13px;
}
@media (max-width: 1180px) {
.workspace {
grid-template-columns: 285px minmax(380px, 1fr) 315px;
}
.section {
padding-left: 18px;
padding-right: 18px;
}
.stage-help,
.legend {
display: none;
}
}
@media (max-width: 900px) {
body {
overflow: auto;
}
.topbar {
position: sticky;
top: 0;
}
.topbar-center {
display: none;
}
.workspace {
height: auto;
display: flex;
flex-direction: column;
}
.stage {
order: -1;
height: 58vh;
min-height: 430px;
}
.panel {
overflow: visible;
}
.panel-left {
border-right: 0;
border-top: 1px solid var(--line);
}
.panel-right {
border-left: 0;
border-top: 1px solid var(--line);
}
.inventory-list {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 560px) {
.topbar {
height: 64px;
padding: 0 14px;
}
.brand {
min-width: 0;
}
.brand-sub,
.stock-pill span,
#reset-all {
display: none;
}
.inventory-list {
grid-template-columns: 1fr;
}
.stage {
min-height: 390px;
}
.stage-heading {
left: 16px;
top: 17px;
}
.stage-tools {
right: 14px;
top: 15px;
}
.stage-result {
left: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<div class="brand-mark">F/</div>
<div>
<div class="brand-name">FORM / FIT</div>
<div class="brand-sub">Inventory selection lab</div>
</div>
</div>
<div class="topbar-center">
<span class="pulse-dot"></span>
<span>Fit engine active · sample collection 04</span>
</div>
<div class="top-actions">
<div class="stock-pill">
12 <span>virtual forms</span>
</div>
<button class="ghost-button" id="reset-all">Reset lab</button>
</div>
</header>
<main class="workspace">
<aside class="panel panel-left" aria-label="Fit constraints and inventory">
<section class="section">
<div class="eyebrow">
<span>01 / Constraint set</span>
<strong id="constraint-count">4 active</strong>
</div>
<h1 class="section-title">A fit is a shape,<br />not a single number.</h1>
<p class="section-copy">
Combine length, width, instep and heel bounds. Disable a dimension when the
customer template does not require it.
</p>
<div class="constraint-stack" id="constraint-stack"></div>
<div class="constraint-actions">
<span class="active-summary" id="active-summary">Using all dimensions</span>
<button class="text-button" id="reset-bounds">Reset bounds</button>
</div>
</section>
<section class="section">
<div class="inventory-head">
<div>
<div class="eyebrow">Stock geometry</div>
<h2>Abstract form inventory</h2>
</div>
<span class="inventory-count" id="inventory-count">12 forms</span>
</div>
<div class="inventory-list" id="inventory-list"></div>
</section>
</aside>
<section class="stage" aria-label="Interactive three-dimensional shoe inventory">
<div id="scene-host"></div>
<div id="label-layer"></div>
<div class="stage-heading">
<div class="stage-kicker">Spatial inventory / 04</div>
<h2>Form wall</h2>
<div class="stage-help">Drag to orbit · scroll to zoom · shift-drag to pan</div>
</div>
<div class="stage-tools">
<button class="tool-button" id="focus-selected" title="Focus selected form" aria-label="Focus selected form">⌖</button>
<button class="tool-button" id="reset-view" title="Reset camera" aria-label="Reset camera">↺</button>
</div>
<div class="stage-result">
<div class="result-number" id="scene-match-count">4</div>
<div class="result-copy">Compatible<br />forms</div>
</div>
<div class="legend">
<div class="legend-item"><span class="legend-swatch"></span>Match</div>
<div class="legend-item"><span class="legend-swatch selected"></span>Selected</div>
<div class="legend-item"><span class="legend-swatch out"></span>Outside bounds</div>
</div>
<div class="webgl-error" id="webgl-error">
This experience needs WebGL. Try enabling hardware acceleration in your browser.
</div>
</section>
<aside class="panel panel-right" aria-label="Customer template and fit result">
<section class="section">
<div class="eyebrow">
<span>02 / Customer template</span>
<strong>4 profiles</strong>
</div>
<h2 class="section-title">Select a foot form</h2>
<p class="section-copy">
Each template describes a fictional customer and a preferred fit envelope.
</p>
<div class="customer-list" id="customer-list"></div>
<div class="profile-card">
<div class="profile-visual" id="profile-visual">
<svg viewBox="0 0 80 120" aria-hidden="true">
<path
d="M31 103 C24 91 21 77 24 63 C27 49 28 36 26 23 C25 13 31 7 39 9 C47 11 49 18 47 30 C45 42 42 52 46 63 C50 74 58 80 59 91 C60 102 53 110 43 110 C38 110 34 108 31 103Z"
fill="rgba(255,255,255,.7)"
stroke="currentColor"
stroke-width="2"
/>
<path d="M13 17 L66 17" stroke="currentColor" stroke-width="1.5" stroke-dasharray="3 3" opacity=".45" />
<path d="M24 39 L55 39" stroke="currentColor" stroke-width="1.5" stroke-dasharray="3 3" opacity=".45" />
<circle cx="27" cy="17" r="3" fill="currentColor" />
<circle cx="26" cy="39" r="3" fill="currentColor" />
<circle cx="42" cy="66" r="3" fill="currentColor" opacity=".55" />
</svg>
</div>
<div>
<div class="profile-name" id="profile-name">Mira Chen</div>
<div class="profile-role" id="profile-role">Urban commuter · neutral stride</div>
<div class="profile-tags" id="profile-tags"></div>
</div>
</div>
</section>
<section class="section">
<div class="eyebrow">
<span>03 / Form match</span>
<strong id="result-status">Compatible</strong>
</div>
<div class="match-heading">
<div>
<h2 class="section-title" id="selected-name">Arc 05</h2>
<div class="selected-code" id="selected-code">SKU F-05 · standard profile</div>
</div>
<div class="score-ring" id="score-ring">
<div class="score-value"><span id="score-value">96</span><small>%</small></div>
</div>
</div>
<div class="verdict" id="fit-verdict">
Strong overlap across every active dimension.
</div>
<div class="metric-list" id="metric-list"></div>
</section>
<section class="section">
<button class="primary-button" id="select-form">+ Add compatible form</button>
</section>
<div class="shortcut-bar">
<div class="shortcut-copy">
<strong id="shortlist-count">0 forms</strong> shortlisted
</div>
<button class="ghost-button" id="review-shortlist">Review selection</button>
</div>
</aside>
</main>
<dialog id="shortlist-dialog">
<div class="dialog-head">
<h2>Selection queue</h2>
<button class="dialog-close" id="close-dialog" aria-label="Close">×</button>
</div>
<div class="dialog-body">
<div id="shortlist-items"></div>
<div class="dialog-actions">
<button class="ghost-button" id="clear-shortlist">Clear</button>
<button class="primary-button" id="confirm-shortlist" style="width:auto">
Lock selection
</button>
</div>
</div>
</dialog>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const dimensionKeys = ["length", "width", "instep", "heel"];
const dimensionMeta = {
length: { label: "Length", short: "L", unit: "cm", domain: [25, 29.5] },
width: { label: "Width", short: "W", unit: "cm", domain: [7.5, 12.5] },
instep: { label: "Instep", short: "I", unit: "cm", domain: [6, 11.5] },
heel: { label: "Heel", short: "H", unit: "cm", domain: [5.5, 9.5] }
};
const customers = [
{
id: "mira",
name: "Mira Chen",
initials: "MC",
role: "Urban commuter · neutral stride",
note: "Long walks, balanced forefoot",
tags: ["Neutral gait", "Roomy toe", "All-day use"],
color: "#c7654b",
background: "#ead8cf",
bounds: {
length: [26.5, 28.1],
width: [8.8, 10.4],
instep: [7.9, 9.8],
heel: [6.8, 8.1]
}
},
{
id: "eli",
name: "Eli Torres",
initials: "ET",
role: "Short-distance runner · light profile",
note: "Narrow heel, flexible midfoot",
tags: ["Light gait", "Narrow fit", "Training"],
color: "#5a7199",
background: "#dbe2eb",
bounds: {
length: [25.9, 27.5],
width: [8.1, 9.5],
instep: [6.8, 8.5],
heel: [6.2, 7.6]
}
},
{
id: "noor",
name: "Noor Mensah",
initials: "NM",
role: "Studio artist · wide stance",
note: "Wide forefoot and high instep",
tags: ["Wide stance", "High instep", "Stable base"],
color: "#347e70",
background: "#d8e7e2",
bounds: {
length: [27.3, 29.0],
width: [10.3, 11.9],
instep: [9.1, 10.8],
heel: [7.3, 8.7]
}
},
{
id: "jules",
name: "Jules Martin",
initials: "JM",
role: "Weekend hiker · orthotic profile",
note: "Secure heel with generous volume",
tags: ["Orthotic", "Secure heel", "Long stride"],
color: "#80639a",
background: "#e4ddea",
bounds: {
length: [26.3, 28.3],
width: [9.3, 10.8],
instep: [8.8, 10.4],
heel: [7.6, 8.9]
}
}
];
const inventory = [
{ id: "s01", sku: "F-01", name: "Arc 01", profile: "Compact / narrow", dims: { length: 25.6, width: 8.2, instep: 7.0, heel: 6.1 } },
{ id: "s02", sku: "F-02", name: "Arc 02", profile: "Compact / flexible", dims: { length: 26.0, width: 8.5, instep: 7.4, heel: 6.5 } },
{ id: "s03", sku: "F-03", name: "Arc 03", profile: "Low / neutral", dims: { length: 26.4, width: 8.9, instep: 7.2, heel: 6.8 } },
{ id: "s04", sku: "F-04", name: "Arc 04", profile: "Low / balanced", dims: { length: 26.8, width: 9.2, instep: 7.8, heel: 7.0 } },
{ id: "s05", sku: "F-05", name: "Arc 05", profile: "Standard / balanced", dims: { length: 27.2, width: 9.6, instep: 8.2, heel: 7.4 } },
{ id: "s06", sku: "F-06", name: "Arc 06", profile: "Standard / roomy", dims: { length: 27.6, width: 10.0, instep: 8.6, heel: 7.8 } },
{ id: "s07", sku: "F-07", name: "Arc 07", profile: "Long / broad", dims: { length: 28.0, width: 10.4, instep: 9.0, heel: 8.2 } },
{ id: "s08", sku: "F-08", name: "Arc 08", profile: "Long / wide", dims: { length: 28.4, width: 10.8, instep: 9.5, heel: 8.6 } },
{ id: "s09", sku: "F-09", name: "Arc 09", profile: "Short / high instep", dims: { length: 26.2, width: 9.8, instep: 9.0, heel: 7.1 } },
{ id: "s10", sku: "F-10", name: "Arc 10", profile: "Balanced / high instep", dims: { length: 27.0, width: 9.3, instep: 9.4, heel: 7.7 } },
{ id: "s11", sku: "F-11", name: "Arc 11", profile: "Wide / high volume", dims: { length: 28.2, width: 11.2, instep: 10.1, heel: 8.4 } },
{ id: "s12", sku: "F-12", name: "Arc 12", profile: "Maximum / wide", dims: { length: 29.0, width: 11.6, instep: 10.6, heel: 8.8 } }
];
const state = {
customerId: "mira",
selectedId: "s05",
active: Object.fromEntries(dimensionKeys.map((key) => [key, true])),
bounds: structuredClone(customers[0].bounds),
shortlist: new Set()
};
const els = {
constraintStack: document.querySelector("#constraint-stack"),
constraintCount: document.querySelector("#constraint-count"),
activeSummary: document.querySelector("#active-summary"),
inventoryList: document.querySelector("#inventory-list"),
inventoryCount: document.querySelector("#inventory-count"),
customerList: document.querySelector("#customer-list"),
profileName: document.querySelector("#profile-name"),
profileRole: document.querySelector("#profile-role"),
profileTags: document.querySelector("#profile-tags"),
profileVisual: document.querySelector("#profile-visual"),
selectedName: document.querySelector("#selected-name"),
selectedCode: document.querySelector("#selected-code"),
scoreRing: document.querySelector("#score-ring"),
scoreValue: document.querySelector("#score-value"),
resultStatus: document.querySelector("#result-status"),
fitVerdict: document.querySelector("#fit-verdict"),
metricList: document.querySelector("#metric-list"),
selectForm: document.querySelector("#select-form"),
shortlistCount: document.querySelector("#shortlist-count"),
sceneMatchCount: document.querySelector("#scene-match-count"),
labelLayer: document.querySelector("#label-layer"),
toast: document.querySelector("#toast"),
dialog: document.querySelector("#shortlist-dialog"),
shortlistItems: document.querySelector("#shortlist-items")
};
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
function activeKeys() {
return dimensionKeys.filter((key) => state.active[key]);
}
function isCompatible(item) {
const keys = activeKeys();
if (!keys.length) return true;
return keys.every((key) => {
const value = item.dims[key];
const [min, max] = state.bounds[key];
return value >= min && value <= max;
});
}
function fitScore(item) {
const keys = activeKeys();
if (!keys.length) return 0;
let penalty = 0;
for (const key of keys) {
const [min, max] = state.bounds[key];
const value = item.dims[key];
const center = (min + max) / 2;
const half = Math.max((max - min) / 2, 0.01);
if (value < min) penalty += ((min - value) / half) * 0.9;
if (value > max) penalty += ((value - max) / half) * 0.9;
const edgeDistance = Math.min(value - min, max - value);
const edgeRatio = clamp(edgeDistance / half, 0, 1);
penalty += (1 - edgeRatio) * 0.12;
}
return clamp(Math.round(100 - penalty / keys.length), 0, 100);
}
function currentCustomer() {
return customers.find((customer) => customer.id === state.customerId);
}
function currentItem() {
return inventory.find((item) => item.id === state.selectedId);
}
function compatibleItems() {
return inventory.filter(isCompatible);
}
function renderConstraints() {
els.constraintStack.innerHTML = dimensionKeys.map((key) => {
const meta = dimensionMeta[key];
const [min, max] = state.bounds[key];
return `
<div class="constraint ${state.active[key] ? "" : "inactive"}" data-constraint="${key}">
<div class="constraint-head">
<input
type="checkbox"
data-toggle="${key}"
${state.active[key] ? "checked" : ""}
aria-label="Use ${meta.label} constraint"
/>
<span class="constraint-name">${meta.label}</span>
<span class="constraint-unit">${meta.unit}</span>
</div>
<div class="range-inputs">
<input
type="number"
step="0.1"
data-bound="${key}"
data-side="min"
value="${min}"
aria-label="Minimum ${meta.label}"
/>
<span class="range-divider">—</span>
<input
type="number"
step="0.1"
data-bound="${key}"
data-side="max"
value="${max}"
aria-label="Maximum ${meta.label}"
/>
</div>
</div>
`;
}).join("");
const count = activeKeys().length;
els.constraintCount.textContent = `${count} active`;
els.activeSummary.textContent = count
? `${count} dimension${count === 1 ? "" : "s"} combined`
: "No dimensions active";
}
function renderCustomers() {
els.customerList.innerHTML = customers.map((customer) => `
<button class="customer-card ${customer.id === state.customerId ? "active" : ""}" data-customer="${customer.id}">
<span class="customer-avatar" style="--avatar:${customer.color}">${customer.initials}</span>
<span>
<span class="customer-name">${customer.name}</span>
<span class="customer-note">${customer.note}</span>
</span>
<span class="customer-check">✓</span>
</button>
`).join("");
const customer = currentCustomer();
els.profileName.textContent = customer.name;
els.profileRole.textContent = customer.role;
els.profileTags.innerHTML = customer.tags.map((tag) => `<span class="tag">${tag}</span>`).join("");
els.profileVisual.style.setProperty("--profile-bg", customer.background);
els.profileVisual.style.color = customer.color;
}
function renderInventory() {
const matches = compatibleItems();
els.inventoryList.innerHTML = inventory.map((item) => {
const compatible = isCompatible(item);
const score = fitScore(item);
return `
<button
class="stock-row ${item.id === state.selectedId ? "selected" : ""} ${compatible ? "" : "incompatible"}"
data-stock="${item.id}"
>
<span class="stock-code">${item.sku.slice(2)}</span>
<span>
<span class="stock-name">${item.name}</span>
<span class="stock-meta">L ${item.dims.length.toFixed(1)} · W ${item.dims.width.toFixed(1)} · I ${item.dims.instep.toFixed(1)} · H ${item.dims.heel.toFixed(1)}</span>
</span>
<span class="fit-badge ${compatible ? "" : "fail"}">${compatible ? `${score}%` : "OUT"}</span>
</button>
`;
}).join("");
els.inventoryCount.textContent = `${matches.length} / ${inventory.length} match`;
els.sceneMatchCount.textContent = matches.length;
}
function renderMetrics(item) {
els.metricList.innerHTML = dimensionKeys.map((key) => {
const meta = dimensionMeta[key];
const value = item.dims[key];
const [min, max] = state.bounds[key];
const [domainMin, domainMax] = meta.domain;
const domainSize = domainMax - domainMin;
const safeLeft = clamp(((min - domainMin) / domainSize) * 100, 0, 100);
const safeWidth = clamp(((max - min) / domainSize) * 100, 0, 100);
const dotLeft = clamp(((value - domainMin) / domainSize) * 100, 0, 100);
const within = value >= min && value <= max;
const statusClass = !state.active[key] ? "" : within ? "good" : "bad";
return `
<div class="metric ${state.active[key] ? "" : "metric-inactive"}">
<div class="metric-head">
<span class="metric-name">${meta.label}</span>
<span class="metric-value ${statusClass}">${value.toFixed(1)} cm · target ${min.toFixed(1)}–${max.toFixed(1)}</span>
</div>
<div class="metric-track">
<span class="metric-safe" style="left:${safeLeft}%;width:${safeWidth}%"></span>
<span class="metric-dot ${within ? "" : "bad"}" style="left:${dotLeft}%"></span>
</div>
</div>
`;
}).join("");
}
function renderSelection() {
const item = currentItem();
const compatible = isCompatible(item);
const score = fitScore(item);
const keys = activeKeys();
els.selectedName.textContent = item.name;
els.selectedCode.textContent = `${item.sku} · ${item.profile}`;
els.scoreValue.textContent = score;
els.scoreRing.style.setProperty("--score", score);
els.scoreRing.style.setProperty(
"--score-color",
compatible ? "var(--green)" : "var(--red)"
);
els.resultStatus.textContent = compatible ? "Compatible" : "Outside bounds";
els.resultStatus.style.color = compatible ? "var(--green)" : "var(--red)";
els.fitVerdict.classList.toggle("fail", !compatible);
els.fitVerdict.textContent = !keys.length
? "Enable at least one dimension to evaluate compatibility."
: compatible
? score >= 94
? "Excellent overlap with comfortable margin at every active edge."
: "Compatible across all active dimensions; check the closest fit boundary."
: `Outside the current envelope in ${keys.filter((key) => {
const value = item.dims[key];
const [min, max] = state.bounds[key];
return value < min || value > max;
}).join(", ")}.`;
renderMetrics(item);
const shortlisted = state.shortlist.has(item.id);
els.selectForm.disabled = !compatible || !keys.length;
els.selectForm.classList.toggle("chosen", shortlisted);
els.selectForm.textContent = !compatible
? "Outside current fit bounds"
: shortlisted
? "✓ Remove from selection"
: "+ Add compatible form";
els.shortlistCount.textContent = `${state.shortlist.size} form${state.shortlist.size === 1 ? "" : "s"}`;
}
function updateAll() {
renderConstraints();
renderCustomers();
renderInventory();
renderSelection();
updateSceneStatus();
}
function chooseCustomer(id) {
const customer = customers.find((entry) => entry.id === id);
if (!customer) return;
state.customerId = id;
state.bounds = structuredClone(customer.bounds);
state.active = Object.fromEntries(dimensionKeys.map((key) => [key, true]));
const best = compatibleItems().sort((a, b) => fitScore(b) - fitScore(a))[0];
if (best) state.selectedId = best.id;
updateAll();
}
function chooseStock(id) {
if (!inventory.some((item) => item.id === id)) return;
state.selectedId = id;
renderInventory();
renderSelection();
updateSceneStatus();
}
function resetBounds() {
state.bounds = structuredClone(currentCustomer().bounds);
state.active = Object.fromEntries(dimensionKeys.map((key) => [key, true]));
updateAll();
}
function showToast(message) {
els.toast.textContent = message;
els.toast.classList.add("show");
clearTimeout(showToast.timer);
showToast.timer = setTimeout(() => els.toast.classList.remove("show"), 2400);
}
function renderShortlist() {
const items = inventory.filter((item) => state.shortlist.has(item.id));
if (!items.length) {
els.shortlistItems.innerHTML = `
<p style="margin:10px 0 4px;color:#6f7772;font-size:12px;line-height:1.6">
No forms yet. Add compatible forms from the match panel.
</p>
`;
return;
}
els.shortlistItems.innerHTML = items.map((item) => `
<div class="shortlist-row">
<div>
<strong>${item.name} · ${item.sku}</strong>
<small>${item.profile} · fit ${fitScore(item)}%</small>
</div>
<span class="fit-badge">${fitScore(item)}%</span>
<button class="remove-button" data-remove="${item.id}">Remove</button>
</div>
`).join("");
}
els.constraintStack.addEventListener("change", (event) => {
const toggle = event.target.closest("[data-toggle]");
if (toggle) {
state.active[toggle.dataset.toggle] = toggle.checked;
updateAll();
return;
}
const bound = event.target.closest("[data-bound]");
if (bound) {
const key = bound.dataset.bound;
const side = bound.dataset.side;
const value = Number.parseFloat(bound.value);
if (!Number.isFinite(value)) return;
const [min, max] = state.bounds[key];
state.bounds[key][side === "min" ? 0 : 1] = value;
if (state.bounds[key][0] > state.bounds[key][1]) {
state.bounds[key] = [value, value];
}
updateAll();
}
});
els.inventoryList.addEventListener("click", (event) => {
const button = event.target.closest("[data-stock]");
if (button) chooseStock(button.dataset.stock);
});
els.customerList.addEventListener("click", (event) => {
const button = event.target.closest("[data-customer]");
if (button) chooseCustomer(button.dataset.customer);
});
document.querySelector("#reset-bounds").addEventListener("click", resetBounds);
document.querySelector("#reset-all").addEventListener("click", () => {
state.shortlist.clear();
chooseCustomer("mira");
resetCamera();
showToast("Lab reset to the default customer and constraints.");
});
els.selectForm.addEventListener("click", () => {
const item = currentItem();
if (!isCompatible(item) || !activeKeys().length) return;
if (state.shortlist.has(item.id)) {
state.shortlist.delete(item.id);
showToast(`${item.name} removed from the selection.`);
} else {
state.shortlist.add(item.id);
showToast(`${item.name} added to the selection.`);
}
renderSelection();
renderShortlist();
});
document.querySelector("#review-shortlist").addEventListener("click", () => {
renderShortlist();
els.dialog.showModal();
});
document.querySelector("#close-dialog").addEventListener("click", () => els.dialog.close());
document.querySelector("#clear-shortlist").addEventListener("click", () => {
state.shortlist.clear();
renderShortlist();
renderSelection();
});
els.shortlistItems.addEventListener("click", (event) => {
const button = event.target.closest("[data-remove]");
if (!button) return;
state.shortlist.delete(button.dataset.remove);
renderShortlist();
renderSelection();
});
document.querySelector("#confirm-shortlist").addEventListener("click", () => {
els.dialog.close();
showToast(`${state.shortlist.size} compatible form${state.shortlist.size === 1 ? "" : "s"} locked for allocation.`);
});
// ------------------------------------------------------------
// Three.js scene
// ------------------------------------------------------------
const host = document.querySelector("#scene-host");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e8e0);
scene.fog = new THREE.Fog(0xe9e8e0, 17, 34);
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 80);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive low-poly shoe form inventory");
host.appendChild(renderer.domElement);
const ambient = new THREE.HemisphereLight(0xfffbef, 0x829087, 2.3);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xfff7df, 3.1);
keyLight.position.set(-6, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xb9d2ca, 1.1);
rimLight.position.set(8, 6, -8);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
new THREE.MeshStandardMaterial({
color: 0xe5e4dc,
roughness: 0.96,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0xc9cbc3, 0xd6d6ce);
grid.position.y = -0.012;
grid.material.transparent = true;
grid.material.opacity = 0.55;
scene.add(grid);
const pickMeshes = [];
const itemVisuals = new Map();
function makeSoleGeometry() {
const shape = new THREE.Shape();
shape.moveTo(-0.72, -0.18);
shape.lineTo(-0.70, -0.25);
shape.lineTo(0.52, -0.23);
shape.quadraticCurveTo(0.73, -0.21, 0.80, -0.08);
shape.quadraticCurveTo(0.86, 0, 0.80, 0.08);
shape.quadraticCurveTo(0.73, 0.21, 0.52, 0.23);
shape.lineTo(-0.70, 0.25);
shape.lineTo(-0.72, 0.18);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.13,
bevelEnabled: true,
bevelSize: 0.025,
bevelThickness: 0.018,
bevelSegments: 1,
steps: 1
});
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
return geometry;
}
const soleGeometry = makeSoleGeometry();
function createShoe(item) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x4f796b,
roughness: 0.78,
metalness: 0.02,
flatShading: true
});
const soleMaterial = new THREE.MeshStandardMaterial({
color: 0x333a37,
roughness: 0.92,
flatShading: true
});
const detailMaterial = new THREE.MeshStandardMaterial({
color: 0xece9dc,
roughness: 0.86,
flatShading: true
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: 0xefc45f,
roughness: 0.72,
flatShading: true
});
const sole = new THREE.Mesh(soleGeometry, soleMaterial);
sole.position.y = 0.12;
sole.castShadow = true;
sole.receiveShadow = true;
group.add(sole);
const toe = new THREE.Mesh(new THREE.DodecahedronGeometry(1, 0), bodyMaterial);
toe.scale.set(0.57, 0.28, 0.35);
toe.position.set(0.19, 0.31, 0);
toe.rotation.z = -0.06;
toe.castShadow = true;
group.add(toe);
const vamp = new THREE.Mesh(new THREE.DodecahedronGeometry(1, 0), bodyMaterial);
vamp.scale.set(0.42, 0.30, 0.30);
vamp.position.set(-0.22, 0.34, 0);
vamp.castShadow = true;
group.add(vamp);
const heel = new THREE.Mesh(new THREE.DodecahedronGeometry(1, 0), bodyMaterial);
heel.scale.set(0.24, 0.34, 0.27);
heel.position.set(-0.56, 0.35, 0);
heel.castShadow = true;
group.add(heel);
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.17, 0.052, 5, 12),
bodyMaterial
);
collar.rotation.x = Math.PI / 2;
collar.position.set(-0.43, 0.53, 0);
collar.scale.set(1.05, 1.05, 0.8);
collar.castShadow = true;
group.add(collar);
const tongue = new THREE.Mesh(
new THREE.BoxGeometry(0.36, 0.055, 0.22),
detailMaterial
);
tongue.position.set(0.02, 0.53, 0);
tongue.rotation.z = -0.12;
tongue.castShadow = true;
group.add(tongue);
for (let i = 0; i < 3; i++) {
const lace = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.025, 0.36 - i * 0.025),
accentMaterial
);
lace.position.set(-0.05 + i * 0.095, 0.565 - i * 0.012, 0);
lace.rotation.z = -0.08;
group.add(lace);
}
const sideMark = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 0.035, 0.022),
accentMaterial
);
sideMark.position.set(-0.05, 0.34, 0.315);
sideMark.rotation.z = -0.18;
group.add(sideMark);
group.traverse((child) => {
if (child.isMesh) {
child.userData.stockId = item.id;
pickMeshes.push(child);
}
});
return {
group,
bodyMaterial,
accentMaterial
};
}
const positions = [];
const rowZ = [1.8, 0, -1.8, -3.6];
const columnX = [-2.5, 0, 2.5];
inventory.forEach((item, index) => {
const row = Math.floor(index / 3);
const column = index % 3;
const position = new THREE.Vector3(columnX[column], 0, rowZ[row]);
positions.push(position);
const root = new THREE.Group();
root.position.copy(position);
scene.add(root);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0xd1d2ca,
roughness: 0.92,
metalness: 0
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.74, 0.81, 0.12, 32),
baseMaterial
);
base.position.y = 0.06;
base.receiveShadow = true;
base.castShadow = true;
base.userData.stockId = item.id;
pickMeshes.push(base);
root.add(base);
const shoe = createShoe(item);
root.add(shoe.group);
const compatibleRing = new THREE.Mesh(
new THREE.TorusGeometry(0.77, 0.025, 5, 36),
new THREE.MeshBasicMaterial({
color: 0x4f8a75,
transparent: true,
opacity: 0.85,
depthWrite: false
})
);
compatibleRing.rotation.x = Math.PI / 2;
compatibleRing.position.y = 0.135;
root.add(compatibleRing);
const selectedRing = new THREE.Mesh(
new THREE.TorusGeometry(0.82, 0.035, 5, 36),
new THREE.MeshBasicMaterial({
color: 0xefc45f,
transparent: true,
opacity: 0.98,
depthTest: false,
depthWrite: false
})
);
selectedRing.rotation.x = Math.PI / 2;
selectedRing.position.y = 0.145;
selectedRing.renderOrder = 5;
root.add(selectedRing);
const lineGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.93, 0.16, 0),
new THREE.Vector3(0.93, 0.16, 0),
new THREE.Vector3(-0.93, 0.16, -0.11),
new THREE.Vector3(-0.93, 0.16, 0.11),
new THREE.Vector3(0.93, 0.16, -0.11),
new THREE.Vector3(0.93, 0.16, 0.11)
]);
const measurementLine = new THREE.LineSegments(
lineGeometry,
new THREE.LineBasicMaterial({
color: 0xefc45f,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
measurementLine.renderOrder = 6;
root.add(measurementLine);
const label = document.createElement("button");
label.className = "scene-label";
label.dataset.labelStock = item.id;
label.innerHTML = `<span class="label-dot"></span>${item.sku}`;
label.addEventListener("click", (event) => {
event.stopPropagation();
chooseStock(item.id);
});
els.labelLayer.appendChild(label);
itemVisuals.set(item.id, {
root,
base,
baseMaterial,
shoe,
compatibleRing,
selectedRing,
measurementLine,
label
});
});
const green = new THREE.Color(0x4f796b);
const muted = new THREE.Color(0xa5aaa3);
const coral = new THREE.Color(0xd96f50);
function updateSceneStatus() {
for (const item of inventory) {
const visual = itemVisuals.get(item.id);
const compatible = isCompatible(item);
const selected = item.id === state.selectedId;
visual.shoe.bodyMaterial.color.copy(
selected ? coral : compatible ? green : muted
);
visual.shoe.accentMaterial.color.set(
selected ? 0xffd777 : compatible ? 0xefc45f : 0xb8bbb4
);
visual.compatibleRing.visible = compatible && !selected;
visual.selectedRing.visible = selected;
visual.selectedRing.material.color.set(
compatible ? 0xefc45f : 0xbf5c4f
);
visual.measurementLine.visible = selected;
visual.measurementLine.material.color.set(
compatible ? 0xefc45f : 0xbf5c4f
);
visual.baseMaterial.color.set(selected ? 0xbfc2b8 : 0xd1d2ca);
visual.base.scale.setScalar(selected ? 1.05 : 1);
visual.label.classList.toggle("selected", selected);
visual.label.classList.toggle("incompatible", !compatible);
}
}
// Camera controls implemented directly without external controls modules.
const defaultTarget = new THREE.Vector3(0, 0.55, -0.85);
const view = {
target: defaultTarget.clone(),
targetGoal: defaultTarget.clone(),
radius: 14.8,
radiusGoal: 14.8,
theta: 0.18,
thetaGoal: 0.18,
phi: 0.78,
phiGoal: 0.78
};
function resetCamera() {
view.targetGoal.copy(defaultTarget);
view.radiusGoal = 14.8;
view.thetaGoal = 0.18;
view.phiGoal = 0.78;
}
function focusSelected() {
const item = currentItem();
const index = inventory.findIndex((entry) => entry.id === item.id);
if (index < 0) return;
view.targetGoal.copy(positions[index]);
view.targetGoal.y = 0.45;
view.radiusGoal = 7.8;
view.thetaGoal = 0.42;
view.phiGoal = 0.92;
}
document.querySelector("#reset-view").addEventListener("click", resetCamera);
document.querySelector("#focus-selected").addEventListener("click", focusSelected);
let dragging = false;
let panMode = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
let travel = 0;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
panMode = event.shiftKey || event.button === 2;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
travel = 0;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
travel += Math.abs(dx) + Math.abs(dy);
if (panMode || event.shiftKey) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3(0, 0, -1).applyQuaternion(camera.quaternion);
forward.y = 0;
forward.normalize();
const scale = view.radius * 0.0012;
view.target.addScaledVector(right, -dx * scale);
view.target.addScaledVector(forward, -dy * scale);
view.targetGoal.copy(view.target);
} else {
view.theta -= dx * 0.006;
view.phi = clamp(view.phi - dy * 0.005, 0.38, 1.32);
view.thetaGoal = view.theta;
view.phiGoal = view.phi;
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
dragging = false;
if (travel < 5 && event.button === 0) selectAt(event.clientX, event.clientY);
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radiusGoal = clamp(
view.radiusGoal * Math.exp(event.deltaY * 0.001),
6.5,
22
);
},
{ passive: false }
);
function selectAt(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 hit = raycaster.intersectObjects(pickMeshes, false)[0];
if (hit?.object.userData.stockId) {
chooseStock(hit.object.userData.stockId);
}
}
function resize() {
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(resize);
resizeObserver.observe(host);
resize();
const projected = new THREE.Vector3();
function updateLabels() {
const width = host.clientWidth;
const height = host.clientHeight;
for (const item of inventory) {
const visual = itemVisuals.get(item.id);
projected.set(
visual.root.position.x,
0.96,
visual.root.position.z
).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
visual.label.style.display = visible ? "flex" : "none";
if (!visible) continue;
visual.label.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
visual.label.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
function animate() {
requestAnimationFrame(animate);
const ease = 0.09;
view.target.lerp(view.targetGoal, ease);
view.radius += (view.radiusGoal - view.radius) * ease;
view.theta += (view.thetaGoal - view.theta) * ease;
view.phi += (view.phiGoal - view.phi) * ease;
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
renderer.render(scene, camera);
updateLabels();
}
updateAll();
animate();
</script>
</body>
</html>
```