Prompt specification
Build or customize the Three.js 3D scene "Festival Stall Break-Even Board" 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: Festival Stall Break-Even Board
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/festival-stall-break-even-board-x3139
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: festival stall break-even board. Create a fictional stall, unsold goods, and a visible cost-revenue balance. Let users change quantity sold and show break-even only under the displayed assumptions. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (festival-stall-break-even-board-x3139):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pixel Pie — Festival Stall Break-Even Board</title>
<style>
:root {
--ink: #173b3a;
--muted: #5e7772;
--cream: #fff9e9;
--paper: rgba(255, 250, 235, 0.94);
--green: #1c9b6c;
--green-dark: #0d6d4e;
--red: #e4574f;
--gold: #efb84e;
--line: rgba(23, 59, 58, 0.15);
--shadow: 0 18px 45px rgba(20, 53, 52, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #91d1cc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255,255,255,0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title-card {
position: absolute;
top: 22px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 19px 22px 18px;
border-radius: 18px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--green-dark);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 39px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.subtitle {
margin: 9px 0 0;
max-width: 340px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
#assumptions {
position: absolute;
top: 22px;
right: 24px;
width: 348px;
max-height: calc(100vh - 44px);
overflow: auto;
border-radius: 18px;
}
#assumptions summary {
padding: 17px 19px;
list-style: none;
cursor: pointer;
font-size: 14px;
font-weight: 850;
letter-spacing: -0.01em;
}
#assumptions summary::-webkit-details-marker { display: none; }
#assumptions summary::after {
content: "+";
float: right;
color: var(--green-dark);
font-size: 19px;
line-height: 16px;
}
#assumptions[open] summary::after { content: "−"; }
.assumption-body {
padding: 0 19px 19px;
border-top: 1px solid var(--line);
}
.assumption-list {
display: grid;
gap: 0;
margin: 10px 0 14px;
}
.assumption-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 16px;
padding: 8px 0;
border-bottom: 1px dashed var(--line);
font-size: 12px;
}
.assumption-row span:first-child { color: var(--muted); }
.assumption-row strong { white-space: nowrap; }
.formula {
padding: 12px 13px;
border-radius: 12px;
background: rgba(23, 59, 58, 0.055);
color: #294e4b;
font: 600 11px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.be-callout {
margin-top: 12px;
padding: 12px 13px;
border-left: 4px solid var(--gold);
border-radius: 9px;
background: rgba(239, 184, 78, 0.13);
font-size: 12px;
line-height: 1.45;
}
.be-callout strong {
display: block;
margin-bottom: 3px;
font-size: 14px;
}
.fine-print {
margin: 12px 0 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
#controls {
position: absolute;
left: 24px;
bottom: 24px;
width: min(650px, calc(100vw - 48px));
padding: 17px 19px 16px;
border-radius: 18px;
}
.control-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-bottom: 12px;
}
.control-title {
font-size: 13px;
font-weight: 850;
}
#status-pill {
max-width: 370px;
padding: 7px 10px;
border-radius: 999px;
background: rgba(228, 87, 79, 0.12);
color: #a33b36;
font-size: 11px;
font-weight: 800;
text-align: center;
}
#status-pill.profit {
background: rgba(28, 155, 108, 0.13);
color: var(--green-dark);
}
.slider-row {
display: grid;
grid-template-columns: 39px 1fr 39px;
align-items: center;
gap: 11px;
}
.step-button, .small-button {
border: 0;
border-radius: 10px;
background: var(--ink);
color: white;
cursor: pointer;
transition: transform 0.12s ease, background 0.12s ease;
}
.step-button {
width: 39px;
height: 39px;
font-size: 22px;
line-height: 1;
}
.step-button:hover, .small-button:hover {
transform: translateY(-1px);
background: var(--green-dark);
}
input[type="range"] {
width: 100%;
height: 7px;
border-radius: 99px;
accent-color: var(--green);
cursor: pointer;
}
.quantity-line {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 15px;
margin: 12px 0;
}
.quantity-line label {
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
#quantity-output {
font-size: 25px;
font-weight: 900;
letter-spacing: -0.04em;
}
#quantity-output small {
color: var(--muted);
font-size: 12px;
font-weight: 700;
letter-spacing: 0;
}
.metrics {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 8px;
}
.metric {
min-width: 0;
padding: 10px 11px;
border-radius: 11px;
background: rgba(23, 59, 58, 0.055);
}
.metric span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric strong {
display: block;
overflow: hidden;
font-size: 16px;
text-overflow: ellipsis;
white-space: nowrap;
}
.metric.revenue strong { color: var(--green-dark); }
.metric.cost strong { color: #ad4540; }
.metric.profit strong.positive { color: var(--green-dark); }
.metric.profit strong.negative { color: #b43d38; }
.control-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 12px;
}
.button-row { display: flex; gap: 8px; }
.small-button {
min-height: 34px;
padding: 0 12px;
font-size: 11px;
font-weight: 800;
}
.small-button.secondary {
background: rgba(23, 59, 58, 0.09);
color: var(--ink);
}
.small-button.secondary:hover {
background: rgba(23, 59, 58, 0.15);
}
#camera-hint {
color: var(--muted);
font-size: 10px;
text-align: right;
}
@media (max-width: 1050px) {
#title-card { width: 320px; }
#assumptions { width: 310px; }
#controls { width: min(600px, calc(100vw - 48px)); }
#status-pill { max-width: 300px; }
}
@media (max-width: 720px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.subtitle { display: none; }
#assumptions {
top: 108px;
right: 12px;
width: min(290px, calc(100vw - 24px));
max-height: 42vh;
}
#controls {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 14px;
}
.metrics { grid-template-columns: repeat(2, 1fr); }
#camera-hint { display: none; }
#status-pill { max-width: 220px; font-size: 10px; }
}
@media (max-height: 650px) and (min-width: 721px) {
#title-card { padding: 13px 16px; }
.subtitle { display: none; }
#assumptions { max-height: calc(100vh - 24px); top: 12px; right: 12px; }
#controls { left: 12px; bottom: 12px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel festival stall and break-even board"></canvas>
<main class="overlay">
<section id="title-card" class="panel">
<p class="eyebrow">Festival economics · voxel demo</p>
<h1>Pixel Pie Stall</h1>
<p class="subtitle">
Sell pixel pies, watch unsold stock disappear, and compare total revenue with
the complete cost of running this one stall.
</p>
</section>
<details id="assumptions" class="panel" open>
<summary>Displayed assumptions</summary>
<div class="assumption-body">
<div class="assumption-list">
<div class="assumption-row"><span>Sale price per pie</span><strong>€15.00</strong></div>
<div class="assumption-row"><span>Starting stock</span><strong>50 pies</strong></div>
<div class="assumption-row"><span>Stock bought upfront</span><strong>€5.00 each</strong></div>
<div class="assumption-row"><span>Stall fee</span><strong>€180.00</strong></div>
<div class="assumption-row"><span>Packaging per sale</span><strong>€1.00</strong></div>
<div class="assumption-row"><span>Unsold salvage / refund</span><strong>€0.00</strong></div>
</div>
<div class="formula">
Revenue(q) = €15q<br>
Cost(q) = €180 + (50 × €5) + €1q<br>
Net(q) = €14q − €430<br>
Break-even(q) = 430 ÷ 14
</div>
<div class="be-callout">
<strong>Scenario break-even: 30.71 pies</strong>
The first whole-item break-even quantity is <b>31 pies</b>.
This threshold applies only to the assumptions listed here.
</div>
<p class="fine-print">
The model includes the full upfront stock cost even when pies remain unsold.
It excludes taxes, additional staff, demand uncertainty, and any refund or
salvage value other than the €0 stated above.
</p>
</div>
</details>
<section id="controls" class="panel">
<div class="control-top">
<div class="control-title">Change quantity sold</div>
<div id="status-pill" aria-live="polite">Calculating…</div>
</div>
<div class="slider-row">
<button id="minus" class="step-button" aria-label="Sell one fewer pie">−</button>
<input id="quantity" type="range" min="0" max="50" value="31" step="1"
aria-label="Quantity sold">
<button id="plus" class="step-button" aria-label="Sell one more pie">+</button>
</div>
<div class="quantity-line">
<label for="quantity">Pies sold</label>
<div id="quantity-output">31 <small>/ 50 sold</small></div>
</div>
<div class="metrics">
<div class="metric revenue"><span>Revenue</span><strong id="revenue">€465</strong></div>
<div class="metric cost"><span>Total cost</span><strong id="cost">€461</strong></div>
<div class="metric profit"><span>Net balance</span><strong id="profit">+€4</strong></div>
<div class="metric"><span>Unsold</span><strong id="unsold">19</strong></div>
</div>
<div class="control-footer">
<div class="button-row">
<button id="demo" class="small-button">▶ Run sales</button>
<button id="reset-sales" class="small-button secondary">Reset sales</button>
<button id="reset-camera" class="small-button secondary">Reset view</button>
</div>
<div id="camera-hint">Drag to orbit · wheel to zoom</div>
</div>
</section>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Fixed, displayed scenario assumptions
// -------------------------------------------------------------------------
const PRICE = 15;
const STOCK = 50;
const UNIT_COST = 5;
const STALL_FEE = 180;
const PACKAGING = 1;
const SALVAGE = 0;
const revenueAt = q => q * PRICE;
const costAt = q =>
STALL_FEE +
STOCK * UNIT_COST -
(STOCK - q) * SALVAGE +
q * PACKAGING;
const profitAt = q => revenueAt(q) - costAt(q);
const exactBreakEven =
(STALL_FEE + STOCK * (UNIT_COST - SALVAGE)) /
(PRICE - SALVAGE - PACKAGING);
const wholeBreakEven = Math.ceil(exactBreakEven);
let quantity = wholeBreakEven;
let demoTimer = null;
const euro = new Intl.NumberFormat("en-IE", {
style: "currency",
currency: "EUR",
maximumFractionDigits: 0
});
const signedEuro = value =>
`${value >= 0 ? "+" : "−"}${euro.format(Math.abs(value))}`;
// -------------------------------------------------------------------------
// DOM references
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const slider = document.querySelector("#quantity");
const quantityOutput = document.querySelector("#quantity-output");
const revenueElement = document.querySelector("#revenue");
const costElement = document.querySelector("#cost");
const profitElement = document.querySelector("#profit");
const unsoldElement = document.querySelector("#unsold");
const statusPill = document.querySelector("#status-pill");
const demoButton = document.querySelector("#demo");
// -------------------------------------------------------------------------
// Renderer, scene, camera, lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x91d1cc);
scene.fog = new THREE.Fog(0x91d1cc, 24, 52);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const hemisphere = new THREE.HemisphereLight(0xdff7ff, 0x6d835b, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0c8, 3.1);
sun.position.set(-8, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x84cfff, 0.85);
fill.position.set(10, 7, -8);
scene.add(fill);
// -------------------------------------------------------------------------
// Voxel helpers
// -------------------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.0,
flatShading: true
}));
}
return materialCache.get(color);
}
function voxel(parent, width, height, depth, color, x, y, z, options = {}) {
const mesh = new THREE.Mesh(
cubeGeometry,
options.material || getMaterial(color)
);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function makeTextPlane(
text,
width,
height,
options = {}
) {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 1024;
textureCanvas.height = 256;
const context = textureCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const geometry = new THREE.PlaneGeometry(width, height);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(geometry, material);
mesh.renderOrder = 4;
function draw(value) {
context.clearRect(0, 0, textureCanvas.width, textureCanvas.height);
if (options.background) {
context.fillStyle = options.background;
context.fillRect(0, 0, textureCanvas.width, textureCanvas.height);
}
if (options.border) {
context.strokeStyle = options.border;
context.lineWidth = options.borderWidth || 10;
context.strokeRect(
options.borderWidth || 5,
options.borderWidth || 5,
textureCanvas.width - 2 * (options.borderWidth || 5),
textureCanvas.height - 2 * (options.borderWidth || 5)
);
}
context.fillStyle = options.color || "#ffffff";
context.textAlign = "center";
context.textBaseline = "middle";
context.font = `${options.weight || 800} ${options.fontSize || 82}px system-ui, sans-serif`;
context.fillText(
value,
textureCanvas.width / 2,
textureCanvas.height / 2 + (options.offsetY || 0),
950
);
texture.needsUpdate = true;
}
draw(text);
mesh.userData.setText = draw;
return mesh;
}
function makeTextSprite(text, width = 2.2, height = 0.65) {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = 512;
textureCanvas.height = 160;
const context = textureCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 5;
function draw(value) {
context.clearRect(0, 0, 512, 160);
context.fillStyle = "rgba(23,59,58,0.94)";
context.fillRect(0, 0, 512, 160);
context.fillStyle = "#fff7d6";
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "800 48px system-ui, sans-serif";
context.fillText(value, 256, 82, 470);
texture.needsUpdate = true;
}
draw(text);
sprite.userData.setText = draw;
return sprite;
}
// -------------------------------------------------------------------------
// Festival ground and environment
// -------------------------------------------------------------------------
const ground = voxel(scene, 28, 0.7, 20, 0x78b982, 0, -0.55, 0, {
castShadow: false
});
ground.receiveShadow = true;
voxel(scene, 28, 0.08, 5.2, 0xe7cf9c, 0, -0.17, 4.3, {
castShadow: false
});
for (let x = -11; x <= 11; x += 2.2) {
voxel(scene, 1.95, 0.025, 4.9, 0xf0d9a9, x, -0.115, 4.25, {
castShadow: false
});
}
// Back fence
for (let x = -12; x <= 12; x += 1.5) {
voxel(scene, 0.2, 1.8, 0.2, 0xf3e7c7, x, 0.55, -7.1);
}
voxel(scene, 24.5, 0.16, 0.18, 0xf3e7c7, 0, 0.6, -7.1);
voxel(scene, 24.5, 0.16, 0.18, 0xf3e7c7, 0, 1.25, -7.1);
// Blocky trees
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
voxel(tree, 0.48, 2.2, 0.48, 0x8c5a3c, 0, 0.8, 0);
voxel(tree, 2.2, 1.1, 2.2, 0x3e9b68, 0, 2.05, 0);
voxel(tree, 1.55, 1.0, 1.55, 0x52b878, 0, 2.85, 0);
voxel(tree, 1.1, 0.85, 1.1, 0x69c986, 0.25, 3.45, -0.1);
}
addTree(-9.5, -5.2, 1.2);
addTree(9.4, -5.4, 1.1);
addTree(-11.5, 2.2, 0.85);
addTree(11.2, 2.9, 0.9);
// Distant blocky clouds
function addCloud(x, y, z, scale = 1) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
scene.add(cloud);
voxel(cloud, 2.6, 0.7, 0.8, 0xf4fbf0, 0, 0, 0, { castShadow: false });
voxel(cloud, 1.2, 1.05, 0.85, 0xf4fbf0, -0.6, 0.45, 0, { castShadow: false });
voxel(cloud, 1.45, 1.35, 0.85, 0xf4fbf0, 0.65, 0.55, 0, { castShadow: false });
voxel(cloud, 1.0, 0.85, 0.8, 0xf4fbf0, 1.6, 0.2, 0, { castShadow: false });
}
addCloud(-7, 10.5, -11, 1.5);
addCloud(7.5, 11.7, -13, 1.2);
// -------------------------------------------------------------------------
// Fictional Pixel Pie stall
// -------------------------------------------------------------------------
const stall = new THREE.Group();
stall.position.set(-1.6, 0, 0.25);
scene.add(stall);
// Back wall and frame
voxel(stall, 6.35, 3.35, 0.25, 0x704c3c, 0, 1.85, -1.55);
for (let x = -3; x <= 3; x += 1) {
voxel(stall, 0.93, 3.4, 0.1, 0x845a43, x, 1.85, -1.39);
}
// Posts
for (const x of [-3.2, 3.2]) {
voxel(stall, 0.22, 4.0, 0.22, 0x563b32, x, 2.05, -1.5);
voxel(stall, 0.22, 4.0, 0.22, 0x563b32, x, 2.05, 1.75);
}
// Counter
voxel(stall, 6.35, 1.42, 1.8, 0x286f67, 0, 0.86, 0.72);
voxel(stall, 6.62, 0.2, 1.98, 0xf1c676, 0, 1.65, 0.72);
voxel(stall, 6.0, 0.18, 0.12, 0xe7ad54, 0, 1.24, 1.65);
// Shelf boards
voxel(stall, 6.0, 0.18, 0.95, 0xa56a43, 0, 2.42, -1.0);
voxel(stall, 6.0, 0.18, 0.95, 0xa56a43, 0, 3.22, -1.0);
// Voxel canopy with a stepped roof
for (let i = 0; i < 9; i++) {
const x = -3.28 + i * 0.82;
const centerLift = 0.62 * (1 - Math.abs(i - 4) / 4);
const color = i % 2 === 0 ? 0xe95f55 : 0xffedc3;
voxel(stall, 0.8, 0.34, 4.45, color, x, 4.42 + centerLift, 0.08);
voxel(stall, 0.8, 0.55, 0.27, color, x, 4.02, 2.23);
}
// Canopy side edging
for (let i = 0; i < 5; i++) {
const z = -1.7 + i * 0.9;
const lift = 0.62 * (1 - Math.abs(z) / 2.1);
voxel(stall, 0.25, 0.32, 0.85, i % 2 ? 0xffedc3 : 0xe95f55,
-3.55, 4.42 + lift, z);
voxel(stall, 0.25, 0.32, 0.85, i % 2 ? 0xffedc3 : 0xe95f55,
3.55, 4.42 + lift, z);
}
// Stall sign
voxel(stall, 4.8, 0.76, 0.18, 0x173b3a, 0, 4.02, 2.38);
const stallSign = makeTextPlane("PIXEL PIE STALL", 4.5, 0.58, {
color: "#fff1b8",
fontSize: 90
});
stallSign.position.set(0, 4.02, 2.485);
stall.add(stallSign);
// Price sign on counter
const priceSign = makeTextPlane("ONE PIE €15", 2.6, 0.5, {
color: "#fff7d6",
background: "#b94642",
fontSize: 82
});
priceSign.position.set(-1.55, 1.08, 1.665);
stall.add(priceSign);
// Cash register
voxel(stall, 0.72, 0.38, 0.65, 0x314b4d, 2.72, 1.94, 1.37);
voxel(stall, 0.78, 0.08, 0.72, 0xd9d8c8, 2.72, 2.16, 1.37);
const registerScreenMaterial = new THREE.MeshStandardMaterial({
color: 0x62d2b4,
emissive: 0x174f42,
emissiveIntensity: 0.7,
roughness: 0.5
});
voxel(stall, 0.5, 0.32, 0.09, 0xffffff, 2.72, 2.15, 1.74, {
material: registerScreenMaterial
});
// Crates beside the stall
for (const [x, z, color] of [
[-3.65, 0.5, 0xb77643],
[-3.65, -0.6, 0xc98a4e],
[3.65, 0.7, 0xb77643]
]) {
voxel(stall, 0.9, 0.75, 0.9, color, x, 0.45, z);
for (const offset of [-0.27, 0, 0.27]) {
voxel(stall, 0.08, 0.77, 0.94, 0x74452f, x + offset, 0.45, z);
}
}
// String of festival bulbs
for (let i = 0; i < 9; i++) {
const x = -2.8 + i * 0.7;
const y = 3.55 - Math.sin((i / 8) * Math.PI) * 0.22;
const bulbMaterial = new THREE.MeshStandardMaterial({
color: i % 2 ? 0xffdf70 : 0xff8c72,
emissive: i % 2 ? 0x9a6810 : 0x8a2c20,
emissiveIntensity: 1.3,
roughness: 0.35
});
voxel(stall, 0.13, 0.18, 0.13, 0xffffff, x, y, 1.85, {
material: bulbMaterial,
castShadow: false
});
}
// -------------------------------------------------------------------------
// Unsold inventory: 50 pixel pies on the counter and shelves
// -------------------------------------------------------------------------
const itemPositions = [];
// Counter items are removed first as sales rise.
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 8; column++) {
itemPositions.push({
x: -2.45 + column * 0.7,
y: 1.89,
z: 1.35 - row * 0.5
});
}
}
// Lower shelf, then upper shelf.
for (let row = 0; row < 2; row++) {
for (let column = 0; column < 13; column++) {
itemPositions.push({
x: -2.6 + column * (5.2 / 12),
y: row === 0 ? 2.67 : 3.47,
z: -1.0
});
}
}
const pieBodyGeometry = new THREE.BoxGeometry(0.31, 0.28, 0.31);
const pieTopGeometry = new THREE.BoxGeometry(0.23, 0.12, 0.23);
const pieBodies = new THREE.InstancedMesh(
pieBodyGeometry,
getMaterial(0xf4bd58),
STOCK
);
const pieTops = new THREE.InstancedMesh(
pieTopGeometry,
getMaterial(0xc94d4b),
STOCK
);
pieBodies.castShadow = true;
pieBodies.receiveShadow = true;
pieTops.castShadow = true;
pieTops.receiveShadow = true;
pieBodies.frustumCulled = false;
pieTops.frustumCulled = false;
stall.add(pieBodies, pieTops);
const unsoldSign = makeTextSprite("UNSOLD 19", 2.2, 0.68);
unsoldSign.position.set(3.25, 3.55, 0.4);
stall.add(unsoldSign);
// -------------------------------------------------------------------------
// Physical break-even board
// -------------------------------------------------------------------------
const board = new THREE.Group();
board.position.set(5.15, 0, -0.55);
scene.add(board);
voxel(board, 0.35, 1.5, 0.35, 0x664638, -1.85, 0.65, 0);
voxel(board, 0.35, 1.5, 0.35, 0x664638, 1.85, 0.65, 0);
voxel(board, 5.65, 4.95, 0.34, 0x214b47, 0, 3.23, 0);
voxel(board, 5.32, 4.62, 0.12, 0xfff3d2, 0, 3.23, 0.22);
const boardTitle = makeTextPlane("BREAK-EVEN BOARD", 4.75, 0.65, {
color: "#173b3a",
fontSize: 83
});
boardTitle.position.set(0, 5.25, 0.31);
board.add(boardTitle);
const chartBaseline = 1.55;
const chartMaxHeight = 3.15;
const chartMaxValue = 800;
const heightFor = value => (value / chartMaxValue) * chartMaxHeight;
const costBar = voxel(board, 1.25, 1, 0.44, 0xe4665d, -1.18, chartBaseline, 0.47);
const revenueBar = voxel(board, 1.25, 1, 0.44, 0x32b77d, 1.18, chartBaseline, 0.47);
const costName = makeTextPlane("COST", 1.3, 0.38, {
color: "#9b3f3a",
fontSize: 76
});
costName.position.set(-1.18, 1.12, 0.72);
board.add(costName);
const revenueName = makeTextPlane("REVENUE", 1.65, 0.38, {
color: "#116b4e",
fontSize: 76
});
revenueName.position.set(1.18, 1.12, 0.72);
board.add(revenueName);
const costValueLabel = makeTextPlane("€461", 1.35, 0.38, {
color: "#9b3f3a",
fontSize: 78
});
board.add(costValueLabel);
const revenueValueLabel = makeTextPlane("€465", 1.35, 0.38, {
color: "#116b4e",
fontSize: 78
});
board.add(revenueValueLabel);
// Horizontal break-even threshold based only on the displayed assumptions.
const breakEvenRevenue = exactBreakEven * PRICE;
const breakEvenY = chartBaseline + heightFor(breakEvenRevenue);
voxel(board, 4.25, 0.055, 0.12, 0xefb84e, 0, breakEvenY, 0.76);
const breakEvenLabel = makeTextPlane(`B/E ${exactBreakEven.toFixed(1)}`, 1.35, 0.35, {
color: "#9a6613",
fontSize: 66
});
breakEvenLabel.position.set(1.94, breakEvenY + 0.25, 0.78);
board.add(breakEvenLabel);
// Net balance plaque
const plaqueMaterial = new THREE.MeshStandardMaterial({
color: 0x2da875,
roughness: 0.75
});
voxel(board, 4.75, 0.61, 0.28, 0xffffff, 0, 0.77, 0.35, {
material: plaqueMaterial
});
const netLabel = makeTextPlane("NET +€4", 4.35, 0.42, {
color: "#ffffff",
fontSize: 82
});
netLabel.position.set(0, 0.77, 0.51);
board.add(netLabel);
// Small voxel scale beside the stall
const scaleGroup = new THREE.Group();
scaleGroup.position.set(-5.1, 0, 2.3);
scene.add(scaleGroup);
voxel(scaleGroup, 0.45, 1.7, 0.45, 0x60463b, 0, 0.75, 0);
voxel(scaleGroup, 1.8, 0.18, 0.45, 0xf0c275, 0, 1.55, 0);
voxel(scaleGroup, 1.35, 0.13, 0.3, 0xf5e5bd, 0, 1.68, 0);
voxel(scaleGroup, 0.28, 0.28, 0.28, 0xe4665d, -0.62, 1.88, 0);
voxel(scaleGroup, 0.28, 0.28, 0.28, 0x32b77d, 0.62, 1.88, 0);
const scaleLabel = makeTextPlane("BALANCE", 1.9, 0.38, {
color: "#173b3a",
fontSize: 76
});
scaleLabel.position.set(0, 0.36, 0.25);
scaleGroup.add(scaleLabel);
// -------------------------------------------------------------------------
// A few voxel festival visitors
// -------------------------------------------------------------------------
function addVisitor(x, z, shirt, skin, scale = 1) {
const visitor = new THREE.Group();
visitor.position.set(x, 0, z);
visitor.scale.setScalar(scale);
scene.add(visitor);
voxel(visitor, 0.7, 0.95, 0.42, shirt, 0, 1.05, 0);
voxel(visitor, 0.52, 0.52, 0.5, skin, 0, 1.77, 0);
voxel(visitor, 0.25, 0.65, 0.28, 0x304f60, -0.2, 0.34, 0);
voxel(visitor, 0.25, 0.65, 0.28, 0x304f60, 0.2, 0.34, 0);
voxel(visitor, 0.18, 0.72, 0.2, shirt, -0.48, 1.05, 0);
voxel(visitor, 0.18, 0.72, 0.2, shirt, 0.48, 1.05, 0);
voxel(visitor, 0.62, 0.12, 0.58, 0x6a4936, 0, 2.08, 0);
}
addVisitor(-4.8, 3.3, 0xe65f59, 0xd79b72, 1.05);
addVisitor(-2.9, 4.2, 0x4e78b7, 0x8f5e42, 0.85);
addVisitor(2.3, 3.6, 0xe4b64f, 0xe1ad85, 0.92);
// -------------------------------------------------------------------------
// UI and scene synchronization
// -------------------------------------------------------------------------
let currentCostHeight = heightFor(costAt(quantity));
let currentRevenueHeight = heightFor(revenueAt(quantity));
let targetCostHeight = currentCostHeight;
let targetRevenueHeight = currentRevenueHeight;
function updateInventory() {
const remaining = STOCK - quantity;
const dummy = new THREE.Object3D();
for (let i = 0; i < remaining; i++) {
const position = itemPositions[i];
dummy.position.set(position.x, position.y, position.z);
dummy.updateMatrix();
pieBodies.setMatrixAt(i, dummy.matrix);
dummy.position.set(position.x, position.y + 0.19, position.z);
dummy.updateMatrix();
pieTops.setMatrixAt(i, dummy.matrix);
}
pieBodies.count = remaining;
pieTops.count = remaining;
pieBodies.instanceMatrix.needsUpdate = true;
pieTops.instanceMatrix.needsUpdate = true;
unsoldSign.userData.setText(`UNSOLD ${remaining}`);
}
function updateBoard() {
const revenue = revenueAt(quantity);
const cost = costAt(quantity);
const profit = profitAt(quantity);
targetCostHeight = heightFor(cost);
targetRevenueHeight = heightFor(revenue);
costValueLabel.userData.setText(euro.format(cost));
revenueValueLabel.userData.setText(euro.format(revenue));
costValueLabel.position.set(-1.18, chartBaseline + targetCostHeight + 0.28, 0.73);
revenueValueLabel.position.set(1.18, chartBaseline + targetRevenueHeight + 0.28, 0.73);
netLabel.userData.setText(`NET ${signedEuro(profit)}`);
plaqueMaterial.color.set(profit >= 0 ? 0x2da875 : 0xdb5a53);
}
function updateUI() {
const revenue = revenueAt(quantity);
const cost = costAt(quantity);
const profit = profitAt(quantity);
const remaining = STOCK - quantity;
slider.value = String(quantity);
quantityOutput.innerHTML = `${quantity} <small>/ ${STOCK} sold</small>`;
revenueElement.textContent = euro.format(revenue);
costElement.textContent = euro.format(cost);
profitElement.textContent = signedEuro(profit);
profitElement.classList.toggle("positive", profit >= 0);
profitElement.classList.toggle("negative", profit < 0);
unsoldElement.textContent = String(remaining);
if (profit >= 0) {
statusPill.classList.add("profit");
statusPill.textContent =
`${signedEuro(profit)} above the scenario break-even threshold`;
} else {
statusPill.classList.remove("profit");
const moreNeeded = Math.max(0, Math.ceil(exactBreakEven - quantity));
statusPill.textContent =
`${signedEuro(profit)} · ${moreNeeded} more whole item${moreNeeded === 1 ? "" : "s"} to reach B/E`;
}
updateInventory();
updateBoard();
}
function stopDemo() {
if (demoTimer !== null) {
clearInterval(demoTimer);
demoTimer = null;
}
demoButton.textContent = "▶ Run sales";
}
function setQuantity(value, fromDemo = false) {
if (!fromDemo) stopDemo();
quantity = THREE.MathUtils.clamp(Math.round(value), 0, STOCK);
updateUI();
}
slider.addEventListener("input", event => {
setQuantity(Number(event.target.value));
});
document.querySelector("#minus").addEventListener("click", () => {
setQuantity(quantity - 1);
});
document.querySelector("#plus").addEventListener("click", () => {
setQuantity(quantity + 1);
});
document.querySelector("#reset-sales").addEventListener("click", () => {
setQuantity(0);
});
demoButton.addEventListener("click", () => {
if (demoTimer !== null) {
stopDemo();
return;
}
if (quantity >= STOCK) setQuantity(0, true);
demoButton.textContent = "Ⅱ Pause sales";
demoTimer = setInterval(() => {
if (quantity >= STOCK) {
stopDemo();
return;
}
setQuantity(quantity + 1, true);
}, 650);
});
// -------------------------------------------------------------------------
// Direct camera controls (no addons)
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0.45, 2.45, 0.15);
const homeRadius = window.innerWidth < 720 ? 27 : 18.5;
let cameraRadius = homeRadius;
let cameraAzimuth = 0.57;
let cameraPolar = 1.08;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
const sinPolar = Math.sin(cameraPolar);
camera.position.set(
cameraTarget.x + cameraRadius * sinPolar * Math.sin(cameraAzimuth),
cameraTarget.y + cameraRadius * Math.cos(cameraPolar),
cameraTarget.z + cameraRadius * sinPolar * Math.cos(cameraAzimuth)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraRadius = homeRadius;
cameraAzimuth = 0.57;
cameraPolar = 1.08;
updateCamera();
}
canvas.addEventListener("pointerdown", event => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraAzimuth -= deltaX * 0.006;
cameraPolar = THREE.MathUtils.clamp(
cameraPolar - deltaY * 0.005,
0.48,
1.42
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
10,
36
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
document.querySelector("#reset-camera").addEventListener("click", resetCamera);
window.addEventListener("keydown", event => {
const tag = document.activeElement?.tagName;
if (tag === "INPUT" || tag === "BUTTON") return;
if (event.key === "ArrowRight") {
event.preventDefault();
setQuantity(quantity + 1);
}
if (event.key === "ArrowLeft") {
event.preventDefault();
setQuantity(quantity - 1);
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.fov = width < 720 ? 56 : 42;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
function animate() {
const easing = 0.13;
currentCostHeight += (targetCostHeight - currentCostHeight) * easing;
currentRevenueHeight += (targetRevenueHeight - currentRevenueHeight) * easing;
costBar.scale.y = Math.max(0.001, currentCostHeight);
revenueBar.scale.y = Math.max(0.001, currentRevenueHeight);
costBar.position.y = chartBaseline + currentCostHeight / 2;
revenueBar.position.y = chartBaseline + currentRevenueHeight / 2;
renderer.render(scene, camera);
}
resize();
resetCamera();
updateUI();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```