@needle-tools/gltf-build-pipeline 3.0.1 → 4.0.0-44b66a4

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 CHANGED
@@ -4,6 +4,39 @@ All notable changes to this package will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [Unreleased]
8
+
9
+ ### Fixed
10
+ - SOG files built from Y-up sources (`.spz`, `.splat`, `.ksplat`) are no longer upside down.
11
+
12
+ ## [4.0.0] - 2026-08-13
13
+
14
+ Gaussian splat compression.
15
+
16
+ ### Added
17
+ - **Splat compression.** The pipeline compresses splat files that a glTF refers to (`.ply`, `.spz`, `.splat`, `.ksplat`, `.sog`, `.lcc`, `.lcc2`) and updates the reference. To run it alone, use `needle-gltf splat <input> [output]`.
18
+ - **RAD output.** Set `config.splat.format` to `'sog'` or `'rad'`. SOG is smaller. RAD contains a LOD tree, so the renderer can stream it. RAD files are about 50% larger than SOG files. The CLI option is `--format`.
19
+ - **Automatic format selection**, which is now the default. `format: 'auto'` selects RAD for scenes with `config.splat.radThreshold` splats or more (default 500,000), and SOG for smaller scenes. The CLI option is `--rad-threshold`.
20
+ - **`build-lod` binaries for Windows and macOS.** RAD output now works without a Rust toolchain. Linux binaries are not included yet.
21
+ - **`--manifest <path>`** writes a JSON file that lists each source file the run replaced. Build tools read it to delete the old files from their own output directory.
22
+ - **`config.splat.flipToYUp`** writes SOG files in Y-up. RAD files are always Y-up.
23
+
24
+ ### Changed
25
+ - The cache now deletes the least recently used files first.
26
+ - The `splat` CLI command now uses the cache.
27
+ - The pipeline deletes a replaced source file only from the output directory, and only after it writes the glTF.
28
+
29
+ ### Fixed
30
+ - Remote `.exr` references in opaque extensions (e.g. a `RemoteSkybox` https URL) are no longer joined onto the input directory and reported as `External EXR not found`. Only relative paths are resolved and injected for PMREM; absolute and remote URLs are left untouched.
31
+ - Authentication no longer fails when the local license server answers slowly.
32
+ - Splat compression now works when `npx` downloads the tool on Windows.
33
+ - The splat CLI accepts an output file path. The output argument is optional.
34
+ - The pipeline deletes partial output before it starts the CPU fallback.
35
+ - PMREM preread hook registration.
36
+
37
+ ### Notes
38
+ - The binaries add about 3.5 MB to the package.
39
+
7
40
  ## [3.0.0] - 2026-06-23
8
41
 
9
42
  First stable 3.0 release. Summary of the headline changes across the 3.0 alpha/beta cycle.
package/README.md CHANGED
@@ -24,19 +24,26 @@ To load progressively enhanced glTF files in Needle Engine or another three.js b
24
24
  `npx @needle-tools/gltf-build-pipeline@latest`
25
25
 
26
26
  ### Commands
27
+ - `transform <input> [output]` - optimize glTF, GLB and VRM files
28
+ - `splat <input> [output]` - compress Gaussian splat files
29
+ - `pmrem <input>` - convert EXR and Radiance HDR files to KTX2
30
+ - `stats <input> <output>` - write file statistics
31
+ - `clear-caches` - delete all caches
27
32
  - `help` - use help to view options
28
33
 
29
34
  ### Platform support
30
35
 
31
- The bundled `basisu` encoder (used for HDR / EXR → KTX2 HDR) supports:
36
+ Two bundled encoders: `basisu` for HDR / EXR → KTX2 HDR, and `build-lod` for RAD splats.
32
37
 
