@needle-tools/three-mesh-effects 0.2.3 → 0.3.2

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 (113) hide show
  1. package/CHANGELOG.md +34 -8
  2. package/README.md +86 -3
  3. package/SKILL.md +14 -4
  4. package/build/box-impostor-runtime.js +1423 -0
  5. package/build/box-impostor-runtime.js.map +7 -0
  6. package/build/deformation-runtime.js +30 -19
  7. package/build/deformation-runtime.js.map +3 -3
  8. package/build/hull-effects.js +60 -28
  9. package/build/hull-effects.js.map +3 -3
  10. package/build/impostor-runtime.js +264 -133
  11. package/build/impostor-runtime.js.map +4 -4
  12. package/build/index.js +8 -0
  13. package/build/index.js.map +2 -2
  14. package/build/internal/box-impostor/box-impostor-display-settings.js +50 -0
  15. package/build/internal/box-impostor/box-impostor-display-settings.js.map +7 -0
  16. package/build/internal/box-impostor/box-impostor-display.js +1102 -0
  17. package/build/internal/box-impostor/box-impostor-display.js.map +7 -0
  18. package/build/internal/box-impostor/box-impostor-face-axes.js +15 -0
  19. package/build/internal/box-impostor/box-impostor-face-axes.js.map +7 -0
  20. package/build/internal/box-impostor/box-impostor-faces.js +125 -0
  21. package/build/internal/box-impostor/box-impostor-faces.js.map +7 -0
  22. package/build/internal/box-impostor/box-impostor-geometry.js +230 -0
  23. package/build/internal/box-impostor/box-impostor-geometry.js.map +7 -0
  24. package/build/internal/box-impostor/box-impostor-material.js +1056 -0
  25. package/build/internal/box-impostor/box-impostor-material.js.map +7 -0
  26. package/build/internal/box-impostor/box-impostor-metadata.js +108 -0
  27. package/build/internal/box-impostor/box-impostor-metadata.js.map +7 -0
  28. package/build/internal/box-impostor/box-impostor-projection.js +276 -0
  29. package/build/internal/box-impostor/box-impostor-projection.js.map +7 -0
  30. package/build/internal/box-impostor/box-impostor-runtime.js +1369 -0
  31. package/build/internal/box-impostor/box-impostor-runtime.js.map +7 -0
  32. package/build/internal/box-impostor/box-impostor-surface-search.js +21 -0
  33. package/build/internal/box-impostor/box-impostor-surface-search.js.map +7 -0
  34. package/build/internal/deformation/cloth-surface.js +23 -17
  35. package/build/internal/deformation/cloth-surface.js.map +3 -3
  36. package/build/internal/deformation/pin-cloth.js +7 -2
  37. package/build/internal/deformation/pin-cloth.js.map +2 -2
  38. package/build/internal/deformation/rig-runtime.js +30 -19
  39. package/build/internal/deformation/rig-runtime.js.map +3 -3
  40. package/build/internal/impostor/impostor-node-material.js +264 -133
  41. package/build/internal/impostor/impostor-node-material.js.map +4 -4
  42. package/build/internal/pixel-impostor/pixel-impostor-display.js +84 -38
  43. package/build/internal/pixel-impostor/pixel-impostor-display.js.map +4 -4
  44. package/build/internal/rendering/captured-surface-depth.js +35 -0
  45. package/build/internal/rendering/captured-surface-depth.js.map +7 -0
  46. package/build/internal/rendering/captured-surface-material.js +28 -0
  47. package/build/internal/rendering/captured-surface-material.js.map +7 -0
  48. package/build/internal/rendering/hull-effect-runtime.js +59 -27
  49. package/build/internal/rendering/hull-effect-runtime.js.map +3 -3
  50. package/build/internal/rendering/renderer-support.js +31 -0
  51. package/build/internal/rendering/renderer-support.js.map +7 -0
  52. package/build/internal/rendering/wireframe.js +41 -9
  53. package/build/internal/rendering/wireframe.js.map +2 -2
  54. package/build/internal/rendering/wrap-preview.js +59 -27
  55. package/build/internal/rendering/wrap-preview.js.map +3 -3
  56. package/build/pixel-impostor-runtime.js +84 -38
  57. package/build/pixel-impostor-runtime.js.map +4 -4
  58. package/build/types/box-impostor/box-impostor-display-settings.d.ts +30 -0
  59. package/build/types/box-impostor/box-impostor-display-settings.js +1 -0
  60. package/build/types/box-impostor/box-impostor-display.d.ts +13 -0
  61. package/build/types/box-impostor/box-impostor-display.js +1 -0
  62. package/build/types/box-impostor/box-impostor-face-axes.d.ts +5 -0
  63. package/build/types/box-impostor/box-impostor-face-axes.js +1 -0
  64. package/build/types/box-impostor/box-impostor-faces.d.ts +11 -0
  65. package/build/types/box-impostor/box-impostor-faces.js +1 -0
  66. package/build/types/box-impostor/box-impostor-geometry.d.ts +5 -0
  67. package/build/types/box-impostor/box-impostor-geometry.js +1 -0
  68. package/build/types/box-impostor/box-impostor-material.d.ts +14 -0
  69. package/build/types/box-impostor/box-impostor-material.js +1 -0
  70. package/build/types/box-impostor/box-impostor-metadata.d.ts +31 -0
  71. package/build/types/box-impostor/box-impostor-metadata.js +1 -0
  72. package/build/types/box-impostor/box-impostor-projection.d.ts +19 -0
  73. package/build/types/box-impostor/box-impostor-projection.js +1 -0
  74. package/build/types/box-impostor/box-impostor-runtime.d.ts +19 -0
  75. package/build/types/box-impostor/box-impostor-runtime.js +1 -0
  76. package/build/types/box-impostor/box-impostor-surface-search.d.ts +13 -0
  77. package/build/types/box-impostor/box-impostor-surface-search.js +1 -0
  78. package/build/types/deformation/cloth-surface.d.ts +1 -0
  79. package/build/types/deformation/pin-cloth.d.ts +1 -0
  80. package/build/types/impostor/impostor-node-material.d.ts +2 -15
  81. package/build/types/public/box-impostor-runtime.d.ts +6 -0
  82. package/build/types/public/box-impostor-runtime.js +1 -0
  83. package/build/types/public/hull-effects.d.ts +1 -0
  84. package/build/types/public/index.d.ts +1 -1
  85. package/build/types/rendering/captured-surface-depth.d.ts +5 -0
  86. package/build/types/rendering/captured-surface-depth.js +1 -0
  87. package/build/types/rendering/captured-surface-material.d.ts +8 -0
  88. package/build/types/rendering/captured-surface-material.js +1 -0
  89. package/build/types/rendering/renderer-support.d.ts +27 -0
  90. package/build/types/rendering/renderer-support.js +1 -0
  91. package/build/types/rendering/wireframe.d.ts +2 -2
  92. package/package.json +29 -8
  93. package/src/box-impostor/box-impostor-display-settings.js +54 -0
  94. package/src/box-impostor/box-impostor-display.js +50 -0
  95. package/src/box-impostor/box-impostor-face-axes.js +11 -0
  96. package/src/box-impostor/box-impostor-faces.js +118 -0
  97. package/src/box-impostor/box-impostor-geometry.js +140 -0
  98. package/src/box-impostor/box-impostor-material.js +771 -0
  99. package/src/box-impostor/box-impostor-metadata.js +122 -0
  100. package/src/box-impostor/box-impostor-projection.js +276 -0
  101. package/src/box-impostor/box-impostor-runtime.js +124 -0
  102. package/src/box-impostor/box-impostor-surface-search.js +11 -0
  103. package/src/deformation/cloth-surface.ts +28 -17
  104. package/src/deformation/pin-cloth.ts +9 -3
  105. package/src/impostor/impostor-node-material.js +188 -157
  106. package/src/pixel-impostor/pixel-impostor-display.js +5 -13
  107. package/src/public/box-impostor-runtime.js +14 -0
  108. package/src/public/hull-effects.js +1 -0
  109. package/src/public/index.js +10 -1
  110. package/src/rendering/captured-surface-depth.js +55 -0
  111. package/src/rendering/captured-surface-material.js +27 -0
  112. package/src/rendering/renderer-support.js +50 -0
  113. package/src/rendering/wireframe.js +51 -13
