Prompt specification
Build or customize the Three.js 3D scene "Two Dates One Shopping List" 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: Two Dates One Shopping List
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-dates-one-shopping-list-x3178
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows price changes in fixed consumption baskets. Display identical baskets on two checkout tables with different fictional price labels. Compute total cost from unchanged quantities and expose each item's contribution to the difference. Stylized solid forms.
Working Three.js Starter (two-dates-one-shopping-list-x3178):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One Basket, Two Prices</title>
<style>
:root {
--ink: #173b38;
--ink-soft: #496963;
--paper: #f7f3eb;
--stage: #e9e3d8;
--line: #d9d1c3;
--coral: #e96d50;
--mint: #79aa99;
--gold: #d7a65e;
--blue: #6f9db5;
--white: #fffdf8;
--shadow: 0 16px 40px rgba(28, 54, 49, 0.09);
}
* {
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;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.app {
min-height: 100vh;
height: 100dvh;
display: grid;
grid-template-rows: auto minmax(0, 1fr);
}
.header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 19px 28px;
border-bottom: 1px solid var(--line);
background: var(--paper);
z-index: 2;
}
.title-block {
display: flex;
align-items: center;
gap: 15px;
}
.brand-mark {
position: relative;
width: 43px;
height: 43px;
flex: 0 0 auto;
border-radius: 13px;
background: var(--ink);
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
border-radius: 50%;
}
.brand-mark::before {
width: 18px;
height: 18px;
left: 8px;
top: 8px;
background: var(--mint);
}
.brand-mark::after {
width: 13px;
height: 13px;
right: 7px;
bottom: 7px;
background: var(--coral);
border: 3px solid var(--ink);
}
.eyebrow {
margin: 0 0 3px;
color: var(--ink-soft);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 2.4vw, 34px);
line-height: 1.08;
letter-spacing: -0.045em;
}
.header-note {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 14px;
border: 1px solid #cbd8d0;
border-radius: 999px;
background: #eef4ee;
color: #355f55;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.header-note::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 0 4px rgba(121, 170, 153, 0.18);
}
.main {
min-height: 0;
display: grid;
grid-template-columns: minmax(0, 1fr) 385px;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: var(--stage);
isolation: isolate;
}
#stage canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.stage-top,
.stage-bottom,
.stage-controls {
position: absolute;
z-index: 2;
pointer-events: none;
}
.stage-top {
top: 18px;
left: 20px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 12px;
background: rgba(255, 253, 248, 0.72);
box-shadow: 0 8px 22px rgba(40, 60, 54, 0.08);
backdrop-filter: blur(12px);
color: var(--ink-soft);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.stage-top span {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--coral);
}
.stage-bottom {
left: 20px;
bottom: 18px;
display: flex;
align-items: center;
gap: 14px;
}
.market-legend {
display: flex;
align-items: center;
gap: 12px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 12px;
background: rgba(255, 253, 248, 0.75);
box-shadow: 0 8px 22px rgba(40, 60, 54, 0.07);
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
}
.market-legend span {
display: flex;
align-items: center;
gap: 6px;
}
.market-legend i {
width: 8px;
height: 8px;
border-radius: 50%;
}
.market-legend .a {
background: var(--mint);
}
.market-legend .b {
background: var(--coral);
}
.market-legend .divider {
width: 1px;
height: 15px;
background: var(--line);
}
.stage-controls {
right: 20px;
bottom: 18px;
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
#controlHint {
padding: 9px 11px;
border-radius: 10px;
background: rgba(23, 59, 56, 0.78);
color: #f8f4ea;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.02em;
backdrop-filter: blur(10px);
}
#resetView {
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 10px;
padding: 9px 12px;
background: rgba(255, 253, 248, 0.84);
box-shadow: 0 8px 22px rgba(40, 60, 54, 0.08);
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
#resetView:hover {
background: var(--white);
transform: translateY(-1px);
}
aside {
min-height: 0;
overflow-y: auto;
padding: 24px 23px 28px;
border-left: 1px solid var(--line);
background:
linear-gradient(rgba(247, 243, 235, 0.96), rgba(247, 243, 235, 0.96)),
radial-gradient(circle at 10% 10%, #d6e5dc, transparent 36%);
scrollbar-width: thin;
scrollbar-color: #b9c7c0 transparent;
}
.panel-heading h2 {
margin: 0 0 6px;
font-size: 27px;
line-height: 1.1;
letter-spacing: -0.04em;
}
.panel-heading p {
margin: 0;
color: var(--ink-soft);
font-size: 13px;
line-height: 1.5;
}
.summary {
position: relative;
overflow: hidden;
margin: 20px 0 23px;
padding: 18px;
border-radius: 18px;
background: var(--ink);
color: var(--white);
box-shadow: var(--shadow);
}
.summary::after {
content: "";
position: absolute;
width: 120px;
height: 120px;
right: -45px;
top: -55px;
border: 24px solid rgba(233, 109, 80, 0.15);
border-radius: 50%;
pointer-events: none;
}
.summary-grid {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: end;
gap: 10px;
}
.market-total small {
display: block;
margin-bottom: 6px;
color: #b7ccc5;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.market-total strong {
display: block;
font-size: 24px;
line-height: 1;
letter-spacing: -0.04em;
}
.summary-arrow {
padding-bottom: 2px;
color: #8fb5a8;
font-size: 20px;
}
.summary-delta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 16px;
padding-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.13);
}
.summary-delta strong {
color: #ff9a7e;
font-size: 18px;
}
.summary-delta span {
color: #c4d4cf;
font-size: 11px;
}
.section-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
color: var(--ink-soft);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-label span {
color: var(--coral);
letter-spacing: 0.03em;
text-transform: none;
}
.item-list {
border-top: 1px solid var(--line);
}
.item-row {
width: 100%;
display: grid;
grid-template-columns: 12px minmax(0, 1fr) auto;
gap: 5px 10px;
padding: 14px 5px 13px;
border: 0;
border-bottom: 1px solid var(--line);
background: transparent;
text-align: left;
cursor: pointer;
transition:
background 160ms ease,
padding 160ms ease,
transform 160ms ease;
}
.item-row:hover,
.item-row:focus-visible,
.item-row.active {
margin: 0 -9px;
padding-right: 14px;
padding-left: 14px;
border-radius: 12px;
background: rgba(255, 255, 255, 0.75);
outline: none;
transform: translateX(2px);
}
.swatch {
grid-row: 1 / span 3;
align-self: start;
width: 10px;
height: 10px;
margin-top: 4px;
border-radius: 3px;
box-shadow: 0 0 0 3px rgba(23, 59, 56, 0.05);
}
.item-copy {
min-width: 0;
}
.item-copy strong {
display: block;
margin-bottom: 2px;
font-size: 14px;
letter-spacing: -0.01em;
}
.item-copy small {
color: var(--ink-soft);
font-size: 10px;
}
.item-delta {
align-self: start;
color: var(--coral);
font-size: 14px;
font-weight: 850;
white-space: nowrap;
}
.item-delta small {
display: block;
margin-top: 2px;
color: var(--ink-soft);
font-size: 8px;
font-weight: 700;
text-align: right;
}
.price-compare {
grid-column: 2 / 4;
display: flex;
align-items: center;
gap: 8px;
color: var(--ink-soft);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.price-compare span:nth-child(2) {
color: #a5b4af;
}
.price-compare span:last-child {
color: var(--ink);
font-weight: 750;
}
.contribution-track {
grid-column: 2 / 4;
height: 4px;
overflow: hidden;
margin-top: 5px;
border-radius: 99px;
background: #e2ddd3;
}
.contribution-track span {
display: block;
height: 100%;
border-radius: inherit;
background: var(--coral);
transform-origin: left;
transition: width 500ms cubic-bezier(0.22, 1, 0.36, 1);
}
.audit {
margin-top: 18px;
padding: 15px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.48);
}
.audit-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
font-size: 11px;
font-weight: 850;
}
.audit-title::before {
content: "=";
display: grid;
place-items: center;
width: 23px;
height: 23px;
border-radius: 7px;
background: var(--ink);
color: white;
font-size: 14px;
}
.audit code {
display: block;
overflow-wrap: anywhere;
color: var(--ink-soft);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
line-height: 1.75;
}
.audit code + code {
margin-top: 5px;
padding-top: 5px;
border-top: 1px dashed var(--line);
}
.method {
display: flex;
gap: 11px;
margin-top: 13px;
color: var(--ink-soft);
font-size: 10px;
line-height: 1.5;
}
.method strong {
display: block;
color: var(--ink);
font-size: 11px;
}
.method p {
margin: 3px 0 0;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 980px) {
.app {
height: auto;
min-height: 100vh;
}
.main {
display: block;
}
#stage {
height: 61vh;
min-height: 460px;
}
aside {
border-top: 1px solid var(--line);
border-left: 0;
overflow: visible;
}
.panel-content {
max-width: 720px;
margin: 0 auto;
}
}
@media (max-width: 620px) {
.header {
align-items: flex-start;
padding: 16px;
}
.brand-mark {
width: 38px;
height: 38px;
}
.brand-mark::before {
left: 7px;
top: 7px;
}
.brand-mark::after {
right: 6px;
bottom: 6px;
}
.header-note {
display: none;
}
h1 {
font-size: 24px;
}
#stage {
height: 56vh;
min-height: 410px;
}
.stage-top {
top: 12px;
left: 12px;
}
.stage-bottom {
left: 12px;
bottom: 12px;
}
.market-legend {
gap: 8px;
padding: 8px 9px;
}
.market-legend .divider,
.market-legend .units {
display: none;
}
.stage-controls {
right: 12px;
bottom: 12px;
}
#controlHint {
display: none;
}
aside {
padding: 22px 17px 28px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<div class="app">
<header class="header">
<div class="title-block">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<p class="eyebrow">Fixed consumption baskets</p>
<h1>One basket. Two price tags.</h1>
</div>
</div>
<div class="header-note" id="fixedUnitsNote">
9 units · quantities fixed
</div>
</header>
<main class="main">
<section id="stage" aria-label="Interactive 3D comparison of two identical checkout baskets">
<div class="stage-top">
<span></span>
Live price comparison
</div>
<div class="stage-bottom">
<div class="market-legend">
<span><i class="a"></i> Meridian</span>
<span class="divider"></span>
<span><i class="b"></i> Corner 24</span>
<span class="divider"></span>
<span class="units">9 fixed units</span>
</div>
</div>
<div class="stage-controls">
<span id="controlHint">Drag to orbit · scroll to zoom</span>
<button id="resetView" type="button">Reset view</button>
</div>
</section>
<aside aria-label="Price difference breakdown">
<div class="panel-content">
<div class="panel-heading">
<p class="eyebrow">Cost decomposition</p>
<h2>The gap, item by item.</h2>
<p>
The quantities never move. Each row shows exactly how one
unchanged unit group contributes to the final difference.
</p>
</div>
<div class="summary">
<div class="summary-grid">
<div class="market-total">
<small>Meridian</small>
<strong id="totalA">$0.00</strong>
</div>
<div class="summary-arrow" aria-hidden="true">→</div>
<div class="market-total">
<small>Corner 24</small>
<strong id="totalB">$0.00</strong>
</div>
</div>
<div class="summary-delta">
<strong id="totalDelta">+$0.00</strong>
<span id="percentHigher">0% higher</span>
</div>
</div>
<div class="section-label">
Item contribution
<span>to the total gap</span>
</div>
<div id="itemList" class="item-list"></div>
<div class="audit">
<div class="audit-title">Fixed-quantity audit</div>
<code id="auditA"></code>
<code id="auditB"></code>
</div>
<div class="method">
<div aria-hidden="true">∑</div>
<div>
<strong>Contribution = quantity × (price B − price A)</strong>
<p>
Hover a row to locate the same goods on both tables.
Click a row or an item to pin its highlight.
</p>
</div>
</div>
<p id="interactionStatus" class="sr-only" aria-live="polite"></p>
</div>
</aside>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const ITEMS = [
{
id: "flour",
name: "Flour",
unit: "bags",
quantity: 2,
priceA: 2.40,
priceB: 2.80,
color: "#d7a65e",
layout: { x: -0.76, z: -0.23 }
},
{
id: "milk",
name: "Milk",
unit: "cartons",
quantity: 2,
priceA: 1.60,
priceB: 1.95,
color: "#6f9db5",
layout: { x: 0.20, z: -0.28 }
},
{
id: "coffee",
name: "Coffee",
unit: "tin",
quantity: 1,
priceA: 8.50,
priceB: 10.20,
color: "#cf6b4e",
layout: { x: 0.79, z: 0.27 }
},
{
id: "apples",
name: "Apples",
unit: "each",
quantity: 4,
priceA: 0.75,
priceB: 0.95,
color: "#d95745",
layout: { x: -0.52, z: 0.34 }
}
];
const MARKET_A = {
title: "MERIDIAN",
subtitle: "MARKET A · UNIT PRICE LAB",
accent: "#79aa99"
};
const MARKET_B = {
title: "CORNER 24",
subtitle: "MARKET B · UNIT PRICE LAB",
accent: "#e96d50"
};
const totalA = ITEMS.reduce(
(sum, item) => sum + item.quantity * item.priceA,
0
);
const totalB = ITEMS.reduce(
(sum, item) => sum + item.quantity * item.priceB,
0
);
const totalDifference = totalB - totalA;
const totalUnits = ITEMS.reduce((sum, item) => sum + item.quantity, 0);
const money = (value) => `$${value.toFixed(2)}`;
document.getElementById("totalA").textContent = money(totalA);
document.getElementById("totalB").textContent = money(totalB);
document.getElementById("totalDelta").textContent = `+${money(totalDifference)}`;
document.getElementById("percentHigher").textContent =
`${((totalDifference / totalA) * 100).toFixed(1)}% higher`;
document.getElementById("fixedUnitsNote").textContent =
`${totalUnits} units · quantities fixed`;
const itemList = document.getElementById("itemList");
const interactionStatus = document.getElementById("interactionStatus");
const itemRows = new Map();
for (const item of ITEMS) {
const contribution =
item.quantity * (item.priceB - item.priceA);
const contributionPercent =
(contribution / totalDifference) * 100;
const row = document.createElement("button");
row.type = "button";
row.className = "item-row";
row.dataset.item = item.id;
row.setAttribute(
"aria-label",
`${item.name}: ${item.quantity} ${item.unit} fixed. ` +
`Unit price ${money(item.priceA)} at Meridian and ${money(item.priceB)} ` +
`at Corner 24. Contribution ${money(contribution)}.`
);
row.innerHTML = `
<span class="swatch" style="background:${item.color}"></span>
<span class="item-copy">
<strong>${item.name}</strong>
<small>${item.quantity} ${item.unit} · quantity fixed</small>
</span>
<span class="item-delta">
+${money(contribution)}
<small>${contributionPercent.toFixed(1)}% of gap</small>
</span>
<span class="price-compare">
<span>A ${money(item.priceA)}</span>
<span>→</span>
<span>B ${money(item.priceB)}</span>
</span>
<span class="contribution-track">
<span style="width:${contributionPercent}%"></span>
</span>
`;
itemList.appendChild(row);
itemRows.set(item.id, row);
}
const buildAudit = (isA) =>
ITEMS.map(
(item) =>
`${item.quantity}×${item.priceA.toFixed(2)}` +
`${isA ? "" : ` / ${item.quantity}×${item.priceB.toFixed(2)}`}`
).join(" + ");
document.getElementById("auditA").textContent =
`${buildAudit(true)} = ${totalA.toFixed(2)}`;
document.getElementById("auditB").textContent =
`${buildAudit(false)} = ${totalB.toFixed(2)}`;
// ------------------------------------------------------------------
// Scene
// ------------------------------------------------------------------
const stage = document.getElementById("stage");
const reduceMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e9e3d8");
scene.fog = new THREE.Fog("#e9e3d8", 13, 26);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 60);
const cameraTarget = new THREE.Vector3(0, 1.15, 0);
const spherical = new THREE.Spherical(9.8, 1.17, 0);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Two checkout tables holding identical baskets at different prices"
);
renderer.domElement.setAttribute("aria-describedby", "controlHint");
renderer.domElement.tabIndex = 0;
stage.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
"#fffaf0",
"#9a8d78",
2.15
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight("#fff5df", 3.25);
keyLight.position.set(-5, 9, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0002;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight("#b8d8d0", 1.15);
fillLight.position.set(6, 4, 1);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: "#e9e3d8",
roughness: 0.97,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? false
});
const materials = {
counter: material("#315a54"),
counterTop: material("#d7c29e"),
counterEdge: material("#eadfc8"),
tray: material("#f4edde"),
trayInset: material("#e2d7c3"),
flour: material("#e8d4a9"),
flourLabel: material("#315a54"),
flourStripe: material("#d7a65e"),
milk: material("#f7f2e5"),
milkStripe: material("#6f9db5"),
coffee: material("#b9563f"),
coffeeBand: material("#173b38"),
coffeeLid: material("#d7a65e"),
apple: material("#cf503d"),
appleLeaf: material("#66854b"),
stem: material("#73513b"),
boardFrame: material("#173b38"),
boardPost: material("#294d48")
};
function roundedBox(width, height, depth, radius, mat) {
const r = Math.min(
radius,
width * 0.49,
depth * 0.49
);
const x = -width / 2;
const y = -depth / 2;
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + depth - r);
shape.quadraticCurveTo(
x + width,
y + depth,
x + width - r,
y + depth
);
shape.lineTo(x + r, y + depth);
shape.quadraticCurveTo(x, y + depth, x, y + r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: height,
bevelEnabled: true,
bevelSegments: 2,
steps: 1,
bevelSize: Math.min(0.035, height * 0.18),
bevelThickness: Math.min(0.035, height * 0.18),
curveSegments: 8
});
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
return new THREE.Mesh(geometry, mat);
}
function enableShadows(object) {
object.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
}
function makeFlour() {
const group = new THREE.Group();
const body = roundedBox(
0.48,
0.60,
0.24,
0.045,
materials.flour
);
body.position.y = 0;
group.add(body);
const label = new THREE.Mesh(
new THREE.BoxGeometry(0.35, 0.18, 0.025),
materials.flourLabel
);
label.position.set(0, 0.32, 0.132);
group.add(label);
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.35, 0.045, 0.028),
materials.flourStripe
);
stripe.position.set(0, 0.25, 0.149);
group.add(stripe);
const fold = roundedBox(
0.51,
0.075,
0.255,
0.025,
materials.flour
);
fold.position.y = 0.60;
group.add(fold);
return group;
}
function makeMilk() {
const group = new THREE.Group();
const body = roundedBox(
0.35,
0.56,
0.30,
0.035,
materials.milk
);
body.position.y = 0;
group.add(body);
const roof = new THREE.Mesh(
new THREE.CylinderGeometry(0, 0.27, 0.18, 4),
materials.milk
);
roof.rotation.y = Math.PI / 4;
roof.position.y = 0.56;
group.add(roof);
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.355, 0.12, 0.022),
materials.milkStripe
);
stripe.position.set(0, 0.27, 0.158);
group.add(stripe);
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.07, 12),
materials.milkStripe
);
cap.position.y = 0.75;
group.add(cap);
return group;
}
function makeCoffee() {
const group = new THREE.Group();
const can = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.22, 0.54, 28),
materials.coffee
);
can.position.y = 0.27;
group.add(can);
const band = new THREE.Mesh(
new THREE.CylinderGeometry(0.223, 0.223, 0.17, 28),
materials.coffeeBand
);
band.position.y = 0.28;
group.add(band);
const lid = new THREE.Mesh(
new THREE.CylinderGeometry(0.235, 0.235, 0.055, 28),
materials.coffeeLid
);
lid.position.y = 0.56;
group.add(lid);
return group;
}
function makeApple() {
const group = new THREE.Group();
const apple = new THREE.Mesh(
new THREE.SphereGeometry(0.135, 18, 14),
materials.apple
);
apple.scale.set(1, 0.92, 1);
apple.position.y = 0.135;
group.add(apple);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.012, 0.016, 0.075, 8),
materials.stem
);
stem.position.y = 0.285;
stem.rotation.z = -0.18;
group.add(stem);
const leaf = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 10, 6),
materials.appleLeaf
);
leaf.scale.set(1.25, 0.25, 0.55);
leaf.position.set(0.05, 0.30, 0);
leaf.rotation.z = 0.28;
group.add(leaf);
return group;
}
function makeItem(item) {
const group = new THREE.Group();
const pieceOffsets = {
flour: [
[-0.27, 0.01],
[0.27, -0.01]
],
milk: [
[-0.23, 0.02],
[0.23, -0.02]
],
coffee: [[0, 0]],
apples: [
[-0.17, -0.15],
[0.17, -0.15],
[-0.17, 0.15],
[0.17, 0.15]
]
};
for (const [offsetX, offsetZ] of pieceOffsets[item.id]) {
let piece;
if (item.id === "flour") piece = makeFlour();
else if (item.id === "milk") piece = makeMilk();
else if (item.id === "coffee") piece = makeCoffee();
else piece = makeApple();
piece.position.x = offsetX;
piece.position.z = offsetZ;
group.add(piece);
}
const ringRadius = {
flour: 0.43,
milk: 0.40,
coffee: 0.31,
apples: 0.40
}[item.id];
const ringMaterial = new THREE.MeshBasicMaterial({
color: item.color,
transparent: true,
opacity: 0,
depthWrite: false,
toneMapped: false
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(ringRadius, 0.018, 8, 56),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.02;
ring.userData.isRing = true;
group.add(ring);
group.userData.ring = ring;
group.userData.targetScale = 1;
group.userData.currentScale = 1;
enableShadows(group);
ring.castShadow = false;
ring.receiveShadow = false;
return group;
}
const itemInstances = new Map(
ITEMS.map((item) => [item.id, []])
);
const pickableMeshes = [];
function makeCheckoutTable(centerX, accentColor) {
const group = new THREE.Group();
group.position.x = centerX;
const body = roundedBox(
3.42,
0.66,
2.04,
0.16,
materials.counter
);
body.position.y = 0.04;
group.add(body);
const top = roundedBox(
3.62,
0.16,
2.24,
0.13,
materials.counterTop
);
top.position.y = 0.68;
group.add(top);
const frontInset = new THREE.Mesh(
new THREE.BoxGeometry(2.54, 0.28, 0.055),
material("#234944")
);
frontInset.position.set(0, 0.36, 1.025);
group.add(frontInset);
const accent = new THREE.Mesh(
new THREE.BoxGeometry(2.36, 0.055, 0.065),
material(accentColor)
);
accent.position.set(0, 0.42, 1.057);
group.add(accent);
const tray = roundedBox(
2.98,
0.095,
1.66,
0.17,
materials.tray
);
tray.position.y = 0.84;
group.add(tray);
const trayInset = roundedBox(
2.76,
0.025,
1.44,
0.13,
materials.trayInset
);
trayInset.position.y = 0.928;
group.add(trayInset);
for (const item of ITEMS) {
const instance = makeItem(item);
instance.position.set(
item.layout.x,
0.955,
item.layout.z
);
instance.traverse((child) => {
if (
child.isMesh &&
!child.userData.isRing
) {
child.userData.itemId = item.id;
pickableMeshes.push(child);
}
});
group.add(instance);
itemInstances.get(item.id).push(instance);
}
enableShadows(group);
scene.add(group);
return group;
}
makeCheckoutTable(-2.45, MARKET_A.accent);
makeCheckoutTable(2.45, MARKET_B.accent);
// ------------------------------------------------------------------
// Physical price boards
// ------------------------------------------------------------------
function canvasRoundRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function createPriceBoard(market, centerX, prices, total) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 768;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#173b38";
ctx.fillRect(0, 0, canvas.width, canvas.height);
canvasRoundRect(ctx, 18, 18, 988, 732, 34);
ctx.fillStyle = "#1b423d";
ctx.fill();
ctx.fillStyle = market.accent;
ctx.fillRect(18, 18, 988, 12);
ctx.textAlign = "left";
ctx.textBaseline = "alphabetic";
ctx.fillStyle = "#fffaf0";
ctx.font = "800 56px system-ui, sans-serif";
ctx.fillText(market.title, 58, 94);
ctx.fillStyle = market.accent;
ctx.font = "800 25px system-ui, sans-serif";
ctx.fillText(market.subtitle, 60, 135);
ctx.strokeStyle = "rgba(255,255,255,0.13)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(55, 164);
ctx.lineTo(969, 164);
ctx.stroke();
ctx.fillStyle = "#9eb9b0";
ctx.font = "700 22px system-ui, sans-serif";
ctx.fillText("ITEM", 90, 205);
ctx.textAlign = "center";
ctx.fillText("QTY", 570, 205);
ctx.textAlign = "right";
ctx.fillText("UNIT PRICE", 938, 205);
const rowY = [270, 362, 454, 546];
ITEMS.forEach((item, index) => {
const y = rowY[index];
ctx.textAlign = "left";
ctx.fillStyle = item.color;
ctx.beginPath();
ctx.arc(63, y - 9, 10, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#f8f4e9";
ctx.font = "750 31px system-ui, sans-serif";
ctx.fillText(item.name.toUpperCase(), 90, y);
ctx.textAlign = "center";
ctx.fillStyle = "#abc2ba";
ctx.font = "650 28px system-ui, sans-serif";
ctx.fillText(String(item.quantity), 570, y);
ctx.textAlign = "right";
ctx.fillStyle = "#ffffff";
ctx.font = "800 32px system-ui, sans-serif";
ctx.fillText(money(prices[item.id]), 938, y);
ctx.strokeStyle = "rgba(255,255,255,0.08)";
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(55, y + 28);
ctx.lineTo(969, y + 28);
ctx.stroke();
});
canvasRoundRect(ctx, 54, 596, 916, 116, 22);
ctx.fillStyle = "#102f2c";
ctx.fill();
ctx.textAlign = "left";
ctx.fillStyle = "#aec6bd";
ctx.font = "750 23px system-ui, sans-serif";
ctx.fillText("BASKET TOTAL", 84, 645);
ctx.fillStyle = "#aec6bd";
ctx.font = "500 19px system-ui, sans-serif";
ctx.fillText("Σ fixed quantity × unit price", 84, 681);
ctx.textAlign = "right";
ctx.fillStyle = market.accent;
ctx.font = "850 50px system-ui, sans-serif";
ctx.fillText(money(total), 938, 668);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const boardGroup = new THREE.Group();
boardGroup.position.set(centerX, 2.22, -1.24);
const backing = new THREE.Mesh(
new THREE.BoxGeometry(2.78, 2.08, 0.10),
materials.boardFrame
);
boardGroup.add(backing);
const face = new THREE.Mesh(
new THREE.PlaneGeometry(2.66, 1.995),
new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
})
);
face.position.z = 0.052;
boardGroup.add(face);
scene.add(boardGroup);
const post = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.075, 0.58, 12),
materials.boardPost
);
post.position.set(centerX, 1.02, -1.24);
post.castShadow = true;
scene.add(post);
}
createPriceBoard(
MARKET_A,
-2.45,
Object.fromEntries(ITEMS.map((item) => [item.id, item.priceA])),
totalA
);
createPriceBoard(
MARKET_B,
2.45,
Object.fromEntries(ITEMS.map((item) => [item.id, item.priceB])),
totalB
);
// ------------------------------------------------------------------
// Highlighting
// ------------------------------------------------------------------
let hoveredItem = null;
let pinnedItem = null;
function updateHighlight() {
const activeItem = hoveredItem ?? pinnedItem;
for (const item of ITEMS) {
const active = activeItem === item.id;
for (const instance of itemInstances.get(item.id)) {
instance.userData.targetScale = active ? 1.13 : 1;
}
const row = itemRows.get(item.id);
row.classList.toggle("active", active);
row.setAttribute("aria-pressed", String(pinnedItem === item.id));
}
}
function setHoveredItem(id) {
if (hoveredItem === id) return;
hoveredItem = id;
updateHighlight();
}
function togglePinnedItem(id) {
pinnedItem = pinnedItem === id ? null : id;
updateHighlight();
if (pinnedItem) {
const item = ITEMS.find((candidate) => candidate.id === id);
interactionStatus.textContent =
`${item.name} highlighted on both checkout tables.`;
} else {
interactionStatus.textContent = "Highlight cleared.";
}
}
for (const item of ITEMS) {
const row = itemRows.get(item.id);
row.addEventListener("pointerenter", () => setHoveredItem(item.id));
row.addEventListener("pointerleave", () => setHoveredItem(null));
row.addEventListener("focus", () => setHoveredItem(item.id));
row.addEventListener("blur", () => setHoveredItem(null));
row.addEventListener("click", () => togglePinnedItem(item.id));
}
// ------------------------------------------------------------------
// Direct camera controls — no external controls addon
// ------------------------------------------------------------------
let userAdjustedCamera = false;
let fittedRadius = 9.8;
function updateCamera() {
spherical.set(
spherical.radius,
THREE.MathUtils.clamp(spherical.phi, 0.76, 1.39),
THREE.MathUtils.clamp(spherical.theta, -0.72, 0.72)
);
camera.position
.setFromSpherical(spherical)
.add(cameraTarget);
camera.lookAt(cameraTarget);
}
function fitCameraToStage() {
const width = stage.clientWidth;
const height = stage.clientHeight;
if (!width || !height) return;
const aspect = width / height;
renderer.setSize(width, height, false);
camera.aspect = aspect;
if (aspect < 0.95) {
camera.fov = 48;
fittedRadius = 12.65;
} else if (aspect < 1.35) {
camera.fov = 42;
fittedRadius = 11.1;
} else {
camera.fov = 38;
fittedRadius = 9.8;
}
camera.updateProjectionMatrix();
if (!userAdjustedCamera) {
spherical.radius = fittedRadius;
}
updateCamera();
}
const resizeObserver = new ResizeObserver(fitCameraToStage);
resizeObserver.observe(stage);
fitCameraToStage();
const drag = {
active: false,
pointerId: null,
lastX: 0,
lastY: 0,
moved: false
};
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function getItemUnderPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(pickableMeshes, false);
return hit.length ? hit[0].object.userData.itemId : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
drag.active = true;
drag.pointerId = event.pointerId;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
drag.moved = false;
renderer.domElement.setPointerCapture(event.pointerId);
setHoveredItem(null);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (drag.active) {
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
drag.lastX = event.clientX;
drag.lastY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
drag.moved = true;
}
spherical.theta -= dx * 0.005;
spherical.phi -= dy * 0.004;
userAdjustedCamera = true;
updateCamera();
return;
}
const itemId = getItemUnderPointer(event);
setHoveredItem(itemId);
renderer.domElement.style.cursor = itemId ? "pointer" : "grab";
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!drag.moved) {
const itemId = getItemUnderPointer(event);
if (itemId) togglePinnedItem(itemId);
}
drag.active = false;
if (
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
drag.active = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!drag.active) setHoveredItem(null);
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius + event.deltaY * 0.008,
7.4,
14.5
);
userAdjustedCamera = true;
updateCamera();
},
{ passive: false }
);
document.getElementById("resetView").addEventListener("click", () => {
userAdjustedCamera = false;
spherical.theta = 0;
spherical.phi = 1.17;
spherical.radius = fittedRadius;
pinnedItem = null;
hoveredItem = null;
updateHighlight();
updateCamera();
});
renderer.domElement.addEventListener("dblclick", () => {
userAdjustedCamera = false;
spherical.theta = 0;
spherical.phi = 1.17;
spherical.radius = fittedRadius;
updateCamera();
});
// ------------------------------------------------------------------
// Animation
// ------------------------------------------------------------------
const clock = new THREE.Clock();
function damp(current, target, lambda, dt) {
if (reduceMotion) return target;
return THREE.MathUtils.lerp(
current,
target,
1 - Math.exp(-lambda * dt)
);
}
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
for (const item of ITEMS) {
for (const instance of itemInstances.get(item.id)) {
const targetScale = instance.userData.targetScale;
instance.userData.currentScale = damp(
instance.userData.currentScale,
targetScale,
11,
dt
);
instance.scale.setScalar(
instance.userData.currentScale
);
const ring = instance.userData.ring;
const targetOpacity =
instance.userData.targetScale > 1.02 ? 0.9 : 0;
ring.material.opacity = damp(
ring.material.opacity,
targetOpacity,
12,
dt
);
}
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```