@zkmake/three-meter 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@ load the scene up.
16
16
  <img
17
17
  src="https://raw.githubusercontent.com/zkmake/three-meter/main/docs/hud-full.png"
18
18
  width="320"
19
- alt="The HUD in full mode, dark theme: a theme row (light, system, dark), a dim-on-leave toggle, FPS, CPU and GPU sparklines with live values, and a checkbox list of counters (FPS, calls, CPU, GPU, triangles, lines, points, render passes, geometries, textures, shaders) choosing what the compact card shows, then a footer with the three-meter version, the three revision, a WebGL2 backend badge and the GPU name. Two discs beside it: a drag grip and the compact/full toggle."
19
+ alt="The HUD in full mode, dark theme. Option rows for theme (light, system, dark), dim on leave, explain metrics and a copy-report button; FPS, CPU and GPU sparklines with live values; then one row per metric, each with an icon, its value and a checkbox choosing whether the compact card shows it (FPS, calls, CPU, GPU, 1% low, frame p99, hitches, triangles, lines, points, render passes, geometries, textures, shaders); and a footer with the three-meter version, the three revision, a WebGL2 backend badge and the GPU name. Two discs beside it: a drag grip and the compact/full toggle."
20
20
  />
21
21
  </p>
22
22
 
@@ -89,6 +89,7 @@ Canvas is its own React root. To run two canvases on one page, pass the same `st
89
89
  | `parent` | `document.body` | Where the host element is appended. |
90
90
  | `injectStyles` | `true` | Append the stylesheet once per document. |
91
91
  | `refreshHz` | `10` | Repaint rate. |
92
+ | `budgets` | timing defaults | Limits past which a value turns amber. See [Budgets](#budgets). |
92
93
 
93
94
  `PerformanceMonitor` and `PerfSampler` take `trackGPU` (default true), `gpuQueryPoolSize` (default 5),
94
95
  `historySize` (default 120) and `frameStatsSize` (default 1000).
@@ -118,7 +119,7 @@ hud.theme.subscribe(() => syncMyPageWith(hud.theme.resolved));
118
119
 
119
120
  The resolved theme lands on `data-theme` of `.perf-hud` and `.perf-monitor`. To restyle either
120
121
  palette, override the `--perf-*` custom properties (`bg`, `fg`, `fg-dim`, `muted`, `row`,
121
- `border`, `accent`, `shadow`) on those selectors.
122
+ `border`, `accent`, `warn`, `shadow`) on those selectors. `warn` is the over-budget amber.
122
123
 
123
124
  ## GPU timing
124
125
 
@@ -143,6 +144,29 @@ monitor.getEnvironment();
143
144
  WebGL's unmasked renderer string, and is `null` where the browser hides it. Chrome's WebGPU gives
144
145
  vendor and architecture, not the model.
145
146
 
147
+ ## Reading the panel
148
+
149
+ Every row has an icon, its value, and a checkbox on the right that puts it in the compact HUD. Hover
150
+ a label for a one-line explanation of the metric and what a bad reading means, or tick **explain
151
+ metrics** to show them all under the rows (also works on touch).
152
+
153
+ ## Budgets
154
+
155
+ A value past its budget turns amber in the full view and the compact HUD, and its tooltip names the
156
+ budget. The FPS, CPU and GPU graphs draw the budget as a dashed line once the series reaches it; the
157
+ scale never stretches to fit it, so a quiet graph keeps its detail.
158
+
159
+ Timing budgets come from `targetFps` (60 by default): FPS at least 95% of it, 1% low at least half,
160
+ CPU and GPU within one frame (16.7 ms), frame p99 within one and a half. Counts have no default,
161
+ since what's reasonable depends on the scene. Set your own:
162
+
163
+ ```ts
164
+ mountPerfHud(monitor, { budgets: { targetFps: 120, calls: 500, triangles: 2_000_000 } });
165
+ hud.setBudgets({ gpu: null }); // null drops a default; false drops them all
166
+ ```
167
+
168
+ `PerfHud` takes the same `budgets` prop and applies changes live.
169
+
146
170
  ## Stutter
147
171
 
148
172
  Average FPS hides a hitch every few seconds. Three rows in the full view catch it, and any of them
@@ -1,4 +1,28 @@
1
1
  import { d as TimingMetric, t as PerformanceMonitor } from "./performance-monitor-CBN05_BC.js";
2
+ //#region src/ui/budgets.d.ts
3
+ /**
4
+ * Budgets: the value each metric should stay within. A reading past its
5
+ * budget turns amber in the card, and the FPS / CPU / GPU graphs draw the
6
+ * line once the series reaches it. `fps` and `low` are floors (worse below);
7
+ * everything else is a ceiling (worse above).
8
+ *
9
+ * Timing budgets default from `targetFps` (60): FPS at least 95% of it, 1%
10
+ * low at least half, CPU and GPU within one frame, p99 within one and a half.
11
+ * Counts have no default, since what's reasonable depends on the scene. Pass
12
+ * `null` for a key to drop its default, or `false` for no budgets at all.
13
+ */
14
+ type BudgetKey = "calls" | "cpu" | "fps" | "geometries" | "gpu" | "hitches" | "lines" | "low" | "p99" | "passes" | "points" | "shaders" | "textures" | "triangles";
15
+ type Budgets = Partial<Record<BudgetKey, number | null>> & {
16
+ /** The frame rate the defaults are derived from. Default 60. */
17
+ targetFps?: number;
18
+ };
19
+ type ResolvedBudgets = {
20
+ /** Frame budget in ms, `1000 / targetFps`. */
21
+ frameMs: number;
22
+ limits: Partial<Record<BudgetKey, number>>;
23
+ };
24
+ declare const resolveBudgets: (budgets: Budgets | false | undefined) => ResolvedBudgets;
25
+ //#endregion
2
26
  //#region src/ui/dock-panel.d.ts
3
27
  declare const EDGES: readonly ["left", "right", "top", "bottom"];
4
28
  type ScreenEdge = (typeof EDGES)[number];
@@ -131,6 +155,11 @@ type PerformanceViewOptions = {
131
155
  mode?: PerformanceViewMode;
132
156
  /** Repaint rate. Default 10. */
133
157
  refreshHz?: number;
158
+ /**
159
+ * Limits past which a value turns amber. Timing budgets default from
160
+ * `targetFps` (60); `false` turns them all off. See {@link Budgets}.
161
+ */
162
+ budgets?: Budgets | false;
134
163
  /** Share one between views to keep them in sync; a fresh instance otherwise. */
135
164
  settings?: HudSettings;
136
165
  /**
@@ -171,6 +200,7 @@ declare class PerformanceView {
171
200
  private hudGridEl;
172
201
  private readonly hudGraphs;
173
202
  private readonly hudNumberEls;
203
+ private budgets;
174
204
  private rafId;
175
205
  private lastPaintAt;
176
206
  private readonly resizeObserver;
@@ -180,12 +210,19 @@ declare class PerformanceView {
180
210
  stop(): void;
181
211
  setMode(mode: PerformanceViewMode): void;
182
212
  getMode(): PerformanceViewMode;
213
+ /** Replace the budgets; `false` turns them all off. Applies on the next paint. */
214
+ setBudgets(budgets: Budgets | false | undefined): void;
183
215
  dispose(): void;
184
216
  private frame;
185
217
  private render;
186
218
  /** The monitor caches the environment once its backend settles; until then this re-reads. */
187
219
  private renderFooter;
188
220
  private renderHud;
221
+ private paintNumber;
222
+ /** Value and sparkline, with the budget line drawn once the series reaches it. */
223
+ private paintGraph;
224
+ /** Each value's tooltip names its budget, so amber explains itself. */
225
+ private applyBudgetTitles;
189
226
  private formatTiming;
190
227
  private build;
191
228
  private rebuildHud;
@@ -221,6 +258,12 @@ type MountPerfHudOptions = {
221
258
  injectStyles?: boolean;
222
259
  /** Repaint rate. Default 10. */
223
260
  refreshHz?: number;
261
+ /**
262
+ * Limits past which a value turns amber, e.g. `{ calls: 500, targetFps: 120 }`.
263
+ * Timing budgets default from `targetFps` (60); `false` turns them all off.
264
+ * Change later with the handle's `setBudgets`.
265
+ */
266
+ budgets?: Budgets | false;
224
267
  /** Accessible name of the panel. Default `Performance`. */
225
268
  label?: string;
226
269
  };
@@ -240,9 +283,11 @@ type PerfHudHandle = {
240
283
  getTheme: () => ThemeMode;
241
284
  /** Sets the consumer layer; a pick made in the panel still wins until `settings.setTheme(null)`. */
242
285
  setTheme: (mode: ThemeMode) => void;
286
+ /** Replace the budgets; `false` turns them all off. */
287
+ setBudgets: (budgets: Budgets | false | undefined) => void;
243
288
  dispose: () => void;
244
289
  };
245
290
  declare const mountPerfHud: (monitor: PerformanceMonitor, options?: MountPerfHudOptions) => PerfHudHandle;
246
291
  //#endregion
247
- export { dockPanel as C, ScreenEdge as S, DefaultPlacement as _, PerformanceViewMode as a, DockPanelOptions as b, HudDefaults as c, HudSettingsOptions as d, HudTheme as f, isThemeMode as g, ThemeMode as h, PerformanceView as i, HudSelection as l, THEME_MODES as m, PerfHudHandle as n, PerformanceViewOptions as o, ResolvedTheme as p, mountPerfHud as r, DEFAULT_STORAGE_KEY as s, MountPerfHudOptions as t, HudSettings as u, DockAlign as v, Placement as x, DockHandle as y };
248
- //# sourceMappingURL=mount-perf-hud-CmINOH3T.d.ts.map
292
+ export { dockPanel as C, resolveBudgets as D, ResolvedBudgets as E, ScreenEdge as S, Budgets as T, DefaultPlacement as _, PerformanceViewMode as a, DockPanelOptions as b, HudDefaults as c, HudSettingsOptions as d, HudTheme as f, isThemeMode as g, ThemeMode as h, PerformanceView as i, HudSelection as l, THEME_MODES as m, PerfHudHandle as n, PerformanceViewOptions as o, ResolvedTheme as p, mountPerfHud as r, DEFAULT_STORAGE_KEY as s, MountPerfHudOptions as t, HudSettings as u, DockAlign as v, BudgetKey as w, Placement as x, DockHandle as y };
293
+ //# sourceMappingURL=mount-perf-hud-6LeJ93Jg.d.ts.map