33
- | OS | Arch | Status |
34
- |---------|-----------------------|--------|
35
- | Linux | x64 | Supported |
36
- | Linux | arm64 | Not supported |
37
- | macOS | arm64 (Apple Silicon) | Supported |
38
- | macOS | x64 (Intel) | Not supported |
39
- | Windows | x64 | Supported |
38
+ | OS | Arch | basisu | build-lod |
39
+ |---------|-----------------------|--------|-----------|
40
+ | Linux | x64 | Supported | Not bundled |
41
+ | Linux | arm64 | Not supported | Not bundled |
42
+ | macOS | arm64 (Apple Silicon) | Supported | Supported |
43
+ | macOS | x64 (Intel) | Not supported | Not supported |
44
+ | Windows | x64 | Supported | Supported |
45
+
46
+ Where `build-lod` is not bundled, splats are written as SOG instead of RAD.
40
47
 
41
48
  ### Configuration
42
49
 
@@ -47,23 +54,157 @@ The pipeline reads an optional `needle.config.json` from the working directory (
47
54
  "gltf": {
48
55
  "usecase": "product",
49
56
  "textures": { "lods": true },
50
- "meshes": { "lods": true },
57
+ "meshes": { "lods": true, "merge": false },
51
58
  "audio": { "enabled": true, "bitrate": 64 },
52
- "exr": { "enabled": true }
59
+ "exr": { "enabled": true },
60
+ "splat": { "enabled": true, "format": "auto" }
53
61
  }
54
62
  }
