@needle-tools/three-mesh-effects 0.3.4 → 0.3.6

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 (65) hide show
  1. package/CHANGELOG.md +32 -27
  2. package/README.md +63 -231
  3. package/SKILL.md +11 -68
  4. package/build/box-impostor-runtime.js +14 -2
  5. package/build/box-impostor-runtime.js.map +2 -2
  6. package/build/deformation-runtime.js +1 -1
  7. package/build/deformation-runtime.js.map +1 -1
  8. package/build/hull-effects.js.map +1 -1
  9. package/build/impostor-runtime.js +2 -2
  10. package/build/impostor-runtime.js.map +2 -2
  11. package/build/index.js +2 -2
  12. package/build/index.js.map +2 -2
  13. package/build/internal/box-impostor/box-impostor-display.js +10 -2
  14. package/build/internal/box-impostor/box-impostor-display.js.map +2 -2
  15. package/build/internal/box-impostor/box-impostor-faces.js.map +1 -1
  16. package/build/internal/box-impostor/box-impostor-geometry.js +4 -0
  17. package/build/internal/box-impostor/box-impostor-geometry.js.map +2 -2
  18. package/build/internal/box-impostor/box-impostor-material.js +10 -2
  19. package/build/internal/box-impostor/box-impostor-material.js.map +2 -2
  20. package/build/internal/box-impostor/box-impostor-metadata.js +4 -0
  21. package/build/internal/box-impostor/box-impostor-metadata.js.map +2 -2
  22. package/build/internal/box-impostor/box-impostor-projection.js.map +1 -1
  23. package/build/internal/box-impostor/box-impostor-runtime.js +14 -2
  24. package/build/internal/box-impostor/box-impostor-runtime.js.map +2 -2
  25. package/build/internal/deformation/rig-runtime.js +1 -1
  26. package/build/internal/deformation/rig-runtime.js.map +1 -1
  27. package/build/internal/impostor/impostor-node-material.js +2 -2
  28. package/build/internal/impostor/impostor-node-material.js.map +2 -2
  29. package/build/internal/impostor/octahedral.js.map +1 -1
  30. package/build/internal/pixel-impostor/pixel-impostor-display.js +39 -16
  31. package/build/internal/pixel-impostor/pixel-impostor-display.js.map +2 -2
  32. package/build/internal/pixel-impostor/pixel-impostor-metadata.js +61 -6
  33. package/build/internal/pixel-impostor/pixel-impostor-metadata.js.map +2 -2
  34. package/build/internal/pixel-impostor/pixel-impostor-runtime.js +980 -26
  35. package/build/internal/pixel-impostor/pixel-impostor-runtime.js.map +4 -4
  36. package/build/internal/rendering/hull-effect-runtime.js.map +1 -1
  37. package/build/internal/rendering/renderer-support.js.map +1 -1
  38. package/build/internal/rendering/skin-projection.js.map +1 -1
  39. package/build/internal/rendering/surface-query.js.map +1 -1
  40. package/build/internal/rendering/wrap-preview.js.map +1 -1
  41. package/build/internal/rendering/wrap-skin.js.map +1 -1
  42. package/build/pixel-impostor-runtime.js +362 -172
  43. package/build/pixel-impostor-runtime.js.map +4 -4
  44. package/build/types/box-impostor/box-impostor-metadata.d.ts +3 -1
  45. package/build/types/deformation/rig-runtime.d.ts +1 -1
  46. package/build/types/impostor/octahedral.d.ts +1 -1
  47. package/build/types/pixel-impostor/pixel-impostor-display.d.ts +3 -3
  48. package/build/types/pixel-impostor/pixel-impostor-metadata.d.ts +76 -5
  49. package/build/types/pixel-impostor/pixel-impostor-runtime.d.ts +19 -7
  50. package/build/types/public/pixel-impostor-runtime.d.ts +1 -1
  51. package/build/types/rendering/renderer-support.d.ts +1 -1
  52. package/build/types/rendering/surface-query.d.ts +2 -2
  53. package/package.json +2 -2
  54. package/src/box-impostor/box-impostor-material.js +10 -2
  55. package/src/box-impostor/box-impostor-metadata.js +5 -1
  56. package/src/deformation/rig-runtime.ts +1 -1
  57. package/src/impostor/impostor-node-material.js +2 -2
  58. package/src/impostor/octahedral.js +1 -1
  59. package/src/pixel-impostor/pixel-impostor-display.js +32 -18
  60. package/src/pixel-impostor/pixel-impostor-metadata.js +69 -9
  61. package/src/pixel-impostor/pixel-impostor-runtime.js +32 -9
  62. package/src/public/index.js +2 -2
  63. package/src/public/pixel-impostor-runtime.js +1 -1
  64. package/src/rendering/renderer-support.js +1 -1
  65. package/src/rendering/surface-query.js +2 -2
package/CHANGELOG.md CHANGED
@@ -1,56 +1,61 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.6 - 2026-11-25
4
+
5
+ - Restore saved pixel and voxel impostor display settings when loading with `useLoader` or passing a renderer to `registerNeedlePixelImpostorLoader`.
6
+ - Load smaller pixel impostor files that use a bounding box in place of the voxel mesh for raycast and screen-pixel displays.
7
+
8
+ ## 0.3.5 - 2026-11-22
9
+
10
+ - Render edge reflections and HDR emission in box and card impostors.
11
+
3
12
  ## 0.3.4 - 2026-11-22
4
13
 
