@zkmake/three-textures 0.1.8 → 0.1.10

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.
Files changed (2) hide show
  1. package/README.md +37 -4
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -13,7 +13,7 @@ original was used. Vanilla three and React Three Fiber.
13
13
  bun add -d @zkmake/three-textures # or npm i -D / pnpm add -D
14
14
  ```
15
15
 
16
- Live demo: [zkmake.github.io/three-kit/three-textures](https://zkmake.github.io/three-kit/three-textures/), with a vanilla three and
16
+ Live demo: [zkmake.github.io/three-kit/three-textures/demo](https://zkmake.github.io/three-kit/three-textures/demo/), with a vanilla three and
17
17
  a React Three Fiber take on the same scene: an image texture and a clone of it, a data texture, and
18
18
  a KTX2 atlas cut into four cards. Download the atlas, paint on it, drop it back.
19
19
 
@@ -26,6 +26,9 @@ const panel = mountTexturePanel({ scene, renderer });
26
26
  // later: panel.dispose()
27
27
  ```
28
28
 
29
+ The handle has `lab` (the `TextureLab` below), `element`, `setCompact(on)`, `setTheme(mode)` and
30
+ `dispose()`.
31
+
29
32
  ## React Three Fiber
30
33
 
31
34
  ```tsx
@@ -38,7 +41,9 @@ import { TexturePanel } from "@zkmake/three-textures/react";
38
41
  ```
39
42
 
40
43
  It reads the scene and renderer from the canvas and asks for a frame after each swap, so
41
- `frameloop="demand"` works.
44
+ `frameloop="demand"` works. Props are the options below minus `scene`, `renderer` and
45
+ `invalidate`, plus `onReady(lab)` for scripting swaps. `theme` follows its prop; the rest are read
46
+ on mount (remount with a new `key` to change them).
42
47
 
43
48
  ## What each row does
44
49
 
@@ -52,7 +57,7 @@ It reads the scene and renderer from the canvas and asks for a frame after each
52
57
  | undo (once swapped) | Put the original back and forget the swap |
53
58
 
54
59
  Swaps are kept in IndexedDB under `storageKey` (default `three-textures`) and come back on reload by
55
- texture name. **Reset all** clears them.
60
+ texture name. **Reset all** clears them. The search box filters rows by name.
56
61
 
57
62
  ## How a swap works
58
63
 
@@ -79,6 +84,9 @@ mountPerfHud(monitor, { defaultPlacement: { edge: "left" } });
79
84
  mountTexturePanel({ scene, renderer }); // right edge by default
80
85
  ```
81
86
 
87
+ [three-devtools](../three-devtools) mounts it behind `?debug` with the HUD: pass
88
+ `panels: { textures: () => import("@zkmake/three-textures/ui") }`.
89
+
82
90
  ## Options
83
91
 
84
92
  ```ts
@@ -93,6 +101,8 @@ mountTexturePanel({
93
101
  theme: "system", // or "dark", "light"
94
102
  defaultPlacement: { edge: "right", align: "start" },
95
103
  compact: false, // start with the list hidden (remembered after the first toggle)
104
+ invalidate: () => requestRender(), // ask for a frame after a swap, for render-on-demand loops
105
+ container: document.body, // where the panel mounts
96
106
  });
97
107
  ```
98
108
 
@@ -120,10 +130,33 @@ await lab.swap("bunny", file);
120
130
  await lab.showOriginal("bunny", true);
121
131
  ```
122
132
 
133
+ `createTexturePanel(lab, { canLink: false })` leaves out the live-link button. The panel also has
134
+ `setTheme("dark" | "light")`, `refresh()` and `dispose()`.
135
+
136
+ | `TextureLab` | Does |
137
+ | -------------------------------------------- | ----------------------------------------------------------------------------------- |
138
+ | `entries()`, `entry(id)` | Every texture by name: kind, format, size, colour space, file, state, link |
139
+ | `subscribe(listener)` | Called on any change; returns the unsubscribe |
140
+ | `refresh()` | Look at the scene again (the panel does this on its own) |
141
+ | `swap(id, blob, { fileName?, persist? })` | Swap an image in; `persist: false` doesn't save it |
142
+ | `showOriginal(id, on)`, `revert(id)` | A/B, and undo |
143
+ | `revertAll()` | Every original back, every saved swap cleared |
144
+ | `toBlob(id)`, `download(id)` | What's showing as a file: the swap, else the source file, else a GPU readback (PNG) |
145
+ | `thumbnail(id, max?)`, `thumbnailAsync(...)` | A data URL, 96 px by default; the async one reads back without stalling the page |
146
+ | `link(id)`, `unlink(id)` | Live link a file; call `link` from a click |
147
+ | `TextureLab.canLink`, `lab.canReadBack` | Whether this browser can live-link, and this renderer read back |
148
+ | `dispose()` | Stop following linked files and drop listeners; swaps stay in place |
149
+
150
+ The core also exports the pieces: `findTextures(root)`, `kindOf` / `formatOf` / `sizeOf`,
151
+ `readTexture`, `readTextureAsync` and `readTextureBlob(renderer, texture, width, height)`,
152
+ `canReadBack(renderer)`, and the swap stores `indexedDbStore(key)` and `memoryStore()` (a
153
+ `TextureLab` takes either as `store`, for tests). `/ui` exports `injectStyles()` and
154
+ `TEXTURE_PANEL_STYLES`.
155
+
123
156
  ## Examples
124
157
 
125
158
  [`apps/site/src/demos/three-textures`](https://github.com/zkmake/three-kit/tree/main/apps/site/src/demos/three-textures)
126
- is what runs at zkmake.github.io/three-kit/three-textures: [`vanilla.ts`](https://github.com/zkmake/three-kit/blob/main/apps/site/src/demos/three-textures/vanilla.ts)
159
+ is what runs at [zkmake.github.io/three-kit/three-textures/demo](https://zkmake.github.io/three-kit/three-textures/demo/): [`vanilla.ts`](https://github.com/zkmake/three-kit/blob/main/apps/site/src/demos/three-textures/vanilla.ts)
127
160
  with `mountTexturePanel`, [`r3f.tsx`](https://github.com/zkmake/three-kit/blob/main/apps/site/src/demos/three-textures/r3f.tsx)
128
161
  with `<TexturePanel />`, each beside the three-meter HUD. `?r3f` opens on Fiber.
129
162
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zkmake/three-textures",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "A dev panel for the textures in a three.js scene: see them, download them, paint them, swap them back in live — compressed (KTX2) textures included. Vanilla three and React Three Fiber.",
5
5
  "keywords": [
6
6
  "devtools",
@@ -46,7 +46,7 @@
46
46
  "typecheck": "tsc"
47
47
  },
48
48
  "dependencies": {
49
- "@zkmake/three-meter": "^0.13.0"
49
+ "@zkmake/three-meter": "^0.13.3"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@arethetypeswrong/core": "catalog:",