@needle-tools/three-mesh-effects 0.3.5 → 0.3.7
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/CHANGELOG.md +33 -28
- package/README.md +63 -231
- package/SKILL.md +11 -68
- package/build/box-impostor-runtime.js +652 -257
- package/build/box-impostor-runtime.js.map +4 -4
- package/build/deformation-runtime.js +1 -1
- package/build/deformation-runtime.js.map +1 -1
- package/build/hull-effects.js.map +1 -1
- package/build/impostor-runtime.js +2 -2
- package/build/impostor-runtime.js.map +2 -2
- package/build/index.js +2 -2
- package/build/index.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-display.js +662 -265
- package/build/internal/box-impostor/box-impostor-display.js.map +4 -4
- package/build/internal/box-impostor/box-impostor-material.js +662 -265
- package/build/internal/box-impostor/box-impostor-material.js.map +4 -4
- package/build/internal/box-impostor/box-impostor-ray-bounds.js +369 -0
- package/build/internal/box-impostor/box-impostor-ray-bounds.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-runtime.js +652 -257
- package/build/internal/box-impostor/box-impostor-runtime.js.map +4 -4
- package/build/internal/deformation/rig-runtime.js +1 -1
- package/build/internal/deformation/rig-runtime.js.map +1 -1
- package/build/internal/impostor/impostor-node-material.js +2 -2
- package/build/internal/impostor/impostor-node-material.js.map +2 -2
- package/build/internal/impostor/octahedral.js.map +1 -1
- package/build/internal/pixel-impostor/pixel-impostor-display.js +39 -16
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +2 -2
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js +61 -6
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js.map +2 -2
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js +980 -26
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js.map +4 -4
- package/build/internal/rendering/hull-effect-runtime.js.map +1 -1
- package/build/internal/rendering/renderer-support.js.map +1 -1
- package/build/internal/rendering/skin-projection.js.map +1 -1
- package/build/internal/rendering/surface-query.js.map +1 -1
- package/build/internal/rendering/wrap-preview.js.map +1 -1
- package/build/internal/rendering/wrap-skin.js.map +1 -1
- package/build/pixel-impostor-runtime.js +362 -172
- package/build/pixel-impostor-runtime.js.map +4 -4
- package/build/types/box-impostor/box-impostor-material.d.ts +2 -1
- package/build/types/box-impostor/box-impostor-ray-bounds.d.ts +6 -0
- package/build/types/box-impostor/box-impostor-ray-bounds.js +1 -0
- package/build/types/deformation/rig-runtime.d.ts +1 -1
- package/build/types/impostor/octahedral.d.ts +1 -1
- package/build/types/pixel-impostor/pixel-impostor-display.d.ts +3 -3
- package/build/types/pixel-impostor/pixel-impostor-metadata.d.ts +76 -5
- package/build/types/pixel-impostor/pixel-impostor-runtime.d.ts +19 -7
- package/build/types/public/pixel-impostor-runtime.d.ts +1 -1
- package/build/types/rendering/renderer-support.d.ts +1 -1
- package/build/types/rendering/surface-query.d.ts +2 -2
- package/package.json +2 -2
- package/src/box-impostor/box-impostor-material.js +128 -90
- package/src/box-impostor/box-impostor-ray-bounds.js +452 -0
- package/src/deformation/rig-runtime.ts +1 -1
- package/src/impostor/impostor-node-material.js +2 -2
- package/src/impostor/octahedral.js +1 -1
- package/src/pixel-impostor/pixel-impostor-display.js +32 -18
- package/src/pixel-impostor/pixel-impostor-metadata.js +69 -9
- package/src/pixel-impostor/pixel-impostor-runtime.js +32 -9
- package/src/public/index.js +2 -2
- package/src/public/pixel-impostor-runtime.js +1 -1
- package/src/rendering/renderer-support.js +1 -1
- package/src/rendering/surface-query.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,60 +1,65 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.7 - 2026-11-27
|
|
4
|
+
|
|
5
|
+
- Improve box impostor rendering performance.
|
|
6
|
+
|
|
7
|
+
## 0.3.6 - 2026-11-25
|
|
8
|
+
|
|
9
|
+
- Restore saved pixel and voxel impostor display settings when loading with `useLoader` or passing a renderer to `registerNeedlePixelImpostorLoader`.
|
|
10
|
+
- Load smaller pixel impostor files that use a bounding box in place of the voxel mesh for raycast and screen-pixel displays.
|
|
11
|
+
|
|
3
12
|
## 0.3.5 - 2026-11-22
|
|
4
13
|
|
|
5
|
-
-
|
|
14
|
+
- Render edge reflections and HDR emission in box and card impostors.
|
|
6
15
|
|
|
7
16
|
## 0.3.4 - 2026-11-22
|
|
8
17
|
|
|
9
|
-
-
|
|
10
|
-
-
|
|
18
|
+
- Support Three.js r187 with `WebGLRenderer` and r185 or later with `WebGPURenderer`.
|
|
19
|
+
- Cast real-time shadows from octahedral impostors on WebGPU.
|
|
11
20
|
|
|
12
21
|
## 0.3.3 - 2026-11-16
|
|
13
22
|
|
|
14
|
-
- Reduce
|
|
23
|
+
- Reduce shader compilation stalls when octahedral impostors first appear.
|
|
15
24
|
|
|
16
25
|
## 0.3.2 - 2026-11-13
|
|
17
26
|
|
|
18
|
-
- Support Three.js r186 and load box and card impostors automatically with WebGLRenderer
|
|
19
|
-
- Smooth
|
|
20
|
-
-
|
|
27
|
+
- Support Three.js r186 and load box and card impostors automatically with `WebGLRenderer`.
|
|
28
|
+
- Smooth shading and view transitions on box impostors.
|
|
29
|
+
- Fix point and spot lighting on reconstructed impostor surfaces.
|
|
21
30
|
- Keep traced boxes and fitted cards visible when the camera enters their bounds.
|
|
22
|
-
- Preserve scene intersections with standard, reversed and logarithmic depth buffers.
|
|
23
|
-
- Avoid repeated shader compilation
|
|
31
|
+
- Preserve scene intersections with standard, reversed, and logarithmic depth buffers.
|
|
32
|
+
- Avoid repeated shader compilation for box and card impostors on WebGL.
|
|
24
33
|
|
|
25
34
|
## 0.3.1 - 2026-11-11
|
|
26
35
|
|
|
27
|
-
-
|
|
28
|
-
- Add
|
|
29
|
-
|
|
30
|
-
- 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.
|
|
31
|
-
|
|
32
|
-
- Preserve steep surfaces between sparse octahedral captures, with bounded candidate validation that rejects false depth shells. This improves coverage at an increased GPU cost.
|
|
36
|
+
- Draw card and box carrier outlines without triangulation diagonals.
|
|
37
|
+
- Add high-contrast, cyan, lime, and magenta wireframes.
|
|
38
|
+
- Preserve narrow surfaces at oblique angles in box impostors and steep surfaces between octahedral captures.
|
|
33
39
|
|
|
34
40
|
## 0.3.0 - 2026-11-06
|
|
35
41
|
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
- Improve cloth stability and contact handling with overlapping colliders.
|
|
42
|
+
- Load experimental basic card, fitted card, and fitted box impostors with shared PBR atlases.
|
|
43
|
+
- Preserve near surfaces where captures overlap and improve silhouette detail and edge lighting.
|
|
44
|
+
- Reduce GPU rendering cost for depth-reconstructed card and box impostors.
|
|
45
|
+
- Improve cloth stability around overlapping colliders.
|
|
41
46
|
|
|
42
47
|
## 0.2.3 - 2026-10-30
|
|
43
48
|
|
|
44
|
-
- Preserve impostor shading and fur detail as higher-
|
|
45
|
-
- Keep impostor views aligned
|
|
49
|
+
- Preserve impostor shading and fur detail as higher-resolution textures load.
|
|
50
|
+
- Keep impostor views aligned when color and shading textures load at different resolutions.
|
|
46
51
|
|
|
47
52
|
## 0.2.2 - 2026-10-21
|
|
48
53
|
|
|
49
|
-
-
|
|
54
|
+
- Bundle integration guidance for loading, animation, and cleanup in Three.js and Needle Engine.
|
|
50
55
|
|
|
51
56
|
## 0.2.1 - 2026-10-21
|
|
52
57
|
|
|
53
|
-
-
|
|
58
|
+
- Document how to configure loaders for compressed glTF models.
|
|
54
59
|
|
|
55
60
|
## 0.2.0 - 2026-10-21
|
|
56
61
|
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
- Restore
|
|
60
|
-
- Attach or detach
|
|
62
|
+
- Load supported Needle glTF extensions with one call to `useLoader(loader, renderer)`.
|
|
63
|
+
- Opt out of individual extensions with `disable`. Optional extensions use the asset's fallback and required extensions fail to load.
|
|
64
|
+
- Restore saved hull effects on static and animated models.
|
|
65
|
+
- Attach or detach the original model at runtime with `bindHull`.
|
package/README.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
Three
|
|
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
|
-
|
|
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
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
- **
|
|
19
|
-
- **
|
|
20
|
-
- **
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
49
|
-
their glTF extension names in the optional third argument:
|
|
40
|
+
## Card and box impostors
|
|
50
41
|
|
|
51
|
-
|
|
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
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+

