Prompt specification
Build or customize the Three.js 3D scene "Adaptive storefront design challenge" 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: Adaptive storefront design challenge
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/adaptive-storefront-design-challenge-x0544
Scene Description Prompt:
A low-poly storefront redesign game: rearrange fixtures for different businesses inside one shell with fixed structure and service connections. One HTML file, Three.js from cdnjs.
Working Three.js Starter (adaptive-storefront-design-challenge-x0544):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Retail Fit — Storefront Lab</title>
<style>
:root {
--ink: #252722;
--muted: #77796f;
--paper: #f8f5ee;
--panel: #fffdf8;
--line: #ddd8cc;
--accent: #d76f45;
--accent-soft: #f4ded2;
--good: #44866a;
--bad: #bb5b51;
--power: #e6a441;
--water: #4a9db6;
--shadow: 0 14px 40px rgba(47, 43, 34, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #ded9cf;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
select {
font: inherit;
}
button {
color: inherit;
}
#app {
width: 100%;
height: 100%;
display: grid;
grid-template-rows: 70px minmax(0, 1fr);
}
header {
position: relative;
z-index: 20;
display: flex;
align-items: center;
gap: 18px;
padding: 0 20px;
background: var(--panel);
border-bottom: 1px solid var(--line);
box-shadow: 0 3px 16px rgba(47, 43, 34, 0.05);
}
.brand {
display: flex;
align-items: center;
gap: 11px;
min-width: 210px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
flex: 0 0 auto;
border-radius: 11px;
background: var(--ink);
overflow: hidden;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--paper);
}
.brand-mark::before {
width: 18px;
height: 18px;
left: 6px;
bottom: 6px;
border-radius: 3px 3px 1px 1px;
}
.brand-mark::after {
width: 10px;
height: 10px;
right: 5px;
top: 6px;
border-radius: 2px;
background: var(--accent);
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1;
letter-spacing: -0.04em;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.tenant-control {
display: flex;
align-items: center;
gap: 9px;
padding-left: 18px;
border-left: 1px solid var(--line);
}
.tenant-control label {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#tenantSelect {
min-width: 190px;
height: 38px;
padding: 0 34px 0 12px;
border: 1px solid var(--line);
border-radius: 10px;
outline: 0;
color: var(--ink);
background: #f5f1e8;
font-weight: 750;
cursor: pointer;
}
.header-spacer {
flex: 1;
}
.header-actions {
display: flex;
align-items: center;
gap: 8px;
}
.button {
height: 38px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 10px;
background: #f7f3eb;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease,
border-color 120ms ease;
}
.button:hover:not(:disabled) {
transform: translateY(-1px);
border-color: #bbb4a7;
background: #fffaf0;
}
.button:active:not(:disabled) {
transform: translateY(0);
}
.button:disabled {
opacity: 0.42;
cursor: not-allowed;
}
.button.primary {
color: white;
border-color: var(--accent);
background: var(--accent);
box-shadow: 0 5px 15px color-mix(in srgb, var(--accent) 28%, transparent);
}
.button.primary:hover {
background: color-mix(in srgb, var(--accent) 88%, #5b2515);
}
.button.icon-only {
width: 38px;
padding: 0;
font-size: 17px;
}
main {
position: relative;
min-height: 0;
display: grid;
grid-template-columns: 292px minmax(0, 1fr) 270px;
}
aside {
position: relative;
z-index: 10;
min-height: 0;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: #c9c2b6 transparent;
background: var(--panel);
}
.left-panel {
border-right: 1px solid var(--line);
}
.right-panel {
border-left: 1px solid var(--line);
}
.section {
padding: 18px;
border-bottom: 1px solid var(--line);
}
.section:last-child {
border-bottom: 0;
}
.eyebrow {
margin: 0 0 7px;
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.section h2,
.section h3 {
margin: 0;
letter-spacing: -0.03em;
}
.section h2 {
font-size: 20px;
}
.section h3 {
font-size: 14px;
}
.brief-card {
position: relative;
overflow: hidden;
border-radius: 15px;
padding: 17px;
color: #fffaf0;
background:
radial-gradient(circle at 85% 0%, rgba(255, 255, 255, 0.19), transparent 38%),
var(--ink);
}
.brief-card::after {
content: "";
position: absolute;
right: -24px;
bottom: -30px;
width: 100px;
height: 100px;
border: 18px solid var(--accent);
border-radius: 50%;
opacity: 0.8;
}
.brief-card .eyebrow {
color: rgba(255, 250, 240, 0.62);
}
.brief-card h2 {
position: relative;
z-index: 1;
margin-bottom: 8px;
font-size: 22px;
}
.brief-card p {
position: relative;
z-index: 1;
margin: 0;
color: rgba(255, 250, 240, 0.74);
font-size: 12px;
line-height: 1.55;
}
.brief-tags {
position: relative;
z-index: 1;
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 15px;
}
.brief-tag {
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 99px;
background: rgba(255, 255, 255, 0.08);
font-size: 9px;
font-weight: 800;
}
.catalog-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.catalog-heading .eyebrow {
margin: 0;
}
.catalog-count {
padding: 4px 7px;
border-radius: 99px;
color: var(--muted);
background: #eee9de;
font-size: 9px;
font-weight: 850;
}
#catalog {
display: grid;
gap: 8px;
}
.fixture-card {
position: relative;
display: grid;
grid-template-columns: 38px 1fr auto;
align-items: center;
gap: 10px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 12px;
background: #fbf8f1;
cursor: pointer;
transition:
border-color 120ms ease,
background 120ms ease,
transform 120ms ease;
}
.fixture-card:hover {
transform: translateY(-1px);
border-color: #bfb7a9;
background: white;
}
.fixture-card.active {
border-color: var(--accent);
background: var(--accent-soft);
box-shadow: inset 0 0 0 1px var(--accent);
}
.fixture-icon {
display: grid;
place-items: center;
width: 38px;
height: 38px;
border-radius: 10px;
background: #ece6d9;
font-size: 19px;
}
.fixture-copy {
min-width: 0;
}
.fixture-name {
display: block;
overflow: hidden;
font-size: 12px;
font-weight: 850;
text-overflow: ellipsis;
white-space: nowrap;
}
.fixture-meta {
display: flex;
align-items: center;
gap: 7px;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.utility-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: #aaa69d;
}
.utility-dot.power {
background: var(--power);
}
.utility-dot.water {
background: var(--water);
}
.fixture-qty {
text-align: right;
}
.fixture-qty strong {
display: block;
font-size: 13px;
}
.fixture-qty span {
color: var(--muted);
font-size: 8px;
font-weight: 800;
text-transform: uppercase;
}
.fixture-qty.complete strong {
color: var(--good);
}
.tip {
display: flex;
gap: 10px;
margin-top: 9px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.tip b {
color: var(--ink);
}
.key {
display: inline-grid;
min-width: 22px;
height: 22px;
place-items: center;
padding: 0 5px;
border: 1px solid #ccc5b8;
border-bottom-width: 2px;
border-radius: 6px;
color: var(--ink);
background: #fffdf8;
font-size: 9px;
font-weight: 850;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #d8d4cb;
}
#stage canvas {
position: absolute;
inset: 0;
z-index: 0;
display: block;
outline: none;
}
.stage-top {
position: absolute;
z-index: 4;
top: 14px;
left: 14px;
right: 14px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.mode-pill,
.stage-legend {
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 12px;
background: rgba(255, 253, 248, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.mode-pill {
display: flex;
align-items: center;
gap: 8px;
min-height: 38px;
padding: 0 12px;
font-size: 11px;
font-weight: 800;
}
.mode-pill::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 17%, transparent);
}
.stage-legend {
display: flex;
gap: 11px;
padding: 10px 12px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
}
.legend-swatch {
width: 9px;
height: 9px;
border-radius: 3px;
}
.legend-swatch.power {
background: var(--power);
}
.legend-swatch.water {
background: var(--water);
}
.legend-swatch.clear {
border: 1px dashed #58a99b;
background: rgba(88, 169, 155, 0.18);
}
.stage-tools {
position: absolute;
z-index: 4;
left: 50%;
bottom: 17px;
display: flex;
align-items: center;
gap: 5px;
padding: 6px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 14px;
background: rgba(255, 253, 248, 0.92);
box-shadow: var(--shadow);
transform: translateX(-50%);
backdrop-filter: blur(12px);
}
.tool-button {
display: flex;
align-items: center;
gap: 6px;
height: 34px;
padding: 0 10px;
border: 0;
border-radius: 9px;
background: transparent;
font-size: 10px;
font-weight: 850;
cursor: pointer;
}
.tool-button:hover:not(:disabled) {
background: #eee8dc;
}
.tool-button:disabled {
opacity: 0.35;
cursor: not-allowed;
}
.tool-divider {
width: 1px;
height: 22px;
margin: 0 2px;
background: var(--line);
}
.camera-help {
position: absolute;
z-index: 3;
right: 14px;
bottom: 16px;
max-width: 190px;
padding: 8px 10px;
border-radius: 10px;
color: rgba(37, 39, 34, 0.7);
background: rgba(255, 253, 248, 0.72);
font-size: 9px;
font-weight: 750;
line-height: 1.5;
text-align: right;
pointer-events: none;
backdrop-filter: blur(7px);
}
.world-label {
position: absolute;
z-index: 2;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 8px;
color: white;
box-shadow: 0 5px 15px rgba(40, 35, 25, 0.15);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.06em;
pointer-events: none;
transform: translate(-50%, -50%);
}
.world-label.power {
background: var(--power);
}
.world-label.water {
background: var(--water);
}
.world-label.entry {
color: #376e64;
background: rgba(245, 255, 250, 0.92);
}
.score-card {
display: flex;
align-items: center;
gap: 13px;
}
.score-ring {
--score: 0%;
position: relative;
display: grid;
width: 68px;
height: 68px;
flex: 0 0 auto;
place-items: center;
border-radius: 50%;
background: conic-gradient(var(--good) var(--score), #e7e2d7 0);
}
.score-ring::before {
content: "";
position: absolute;
inset: 6px;
border-radius: 50%;
background: var(--panel);
}
.score-ring strong {
position: relative;
z-index: 1;
font-size: 17px;
}
.score-copy h3 {
margin-bottom: 5px;
}
.score-copy p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.budget-row {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-top: 12px;
}
.budget-row span {
color: var(--muted);
font-size: 10px;
font-weight: 750;
}
.budget-row strong {
font-size: 13px;
}
.budget-bar {
height: 6px;
margin-top: 7px;
border-radius: 99px;
overflow: hidden;
background: #e8e2d6;
}
.budget-bar i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--accent);
transition: width 180ms ease;
}
.objective-list {
display: grid;
gap: 7px;
margin-top: 12px;
}
.objective {
display: grid;
grid-template-columns: 21px 1fr auto;
align-items: center;
gap: 7px;
padding: 8px;
border-radius: 9px;
background: #f3eee4;
}
.objective-icon {
display: grid;
width: 21px;
height: 21px;
place-items: center;
border-radius: 7px;
color: var(--bad);
background: rgba(187, 91, 81, 0.11);
font-size: 10px;
font-weight: 900;
}
.objective.pass .objective-icon {
color: var(--good);
background: rgba(68, 134, 106, 0.13);
}
.objective-text {
min-width: 0;
}
.objective-text strong {
display: block;
overflow: hidden;
font-size: 10px;
text-overflow: ellipsis;
white-space: nowrap;
}
.objective-text span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
}
.objective-status {
color: var(--muted);
font-size: 9px;
font-weight: 850;
}
.objective.pass .objective-status {
color: var(--good);
}
.service-row {
display: flex;
align-items: flex-start;
gap: 10px;
margin-top: 12px;
}
.service-icon {
display: grid;
width: 32px;
height: 32px;
flex: 0 0 auto;
place-items: center;
border-radius: 9px;
color: white;
font-size: 15px;
}
.service-icon.power {
background: var(--power);
}
.service-icon.water {
background: var(--water);
}
.service-row strong {
display: block;
font-size: 11px;
}
.service-row p {
margin: 3px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.shell-lock {
display: flex;
align-items: center;
gap: 9px;
padding: 11px;
border: 1px dashed #bbb4a6;
border-radius: 11px;
color: var(--muted);
background: #f5f0e7;
font-size: 10px;
font-weight: 750;
line-height: 1.4;
}
#toast {
position: absolute;
z-index: 30;
left: 50%;
bottom: 78px;
max-width: 360px;
padding: 10px 14px;
border-radius: 10px;
color: white;
background: rgba(37, 39, 34, 0.94);
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 750;
opacity: 0;
transform: translate(-50%, 8px);
transition:
opacity 160ms ease,
transform 160ms ease;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#modal {
position: fixed;
z-index: 100;
inset: 0;
display: none;
place-items: center;
padding: 20px;
background: rgba(31, 31, 27, 0.46);
backdrop-filter: blur(7px);
}
#modal.open {
display: grid;
}
.modal-card {
width: min(470px, 100%);
max-height: 90vh;
overflow: auto;
padding: 26px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 20px;
background: var(--panel);
box-shadow: 0 30px 80px rgba(25, 24, 20, 0.3);
animation: modal-in 220ms ease both;
}
@keyframes modal-in {
from {
opacity: 0;
transform: translateY(12px) scale(0.98);
}
to {
opacity: 1;
transform: none;
}
}
.modal-hero {
display: flex;
align-items: center;
gap: 15px;
margin-bottom: 18px;
}
.modal-icon {
display: grid;
width: 58px;
height: 58px;
flex: 0 0 auto;
place-items: center;
border-radius: 17px;
color: white;
background: var(--accent);
font-size: 27px;
}
#modal.success .modal-icon {
background: var(--good);
}
.modal-hero h2 {
margin: 0 0 5px;
font-size: 23px;
letter-spacing: -0.04em;
}
.modal-hero p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.review-list {
display: grid;
gap: 7px;
margin: 18px 0;
}
.review-row {
display: grid;
grid-template-columns: 24px 1fr auto;
align-items: center;
gap: 9px;
padding: 10px;
border-radius: 10px;
background: #f1ece2;
font-size: 11px;
}
.review-row i {
display: grid;
width: 24px;
height: 24px;
place-items: center;
border-radius: 7px;
color: var(--bad);
background: rgba(187, 91, 81, 0.12);
font-style: normal;
font-weight: 900;
}
.review-row.pass i {
color: var(--good);
background: rgba(68, 134, 106, 0.13);
}
.review-row strong {
display: block;
font-size: 11px;
}
.review-row span {
color: var(--muted);
font-size: 9px;
}
.modal-actions {
display: flex;
justify-content: flex-end;
gap: 8px;
margin-top: 20px;
}
@media (max-width: 1120px) {
main {
grid-template-columns: 250px minmax(0, 1fr) 238px;
}
.section {
padding: 15px;
}
.brand {
min-width: 170px;
}
.brand p,
.tenant-control label,
.camera-help {
display: none;
}
}
@media (max-width: 900px) {
main {
grid-template-columns: 235px minmax(0, 1fr);
}
.right-panel {
position: absolute;
z-index: 12;
top: 12px;
right: 12px;
bottom: 12px;
width: 235px;
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: var(--shadow);
}
.stage-top {
right: 260px;
}
.stage-legend {
display: none;
}
#undoButton {
display: none;
}
}
@media (max-width: 680px) {
#app {
grid-template-rows: 62px minmax(0, 1fr);
}
header {
gap: 9px;
padding: 0 10px;
}
.brand {
min-width: auto;
}
.brand h1 {
display: none;
}
.tenant-control {
padding-left: 9px;
}
#tenantSelect {
min-width: 145px;
}
.header-actions .button:not(.primary) {
display: none;
}
.button.primary {
padding: 0 10px;
}
main {
display: block;
}
.left-panel {
position: absolute;
z-index: 12;
top: 10px;
bottom: 10px;
left: 10px;
width: 220px;
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: var(--shadow);
}
.right-panel {
top: 10px;
width: 220px;
}
.stage-top {
right: 12px;
}
.stage-tools {
bottom: 12px;
}
.tool-button span {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Retail Fit</h1>
<p>Storefront lab</p>
</div>
</div>
<div class="tenant-control">
<label for="tenantSelect">Tenant</label>
<select id="tenantSelect">
<option value="coffee">Morning Brew Co.</option>
<option value="salon">Northside Salon</option>
<option value="books">Page & Pine Books</option>
</select>
</div>
<div class="header-spacer"></div>
<div class="header-actions">
<button class="button icon-only" id="undoButton" title="Undo">↶</button>
<button class="button" id="resetButton">Reset layout</button>
<button class="button primary" id="openButton">Open shop</button>
</div>
</header>
<main>
<aside class="left-panel">
<section class="section">
<div class="brief-card">
<p class="eyebrow">New tenant brief</p>
<h2 id="briefName">Morning Brew Co.</h2>
<p id="briefDescription"></p>
<div class="brief-tags" id="briefTags"></div>
</div>
</section>
<section class="section">
<div class="catalog-heading">
<p class="eyebrow">Fixture catalog</p>
<span class="catalog-count" id="catalogCount">0 items</span>
</div>
<div id="catalog"></div>
<div class="tip">
<span>①</span>
<span>Click a fixture, then click the floor. Drag placed fixtures to move them.</span>
</div>
</section>
<section class="section">
<p class="eyebrow">Shortcuts</p>
<div class="tip">
<span class="key">R</span>
<span>Rotate the selected fixture.</span>
</div>
<div class="tip">
<span class="key">⌫</span>
<span>Remove the selected fixture.</span>
</div>
<div class="tip">
<span class="key">esc</span>
<span>Cancel placement.</span>
</div>
</section>
</aside>
<section id="stage" aria-label="Interactive 3D storefront">
<div class="stage-top">
<div class="mode-pill" id="modePill">Select a fixture to begin</div>
<div class="stage-legend">
<span class="legend-item">
<i class="legend-swatch power"></i> Power run
</span>
<span class="legend-item">
<i class="legend-swatch water"></i> Water run
</span>
<span class="legend-item">
<i class="legend-swatch clear"></i> Keep clear
</span>
</div>
</div>
<div class="stage-tools">
<button class="tool-button" id="rotateButton" disabled>
↻ <span>Rotate</span>
</button>
<button class="tool-button" id="deleteButton" disabled>
⌫ <span>Remove</span>
</button>
<div class="tool-divider"></div>
<button class="tool-button" id="cameraButton">
⌖ <span>Reset view</span>
</button>
</div>
<div class="camera-help">
Right-drag or Shift-drag: orbit<br />
Scroll: zoom · Left-drag fixture: move
</div>
<div class="world-label power" id="powerLabel">⚡ POWER</div>
<div class="world-label water" id="waterLabel">≈ WATER</div>
<div class="world-label entry" id="entryLabel">ENTRY · KEEP CLEAR</div>
<div id="toast"></div>
</section>
<aside class="right-panel">
<section class="section">
<div class="score-card">
<div class="score-ring" id="scoreRing">
<strong id="scoreValue">0%</strong>
</div>
<div class="score-copy">
<h3>Layout readiness</h3>
<p id="scoreCopy">Start by placing the required fixtures.</p>
</div>
</div>
<div class="budget-row">
<span>Fixture budget</span>
<strong id="budgetValue">$0 / $0</strong>
</div>
<div class="budget-bar"><i id="budgetBar"></i></div>
</section>
<section class="section">
<p class="eyebrow">Open-shop checklist</p>
<h3>Today's requirements</h3>
<div class="objective-list" id="objectiveList"></div>
</section>
<section class="section">
<p class="eyebrow">Fixed connections</p>
<div class="service-row">
<div class="service-icon power">⚡</div>
<div>
<strong>Power panel</strong>
<p>Powered fixtures need a cable run of 4.75 m or less.</p>
</div>
</div>
<div class="service-row">
<div class="service-icon water">≈</div>
<div>
<strong>Water line</strong>
<p>Wet fixtures must be within the marked water-run area.</p>
</div>
</div>
</section>
<section class="section">
<div class="shell-lock">
<span>🔒</span>
<span>The shell, entrance, grid, and service connections are fixed. Only fixtures can move.</span>
</div>
</section>
</aside>
</main>
</div>
<div id="modal" role="dialog" aria-modal="true" aria-labelledby="modalTitle">
<div class="modal-card">
<div class="modal-hero">
<div class="modal-icon" id="modalIcon">!</div>
<div>
<h2 id="modalTitle">Layout review</h2>
<p id="modalSubtitle"></p>
</div>
</div>
<div class="review-list" id="reviewList"></div>
<div class="modal-actions">
<button class="button" id="closeModalButton">Keep editing</button>
<button class="button primary" id="confirmModalButton">Looks good</button>
</div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const GRID_WIDTH = 12;
const GRID_DEPTH = 8;
const UTILITY_RADIUS = 4.75;
const UTILITIES = {
power: {
point: new THREE.Vector3(4.65, 0.12, -3.5),
wall: new THREE.Vector3(4.65, 1.55, -3.91),
color: 0xe6a441,
css: "#e6a441"
},
water: {
point: new THREE.Vector3(5.35, 0.12, -3.5),
wall: new THREE.Vector3(5.35, 1.55, -3.91),
color: 0x4a9db6,
css: "#4a9db6"
}
};
const BUSINESSES = {
coffee: {
name: "Morning Brew Co.",
accent: "#d76f45",
accentHex: 0xd76f45,
description:
"A compact neighborhood coffee bar. Create a quick ordering zone, comfortable coffee spots, and an attractive pastry display.",
tags: ["Quick service", "3 seats", "Pastry display"],
budget: 3400,
fixtures: {
brewCounter: {
name: "Brew counter",
icon: "☕",
w: 2,
d: 1,
h: 1.1,
cost: 1200,
utility: ["power"],
color: 0xb96d4c,
shape: "counter"
},
cafeTable: {
name: "Cafe table",
icon: "🪑",
w: 1,
d: 1,
h: 0.9,
cost: 350,
utility: [],
color: 0x789184,
shape: "table"
},
pastryCase: {
name: "Pastry case",
icon: "🥐",
w: 2,
d: 1,
h: 1.25,
cost: 900,
utility: ["power"],
color: 0xd4a76c,
shape: "pastry"
},
queueRail: {
name: "Queue rail",
icon: "▥",
w: 2,
d: 1,
h: 0.9,
cost: 250,
utility: [],
color: 0x5e625c,
shape: "rail"
}
},
requirements: {
brewCounter: 1,
cafeTable: 3,
pastryCase: 1,
queueRail: 1
}
},
salon: {
name: "Northside Salon",
accent: "#a06483",
accentHex: 0xa06483,
description:
"A calm, modern salon. Arrange chairs around the power panel and keep the shampoo basin close to the fixed water connection.",
tags: ["2 chairs", "Wet station", "Product wall"],
budget: 3600,
fixtures: {
stylingChair: {
name: "Styling chair",
icon: "💈",
w: 1,
d: 1,
h: 1.15,
cost: 650,
utility: ["power"],
color: 0x9c6681,
shape: "chair"
},
stylingStation: {
name: "Styling station",
icon: "🪞",
w: 2,
d: 1,
h: 1.6,
cost: 1050,
utility: ["power"],
color: 0xc49aaf,
shape: "station"
},
shampooBasin: {
name: "Shampoo basin",
icon: "🚿",
w: 1,
d: 1,
h: 1.1,
cost: 850,
utility: ["water"],
color: 0x6e9ca5,
shape: "basin"
},
productShelf: {
name: "Product shelf",
icon: "🧴",
w: 1,
d: 1,
h: 1.5,
cost: 400,
utility: [],
color: 0xb88699,
shape: "shelf"
}
},
requirements: {
stylingChair: 2,
stylingStation: 1,
shampooBasin: 1,
productShelf: 1
}
},
books: {
name: "Page & Pine Books",
accent: "#4e7f70",
accentHex: 0x4e7f70,
description:
"A warm neighborhood bookshop. Fit the shelves, make room for browsing, and keep the checkout counter connected to power.",
tags: ["3 bookcases", "Reading table", "Checkout"],
budget: 3650,
fixtures: {
bookcase: {
name: "Bookcase",
icon: "📚",
w: 2,
d: 1,
h: 1.75,
cost: 650,
utility: [],
color: 0x617d6d,
shape: "bookcase"
},
checkoutDesk: {
name: "Checkout desk",
icon: "🧾",
w: 2,
d: 1,
h: 1.1,
cost: 850,
utility: ["power"],
color: 0x9a795d,
shape: "checkout"
},
readingTable: {
name: "Reading table",
icon: "📖",
w: 2,
d: 1,
h: 0.9,
cost: 550,
utility: [],
color: 0xc49b71,
shape: "reading"
},
displayPlinth: {
name: "Display plinth",
icon: "📕",
w: 1,
d: 1,
h: 1.25,
cost: 300,
utility: [],
color: 0x6c8c7b,
shape: "plinth"
}
},
requirements: {
bookcase: 3,
checkoutDesk: 1,
readingTable: 1,
displayPlinth: 1
}
}
};
const $ = (selector) => document.querySelector(selector);
const stage = $("#stage");
const tenantSelect = $("#tenantSelect");
const catalogElement = $("#catalog");
const objectiveElement = $("#objectiveList");
const modal = $("#modal");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d4cb);
scene.fog = new THREE.Fog(0xd8d4cb, 27, 48);
const camera = new THREE.PerspectiveCamera(
42,
stage.clientWidth / stage.clientHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("tabindex", "0");
stage.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff9eb, 0x766f64, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff5df, 3.0);
sun.position.set(7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00045;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfd5df, 0.75);
fill.position.set(-8, 6, -4);
scene.add(fill);
const shellGroup = new THREE.Group();
const fixtureGroup = new THREE.Group();
const utilityGroup = new THREE.Group();
scene.add(shellGroup, fixtureGroup, utilityGroup);
const fixtures = [];
const history = [];
const layouts = loadLayouts();
let businessKey = tenantSelect.value;
let selectedFixtureId = null;
let placementType = null;
let nextFixtureId = 1;
let dragState = null;
let orbitState = null;
let toastTimer = null;
const cameraTarget = new THREE.Vector3(0, 0.45, 0);
let cameraAzimuth = 0;
let cameraPolar = 0.92;
let cameraRadius = 18;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const groundPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const groundPoint = new THREE.Vector3();
const ghost = new THREE.Mesh(
new THREE.PlaneGeometry(1, 1),
new THREE.MeshBasicMaterial({
color: 0x4c9a78,
transparent: true,
opacity: 0.38,
depthWrite: false,
side: THREE.DoubleSide
})
);
ghost.rotation.x = -Math.PI / 2;
ghost.position.y = 0.055;
ghost.visible = false;
scene.add(ghost);
const selectionHelper = new THREE.BoxHelper(scene, 0xf7efe0);
selectionHelper.visible = false;
selectionHelper.material.depthTest = false;
selectionHelper.material.transparent = true;
selectionHelper.material.opacity = 0.95;
scene.add(selectionHelper);
const connectionLines = new THREE.Group();
scene.add(connectionLines);
buildShell();
buildUtilityConnections();
updateCamera();
restoreSnapshot(layouts[businessKey] || []);
rebuildCatalog();
updateUI();
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
}
function addBox(
group,
width,
height,
depth,
x,
y,
z,
color,
options = {}
) {
const material =
color && color.isMaterial
? color
: standardMaterial(color, options.material || {});
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
group.add(mesh);
return mesh;
}
function addCylinder(
group,
radiusTop,
radiusBottom,
height,
x,
y,
z,
color,
radialSegments = 8,
options = {}
) {
const material =
color && color.isMaterial
? color
: standardMaterial(color, options.material || {});
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
radialSegments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function createWallSign() {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const context = canvas.getContext("2d");
context.fillStyle = "#292b26";
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "#f6f0e4";
context.font = "900 76px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText("RETAIL / UNIT 14", 384, 82);
context.fillStyle = "#d76f45";
context.fillRect(272, 137, 224, 9);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(4.8, 1.2),
new THREE.MeshBasicMaterial({ map: texture })
);
sign.position.set(-1.25, 2.65, -3.965);
shellGroup.add(sign);
}
function buildShell() {
const ground = addBox(
shellGroup,
50,
0.16,
50,
0,
-0.38,
0,
0xd8d4cb,
{ castShadow: false }
);
ground.receiveShadow = true;
addBox(
shellGroup,
12.45,
0.24,
8.45,
0,
-0.15,
0,
0xe7dfd0
);
addBox(
shellGroup,
12.35,
3.65,
0.2,
0,
1.7,
-4.1,
0xf1eee6
);
addBox(
shellGroup,
0.2,
3.65,
8.15,
-6.12,
1.7,
0,
0xe9e5dc
);
addBox(
shellGroup,
0.16,
0.62,
8.15,
6.12,
0.22,
0,
0xe9e5dc
);
// Structural columns and fixed window panels.
[-6.05, -0.15, 6.05].forEach((x) => {
addBox(shellGroup, 0.19, 3.7, 0.24, x, 1.7, -3.97, 0xd7d1c4);
});
[-4.55, -2.2, 1.65, 3.05].forEach((x) => {
addBox(
shellGroup,
1.82,
1.42,
0.055,
x,
1.95,
-3.965,
standardMaterial(0xa9cbd0, {
transparent: true,
opacity: 0.53,
roughness: 0.28,
metalness: 0.04
})
);
addBox(shellGroup, 0.055, 1.48, 0.07, x, 1.95, -3.92, 0x8c9996);
addBox(shellGroup, 1.87, 0.055, 0.07, x, 1.95, -3.92, 0x8c9996);
});
// Front threshold and low storefront returns.
addBox(shellGroup, 12.2, 0.13, 0.22, 0, 0.01, 4.03, 0x8d7764);
addBox(shellGroup, 2.8, 0.38, 0.18, -4.7, 0.1, 4.03, 0xe9e3d7);
addBox(shellGroup, 2.8, 0.38, 0.18, 4.7, 0.1, 4.03, 0xe9e3d7);
// Customer approach lane.
const lane = addBox(
shellGroup,
2,
0.018,
4,
0,
0.005,
2,
standardMaterial(0x62a99a, {
transparent: true,
opacity: 0.18,
depthWrite: false
}),
{ castShadow: false }
);
lane.receiveShadow = false;
for (let z = 0.65; z <= 3.45; z += 0.7) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.12, 0.28, 3),
standardMaterial(0x4f9286, { transparent: true, opacity: 0.5 })
);
arrow.rotation.x = Math.PI / 2;
arrow.rotation.z = Math.PI;
arrow.position.set(0, 0.035, z);
shellGroup.add(arrow);
}
createWallSign();
buildGrid();
}
function buildGrid() {
const points = [];
for (let x = -6; x <= 6; x += 1) {
points.push(
new THREE.Vector3(x, 0.025, -4),
new THREE.Vector3(x, 0.025, 4)
);
}
for (let z = -4; z <= 4; z += 1) {
points.push(
new THREE.Vector3(-6, 0.025, z),
new THREE.Vector3(6, 0.025, z)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: 0xa9a294,
transparent: true,
opacity: 0.23
});
const grid = new THREE.LineSegments(geometry, material);
shellGroup.add(grid);
}
function buildUtilityConnections() {
for (const [type, utility] of Object.entries(UTILITIES)) {
addBox(
utilityGroup,
0.58,
0.78,
0.13,
utility.wall.x,
utility.wall.y,
utility.wall.z,
utility.color
);
addBox(
utilityGroup,
0.68,
0.08,
0.16,
utility.wall.x,
utility.wall.y + 0.44,
utility.wall.z,
standardMaterial(utility.color, { roughness: 0.45 })
);
addBox(
utilityGroup,
0.08,
1.0,
0.08,
utility.wall.x,
0.54,
-3.94,
utility.color
);
const ringPoints = [];
const radius = UTILITY_RADIUS;
for (let i = 0; i <= 64; i++) {
const angle = (i / 64) * Math.PI * 2;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
ringPoints.push(
new THREE.Vector3(
utility.point.x + x * 0.7071,
0.035,
utility.point.z + z * 0.7071
)
);
}
const ring = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(ringPoints),
new THREE.LineDashedMaterial({
color: utility.color,
transparent: true,
opacity: 0.32,
dashSize: 0.18,
gapSize: 0.13
})
);
ring.computeLineDistances();
utilityGroup.add(ring);
}
// Visible conduits reinforce that these connections belong to the shell.
addBox(
utilityGroup,
0.76,
0.08,
0.08,
5,
0.3,
-3.91,
0x68716e
);
}
function makeFixture(type, id) {
const business = BUSINESSES[businessKey];
const spec = business.fixtures[type];
const group = new THREE.Group();
group.userData.fixtureId = id;
switch (spec.shape) {
case "counter":
buildCounter(group, spec);
break;
case "table":
buildTable(group, spec);
break;
case "pastry":
buildPastry(group, spec);
break;
case "rail":
buildRail(group, spec);
break;
case "chair":
buildSalonChair(group, spec);
break;
case "station":
buildStation(group, spec);
break;
case "basin":
buildBasin(group, spec);
break;
case "shelf":
buildProductShelf(group, spec);
break;
case "bookcase":
buildBookcase(group, spec);
break;
case "checkout":
buildCheckout(group, spec);
break;
case "reading":
buildReadingTable(group, spec);
break;
case "plinth":
buildPlinth(group, spec);
break;
}
group.traverse((child) => {
if (child.isMesh) {
child.userData.fixtureId = id;
}
});
return group;
}
function buildCounter(group, spec) {
addBox(group, 1.86, 0.82, 0.78, 0, 0.41, 0, spec.color);
addBox(group, 1.98, 0.12, 0.92, 0, 0.87, 0, 0xf2e7d5);
addBox(group, 1.8, 0.12, 0.04, 0, 0.62, 0.41, 0x825443);
addBox(group, 0.45, 0.35, 0.35, -0.48, 1.1, -0.08, 0x4d504b);
addBox(group, 0.3, 0.08, 0.22, -0.48, 1.31, -0.04, 0x30322f);
addCylinder(group, 0.08, 0.08, 0.18, 0.47, 1.01, 0.02, 0xf1eee4);
}
function buildTable(group, spec) {
addCylinder(group, 0.38, 0.38, 0.1, 0, 0.79, 0, 0xe6d5b9);
addCylinder(group, 0.065, 0.075, 0.68, 0, 0.4, 0, 0x505852);
addCylinder(group, 0.27, 0.3, 0.07, 0, 0.055, 0, 0x505852);
addCylinder(group, 0.07, 0.055, 0.12, 0.13, 0.9, 0.05, spec.color);
}
function buildPastry(group, spec) {
addBox(group, 1.86, 0.68, 0.78, 0, 0.34, 0, spec.color);
addBox(group, 1.96, 0.09, 0.88, 0, 0.72, 0, 0xf2e5cf);
const glass = standardMaterial(0xcce5e5, {
transparent: true,
opacity: 0.38,
depthWrite: false,
roughness: 0.25
});
addBox(group, 1.76, 0.48, 0.66, 0, 1.0, 0, glass, {
castShadow: false
});
[-0.5, 0, 0.5].forEach((x, index) => {
addBox(
group,
0.34,
0.11,
0.36,
x,
0.84 + (index % 2) * 0.08,
0.02,
index % 2 ? 0xd99758 : 0xe5b96e
);
});
}
function buildRail(group, spec) {
const positions = [
[-0.82, -0.28],
[0.82, -0.28],
[-0.82, 0.28],
[0.82, 0.28]
];
positions.forEach(([x, z]) => {
addCylinder(group, 0.045, 0.055, 0.8, x, 0.4, z, spec.color);
addCylinder(group, 0.12, 0.14, 0.05, x, 0.025, z, 0x484d49);
});
addBox(group, 1.72, 0.055, 0.055, 0, 0.67, -0.28, spec.color);
addBox(group, 1.72, 0.055, 0.055, 0, 0.67, 0.28, spec.color);
}
function buildSalonChair(group, spec) {
addCylinder(group, 0.32, 0.37, 0.07, 0, 0.04, 0, 0x4f5350);
addCylinder(group, 0.07, 0.08, 0.4, 0, 0.27, 0, 0x676b67);
addBox(group, 0.58, 0.17, 0.55, 0, 0.54, 0, spec.color);
addBox(group, 0.58, 0.63, 0.14, 0, 0.9, -0.22, spec.color);
addBox(group, 0.12, 0.42, 0.36, 0.34, 0.76, -0.04, spec.color);
addBox(group, 0.12, 0.42, 0.36, -0.34, 0.76, -0.04, spec.color);
}
function buildStation(group, spec) {
addBox(group, 1.82, 0.68, 0.75, 0, 0.34, 0, spec.color);
addBox(group, 1.92, 0.1, 0.84, 0, 0.73, 0, 0xf0dfd8);
addBox(group, 0.78, 0.78, 0.08, 0, 1.2, -0.3, 0x77646d);
addBox(
group,
0.67,
0.67,
0.025,
0,
1.2,
-0.245,
standardMaterial(0xc5d8d9, {
metalness: 0.35,
roughness: 0.2
})
);
addCylinder(group, 0.21, 0.23, 0.08, 0, 0.08, 0, 0x555956);
addCylinder(group, 0.05, 0.06, 0.38, 0, 0.3, 0, 0x555956);
addCylinder(group, 0.24, 0.24, 0.12, 0, 0.55, 0, spec.color);
}
function buildBasin(group, spec) {
addBox(group, 0.82, 0.58, 0.8, 0, 0.29, 0, spec.color);
addCylinder(group, 0.38, 0.32, 0.23, 0, 0.7, 0, 0xe4e9e3);
addCylinder(
group,
0.29,
0.29,
0.025,
0,
0.83,
0,
standardMaterial(0x78949a, { roughness: 0.3 })
);
addCylinder(group, 0.035, 0.035, 0.35, 0.28, 0.98, -0.26, 0x879497);
addBox(group, 0.23, 0.035, 0.035, 0.18, 1.14, -0.26, 0x879497);
}
function buildProductShelf(group, spec) {
addBox(group, 0.88, 0.08, 0.52, 0, 0.08, 0, spec.color);
addBox(group, 0.88, 0.08, 0.52, 0, 0.65, 0, spec.color);
addBox(group, 0.88, 0.08, 0.52, 0, 1.22, 0, spec.color);
addBox(group, 0.07, 1.45, 0.08, -0.42, 0.72, -0.24, spec.color);
addBox(group, 0.07, 1.45, 0.08, 0.42, 0.72, -0.24, spec.color);
const bottleColors = [0xe4b87b, 0x7d9e8d, 0xc78484];
for (let shelf = 0; shelf < 3; shelf++) {
for (let i = 0; i < 3; i++) {
addBox(
group,
0.12,
0.24,
0.13,
-0.25 + i * 0.25,
0.24 + shelf * 0.57,
-0.03,
bottleColors[(i + shelf) % bottleColors.length]
);
}
}
}
function buildBookcase(group, spec) {
addBox(group, 1.9, 1.7, 0.12, 0, 0.85, -0.28, spec.color);
addBox(group, 1.9, 0.09, 0.65, 0, 0.06, 0, spec.color);
addBox(group, 1.9, 0.09, 0.65, 0, 1.7, 0, spec.color);
addBox(group, 0.09, 1.7, 0.65, -0.94, 0.85, 0, spec.color);
addBox(group, 0.09, 1.7, 0.65, 0.94, 0.85, 0, spec.color);
[0.56, 1.08].forEach((y) => {
addBox(group, 1.8, 0.07, 0.62, 0, y, 0, spec.color);
});
const colors = [0xd88766, 0xe1bd77, 0x799a8e, 0x8d789b, 0xbb8e7b];
for (let shelf = 0; shelf < 3; shelf++) {
for (let i = 0; i < 8; i++) {
const height = 0.3 + ((i + shelf) % 3) * 0.045;
addBox(
group,
0.12,
height,
0.34,
-0.75 + i * 0.21,
0.11 + shelf * 0.52 + height / 2,
0.04,
colors[(i + shelf * 2) % colors.length]
);
}
}
}
function buildCheckout(group, spec) {
addBox(group, 1.84, 0.82, 0.78, 0, 0.41, 0, spec.color);
addBox(group, 1.96, 0.12, 0.9, 0, 0.87, 0, 0xeadbc5);
addBox(group, 0.43, 0.32, 0.3, 0.48, 1.08, -0.07, 0x484e4a);
addBox(group, 0.35, 0.2, 0.03, 0.48, 1.15, 0.095, 0x8db1a6);
addBox(group, 0.35, 0.03, 0.2, 0.48, 0.95, 0.12, 0x4e5350);
}
function buildReadingTable(group, spec) {
addBox(group, 1.78, 0.12, 0.88, 0, 0.78, 0, spec.color);
addBox(group, 0.12, 0.7, 0.7, -0.72, 0.39, 0, 0x5f6962);
addBox(group, 0.12, 0.7, 0.7, 0.72, 0.39, 0, 0x5f6962);
addBox(group, 0.42, 0.06, 0.3, -0.28, 0.87, 0.04, 0xeee1ca);
addBox(group, 0.06, 0.45, 0.3, 0.28, 1.02, -0.08, 0x6f8f80);
}
function buildPlinth(group, spec) {
addCylinder(group, 0.28, 0.34, 0.82, 0, 0.41, 0, spec.color);
addCylinder(group, 0.38, 0.38, 0.08, 0, 0.05, 0, 0x4d5751);
addBox(group, 0.38, 0.42, 0.3, 0, 1.03, 0, 0xd08b66);
addBox(group, 0.43, 0.05, 0.34, 0, 1.27, 0, 0xf0d5ac);
}
function addFixture(type, col, row, rot = 0, id = null) {
const idValue = id ?? nextFixtureId++;
const group = makeFixture(type, idValue);
const spec = BUSINESSES[businessKey].fixtures[type];
const fixture = {
id: idValue,
type,
group,
col,
row,
rot,
w: spec.w,
d: spec.d
};
fixtureGroup.add(group);
fixtures.push(fixture);
updateFixtureTransform(fixture);
return fixture;
}
function fixtureDimensions(fixture) {
const spec = BUSINESSES[businessKey].fixtures[fixture.type];
return fixture.rot % 2 === 0
? { w: spec.w, d: spec.d }
: { w: spec.d, d: spec.w };
}
function updateFixtureTransform(fixture) {
const { w, d } = fixtureDimensions(fixture);
fixture.group.position.set(
fixture.col + (w - 1) / 2 - 5.5,
0,
fixture.row + (d - 1) / 2 - 3.5
);
fixture.group.rotation.y = fixture.rot * (Math.PI / 2);
}
function getFixture(id) {
return fixtures.find((fixture) => fixture.id === id) || null;
}
function removeFixture(id) {
const fixture = getFixture(id);
if (!fixture) return;
fixtureGroup.remove(fixture.group);
disposeObject(fixture.group);
fixtures.splice(fixtures.indexOf(fixture), 1);
if (selectedFixtureId === id) {
selectedFixtureId = null;
}
}
function disposeObject(object) {
const geometries = new Set();
const materials = new Set();
object.traverse((child) => {
if (child.geometry) geometries.add(child.geometry);
if (child.material) {
if (Array.isArray(child.material)) {
child.material.forEach((material) => materials.add(material));
} else {
materials.add(child.material);
}
}
});
geometries.forEach((geometry) => geometry.dispose());
materials.forEach((material) => material.dispose());
}
function clearFixtures() {
fixtures.forEach((fixture) => {
fixtureGroup.remove(fixture.group);
disposeObject(fixture.group);
});
fixtures.length = 0;
selectedFixtureId = null;
placementType = null;
ghost.visible = false;
}
function captureSnapshot() {
return fixtures.map((fixture) => ({
type: fixture.type,
col: fixture.col,
row: fixture.row,
rot: fixture.rot
}));
}
function restoreSnapshot(snapshot) {
clearFixtures();
if (!Array.isArray(snapshot)) return;
snapshot.forEach((item) => {
if (!BUSINESSES[businessKey].fixtures[item.type]) return;
const fixture = addFixture(
item.type,
item.col,
item.row,
item.rot || 0
);
fixture.group.position.set(
fixture.group.position.x,
0,
fixture.group.position.z
);
});
}
function loadLayouts() {
try {
const parsed = JSON.parse(
localStorage.getItem("retail-fit-layouts-v1") || "{}"
);
return parsed && typeof parsed === "object" ? parsed : {};
} catch {
return {};
}
}
function persistCurrent() {
layouts[businessKey] = captureSnapshot();
try {
localStorage.setItem("retail-fit-layouts-v1", JSON.stringify(layouts));
} catch {
// The game remains fully functional if storage is unavailable.
}
}
function isReservedCell(col, row) {
// The two-cell-wide customer approach from the entrance stays clear.
return (col === 5 || col === 6) && row >= 4;
}
function validatePlacement(col, row, w, d, ignoreId = null) {
if (col < 0 || row < 0 || col + w > GRID_WIDTH || row + d > GRID_DEPTH) {
return { valid: false, reason: "That fixture must stay inside the shell." };
}
for (let x = col; x < col + w; x++) {
for (let y = row; y < row + d; y++) {
if (isReservedCell(x, y)) {
return {
valid: false,
reason: "Keep the striped customer entrance lane clear."
};
}
}
}
for (const other of fixtures) {
if (other.id === ignoreId) continue;
const dimensions = fixtureDimensions(other);
const overlaps =
col < other.col + dimensions.w &&
col + w > other.col &&
row < other.row + dimensions.d &&
row + d > other.row;
if (overlaps) {
return { valid: false, reason: "Fixtures cannot overlap." };
}
}
return { valid: true, reason: "" };
}
function selectedBusiness() {
return BUSINESSES[businessKey];
}
function countType(type) {
return fixtures.filter((fixture) => fixture.type === type).length;
}
function totalSpend() {
return fixtures.reduce(
(sum, fixture) =>
sum + selectedBusiness().fixtures[fixture.type].cost,
0
);
}
function isConnected(fixture, utilityType) {
const utility = UTILITIES[utilityType];
const dx = Math.abs(fixture.group.position.x - utility.point.x);
const dz = Math.abs(fixture.group.position.z - utility.point.z);
return dx + dz <= UTILITY_RADIUS;
}
function evaluateLayout() {
const business = selectedBusiness();
const checks = [];
for (const [type, required] of Object.entries(business.requirements)) {
const count = countType(type);
checks.push({
label: business.fixtures[type].name,
detail: `${count} of ${required} required`,
pass: count >= required,
weight: required
});
}
const powered = fixtures.filter((fixture) =>
business.fixtures[fixture.type].utility.includes("power")
);
const connectedPower = powered.filter((fixture) =>
isConnected(fixture, "power")
);
checks.push({
label: "Power connections",
detail: `${connectedPower.length} of ${powered.length} powered fixtures connected`,
pass: powered.length === connectedPower.length,
weight: Math.max(1, powered.length)
});
const wet = fixtures.filter((fixture) =>
business.fixtures[fixture.type].utility.includes("water")
);
const connectedWater = wet.filter((fixture) =>
isConnected(fixture, "water")
);
checks.push({
label: "Water connections",
detail: `${connectedWater.length} of ${wet.length} wet fixtures connected`,
pass: wet.length === connectedWater.length,
weight: Math.max(1, wet.length)
});
const spend = totalSpend();
checks.push({
label: "Fixture budget",
detail: `$${spend.toLocaleString()} of $${business.budget.toLocaleString()}`,
pass: spend <= business.budget,
weight: 2
});
const laneBlocked = fixtures.some((fixture) => {
const dimensions = fixtureDimensions(fixture);
for (let x = fixture.col; x < fixture.col + dimensions.w; x++) {
for (let y = fixture.row; y < fixture.row + dimensions.d; y++) {
if (isReservedCell(x, y)) return true;
}
}
return false;
});
checks.push({
label: "Entrance access",
detail: laneBlocked ? "Customer lane is blocked" : "Customer lane is clear",
pass: !laneBlocked,
weight: 1
});
const totalWeight = checks.reduce((sum, check) => sum + check.weight, 0);
const earnedWeight = checks.reduce(
(sum, check) => sum + (check.pass ? check.weight : 0),
0
);
return {
checks,
score: Math.round((earnedWeight / totalWeight) * 100),
passed: checks.every((check) => check.pass)
};
}
function rebuildCatalog() {
const business = selectedBusiness();
catalogElement.innerHTML = "";
Object.entries(business.fixtures).forEach(([type, spec]) => {
const card = document.createElement("div");
card.className = "fixture-card";
card.dataset.type = type;
card.tabIndex = 0;
const utilityDots = spec.utility
.map(
(utility) =>
`<i class="utility-dot ${utility}" title="${utility} connection"></i>`
)
.join("");
card.innerHTML = `
<div class="fixture-icon">${spec.icon}</div>
<div class="fixture-copy">
<span class="fixture-name">${spec.name}</span>
<span class="fixture-meta">
${spec.w}×${spec.d} · $${spec.cost.toLocaleString()}
${utilityDots}
</span>
</div>
<div class="fixture-qty">
<strong>0/${business.requirements[type]}</strong>
<span>placed</span>
</div>
`;
card.addEventListener("click", () => {
placementType = placementType === type ? null : type;
selectedFixtureId = null;
ghost.visible = false;
updateUI();
});
card.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
card.click();
}
});
catalogElement.appendChild(card);
});
$("#catalogCount").textContent = `${Object.keys(business.fixtures).length} items`;
document.documentElement.style.setProperty(
"--accent",
business.accent
);
document.documentElement.style.setProperty(
"--accent-soft",
`${business.accent}24`
);
}
function updateUI() {
const business = selectedBusiness();
const result = evaluateLayout();
$("#briefName").textContent = business.name;
$("#briefDescription").textContent = business.description;
$("#briefTags").innerHTML = business.tags
.map((tag) => `<span class="brief-tag">${tag}</span>`)
.join("");
for (const [type, spec] of Object.entries(business.fixtures)) {
const card = catalogElement.querySelector(`[data-type="${type}"]`);
if (!card) continue;
const count = countType(type);
card.classList.toggle("active", placementType === type);
card.querySelector(".fixture-qty strong").textContent =
`${count}/${business.requirements[type]}`;
card.querySelector(".fixture-qty").classList.toggle(
"complete",
count >= business.requirements[type]
);
}
$("#scoreRing").style.setProperty("--score", `${result.score}%`);
$("#scoreValue").textContent = `${result.score}%`;
$("#scoreCopy").textContent = result.passed
? "Everything checks out. Open when ready."
: "Complete the checklist before opening.";
const spend = totalSpend();
$("#budgetValue").textContent = `$${spend.toLocaleString()} / $${business.budget.toLocaleString()}`;
$("#budgetBar").style.width = `${Math.min(100, (spend / business.budget) * 100)}%`;
$("#budgetBar").style.background =
spend > business.budget ? "var(--bad)" : "var(--accent)";
objectiveElement.innerHTML = result.checks
.map(
(check) => `
<div class="objective ${check.pass ? "pass" : ""}">
<span class="objective-icon">${check.pass ? "✓" : "!"}</span>
<div class="objective-text">
<strong>${check.label}</strong>
<span>${check.detail}</span>
</div>
<span class="objective-status">${check.pass ? "Done" : "Open"}</span>
</div>
`
)
.join("");
const selected = getFixture(selectedFixtureId);
$("#rotateButton").disabled = !selected && !placementType;
$("#deleteButton").disabled = !selected;
$("#undoButton").disabled = history.length === 0;
if (placementType) {
const spec = business.fixtures[placementType];
$("#modePill").textContent = `Placing: ${spec.name} — click the floor`;
} else if (selected) {
$("#modePill").textContent = `Selected: ${business.fixtures[selected.type].name}`;
} else {
$("#modePill").textContent = "Select a fixture to begin";
}
}
function selectFixture(id) {
selectedFixtureId = id;
placementType = null;
ghost.visible = false;
updateSelectionVisual();
updateUI();
}
function updateSelectionVisual() {
while (connectionLines.children.length) {
const child = connectionLines.children[0];
connectionLines.remove(child);
child.geometry?.dispose();
child.material?.dispose();
}
const fixture = getFixture(selectedFixtureId);
if (!fixture) {
selectionHelper.visible = false;
return;
}
selectionHelper.setFromObject(fixture.group);
selectionHelper.visible = true;
const utilities =
selectedBusiness().fixtures[fixture.type].utility || [];
for (const type of utilities) {
const utility = UTILITIES[type];
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(
fixture.group.position.x,
0.12,
fixture.group.position.z
),
new THREE.Vector3(utility.point.x, 0.12, utility.point.z)
]);
const material = new THREE.LineDashedMaterial({
color: utility.color,
dashSize: 0.14,
gapSize: 0.09,
transparent: true,
opacity: 0.9
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
connectionLines.add(line);
}
}
function setGhost(col, row, w, d, valid) {
ghost.visible = true;
ghost.scale.set(w, d, 1);
ghost.position.set(
col + (w - 1) / 2 - 5.5,
0.055,
row + (d - 1) / 2 - 3.5
);
ghost.material.color.set(valid ? 0x4c9a78 : 0xbb5b51);
ghost.material.opacity = valid ? 0.38 : 0.48;
}
function showToast(message) {
const toast = $("#toast");
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toast.classList.remove("show");
}, 2200);
}
function pushHistory(snapshot) {
history.push(snapshot);
if (history.length > 40) history.shift();
}
function placeFixtureAt(point) {
if (!placementType) return;
const spec = selectedBusiness().fixtures[placementType];
const col = Math.round(point.x + GRID_WIDTH / 2 - spec.w / 2);
const row = Math.round(point.z + GRID_DEPTH / 2 - spec.d / 2);
const validation = validatePlacement(col, row, spec.w, spec.d);
if (!validation.valid) {
showToast(validation.reason);
return;
}
pushHistory(captureSnapshot());
const fixture = addFixture(placementType, col, row);
placementType = null;
selectedFixtureId = fixture.id;
ghost.visible = false;
persistCurrent();
updateSelectionVisual();
updateUI();
showToast(`${spec.name} placed.`);
}
function moveSelectedTo(point) {
const fixture = getFixture(selectedFixtureId);
if (!fixture) return;
const dimensions = fixtureDimensions(fixture);
const col = Math.round(
point.x + GRID_WIDTH / 2 - dimensions.w / 2
);
const row = Math.round(
point.z + GRID_DEPTH / 2 - dimensions.d / 2
);
const validation = validatePlacement(
col,
row,
dimensions.w,
dimensions.d,
fixture.id
);
if (!validation.valid) {
showToast(validation.reason);
return;
}
pushHistory(captureSnapshot());
fixture.col = col;
fixture.row = row;
updateFixtureTransform(fixture);
persistCurrent();
updateSelectionVisual();
updateUI();
}
function rotateSelected() {
if (placementType) {
showToast("Place the fixture first, then rotate it.");
return;
}
const fixture = getFixture(selectedFixtureId);
if (!fixture) return;
const oldDimensions = fixtureDimensions(fixture);
const center = fixture.group.position.clone();
const newW = oldDimensions.d;
const newD = oldDimensions.w;
const col = Math.round(center.x + GRID_WIDTH / 2 - newW / 2);
const row = Math.round(center.z + GRID_DEPTH / 2 - newD / 2);
const validation = validatePlacement(
col,
row,
newW,
newD,
fixture.id
);
if (!validation.valid) {
showToast(validation.reason);
return;
}
pushHistory(captureSnapshot());
fixture.rot = (fixture.rot + 1) % 2;
fixture.col = col;
fixture.row = row;
updateFixtureTransform(fixture);
persistCurrent();
updateSelectionVisual();
updateUI();
}
function deleteSelected() {
const fixture = getFixture(selectedFixtureId);
if (!fixture) return;
pushHistory(captureSnapshot());
removeFixture(fixture.id);
persistCurrent();
updateSelectionVisual();
updateUI();
showToast("Fixture removed.");
}
function undo() {
if (!history.length) return;
const previous = history.pop();
restoreSnapshot(previous);
persistCurrent();
updateSelectionVisual();
updateUI();
showToast("Last change undone.");
}
function resetLayout() {
if (!fixtures.length) return;
if (!confirm("Clear all fixtures from this tenant's layout?")) return;
pushHistory(captureSnapshot());
restoreSnapshot([]);
persistCurrent();
updateSelectionVisual();
updateUI();
showToast("Layout cleared.");
}
function changeBusiness(key) {
persistCurrent();
businessKey = key;
clearFixtures();
history.length = 0;
restoreSnapshot(layouts[businessKey] || []);
rebuildCatalog();
updateSelectionVisual();
updateUI();
showToast(`${selectedBusiness().name} layout loaded.`);
}
function openReview() {
const result = evaluateLayout();
modal.classList.toggle("success", result.passed);
$("#modalIcon").textContent = result.passed ? "✓" : "!";
$("#modalTitle").textContent = result.passed
? "Doors open!"
: "A few things need attention";
$("#modalSubtitle").textContent = result.passed
? `${selectedBusiness().name} is ready for customers. Your layout scored ${result.score}%.`
: `Your current layout is ${result.score}% ready. Review the open items below.`;
$("#reviewList").innerHTML = result.checks
.map(
(check) => `
<div class="review-row ${check.pass ? "pass" : ""}">
<i>${check.pass ? "✓" : "!"}</i>
<div>
<strong>${check.label}</strong>
<span>${check.detail}</span>
</div>
<span>${check.pass ? "Ready" : "Fix"}</span>
</div>
`
)
.join("");
$("#confirmModalButton").textContent = result.passed
? "Great!"
: "Keep editing";
modal.classList.add("open");
}
function updatePointer(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;
}
function pointOnGround() {
raycaster.setFromCamera(pointer, camera);
return raycaster.ray.intersectPlane(groundPlane, groundPoint)
? groundPoint
: null;
}
function hitFixture(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(
fixtures.map((fixture) => fixture.group),
true
);
for (const hit of hits) {
let object = hit.object;
while (object && object.userData.fixtureId === undefined) {
object = object.parent;
}
if (object?.userData.fixtureId !== undefined) {
return getFixture(object.userData.fixtureId);
}
}
return null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.focus();
if (event.button === 2 || event.button === 1 || event.shiftKey) {
orbitState = {
x: event.clientX,
y: event.clientY,
azimuth: cameraAzimuth,
polar: cameraPolar
};
renderer.domElement.setPointerCapture(event.pointerId);
event.preventDefault();
return;
}
if (event.button !== 0) return;
const point = pointOnGround();
const hit = hitFixture(event);
if (hit) {
selectFixture(hit.id);
dragState = {
id: hit.id,
startX: event.clientX,
startY: event.clientY,
moved: false,
before: captureSnapshot(),
originalPosition: hit.group.position.clone()
};
renderer.domElement.setPointerCapture(event.pointerId);
return;
}
if (placementType && point) {
placeFixtureAt(point);
return;
}
if (selectedFixtureId !== null && point) {
moveSelectedTo(point);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (orbitState) {
const dx = event.clientX - orbitState.x;
const dy = event.clientY - orbitState.y;
cameraAzimuth = orbitState.azimuth - dx * 0.006;
cameraPolar = THREE.MathUtils.clamp(
orbitState.polar + dy * 0.005,
0.48,
1.32
);
updateCamera();
return;
}
updatePointer(event);
if (dragState) {
const distance = Math.hypot(
event.clientX - dragState.startX,
event.clientY - dragState.startY
);
if (distance < 4) return;
const point = pointOnGround();
const fixture = getFixture(dragState.id);
if (!point || !fixture) return;
const dimensions = fixtureDimensions(fixture);
const col = Math.round(
point.x + GRID_WIDTH / 2 - dimensions.w / 2
);
const row = Math.round(
point.z + GRID_DEPTH / 2 - dimensions.d / 2
);
const validation = validatePlacement(
col,
row,
dimensions.w,
dimensions.d,
fixture.id
);
fixture.group.position.set(
col + (dimensions.w - 1) / 2 - 5.5,
0,
row + (dimensions.d - 1) / 2 - 3.5
);
setGhost(
col,
row,
dimensions.w,
dimensions.d,
validation.valid
);
dragState.moved = true;
return;
}
if (placementType) {
const point = pointOnGround();
if (!point) return;
const spec = selectedBusiness().fixtures[placementType];
const col = Math.round(
point.x + GRID_WIDTH / 2 - spec.w / 2
);
const row = Math.round(
point.z + GRID_DEPTH / 2 - spec.d / 2
);
const validation = validatePlacement(
col,
row,
spec.w,
spec.d
);
setGhost(
col,
row,
spec.w,
spec.d,
validation.valid
);
} else {
const hit = hitFixture(event);
renderer.domElement.style.cursor = hit ? "grab" : "default";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (orbitState) {
orbitState = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
return;
}
if (!dragState) return;
const fixture = getFixture(dragState.id);
if (!fixture) {
dragState = null;
return;
}
if (dragState.moved) {
const dimensions = fixtureDimensions(fixture);
const col = Math.round(
fixture.group.position.x + GRID_WIDTH / 2 - dimensions.w / 2
);
const row = Math.round(
fixture.group.position.z + GRID_DEPTH / 2 - dimensions.d / 2
);
const validation = validatePlacement(
col,
row,
dimensions.w,
dimensions.d,
fixture.id
);
if (!validation.valid) {
fixture.group.position.copy(dragState.originalPosition);
showToast(validation.reason);
} else {
fixture.col = col;
fixture.row = row;
updateFixtureTransform(fixture);
pushHistory(dragState.before);
persistCurrent();
updateUI();
}
}
ghost.visible = false;
updateSelectionVisual();
renderer.domElement.style.cursor = "grab";
dragState = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
if (dragState) {
const fixture = getFixture(dragState.id);
if (fixture) fixture.group.position.copy(dragState.originalPosition);
}
dragState = null;
orbitState = null;
ghost.visible = false;
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
11,
25
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key.toLowerCase() === "r") {
rotateSelected();
} else if (event.key === "Delete" || event.key === "Backspace") {
event.preventDefault();
deleteSelected();
} else if (event.key === "Escape") {
placementType = null;
ghost.visible = false;
updateUI();
} else if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "z") {
event.preventDefault();
undo();
}
});
function updateCamera() {
const sine = Math.sin(cameraPolar);
camera.position.set(
cameraTarget.x + cameraRadius * sine * Math.sin(cameraAzimuth),
cameraTarget.y + cameraRadius * Math.cos(cameraPolar),
cameraTarget.z + cameraRadius * sine * Math.cos(cameraAzimuth)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraAzimuth = 0;
cameraPolar = 0.92;
cameraRadius = 18;
updateCamera();
}
function positionLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
element.style.left = `${(projected.x * 0.5 + 0.5) * stage.clientWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * stage.clientHeight}px`;
}
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / Math.max(1, height);
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
tenantSelect.addEventListener("change", () => {
changeBusiness(tenantSelect.value);
});
$("#undoButton").addEventListener("click", undo);
$("#resetButton").addEventListener("click", resetLayout);
$("#openButton").addEventListener("click", openReview);
$("#rotateButton").addEventListener("click", rotateSelected);
$("#deleteButton").addEventListener("click", deleteSelected);
$("#cameraButton").addEventListener("click", resetCamera);
$("#closeModalButton").addEventListener("click", () => {
modal.classList.remove("open");
});
$("#confirmModalButton").addEventListener("click", () => {
modal.classList.remove("open");
});
modal.addEventListener("click", (event) => {
if (event.target === modal) modal.classList.remove("open");
});
function animate() {
requestAnimationFrame(animate);
if (selectionHelper.visible) {
selectionHelper.update();
}
positionLabel(
$("#powerLabel"),
UTILITIES.power.wall.clone().add(new THREE.Vector3(0, 0.55, 0.06))
);
positionLabel(
$("#waterLabel"),
UTILITIES.water.wall.clone().add(new THREE.Vector3(0, 0.55, 0.06))
);
positionLabel(
$("#entryLabel"),
new THREE.Vector3(0, 0.12, 3.75)
);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```