@zkmake/three-meter 0.13.1 → 0.13.3

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
@@ -9,7 +9,7 @@ textures and shaders in GPU memory. Zero dependencies. Works with `WebGLRenderer
9
9
  bun add -d @zkmake/three-meter # or npm i -D / pnpm add -D
10
10
  ```
11
11
 
12
- Live demo: [zkmake.github.io/three-kit/three-meter](https://zkmake.github.io/three-kit/three-meter/), with a vanilla three and a
12
+ Live demo: [zkmake.github.io/three-kit/three-meter/demo](https://zkmake.github.io/three-kit/three-meter/demo/), with a vanilla three and a
13
13
  React Three Fiber take on the same scene. Add `?webgpu` for the WebGPU renderer and `?count=30000` to
14
14
  load the scene up past the demo's triangle budget.
15
15
 
@@ -68,6 +68,11 @@ Three Fiber, on `WebGLRenderer` and `WebGPURenderer`.
68
68
  | `@zkmake/three-meter/ui` | `mountPerfHud(monitor, options)`, the dockable card. Vanilla DOM. |
69
69
  | `@zkmake/three-meter/react` | `PerfSampler` inside `<Canvas>`, `PerfHud` outside it. Peers: react and r3f. |
70
70
 
71
+ `/ui` also exports the pieces under the HUD, for a host composing its own panel: `PerformanceView`
72
+ (the card's body), `HudSettings`, `HudTheme`, `mountDevPanel`, `dockPanel`, `injectStyles` and
73
+ `PERF_HUD_STYLES`, `resolveBudgets`, `formatReport` and `formatQuality`. The core also exports
74
+ `RingBuffer`, and `/react` `createPerfMonitorStore`.
75
+
71
76
  ## Vanilla three
72
77
 
73
78
  ```ts
@@ -92,6 +97,10 @@ monitor.dispose();
92
97
  If you run your own loop, call `monitor.begin()` before the frame's work and `monitor.end()` after
93
98
  the render.
94
99
 
100
+ Without the HUD, read the monitor: `monitor.getSample()` is the last frame (`fps`, `cpu`,
101
+ `gpu: { ms, available }`, `render` counts, `resources`), and `monitor.getHistory("fps" | "cpu" |
102
+ "gpu")` the last `historySize` values the graphs draw.
103
+
95
104
  ## React Three Fiber
96
105
 
97
106
  ```tsx
@@ -109,7 +118,11 @@ import { PerfHud, PerfSampler } from "@zkmake/three-meter/react";
109
118
 
110
119
  `PerfHud` must sit outside `<Canvas>`, because Fiber treats HTML under it as three objects. The two
111
120
  components find each other through a small shared store. A React context can't do this, since the
112
- Canvas is its own React root. To run two canvases on one page, pass the same `store` prop to both.
121
+ Canvas is its own React root. To run two canvases on one page, give each canvas's `PerfSampler` and
122
+ its `PerfHud` the same `store` prop, one `createPerfMonitorStore()` per pair.
123
+
124
+ `theme`, `mode`, `label`, `budgets` (by value) and `quality` apply live. `defaultPlacement` (by
125
+ value), `storageKey`, `parent`, `refreshHz`, `injectStyles` and `store` remount the HUD.
113
126
 
114
127
  ## Options
115
128
 
@@ -124,9 +137,10 @@ Canvas is its own React root. To run two canvases on one page, pass the same `st
124
137
  | `parent` | `document.body` | Where the host element is appended. |
125
138
  | `injectStyles` | `true` | Append the stylesheet once per document. |
126
139
  | `refreshHz` | `10` | Repaint rate. |
127
- | `budgets` | timing defaults | Limits past which a value turns amber. See [Budgets](#budgets). |
140
+ | `budgets` | timing defaults | Limits past which a value turns amber; `false` for none. See [Budgets](#budgets). |
128
141
  | `quality` | none | Adaptive quality to show. See [Adaptive quality](#adaptive-quality). |
129
142
  | `label` | `"Performance"` | Accessible name of the panel. |
143
+ | `settings` | from `storageKey` | Your own `HudSettings`, e.g. with `defaults` for what a first visit shows. Not on `PerfHud`. |
130
144
 
131
145
  `PerformanceMonitor` and `PerfSampler` take `trackGPU` (default true), `gpuQueryPoolSize` (default 5),
132
146
  `historySize` (default 120) and `frameStatsSize` (default 1000).
@@ -177,10 +191,16 @@ they follow the detected refresh rate, so a 120 Hz display gets 8.3 ms budgets (
177
191
  detected). Counts have no default, since what's reasonable depends on the scene. Set your own:
178
192
 
179
193
  ```ts
180
- mountPerfHud(monitor, { budgets: { targetFps: 120, calls: 500, triangles: 2_000_000 } });
194
+ const hud = mountPerfHud(monitor, {
195
+ budgets: { targetFps: 120, calls: 500, triangles: 2_000_000 },
196
+ });
181
197
  hud.setBudgets({ gpu: null }); // null drops a default; false drops them all
182
198
  ```
183
199
 
200
+ A budget goes on any row by its key: `fps`, `cpu`, `gpu`, `headroom`, `refresh`, `low` (1% low),
201
+ `p99`, `hitches`, `calls`, `triangles`, `lines`, `points`, `passes`, `geometries`, `textures`,
202
+ `shaders`. `fps`, `low` and `headroom` are floors (amber below); the rest are ceilings.
203
+
184
204
  `PerfHud` takes the same `budgets` prop and applies changes live.
185
205
 
186
206
  An app that keeps its budgets in one file with [three-audit](../three-audit)'s `defineBudgets`
@@ -293,6 +313,10 @@ On WebGL2 the monitor uses `EXT_disjoint_timer_query_webgl2`, which Chrome and E
293
313
  and Firefox don't, so the GPU row shows `—` and `sample.gpu.available` is `false`.
294
314
 
295
315
  On WebGPU, construct the renderer with `trackTimestamp: true`. Timings resolve a frame or two late.
316
+ The number is how long the GPU was busy in the frame, with overlapping passes counted once. three's
317
+ own `resolveTimestampsAsync` sums every pass, which on tile-based GPUs (Apple, most mobile) reads
318
+ a post-processing stack at several times its cost; the meter falls back to that sum when three's
319
+ timestamp pool isn't the shape it knows.
296
320
 
297
321
  ## Theme
298
322
 
@@ -325,7 +349,8 @@ palette, override the `--perf-*` custom properties (`bg`, `fg`, `fg-dim`, `muted
325
349
 
326
350
  The HUD's frame is `mountDevPanel` from `@zkmake/three-meter/ui`: the docked host, a card with a
327
351
  brand label on top, and the drag / expand-compact / dim-on-leave discs. Other zkmake dev panels
328
- (`@zkmake/three-textures`) mount through it too, so they all dock, wake, dim and theme the same way.
352
+ (`@zkmake/three-textures`, `@zkmake/three-cameras`) mount through it too, so they all dock, wake,
353
+ dim and theme the same way.
329
354
  A tool of your own can use it:
330
355
 
331
356
  ```ts
@@ -346,7 +371,7 @@ The card is `.perf-hud__card`, holding `.perf-hud__brand` and your content (the
346
371
 
347
372
  ## Examples
348
373
 
349
- [`apps/site/src/demos/three-meter`](https://github.com/zkmake/three-kit/tree/main/apps/site/src/demos/three-meter) is what runs at [zkmake.github.io/three-kit/three-meter](https://zkmake.github.io/three-kit/three-meter/):
374
+ [`apps/site/src/demos/three-meter`](https://github.com/zkmake/three-kit/tree/main/apps/site/src/demos/three-meter) is what runs at [zkmake.github.io/three-kit/three-meter/demo](https://zkmake.github.io/three-kit/three-meter/demo/):
350
375
  both integrations of the same scene, swapped from the header.
351
376
  [`vanilla.ts`](https://github.com/zkmake/three-kit/blob/main/apps/site/src/demos/three-meter/vanilla.ts) is plain three with `mountPerfHud`;
352
377
  [`r3f.tsx`](https://github.com/zkmake/three-kit/blob/main/apps/site/src/demos/three-meter/r3f.tsx) is React Three Fiber with `PerfSampler` and
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as RingBuffer, t as PerformanceMonitor } from "./performance-monitor-CKAI0-Dp.js";
1
+ import { n as RingBuffer, t as PerformanceMonitor } from "./performance-monitor-Dj5H2VXT.js";
2
2
  // src/core/wrap-animation-loop.ts
3
3
  /**
4
4
  * Wrap a `renderer.setAnimationLoop` callback so each tick is one frame:
@@ -1428,7 +1428,7 @@ const mountDevPanel = (options) => {
1428
1428
  };
1429
1429
  // package.json
1430
1430
  var name = "@zkmake/three-meter";
1431
- var version = "0.13.1";
1431
+ var version = "0.13.3";
1432
1432
  // src/ui/clipboard.ts
1433
1433
  /**
1434
1434
  * Copy text from a click handler. The async Clipboard API needs a secure
@@ -2648,4 +2648,4 @@ const mountPerfHud = (monitor, options = {}) => {
2648
2648
  };
2649
2649
  export { mountDevPanel as a, dockPanel as c, HudTheme as d, THEME_MODES as f, formatQuality as i, DEFAULT_STORAGE_KEY as l, resolveBudgets as m, PerformanceView as n, PERF_HUD_STYLES as o, isThemeMode as p, formatReport as r, injectStyles as s, mountPerfHud as t, HudSettings as u };
2650
2650
 
2651
- //# sourceMappingURL=mount-perf-hud-DZ1_LUZ8.js.map
2651
+ //# sourceMappingURL=mount-perf-hud-BRihOM2d.js.map