|
|
183
67
|
|
|
184
|
-
|
|
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
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
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
|
-
`
|
|
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
|
-
|
|
211
|
-
{ "version": 1, "mode": "flames", "values": { "height": 0.51, "speed": 1 } }
|
|
212
|
-
```
|
|
83
|
+
## Hull effects
|
|
213
84
|
|
|
214
|
-
|
|
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
|
-
|
|
87
|
+
```js
|
|
88
|
+
import { bindHull, getHullEffect } from '@needle-tools/three-mesh-effects/hull-effects';
|
|
223
89
|
|
|
224
|
-
|
|
90
|
+
const { scene: hull } = await loader.loadAsync('/hull.glb');
|
|
91
|
+
scene.add(hull);
|
|
92
|
+
let effect = getHullEffect(hull);
|
|
225
93
|
|
|
226
|
-
|
|
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
|
-
|
|
98
|
+
// For animation, call effect.syncAnimation() after updating mixers and rigs.
|
|
99
|
+
// At teardown, call effect.dispose().
|
|
100
|
+
```
|
|
229
101
|
|
|
230
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const
|
|
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(
|
|
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
|
-
|
|
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
|
-
##
|
|
132
|
+
## Needle Engine
|
|
301
133
|
|
|
302
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
##
|
|
10
|
+
## Loading
|
|
13
11
|
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|