package/CHANGELOG.md CHANGED
@@ -1,21 +1,47 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.2 - 2026-11-13
4
+
5
+ - Support Three.js r186 and load box and card impostors automatically with WebGLRenderer.
6
+ - Smooth box-impostor shading and view transitions, including capture edges.
7
+ - Correct point and spot lighting on reconstructed impostor surfaces.
8
+ - Keep traced boxes and fitted cards visible when the camera enters their bounds.
9
+ - Preserve scene intersections with standard, reversed and logarithmic depth buffers.
10
+ - Avoid repeated shader compilation when rendering box and card impostors on WebGL.
11
+
12
+ ## 0.3.1 - 2026-11-11
13
+
14
+ - Show card and box carrier outlines without triangulation diagonals, including card overlays on WebGPU.
15
+ - Add High Contrast with black lines and a thin gray outline, plus Cyan, Lime and Magenta preview wireframe colors.
16
+
17
+ - 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.
18
+
19
+ - Preserve steep surfaces between sparse octahedral captures, with bounded candidate validation that rejects false depth shells. This improves coverage at an increased GPU cost.
20
+
21
+ ## 0.3.0 - 2026-11-06
22
+
23
+ - Keep nearer surfaces visible when another card or box capture sees a farther layer.
24
+ - Add experimental basic cards, fitted cards and fitted-box impostors with automatic glTF loading and shared PBR atlases.
25
+ - Recover more silhouette detail in card and box impostors, with smoother edge lighting and voxel-based empty-space rejection.
26
+ - Reduce GPU rendering cost for depth-reconstructed card and box impostors without lowering image quality.
27
+ - Improve cloth stability and contact handling with overlapping colliders.
28
+
3
29
  ## 0.2.3 - 2026-10-30
