Prompt specification
Build or customize the Three.js 3D scene "Two Workshops Under Variable Demand" 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 Workshops Under Variable Demand
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-workshops-under-variable-demand-x3140
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing fixed costs, variable costs, and break-even quantities. Compare workshops with different fixed and variable costs using explicit toy values. Change demand and let the displayed totals reveal where each arrangement becomes less costly. Voxel style.
Working Three.js Starter (two-workshops-under-variable-demand-x3140):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>VoxelCost Lab — Workshop Break-even Explorer</title>
<style>
:root {
--ink: #182231;
--muted: #69717d;
--paper: #f4f1e8;
--panel: #fffdf7;
--line: #d9d8d0;
--fixed: #355070;
--variable: #f2a33b;
--studio-a: #0b8f87;
--studio-b: #7657c8;
--green: #e0f3e9;
--purple: #eee8fb;
--shadow: 6px 6px 0 var(--ink);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
}
body {
color: var(--ink);
background:
linear-gradient(rgba(24, 34, 49, 0.035) 1px, transparent 1px),
linear-gradient(90deg, rgba(24, 34, 49, 0.035) 1px, transparent 1px),
var(--paper);
background-size: 24px 24px;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.topbar {
max-width: 1540px;
margin: 0 auto;
padding: 20px 24px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
position: relative;
width: 42px;
height: 42px;
transform: rotate(-4deg);
}
.brand-mark span {
position: absolute;
display: block;
width: 18px;
height: 18px;
border: 2px solid var(--ink);
box-shadow: 2px 2px 0 var(--ink);
}
.brand-mark span:nth-child(1) {
left: 1px;
top: 12px;
background: #58c7ba;
}
.brand-mark span:nth-child(2) {
left: 20px;
top: 2px;
background: #f3ad47;
}
.brand-mark span:nth-child(3) {
left: 21px;
top: 22px;
background: #8c76d5;
}
.brand-name {
font-size: 18px;
font-weight: 900;
letter-spacing: -0.04em;
}
.brand-subtitle {
margin-top: 2px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.top-pills {
display: flex;
align-items: center;
gap: 8px;
flex-wrap: wrap;
justify-content: flex-end;
}
.pill {
border: 2px solid var(--ink);
border-radius: 999px;
padding: 8px 12px;
background: var(--panel);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
}
.live-dot {
display: inline-block;
width: 8px;
height: 8px;
margin-right: 7px;
border-radius: 2px;
background: #21a66f;
box-shadow: 0 0 0 3px rgba(33, 166, 111, 0.16);
}
.layout {
max-width: 1540px;
margin: 0 auto;
padding: 0 24px 24px;
display: grid;
grid-template-columns: minmax(0, 1fr) 410px;
gap: 22px;
align-items: stretch;
}
.scene-card,
.control-panel {
border: 3px solid var(--ink);
border-radius: 22px;
box-shadow: var(--shadow);
}
.scene-card {
position: relative;
min-height: 780px;
overflow: hidden;
background: #dce9e5;
isolation: isolate;
}
#viewport {
position: absolute;
inset: 0;
}
#viewport canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#viewport canvas:active {
cursor: grabbing;
}
.scene-hud {
position: absolute;
z-index: 3;
top: 0;
left: 0;
right: 0;
padding: 26px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
background: linear-gradient(
180deg,
rgba(220, 233, 229, 0.94),
rgba(220, 233, 229, 0.5) 65%,
transparent
);
}
.eyebrow,
.section-kicker,
.mini-label {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scene-hud h1 {
max-width: 530px;
margin: 7px 0 9px;
font-size: clamp(28px, 3.5vw, 51px);
line-height: 0.98;
letter-spacing: -0.065em;
}
.scene-hud p {
max-width: 490px;
margin: 0;
color: #56626c;
font-size: 13px;
line-height: 1.5;
}
.scene-legend {
display: grid;
gap: 8px;
min-width: 155px;
padding: 12px;
border: 2px solid var(--ink);
border-radius: 12px;
background: rgba(255, 253, 247, 0.9);
box-shadow: 3px 3px 0 rgba(24, 34, 49, 0.85);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 11px;
font-weight: 800;
}
.legend-swatch {
width: 13px;
height: 13px;
border: 2px solid var(--ink);
}
.legend-swatch.fixed {
background: var(--fixed);
}
.legend-swatch.variable {
background: var(--variable);
}
.scene-bottom {
position: absolute;
z-index: 3;
left: 22px;
right: 22px;
bottom: 18px;
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 12px;
pointer-events: none;
}
.scene-tip {
padding: 10px 12px;
border: 2px solid var(--ink);
border-radius: 10px;
background: rgba(255, 253, 247, 0.92);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.02em;
}
.reset-button {
pointer-events: auto;
border: 2px solid var(--ink);
border-radius: 10px;
padding: 10px 13px;
background: var(--ink);
color: white;
box-shadow: 3px 3px 0 #57b9ae;
cursor: pointer;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.reset-button:hover {
transform: translate(-1px, -1px);
}
.world-label {
position: absolute;
z-index: 2;
pointer-events: none;
transform: translate(-50%, -100%);
white-space: nowrap;
}
.building-label {
padding: 6px 9px;
border: 2px solid var(--ink);
border-radius: 7px;
box-shadow: 3px 3px 0 var(--ink);
background: #fffdf7;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.06em;
}
.cost-label {
min-width: 164px;
padding: 9px 10px;
border: 2px solid var(--ink);
border-radius: 9px;
background: #fffdf7;
box-shadow: 3px 3px 0 var(--ink);
text-align: center;
}
.cost-label .label-name {
color: #68717a;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.1em;
}
.cost-label .label-total {
margin-top: 2px;
font-size: 18px;
font-weight: 950;
letter-spacing: -0.04em;
}
.cost-label .label-detail {
margin-top: 2px;
color: #68717a;
font-size: 9px;
font-weight: 700;
}
.crossover-label {
transform: translate(-50%, -100%);
padding: 6px 8px;
border: 2px solid var(--ink);
border-radius: 7px;
background: #f2a33b;
box-shadow: 3px 3px 0 var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 900;
text-align: center;
}
.demand-label {
transform: translate(-50%, 15px);
padding: 5px 7px;
border: 2px solid var(--ink);
border-radius: 6px;
background: #58c7ba;
box-shadow: 2px 2px 0 var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 900;
}
.control-panel {
padding: 22px;
background: var(--panel);
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
}
.panel-heading h2 {
margin: 4px 0 0;
font-size: 25px;
letter-spacing: -0.05em;
}
.demand-badge {
border: 2px solid var(--ink);
border-radius: 9px;
padding: 8px 10px;
background: #d9f2ed;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
font-weight: 900;
white-space: nowrap;
}
.demand-label-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
font-size: 12px;
font-weight: 800;
}
.number-wrap {
display: flex;
align-items: center;
border: 2px solid var(--ink);
border-radius: 9px;
overflow: hidden;
background: white;
}
.number-wrap button {
width: 31px;
height: 31px;
border: 0;
border-right: 1px solid var(--line);
background: #f1efe8;
cursor: pointer;
font-weight: 900;
}
.number-wrap button:last-child {
border-right: 0;
border-left: 1px solid var(--line);
}
.number-wrap input {
width: 65px;
height: 31px;
padding: 0;
border: 0;
outline: 0;
color: var(--ink);
background: white;
text-align: center;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
font-weight: 900;
appearance: textfield;
}
.number-wrap input::-webkit-inner-spin-button,
.number-wrap input::-webkit-outer-spin-button {
appearance: none;
margin: 0;
}
input[type="range"] {
width: 100%;
height: 12px;
margin: 0;
border: 2px solid var(--ink);
border-radius: 999px;
outline: none;
background: linear-gradient(
90deg,
#58c7ba 0%,
#58c7ba var(--fill, 44%),
#e7e4da var(--fill, 44%),
#e7e4da 100%
);
appearance: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 22px;
height: 22px;
border: 3px solid var(--ink);
border-radius: 5px;
background: #fffdf7;
box-shadow: 2px 2px 0 var(--ink);
appearance: none;
}
input[type="range"]::-moz-range-thumb {
width: 18px;
height: 18px;
border: 3px solid var(--ink);
border-radius: 5px;
background: #fffdf7;
box-shadow: 2px 2px 0 var(--ink);
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 800;
}
.scenario-row {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 13px;
}
.scenario-button {
border: 2px solid var(--ink);
border-radius: 9px;
padding: 8px 6px;
background: #f0eee6;
cursor: pointer;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 900;
}
.scenario-button:hover,
.scenario-button.active {
background: #d9f2ed;
}
.price-note {
margin-top: 12px;
padding: 9px 11px;
border-left: 4px solid var(--variable);
background: #f4f1e8;
color: #59616a;
font-size: 10px;
line-height: 1.45;
}
.chart-block {
margin-top: 20px;
padding-top: 18px;
border-top: 2px solid var(--line);
}
.block-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.block-heading h3 {
margin: 0;
font-size: 16px;
letter-spacing: -0.025em;
}
.chart-legend {
display: flex;
gap: 9px;
font-size: 9px;
font-weight: 800;
}
.chart-legend span {
display: flex;
align-items: center;
gap: 4px;
}
.chart-legend i {
width: 13px;
height: 4px;
display: inline-block;
}
.chart-wrap {
margin-top: 10px;
overflow: hidden;
border: 2px solid var(--ink);
border-radius: 12px;
background: #f7f5ee;
}
#costChart {
width: 100%;
height: auto;
display: block;
}
.chart-caption {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.insight {
margin-top: 16px;
padding: 13px;
border: 2px solid var(--ink);
border-radius: 11px;
background: var(--green);
box-shadow: 3px 3px 0 var(--ink);
}
.insight.winner-b {
background: var(--purple);
}
.insight-label {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.insight-title {
margin-top: 4px;
font-size: 15px;
font-weight: 900;
letter-spacing: -0.025em;
}
.insight-detail {
margin-top: 4px;
color: #58616b;
font-size: 10px;
line-height: 1.4;
}
.arrangements {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 20px;
}
.arrangement {
min-width: 0;
padding: 12px;
border: 2px solid var(--ink);
border-radius: 11px;
background: white;
}
.arrangement.winner {
box-shadow: 4px 4px 0 var(--ink);
transform: translate(-1px, -1px);
}
.arrangement-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 6px;
margin-bottom: 11px;
}
.arrangement-name {
font-size: 12px;
font-weight: 950;
line-height: 1.1;
}
.winner-tag {
padding: 3px 5px;
border: 1px solid var(--ink);
border-radius: 4px;
background: #d9f2ed;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 7px;
font-weight: 900;
text-transform: uppercase;
}
.cost-row {
display: flex;
justify-content: space-between;
gap: 8px;
padding: 5px 0;
border-top: 1px solid #eceae2;
font-size: 10px;
}
.cost-row span:first-child {
color: var(--muted);
}
.cost-row strong {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
}
.total-row {
margin-top: 7px;
padding-top: 9px;
border-top: 2px solid var(--ink);
}
.total-row strong {
font-size: 16px;
letter-spacing: -0.04em;
}
.profit-positive {
color: #137455;
}
.profit-negative {
color: #b4473f;
}
.crossover-note {
margin-top: 13px;
padding: 11px 12px;
border: 2px dashed var(--ink);
border-radius: 10px;
background: #fff5dd;
font-size: 10px;
line-height: 1.45;
}
.crossover-note strong {
font-size: 12px;
}
footer {
max-width: 1540px;
margin: 0 auto;
padding: 0 28px 26px;
color: #727984;
font-size: 10px;
line-height: 1.5;
}
@media (max-width: 1100px) {
.layout {
grid-template-columns: 1fr;
}
.scene-card {
min-height: 650px;
}
.control-panel {
display: grid;
grid-template-columns: 1fr 1fr;
column-gap: 24px;
}
.demand-section {
grid-column: 1;
}
.chart-block {
grid-column: 1;
}
.results-section {
grid-column: 2;
grid-row: 1 / span 2;
}
}
@media (max-width: 760px) {
.topbar {
padding: 16px;
}
.top-pills .pill:not(.live-pill) {
display: none;
}
.layout {
padding: 0 14px 18px;
}
.scene-card {
min-height: 570px;
}
.scene-hud {
padding: 18px;
}
.scene-hud h1 {
font-size: 31px;
}
.scene-hud p {
font-size: 11px;
}
.scene-legend {
display: none;
}
.control-panel {
display: block;
padding: 17px;
}
.building-label {
display: none;
}
.cost-label {
min-width: 128px;
padding: 7px;
}
.cost-label .label-total {
font-size: 14px;
}
.cost-label .label-detail {
display: none;
}
}
@media (max-width: 470px) {
.brand-subtitle {
display: none;
}
.scene-card {
min-height: 520px;
}
.scene-tip {
max-width: 210px;
line-height: 1.35;
}
.arrangements {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span>
</div>
<div>
<div class="brand-name">VoxelCost Lab</div>
<div class="brand-subtitle">Workshop break-even explorer</div>
</div>
</div>
<div class="top-pills">
<div class="pill live-pill"><span class="live-dot"></span>LIVE TOY MODEL</div>
<div class="pill">USD / MONTH</div>
<div class="pill">THREE.JS VOXEL SCENE</div>
</div>
</header>
<main class="layout">
<section class="scene-card" aria-label="Interactive 3D workshop cost comparison">
<div id="viewport"></div>
<div class="scene-hud">
<div>
<div class="eyebrow">Two ways to make the same thing</div>
<h1>Pick a workshop.<br />Watch the cost curve turn.</h1>
<p>
Block Studio has lower rent but higher unit cost. Assembly Hall asks
for more upfront investment, then saves money on every item.
</p>
</div>
<div class="scene-legend" aria-label="Cost stack legend">
<div class="section-kicker">Cost stack</div>
<div class="legend-item">
<span class="legend-swatch fixed"></span>
Fixed cost
</div>
<div class="legend-item">
<span class="legend-swatch variable"></span>
Variable cost
</div>
</div>
</div>
<div class="world-label building-label" id="labelA">BLOCK STUDIO</div>
<div class="world-label building-label" id="labelB">ASSEMBLY HALL</div>
<div class="world-label cost-label" id="costA"></div>
<div class="world-label cost-label" id="costB"></div>
<div class="world-label crossover-label" id="crossoverLabel">
COST CROSSOVER<br />92.3 UNITS
</div>
<div class="world-label demand-label" id="demandLabel">DEMAND 80</div>
<div class="scene-bottom">
<div class="scene-tip">DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET</div>
<button class="reset-button" id="resetView" type="button">Reset view</button>
</div>
</section>
<aside class="control-panel" aria-label="Cost model controls and results">
<section class="demand-section">
<div class="panel-heading">
<div>
<div class="section-kicker">Demand lab</div>
<h2>Monthly demand</h2>
</div>
<div class="demand-badge" id="demandReadout">80 units</div>
</div>
<div class="demand-label-row">
<label for="demandRange">Units requested</label>
<div class="number-wrap">
<button type="button" id="minusDemand" aria-label="Decrease demand">−</button>
<input
id="demandNumber"
type="number"
min="0"
max="180"
value="80"
aria-label="Demand in units"
/>
<button type="button" id="plusDemand" aria-label="Increase demand">+</button>
</div>
</div>
<input
id="demandRange"
type="range"
min="0"
max="180"
step="1"
value="80"
aria-label="Monthly demand"
/>
<div class="range-labels">
<span>0 UNITS</span>
<span>90</span>
<span>180 UNITS</span>
</div>
<div class="scenario-row" aria-label="Example demand scenarios">
<button class="scenario-button" type="button" data-demand="40">40 · Small</button>
<button class="scenario-button" type="button" data-demand="93">93 · Crossover</button>
<button class="scenario-button" type="button" data-demand="140">140 · Busy</button>
</div>
<div class="price-note">
Toy selling price: <strong>$50 per unit</strong>. Profit break-even includes
this price; the cost crossover only compares the two workshops.
</div>
</section>
<section class="chart-block">
<div class="block-heading">
<h3>Monthly cost curves</h3>
<div class="chart-legend">
<span><i style="background:#0b8f87"></i>Block</span>
<span><i style="background:#7657c8"></i>Assembly</span>
</div>
</div>
<div class="chart-wrap">
<svg
id="costChart"
viewBox="0 0 360 220"
role="img"
aria-label="Line chart comparing the total monthly costs of Block Studio and Assembly Hall"
>
<rect x="0" y="0" width="360" height="220" fill="#f7f5ee"></rect>
<rect id="zoneA" x="28" y="16" width="164" height="174" fill="#e0f3e9"></rect>
<rect id="zoneB" x="192" y="16" width="156" height="174" fill="#eee8fb"></rect>
<g id="chartGrid" stroke="#d9d8d0" stroke-width="1"></g>
<g id="yTicks" fill="#747b84" font-size="8" font-family="monospace"></g>
<g id="xTicks" fill="#747b84" font-size="8" font-family="monospace"></g>
<path
id="curveA"
fill="none"
stroke="#0b8f87"
stroke-width="3.5"
stroke-linejoin="round"
stroke-linecap="round"
></path>
<path
id="curveB"
fill="none"
stroke="#7657c8"
stroke-width="3.5"
stroke-linejoin="round"
stroke-linecap="round"
></path>
<line
id="demandLine"
x1="0"
x2="0"
y1="16"
y2="190"
stroke="#182231"
stroke-width="1.5"
stroke-dasharray="4 4"
></line>
<circle
id="crossPoint"
r="5"
fill="#f2a33b"
stroke="#182231"
stroke-width="2"
></circle>
<circle
id="pointA"
r="5"
fill="#0b8f87"
stroke="#182231"
stroke-width="2"
></circle>
<circle
id="pointB"
r="5"
fill="#7657c8"
stroke="#182231"
stroke-width="2"
></circle>
<text
x="43"
y="29"
fill="#397a63"
font-size="8"
font-family="monospace"
font-weight="bold"
>BLOCK IS CHEAPER</text>
<text
x="205"
y="29"
fill="#6c56a2"
font-size="8"
font-family="monospace"
font-weight="bold"
>ASSEMBLY IS CHEAPER</text>
<text
x="28"
y="211"
fill="#747b84"
font-size="8"
font-family="monospace"
>UNITS</text>
<text
x="291"
y="211"
fill="#747b84"
font-size="8"
font-family="monospace"
>COST</text>
</svg>
</div>
<div class="chart-caption">
<span>Curves use identical demand.</span>
<span>Intersection: 92.3 units</span>
</div>
</section>
<section class="results-section">
<div class="insight" id="insightBox">
<div class="insight-label">Current cost leader</div>
<div class="insight-title" id="insightTitle">Block Studio is cheaper</div>
<div class="insight-detail" id="insightDetail">
At 80 units, Block Studio costs $160 less.
</div>
</div>
<div class="arrangements">
<article class="arrangement winner" id="cardA">
<div class="arrangement-head">
<div>
<div class="mini-label" style="color:#0b8f87">Workshop A</div>
<div class="arrangement-name">Block Studio</div>
</div>
<span class="winner-tag">Cheaper</span>
</div>
<div class="cost-row">
<span>Fixed</span>
<strong>$1,200</strong>
</div>
<div class="cost-row">
<span>Variable</span>
<strong>$35 / unit</strong>
</div>
<div class="cost-row total-row">
<span>Total</span>
<strong id="totalA">$4,000</strong>
</div>
<div class="cost-row">
<span>Profit break-even</span>
<strong id="beA">35 units</strong>
</div>
<div class="cost-row">
<span>Profit / loss</span>
<strong id="profitA">$0</strong>
</div>
</article>
<article class="arrangement" id="cardB">
<div class="arrangement-head">
<div>
<div class="mini-label" style="color:#7657c8">Workshop B</div>
<div class="arrangement-name">Assembly Hall</div>
</div>
<span class="winner-tag" style="visibility:hidden">Cheaper</span>
</div>
<div class="cost-row">
<span>Fixed</span>
<strong>$2,400</strong>
</div>
<div class="cost-row">
<span>Variable</span>
<strong>$22 / unit</strong>
</div>
<div class="cost-row total-row">
<span>Total</span>
<strong id="totalB">$4,160</strong>
</div>
<div class="cost-row">
<span>Profit break-even</span>
<strong id="beB">86 units</strong>
</div>
<div class="cost-row">
<span>Profit / loss</span>
<strong id="profitB">−$160</strong>
</div>
</article>
</div>
<div class="crossover-note">
<strong>Where the arrangement flips:</strong>
Assembly Hall becomes cheaper after <strong>92.3 units</strong>.
Block Studio's lower fixed cost wins in the small-demand market;
Assembly Hall's lower variable cost wins at scale.
</div>
</section>
</aside>
</main>
<footer>
Toy model only: fixed costs are monthly, variable costs are per unit, and the
selling price is $50 per unit. Taxes, financing, capacity limits, discounts,
and time value are intentionally ignored.
</footer>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Toy economics
// -------------------------------------------------------------------------
const MODEL = {
sellingPrice: 50,
maxDemand: 180,
costScale: 1050,
workshopA: {
name: "Block Studio",
fixed: 1200,
variable: 35,
color: 0x0b8f87
},
workshopB: {
name: "Assembly Hall",
fixed: 2400,
variable: 22,
color: 0x7657c8
}
};
const crossover =
(MODEL.workshopB.fixed - MODEL.workshopA.fixed) /
(MODEL.workshopA.variable - MODEL.workshopB.variable);
const breakEvenA = Math.ceil(
MODEL.workshopA.fixed /
(MODEL.sellingPrice - MODEL.workshopA.variable)
);
const breakEvenB = Math.ceil(
MODEL.workshopB.fixed /
(MODEL.sellingPrice - MODEL.workshopB.variable)
);
const money = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
maximumFractionDigits: 0
});
function totalCost(workshop, demand) {
return workshop.fixed + workshop.variable * demand;
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9e5);
scene.fog = new THREE.Fog(0xdce9e5, 27, 48);
const camera = new THREE.PerspectiveCamera(39, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf6fff9, 0x75808a, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4d6, 3.4);
sun.position.set(-7, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0005;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x9ec8ff, 1.2);
rim.position.set(9, 8, -11);
scene.add(rim);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x182231,
transparent: true,
opacity: 0.48
});
function addBox(
parent,
width,
height,
depth,
x,
y,
z,
color,
options = {}
) {
const {
outline = true,
roughness = 0.82,
metalness = 0,
emissive = 0,
emissiveIntensity = 0
} = options;
const material = new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
emissive,
emissiveIntensity
});
const geometry = new THREE.BoxGeometry(width, height, depth);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
if (outline) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
edgeMaterial
);
mesh.add(edges);
}
parent.add(mesh);
return mesh;
}
// Ground and grid.
addBox(
scene,
18,
0.65,
16,
0,
-0.35,
0,
0xe7e3d5,
{ outline: false }
);
const grid = new THREE.GridHelper(18, 18, 0xa7b1ab, 0xc4cbc3);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.58;
scene.add(grid);
// A small stepped entrance.
addBox(scene, 4.3, 0.18, 1.5, 0, 0.08, 7.05, 0xcfc9b8);
addBox(scene, 3.2, 0.18, 1.0, 0, 0.19, 6.65, 0xdad4c3);
function createBlockStudio() {
const group = new THREE.Group();
group.position.set(-4.25, 0, -2.25);
// Foundation.
addBox(group, 4.05, 0.35, 3.35, 0, 0.19, 0, 0xb9b4a6);
addBox(group, 3.65, 0.12, 2.95, 0, 0.42, 0, 0xd7d1c1);
// Main body.
addBox(group, 3.45, 1.65, 2.72, 0, 1.27, 0, 0xf2e6cf);
addBox(group, 3.58, 0.14, 2.82, 0, 2.11, 0, 0x31536d);
// Stepped voxel roof.
addBox(group, 3.9, 0.3, 3.12, 0, 2.31, 0, 0x43b8aa);
addBox(group, 3.15, 0.27, 2.5, 0, 2.59, 0, 0x35a99e);
addBox(group, 2.35, 0.22, 1.9, 0, 2.83, 0, 0x258f87);
// Front facade.
addBox(group, 0.76, 1.45, 0.12, 0, 1.12, 1.42, 0x274257);
addBox(
group,
0.66,
0.64,
0.13,
-1.02,
1.37,
1.42,
0xffd66d,
{ emissive: 0xffc94f, emissiveIntensity: 0.38 }
);
addBox(
group,
0.66,
0.64,
0.13,
1.02,
1.37,
1.42,
0xffd66d,
{ emissive: 0xffc94f, emissiveIntensity: 0.38 }
);
addBox(group, 1.3, 0.14, 0.35, 0, 1.88, 1.57, 0xf2a33b);
addBox(group, 0.52, 0.22, 0.11, 0, 2.25, 1.48, 0x182231);
// Side details.
addBox(group, 0.13, 1.45, 0.15, -1.76, 1.28, 0.85, 0x31536d);
addBox(group, 0.13, 1.45, 0.15, 1.76, 1.28, 0.85, 0x31536d);
addBox(group, 0.46, 0.78, 0.5, 0.9, 3.13, -0.55, 0xe7b765);
addBox(group, 0.62, 0.16, 0.66, 0.9, 3.55, -0.55, 0x31536d);
// Crates.
addBox(group, 0.6, 0.6, 0.6, -2.25, 0.72, 0.72, 0xf2a33b);
addBox(group, 0.48, 0.48, 0.48, -2.22, 1.25, 0.72, 0x8b6a3d);
scene.add(group);
}
function createAssemblyHall() {
const group = new THREE.Group();
group.position.set(4.25, 0, -2.25);
addBox(group, 4.95, 0.38, 3.85, 0, 0.2, 0, 0xb9b4a6);
addBox(group, 4.5, 0.12, 3.4, 0, 0.44, 0, 0xd7d1c1);
addBox(group, 4.4, 2.25, 3.18, 0, 1.6, 0, 0xf0e7d4);
addBox(group, 4.55, 0.16, 3.32, 0, 2.79, 0, 0x31536d);
// Broad production roof.
addBox(group, 4.85, 0.34, 3.62, 0, 3.03, 0, 0x8c76d5);
addBox(group, 3.85, 0.28, 2.8, 0, 3.33, 0, 0x7657c8);
addBox(group, 2.55, 0.23, 1.85, 0, 3.58, 0, 0x5f43aa);
// Loading door and windows.
addBox(group, 1.22, 1.58, 0.13, -0.85, 1.2, 1.66, 0x30465d);
for (let i = 0; i < 4; i++) {
addBox(
group,
0.12,
1.42,
0.08,
-1.28 + i * 0.29,
1.2,
1.74,
0x7893aa
);
}
addBox(
group,
0.74,
0.62,
0.13,
1.12,
1.55,
1.66,
0xffd66d,
{ emissive: 0xffc94f, emissiveIntensity: 0.35 }
);
addBox(
group,
0.74,
0.62,
0.13,
1.92,
1.55,
1.66,
0xffd66d,
{ emissive: 0xffc94f, emissiveIntensity: 0.35 }
);
addBox(group, 1.6, 0.15, 0.42, 0.9, 2.28, 1.8, 0xf2a33b);
// Vents and pipes.
addBox(group, 0.55, 0.75, 0.55, -1.35, 3.35, -0.75, 0x9aa4a8);
addBox(group, 0.7, 0.13, 0.7, -1.35, 3.76, -0.75, 0x31536d);
addBox(group, 0.45, 0.85, 0.45, 1.4, 3.3, -0.7, 0xe0b66d);
addBox(group, 0.16, 1.5, 0.16, 2.35, 2.6, 0.2, 0x31536d);
// Pallets.
addBox(group, 0.92, 0.17, 0.78, 2.7, 0.55, 0.85, 0x8b6a3d);
addBox(group, 0.68, 0.58, 0.62, 2.7, 0.92, 0.85, 0x58b5aa);
scene.add(group);
}
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
addBox(group, 0.28, 1.1, 0.28, 0, 0.55, 0, 0x886746);
addBox(group, 1.0, 0.8, 1.0, 0, 1.35, 0, 0x62a86e);
addBox(group, 0.72, 0.7, 0.72, -0.28, 1.83, 0.12, 0x76b97c);
addBox(group, 0.68, 0.66, 0.68, 0.32, 1.83, -0.05, 0x4f9464);
scene.add(group);
}
function createCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
addBox(group, 1.6, 0.55, 0.7, 0, 0, 0, 0xf4f7f0, { outline: false });
addBox(group, 0.85, 0.75, 0.7, -0.62, 0.22, 0, 0xf4f7f0, { outline: false });
addBox(group, 0.9, 0.9, 0.7, 0.55, 0.26, 0, 0xf4f7f0, { outline: false });
scene.add(group);
return group;
}
createBlockStudio();
createAssemblyHall();
createTree(-7.2, -4.4, 0.9);
createTree(7.2, -4.6, 1.05);
createTree(-7.1, 1.5, 0.72);
createTree(7.2, 1.7, 0.78);
const cloudA = createCloud(-7.6, 5.6, -5.8, 0.85);
const cloudB = createCloud(7.4, 6.2, -6.3, 0.7);
// -------------------------------------------------------------------------
// Cost towers
// -------------------------------------------------------------------------
function createCostTower(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
addBox(group, 2.65, 0.18, 2.15, 0, 0.1, 0, 0xcac4b5);
addBox(group, 2.25, 0.08, 1.8, 0, 0.23, 0, 0xe1dccd);
const fixed = addBox(
group,
1.18,
1,
1.18,
0,
0.5,
0,
0x355070
);
const variable = addBox(
group,
1.18,
1,
1.18,
0,
0.5,
0,
0xf2a33b
);
const cap = addBox(
group,
0.74,
0.12,
0.74,
0,
0.5,
0,
0xfffdf7
);
return { group, fixed, variable, cap };
}
const towerA = createCostTower(-4.25, 1.65);
const towerB = createCostTower(4.25, 1.65);
function updateTower(tower, workshop, demand) {
const fixedHeight = workshop.fixed / MODEL.costScale;
const variableHeight =
(workshop.variable * demand) / MODEL.costScale;
const totalHeight = fixedHeight + variableHeight;
tower.fixed.scale.y = fixedHeight;
tower.fixed.position.y = fixedHeight / 2;
tower.variable.scale.y = Math.max(variableHeight, 0.001);
tower.variable.position.y =
fixedHeight + Math.max(variableHeight, 0.001) / 2;
tower.cap.position.y = totalHeight + 0.07;
}
// -------------------------------------------------------------------------
// Demand runway and crossover marker
// -------------------------------------------------------------------------
const runway = new THREE.Group();
scene.add(runway);
function volumeToX(units) {
return -7.5 + (units / MODEL.maxDemand) * 15;
}
for (let i = 0; i <= 30; i++) {
const x = -7.5 + i * 0.5;
const major = i % 6 === 0;
addBox(
runway,
major ? 0.2 : 0.11,
0.07,
major ? 0.52 : 0.3,
x,
0.055,
4.65,
major ? 0x71808a : 0xaeb7b5,
{ outline: false }
);
}
const demandMarker = new THREE.Group();
addBox(
demandMarker,
0.55,
0.55,
0.55,
0,
0.35,
0,
0x58c7ba
);
addBox(
demandMarker,
0.22,
0.22,
0.22,
0,
0.78,
0,
0xfffdf7
);
scene.add(demandMarker);
const crossX = volumeToX(crossover);
const crossoverMarker = new THREE.Group();
addBox(
crossoverMarker,
0.28,
1.15,
0.28,
crossX,
0.58,
4.23,
0xf2a33b
);
const diamond = addBox(
crossoverMarker,
0.42,
0.42,
0.42,
crossX,
1.28,
4.23,
0xf2a33b
);
diamond.rotation.set(Math.PI / 4, Math.PI / 4, 0);
scene.add(crossoverMarker);
// -------------------------------------------------------------------------
// Custom camera controls — no external addons
// -------------------------------------------------------------------------
const cameraState = {
azimuth: 0.62,
polar: 1.04,
radius: 21.5,
target: new THREE.Vector3(0, 1.55, 0)
};
const defaultCamera = { ...cameraState };
function updateCamera() {
const { azimuth, polar, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(polar) * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * Math.sin(polar) * Math.cos(azimuth)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.azimuth = defaultCamera.azimuth;
cameraState.polar = defaultCamera.polar;
cameraState.radius = defaultCamera.radius;
cameraState.target.copy(defaultCamera.target);
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.azimuth -= dx * 0.008;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar + dy * 0.006,
0.52,
1.34
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
13,
29
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("resetView").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// DOM and chart controls
// -------------------------------------------------------------------------
const demandRange = document.getElementById("demandRange");
const demandNumber = document.getElementById("demandNumber");
const demandReadout = document.getElementById("demandReadout");
const totalAElement = document.getElementById("totalA");
const totalBElement = document.getElementById("totalB");
const profitAElement = document.getElementById("profitA");
const profitBElement = document.getElementById("profitB");
const cardA = document.getElementById("cardA");
const cardB = document.getElementById("cardB");
const insightBox = document.getElementById("insightBox");
const insightTitle = document.getElementById("insightTitle");
const insightDetail = document.getElementById("insightDetail");
document.getElementById("beA").textContent = `${breakEvenA} units`;
document.getElementById("beB").textContent = `${breakEvenB} units`;
const chart = {
curveA: document.getElementById("curveA"),
curveB: document.getElementById("curveB"),
demandLine: document.getElementById("demandLine"),
pointA: document.getElementById("pointA"),
pointB: document.getElementById("pointB"),
crossPoint: document.getElementById("crossPoint"),
zoneA: document.getElementById("zoneA"),
zoneB: document.getElementById("zoneB"),
grid: document.getElementById("chartGrid"),
yTicks: document.getElementById("yTicks"),
xTicks: document.getElementById("xTicks")
};
const chartX = (units) => 28 + (units / MODEL.maxDemand) * 320;
const chartY = (cost) => 190 - (cost / 8000) * 150;
chart.curveA.setAttribute(
"d",
`M ${chartX(0)} ${chartY(MODEL.workshopA.fixed)} ` +
`L ${chartX(MODEL.maxDemand)} ${chartY(
totalCost(MODEL.workshopA, MODEL.maxDemand)
)}`
);
chart.curveB.setAttribute(
"d",
`M ${chartX(0)} ${chartY(MODEL.workshopB.fixed)} ` +
`L ${chartX(MODEL.maxDemand)} ${chartY(
totalCost(MODEL.workshopB, MODEL.maxDemand)
)}`
);
chart.crossPoint.setAttribute("cx", chartX(crossover));
chart.crossPoint.setAttribute("cy", chartY(totalCost(MODEL.workshopA, crossover)));
chart.zoneA.setAttribute("width", chartX(crossover) - 28);
chart.zoneB.setAttribute("x", chartX(crossover));
chart.zoneB.setAttribute("width", 348 - chartX(crossover));
for (let cost = 0; cost <= 8000; cost += 2000) {
const y = chartY(cost);
const line = document.createElementNS("http://www.w3.org/2000/svg", "line");
line.setAttribute("x1", "28");
line.setAttribute("x2", "348");
line.setAttribute("y1", y);
line.setAttribute("y2", y);
chart.grid.appendChild(line);
const text = document.createElementNS("http://www.w3.org/2000/svg", "text");
text.setAttribute("x", "21");
text.setAttribute("y", y + 3);
text.setAttribute("text-anchor", "end");
text.textContent =
cost === 0 ? "$0" : `$${cost / 1000}k`;
chart.yTicks.appendChild(text);
}
for (const units of [0, 60, 120, 180]) {
const text = document.createElementNS("http://www.w3.org/2000/svg", "text");
text.setAttribute("x", chartX(units));
text.setAttribute("y", "205");
text.setAttribute("text-anchor", "middle");
text.textContent = units;
chart.xTicks.appendChild(text);
}
const scenarioButtons = [
...document.querySelectorAll(".scenario-button")
];
function setDemand(value) {
const demand = Math.max(
0,
Math.min(MODEL.maxDemand, Math.round(Number(value) || 0))
);
demandRange.value = demand;
demandNumber.value = demand;
demandReadout.textContent = `${demand} units`;
const fill = (demand / MODEL.maxDemand) * 100;
demandRange.style.setProperty("--fill", `${fill}%`);
const totalA = totalCost(MODEL.workshopA, demand);
const totalB = totalCost(MODEL.workshopB, demand);
const variableA = MODEL.workshopA.variable * demand;
const variableB = MODEL.workshopB.variable * demand;
const revenue = demand * MODEL.sellingPrice;
const profitA = revenue - totalA;
const profitB = revenue - totalB;
const difference = Math.abs(totalA - totalB);
const aWins = totalA < totalB;
totalAElement.textContent = money.format(totalA);
totalBElement.textContent = money.format(totalB);
profitAElement.textContent = money.format(profitA);
profitBElement.textContent = money.format(profitB);
profitAElement.classList.toggle("profit-positive", profitA >= 0);
profitAElement.classList.toggle("profit-negative", profitA < 0);
profitBElement.classList.toggle("profit-positive", profitB >= 0);
profitBElement.classList.toggle("profit-negative", profitB < 0);
cardA.classList.toggle("winner", aWins);
cardB.classList.toggle("winner", !aWins);
cardA.querySelector(".winner-tag").style.visibility = aWins
? "visible"
: "hidden";
cardB.querySelector(".winner-tag").style.visibility = aWins
? "hidden"
: "visible";
insightBox.classList.toggle("winner-b", !aWins);
if (difference < 1) {
insightTitle.textContent = "The workshops cost the same";
insightDetail.textContent =
`At ${demand} units, both workshops cost ${money.format(totalA)}.`;
} else if (aWins) {
insightTitle.textContent = "Block Studio is cheaper";
insightDetail.textContent =
`At ${demand} units, Block Studio costs ${money.format(
difference
)} less.`;
} else {
insightTitle.textContent = "Assembly Hall is cheaper";
insightDetail.textContent =
`At ${demand} units, Assembly Hall costs ${money.format(
difference
)} less.`;
}
// Update 3D towers.
updateTower(towerA, MODEL.workshopA, demand);
updateTower(towerB, MODEL.workshopB, demand);
// Update HTML labels in the 3D scene.
document.getElementById("costA").innerHTML = `
<div class="label-name">BLOCK STUDIO</div>
<div class="label-total">${money.format(totalA)}</div>
<div class="label-detail">
${money.format(MODEL.workshopA.fixed)} fixed +
${money.format(variableA)} variable
</div>
`;
document.getElementById("costB").innerHTML = `
<div class="label-name">ASSEMBLY HALL</div>
<div class="label-total">${money.format(totalB)}</div>
<div class="label-detail">
${money.format(MODEL.workshopB.fixed)} fixed +
${money.format(variableB)} variable
</div>
`;
document.getElementById("demandLabel").textContent =
`DEMAND ${demand}`;
demandMarker.position.x = volumeToX(demand);
// Update chart marker.
const x = chartX(demand);
chart.demandLine.setAttribute("x1", x);
chart.demandLine.setAttribute("x2", x);
chart.pointA.setAttribute("cx", x);
chart.pointA.setAttribute("cy", chartY(totalA));
chart.pointB.setAttribute("cx", x);
chart.pointB.setAttribute("cy", chartY(totalB));
scenarioButtons.forEach((button) => {
button.classList.toggle(
"active",
Number(button.dataset.demand) === demand
);
});
}
demandRange.addEventListener("input", (event) => {
setDemand(event.target.value);
});
demandNumber.addEventListener("change", (event) => {
setDemand(event.target.value);
});
document.getElementById("minusDemand").addEventListener("click", () => {
setDemand(Number(demandRange.value) - 1);
});
document.getElementById("plusDemand").addEventListener("click", () => {
setDemand(Number(demandRange.value) + 1);
});
scenarioButtons.forEach((button) => {
button.addEventListener("click", () => {
setDemand(button.dataset.demand);
});
});
// -------------------------------------------------------------------------
// Project HTML labels into the 3D scene
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, offsetX = 0, offsetY = 0) {
projected.copy(worldPosition).project(camera);
const width = viewport.clientWidth;
const height = viewport.clientHeight;
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.2 &&
projected.x < 1.2 &&
projected.y > -1.2 &&
projected.y < 1.2;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * width + offsetX;
const y = (-projected.y * 0.5 + 0.5) * height + offsetY;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateWorldLabels() {
placeLabel(
document.getElementById("labelA"),
new THREE.Vector3(-4.25, 3.55, -2.25)
);
placeLabel(
document.getElementById("labelB"),
new THREE.Vector3(4.25, 4.0, -2.25)
);
placeLabel(
document.getElementById("costA"),
new THREE.Vector3(
-4.25,
MODEL.workshopA.fixed / MODEL.costScale +
(MODEL.workshopA.variable * Number(demandRange.value)) /
MODEL.costScale +
0.58,
1.65
)
);
placeLabel(
document.getElementById("costB"),
new THREE.Vector3(
4.25,
MODEL.workshopB.fixed / MODEL.costScale +
(MODEL.workshopB.variable * Number(demandRange.value)) /
MODEL.costScale +
0.58,
1.65
)
);
placeLabel(
document.getElementById("crossoverLabel"),
new THREE.Vector3(crossX, 1.65, 4.23),
0,
-4
);
placeLabel(
document.getElementById("demandLabel"),
new THREE.Vector3(
volumeToX(Number(demandRange.value)),
0.1,
4.72
)
);
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resizeRenderer() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(viewport);
resizeRenderer();
updateCamera();
setDemand(80);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
cloudA.position.y = 5.6 + Math.sin(elapsed * 0.35) * 0.08;
cloudB.position.y = 6.2 + Math.sin(elapsed * 0.31 + 2) * 0.07;
demandMarker.position.y = Math.sin(elapsed * 2.8) * 0.035;
demandMarker.rotation.y = elapsed * 0.35;
updateWorldLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```