@needle-tools/three-mesh-effects 0.1.0 → 0.2.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +114 -16
  3. package/build/hull-effects.js +5747 -0
  4. package/build/hull-effects.js.map +7 -0
  5. package/build/index.js +57 -0
  6. package/build/index.js.map +7 -0
  7. package/build/internal/rendering/hull-effect-metadata.js +136 -0
  8. package/build/internal/rendering/hull-effect-metadata.js.map +7 -0
  9. package/build/{wrap-effects.js → internal/rendering/hull-effect-runtime.js} +131 -64
  10. package/build/internal/rendering/hull-effect-runtime.js.map +7 -0
  11. package/build/internal/rendering/wrap-preview-settings.js +14 -10
  12. package/build/internal/rendering/wrap-preview-settings.js.map +2 -2
  13. package/build/internal/rendering/wrap-preview.js +33 -30
  14. package/build/internal/rendering/wrap-preview.js.map +2 -2
  15. package/build/types/public/hull-effects.d.ts +6 -0
  16. package/build/types/public/hull-effects.js +1 -0
  17. package/build/types/public/index.d.ts +23 -0
  18. package/build/types/public/index.js +1 -0
  19. package/build/types/rendering/hull-effect-metadata.d.ts +12 -0
  20. package/build/types/rendering/hull-effect-metadata.js +1 -0
  21. package/build/types/rendering/hull-effect-runtime.d.ts +39 -0
  22. package/build/types/rendering/hull-effect-runtime.js +1 -0
  23. package/build/types/rendering/wrap-preview-settings.d.ts +6 -7
  24. package/build/types/rendering/wrap-preview.d.ts +8 -6
  25. package/package.json +12 -6
  26. package/src/public/{wrap-effects.js → hull-effects.js} +7 -4
  27. package/src/public/index.js +73 -0
  28. package/src/rendering/hull-effect-metadata.js +27 -0
  29. package/src/rendering/hull-effect-runtime.js +89 -0
  30. package/src/rendering/wrap-preview-settings.js +7 -6
  31. package/src/rendering/wrap-preview.js +35 -32
  32. package/build/types/public/wrap-effects.d.ts +0 -4
  33. package/build/types/public/wrap-effects.js +0 -1
  34. package/build/wrap-effects.js.map +0 -7
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 - 2026-10-21
4
+
5
+ - Register `useLoader(loader, renderer)` once to load any combination of Needle glTF runtime extensions without inspecting an asset beforehand. Extension handlers load dynamically as needed.
6
+ - Opt out of specific extensions with the typed `{ disable: [extensionName] }` option. Optional extensions retain their portable fallback; disabled required extensions report an error.
7
+ - Automatically restore saved hull effects and settings from the versioned `NEEDLE_hull_effect` extension. Hull effects work without an original model and can follow their own skin animation.
8
+ - Use `bindHull(hull, original)` to attach an original model and animation syncing later, or pass `null` to detach it. Existing manual registration functions and `createHullEffect` remain supported.
package/README.md CHANGED
@@ -1,11 +1,43 @@
1
1
  Three.js loaders and TSL materials for GLBs exported by [Needle Mesh Baker](https://mesh-baker.needle.tools).
2
2
 
3
- ## Features
3
+ ## Automatic glTF loading
4
4
 
5
- - **Hull effects:** Render effects using an exported hull and its source model.
6
- - **Octahedral impostors:** Load exported glTF extensions with a Three.js TSL material.
7
- - **Deformation rigs:** Run IK and secondary motion alongside standard animation clips.
8
- - **Pixel and voxel impostors:** Create the display mode selected in the workbench.
5
+ Register once, then load any Mesh Baker glTF without knowing its extensions:
6
+
7
+ ```js
8
+ import { useLoader } from '@needle-tools/three-mesh-effects';
9
+ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
10
+
11
+ const loader = useLoader(new GLTFLoader(), renderer);
12
+ const { scene: model } = await loader.loadAsync('/model.glb');
13
+ scene.add(model);
14
+ ```
15
+
16
+ This handles hull effects, deformation rigs, octahedral impostors, and pixel impostor atlas
17
+ bindings, including assets combining extensions. It also works with `load`,
18
+ `parse`, and `parseAsync`. Each handler is dynamically imported only for assets
19
+ declaring that extension; bundlers can keep those imports in separate chunks.
20
+ Dynamic imports defer downloads, rather than removing handlers that an asset
21
+ might need. The existing individual registration functions remain available.
22
+
23
+ All extensions are enabled by default. To opt out of specific handlers, pass
24
+ their glTF extension names in the optional third argument:
25
+
26
+ ```js
27
+ useLoader(loader, renderer, { disable: ['NEEDLE_mesh_impostor'] });
28
+ ```
29
+
30
+ Supported keys are `NEEDLE_hull_effect`, `NEEDLE_mesh_impostor`, `NEEDLE_pixel_impostor`, and
31
+ `NEEDLE_deformation_rig`. Disabled optional extensions keep their portable
32
+ fallback without importing the handler. A disabled extension listed in the
33
+ asset's `extensionsRequired` rejects the load with an error. Calling `useLoader`
34
+ again replaces the renderer and disable list for subsequent parses; omitting
35
+ options enables everything again.
36
+
37
+ Configure Draco, Meshopt and KTX2 decoders on the loader as usual when needed.
38
+ Rig animation still needs a per-frame update, pixel display modes remain available
39
+ through `createPixelImpostorDisplay`. Hull effects load alone; optionally use
40
+ `bindHull` to add an original model and animation syncing.
9
41
 
10
42
  ## Install
11
43
 
@@ -14,25 +46,85 @@ npm install @needle-tools/three-mesh-effects three
14
46
  ```
15
47
 
16
48
  The package supports Three.js r185 and r186. Its Needle Engine adapter is an
17
- optional import. The examples below use ordinary Three.js and assume an existing
49
+ optional import. The examples use ordinary Three.js and assume an existing
18
50
  `renderer`, `scene`, and `camera`.
19
51
 
52
+ ## Features
53
+
54
+ - **Hull effects:** Restore the saved effect automatically, optionally binding its source model.
55
+ - **Octahedral impostors:** Load exported glTF extensions with a Three.js TSL material.
56
+ - **Deformation rigs:** Run IK and secondary motion alongside standard animation clips.
57
+ - **Pixel and voxel impostors:** Create the display mode selected in the workbench.
58
+
20
59
  ## Hull effects
21
60
 
22
- Hull effects use the exported hull and its original source model. Available
23
- modes and their defaults are in `WRAP_PREVIEW_MODES` and
24
- `createWrapPreviewValues()`:
61
+ When exporting with a hull effect selected, Mesh Baker saves its mode and
62
+ settings in `NEEDLE_hull_effect`. `useLoader` restores it without a second model:
63
+
64
+ ```js
65
+ import { useLoader } from '@needle-tools/three-mesh-effects';
66
+ import { bindHull, getHullEffect } from '@needle-tools/three-mesh-effects/hull-effects';
67
+ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
68
+
69
+ const loader = useLoader(new GLTFLoader(), renderer);
70
+ const { scene: hull } = await loader.loadAsync('/hull.glb');
71
+ scene.add(hull);
72
+ let effect = getHullEffect(hull);
73
+
74
+ // Optional: show the original inside the hull and follow its animation.
75
+ const { scene: original } = await loader.loadAsync('/original.glb');
76
+ effect = bindHull(hull, original, { animate: true });
77
+ // Each frame: advance your AnimationMixers, then effect.syncAnimation().
78
+ // Call effect.dispose() before removing the hull.
79
+ ```
80
+
81
+ `bindHull` replaces the automatically created effect, preserving its settings.
82
+ It borrows the original and leaves the caller's hierarchy and resources intact.
83
+ Get the current effect again after rebinding; old bindings no longer control it.
84
+ `bindHull(hull, null)` detaches the original and restores the standalone effect.
85
+ `getHullEffect(hull)` returns `undefined` for an ordinary or disposed hull.
86
+ Standalone animated hulls can follow their own animation; call `syncAnimation()`
87
+ after updating their mixers or deformation rig. TSL effects require
88
+ `WebGPURenderer` from `three/webgpu`, using either its WebGPU or WebGL2 backend.
89
+
90
+ The existing manual API remains available for models without the extension.
91
+ Here the hull supplies the effect's surface and the original stays visible inside:
92
+ Available modes and their defaults are in `HULL_EFFECT_MODES` and
93
+ `createHullEffectValues()`:
25
94
 
26
95
  ![Hull effect preview](https://needle.click/3f8bbjvfjxbgswy3cvbx.gif)
27
96
 
28
97
  ```js
29
- import { createWrapPreview, createWrapPreviewValues } from '@needle-tools/three-mesh-effects/wrap-effects';
98
+ import { createHullEffect, createHullEffectValues } from '@needle-tools/three-mesh-effects/hull-effects';
99
+ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
30
100
 
31
- const effect = createWrapPreview(hull, original, 'flames', createWrapPreviewValues().flames);
101
+ const loader = new GLTFLoader();
102
+ const [{ scene: hull }, { scene: original }] = await Promise.all([
103
+ loader.loadAsync('/hull.glb'), // Exported by Mesh Baker.
104
+ loader.loadAsync('/original.glb'), // The model uploaded to Mesh Baker.
105
+ ]);
106
+ scene.add(hull);
107
+ const effect = createHullEffect(hull, original, createHullEffectValues().flames);
32
108
  // For animated models, advance both mixers and call effect.syncAnimation() each frame.
33
109
  // Call effect.dispose() at teardown.
34
110
  ```
35
111
 
112
+ ### Hull extension contract
113
+
114
+ `NEEDLE_hull_effect` version 1 is stored on the glTF scene containing the hull:
115
+
116
+ ```json
117
+ { "version": 1, "mode": "flames", "values": { "height": 0.51, "speed": 1 } }
118
+ ```
119
+
120
+ The name appears in `extensionsUsed`. Exported hull geometry and standard
121
+ materials remain a portable fallback, so it is not marked required. `mode` must
122
+ be a supported `HULL_EFFECT_MODES` value; omitted controls use their documented
123
+ defaults, finite numeric values are clamped to their control ranges. Unknown
124
+ versions, unknown modes, and non-finite or non-numeric control values fail
125
+ explicitly. The extension stores no source URL and triggers no source download.
126
+ Each scene with the extension gets its own runtime; dispose each when unloading.
127
+
36
128
  ## Octahedral impostors
37
129
 
38
130
  An 800,000-triangle source represented by a two-triangle impostor:
@@ -45,7 +137,9 @@ Register the extension loader before loading an exported impostor GLB:
45
137
  import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
46
138
  import { registerNeedleImpostorLoader } from '@needle-tools/three-mesh-effects/impostor-runtime';
47
139
 
48
- const loader = registerNeedleImpostorLoader(new GLTFLoader(), { renderer });
140
+ const loader = new GLTFLoader();
141
+ // Register before loading so the extension can replace the portable fallback.
142
+ registerNeedleImpostorLoader(loader, { renderer });
49
143
  const { scene: model } = await loader.loadAsync('/result_impostor.glb');
50
144
  scene.add(model);
51
145
  ```
@@ -60,8 +154,10 @@ import { AnimationMixer, Clock } from 'three';
60
154
  import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
61
155
  import { registerNeedleDeformationRigLoader, getDeformationRig } from '@needle-tools/three-mesh-effects/deformation-runtime';
62
156
 
63
- const rigLoader = registerNeedleDeformationRigLoader(new GLTFLoader());
64
- const { scene: riggedModel, animations } = await rigLoader.loadAsync('/rigged.glb');
157
+ const loader = new GLTFLoader();
158
+ // Register before loading so the rig extension is available while parsing.
159
+ registerNeedleDeformationRigLoader(loader);
160
+ const { scene: riggedModel, animations } = await loader.loadAsync('/rigged.glb');
65
161
  scene.add(riggedModel);
66
162
  const clock = new Clock();
67
163
  const mixer = new AnimationMixer(riggedModel);
@@ -89,8 +185,10 @@ create the display that matches the chosen workbench mode:
89
185
  import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
90
186
  import { registerNeedlePixelImpostorLoader, createPixelImpostorDisplay } from '@needle-tools/three-mesh-effects/pixel-impostor-runtime';
91
187
 
92
- const pixelLoader = registerNeedlePixelImpostorLoader(new GLTFLoader());
93
- const { scene: pixelModel } = await pixelLoader.loadAsync('/pixel.glb');
188
+ const loader = new GLTFLoader();
189
+ // Register before loading so the pixel atlas is available while parsing.
190
+ registerNeedlePixelImpostorLoader(loader);
191
+ const { scene: pixelModel } = await loader.loadAsync('/pixel.glb');
94
192
  scene.add(pixelModel);
95
193
  const display = createPixelImpostorDisplay(pixelModel, { renderer, mode: 'screen-pixels', pixelSize: 5 });
96
194
  // Call display.updateViewport() after a resize and display.dispose() at teardown.