4
30
 
5
- - Keep impostor shading and fur textures connected when progressive loading replaces a texture. Fur height preserves its UV channel and texture transforms; fur motion limits follow the loaded resolution.
6
- - Sample resized impostor color and shading atlases using their loaded dimensions, with frame boundaries and safe mip levels respected. Packed geometry/depth and sparse pixel records still require their authored resolution.
31
+ - Preserve impostor shading and fur detail as higher-quality textures arrive through progressive loading.
32
+ - Keep impostor views aligned and sharp when color and shading textures load at different resolutions.
7
33
 
8
34
  ## 0.2.2 - 2026-10-21
9
35
 
10
- - Include a package-root `SKILL.md` with integration guidance for extension loading, compression decoders, runtime updates, and cleanup in Three.js and Needle Engine applications.
36
+ - Help coding agents integrate Mesh Effects with bundled guidance for Three.js and Needle Engine, covering loading, animation and cleanup.
11
37
 
12
38
  ## 0.2.1 - 2026-10-21
13
39
 
14
- - Put installation and features before the Quick start, and clarify that consumers configure compression decoders themselves when needed.
40
+ - Get started more easily with a reorganized Quick start and guidance for compressed model loading.
15
41
 
16
42
  ## 0.2.0 - 2026-10-21
17
43
 
18
- - 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.
19
- - Opt out of specific extensions with the typed `{ disable: [extensionName] }` option. Optional extensions retain their portable fallback; disabled required extensions report an error.
20
- - 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.
21
- - 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.
44
+ - Register `useLoader(loader, renderer)` once to load any combination of supported Needle glTF extensions automatically.
45
+ - Choose which effects to enable with the typed `disable` option. Optional effects retain their portable fallback; required effects report when they cannot load.
46
+ - Restore exported hull effects with their saved appearance and settings, including animated models.
47
+ - Attach or detach an original model with `bindHull` for display and animation syncing, or use a hull effect on its own.
package/README.md CHANGED
@@ -13,6 +13,7 @@ optional import. The examples use ordinary Three.js and assume an existing
13
13
  ## Features
14
14
 
15
15
  - **Hull effects:** Restore the saved effect automatically, optionally binding its source model.
16
+ - **Card and box impostors (experimental):** Project or reconstruct six captures per part using shared PBR atlases.
16
17
  - **Octahedral impostors:** Load exported glTF extensions with a Three.js TSL material.
17
18
  - **Deformation rigs:** Run IK and secondary motion alongside standard animation clips.
18
19
  - **Pixel and voxel impostors:** Create the display mode selected in the workbench.
@@ -30,13 +31,19 @@ const { scene: model } = await loader.loadAsync('/model.glb');
30
31
  scene.add(model);
