Prompt specification
Build or customize the Three.js 3D scene "Price Cards and Quantity Steps" 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: Price Cards and Quantity Steps
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/price-cards-and-quantity-steps-x3141
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring supply and demand schedules in a fictional market. Model two stair-step boards labeled supplied and requested quantities at fictional prices. Make each step's count inspectable and avoid implying real market data. Stylized solid forms.
Working Three.js Starter (price-cards-and-quantity-steps-x3141):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="color-scheme" content="light" />
<title>The Imagined Exchange — Fictional Supply and Demand</title>
<style>
:root {
--ink: #263733;
--muted: #68736f;
--paper: #f3efe8;
--supply: #287c72;
--request: #c86750;
--panel: rgba(255, 252, 246, 0.9);
--line: rgba(38, 55, 51, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
select {
font: inherit;
}
#app {
position: fixed;
inset: 0;
}
#app canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#app canvas:focus-visible {
outline: 3px solid rgba(40, 124, 114, 0.45);
outline-offset: -3px;
}
.hud {
position: fixed;
inset: 0;
z-index: 10;
pointer-events: none;
}
.masthead {
position: absolute;
top: 24px;
left: 26px;
width: min(420px, calc(100vw - 390px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--supply);
box-shadow: 13px 0 0 var(--request);
margin-right: 4px;
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 42px);
font-weight: 780;
letter-spacing: -0.045em;
line-height: 1;
}
.subtitle {
max-width: 390px;
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.fiction-badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid rgba(200, 103, 80, 0.28);
border-radius: 999px;
background: rgba(255, 248, 241, 0.72);
color: #8b4939;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.fiction-badge span {
display: grid;
width: 17px;
height: 17px;
place-items: center;
border-radius: 50%;
background: var(--request);
color: white;
font-size: 11px;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 14px;
margin-top: 12px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
}
.swatch.supply {
background: var(--supply);
}
.swatch.request {
background: var(--request);
}
.inspector {
position: absolute;
top: 24px;
right: 24px;
width: 300px;
padding: 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(44, 55, 51, 0.11),
inset 0 1px 0 rgba(255, 255, 255, 0.8);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.panel-kicker {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#selectionMode {
padding: 4px 7px;
border-radius: 999px;
background: rgba(40, 124, 114, 0.09);
color: var(--supply);
letter-spacing: 0.05em;
}
.inspector label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
select {
width: 100%;
min-height: 40px;
padding: 8px 30px 8px 10px;
border: 1px solid rgba(38, 55, 51, 0.16);
border-radius: 10px;
outline: none;
background: #fffdf9;
color: var(--ink);
font-size: 12px;
font-weight: 650;
}
select:focus {
border-color: rgba(40, 124, 114, 0.6);
box-shadow: 0 0 0 3px rgba(40, 124, 114, 0.1);
}
.readout {
margin-top: 14px;
padding: 12px 0;
border-top: 1px solid var(--line);
border-bottom: 1px solid var(--line);
}
.readout-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 18px;
padding: 5px 0;
}
.readout-row span {
color: var(--muted);
font-size: 11px;
}
.readout-row strong {
text-align: right;
font-size: 12px;
font-weight: 780;
}
.readout-row .quantity {
color: var(--supply);
font-size: 22px;
letter-spacing: -0.04em;
}
.synthetic-note {
display: flex;
align-items: flex-start;
gap: 9px;
margin-top: 13px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.synthetic-note b {
color: #75493f;
}
.synthetic-note i {
display: grid;
flex: 0 0 20px;
height: 20px;
place-items: center;
border-radius: 50%;
background: rgba(200, 103, 80, 0.11);
color: var(--request);
font-style: normal;
font-weight: 900;
}
.hint {
position: absolute;
bottom: 22px;
left: 50%;
transform: translateX(-50%);
padding: 8px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 252, 246, 0.76);
color: var(--muted);
font-size: 10px;
font-weight: 700;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.view-controls {
position: absolute;
right: 24px;
bottom: 22px;
display: flex;
gap: 6px;
pointer-events: auto;
}
.view-controls button {
min-width: 38px;
height: 38px;
padding: 0 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 252, 246, 0.88);
color: var(--ink);
cursor: pointer;
font-size: 12px;
font-weight: 800;
box-shadow: 0 7px 22px rgba(44, 55, 51, 0.08);
}
.view-controls button:hover {
background: white;
transform: translateY(-1px);
}
.view-controls button:active {
transform: translateY(0);
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 760px) {
.masthead {
top: 15px;
left: 15px;
width: calc(100vw - 30px);
}
h1 {
font-size: 27px;
}
.subtitle {
max-width: 290px;
font-size: 11px;
}
.legend {
display: none;
}
.inspector {
top: auto;
right: 14px;
bottom: 14px;
left: 14px;
width: auto;
padding: 13px;
border-radius: 14px;
}
.panel-kicker {
margin-bottom: 8px;
}
.readout {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 9px;
padding: 9px 0;
}
.readout-row {
display: block;
padding: 0;
}
.readout-row span,
.readout-row strong {
display: block;
text-align: left;
}
.readout-row strong {
margin-top: 3px;
}
.readout-row .quantity {
font-size: 18px;
}
.synthetic-note {
margin-top: 8px;
}
.hint {
display: none;
}
.view-controls {
top: 14px;
right: 14px;
bottom: auto;
}
}
</style>
</head>
<body>
<main id="app" aria-label="Interactive fictional supply and demand schedule"></main>
<div class="hud">
<header class="masthead">
<div class="eyebrow">Illustrative market study / 01</div>
<h1>The Imagined Exchange</h1>
<p class="subtitle">
Supply and demand schedules assembled from invented numbers for an
interactive 3D study.
</p>
<div class="fiction-badge">
<span>!</span>
Fictional data · not real market values
</div>
<div class="legend" aria-label="Schedule color legend">
<span><i class="swatch supply"></i> Supply schedule</span>
<span><i class="swatch request"></i> Demand schedule</span>
</div>
</header>
<aside class="inspector" aria-label="Step inspector">
<div class="panel-kicker">
Live step inspector
<span id="selectionMode">Selected step</span>
</div>
<label for="stepSelect">Choose a step</label>
<select id="stepSelect"></select>
<div class="readout" aria-live="polite">
<div class="readout-row">
<span>Schedule</span>
<strong id="detailSchedule">—</strong>
</div>
<div class="readout-row">
<span>Fictional price</span>
<strong id="detailPrice">—</strong>
</div>
<div class="readout-row">
<span>Quantity</span>
<strong id="detailQuantity" class="quantity">—</strong>
</div>
</div>
<div class="synthetic-note">
<i>i</i>
<p>
<b>Invented values.</b> “fc” means fictional credits. All quantities
are made-up units. Prices increase from left to right.
</p>
</div>
</aside>
<div class="hint">
Drag to orbit · Scroll to zoom · Hover or select a step
</div>
<div class="view-controls" aria-label="Camera controls">
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="resetView" type="button">Reset</button>
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
</div>
<div id="liveStatus" class="sr-only" aria-live="polite"></div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const stepSelect = document.getElementById("stepSelect");
const selectionMode = document.getElementById("selectionMode");
const detailSchedule = document.getElementById("detailSchedule");
const detailPrice = document.getElementById("detailPrice");
const detailQuantity = document.getElementById("detailQuantity");
const liveStatus = document.getElementById("liveStatus");
/*
Every number below is deliberately invented.
fc = fictional credits
quantity = fictional units
*/
const schedules = [
{
id: "supply",
title: "Supply schedule",
quantityLabel: "Supplied quantities",
x: -3.15,
color: 0x287c72,
css: "#287c72",
backingColor: 0xe1ebe6,
prices: [2, 4, 6, 8],
counts: [12, 26, 44, 64]
},
{
id: "request",
title: "Demand schedule",
quantityLabel: "Requested quantities",
x: 3.15,
color: 0xc86750,
css: "#c86750",
backingColor: 0xf0e2dc,
prices: [2, 4, 6, 8],
counts: [64, 45, 29, 14]
}
];
// ---------- Renderer and scene ----------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.04;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.id = "sceneCanvas";
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D fictional supply and demand schedules. Use the inspector to choose a step."
);
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf3efe8);
scene.fog = new THREE.Fog(0xf3efe8, 20, 36);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const cameraTarget = new THREE.Vector3(0.45, 1.65, 0);
let azimuth = 0.015;
let elevation = 0.39;
let cameraZoom = 1;
function updateCamera() {
const distance = 18;
camera.position.set(
cameraTarget.x + distance * Math.sin(azimuth) * Math.cos(elevation),
cameraTarget.y + distance * Math.sin(elevation),
cameraTarget.z + distance * Math.cos(azimuth) * Math.cos(elevation)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Retain a minimum horizontal view so both boards remain visible.
const viewHeight = Math.max(10.3, 12.8 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
// ---------- Lighting and ground ----------
const hemisphere = new THREE.HemisphereLight(0xfff8eb, 0x66736f, 1.9);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2dc, 3.1);
keyLight.position.set(-5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9dcd5, 1.15);
fillLight.position.set(7, 5, -5);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 30),
new THREE.MeshStandardMaterial({
color: 0xf3efe8,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(26, 26, 0xb8b1a7, 0xd7d0c6);
grid.position.y = -0.008;
grid.material.transparent = true;
grid.material.opacity = 0.2;
grid.material.depthWrite = false;
scene.add(grid);
// ---------- Geometry and texture helpers ----------
function drawRoundedRect(ctx, x, y, width, height, radius) {
radius = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function roundedPrism(width, height, depth, radius, material) {
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
curveSegments: 8,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: Math.min(0.045, radius * 0.4),
bevelThickness: 0.045
});
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
return new THREE.Mesh(geometry, material);
}
function addEdges(mesh, color = 0x243b36, opacity = 0.28) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 35),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
edges.renderOrder = 2;
mesh.add(edges);
return edges;
}
function createTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
draw(context, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
texture.needsUpdate = true;
return texture;
}
function createGroupTexture(schedule) {
return createTexture(1200, 300, (ctx) => {
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = schedule.css;
ctx.font = "750 52px system-ui, sans-serif";
ctx.fillText(schedule.title.toUpperCase(), 600, 72);
ctx.font = "850 68px system-ui, sans-serif";
ctx.fillText(schedule.quantityLabel.toUpperCase(), 600, 166);
ctx.globalAlpha = 0.24;
ctx.fillRect(420, 232, 360, 7);
ctx.globalAlpha = 1;
});
}
function createCountTexture(schedule, count) {
return createTexture(640, 300, (ctx) => {
ctx.save();
ctx.shadowColor = "rgba(36, 55, 51, 0.18)";
ctx.shadowBlur = 20;
ctx.shadowOffsetY = 8;
drawRoundedRect(ctx, 12, 12, 616, 276, 48);
ctx.fillStyle = "#fffaf1";
ctx.fill();
ctx.restore();
drawRoundedRect(ctx, 12, 12, 616, 276, 48);
ctx.strokeStyle = schedule.css;
ctx.lineWidth = 8;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = schedule.css;
ctx.font = "850 108px system-ui, sans-serif";
ctx.fillText(String(count), 320, 132);
ctx.fillStyle = "#53605b";
ctx.font = "750 24px system-ui, sans-serif";
ctx.fillText("FICTIONAL QTY", 320, 234);
});
}
function createPriceTexture(schedule, price) {
return createTexture(640, 220, (ctx) => {
drawRoundedRect(ctx, 8, 8, 624, 204, 40);
ctx.fillStyle = schedule.css;
ctx.fill();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#fffdf8";
ctx.font = "850 82px system-ui, sans-serif";
ctx.fillText(`${price} fc`, 320, 91);
ctx.globalAlpha = 0.8;
ctx.font = "750 23px system-ui, sans-serif";
ctx.fillText("FICTIONAL PRICE", 320, 165);
ctx.globalAlpha = 1;
});
}
function createMedallionTexture() {
return createTexture(700, 280, (ctx) => {
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#33443f";
ctx.font = "850 92px Georgia, serif";
ctx.fillText("fc", 350, 100);
ctx.fillStyle = "#68736f";
ctx.font = "750 25px system-ui, sans-serif";
ctx.fillText("FICTIONAL CREDITS", 350, 205);
});
}
function addSprite(texture, width, height, parent, x, y, z) {
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(width, height, 1);
sprite.position.set(x, y, z);
sprite.renderOrder = 10;
parent.add(sprite);
return sprite;
}
// ---------- Schedule construction ----------
const stepMeshes = [];
const stepRecords = [];
const BASE_Y = 0.43;
const HEIGHT_SCALE = 0.043;
const STEP_SPACING = 1.22;
const STEP_WIDTH = 1.08;
function buildSchedule(schedule) {
const group = new THREE.Group();
group.position.x = schedule.x;
scene.add(group);
const backing = roundedPrism(
5.22,
3.5,
0.18,
0.18,
new THREE.MeshStandardMaterial({
color: schedule.backingColor,
roughness: 0.9,
metalness: 0
})
);
backing.position.set(0, 2.15, -0.94);
backing.castShadow = true;
backing.receiveShadow = true;
group.add(backing);
addEdges(backing, schedule.color, 0.16);
const platform = roundedPrism(
5.25,
0.38,
2.0,
0.16,
new THREE.MeshStandardMaterial({
color: 0xd9d0c3,
roughness: 0.82,
metalness: 0
})
);
platform.position.set(0, 0.19, 0);
platform.castShadow = true;
platform.receiveShadow = true;
group.add(platform);
addEdges(platform, 0x52605b, 0.2);
const titleSprite = addSprite(
createGroupTexture(schedule),
3.65,
0.79,
group,
0,
3.52,
-0.72
);
titleSprite.renderOrder = 8;
schedule.counts.forEach((count, index) => {
const x = (index - 1.5) * STEP_SPACING;
const height = count * HEIGHT_SCALE;
const key = `${schedule.id}-${index}`;
const material = new THREE.MeshStandardMaterial({
color: schedule.color,
roughness: 0.62,
metalness: 0.02,
emissive: schedule.color,
emissiveIntensity: 0
});
const step = roundedPrism(
STEP_WIDTH,
height,
1.35,
0.13,
material
);
step.position.set(x, BASE_Y + height / 2, -0.02);
step.castShadow = true;
step.receiveShadow = true;
step.userData = {
key,
scheduleId: schedule.id,
index
};
const edge = addEdges(
step,
schedule.id === "supply" ? 0x174c46 : 0x743b31,
0.3
);
group.add(step);
stepMeshes.push(step);
const countSprite = addSprite(
createCountTexture(schedule, count),
0.87,
0.43,
group,
x,
BASE_Y + height * 0.59,
0.72
);
countSprite.renderOrder = 12;
const priceSprite = addSprite(
createPriceTexture(schedule, schedule.prices[index]),
0.78,
0.29,
group,
x,
0.25,
1.08
);
priceSprite.renderOrder = 11;
stepRecords.push({
key,
schedule,
index,
mesh: step,
edge,
material,
countSprite,
priceSprite
});
});
}
schedules.forEach(buildSchedule);
// Central fictional-credit marker.
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xe0d6c8,
roughness: 0.72,
metalness: 0.02
});
const marker = new THREE.Mesh(
new THREE.CylinderGeometry(0.74, 0.82, 0.28, 48),
markerMaterial
);
marker.position.set(0, 0.14, 0.15);
marker.castShadow = true;
marker.receiveShadow = true;
scene.add(marker);
addEdges(marker, 0x52605b, 0.24);
const markerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.61, 0.035, 12, 48),
new THREE.MeshStandardMaterial({
color: 0xb9ad9c,
roughness: 0.65,
metalness: 0.03
})
);
markerRing.rotation.x = Math.PI / 2;
markerRing.position.set(0, 0.29, 0.15);
markerRing.castShadow = true;
scene.add(markerRing);
addSprite(
createMedallionTexture(),
1.3,
0.52,
scene,
0,
0.89,
0.15
);
// ---------- Inspector and selection ----------
for (const schedule of schedules) {
const optionGroup = document.createElement("optgroup");
optionGroup.label = schedule.quantityLabel;
schedule.counts.forEach((count, index) => {
const option = document.createElement("option");
option.value = `${schedule.id}-${index}`;
option.textContent =
`${schedule.prices[index]} fc · ${count} fictional units`;
optionGroup.appendChild(option);
});
stepSelect.appendChild(optionGroup);
}
let selectedKey = "supply-1";
let hoveredKey = null;
function findRecord(key) {
return stepRecords.find((record) => record.key === key);
}
function updateHighlights() {
for (const record of stepRecords) {
const selected = record.key === selectedKey;
const hovered = record.key === hoveredKey;
record.material.emissiveIntensity = hovered
? 0.34
: selected
? 0.18
: 0;
record.edge.material.opacity = hovered
? 0.95
: selected
? 0.72
: 0.3;
record.edge.material.color.set(
hovered || selected
? 0xffffff
: record.schedule.id === "supply"
? 0x174c46
: 0x743b31
);
}
}
function updateInspector() {
const activeKey = hoveredKey || selectedKey;
const record = findRecord(activeKey);
if (!record) {
detailSchedule.textContent = "—";
detailPrice.textContent = "—";
detailQuantity.textContent = "—";
selectionMode.textContent = "No step selected";
return;
}
const { schedule, index } = record;
stepSelect.value = activeKey;
selectionMode.textContent = hoveredKey
? "Hover preview"
: "Selected step";
detailSchedule.textContent = schedule.quantityLabel;
detailPrice.textContent = `${schedule.prices[index]} fictional credits`;
detailQuantity.textContent = `${schedule.counts[index]} units`;
liveStatus.textContent =
`${schedule.quantityLabel}, ${schedule.prices[index]} fictional credits, ` +
`${schedule.counts[index]} fictional units.`;
}
function selectStep(key) {
if (!findRecord(key)) return;
selectedKey = key;
updateHighlights();
updateInspector();
}
function setHovered(key) {
if (hoveredKey === key) return;
hoveredKey = key;
updateHighlights();
updateInspector();
renderer.domElement.style.cursor = key ? "pointer" : "grab";
}
stepSelect.addEventListener("change", () => {
selectStep(stepSelect.value);
});
// ---------- Direct camera and pointer controls ----------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
function raycastStep(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(stepMeshes, false);
return hits.length ? hits[0].object.userData.key : null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) {
setHovered(raycastStep(event));
return;
}
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
if (Math.abs(event.clientX - lastPointerX) > 1) {
pointerMoved = true;
}
azimuth -= deltaX * 0.006;
elevation = THREE.MathUtils.clamp(
elevation + deltaY * 0.0045,
0.16,
0.92
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (pointerMoved) {
setHovered(null);
updateCamera();
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointerMoved) {
const key = raycastStep(event);
if (key) selectStep(key);
}
pointerDown = false;
renderer.domElement.style.cursor = hoveredKey ? "pointer" : "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
pointerMoved = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!pointerDown) setHovered(null);
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.65
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
function zoomBy(factor) {
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * factor,
0.68,
1.65
);
updateCamera();
}
function resetView() {
azimuth = 0.015;
elevation = 0.39;
cameraZoom = 1;
updateCamera();
}
document.getElementById("zoomOut").addEventListener("click", () => {
zoomBy(0.88);
});
document.getElementById("zoomIn").addEventListener("click", () => {
zoomBy(1.14);
});
document.getElementById("resetView").addEventListener("click", resetView);
renderer.domElement.addEventListener("keydown", (event) => {
const amount = 0.07;
if (event.key === "ArrowLeft") azimuth += amount;
else if (event.key === "ArrowRight") azimuth -= amount;
else if (event.key === "ArrowUp") elevation += amount;
else if (event.key === "ArrowDown") elevation -= amount;
else if (event.key === "+" || event.key === "=") zoomBy(1.1);
else if (event.key === "-") zoomBy(0.9);
else if (event.key === "0") resetView();
else return;
event.preventDefault();
elevation = THREE.MathUtils.clamp(elevation, 0.16, 0.92);
updateCamera();
});
renderer.domElement.addEventListener("dblclick", resetView);
// Initial UI state.
selectStep(selectedKey);
updateCamera();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```