5
- - Use Mesh Effects with the latest Three.js, r187. WebGPURenderer is supported from r185 and WebGLRenderer from r187.
6
- - Ground octahedral impostors in your scene with real-time shadows on WebGPU, shaped by the captured model.
14
+ - Support Three.js r187 with `WebGLRenderer` and r185 or later with `WebGPURenderer`.
15
+ - Cast real-time shadows from octahedral impostors on WebGPU.
7
16
 
8
17
  ## 0.3.3 - 2026-11-16
9
18
 
10
- - Reduce first-use shader compilation stalls for octahedral impostors.
19
+ - Reduce shader compilation stalls when octahedral impostors first appear.
11
20
 
12
21
  ## 0.3.2 - 2026-11-13
13
22
 
14
- - Support Three.js r186 and load box and card impostors automatically with WebGLRenderer.
15
- - Smooth box-impostor shading and view transitions, including capture edges.
16
- - Correct point and spot lighting on reconstructed impostor surfaces.
23
+ - Support Three.js r186 and load box and card impostors automatically with `WebGLRenderer`.
24
+ - Smooth shading and view transitions on box impostors.
25
+ - Fix point and spot lighting on reconstructed impostor surfaces.
17
26
  - Keep traced boxes and fitted cards visible when the camera enters their bounds.
18
- - Preserve scene intersections with standard, reversed and logarithmic depth buffers.
19
- - Avoid repeated shader compilation when rendering box and card impostors on WebGL.
27
+ - Preserve scene intersections with standard, reversed, and logarithmic depth buffers.
28
+ - Avoid repeated shader compilation for box and card impostors on WebGL.
20
29
 
21
30
  ## 0.3.1 - 2026-11-11
22
31
 
23
- - Show card and box carrier outlines without triangulation diagonals, including card overlays on WebGPU.
24
- - Add High Contrast with black lines and a thin gray outline, plus Cyan, Lime and Magenta preview wireframe colors.
25
-
26
- - Keep narrow captured surfaces visible in box impostors at oblique angles. The traced renderer now scales its search to the crossed texture pixels, improving detailed assets at increased GPU cost.
27
-
28
- - Preserve steep surfaces between sparse octahedral captures, with bounded candidate validation that rejects false depth shells. This improves coverage at an increased GPU cost.
32
+ - Draw card and box carrier outlines without triangulation diagonals.
33
+ - Add high-contrast, cyan, lime, and magenta wireframes.
34
+ - Preserve narrow surfaces at oblique angles in box impostors and steep surfaces between octahedral captures.
29
35
 
30
36
  ## 0.3.0 - 2026-11-06
31
37
 
32
- - Keep nearer surfaces visible when another card or box capture sees a farther layer.
33
- - Add experimental basic cards, fitted cards and fitted-box impostors with automatic glTF loading and shared PBR atlases.
34
- - Recover more silhouette detail in card and box impostors, with smoother edge lighting and voxel-based empty-space rejection.
35
- - Reduce GPU rendering cost for depth-reconstructed card and box impostors without lowering image quality.
36
- - Improve cloth stability and contact handling with overlapping colliders.
38
+ - Load experimental basic card, fitted card, and fitted box impostors with shared PBR atlases.
39
+ - Preserve near surfaces where captures overlap and improve silhouette detail and edge lighting.
40
+ - Reduce GPU rendering cost for depth-reconstructed card and box impostors.
41
+ - Improve cloth stability around overlapping colliders.
37
42
 
38
43
  ## 0.2.3 - 2026-10-30
39
44
 
40
- - Preserve impostor shading and fur detail as higher-quality textures arrive through progressive loading.
41
- - Keep impostor views aligned and sharp when color and shading textures load at different resolutions.
45
+ - Preserve impostor shading and fur detail as higher-resolution textures load.
46
+ - Keep impostor views aligned when color and shading textures load at different resolutions.
42
47
 
43
48
  ## 0.2.2 - 2026-10-21
44
49
 
45
- - Help coding agents integrate Mesh Effects with bundled guidance for Three.js and Needle Engine, covering loading, animation and cleanup.
50
+ - Bundle integration guidance for loading, animation, and cleanup in Three.js and Needle Engine.
46
51
 
47
52
  ## 0.2.1 - 2026-10-21
48
53
 
49
- - Get started more easily with a reorganized Quick start and guidance for compressed model loading.
54
+ - Document how to configure loaders for compressed glTF models.
50
55
 
51
56
  ## 0.2.0 - 2026-10-21
52
57
 