31
32
  ```
32
33
 
33
- This handles hull effects, deformation rigs, octahedral impostors, and pixel impostor atlas
34
+ This handles hull effects, deformation rigs, box and card impostors, octahedral impostors, and pixel impostor atlas
34
35
  bindings, including assets combining extensions. It also works with `load`,
35
36
  `parse`, and `parseAsync`. Each handler is dynamically imported only for assets
36
37
  declaring that extension; bundlers can keep those imports in separate chunks.
37
38
  Dynamic imports defer downloads, rather than removing handlers that an asset
38
39
  might need. The existing individual registration functions remain available.
39
40
 
41
+ On `WebGLRenderer`, loading an enabled Mesh Effects extension installs Three's
42
+ `WebGLNodesHandler` once per renderer, so the same TSL materials render on WebGL.
43
+ Ordinary glTF files and disabled extensions leave the renderer untouched. Hosts
44
+ with their own compatible handler can advertise
45
+ `renderer.capabilities.supportsNodeMaterials = true` to retain it.
46
+
40
47
  All extensions are enabled by default. To opt out of specific handlers, pass
41
48
  their glTF extension names in the optional third argument:
42
49
 
@@ -44,7 +51,7 @@ their glTF extension names in the optional third argument:
44
51
  useLoader(loader, renderer, { disable: ['NEEDLE_mesh_impostor'] });
45
52
  ```
46
53
 
47
- Supported keys are `NEEDLE_hull_effect`, `NEEDLE_mesh_impostor`, `NEEDLE_pixel_impostor`, and
54
+ Supported keys are `NEEDLE_box_impostor`, `NEEDLE_hull_effect`, `NEEDLE_mesh_impostor`, `NEEDLE_pixel_impostor`, and
48
55
  `NEEDLE_deformation_rig`. Disabled optional extensions keep their portable
49
56
  fallback without importing the handler. A disabled extension listed in the
50
57
  asset's `extensionsRequired` rejects the load with an error. Calling `useLoader`
@@ -66,6 +73,81 @@ across neighboring views. Compact shading alpha stores material data and needs
66
73
  independent channel filtering and lossless PNG encoding. Packed depth/geometry
67
74
  and sparse pixel-impostor records must retain their authored resolution.
68
75
 
76
+ ## Card and fitted-box impostors (experimental)
77
+
78
+ `NEEDLE_box_impostor` stores six orthographic PBR/depth views for each oriented
79
+ part, packed into four shared atlases. Basic mode draws one camera-facing card;
80
+ `cards` draws one per fitted region, and `fitted` draws twelve-triangle box proxies. Motion/opacity batches share atlas textures;
81
+ transparent boxes use separate draws for depth sorting. The runtime supports direct
82
+ plane projection, source-material transparency and standard rigid node
83
+ animation. Auto depth uses projection for flat captures and traces other captures.
84
+ Every display setting retains the same compact geometry: two triangles per card
85
+ or twelve per fitted box. Explicit projection trades curved silhouette/parallax
86
+ accuracy for lower shader cost. Fitted boxes with projection and no view blending
87
+ use ordinary fitted faces with no fragment depth search. Projected cards select
88
+ the nearest supported plane before blending. Captured depth bounds shorten traced
89
+ searches, and padded depth needs one texture read per step. Tracing checks the
90
+ supported captures in facing order and retains the nearest validated surface,
91
+ including surfaces hidden from the most directly facing capture.
92
+ Conservative voxel masks reject empty rays without reducing texture resolution.
93
+ Filtered normals preserve edge lighting. Geometric occupancy
94
+ in the material atlas rejects empty hits. Sampling rejects depth discontinuities
95
+ that would otherwise form extruded walls. Captures preserve surface opacity
96
+ independently of the display cutoff. `useLoader(loader, renderer)` enables it automatically.
97
+
98
+ Use `WebGLRenderer` or `WebGPURenderer` from `three/webgpu`. `useLoader` and the
99
+ manual box registration enable Three's WebGL TSL handler when needed. Renderers
100
+ without node-material support retain the portable fallback for optional box
101
+ extensions and reject required ones. Captures remain fixed in their animated node frame.
102
+ A nearest-surface depth field cannot represent all hidden layers; split complex
103
+ parts into more boxes when gaps or occluded surfaces disappear.
104
+
105
+ Depth-writing variants use the reconstructed surface for depth, point/spot lighting
106
+ and received shadows. Enable Three's shadow map and the usual light/mesh
107
+ `castShadow` and mesh `receiveShadow` flags. Raster reflection probes use
108
+ `CubeRenderTarget` with `WebGPURenderer`; geometry raycasts still see the compact
109
+ carrier. Alpha-blended variants retain sorting and do not write depth.
110
+
111
+ For manual integration, `@needle-tools/three-mesh-effects/box-impostor-runtime`
112
+ exports `registerNeedleBoxImpostorLoader(loader, { renderer })`,
113
+ `createBoxImpostorGeometry(descriptor)`, `createBoxImpostorMaterial(descriptor, maps)`
114
+ `parseBoxImpostorDescriptor`, and `setBoxImpostorDisplay(root, options)`. `maps` binds `baseColor`, `normalDepth`, `orm`
115
+ and `emissive` explicitly. The material owns its small rectangle lookup texture;
116
+ dispose the material and geometry on unload, and dispose shared atlas textures
117
+ once their last consumer is gone. No per-frame update is needed.
118
+
119
+ Change display settings after loading without rebuilding the geometry or atlases:
120
+
121
+ ```js
122
+ import { setBoxImpostorDisplay } from '@needle-tools/three-mesh-effects/box-impostor-runtime';
123
+ setBoxImpostorDisplay(gltf.scene, {
124
+ depthMode: 'auto', // auto, projection, depth
125
+ raySteps: 16,
126
+ interpolation: 'smooth', // none, linear, smooth
127
+ transparency: 'auto', // auto, cutout, dithered, blended
128
+ alphaCutoff: 0.5,
129
+ });
130
+ ```
131
+
132
+ Interpolation blends occupied captured planes, or depth-consistent samples on traced surfaces. Auto transparency follows each primitive’s source alpha mode. Blended
133
+ opacity uses sorted draws without depth writes. Dithered opacity uses
134
+ alpha hashing; captures do not represent layered glass or refraction. Cutout
135
+ uses the live alpha cutoff.
136
+ Depth quality, interpolation and transparency select cached compiled materials;
137
+ disposing the current material releases its cached variants without disposing
138
+ shared atlases. Dispose geometry separately; a renderer may refresh its buffers
139
+ without unloading the material.
140
+ `DEFAULT_BOX_IMPOSTOR_DISPLAY` and `normalizeBoxImpostorDisplay` expose the same
141
+ defaults and validation used by loading and live updates.
142
+
143
+ Explicit depth reconstruction compiles Low, Medium or High adaptive sampling
144
+ (`raySteps: 8`, `16` or `32`). These set minimum interval budgets and respectively
145
+ 1, 2 or 4 samples per projected capture texel along the dominant texture axis;
146
+ they are not maximum counts. Oblique rays can require hundreds of samples.
147
+ Projection omits depth search entirely. Keep depth bytes lossless, atlas
148
+ resolution unchanged and mipmaps disabled: filtering packed 16-bit depth or
149
+ across neighboring views corrupts reconstruction.
150
+
69
151
  ## Hull effects