55
63
  ```
56
64
 
57
65
  The `gltf` value may also be a string shorthand for `usecase` — `"gltf": "product"` is equivalent to `"gltf": { "usecase": "product" }`.
58
66
 
67
+ Exporter integrations can supply a merge toggle on the command line:
68
+
69
+ ```bash
70
+ needle-gltf transform input.glb output.glb --merge true
71
+ ```
72
+
73
+ `--merge` also enables it; `--merge false` disables it. These options apply only
74
+ when `meshes.merge` is absent from the resolved config. An explicit config value
75
+ (`true` or `false`) takes precedence. With neither set, merging stays off.
76
+ Error-based simplification uses a default error of `0.0003` (0.03%) when merging is enabled.
77
+ Override it in the resolved config:
78
+
79
+ ```json
80
+ { "meshes": { "merge": true, "simplificationError": 0.001 } }
81
+ ```
82
+
83
+ The error is sampled surface distance divided by the merged group's longest
84
+ world-space bounds dimension (`0.001` = 0.1%). It is not a vertex reduction ratio
85
+ or a guarantee of pixel/texture accuracy. Each spatial group is measured separately.
86
+ The baker selects geometry using this tolerance; no user triangle budget is needed.
87
+ Omitting the error uses `0.0003` (0.03%). This setting only affects eligible
88
+ merged groups, requires merging to be enabled, and runs before existing LOD
89
+ simplification. Later LODs have their own quality settings.
90
+
91
+ Atlas groups use the baker Node `optimizeMesh` workflow with automatic topology
92
+ selection and error targeting. Baker selects each atlas resolution from source
93
+ texel density and geometry detail when `meshes.atlasResolution` is omitted.
94
+ Override it with `meshes.atlasResolution` (128, 256, 512, 1024, 2048 or 4096). Native defaults select backend
95
+ (`auto`, with CPU fallback), material baking, and animation preservation.
96
+ The baker restores skinning for both skinned meshes and rigid animated parts.
97
+ The baker compares authored simplification and voxel candidates and owns selection
98
+ and fallback. Geometry-only groups also use its automatic method while retaining
99
+ materials. The pipeline does not add mode-selection heuristics or retries.
100
+ Geometry-only groups with additional UV sets or tangents keep those attributes
101
+ and skip simplification with a logged reason.
102
+
103
+ Outputs include a compact latest-run settings snapshot in `asset.extras.needle.processing`:
104
+
105
+ ```json
106
+ {
107
+ "schemaVersion": 1,
108
+ "bakerRevision": "<bundled baker commit SHA>",
109
+ "merge": { "enabled": true, "topologyMode": "auto", "error": 0.0003, "atlasResolution": 4096 }
110
+ }
111
+ ```
112
+
113
+ The atlas resolution is the actual size selected for baking: a number for one
114
+ distinct size, an array for multiple group sizes, and omitted when no atlas was baked.
115
+ These are resolved workflow settings, not a report of per-group outcomes or native
116
+ fallbacks. When merging is disabled, the snapshot contains only `schemaVersion`
117
+ and `merge: { "enabled": false }`. The pipeline version remains in `asset.generator`.
118
+
119
+ `meshes.materialSplitting` and `meshes.spatialGrouping` both default to `false`.
120
+ This suits standalone assets: material baking/partitioning is delegated to the
121
+ baker, and distance does not divide eligible merge groups. The baker determines
122
+ the output representation of material extensions; preservation of every source
123
+ shading feature is not guaranteed. Animation, skin, component and dynamic-material
124
+ protections still apply. Merging itself remains off unless `meshes.merge` is enabled.
125
+
126
+ Static `KHR_node_visibility` and standard `NEEDLE_gameobject_data` fields do not
127
+ exclude meshes. Compatible groups preserve inherited visibility/active state,
128
+ layers, tags, hide flags, and static flags on their merged output. Recognized
129
+ direct `Renderer`, `MeshRenderer`, and `SkinnedMeshRenderer` components on leaf
130
+ nodes transfer their render settings and retain their component type
131
+ with fresh identities. Original components, GUIDs, and component array indices
132
+ stay on the source nodes. Unknown scripts and their serialized references do not
133
+ exclude meshes by default; their behavior is not inferred to be safe, and moving
134
+ or changing an original node at runtime may no longer affect its merged geometry.
135
+ Explicit behavior findings and animation still constrain merging. Inherited renderer
136
+ behavior, unsupported/lightmapped renderer settings, GPU instancing, and material
137
+ variant mappings remain protected. An unused variants table or root lighting settings
138
+ alone do not prevent merging. Root persistent assets, lightmap tables, and dependency
139
+ metadata likewise do not exclude unrelated geometry. Animated visibility remains
140
+ protected. Fine-grained object/hierarchy no-merge authoring controls are planned
141
+ for later.
142
+
143
+
144
+ Opt into pipeline restrictions for scene-oriented processing:
145
+
146
+ ```json
147
+ { "meshes": { "merge": true, "materialSplitting": true, "spatialGrouping": true } }
148
+ ```
149
+
150
+ CLI fallbacks are `--material-splitting true|false` and
151
+ `--spatial-grouping true|false`; explicit JSON values take precedence.
152
+
153
+ With `spatialGrouping: true`, merging uses an adaptive bounds hierarchy with no absolute world-size cutoff.
154
+ It splits spatially when merging would inflate triangle-weighted bounds area by
155
+ more than a factor of three. This is a culling-cost heuristic, not a measured GPU
156
+ cost: it permits large overlapping meshes and avoids grouping across distant
157
+ outliers. Uniform scale and translation do not change the grouping policy.
158
+ Different supported materials and source
159
+ layouts can be combined through the Node baker's texture atlas workflow. Atlas
160
+ resolution is selected by the baker (128–4096) in the pipeline; texture LOD generation follows the
161
+ existing texture settings. Compatible transparency groups,
162
+ meshes under a shared animated parent, and compatible skins are supported.
163
+ Animated or component-referenced materials retain their original identities;
164
+ with `materialSplitting: true`, unsupported material extensions use the
165
+ geometry-only path where possible and conservative material state splits atlases.
166
+ Morph targets and component-transfer cases remain excluded. Existing source
167
+ nodes and animation targets remain in place.
168
+
169
+ Callers must use a pipeline version that supports `--merge`; older versions
170
+ reject the option.
171
+
59
172
  | Key | Type | Default | Description |
60
173
  |-----|------|---------|-------------|
61
174
  | `usecase` | `"default" \| "product" \| "world"` | `"default"` | High-level optimisation profile. |
62
175
  | `textures.lods` | `boolean` | `true` | Generate progressive texture LODs. |
63
176
  | `meshes.lods` | `boolean` | `true` | Generate progressive mesh LODs. |
177
+ | `meshes.merge` | `boolean` | `false` | Analyze eligible groups and merge geometry or bake materials into atlases before LOD generation and compression. Preserve protected material identities and original animation bindings. Unsupported geometry and component-transfer cases are skipped. |
178
+ | `meshes.simplificationError` | `number` | `0.0003` | With merging enabled, simplify eligible merged groups by sampled surface error. Must be greater than 0 and at most 1. Smaller values preserve more detail. |
179
+ | `meshes.atlasResolution` | `number` | Baker auto (128–4096) | Explicit power-of-two atlas size. |
180
+ | `meshes.materialSplitting` | `boolean` | `false` | Apply conservative pipeline material restrictions before baking. When false, delegate material partitioning to mesh-baker. |
181
+ | `meshes.spatialGrouping` | `boolean` | `false` | Subdivide eligible merge groups using the spatial culling-cost heuristic. |
64
182
  | `audio.enabled` | `boolean` | `true` | Compress externally referenced lossless audio files (`.wav`, `.flac`, `.aiff`/`.aif`) to Opus in an `.ogg` container, rewriting the URIs in the glTF. Lossy formats (`.mp3`, `.ogg`, `.m4a`, `.aac`) pass through unchanged to avoid compounding compression artifacts. Requires `ffmpeg` with `libopus` on `PATH`; when missing the build logs a warning and leaves the audio files untouched. |
65
183
  | `audio.bitrate` | `number` (kbps) | `128` | Opus encoding bitrate. 96 is near-transparent for most music; 128 matches YouTube's music tier and is the safe "won't sound bad" default. Drop to 48–64 for known mono/UI-only assets. |
66
184
  | `exr.enabled` | `boolean` | `true` | Convert EXR textures to KTX2 HDR via PMREM. When `false`, EXR textures (bundled and externally referenced) are left as-is so a downstream step can handle them. |
185
+ | `splat.enabled` | `boolean` | `true` | Compress externally referenced Gaussian splat files (`.ply`, `.spz`, `.splat`, `.ksplat`, `.sog`), rewriting the URIs in the glTF. |
186
+ | `splat.format` | `"auto" \| "sog" \| "rad"` | `"auto"` | Output container. SOG is smaller and is downloaded whole. RAD contains a LOD tree, so the renderer can stream it, and is about 50% larger. `auto` selects RAD for large scenes and SOG for small ones. |
187
+ | `splat.radThreshold` | `number` | `500000` | Splat count at which `auto` selects RAD. |
188
+ | `splat.flipToYUp` | `boolean` | `false` | Write SOG files in Y-up. Only needed for consumers that do not flip `.sog` themselves. RAD files are always Y-up. |
189
+
190
+ ## Running the tests
191
+
192
+ The static merge integration tests call the pinned mesh-baker submodule's public
193
+ API. From the repository root, initialize both pinned submodules:
194
+
195
+ ```sh
196
+ git submodule update --init modules/mesh-baker
197
+ git -C modules/mesh-baker -c submodule.modules/three-mesh-effects.url=https://github.com/needle-tools/three-mesh-effects.git submodule update --init modules/three-mesh-effects
198
+ ```
199
+
200
+ Access to both repositories is required. Then run `npm run test:setup:baker` from
201
+ `package/` to install baker dependencies (including build tools, with lifecycle
202
+ scripts disabled) and explicitly build the `three-mesh-effects` workspace.
203
+ Run `npm run compile` afterward. The build bundles
204
+ the pinned public baker API, Node workers and atlas WASM into `dist/baker`; installed
205
+ pipeline packages do not need a submodule checkout. These tests fail if the baker
206
+ is unavailable; they do not silently substitute a mock. `npm test` runs them with
207
+ the full suite.
67
208
 
68
209
  # Contact
69
210