Prompt specification
Build or customize the Three.js 3D scene "Shelf With Reorder Marker" 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: Shelf With Reorder Marker
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shelf-with-reorder-marker-x3153
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows stock levels and reorder thresholds. Model a shelf holding twelve identical jars and a movable threshold marker. Show current stock, reserved stock, and free slots as distinct physical regions. Low-poly.
Working Three.js Starter (shelf-with-reorder-marker-x3153):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stock Shelf Visualizer</title>
<style>
:root {
color-scheme: dark;
--bg: #07101d;
--panel: rgba(13, 25, 42, 0.78);
--border: rgba(151, 180, 215, 0.16);
--text: #edf5ff;
--muted: #91a5bd;
--teal: #35d6b5;
--amber: #f4ad49;
--blue: #668dff;
--danger: #ff6474;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 42%, rgba(39, 79, 117, 0.22), transparent 43%),
linear-gradient(145deg, #081422 0%, #050b14 100%);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.topbar {
position: absolute;
top: 24px;
left: 28px;
right: 28px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
position: relative;
width: 42px;
height: 42px;
border: 1px solid rgba(83, 223, 194, 0.45);
border-radius: 12px;
background:
linear-gradient(145deg, rgba(53, 214, 181, 0.22), rgba(53, 214, 181, 0.04));
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.28);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
left: 9px;
right: 9px;
height: 5px;
border-radius: 2px;
background: var(--teal);
box-shadow: 0 9px 0 rgba(53, 214, 181, 0.48);
}
.brand-mark::before {
top: 10px;
}
.brand-mark::after {
top: 26px;
right: 15px;
background: var(--amber);
box-shadow: none;
}
.brand-copy strong {
display: block;
font-size: 14px;
letter-spacing: 0.16em;
}
.brand-copy span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 12px;
}
.live {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(9, 18, 31, 0.7);
color: #b9c9dc;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
backdrop-filter: blur(12px);
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 5px rgba(53, 214, 181, 0.1);
animation: pulse 2s infinite;
}
@keyframes pulse {
50% {
box-shadow: 0 0 0 8px rgba(53, 214, 181, 0);
}
}
.stats {
position: absolute;
top: 92px;
left: 28px;
display: grid;
grid-template-columns: repeat(4, minmax(126px, 1fr));
gap: 10px;
}
.stat {
min-width: 142px;
padding: 13px 15px;
border: 1px solid var(--border);
border-radius: 13px;
background: var(--panel);
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.16);
backdrop-filter: blur(15px);
}
.stat-label {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.stat-dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--stat-color);
box-shadow: 0 0 10px color-mix(in srgb, var(--stat-color) 55%, transparent);
}
.stat-value {
display: flex;
align-items: baseline;
gap: 6px;
margin-top: 8px;
}
.stat-value strong {
font-size: 25px;
line-height: 1;
letter-spacing: -0.04em;
}
.stat-value span {
color: var(--muted);
font-size: 10px;
}
.stat-note {
margin-top: 6px;
color: #70859d;
font-size: 10px;
}
.control-panel {
position: absolute;
right: 28px;
bottom: 28px;
width: 360px;
padding: 18px;
border: 1px solid var(--border);
border-radius: 16px;
background: rgba(11, 23, 39, 0.86);
box-shadow: 0 22px 60px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
}
.status {
display: inline-flex;
align-items: center;
gap: 8px;
color: var(--status-color);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
}
.status::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.status.good {
--status-color: var(--teal);
}
.status.warn {
--status-color: var(--amber);
}
.status.danger {
--status-color: var(--danger);
}
.status-note {
color: var(--muted);
font-size: 10px;
text-align: right;
}
.threshold-heading {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.threshold-heading label {
color: #b9c9dc;
font-size: 12px;
font-weight: 700;
}
.threshold-heading output {
color: var(--text);
font-size: 12px;
font-weight: 800;
}
input[type="range"] {
--pct: 58.33%;
width: 100%;
height: 5px;
margin: 7px 0 0;
border-radius: 999px;
appearance: none;
background: linear-gradient(
to right,
var(--amber) 0%,
var(--amber) var(--pct),
rgba(140, 163, 190, 0.2) var(--pct),
rgba(140, 163, 190, 0.2) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
border: 3px solid #111d2b;
border-radius: 50%;
appearance: none;
background: #ffd176;
box-shadow: 0 0 0 1px rgba(255, 209, 118, 0.8);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid #111d2b;
border-radius: 50%;
background: #ffd176;
box-shadow: 0 0 0 1px rgba(255, 209, 118, 0.8);
}
.range-scale {
display: flex;
justify-content: space-between;
margin-top: 10px;
color: #6f849c;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.legend {
position: absolute;
left: 28px;
bottom: 28px;
display: flex;
align-items: center;
gap: 8px;
padding: 10px 12px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(10, 20, 34, 0.68);
backdrop-filter: blur(14px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #9fb1c7;
font-size: 10px;
font-weight: 700;
}
.legend-swatch {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--swatch);
box-shadow: 0 0 9px color-mix(in srgb, var(--swatch) 45%, transparent);
}
.hint {
position: absolute;
bottom: 31px;
left: 50%;
transform: translateX(-50%);
color: rgba(151, 171, 195, 0.58);
font-size: 10px;
letter-spacing: 0.04em;
white-space: nowrap;
}
.hint kbd {
padding: 3px 6px;
border: 1px solid rgba(151, 171, 195, 0.16);
border-radius: 4px;
background: rgba(255, 255, 255, 0.035);
color: #9eb0c5;
font: inherit;
}
.webgl-error {
position: fixed;
inset: 50% auto auto 50%;
width: min(440px, calc(100% - 40px));
transform: translate(-50%, -50%);
padding: 24px;
border: 1px solid rgba(255, 100, 116, 0.35);
border-radius: 15px;
background: #101a28;
color: #dce7f4;
line-height: 1.6;
text-align: center;
}
@media (max-width: 900px) {
.stats {
right: 20px;
grid-template-columns: repeat(4, 1fr);
}
.stat {
min-width: 0;
}
.hint {
display: none;
}
}
@media (max-width: 680px) {
.topbar {
top: 15px;
left: 14px;
right: 14px;
}
.brand-copy span {
display: none;
}
.live {
padding: 8px 10px;
font-size: 9px;
}
.stats {
top: 76px;
left: 12px;
right: 12px;
grid-template-columns: repeat(2, 1fr);
gap: 7px;
}
.stat {
padding: 10px 12px;
}
.stat-value strong {
font-size: 21px;
}
.stat-note {
display: none;
}
.legend {
left: 12px;
bottom: 154px;
gap: 6px;
padding: 8px 10px;
}
.legend-item {
font-size: 9px;
}
.control-panel {
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
padding: 14px;
}
.status-row {
margin-bottom: 12px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<main class="ui">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<strong>STOCK / 12</strong>
<span>Low-poly inventory shelf monitor</span>
</div>
</div>
<div class="live">
<span class="live-dot"></span>
LIVE MODEL
</div>
</header>
<section class="stats" aria-label="Stock summary">
<article class="stat" style="--stat-color: var(--teal)">
<div class="stat-label">
<span class="stat-dot"></span>
Current stock
</div>
<div class="stat-value">
<strong>5</strong>
<span>units</span>
</div>
<div class="stat-note">Ready to pick</div>
</article>
<article class="stat" style="--stat-color: var(--amber)">
<div class="stat-label">
<span class="stat-dot"></span>
Reserved stock
</div>
<div class="stat-value">
<strong>3</strong>
<span>units</span>
</div>
<div class="stat-note">Allocated orders</div>
</article>
<article class="stat" style="--stat-color: var(--blue)">
<div class="stat-label">
<span class="stat-dot"></span>
Free slots
</div>
<div class="stat-value">
<strong>4</strong>
<span>open</span>
</div>
<div class="stat-note">Available capacity</div>
</article>
<article class="stat" style="--stat-color: #b9c9dc">
<div class="stat-label">
<span class="stat-dot"></span>
Total on hand
</div>
<div class="stat-value">
<strong>8</strong>
<span>/ 12</span>
</div>
<div class="stat-note">67% utilized</div>
</article>
</section>
<div class="legend" aria-label="Region legend">
<div class="legend-item">
<span class="legend-swatch" style="--swatch: var(--teal)"></span>
Current
</div>
<div class="legend-item">
<span class="legend-swatch" style="--swatch: var(--amber)"></span>
Reserved
</div>
<div class="legend-item">
<span class="legend-swatch" style="--swatch: var(--blue)"></span>
Free
</div>
</div>
<div class="hint">
Drag the marker to set threshold · Drag scene to rotate · Scroll to zoom
</div>
<section class="control-panel" aria-label="Reorder threshold controls">
<div class="status-row">
<div id="status" class="status warn" aria-live="polite">AT BUFFER</div>
<div id="statusNote" class="status-note">1 unit above the trigger</div>
</div>
<div class="threshold-heading">
<label for="threshold">Reorder threshold</label>
<output id="thresholdValue" for="threshold">7 units</output>
</div>
<input
id="threshold"
type="range"
min="0"
max="12"
step="1"
value="7"
aria-label="Reorder threshold in units"
>
<div class="range-scale">
<span>0 · Empty</span>
<span>12 · Full</span>
</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";
const sceneHost = document.getElementById("scene");
const slider = document.getElementById("threshold");
const thresholdValue = document.getElementById("thresholdValue");
const statusElement = document.getElementById("status");
const statusNote = document.getElementById("statusNote");
const inventory = {
current: 5,
reserved: 3,
capacity: 12,
threshold: 7
};
const onHand = inventory.current + inventory.reserved;
const freeSlots = inventory.capacity - onHand;
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
} catch (error) {
const message = document.createElement("div");
message.className = "webgl-error";
message.textContent =
"This visualization requires WebGL. Please open it in a browser with hardware acceleration enabled.";
document.body.appendChild(message);
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x07101d, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D shelf showing five current-stock jars, three reserved jars, four free slots, and a movable reorder threshold."
);
renderer.domElement.tabIndex = 0;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x07101d, 22, 43);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.75, 0);
const cameraState = {
theta: 0.38,
phi: 1.02,
radius: 22
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.phi),
cameraTarget.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xc7e1ff, 0x172033, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4de, 3.6);
keyLight.position.set(-5, 11, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x7aa7ff, 2.1);
fillLight.position.set(9, 6, -8);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0x35d6b5, 18, 16, 2);
rimLight.position.set(-7, 4, 2);
scene.add(rimLight);
const materials = {
shelf: new THREE.MeshStandardMaterial({
color: 0x172334,
roughness: 0.68,
metalness: 0.42,
flatShading: true
}),
shelfEdge: new THREE.MeshStandardMaterial({
color: 0x314258,
roughness: 0.52,
metalness: 0.55,
flatShading: true
}),
currentDeck: new THREE.MeshStandardMaterial({
color: 0x124f48,
emissive: 0x062c29,
emissiveIntensity: 0.35,
roughness: 0.8,
flatShading: true
}),
reservedDeck: new THREE.MeshStandardMaterial({
color: 0x70451d,
emissive: 0x382006,
emissiveIntensity: 0.35,
roughness: 0.8,
flatShading: true
}),
freeDeck: new THREE.MeshStandardMaterial({
color: 0x1c3150,
emissive: 0x0b1830,
emissiveIntensity: 0.35,
roughness: 0.82,
flatShading: true
}),
currentPanel: new THREE.MeshStandardMaterial({
color: 0x0c292d,
roughness: 0.92,
flatShading: true
}),
reservedPanel: new THREE.MeshStandardMaterial({
color: 0x302416,
roughness: 0.92,
flatShading: true
}),
freePanel: new THREE.MeshStandardMaterial({
color: 0x111f34,
roughness: 0.92,
flatShading: true
})
};
function makeBox(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function makeRegionTexture(title, value, accent) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 160;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(context, 4, 4, 504, 152, 20);
context.fillStyle = "rgba(7, 15, 27, 0.86)";
context.fill();
context.strokeStyle = accent;
context.lineWidth = 4;
context.stroke();
context.fillStyle = accent;
context.font = "800 27px system-ui, sans-serif";
context.textAlign = "left";
context.textBaseline = "middle";
context.fillText(title, 28, 48);
context.fillStyle = "#eef6ff";
context.font = "800 68px system-ui, sans-serif";
context.fillText(value, 28, 105);
context.fillStyle = "rgba(222, 235, 249, 0.56)";
context.font = "700 18px system-ui, sans-serif";
context.fillText("PHYSICAL SHELF REGION", 28, 139);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addRegionLabel(texture, x, y, z, width) {
const height = width / 3.2;
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const label = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
label.position.set(x, y, z);
scene.add(label);
return label;
}
// Ground plane and low-poly grid.
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x081320,
roughness: 1,
metalness: 0,
transparent: true,
opacity: 0.86
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.26;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(36, 36, 0x263d55, 0x14263a);
grid.position.y = -1.245;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
// Shelf body.
makeBox(14.35, 0.36, 3.0, materials.shelf, 0, 0, 0);
makeBox(14.45, 0.12, 3.08, materials.shelfEdge, 0, -0.19, 0);
makeBox(14.35, 0.54, 0.16, materials.shelf, 0, 0.02, 1.48);
makeBox(13.8, 0.14, 0.16, materials.shelfEdge, 0, 2.66, -1.22);
// Four shelf legs and rear supports.
for (const x of [-6.55, 6.55]) {
for (const z of [-1.03, 1.03]) {
makeBox(0.34, 1.12, 0.34, materials.shelfEdge, x, -0.73, z);
}
makeBox(0.24, 2.75, 0.22, materials.shelfEdge, x, 1.35, -1.26);
}
makeBox(13.45, 0.16, 0.16, materials.shelfEdge, 0, 0.73, -1.25);
const slotPitch = 1.14;
const slotHalf = slotPitch / 2;
const leftBoundary = (0 - 6.5) * slotPitch;
const regions = [
{
start: 0,
end: 5,
title: "CURRENT STOCK",
value: "5 UNITS",
accent: "#35d6b5",
deck: materials.currentDeck,
panel: materials.currentPanel
},
{
start: 5,
end: 8,
title: "RESERVED STOCK",
value: "3 UNITS",
accent: "#f4ad49",
deck: materials.reservedDeck,
panel: materials.reservedPanel
},
{
start: 8,
end: 12,
title: "FREE SLOTS",
value: "4 SLOTS",
accent: "#668dff",
deck: materials.freeDeck,
panel: materials.freePanel
}
];
for (const region of regions) {
const startX = (region.start - 6) * slotPitch;
const endX = (region.end - 6) * slotPitch;
const width = endX - startX;
const centerX = (startX + endX) / 2;
makeBox(width, 0.075, 2.55, region.deck, centerX, 0.225, 0);
makeBox(width - 0.08, 2.32, 0.12, region.panel, centerX, 1.45, -1.28);
const texture = makeRegionTexture(
region.title,
region.value,
region.accent
);
const labelWidth = Math.min(width * 0.79, 3.55);
addRegionLabel(texture, centerX, 2.02, -1.205, labelWidth);
}
// Visible separators between physical inventory regions.
for (const x of [-1.14, 2.28]) {
makeBox(0.055, 2.35, 0.18, materials.shelfEdge, x, 1.44, -1.18);
}
const bodyGeometry = new THREE.CylinderGeometry(0.31, 0.33, 0.72, 8, 1, false);
const lidGeometry = new THREE.CylinderGeometry(0.35, 0.35, 0.14, 8, 1, false);
const bandGeometry = new THREE.CylinderGeometry(0.336, 0.336, 0.17, 8, 1, false);
const currentBodyMaterial = new THREE.MeshStandardMaterial({
color: 0x63d8c2,
roughness: 0.58,
metalness: 0.08,
flatShading: true
});
const currentLidMaterial = new THREE.MeshStandardMaterial({
color: 0x138f7d,
roughness: 0.48,
metalness: 0.2,
flatShading: true
});
const reservedBodyMaterial = new THREE.MeshStandardMaterial({
color: 0xf0b25c,
roughness: 0.6,
metalness: 0.06,
flatShading: true
});
const reservedLidMaterial = new THREE.MeshStandardMaterial({
color: 0xbd6b1f,
roughness: 0.48,
metalness: 0.2,
flatShading: true
});
const labelBandMaterial = new THREE.MeshStandardMaterial({
color: 0xe7f2ec,
roughness: 0.75,
flatShading: true
});
function createJar(x, isReserved) {
const group = new THREE.Group();
group.position.set(x, 0, 0.08);
const body = new THREE.Mesh(
bodyGeometry,
isReserved ? reservedBodyMaterial : currentBodyMaterial
);
body.position.y = 0.68;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const band = new THREE.Mesh(bandGeometry, labelBandMaterial);
band.position.y = 0.66;
band.castShadow = true;
group.add(band);
const lid = new THREE.Mesh(
lidGeometry,
isReserved ? reservedLidMaterial : currentLidMaterial
);
lid.position.y = 1.1;
lid.castShadow = true;
group.add(lid);
scene.add(group);
}
const slotOutlineMaterial = new THREE.LineBasicMaterial({
color: 0x6f89a6,
transparent: true,
opacity: 0.3
});
const ghostMaterial = new THREE.MeshBasicMaterial({
color: 0x8ba2bd,
transparent: true,
opacity: 0.07,
depthWrite: false
});
const ghostWireMaterial = new THREE.MeshBasicMaterial({
color: 0x8ba2bd,
wireframe: true,
transparent: true,
opacity: 0.24,
depthWrite: false
});
for (let i = 0; i < inventory.capacity; i++) {
const x = (i - 5.5) * slotPitch;
const isCurrent = i < inventory.current;
const isReserved = !isCurrent && i < onHand;
const padMaterial = isCurrent
? materials.currentDeck
: isReserved
? materials.reservedDeck
: materials.freeDeck;
const pad = makeBox(0.9, 0.035, 1.46, padMaterial, x, 0.285, 0.08);
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(pad.geometry),
slotOutlineMaterial
);
outline.position.copy(pad.position);
scene.add(outline);
if (isCurrent || isReserved) {
createJar(x, isReserved);
} else {
const ghostBody = new THREE.Mesh(bodyGeometry, ghostMaterial);
ghostBody.position.set(x, 0.68, 0.08);
scene.add(ghostBody);
const ghostBodyWire = new THREE.Mesh(
bodyGeometry,
ghostWireMaterial
);
ghostBodyWire.position.copy(ghostBody.position);
scene.add(ghostBodyWire);
const ghostLid = new THREE.Mesh(lidGeometry, ghostWireMaterial);
ghostLid.position.set(x, 1.1, 0.08);
scene.add(ghostLid);
}
}
// Threshold rail and its thirteen snap positions.
makeBox(14.2, 0.075, 0.08, materials.shelfEdge, 0, 0.5, 1.72);
const tickMaterial = new THREE.MeshStandardMaterial({
color: 0x9db0c7,
emissive: 0x25384d,
emissiveIntensity: 0.25,
roughness: 0.55,
flatShading: true
});
for (let i = 0; i <= inventory.capacity; i++) {
const x = leftBoundary + i * slotPitch;
makeBox(0.025, 0.15, 0.055, tickMaterial, x, 0.61, 1.73);
}
const thresholdMaterial = new THREE.MeshStandardMaterial({
color: 0xffcc5c,
emissive: 0xff9f30,
emissiveIntensity: 0.55,
roughness: 0.4,
metalness: 0.15,
flatShading: true
});
const thresholdMarker = new THREE.Group();
thresholdMarker.position.z = 1.72;
scene.add(thresholdMarker);
const markerPost = makeBox(
0.095,
2.02,
0.095,
thresholdMaterial,
0,
1.49,
0,
thresholdMarker
);
const markerArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.19, 0.36, 3),
thresholdMaterial
);
markerArrow.rotation.z = Math.PI;
markerArrow.position.set(0, 0.34, 0);
markerArrow.castShadow = true;
thresholdMarker.add(markerArrow);
const badgeCanvas = document.createElement("canvas");
badgeCanvas.width = 512;
badgeCanvas.height = 160;
const badgeContext = badgeCanvas.getContext("2d");
const badgeTexture = new THREE.CanvasTexture(badgeCanvas);
badgeTexture.colorSpace = THREE.SRGBColorSpace;
const badgeMaterial = new THREE.SpriteMaterial({
map: badgeTexture,
transparent: true,
depthTest: false,
depthWrite: false
});
const markerBadge = new THREE.Sprite(badgeMaterial);
markerBadge.position.set(0, 2.78, 0);
markerBadge.scale.set(1.65, 0.52, 1);
markerBadge.renderOrder = 10;
thresholdMarker.add(markerBadge);
const thresholdLineMaterial = new THREE.MeshBasicMaterial({
color: 0xffcc5c,
transparent: true,
opacity: 0.9
});
const thresholdLine = makeBox(
0.038,
0.035,
2.48,
thresholdLineMaterial,
0,
0.312,
0.02
);
const markerHitObjects = [markerPost, markerArrow, markerBadge];
markerHitObjects.forEach((object) => {
object.userData.thresholdMarker = true;
});
function boundaryX(value) {
return leftBoundary + value * slotPitch;
}
function drawBadge(value, danger) {
const accent = danger ? "#ff6474" : "#ffd176";
badgeContext.clearRect(0, 0, badgeCanvas.width, badgeCanvas.height);
roundedRect(badgeContext, 5, 5, 502, 150, 22);
badgeContext.fillStyle = "rgba(8, 16, 27, 0.94)";
badgeContext.fill();
badgeContext.strokeStyle = accent;
badgeContext.lineWidth = 5;
badgeContext.stroke();
badgeContext.textAlign = "left";
badgeContext.textBaseline = "middle";
badgeContext.fillStyle = accent;
badgeContext.font = "800 28px system-ui, sans-serif";
badgeContext.fillText("REORDER", 27, 46);
badgeContext.fillStyle = "#f4f8ff";
badgeContext.font = "900 76px system-ui, sans-serif";
badgeContext.fillText(String(value), 28, 105);
badgeContext.textAlign = "right";
badgeContext.fillStyle = "rgba(229, 239, 250, 0.68)";
badgeContext.font = "700 22px system-ui, sans-serif";
badgeContext.fillText("UNITS", 479, 104);
badgeTexture.needsUpdate = true;
}
function updateStatus() {
const difference = onHand - inventory.threshold;
let label;
let note;
let className;
if (difference <= 0) {
label = "REORDER NOW";
note = difference === 0
? "On-hand has reached the trigger"
: `${Math.abs(difference)} unit${Math.abs(difference) === 1 ? "" : "s"} below the trigger`;
className = "danger";
} else if (difference === 1) {
label = "AT BUFFER";
note = "1 unit above the trigger";
className = "warn";
} else {
label = "ABOVE THRESHOLD";
note = `${difference} units above the trigger`;
className = "good";
}
statusElement.className = `status ${className}`;
statusElement.textContent = label;
statusNote.textContent = note;
const danger = difference <= 0;
const markerColor = danger ? 0xff6474 : 0xffcc5c;
thresholdMaterial.color.setHex(markerColor);
thresholdMaterial.emissive.setHex(danger ? 0x8c1528 : 0xff9f30);
thresholdLineMaterial.color.setHex(markerColor);
drawBadge(inventory.threshold, danger);
}
function setThreshold(value) {
inventory.threshold = THREE.MathUtils.clamp(
Math.round(value),
0,
inventory.capacity
);
thresholdMarker.position.x = boundaryX(inventory.threshold);
thresholdLine.position.x = thresholdMarker.position.x;
slider.value = inventory.threshold;
thresholdValue.textContent =
`${inventory.threshold} unit${inventory.threshold === 1 ? "" : "s"}`;
const percentage = (inventory.threshold / inventory.capacity) * 100;
slider.style.setProperty("--pct", `${percentage}%`);
updateStatus();
}
slider.addEventListener("input", (event) => {
setThreshold(Number(event.target.value));
});
setThreshold(inventory.threshold);
// Custom camera controls implemented directly without Three.js addons.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(
new THREE.Vector3(0, 1, 0),
-1.35
);
const intersection = new THREE.Vector3();
let pointerState = null;
function updatePointer(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);
}
function isMarkerHit() {
return raycaster.intersectObjects(markerHitObjects, true).length > 0;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
updatePointer(event);
if (isMarkerHit()) {
raycaster.ray.intersectPlane(dragPlane, intersection);
pointerState = {
type: "threshold",
pointerId: event.pointerId,
offset: thresholdMarker.position.x - intersection.x
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
} else {
pointerState = {
type: "orbit",
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY
};
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerState?.type === "threshold") {
updatePointer(event);
if (raycaster.ray.intersectPlane(dragPlane, intersection)) {
const rawValue =
(intersection.x + pointerState.offset - leftBoundary) /
slotPitch;
setThreshold(rawValue);
}
return;
}
if (pointerState?.type === "orbit") {
const dx = event.clientX - pointerState.x;
const dy = event.clientY - pointerState.y;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.58,
1.38
);
updateCamera();
return;
}
updatePointer(event);
renderer.domElement.style.cursor = isMarkerHit() ? "ew-resize" : "grab";
});
function endPointer(event) {
if (!pointerState) return;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
pointerState = null;
renderer.domElement.style.cursor = "grab";
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
13,
31
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.theta = 0.38;
cameraState.phi = 1.02;
cameraState.radius = 22;
updateCamera();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
const viewHeight = Math.max(9.4, 17.3 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```