70
152
 
71
153
  When exporting with a hull effect selected, Mesh Baker saves its mode and
@@ -95,7 +177,8 @@ Get the current effect again after rebinding; old bindings no longer control it.
95
177
  `getHullEffect(hull)` returns `undefined` for an ordinary or disposed hull.
96
178
  Standalone animated hulls can follow their own animation; call `syncAnimation()`
97
179
  after updating their mixers or deformation rig. TSL effects require
98
- `WebGPURenderer` from `three/webgpu`, using either its WebGPU or WebGL2 backend.
180
+ `WebGPURenderer` from `three/webgpu` or `WebGLRenderer` with Three's
181
+ `WebGLNodesHandler`, which `useLoader` enables when loading an effect.
99
182
 
100
183
  The existing manual API remains available for models without the extension.
101
184
  Here the hull supplies the effect's surface and the original stays visible inside:
package/SKILL.md CHANGED
@@ -1,6 +1,6 @@
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 pixel impostor displays.
3
+ description: Integrate Mesh Baker glTF models into Three.js or Needle Engine applications, including extension loading, hull effects, deformation rigs, and impostor displays.
4
4
  ---
5
5
 
6
6
  # Three Mesh Effects
@@ -43,13 +43,23 @@ independent animation loop.
43
43
  - Pixel impostors: extension loading restores atlas bindings. Custom display
44
44
  modes still use `createPixelImpostorDisplay` from `/pixel-impostor-runtime`;
45
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.
46
54
  - Octahedral impostors: pass the actual renderer to `useLoader` so the handler
47
55
  can choose the supported material implementation.
48
56
 
49
57
  Hull and other TSL effects require a renderer supporting node materials. Ordinary
50
- Three.js applications use WebGPURenderer from `three/webgpu`, with its WebGPU or
51
- WebGL2 backend. Some hosts provide their own TSL integration; inspect it before
52
- changing their renderer or disabling existing rendering features.
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.
53
63
 
54
64
  When a scene is cleared while asynchronous initialization is pending, dispose
55
65
  any runtimes that finish afterward. Track scenes separately per viewer/context,