Prompt specification
Build or customize the Three.js 3D scene "Fixed Grocery Basket Model" 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: Fixed Grocery Basket Model
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/fixed-grocery-basket-model-x3177
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring price changes in fixed consumption baskets. Arrange a fixed count of bread, milk, and fruit tokens in one basket. Attach replaceable price cards while keeping quantities physically unchanged between comparisons. Low-poly.
Working Three.js Starter (fixed-grocery-basket-model-x3177):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Fixed Basket — Changing Prices</title>
<style>
:root {
color-scheme: light;
--ink: #242820;
--muted: #6d7167;
--paper: rgba(255, 252, 245, 0.91);
--line: rgba(55, 60, 48, 0.14);
--bread: #d99a45;
--milk: #4e83b7;
--fruit: #d86649;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background:
radial-gradient(circle at 38% 28%, #fffdf7 0, #f4eee3 42%, #e7dfd1 100%);
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.masthead {
position: fixed;
top: 26px;
left: 30px;
z-index: 4;
max-width: 370px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: #737568;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 23px;
height: 2px;
content: "";
background: #727663;
}
h1 {
margin: 0;
font-size: clamp(31px, 3.2vw, 52px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.masthead p {
max-width: 315px;
margin: 13px 0 0;
color: #707368;
font-size: 13px;
line-height: 1.55;
}
.locked {
position: fixed;
top: 28px;
right: 28px;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
border: 1px solid rgba(47, 65, 44, 0.17);
border-radius: 999px;
background: rgba(250, 248, 239, 0.72);
color: #506047;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
backdrop-filter: blur(12px);
pointer-events: none;
}
.locked::before {
width: 7px;
height: 7px;
border-radius: 50%;
content: "";
background: #69865a;
box-shadow: 0 0 0 4px rgba(105, 134, 90, 0.14);
}
.panel {
position: fixed;
top: 88px;
right: 24px;
z-index: 5;
width: 348px;
max-height: calc(100vh - 112px);
padding: 19px;
overflow: auto;
border: 1px solid rgba(57, 59, 47, 0.13);
border-radius: 22px;
background: var(--paper);
box-shadow:
0 24px 65px rgba(61, 53, 37, 0.13),
inset 0 1px 0 rgba(255, 255, 255, 0.8);
backdrop-filter: blur(18px);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
}
.panel-heading h2 {
margin: 0;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.mode-tag {
padding: 5px 8px;
border-radius: 7px;
background: #ece9df;
color: #62665a;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
}
.mode-switch {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 4px;
margin-bottom: 16px;
padding: 4px;
border-radius: 11px;
background: #eae7dd;
}
.mode-switch button {
min-height: 32px;
border: 0;
border-radius: 8px;
background: transparent;
color: #77796f;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.09em;
cursor: pointer;
transition: 160ms ease;
}
.mode-switch button.active {
background: #fffdf8;
color: #30362e;
box-shadow: 0 3px 12px rgba(50, 47, 38, 0.1);
}
.mode-switch button:disabled {
opacity: 0.38;
cursor: not-allowed;
}
.price-row {
padding: 14px 0;
border-top: 1px solid var(--line);
cursor: pointer;
transition: opacity 160ms ease;
}
.price-row:first-child {
border-top: 0;
}
.price-row.disabled {
opacity: 0.66;
}
.item-heading {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 8px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
background: var(--item-color);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--item-color) 16%, transparent);
}
.item-heading strong {
font-size: 13px;
letter-spacing: -0.01em;
}
.quantity {
padding: 4px 7px;
border-radius: 6px;
background: #eeece3;
color: #76796e;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.price-entry {
display: grid;
grid-template-columns: 18px 88px 1fr;
align-items: end;
gap: 2px;
margin-top: 10px;
}
.price-entry .currency {
align-self: center;
color: #72756b;
font-size: 16px;
font-weight: 750;
}
.price-entry input[type="number"] {
width: 88px;
padding: 2px 0 3px;
border: 0;
border-bottom: 1px solid #b9b9ae;
outline: 0;
background: transparent;
color: #252a24;
font-size: 26px;
font-weight: 780;
letter-spacing: -0.04em;
appearance: textfield;
}
.price-entry input[type="number"]::-webkit-inner-spin-button,
.price-entry input[type="number"]::-webkit-outer-spin-button {
margin: 0;
appearance: none;
}
.price-entry .unit {
align-self: center;
color: #85877d;
font-size: 10px;
font-weight: 700;
text-transform: uppercase;
}
.price-row input[type="range"] {
width: 100%;
height: 4px;
margin: 14px 0 9px;
border-radius: 10px;
outline: none;
background: #dedbd0;
accent-color: var(--item-color);
cursor: pointer;
}
.contribution {
display: flex;
justify-content: space-between;
color: #85877d;
font-size: 10px;
}
.contribution strong {
color: #4c5147;
font-size: 11px;
}
.total-card {
margin-top: 5px;
padding: 15px;
border-radius: 14px;
background: #2e352c;
color: #f9f5e9;
box-shadow: 0 12px 30px rgba(40, 47, 37, 0.16);
}
.total-label {
color: #bfc5b8;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.total-line {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-top: 5px;
}
#total {
font-size: 31px;
font-weight: 780;
letter-spacing: -0.05em;
}
#delta {
color: #c5cabc;
font-size: 10px;
font-weight: 750;
}
#delta.up {
color: #efaa8f;
}
#delta.down {
color: #a9c99e;
}
.snapshot-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 11px;
}
.snapshot-actions button,
.demo-button {
min-height: 36px;
border: 1px solid #d5d2c7;
border-radius: 9px;
background: #fffdf8;
color: #555a4f;
font-size: 10px;
font-weight: 800;
cursor: pointer;
transition: 150ms ease;
}
.snapshot-actions button:hover,
.demo-button:hover {
border-color: #a9ad9f;
transform: translateY(-1px);
}
.demo-button {
width: 100%;
margin-top: 7px;
border-color: transparent;
background: #e3dfd1;
}
.panel-note {
margin: 13px 2px 0;
color: #8a8c82;
font-size: 9px;
line-height: 1.55;
}
.hint {
position: fixed;
left: 30px;
bottom: 25px;
z-index: 3;
display: flex;
align-items: center;
gap: 9px;
color: rgba(63, 68, 58, 0.68);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
pointer-events: none;
}
.hint svg {
width: 17px;
height: 17px;
stroke: currentColor;
fill: none;
stroke-width: 1.6;
}
#toast {
position: fixed;
left: 50%;
bottom: 28px;
z-index: 10;
max-width: calc(100vw - 32px);
padding: 11px 16px;
border-radius: 999px;
background: rgba(43, 50, 41, 0.93);
color: #faf7ee;
font-size: 11px;
font-weight: 700;
text-align: center;
opacity: 0;
transform: translate(-50%, 12px);
transition: 220ms ease;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #f1ebdf;
color: #6f7468;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 780px) {
.masthead {
top: 17px;
left: 18px;
max-width: 230px;
}
h1 {
font-size: 31px;
}
.masthead p {
display: none;
}
.locked {
top: 17px;
right: 16px;
padding: 8px 10px;
font-size: 8px;
}
.panel {
top: auto;
right: 11px;
bottom: 11px;
left: 11px;
width: auto;
max-height: 42vh;
padding: 14px;
border-radius: 17px;
}
.panel-heading {
margin-bottom: 8px;
}
.mode-switch {
margin-bottom: 8px;
}
.price-row {
padding: 9px 0;
}
.price-entry {
margin-top: 4px;
}
.price-entry input[type="number"] {
font-size: 22px;
}
.price-row input[type="range"] {
margin: 9px 0 6px;
}
.hint {
display: none;
}
#toast {
bottom: calc(42vh + 24px);
}
}
</style>
</head>
<body>
<div id="viewport" aria-label="Interactive low-poly fixed consumption basket"></div>
<header class="masthead">
<div class="eyebrow">Market study / 01</div>
<h1>Fixed basket,<br />changing prices.</h1>
<p>
Twelve everyday items stay in the basket. Only the replaceable price
cards change between comparisons.
</p>
</header>
<div class="locked">Quantities locked · 12 items</div>
<aside class="panel" aria-label="Price card controls">
<div class="panel-heading">
<h2>Price cards</h2>
<span class="mode-tag" id="mode-tag">LIVE</span>
</div>
<div class="mode-switch" role="group" aria-label="Displayed card set">
<button type="button" data-mode="live" class="active">LIVE</button>
<button type="button" data-mode="A" disabled>SET A</button>
<button type="button" data-mode="B" disabled>SET B</button>
</div>
<div id="price-rows"></div>
<div class="total-card">
<div class="total-label">Basket total</div>
<div class="total-line">
<strong id="total">$19.65</strong>
<span id="delta">Base basket</span>
</div>
</div>
<div class="snapshot-actions">
<button type="button" id="capture-a">Capture → A</button>
<button type="button" id="capture-b">Capture → B</button>
</div>
<button type="button" class="demo-button" id="demo-shift">
Try a market price shift
</button>
<p class="panel-note">
Capture two price-card sets, then switch between them. The bread,
milk, and fruit tokens are never added, removed, or rearranged.
</p>
</aside>
<div class="hint">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M8 10V7a2 2 0 0 1 4 0v3" />
<path d="M12 10V5a2 2 0 0 1 4 0v5" />
<path d="M16 10V7a2 2 0 0 1 4 0v7c0 4-3 7-7 7h-1c-2.2 0-4.2-1.1-5.4-2.9L3.8 14a1.7 1.7 0 0 1 2.6-2.1L8 13.5V10Z" />
</svg>
Drag to orbit · Scroll to zoom · Click an item or card
</div>
<div id="toast" role="status" aria-live="polite"></div>
<div id="loading">Building the basket…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// State
// -------------------------------------------------------------------------
const catalog = {
bread: {
label: "BREAD",
name: "Bread",
quantity: 4,
color: "#d99a45",
min: 1,
max: 5,
step: 0.05
},
milk: {
label: "MILK",
name: "Milk",
quantity: 3,
color: "#4e83b7",
min: 0.5,
max: 4,
step: 0.05
},
fruit: {
label: "FRUIT",
name: "Fruit",
quantity: 5,
color: "#d86649",
min: 0.3,
max: 3,
step: 0.05
}
};
const draft = {
bread: 2.4,
milk: 1.85,
fruit: 0.9
};
const snapshots = {
A: null,
B: null
};
let displayedPrices = { ...draft };
let mode = "live";
let selectedCategory = "bread";
let toastTimer;
const money = (value) =>
new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
minimumFractionDigits: 2
}).format(value);
const basketTotal = (prices) =>
Object.keys(catalog).reduce(
(sum, key) => sum + prices[key] * catalog[key].quantity,
0
);
// -------------------------------------------------------------------------
// Renderer, camera, and scene
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);
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", "Three-dimensional fixed basket scene");
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xeee7dc, 18, 34);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
azimuth: 0.48,
polar: 1.02,
radius: 14.2,
target: new THREE.Vector3(0.72, 2.25, 0)
};
function updateCamera() {
const sinPolar = Math.sin(controls.polar);
camera.position.set(
controls.target.x + controls.radius * sinPolar * Math.sin(controls.azimuth),
controls.target.y + controls.radius * Math.cos(controls.polar),
controls.target.z + controls.radius * sinPolar * Math.cos(controls.azimuth)
);
camera.lookAt(controls.target);
}
const hemisphere = new THREE.HemisphereLight(0xfff7df, 0x879080, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d4, 3.4);
sun.position.set(-5, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0xbdd7e8, 1.2);
rimLight.position.set(8, 6, -8);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.ShadowMaterial({ opacity: 0.16 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.34;
ground.receiveShadow = true;
scene.add(ground);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(5.25, 5.65, 0.35, 12),
new THREE.MeshStandardMaterial({
color: 0xd9d0bf,
roughness: 0.96,
metalness: 0,
flatShading: true
})
);
pedestal.position.y = -0.15;
pedestal.receiveShadow = true;
pedestal.castShadow = true;
scene.add(pedestal);
// -------------------------------------------------------------------------
// Low-poly basket
// -------------------------------------------------------------------------
const basket = new THREE.Group();
scene.add(basket);
const wicker = new THREE.MeshStandardMaterial({
color: 0xb8783c,
roughness: 0.88,
metalness: 0,
flatShading: true
});
const wickerLight = new THREE.MeshStandardMaterial({
color: 0xd39a58,
roughness: 0.9,
metalness: 0,
flatShading: true
});
const wickerDark = new THREE.MeshStandardMaterial({
color: 0x85502b,
roughness: 0.92,
metalness: 0,
flatShading: true
});
function addBasketMesh(geometry, material, x, y, z) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
basket.add(mesh);
return mesh;
}
addBasketMesh(
new THREE.BoxGeometry(6.85, 0.34, 4.22),
wickerDark,
0,
0.2,
0
);
// Long sides: vertical slats.
for (let i = 0; i < 13; i++) {
const x = -3.15 + i * 0.525;
const material = i % 2 === 0 ? wicker : wickerLight;
addBasketMesh(
new THREE.BoxGeometry(0.25, 1.78, 0.25),
material,
x,
1.14,
-2.05
);
addBasketMesh(
new THREE.BoxGeometry(0.25, 1.78, 0.25),
material,
x,
1.14,
2.05
);
}
// Short sides: vertical slats.
for (let i = 0; i < 7; i++) {
const z = -1.68 + i * 0.56;
const material = i % 2 === 0 ? wickerLight : wicker;
addBasketMesh(
new THREE.BoxGeometry(0.25, 1.78, 0.27),
material,
-3.33,
1.14,
z
);
addBasketMesh(
new THREE.BoxGeometry(0.25, 1.78, 0.27),
material,
3.33,
1.14,
z
);
}
// Woven horizontal rails.
[0.62, 1.08, 1.54, 2.0].forEach((y, index) => {
const material = index % 2 === 0 ? wickerLight : wicker;
addBasketMesh(
new THREE.BoxGeometry(7.0, 0.17, 0.29),
material,
0,
y,
-2.05
);
addBasketMesh(
new THREE.BoxGeometry(7.0, 0.17, 0.29),
material,
0,
y,
2.05
);
addBasketMesh(
new THREE.BoxGeometry(0.29, 0.17, 4.37),
material,
-3.33,
y,
0
);
addBasketMesh(
new THREE.BoxGeometry(0.29, 0.17, 4.37),
material,
3.33,
y,
0
);
});
// Stronger top rim.
addBasketMesh(
new THREE.BoxGeometry(7.22, 0.25, 0.38),
wickerDark,
0,
2.31,
-2.05
);
addBasketMesh(
new THREE.BoxGeometry(7.22, 0.25, 0.38),
wickerDark,
0,
2.31,
2.05
);
addBasketMesh(
new THREE.BoxGeometry(0.38, 0.25, 4.48),
wickerDark,
-3.33,
2.31,
0
);
addBasketMesh(
new THREE.BoxGeometry(0.38, 0.25, 4.48),
wickerDark,
3.33,
2.31,
0
);
// Fixed-count plaque on the basket.
const plaqueCanvas = document.createElement("canvas");
plaqueCanvas.width = 700;
plaqueCanvas.height = 180;
const plaqueContext = plaqueCanvas.getContext("2d");
plaqueContext.fillStyle = "#f1dfb9";
plaqueContext.fillRect(0, 0, 700, 180);
plaqueContext.strokeStyle = "#7a512d";
plaqueContext.lineWidth = 12;
plaqueContext.strokeRect(8, 8, 684, 164);
plaqueContext.fillStyle = "#634726";
plaqueContext.textAlign = "center";
plaqueContext.font = "800 42px system-ui";
plaqueContext.fillText("FIXED BASKET · 12 ITEMS", 350, 76);
plaqueContext.font = "700 28px system-ui";
plaqueContext.fillText("4 BREAD • 3 MILK • 5 FRUIT", 350, 128);
const plaqueTexture = new THREE.CanvasTexture(plaqueCanvas);
plaqueTexture.colorSpace = THREE.SRGBColorSpace;
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(2.55, 0.65),
new THREE.MeshStandardMaterial({
map: plaqueTexture,
roughness: 0.9,
flatShading: true
})
);
plaque.position.set(0, 1.18, 2.235);
plaque.castShadow = true;
basket.add(plaque);
// -------------------------------------------------------------------------
// Product tokens — these are created once and never changed
// -------------------------------------------------------------------------
const pickables = [];
function registerProduct(group, category) {
group.userData.category = category;
group.traverse((child) => {
if (child.isMesh) {
child.userData.category = category;
pickables.push(child);
}
});
scene.add(group);
}
function createBread(x, y, z, rotation) {
const group = new THREE.Group();
const loaf = new THREE.Mesh(
new THREE.CapsuleGeometry(0.36, 1.05, 4, 8),
new THREE.MeshStandardMaterial({
color: 0xc98232,
roughness: 0.9,
flatShading: true
})
);
loaf.rotation.z = Math.PI / 2;
loaf.castShadow = true;
loaf.receiveShadow = true;
group.add(loaf);
const scoreMaterial = new THREE.MeshStandardMaterial({
color: 0xf0c477,
roughness: 1,
flatShading: true
});
[-0.42, 0, 0.42].forEach((scoreX, index) => {
const score = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.035, 0.7),
scoreMaterial
);
score.position.set(scoreX, 0.335, 0);
score.rotation.y = index % 2 ? -0.3 : 0.3;
score.castShadow = true;
group.add(score);
});
group.position.set(x, y, z);
group.rotation.y = rotation;
registerProduct(group, "bread");
}
function createMilk(x, y, z, rotation) {
const group = new THREE.Group();
const carton = new THREE.MeshStandardMaterial({
color: 0xf4f0dc,
roughness: 0.72,
flatShading: true
});
const blue = new THREE.MeshStandardMaterial({
color: 0x4d82b4,
roughness: 0.68,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.BoxGeometry(0.69, 0.92, 0.69),
carton
);
body.position.y = 0.46;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const roof = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.49, 0.32, 4),
carton
);
roof.position.y = 1.07;
roof.rotation.y = Math.PI / 4;
roof.castShadow = true;
group.add(roof);
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.52, 0.24, 0.025),
blue
);
stripe.position.set(0, 0.42, 0.358);
stripe.castShadow = true;
group.add(stripe);
const cap = new THREE.Mesh(
new THREE.BoxGeometry(0.17, 0.15, 0.17),
blue
);
cap.position.y = 1.29;
cap.castShadow = true;
group.add(cap);
group.position.set(x, y, z);
group.rotation.y = rotation;
registerProduct(group, "milk");
}
function createFruit(x, y, z, color, rotation) {
const group = new THREE.Group();
const fruit = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.43, 1),
new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
flatShading: true
})
);
fruit.scale.y = 0.92;
fruit.castShadow = true;
fruit.receiveShadow = true;
group.add(fruit);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.055, 0.24, 5),
new THREE.MeshStandardMaterial({
color: 0x725039,
roughness: 1,
flatShading: true
})
);
stem.position.y = 0.43;
stem.rotation.z = -0.12;
stem.castShadow = true;
group.add(stem);
const leaf = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.36, 4),
new THREE.MeshStandardMaterial({
color: 0x66884f,
roughness: 0.95,
flatShading: true
})
);
leaf.position.set(0.12, 0.51, 0);
leaf.rotation.z = Math.PI / 2.5;
leaf.castShadow = true;
group.add(leaf);
group.position.set(x, y, z);
group.rotation.y = rotation;
registerProduct(group, "fruit");
}
// Bread: 4
createBread(-1.85, 2.3, -0.9, 0.14);
createBread(-0.68, 2.28, -1.05, -0.2);
createBread(-1.58, 2.68, 0.58, 0.52);
createBread(-0.38, 2.62, 0.48, -0.38);
// Milk: 3
createMilk(0.72, 2.0, -1.03, -0.12);
createMilk(1.53, 1.97, -0.76, 0.22);
createMilk(1.08, 2.36, 0.7, -0.28);
// Fruit: 5
createFruit(2.22, 1.97, 0.62, 0xd75f40, 0.2);
createFruit(2.82, 2.12, -0.45, 0xe28b32, -0.3);
createFruit(1.92, 1.88, 1.27, 0xd75f40, 0.5);
createFruit(0.45, 1.78, 1.35, 0xe28b32, -0.25);
createFruit(-2.45, 1.86, 1.28, 0xd75f40, 0.38);
// -------------------------------------------------------------------------
// Replaceable 3D price cards
// -------------------------------------------------------------------------
const cardDefinitions = {
bread: {
position: new THREE.Vector3(-3.05, 4.86, -0.55),
anchor: new THREE.Vector3(-1.15, 2.72, 0.12)
},
milk: {
position: new THREE.Vector3(0.02, 5.48, -1.25),
anchor: new THREE.Vector3(1.0, 2.87, 0.28)
},
fruit: {
position: new THREE.Vector3(3.05, 4.86, 0.42),
anchor: new THREE.Vector3(2.05, 2.52, 0.62)
}
};
const cards = {};
const cardSprites = [];
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function makeCardTexture(category) {
const item = catalog[category];
const unitPrice = displayedPrices[category];
const contribution = unitPrice * item.quantity;
const modeLabel = mode === "live" ? "LIVE" : `SET ${mode}`;
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 280;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.save();
context.shadowColor = "rgba(57, 49, 34, 0.18)";
context.shadowBlur = 18;
context.shadowOffsetY = 9;
context.fillStyle = "#fffdf7";
roundedRect(context, 8, 8, 624, 264, 26);
context.fill();
context.restore();
context.fillStyle = item.color;
roundedRect(context, 8, 8, 14, 264, 7);
context.fill();
context.strokeStyle =
selectedCategory === category ? item.color : "rgba(53, 58, 48, 0.18)";
context.lineWidth = selectedCategory === category ? 5 : 2;
roundedRect(context, 10, 10, 620, 260, 25);
context.stroke();
context.textBaseline = "middle";
context.fillStyle = "#30362e";
context.font = "850 31px system-ui";
context.fillText(item.label, 43, 49);
context.fillStyle = "#ece8dc";
roundedRect(context, 444, 25, 148, 43, 12);
context.fill();
context.fillStyle = "#60655a";
context.font = "800 19px system-ui";
context.textAlign = "center";
context.fillText(`${item.quantity} FIXED`, 518, 47);
context.textAlign = "left";
context.fillStyle = "#2d332b";
context.font = "780 61px system-ui";
context.fillText(money(unitPrice), 40, 121);
context.fillStyle = "#85887e";
context.font = "750 18px system-ui";
context.fillText("/ UNIT", 225, 135);
context.strokeStyle = "rgba(56, 62, 50, 0.13)";
context.lineWidth = 2;
context.beginPath();
context.moveTo(42, 172);
context.lineTo(598, 172);
context.stroke();
context.fillStyle = "#85887e";
context.font = "700 18px system-ui";
context.fillText("BASKET SHARE", 43, 210);
context.fillStyle = "#394036";
context.font = "820 29px system-ui";
context.textAlign = "right";
context.fillText(money(contribution), 596, 210);
context.fillStyle = item.color;
context.font = "850 16px system-ui";
context.textAlign = "left";
context.fillText(modeLabel, 43, 246);
context.fillStyle = "#9a9c92";
context.font = "700 14px system-ui";
context.textAlign = "right";
context.fillText("REPLACEABLE CARD", 596, 246);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function updateCard(category, pulse = true) {
const card = cards[category];
const oldTexture = card.material.map;
const texture = makeCardTexture(category);
card.material.map = texture;
card.material.needsUpdate = true;
if (oldTexture) {
oldTexture.dispose();
}
if (pulse) {
card.userData.pulse = 1;
}
}
Object.entries(cardDefinitions).forEach(([category, definition]) => {
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.copy(definition.position);
sprite.scale.set(2.55, 1.115, 1);
sprite.renderOrder = 20;
sprite.userData.category = category;
sprite.userData.pulse = 0;
sprite.userData.baseScale = new THREE.Vector3(2.55, 1.115, 1);
scene.add(sprite);
cards[category] = sprite;
cardSprites.push(sprite);
const lineGeometry = new THREE.BufferGeometry().setFromPoints([
definition.anchor,
definition.position.clone().add(new THREE.Vector3(0, -0.52, 0))
]);
const line = new THREE.Line(
lineGeometry,
new THREE.LineBasicMaterial({
color: new THREE.Color(catalog[category].color),
transparent: true,
opacity: 0.58
})
);
scene.add(line);
const node = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.075, 1),
new THREE.MeshBasicMaterial({
color: catalog[category].color
})
);
node.position.copy(definition.anchor);
scene.add(node);
updateCard(category, false);
});
// -------------------------------------------------------------------------
// Interface
// -------------------------------------------------------------------------
const rowsContainer = document.getElementById("price-rows");
const rowElements = {};
Object.entries(catalog).forEach(([key, item]) => {
const row = document.createElement("section");
row.className = "price-row";
row.style.setProperty("--item-color", item.color);
row.innerHTML = `
<div class="item-heading">
<span class="swatch"></span>
<strong>${item.name}</strong>
<span class="quantity">${item.quantity} units · fixed</span>
</div>
<div class="price-entry">
<span class="currency">$</span>
<input
type="number"
min="${item.min}"
max="${item.max}"
step="${item.step}"
value="${draft[key].toFixed(2)}"
aria-label="${item.name} unit price"
/>
<span class="unit">per unit</span>
</div>
<input
type="range"
min="${item.min}"
max="${item.max}"
step="${item.step}"
value="${draft[key]}"
aria-label="${item.name} price slider"
/>
<div class="contribution">
<span>Basket contribution</span>
<strong></strong>
</div>
`;
rowsContainer.appendChild(row);
const numberInput = row.querySelector('input[type="number"]');
const rangeInput = row.querySelector('input[type="range"]');
const contribution = row.querySelector(".contribution strong");
rowElements[key] = {
row,
numberInput,
rangeInput,
contribution
};
const updatePrice = (value) => {
if (!Number.isFinite(value)) return;
const clamped = THREE.MathUtils.clamp(value, item.min, item.max);
draft[key] = Number(clamped.toFixed(2));
numberInput.value = draft[key].toFixed(2);
rangeInput.value = String(draft[key]);
if (mode === "live") {
displayedPrices[key] = draft[key];
updateCard(key);
syncSummary();
}
};
numberInput.addEventListener("input", () => {
updatePrice(Number.parseFloat(numberInput.value));
});
numberInput.addEventListener("blur", () => {
numberInput.value = draft[key].toFixed(2);
});
rangeInput.addEventListener("input", () => {
updatePrice(Number.parseFloat(rangeInput.value));
});
row.addEventListener("click", (event) => {
if (event.target.tagName !== "INPUT") {
selectCategory(key);
}
});
});
const totalElement = document.getElementById("total");
const deltaElement = document.getElementById("delta");
const modeTag = document.getElementById("mode-tag");
const modeButtons = [...document.querySelectorAll("[data-mode]")];
const toast = document.getElementById("toast");
function syncSummary() {
const total = basketTotal(displayedPrices);
totalElement.textContent = money(total);
Object.entries(catalog).forEach(([key, item]) => {
rowElements[key].contribution.textContent =
money(displayedPrices[key] * item.quantity);
});
deltaElement.className = "";
if (snapshots.A && mode !== "A") {
const difference = total - basketTotal(snapshots.A);
const sign = difference > 0 ? "+" : difference < 0 ? "−" : "";
deltaElement.textContent =
`${sign}${money(Math.abs(difference))} vs set A`;
deltaElement.classList.add(difference > 0 ? "up" : "down");
} else if (snapshots.A && mode === "A") {
deltaElement.textContent = "Comparison baseline";
} else {
deltaElement.textContent = "Base basket";
}
}
function syncControls() {
Object.entries(catalog).forEach(([key]) => {
const elements = rowElements[key];
const price = displayedPrices[key];
elements.numberInput.value = price.toFixed(2);
elements.rangeInput.value = String(price);
elements.numberInput.disabled = mode !== "live";
elements.rangeInput.disabled = mode !== "live";
elements.row.classList.toggle("disabled", mode !== "live");
});
modeTag.textContent = mode === "live" ? "LIVE" : `SET ${mode}`;
modeButtons.forEach((button) => {
const buttonMode = button.dataset.mode;
button.classList.toggle("active", buttonMode === mode);
if (buttonMode !== "live") {
button.disabled = !snapshots[buttonMode];
}
});
syncSummary();
}
function selectCategory(category) {
selectedCategory = category;
Object.entries(catalog).forEach(([key]) => {
rowElements[key].row.style.borderLeft =
key === category ? `3px solid ${catalog[key].color}` : "";
rowElements[key].row.style.paddingLeft = key === category ? "9px" : "";
rowElements[key].row.style.marginLeft = key === category ? "-12px" : "";
updateCard(key, key === category);
});
}
function setMode(nextMode) {
if (nextMode !== "live" && !snapshots[nextMode]) return;
mode = nextMode;
if (mode === "live") {
displayedPrices = { ...draft };
} else {
displayedPrices = { ...snapshots[mode] };
}
Object.keys(catalog).forEach((key) => updateCard(key));
syncControls();
showToast(
mode === "live"
? "Live price cards restored. Basket quantities remain fixed."
: `Set ${mode} price cards replaced. All 12 tokens remain in place.`
);
}
function captureSnapshot(snapshotName) {
snapshots[snapshotName] = { ...displayedPrices };
modeButtons.forEach((button) => {
if (button.dataset.mode === snapshotName) {
button.disabled = false;
}
});
showToast(`Current price cards captured as set ${snapshotName}.`);
}
function showToast(message) {
clearTimeout(toastTimer);
toast.textContent = message;
toast.classList.add("show");
toastTimer = setTimeout(() => {
toast.classList.remove("show");
}, 2600);
}
modeButtons.forEach((button) => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
document.getElementById("capture-a").addEventListener("click", () => {
captureSnapshot("A");
});
document.getElementById("capture-b").addEventListener("click", () => {
captureSnapshot("B");
});
document.getElementById("demo-shift").addEventListener("click", () => {
draft.bread = 2.65;
draft.milk = 1.79;
draft.fruit = 1.08;
mode = "live";
displayedPrices = { ...draft };
Object.keys(catalog).forEach((key) => updateCard(key));
syncControls();
showToast(
"Market shift applied: bread and fruit rose while milk fell slightly."
);
});
// -------------------------------------------------------------------------
// Direct camera controls — no external controls or addons
// -------------------------------------------------------------------------
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
const activePointers = new Map();
let dragged = false;
let pointerStart = { x: 0, y: 0 };
let previousPoint = { x: 0, y: 0 };
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
dragged = false;
pointerStart = { x: event.clientX, y: event.clientY };
previousPoint = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
const dx = event.clientX - previousPoint.x;
const dy = event.clientY - previousPoint.y;
if (
Math.abs(event.clientX - pointerStart.x) +
Math.abs(event.clientY - pointerStart.y) >
5
) {
dragged = true;
}
controls.azimuth -= dx * 0.006;
controls.polar = THREE.MathUtils.clamp(
controls.polar + dy * 0.005,
0.62,
1.36
);
previousPoint = { x: event.clientX, y: event.clientY };
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
activePointers.delete(event.pointerId);
if (dragged || activePointers.size > 0) return;
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(
[...cardSprites, ...pickables],
true
);
if (intersections.length) {
let object = intersections[0].object;
while (object && !object.userData.category) {
object = object.parent;
}
if (object?.userData.category) {
selectCategory(object.userData.category);
}
}
});
renderer.domElement.addEventListener("pointercancel", (event) => {
activePointers.delete(event.pointerId);
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.009,
10.5,
21
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
controls.azimuth = 0.48;
controls.polar = 1.02;
controls.radius = window.innerWidth < 780 ? 17 : 14.2;
showToast("Camera reset.");
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
if (width < 780) {
controls.target.set(0, 2.85, 0);
controls.radius = Math.max(controls.radius, 16.4);
} else {
controls.target.set(0.72, 2.25, 0);
}
}
window.addEventListener("resize", resize);
resize();
selectCategory("bread");
syncControls();
updateCamera();
function animate() {
requestAnimationFrame(animate);
updateCamera();
Object.values(cards).forEach((card) => {
card.userData.pulse = Math.max(0, card.userData.pulse - 0.035);
const selectedBoost =
card.userData.category === selectedCategory ? 0.025 : 0;
const targetScale = card.userData.baseScale.clone().multiplyScalar(
1 + selectedBoost + card.userData.pulse * 0.075
);
card.scale.lerp(targetScale, 0.14);
});
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```