53
- - Register `useLoader(loader, renderer)` once to load any combination of supported Needle glTF extensions automatically.
54
- - Choose which effects to enable with the typed `disable` option. Optional effects retain their portable fallback; required effects report when they cannot load.
55
- - Restore exported hull effects with their saved appearance and settings, including animated models.
56
- - Attach or detach an original model with `bindHull` for display and animation syncing, or use a hull effect on its own.
58
+ - Load supported Needle glTF extensions with one call to `useLoader(loader, renderer)`.
59
+ - Opt out of individual extensions with `disable`. Optional extensions use the asset's fallback and required extensions fail to load.
60
+ - Restore saved hull effects on static and animated models.
61
+ - Attach or detach the original model at runtime with `bindHull`.
package/README.md CHANGED
@@ -1,4 +1,8 @@
1
- Three.js loaders and TSL materials for GLBs exported by [Needle Mesh Baker](https://mesh-baker.needle.tools).
1
+ # Three Mesh Effects
2
+
3
+ Three.js loaders and TSL materials for glTF impostors, hull effects, and deformation rigs.
4
+
5
+ You can create compatible glTF assets with [Needle Mesh Baker](https://mesh-baker.needle.tools).
2
6
 
3
7
  ## Install
4
8
 
@@ -6,22 +10,19 @@ Three.js loaders and TSL materials for GLBs exported by [Needle Mesh Baker](http
6
10
  npm install @needle-tools/three-mesh-effects three
7
11
  ```
8
12
 
9
- The package supports Three.js r185 and later with `WebGPURenderer`, and r187
10
- and later with `WebGLRenderer`. Its Needle Engine adapter is an
11
- optional import. The examples use ordinary Three.js and assume an existing
12
- `renderer`, `scene`, and `camera`.
13
+ Use Three.js r185 or later with `WebGPURenderer`, or r187 or later with `WebGLRenderer`. The examples assume you already have a renderer, scene, and camera.
13
14
 
14
15
  ## Features
15
16
 
16
- - **Hull effects:** Restore the saved effect automatically, optionally binding its source model.
17
- - **Card and box impostors (experimental):** Project or reconstruct six captures per part using shared PBR atlases.
18
- - **Octahedral impostors:** Load exported glTF extensions with a Three.js TSL material.
19
- - **Deformation rigs:** Run IK and secondary motion alongside standard animation clips.
20
- - **Pixel and voxel impostors:** Create the display mode selected in the workbench.
17
+ - **Card and box impostors (experimental)** render PBR captures on cards or fitted boxes.
18
+ - **Octahedral impostors** reproject captured views onto a two-triangle billboard and cast shadows on WebGPU.
19
+ - **Pixel and voxel impostors** render voxel meshes, splats, or raycast volumes.
20
+ - **Hull effects** restore saved materials and can follow an original model's animation.
21
+ - **Deformation rigs** add IK and secondary motion to standard glTF animation.
21
22
 
22
23
  ## Quick start
23
24
 
24
- Register once, then load any Mesh Baker glTF without knowing its extensions:
25
+ Register the extension loaders before loading a model. `useLoader` returns the same `GLTFLoader` and loads each handler when an asset declares its extension.
25
26
 
26
27
  ```js
27
28
  import { useLoader } from '@needle-tools/three-mesh-effects';
@@ -32,231 +33,92 @@ const { scene: model } = await loader.loadAsync('/model.glb');
32
33
  scene.add(model);
33
34
  ```
34
35
 
35
- This handles hull effects, deformation rigs, box and card impostors, octahedral impostors, and pixel impostor atlas
36
- bindings, including assets combining extensions. It also works with `load`,
37
- `parse`, and `parseAsync`. Each handler is dynamically imported only for assets
38
- declaring that extension; bundlers can keep those imports in separate chunks.
39
- Dynamic imports defer downloads, rather than removing handlers that an asset
40
- might need. The existing individual registration functions remain available.
36
+ Configure any Draco, Meshopt, or KTX2 decoders or loaders on the same `GLTFLoader`. On `WebGLRenderer`, `useLoader` installs Three.js's `WebGLNodesHandler` when loading an enabled extension. If your renderer already has a compatible handler, set `renderer.capabilities.supportsNodeMaterials = true`.
41
37
 
42
- On `WebGLRenderer`, loading an enabled Mesh Effects extension installs Three's
43
- `WebGLNodesHandler` once per renderer, so the same TSL materials render on WebGL.
44
- Ordinary glTF files and disabled extensions leave the renderer untouched. Hosts
45
- with their own compatible handler can advertise
46
- `renderer.capabilities.supportsNodeMaterials = true` to retain it.
38
+ All five extensions are enabled by default. Pass `{ disable: ['NEEDLE_mesh_impostor'] }` as the third argument to opt out of a handler. The supported names are `NEEDLE_box_impostor`, `NEEDLE_deformation_rig`, `NEEDLE_hull_effect`, `NEEDLE_mesh_impostor`, and `NEEDLE_pixel_impostor`. A disabled optional extension uses the asset's fallback. If the asset requires a disabled extension, the load fails. Call `useLoader` again to change the renderer or replace the disable list for future loads.
47
39
 
48
- All extensions are enabled by default. To opt out of specific handlers, pass
49
- their glTF extension names in the optional third argument:
40
+ ## Card and box impostors
50
41
 
51
- ```js
52
- useLoader(loader, renderer, { disable: ['NEEDLE_mesh_impostor'] });
53
- ```
42
+ `NEEDLE_box_impostor` uses six orthographic captures per part. Flat captures can use direct projection. Depth reconstruction preserves more silhouette and parallax detail at a higher shader cost. Raycasts against the Three.js mesh hit the carrier geometry.
54
43
 
55
- Supported keys are `NEEDLE_box_impostor`, `NEEDLE_hull_effect`, `NEEDLE_mesh_impostor`, `NEEDLE_pixel_impostor`, and
56
- `NEEDLE_deformation_rig`. Disabled optional extensions keep their portable
57
- fallback without importing the handler. A disabled extension listed in the
58
- asset's `extensionsRequired` rejects the load with an error. Calling `useLoader`
59
- again replaces the renderer and disable list for subsequent parses; omitting
60
- options enables everything again.
61
-
62
- If a model uses Draco, Meshopt, or KTX2 compression, you must configure the
63
- corresponding decoder or texture loader on your `GLTFLoader` yourself.
64
- `useLoader` handles Needle extensions; it does not configure compression decoders.
65
- Rig animation still needs a per-frame update, pixel display modes remain available
66
- through `createPixelImpostorDisplay`. Hull effects load alone; optionally use
67
- `bindHull` to add an original model and animation syncing.
68
-
69
- When your loader also supports `NEEDLE_progressive`, impostor shading and fur
70
- textures can change resolution in place. Material bindings and size-dependent
71
- sampling update when a texture is replaced; fur height keeps its UV channel and
72
- texture transforms. Resize impostor atlases per frame rather than filtering
73
- across neighboring views. Compact shading alpha stores material data and needs
74
- independent channel filtering and lossless PNG encoding. Packed depth/geometry
75
- and sparse pixel-impostor records must retain their authored resolution.
76
-
77
- ## Card and fitted-box impostors (experimental)
78
-
79
- `NEEDLE_box_impostor` stores six orthographic PBR/depth views for each oriented
80
- part, packed into four shared atlases. Basic mode draws one camera-facing card;
81
- `cards` draws one per fitted region, and `fitted` draws twelve-triangle box proxies. Motion/opacity batches share atlas textures;
82
- transparent boxes use separate draws for depth sorting. The runtime supports direct
83
- plane projection, source-material transparency and standard rigid node
84
- animation. Auto depth uses projection for flat captures and traces other captures.
85
- Every display setting retains the same compact geometry: two triangles per card
86
- or twelve per fitted box. Explicit projection trades curved silhouette/parallax
87
- accuracy for lower shader cost. Fitted boxes with projection and no view blending
88
- use ordinary fitted faces with no fragment depth search. Projected cards select
89
- the nearest supported plane before blending. Captured depth bounds shorten traced
90
- searches, and padded depth needs one texture read per step. Tracing checks the
91
- supported captures in facing order and retains the nearest validated surface,
92
- including surfaces hidden from the most directly facing capture.
93
- Conservative voxel masks reject empty rays without reducing texture resolution.
94
- Filtered normals preserve edge lighting. Geometric occupancy
95
- in the material atlas rejects empty hits. Sampling rejects depth discontinuities
96
- that would otherwise form extruded walls. Captures preserve surface opacity
97
- independently of the display cutoff. `useLoader(loader, renderer)` enables it automatically.
98
-
99
- Use `WebGLRenderer` or `WebGPURenderer` from `three/webgpu`. `useLoader` and the
100
- manual box registration enable Three's WebGL TSL handler when needed. Renderers
101
- without node-material support retain the portable fallback for optional box
102
- extensions and reject required ones. Captures remain fixed in their animated node frame.
103
- A nearest-surface depth field cannot represent all hidden layers; split complex
104
- parts into more boxes when gaps or occluded surfaces disappear.
105
-
106
- Depth-writing variants use the reconstructed surface for depth, point/spot lighting
107
- and received shadows. Enable Three's shadow map and the usual light/mesh
108
- `castShadow` and mesh `receiveShadow` flags. Raster reflection probes use
109
- `CubeRenderTarget` with `WebGPURenderer`; geometry raycasts still see the compact
110
- carrier. Alpha-blended variants retain sorting and do not write depth.
111
-
112
- For manual integration, `@needle-tools/three-mesh-effects/box-impostor-runtime`
113
- exports `registerNeedleBoxImpostorLoader(loader, { renderer })`,
114
- `createBoxImpostorGeometry(descriptor)`, `createBoxImpostorMaterial(descriptor, maps)`
115
- `parseBoxImpostorDescriptor`, and `setBoxImpostorDisplay(root, options)`. `maps` binds `baseColor`, `normalDepth`, `orm`
116
- and `emissive` explicitly. The material owns its small rectangle lookup texture;
117
- dispose the material and geometry on unload, and dispose shared atlas textures
118
- once their last consumer is gone. No per-frame update is needed.
119
-
120
- Change display settings after loading without rebuilding the geometry or atlases:
44
+ Change the display after loading with `useLoader`:
121
45
 
122
46
  ```js
123
47
  import { setBoxImpostorDisplay } from '@needle-tools/three-mesh-effects/box-impostor-runtime';
124
- setBoxImpostorDisplay(gltf.scene, {
125
- depthMode: 'auto', // auto, projection, depth
126
- raySteps: 16,
127
- interpolation: 'smooth', // none, linear, smooth
128
- transparency: 'auto', // auto, cutout, dithered, blended
48
+
49
+ setBoxImpostorDisplay(model, {
50
+ depthMode: 'auto', // 'auto', 'projection', 'depth'
51
+ raySteps: 16, // 8, 16, 32
52
+ interpolation: 'smooth', // 'none', 'linear', 'smooth'
53
+ transparency: 'auto', // 'auto', 'cutout', 'dithered', 'blended'
129
54
  alphaCutoff: 0.5,
130
55
  });
131
56
  ```
132
57
 
133
- Interpolation blends occupied captured planes, or depth-consistent samples on traced surfaces. Auto transparency follows each primitive’s source alpha mode. Blended
134
- opacity uses sorted draws without depth writes. Dithered opacity uses
135
- alpha hashing; captures do not represent layered glass or refraction. Cutout
136
- uses the live alpha cutoff.
137
- Depth quality, interpolation and transparency select cached compiled materials;
138
- disposing the current material releases its cached variants without disposing
139
- shared atlases. Dispose geometry separately; a renderer may refresh its buffers
140
- without unloading the material.
141
- `DEFAULT_BOX_IMPOSTOR_DISPLAY` and `normalizeBoxImpostorDisplay` expose the same
142
- defaults and validation used by loading and live updates.
143
-
144
- Explicit depth reconstruction compiles Low, Medium or High adaptive sampling
145
- (`raySteps: 8`, `16` or `32`). These set minimum interval budgets and respectively
146
- 1, 2 or 4 samples per projected capture texel along the dominant texture axis;
147
- they are not maximum counts. Oblique rays can require hundreds of samples.
148
- Projection omits depth search entirely. Keep depth bytes lossless, atlas
149
- resolution unchanged and mipmaps disabled: filtering packed 16-bit depth or
150
- across neighboring views corrupts reconstruction.
151
-
152
- ## Hull effects
58
+ `raySteps` selects the sampling quality for depth reconstruction. Oblique rays can take more samples than the setting. `auto` transparency follows the source alpha mode. Blended impostors use sorted draws without depth writes. Keep packed depth textures lossless at their original resolution with mipmaps disabled.
153
59
 
154
- When exporting with a hull effect selected, Mesh Baker saves its mode and
155
- settings in `NEEDLE_hull_effect`. `useLoader` restores it without a second model:
60
+ For manual setup, the same entry point exports `registerNeedleBoxImpostorLoader(loader, { renderer })`, `parseBoxImpostorDescriptor`, `createBoxImpostorGeometry`, and `createBoxImpostorMaterial`. Pass `baseColor`, `normalDepth`, `orm`, and `emissive` in the material's maps. Dispose the material and geometry on unload. Dispose shared atlases after their final consumer.
156
61
 
157
- ```js
158
- import { useLoader } from '@needle-tools/three-mesh-effects';
159
- import { bindHull, getHullEffect } from '@needle-tools/three-mesh-effects/hull-effects';
160
- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
161
-
162
- const loader = useLoader(new GLTFLoader(), renderer);
163
- const { scene: hull } = await loader.loadAsync('/hull.glb');
164
- scene.add(hull);
165
- let effect = getHullEffect(hull);
62
+ ## Octahedral impostors
166
63
 
167
- // Optional: show the original inside the hull and follow its animation.
168
- const { scene: original } = await loader.loadAsync('/original.glb');
169
- effect = bindHull(hull, original, { animate: true });
170
- // Each frame: advance your AnimationMixers, then effect.syncAnimation().
171
- // Call effect.dispose() before removing the hull.
172
- ```
64
+ `NEEDLE_mesh_impostor` supplies the view atlases and settings. For manual registration, import `registerNeedleImpostorLoader` from `@needle-tools/three-mesh-effects/impostor-runtime` and call `registerNeedleImpostorLoader(loader, { renderer })` before loading.
173
65
 
174
- `bindHull` replaces the automatically created effect, preserving its settings.
175
- It borrows the original and leaves the caller's hierarchy and resources intact.
176
- Get the current effect again after rebinding; old bindings no longer control it.
177
- `bindHull(hull, null)` detaches the original and restores the standalone effect.
178
- `getHullEffect(hull)` returns `undefined` for an ordinary or disposed hull.
179
- Standalone animated hulls can follow their own animation; call `syncAnimation()`
180
- after updating their mixers or deformation rig. TSL effects require
181
- `WebGPURenderer` from `three/webgpu` or `WebGLRenderer` with Three's
182
- `WebGLNodesHandler`, which `useLoader` enables when loading an effect.
66
+ ![Octahedral impostor example](https://needle.click/yyqae2kdwecbmg5cqw2q.gif)
183
67
 
184
- The existing manual API remains available for models without the extension.
185
- Here the hull supplies the effect's surface and the original stays visible inside:
186
- Available modes and their defaults are in `HULL_EFFECT_MODES` and
187
- `createHullEffectValues()`:
68
+ ## Pixel and voxel impostors
188
69
 
189
- ![Hull effect preview](https://needle.click/3f8bbjvfjxbgswy3cvbx.gif)
70
+ `useLoader` reads the display settings stored in `NEEDLE_pixel_impostor` and applies them with a renderer that supports node materials. To change the mode after loading, use the scene's display handle and dispose it when unloading the model.
190
71
 
191
72
  ```js
192
- import { createHullEffect, createHullEffectValues } from '@needle-tools/three-mesh-effects/hull-effects';
193
- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
194
-
195
- const loader = new GLTFLoader();
196
- const [{ scene: hull }, { scene: original }] = await Promise.all([
197
- loader.loadAsync('/hull.glb'), // Exported by Mesh Baker.
198
- loader.loadAsync('/original.glb'), // The model uploaded to Mesh Baker.
199
- ]);
200
- scene.add(hull);
201
- const effect = createHullEffect(hull, original, createHullEffectValues().flames);
202
- // For animated models, advance both mixers and call effect.syncAnimation() each frame.
203
- // Call effect.dispose() at teardown.
73
+ const display = model.userData.pixelImpostorDisplay;
74
+ display?.setMode('screen-pixels');
75
+ // At teardown:
76
+ display?.dispose();
204
77
  ```
205
78
 
206
- ### Hull extension contract
79
+ Standalone registration is available as `registerNeedlePixelImpostorLoader(loader, { renderer })` from `@needle-tools/three-mesh-effects/pixel-impostor-runtime`. With no renderer, it loads the texture bindings and leaves the mesh as stored in the file. To set your own options, register without a renderer and call `createPixelImpostorDisplay(model, { renderer, mode: 'screen-pixels', pixelSize: 5 })` from the same entry point. Omitted options use the asset's settings when present. For a manually created display, call `updateViewport()` after a resize or pixel ratio change.
207
80
 
208
- `NEEDLE_hull_effect` version 1 is stored on the glTF scene containing the hull:
81
+ Assets with a bounding box in place of a voxel shell support `raycast` and `screen-pixels`, and can use `vertex-snap` when surface points are present. The `geometry` mode requires a voxel shell.
209
82
 
210
- ```json
211
- { "version": 1, "mode": "flames", "values": { "height": 0.51, "speed": 1 } }
212
- ```
83
+ ## Hull effects
213
84
 
214
- The name appears in `extensionsUsed`. Exported hull geometry and standard
215
- materials remain a portable fallback, so it is not marked required. `mode` must
216
- be a supported `HULL_EFFECT_MODES` value; omitted controls use their documented
217
- defaults, finite numeric values are clamped to their control ranges. Unknown
218
- versions, unknown modes, and non-finite or non-numeric control values fail
219
- explicitly. The extension stores no source URL and triggers no source download.
220
- Each scene with the extension gets its own runtime; dispose each when unloading.
85
+ `useLoader` restores the effect from the scene's `NEEDLE_hull_effect` extension. An original model is optional.
221
86
 
222
- ## Octahedral impostors
87
+ ```js
88
+ import { bindHull, getHullEffect } from '@needle-tools/three-mesh-effects/hull-effects';
223
89
 
224
- An 800,000-triangle source represented by a two-triangle impostor:
90
+ const { scene: hull } = await loader.loadAsync('/hull.glb');
91
+ scene.add(hull);
92
+ let effect = getHullEffect(hull);
225
93
 
226
- ![Octahedral impostor example](https://needle.click/yyqae2kdwecbmg5cqw2q.gif)
94
+ // Optional: attach the original model and follow its animation.
95
+ const { scene: original } = await loader.loadAsync('/original.glb');
96
+ effect = bindHull(hull, original, { animate: true });
227
97
 
228
- Register the extension loader before loading an exported impostor GLB:
98
+ // For animation, call effect.syncAnimation() after updating mixers and rigs.
99
+ // At teardown, call effect.dispose().
100
+ ```
229
101
 
230
- ```js
231
- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
232
- import { registerNeedleImpostorLoader } from '@needle-tools/three-mesh-effects/impostor-runtime';
102
+ `bindHull` returns the current effect and borrows the original model. `bindHull(hull, null)` detaches the original and restores the standalone effect. For a hull without the extension, use `createHullEffect(hull, original, createHullEffectValues().flames)` from the same entry point. `HULL_EFFECT_MODES` lists the available modes.
233
103
 
234
- const loader = new GLTFLoader();
235
- // Register before loading so the extension can replace the portable fallback.
236
- registerNeedleImpostorLoader(loader, { renderer });
237
- const { scene: model } = await loader.loadAsync('/result_impostor.glb');
238
- scene.add(model);
239
- ```
104
+ The scene-level extension uses `version: 1`, a `mode` from `HULL_EFFECT_MODES`, and numeric `values` for that mode. Omitted values use the defaults. A standard glTF loader displays the hull geometry and materials.
240
105
 
241
106
  ## Deformation rigs
242
107
 
243
- For a rigged GLB, register the extension before loading and advance the rig
244
- once per frame. Update the animation mixer first:
108
+ Load the model with `useLoader` and update its animation mixer before updating the rig each frame:
245
109
 
246
110
  ```js
247
111
  import { AnimationMixer, Clock } from 'three';
248
- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
249
- import { registerNeedleDeformationRigLoader, getDeformationRig } from '@needle-tools/three-mesh-effects/deformation-runtime';
112
+ import { getDeformationRig } from '@needle-tools/three-mesh-effects/deformation-runtime';
250
113
 
251
- const loader = new GLTFLoader();
252
- // Register before loading so the rig extension is available while parsing.
253
- registerNeedleDeformationRigLoader(loader);
254
- const { scene: riggedModel, animations } = await loader.loadAsync('/rigged.glb');
255
- scene.add(riggedModel);
256
- const clock = new Clock();
257
- const mixer = new AnimationMixer(riggedModel);
114
+ const { scene: model, animations } = await loader.loadAsync('/rigged.glb');
115
+ scene.add(model);
116
+
117
+ const mixer = new AnimationMixer(model);
258
118
  if (animations[0]) mixer.clipAction(animations[0]).play();
259
- const rig = getDeformationRig(riggedModel);
119
+ const rig = getDeformationRig(model);
120
+ const clock = new Clock();
121
+
260
122
  renderer.setAnimationLoop(() => {
261
123
  const dt = clock.getDelta();
262
124
  mixer.update(dt);
@@ -265,38 +127,8 @@ renderer.setAnimationLoop(() => {
265
127
  });
266
128
  ```
267
129
 
268
- Standard animation clips use an ordinary Three.js `AnimationMixer`. Update the
269
- mixer before `rig.update(deltaSeconds)` when also using IK or secondary motion.
270
- The runtime respects the animated bone frame; it does not play the clip itself.
271
- Without procedural rig features, the mixer and standard GLTFLoader are sufficient.
272
-
273
- ## Pixel and voxel impostors
274
-
275
- Pixel and voxel impostors have a portable glTF shell. Register the loader and
276
- create the display that matches the chosen workbench mode:
277
-
278
- ```js
279
- import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
280
- import { registerNeedlePixelImpostorLoader, createPixelImpostorDisplay } from '@needle-tools/three-mesh-effects/pixel-impostor-runtime';
281
-
282
- const loader = new GLTFLoader();
283
- // Register before loading so the pixel atlas is available while parsing.
284
- registerNeedlePixelImpostorLoader(loader);
285
- const { scene: pixelModel } = await loader.loadAsync('/pixel.glb');
286
- scene.add(pixelModel);
287
- const display = createPixelImpostorDisplay(pixelModel, { renderer, mode: 'screen-pixels', pixelSize: 5 });
288
- // Call display.updateViewport() after a resize and display.dispose() at teardown.
289
- ```
290
-
291
- ## Needle Engine and glTF fallbacks
292
-
293
- `impostor-runtime/needle-engine` is a separate optional import that requires
294
- `@needle-tools/engine`; ordinary Three.js applications never import it.
295
-
296
- Each GLB has a portable fallback. Register its extension loader to reproduce
297
- the workbench's full result. See the download-time snippet in the workbench
298
- for the code and settings specific to an exported model.
130
+ Dispose the rig when unloading the model. For manual registration, call `registerNeedleDeformationRigLoader(loader)` from the same entry point before loading.
299
131
 
300
- ## Contact
132
+ ## Needle Engine
301
133
 
302
- Questions or feedback? Email [hi@needle.tools](mailto:hi@needle.tools).
134
+ The optional `@needle-tools/three-mesh-effects/impostor-runtime/needle-engine` entry point registers the octahedral impostor loader and requires `@needle-tools/engine`. For all five extensions, call `useLoader(loader, context.renderer)` in a custom import plugin's `onImport` hook.
package/SKILL.md CHANGED
@@ -1,80 +1,23 @@
1
1
  ---
2
2
  name: three-mesh-effects
3
- description: Integrate Mesh Baker glTF models into Three.js or Needle Engine applications, including extension loading, hull effects, deformation rigs, and impostor displays.
3
+ description: Load glTF impostors, hull effects, and deformation rigs in Three.js and Needle Engine.
4
4
  ---
5
5
 
6
6
  # Three Mesh Effects
7
7
 
8
- Use the public runtime package to reproduce a Mesh Baker export in an existing
9
- viewer. Read [README.md](README.md) for effect-specific examples and supported
10
- Three.js versions. Read `package.json` for the installed version and exports.
8
+ See [README.md](README.md) for installation, renderer requirements, and examples.
11
9
 
12
- ## Loader setup
10
+ ## Loading
13
11
 
14
- Register `useLoader(loader, renderer)` from `@needle-tools/three-mesh-effects`
15
- before loading or parsing an asset. Reuse the application's configured GLTFLoader
16
- and renderer; preserve its Draco, Meshopt, KTX2, progressive-loading and other
17
- plugins. Consumers configure compression decoders themselves.
12
+ Call `useLoader(loader, renderer)` from `@needle-tools/three-mesh-effects` before loading or parsing a model. Reuse the application's GLTFLoader, renderer, and compression decoders. The loader imports handlers for the extensions the asset declares. Pass `{ disable: ['NEEDLE_hull_effect'] }` to opt out of an extension. A disabled optional extension uses the asset's fallback. A disabled required extension fails the load.
18
13
 
19
- The loader detects the asset's declared Needle extensions and dynamically
20
- imports their handlers. Do not require callers to inspect extensions or invoke
21
- separate registration functions. An optional typed third argument can disable
22
- handlers, for example `{ disable: ['NEEDLE_hull_effect'] }`. Everything is enabled
23
- by default. Disabled optional extensions retain their portable fallback;
24
- disabled required extensions reject loading.
14
+ For Needle Engine, call `useLoader(loader, context.renderer)` in the import plugin's `onImport` hook. Register the plugin before creating viewers. Use the application's render loop and teardown hooks.
25
15
 
26
- For Needle Engine, call `useLoader(loader, context.renderer)` in the engine's
27
- custom extension `onImport` hook. Install the integration before creating viewers.
28
- Use the existing render loop and model teardown hooks rather than starting an
29
- independent animation loop.
16
+ ## Updates and cleanup
30
17
 
31
- ## Runtime updates and ownership
18
+ - For deformation rigs, get the runtime with `getDeformationRig(scene)` from `/deformation-runtime`. Update the AnimationMixer first, then call `rig.update(deltaSeconds)`. Dispose the rig on unload.
19
+ - For hull effects, use `getHullEffect(scene)` and `bindHull` from `/hull-effects`. Rebinding returns a replacement effect. Update mixers and rigs before calling `syncAnimation()`. Dispose the current effect on unload. The caller owns the original model's resources.
20
+ - For pixel impostors, the loader applies a saved display when it has a renderer with node-material support. Use `scene.userData.pixelImpostorDisplay` to change modes and dispose the display. To supply your own settings, use `createPixelImpostorDisplay` from `/pixel-impostor-runtime` and call `updateViewport()` after resizes.
21
+ - For card and box impostors, use `setBoxImpostorDisplay` from `/box-impostor-runtime` to adjust depth, blending, and transparency. Animate rigid nodes with the AnimationMixer. Dispose geometry and materials on unload, and shared textures after their last consumer.
32
22
 
33
- - Deformation rigs: obtain `getDeformationRig(scene)` from `/deformation-runtime`.
34
- Advance the application's AnimationMixer first, then `rig.update(deltaSeconds)`.
35
- Dispose the rig before releasing its model.
36
- - Hulls: the versioned scene extension restores the saved effect automatically.
37
- Obtain `getHullEffect(scene)` from `/hull-effects`. An original model is optional.
38
- `bindHull(hull, original, { animate: true })` attaches a borrowed original and
39
- replaces the effect; `bindHull(hull, null)` detaches it. Fetch the current effect
40
- after rebinding, call `syncAnimation()` after mixers and rig updates, and dispose
41
- the current effect before unloading. Never dispose the borrowed original's
42
- geometry, materials or textures as part of binding cleanup.
43
- - Pixel impostors: extension loading restores atlas bindings. Custom display
44
- modes still use `createPixelImpostorDisplay` from `/pixel-impostor-runtime`;
45
- update its viewport and dispose it as documented in the README.
46
- - Card and fitted-box impostors: `useLoader` restores `NEEDLE_box_impostor` with
47
- WebGPURenderer or WebGLRenderer, enabling Three's WebGLNodesHandler as needed. Use `setBoxImpostorDisplay` from
48
- `/box-impostor-runtime` for live depth, view blending, transparency and cutoff
49
- changes. Rigid node animation uses the application's AnimationMixer. Dispose
50
- geometry and materials on unload; material disposal also releases cached
51
- display variants. Dispose shared atlas textures after their final consumer.
52
- Captures contain one surface per direction, so hidden layers and refraction
53
- are approximations; projection and traced modes have different quality costs.
54
- - Octahedral impostors: pass the actual renderer to `useLoader` so the handler
55
- can choose the supported material implementation.
56
-
57
- Hull and other TSL effects require a renderer supporting node materials. Ordinary
58
- Three.js applications use WebGPURenderer from `three/webgpu` or WebGLRenderer
59
- with Three's WebGLNodesHandler. `useLoader` enables the latter lazily for an
60
- enabled extension. Hosts with an existing compiler advertise
61
- `renderer.capabilities.supportsNodeMaterials = true` to preserve it. Reuse the
62
- host's renderer and render loop.
63
-
64
- When a scene is cleared while asynchronous initialization is pending, dispose
65
- any runtimes that finish afterward. Track scenes separately per viewer/context,
66
- including assets with multiple scenes. Avoid loading optional runtime modules
67
- just to poll ordinary models that have no corresponding extension.
68
-
69
- ## Verification
70
-
71
- Exercise real GLTFLoader parsing and the host's update/clear lifecycle. Cover
72
- ordinary assets, mixed extensions, opt-outs, disposal and asynchronous clear/load
73
- races. Verify renderer compatibility when shader effects are involved; mocked
74
- lifecycle tests alone do not establish visual correctness. Report checks that
75
- were not run.
76
-
77
- When extending this package, every new Needle glTF runtime extension must also
78
- work through `useLoader`, including its typed disable key and lazy handler.
79
- Preserve existing manual APIs. Use a versioned glTF extension for runtime data,
80
- retain a portable fallback, and keep runtime contracts out of `extras`.
23
+ If a scene is removed during loading, dispose any runtimes created after its removal.
@@ -69,6 +69,8 @@ function parseBoxImpostorDescriptor(raw) {
69
69
  fail();
70
70
  if (d.alphaMode !== void 0 && !["opaque", "mask", "blend"].includes(d.alphaMode))
71
71
  fail();
72
+ if (d.fresnelOpacity !== void 0 && typeof d.fresnelOpacity !== "boolean") fail();
73
+ if (d.emissiveStrength !== void 0 && (!Number.isFinite(d.emissiveStrength) || d.emissiveStrength < 1)) fail();
72
74
  if (d.mode === "basic" && d.boxes.length !== 1) fail();
73
75
  for (const b of d.boxes) {
74
76
  if (b.occupancy !== void 0 && (!Array.isArray(b.occupancy) || b.occupancy.length !== BOX_OCCUPANCY_WORDS || !b.occupancy.every(
@@ -103,6 +105,8 @@ function parseBoxImpostorDescriptor(raw) {
103
105
  atlasResolution: d.atlasResolution,
104
106
  padding: d.padding,
105
107
  boxes: d.boxes,
108
+ ...d.fresnelOpacity !== void 0 ? { fresnelOpacity: d.fresnelOpacity } : {},
109
+ ...d.emissiveStrength !== void 0 ? { emissiveStrength: d.emissiveStrength } : {},
106
110
  ...d.alphaMode ? { alphaMode: d.alphaMode } : {},
107
111
  ...normalizeBoxImpostorDisplay(d)
108
112
  };
@@ -284,6 +288,7 @@ import {
284
288
  attribute as attribute3,
285
289
  varying,
286
290
  positionLocal as positionLocal2,
291
+ positionViewDirection,
287
292
  modelWorldMatrixInverse,
288
293
  cameraPosition,
289
294
  cameraWorldMatrix,
@@ -1213,8 +1218,15 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false
1213
1218
  material.roughnessNode = surfaceOrm.g;
1214
1219
  material.metalnessNode = surfaceOrm.b;
1215
1220
  material.aoNode = surfaceOrm.r;
1216
- material.emissiveNode = emission;
1217
- if (transparency !== "cutout") material.opacityNode = color.a.clamp(0, 1);
1221
+ material.emissiveNode = emission.mul(descriptor.emissiveStrength ?? 1);
1222
+ if (transparency !== "cutout") {
1223
+ let opacity = color.a.clamp(0, 1);
1224
+ if (descriptor.fresnelOpacity) {
1225
+ const cosine = material.normalNode.dot(positionViewDirection).abs().clamp(0, 1);
1226
+ opacity = opacity.add(opacity.oneMinus().mul(cosine.oneMinus().pow(5)));
1227
+ }
1228
+ material.opacityNode = opacity;
1229
+ }
1218
1230
  material.maskNode = hit.get("valid").greaterThan(0.5);
1219
1231
  material.maskShadowNode = material.maskNode;
1220
1232
  material.depthNode = capturedSurfaceDepth(hit.get("position"));